use of org.codehaus.groovy.control.CompilePhase in project groovy by apache.
the class ASTTransformationCollectorCodeVisitor method verifyAndAddTransform.
@SuppressWarnings("unchecked")
private void verifyAndAddTransform(final AnnotationNode annotation, final Class<?> transformClass) {
if (!ASTTransformation.class.isAssignableFrom(transformClass)) {
String error = "Not an ASTTransformation: " + transformClass.getName() + " declared by " + annotation.getClassNode().getName();
source.getErrorCollector().addError(new SimpleMessage(error, source));
}
GroovyASTTransformation transformationClass = transformClass.getAnnotation(GroovyASTTransformation.class);
if (transformationClass == null) {
String error = "AST transformation implementation classes must be annotated with " + GroovyASTTransformation.class.getName() + ". " + transformClass.getName() + " lacks this annotation.";
source.getErrorCollector().addError(new SimpleMessage(error, source));
}
CompilePhase specifiedCompilePhase = transformationClass.phase();
if (specifiedCompilePhase.getPhaseNumber() < CompilePhase.SEMANTIC_ANALYSIS.getPhaseNumber()) {
String error = annotation.getClassNode().getName() + " is defined to be run in compile phase " + specifiedCompilePhase + ". Local AST transformations must run in SEMANTIC_ANALYSIS or later!";
source.getErrorCollector().addError(new SimpleMessage(error, source));
}
if (!Traits.isTrait(classNode) || transformClass == TraitASTTransformation.class || transformClass == SealedASTTransformation.class) {
classNode.addTransform((Class<? extends ASTTransformation>) transformClass, annotation);
}
}
use of org.codehaus.groovy.control.CompilePhase in project groovy by apache.
the class InlinedASTCustomizerFactory method postCompleteNode.
@Override
public Object postCompleteNode(final FactoryBuilderSupport factory, final Object parent, final Object node) {
if (node instanceof Map) {
Map map = (Map) node;
ProxyGeneratorAdapter adapter = new ProxyGeneratorAdapter(map, map.containsKey("superClass") ? (Class) map.get("superClass") : CompilationCustomizer.class, map.containsKey("interfaces") ? (Class[]) map.get("interfaces") : null, this.getClass().getClassLoader(), false, null);
Object phase = map.get("phase");
if (!(phase instanceof CompilePhase)) {
phase = CompilePhase.valueOf(phase.toString());
}
return adapter.proxy(map, phase);
}
return node;
}
use of org.codehaus.groovy.control.CompilePhase in project groovy by apache.
the class ASTTransformationVisitor method addPhaseOperations.
public static void addPhaseOperations(final CompilationUnit compilationUnit) {
ASTTransformationsContext context = compilationUnit.getASTTransformationsContext();
addGlobalTransforms(context);
compilationUnit.addPhaseOperation((final SourceUnit source, final GeneratorContext ignore, final ClassNode classNode) -> {
GroovyClassVisitor visitor = new ASTTransformationCollectorCodeVisitor(source, compilationUnit.getTransformLoader());
visitor.visitClass(classNode);
}, Phases.SEMANTIC_ANALYSIS);
for (CompilePhase phase : CompilePhase.values()) {
switch(phase) {
case INITIALIZATION:
case PARSING:
case CONVERSION:
// with transform detection alone these phases are inaccessible, so don't add it
break;
default:
compilationUnit.addPhaseOperation((final SourceUnit source, final GeneratorContext ignore, final ClassNode classNode) -> {
ASTTransformationVisitor visitor = new ASTTransformationVisitor(phase, context);
visitor.source = source;
visitor.visitClass(classNode);
}, phase.getPhaseNumber());
break;
}
}
}
use of org.codehaus.groovy.control.CompilePhase in project groovy-core by groovy.
the class InlinedASTCustomizerFactory method postCompleteNode.
public Object postCompleteNode(final FactoryBuilderSupport factory, final Object parent, final Object node) {
if (node instanceof Map) {
Map map = (Map) node;
ProxyGeneratorAdapter adapter = new ProxyGeneratorAdapter(map, map.containsKey("superClass") ? (Class) map.get("superClass") : CompilationCustomizer.class, map.containsKey("interfaces") ? (Class[]) map.get("interfaces") : null, this.getClass().getClassLoader(), false, null);
Object phase = map.get("phase");
if (!(phase instanceof CompilePhase)) {
phase = CompilePhase.valueOf(phase.toString());
}
return adapter.proxy(map, phase);
}
return node;
}
Aggregations