Skip to content

Custom AST transformation classes broken #270

@admxiii

Description

@admxiii

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));
}

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions