Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support custom compiler annotations #353

Closed
nigelsim opened this issue Oct 20, 2017 · 8 comments
Closed

Support custom compiler annotations #353

nigelsim opened this issue Oct 20, 2017 · 8 comments

Comments

@nigelsim
Copy link

I'm using Groovy-Eclipse on a Grails 3 project. We are starting to the the @GrailsCompileStatic annotation to have Goovy do static type checking, but also not fail the methods that come from Grail's metaclasses. However, in Eclipse these methods are still marked as missing, so it appears that annotation isn't being applied in the same way it does from the command line.

For instance, the log and respond methods on controllers are provided by metaclasses, but show up as errors.

GrailsCompileStatic code
GrailsCompileStatic docs

Thanks

@eric-milles
Copy link
Member

Can you provide a very small example? CompileStatic and type checking extensions are indeed applied. However, a command-line compilation is not the equivalent of opening a file for edit, parsing it, resolving types, and whatnot. Some of the Groovy code is exported to the Java model so that the base JDT can do its thing.

@nigelsim
Copy link
Author

Hi @eric-milles , please see https://github.com/nigelsim/grails-test-compile-static

From the command line this compiles fine
`
$ ./grailsw compile

Configuring > 0/1 projects > root project > Resolving dependencies ':classpath:compileJava NO-SOURCE
:compileGroovy
:buildProperties
:processResources
:classes

BUILD SUCCESSFUL
`

But from the Grails project it fails.
log method not found

Is it possible I've not properly configured something?

@eric-milles
Copy link
Member

Here is a quick update. The file did compile (there is a class file) with no errors (see Problems view). The type checking error is in the editor only.

The log field is created by org.grails.compiler.logging.LoggingTransformer, which is executed by org.grails.compiler.injection.GlobalGrailsClassInjectorTransformation. Do you have the Grails tooling installed?

grails-transforms

@eric-milles
Copy link
Member

eric-milles commented Oct 23, 2017

To enable the global transformation on reconcile (editor opens file buffer, parses the source code, and resolves the types) you can add the system property greclipse.globalTransformsInReconcile=org.grails.compiler.injection.GlobalGrailsClassInjectorTransformation,org.grails.compiler.injection.GlobalImportTransformation to your Eclipse (like in eclipse.ini). I think GGTS did this as part of the distro.

@nigelsim
Copy link
Author

Thanks @eric-milles, that addition to my eclipse.ini file does seem to have solved the issue. It's good to understand that the editor and the compiler have their own distinct views of the code.

What are the consequences of putting that line in my eclipse.ini file?

I'm not using any other Grails specific tools. It seems that everything that does exist (GGTS, Grails-IDE, etc) were pretty poor at best, and I've got far more mileage out of goovy-eclipse + buildship.

I'll give this a go on my main project today and will let you know how it goes.

@eric-milles
Copy link
Member

eric-milles commented Oct 24, 2017 via email

@nigelsim
Copy link
Author

nigelsim commented Oct 26, 2017

Interestingly the use of globalTransformsInReconcile removes some, but not all type check errors from the editor. As you pointed out, these errors are only in the editor, not the compiler.

With globalTransformsInReconcile:
with-globaltransformsinreconcile

Without globalTransformsInReconcile:
without-globaltransformsinreconcile

I've pushed the change to demonstrate this to the previous repo.

@eric-milles
Copy link
Member

There are more global transforms that were discovered on the classpath. You could try adding one or more of them:

org.grails.datastore.gorm.query.transform.GlobalDetachedCriteriaASTTransformation
org.grails.compiler.gorm.GlobalTraitRepairTransformation
org.spockframework.compiler.SpockTransform
and one or more from Geb...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants