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

Custom AST transformation classes broken #270

Closed
admxiii opened this issue Mar 15, 2017 · 12 comments
Closed

Custom AST transformation classes broken #270

admxiii opened this issue Mar 15, 2017 · 12 comments

Comments

@admxiii
Copy link

admxiii commented Mar 15, 2017

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 {

private static final String FIELD_NAME = "serialVersionUID";
private static final int FIELD_MODIFIERS = Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC | Opcodes.ACC_FINAL;
private static final ClassNode FIELD_TYPE = ClassHelper.long_TYPE;
private static final Long FIELD_VALUE = Long.valueOf(1);

@Override
public void visit(ASTNode[] nodes, SourceUnit source) {
	ClassNode classNode = (ClassNode) nodes[1];

	ClassNode serializable = ClassHelper.make(Serializable.class);

	if (!classNode.implementsInterface(serializable)) {
		classNode.addInterface(serializable);
	}

	classNode.addField(FIELD_NAME, FIELD_MODIFIERS, FIELD_TYPE, new ConstantExpression(FIELD_VALUE));
}

}

@eric-milles
Copy link
Member

eric-milles commented Mar 15, 2017 via email

@admxiii
Copy link
Author

admxiii commented Mar 15, 2017

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

@eric-milles eric-milles changed the title Custom AST classes broken Custom AST transformation classes broken Mar 16, 2017
@eric-milles
Copy link
Member

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.

@admxiii
Copy link
Author

admxiii commented Mar 17, 2017

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.

@eric-milles
Copy link
Member

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.

@mariogarcia
Copy link

mariogarcia commented Mar 21, 2017 via email

@admxiii
Copy link
Author

admxiii commented Mar 22, 2017

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

@eric-milles
Copy link
Member

eric-milles commented Mar 22, 2017 via email

@admxiii
Copy link
Author

admxiii commented Mar 22, 2017

Heres a tiny example showing the code compiling through gradle and not inside eclipse

Example

Moving the transform to src/main/java outside of the main project (src/main/groovy) solved my issue for now.

@mariogarcia
Copy link

mariogarcia commented Mar 23, 2017 via email

@eric-milles
Copy link
Member

@mariogarcia Thanks for the extra clarification and examples.

@mariogarcia
Copy link

mariogarcia commented Mar 23, 2017 via email

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

3 participants