use of org.codehaus.groovy.ast.AnnotationNode in project groovy by apache.
the class NotYetImplementedASTTransformation method visit.
public void visit(ASTNode[] nodes, SourceUnit source) {
if (nodes.length != 2 || !(nodes[0] instanceof AnnotationNode) || !(nodes[1] instanceof AnnotatedNode)) {
throw new RuntimeException("Internal error: expecting [AnnotationNode, AnnotatedNode] but got: " + Arrays.asList(nodes));
}
AnnotationNode annotationNode = (AnnotationNode) nodes[0];
ASTNode node = nodes[1];
if (!(node instanceof MethodNode)) {
addError("@NotYetImplemented must only be applied on test methods!", node);
return;
}
MethodNode methodNode = (MethodNode) node;
ArrayList<Statement> statements = new ArrayList<Statement>();
Statement statement = methodNode.getCode();
if (statement instanceof BlockStatement) {
statements.addAll(((BlockStatement) statement).getStatements());
}
if (statements.isEmpty())
return;
BlockStatement rewrittenMethodCode = new BlockStatement();
rewrittenMethodCode.addStatement(tryCatchAssertionFailedError(annotationNode, methodNode, statements));
rewrittenMethodCode.addStatement(throwAssertionFailedError(annotationNode));
methodNode.setCode(rewrittenMethodCode);
}
use of org.codehaus.groovy.ast.AnnotationNode in project spring-boot by spring-projects.
the class SpringBootCompilerAutoConfiguration method addEnableAutoConfigurationAnnotation.
private void addEnableAutoConfigurationAnnotation(SourceUnit source, ClassNode classNode) {
if (!hasEnableAutoConfigureAnnotation(classNode)) {
AnnotationNode annotationNode = new AnnotationNode(ClassHelper.make("EnableAutoConfiguration"));
classNode.addAnnotation(annotationNode);
}
}
use of org.codehaus.groovy.ast.AnnotationNode in project spring-boot by spring-projects.
the class SpringTestCompilerAutoConfiguration method apply.
@Override
public void apply(GroovyClassLoader loader, GroovyCompilerConfiguration configuration, GeneratorContext generatorContext, SourceUnit source, ClassNode classNode) throws CompilationFailedException {
if (!AstUtils.hasAtLeastOneAnnotation(classNode, "RunWith")) {
AnnotationNode runWith = new AnnotationNode(ClassHelper.make("RunWith"));
runWith.addMember("value", new ClassExpression(ClassHelper.make("SpringRunner")));
classNode.addAnnotation(runWith);
}
}
use of org.codehaus.groovy.ast.AnnotationNode in project spock by spockframework.
the class SpecAnnotator method addBlockMetadata.
private void addBlockMetadata(Block block, BlockKind kind) {
AnnotationNode blockAnn = new AnnotationNode(nodeCache.BlockMetadata);
blockAnn.setMember(BlockMetadata.KIND, new PropertyExpression(new ClassExpression(nodeCache.BlockKind), kind.name()));
ListExpression textExprs = new ListExpression();
for (String text : block.getDescriptions()) textExprs.addExpression(new ConstantExpression(text));
blockAnn.setMember(BlockMetadata.TEXTS, textExprs);
blockAnnElems.addExpression(new AnnotationConstantExpression(blockAnn));
}
use of org.codehaus.groovy.ast.AnnotationNode in project spock by spockframework.
the class SpecAnnotator method addFieldMetadata.
private void addFieldMetadata(Field field) {
AnnotationNode ann = new AnnotationNode(nodeCache.FieldMetadata);
ann.setMember(FieldMetadata.NAME, new ConstantExpression(field.getName()));
ann.setMember(FieldMetadata.ORDINAL, new ConstantExpression(field.getOrdinal()));
ann.setMember(FieldMetadata.LINE, new ConstantExpression(field.getAst().getLineNumber()));
field.getAst().addAnnotation(ann);
}
Aggregations