fernando88to opened a new pull request, #433:
URL: https://github.com/apache/grails-intellij-plugin/pull/433

   ## Problem
   
     Inside a where query, the bare property names were not resolved:
   
         @GrailsCompileStatic
         class PersonService {
             List<Person> findActive(Integer minAge) {
                 Person.where { active == true && age >= minAge }.list()
             }
         }
   
   With `@GrailsCompileStatic` the IDE flagged `active` and `age` as errors, 
even though the code compiles and runs. Without the annotation the error went 
away, but the properties still didn't resolve,  so Ctrl+click didn't take you 
to the field. 
     
   The cause is that the GORM 5+ `GormEntity` trait declares 
`where(@DelegatesTo(DetachedCriteria) Closure)`. The closure's delegate is a 
plain `DetachedCriteria`, which knows nothing about the domain  properties, 
because GORM rewrites the closure at compile time.
     
     ## Fix
     
   A new `WhereQueryClosureMemberContributor` resolves those names to the 
persistent properties of the queried domain class (plus `id` and `version`) in 
the closures of `where`, `whereAny`, `whereLazy`,  `find` and `findAll`. It 
covers:
     
     - `Person.where { ... }`
     - composed queries: `query.where { ... }`
     - unqualified `where { ... }` inside the domain class itself
     
   Properties resolve through their getter rather than the field. A Groovy 
property is a private field, so resolving to the field directly triggers an 
"access rights" error under static compilation. Navigation and rename still go 
to the field.
     
   Transient properties, unknown names and closures nested inside the where 
closure stay unresolved. Association sub-queries (`pets { name == 'x' }`) are 
not handled yet and could be a follow-up.
     
     ## Tests
     
   The new `GormWhereQueryTest` covers the `@CompileStatic` case (including a 
check that an unknown name is still an error, so the class really is type 
checked), navigation, rename, composed queries and  the cases that must not 
resolve.
     
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to