-
Notifications
You must be signed in to change notification settings - Fork 193
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
Custom AST transformation classes broken #270
Comments
Thanks for reporting this issue. Your recreation steps worked quite effectively.
If you change your AST transform definition in this way, you should be able to work around the issue until a fix is completed.
```java
@GroovyASTTransformationClass(classes={com.company.transform.SerializableTransformation.class})
//@GroovyASTTransformationClass("com.company.transform.SerializableTransformation")
public @interface Serializable {
// implements serializable interface
}
```
|
not sure why, but the work around isn't working for me for some reason. The work around works with groovyc just not in eclipse with latest snapshot. I can live with the error for a while so its not a big deal. Groovy:@GroovyASTTransformationClass in com.company.transform.Serializable does not specify any transform class names/classes |
Hmm, the error seems to indicate that the classes attribute value did not get recognized. Before trying to load the transform class(es), there is a check on the lengths of the "classes" and "value" arrays. That is where the error you listed is emitted. One detail, are you defining the transform annotation and implementation in the same project in which it is used? I can't remember if that is a special case or unsupported. When I get a chance, I'm going to try and go back to an earlier eclipse so I can see the same code working. There have been a lot of changes in JDT core recently with Neon fast approaching SR3 and Oxygen already up to M6. |
Yes the interface/implementation are both in the same project in which it is used. I can try moving it to its own project if it continues to be an issue or is not recommended. |
What version of Groovy and Eclipse are and were you using? I have checked the test case with Groovy 2.4, 2.3, 2.2 and Eclipse 4.7 (Oxygen), 4.6 (Neon) and 4.5 (Mars). It produces the error for all. |
AST Transformations are not visible in the same module unless you use
compilation programmatically, like using assertScript in a GroovyTestCase,
or using GroovyShell directly. That's a common gotcha when developing AST
transformations.
You should keep transformations and the code using those transformations in
different modules (I'm thinking in a Gradle module for example).
Mario
2017-03-18 16:01 GMT+01:00 Eric Milles <[email protected]>:
… What version of Groovy and Eclipse are and were you using? I have checked
the test case with Groovy 2.4, 2.3, 2.2 and Eclipse 4.7 (Oxygen), 4.6
(Neon) and 4.5 (Mars). It produces the error for all.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#270 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABWT85voJS90tI5t3fm2-q60GuTmlzFbks5rm_HhgaJpZM4MeGQj>
.
|
Thanks for looking into this and pointing out the groovy limitation, I was unaware of that. It still works compiling through Gradle/Groovy, just eclipse can't seem to find them anymore with this new update. I can move them to a subproject or jar them up, gradle does make that easy, but subprojects in eclipse are ugly and i was trying to avoid the additional project complexity. FYI, i am using Neon 4.6.2 and Groovy 2.4.9 |
If this works through Gradle or Groovyc build, I'm inclined to keep this issue and try to get back to previous state. Can you create a tiny project incl. gradlew that shows it working?
|
Heres a tiny example showing the code compiling through gradle and not inside eclipse Moving the transform to src/main/java outside of the main project (src/main/groovy) solved my issue for now. |
Ah ah ah, I think why it is working with gradle: JOINT COMPILATION
Your transformations are SerializableTransformation.java and
Serializable.java and are located in src/main/groovy that means the Groovy
compiler should do "joint compilation", that means it has to do several
compilations until both java code and groovy code see each other. Again
that means in best case scenario 2 different compilations (first java, then
groovy, but I think is more complex than that).
And also that's probably why it's working with the eclipse plugin when you
move your java code to the java folder, because it compiles the
transformation first (java code), and then compiles the Groovy code.
Bearing that in mind, it makes sense that your gradle project worked,
because gradle plugin is aware of joint compilation. However It wouldn't
have worked if all your code had been groovy code. In that case you should
have written your transformations in one gradle module separated from the
code you want to apply your transformation to, or, if you only wanted to
test the transformation, use `assertScript` in your tests. If you check any
transformation in Groovy repository most (if not all) are tested using
`assertScript` which basically forces to compile that specific code again
to make sure it sees the AST (check for example
https://github.com/apache/groovy/blob/master/src/test/org/codehaus/groovy/transform/ToStringTransformTest.groovy
)
Regards
Mario
2017-03-22 17:56 GMT+01:00 admxiii <[email protected]>:
… Heres a tiny example showing the code compiling through gradle and not
inside eclipse
Example <https://github.com/admxiii/GroovyAstExample>
Moving the transform to src/main/java outside of the main project
(src/main/groovy) solved my issue for now.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#270 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABWT85xfYsga7oFOQ_mWeYQ02cHQ3Qzhks5roVLagaJpZM4MeGQj>
.
|
@mariogarcia Thanks for the extra clarification and examples. |
Glad to help :)
2017-03-23 15:38 GMT+01:00 Eric Milles <[email protected]>:
… @mariogarcia <https://github.com/mariogarcia> Thanks for the extra
clarification and examples.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#270 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABWT804GkTlQXBuWqf0Ngd7QVttW9EU1ks5rooPwgaJpZM4MeGQj>
.
|
Getting a new error with latest snapshot version, this works with groovyc and was working as of 3-10-17 in groovy-eclipse. Seemed to break with the JDT patch commit.
Groovy:Could not find class for Transformation Processor com.company.transform.SerializableTransformation declared by com.company.transform.Serializable
Here's a slimmed down example
// POGO with error - SomePOGO.groovy
@serializable
class SomePOGO {
// fields
}
// annotation - Serializable.java
@retention(RetentionPolicy.RUNTIME)
@target(ElementType.TYPE)
@GroovyASTTransformationClass("com.company.transform.SerializableTransformation")
public @interface Serializable {
// implements serializable interface
}
// ast impl - SerializableTransformation.java
@GroovyASTTransformation(phase = CompilePhase.CANONICALIZATION)
public class SerializableTransformation implements ASTTransformation {
}
The text was updated successfully, but these errors were encountered: