use of org.codehaus.groovy.ast.AnnotationNode in project groovy by apache.
the class AntlrParserPlugin method innerInterfaceDef.
protected void innerInterfaceDef(AST classDef) {
List<AnnotationNode> annotations = new ArrayList<AnnotationNode>();
AST node = classDef.getFirstChild();
int modifiers = Opcodes.ACC_PUBLIC;
if (isType(MODIFIERS, node)) {
modifiers = modifiers(node, annotations, modifiers);
checkNoInvalidModifier(classDef, "Interface", modifiers, Opcodes.ACC_SYNCHRONIZED, "synchronized");
node = node.getNextSibling();
}
modifiers |= Opcodes.ACC_ABSTRACT | Opcodes.ACC_INTERFACE;
String name = identifier(node);
node = node.getNextSibling();
ClassNode superClass = ClassHelper.OBJECT_TYPE;
GenericsType[] genericsType = null;
if (isType(TYPE_PARAMETERS, node)) {
genericsType = makeGenericsType(node);
node = node.getNextSibling();
}
ClassNode[] interfaces = ClassNode.EMPTY_ARRAY;
if (isType(EXTENDS_CLAUSE, node)) {
interfaces = interfaces(node);
node = node.getNextSibling();
}
ClassNode outerClass = classNode;
boolean syntheticPublic = ((modifiers & Opcodes.ACC_SYNTHETIC) != 0);
modifiers &= ~Opcodes.ACC_SYNTHETIC;
if (classNode != null) {
name = classNode.getNameWithoutPackage() + "$" + name;
String fullName = dot(classNode.getPackageName(), name);
classNode = new InnerClassNode(classNode, fullName, modifiers, superClass, interfaces, null);
} else {
classNode = new ClassNode(dot(getPackageName(), name), modifiers, superClass, interfaces, null);
}
classNode.setSyntheticPublic(syntheticPublic);
classNode.addAnnotations(annotations);
classNode.setGenericsTypes(genericsType);
configureAST(classNode, classDef);
int oldClassCount = innerClassCounter;
assertNodeType(OBJBLOCK, node);
objectBlock(node);
output.addClass(classNode);
classNode = outerClass;
innerClassCounter = oldClassCount;
}
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 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