use of org.codehaus.groovy.ast.AnnotationNode in project grails-core by grails.
the class GrailsApplicationCompilerAutoConfiguration method createGrabAnnotation.
public static AnnotationNode createGrabAnnotation(String group, String module, String version, String classifier, String type, boolean transitive) {
AnnotationNode annotationNode = new AnnotationNode(new ClassNode(Grab.class));
annotationNode.addMember("group", new ConstantExpression(group));
annotationNode.addMember("module", new ConstantExpression(module));
annotationNode.addMember("version", new ConstantExpression(version));
if (classifier != null) {
annotationNode.addMember("classifier", new ConstantExpression(classifier));
}
if (type != null) {
annotationNode.addMember("type", new ConstantExpression(type));
}
annotationNode.addMember("transitive", new ConstantExpression(transitive));
annotationNode.addMember("initClass", new ConstantExpression(false));
return annotationNode;
}
use of org.codehaus.groovy.ast.AnnotationNode in project grails-core by grails.
the class DirtiesRuntimeTransformation method visit.
@Override
public void visit(final ASTNode[] astNodes, final SourceUnit source) {
if (!(astNodes[0] instanceof AnnotationNode) || !(astNodes[1] instanceof MethodNode)) {
throw new RuntimeException("Internal error: wrong types: $node.class / $parent.class");
}
final MethodNode methodNode = (MethodNode) astNodes[1];
final ClassNode declaringClassNode = methodNode.getDeclaringClass();
if (declaringClassNode != null) {
final List<AnnotationNode> annotations = declaringClassNode.getAnnotations(ClassHelper.make(FreshRuntime.class));
if (annotations != null && annotations.size() > 0) {
final String message = "The [" + methodNode.getName() + "] method in [" + declaringClassNode.getName() + "] is marked with @DirtiesRuntime. " + "There is no need to mark a test method with @DirtiesRuntime " + "inside of a test class which is marked with @FreshRuntime.";
GrailsASTUtils.warning(source, methodNode, message);
}
}
}
use of org.codehaus.groovy.ast.AnnotationNode in project grails-core by grails.
the class TestMixinTransformation method addSpockFieldMetadata.
private void addSpockFieldMetadata(FieldNode field, int ordinal) {
AnnotationNode ann = new AnnotationNode(ClassHelper.make(FieldMetadata.class));
ann.setMember(FieldMetadata.NAME, new ConstantExpression(field.getName()));
ann.setMember(FieldMetadata.ORDINAL, new ConstantExpression(ordinal));
ann.setMember(FieldMetadata.LINE, new ConstantExpression(field.getLineNumber()));
field.addAnnotation(ann);
}
use of org.codehaus.groovy.ast.AnnotationNode in project grails-core by grails.
the class TestMixinTransformation method visit.
public void visit(ASTNode[] astNodes, SourceUnit source) {
if (!(astNodes[0] instanceof AnnotationNode) || !(astNodes[1] instanceof AnnotatedNode)) {
throw new RuntimeException("Internal error: wrong types: " + astNodes[0].getClass() + " / " + astNodes[1].getClass());
}
AnnotatedNode parent = (AnnotatedNode) astNodes[1];
AnnotationNode annotationNode = (AnnotationNode) astNodes[0];
if (!MY_TYPE.equals(annotationNode.getClassNode()) || !(parent instanceof ClassNode)) {
return;
}
String mainClass = MainClassFinder.searchMainClass(source.getSource().getURI());
ClassNode applicationClassNode = null;
if (mainClass != null) {
applicationClassNode = ClassHelper.make(mainClass);
}
ClassNode classNode = (ClassNode) parent;
ListExpression values = getListOfClasses(annotationNode);
weaveTestMixins(classNode, values, applicationClassNode);
}
use of org.codehaus.groovy.ast.AnnotationNode in project grails-core by grails.
the class TestMixinTransformation method addJunitRuleFields.
protected void addJunitRuleFields(ClassNode classNode) {
if (classNode.getField(JUNIT_ADAPTER_FIELD_NAME) != null) {
return;
}
ClassNode junitAdapterType = ClassHelper.make(TestRuntimeJunitAdapter.class);
FieldNode junitAdapterFieldNode = classNode.addField(JUNIT_ADAPTER_FIELD_NAME, Modifier.STATIC, junitAdapterType, new ConstructorCallExpression(junitAdapterType, MethodCallExpression.NO_ARGUMENTS));
boolean spockTest = isSpockTest(classNode);
FieldNode staticRuleFieldNode = classNode.addField(RULE_FIELD_NAME_BASE + "StaticClassRule", Modifier.PRIVATE | Modifier.STATIC, ClassHelper.make(TestRule.class), new MethodCallExpression(new FieldExpression(junitAdapterFieldNode), "newClassRule", new ClassExpression(classNode)));
AnnotationNode classRuleAnnotation = new AnnotationNode(ClassHelper.make(ClassRule.class));
if (spockTest) {
// @ClassRule must be added to @Shared field in spock
FieldNode spockSharedRuleFieldNode = classNode.addField(RULE_FIELD_NAME_BASE + "SharedClassRule", Modifier.PUBLIC, ClassHelper.make(TestRule.class), new FieldExpression(staticRuleFieldNode));
spockSharedRuleFieldNode.addAnnotation(classRuleAnnotation);
spockSharedRuleFieldNode.addAnnotation(new AnnotationNode(ClassHelper.make(Shared.class)));
addSpockFieldMetadata(spockSharedRuleFieldNode, 0);
} else {
staticRuleFieldNode.setModifiers(Modifier.PUBLIC | Modifier.STATIC);
staticRuleFieldNode.addAnnotation(classRuleAnnotation);
}
FieldNode ruleFieldNode = classNode.addField(RULE_FIELD_NAME_BASE + "Rule", Modifier.PUBLIC, ClassHelper.make(TestRule.class), new MethodCallExpression(new FieldExpression(junitAdapterFieldNode), "newRule", new VariableExpression("this")));
ruleFieldNode.addAnnotation(new AnnotationNode(ClassHelper.make(Rule.class)));
if (spockTest) {
addSpockFieldMetadata(ruleFieldNode, 0);
}
}
Aggregations