public List<AnnotationNode> getAnnotations(ClassNode type) { List<AnnotationNode> ret = new ArrayList<AnnotationNode>(annotations.size()); for (AnnotationNode node: annotations) { if (type.equals(node.getClassNode())) ret.add(node); } return ret; }
private static List<AnnotationNode> filterAnnotations(List<AnnotationNode> annotations) { List<AnnotationNode> result = new ArrayList<AnnotationNode>(annotations.size()); for (AnnotationNode annotation : annotations) { if (!OVERRIDE_CLASSNODE.equals(annotation.getClassNode())) { result.add(annotation); } } return result; }
private static boolean acceptableTransform(AnnotationNode annotation) { // TODO also check for phase after sourceUnit.getPhase()? but will be ignored anyway? // TODO we should only copy those annotations with FIELD_TARGET but haven't visited annotations // and gathered target info at this phase, so we can't do this: // return annotation.isTargetAllowed(AnnotationNode.FIELD_TARGET); // instead just don't copy ourselves for now return !annotation.getClassNode().equals(MY_TYPE); }
private static List<AnnotationNode> filterAnnotations(List<AnnotationNode> annotations) { List<AnnotationNode> result = new ArrayList<AnnotationNode>(annotations.size()); for (AnnotationNode annotation : annotations) { if (!OVERRIDE_CLASSNODE.equals(annotation.getClassNode())) { result.add(annotation); } } return result; }
public static AnnotationNode getAnnotation(ASTNode node, Class<?> annotationType) { if (!(node instanceof AnnotatedNode)) return null; AnnotatedNode annotated = (AnnotatedNode)node; @SuppressWarnings("unchecked") List<AnnotationNode> annotations = annotated.getAnnotations(); for (AnnotationNode a : annotations) if (a.getClassNode().getName().equals(annotationType.getName())) return a; return null; }
private void printAnnotation(PrintWriter out, AnnotationNode annotation) { out.print("@" + annotation.getClassNode().getName().replace('$', '.') + "("); boolean first = true; Map<String, Expression> members = annotation.getMembers(); for (Map.Entry<String, Expression> entry : members.entrySet()) { String key = entry.getKey(); if (first) first = false; else out.print(", "); out.print(key + "=" + getAnnotationValue(entry.getValue()).replace('$', '.')); } out.print(") "); }
private static List<AnnotationNode> copy(List<AnnotationNode> orig, AnnotationNode aliasAnnotationUsage) { if (orig.isEmpty()) return orig; List<AnnotationNode> ret = new ArrayList<AnnotationNode>(orig.size()); for (AnnotationNode an : orig) { AnnotationNode newAn = new AnnotationNode(an.getClassNode()); copyMembers(an, newAn); newAn.setSourcePosition(aliasAnnotationUsage); ret.add(newAn); } return ret; }
protected Expression transformAnnotationConstantExpression(AnnotationConstantExpression ace) { AnnotationNode an = (AnnotationNode) ace.getValue(); ClassNode type = an.getClassNode(); resolveOrFail(type, ", unable to find class for annotation", an); for (Map.Entry<String, Expression> member : an.getMembers().entrySet()) { member.setValue(transform(member.getValue())); } return ace; }
private void verifyClass(AnnotationNode annotation, Class klass) { if (!ASTTransformation.class.isAssignableFrom(klass)) { source.getErrorCollector().addError(new SimpleMessage("Not an ASTTransformation: " + klass.getName() + " declared by " + annotation.getClassNode().getName(), source)); } }
public void visit(ASTNode[] nodes, SourceUnit source) { init(nodes, source); AnnotatedNode parent = (AnnotatedNode) nodes[1]; AnnotationNode node = (AnnotationNode) nodes[0]; if (!MY_TYPE.equals(node.getClassNode())) return; if (parent instanceof ClassNode) { processClass((ClassNode) parent, node); } }
private static boolean hasImmutableAnnotation(ClassNode type) { List<AnnotationNode> annotations = type.getAnnotations(); for (AnnotationNode next : annotations) { String name = next.getClassNode().getName(); if (matchingMarkerName(name)) return true; } return false; }
private static List<AnnotationNode> getStoredTargetList(AnnotationNode aliasAnnotationUsage, SourceUnit source) { ClassNode alias = aliasAnnotationUsage.getClassNode().redirect(); List<AnnotationNode> ret = getMeta(alias); return copy(ret, aliasAnnotationUsage); }
@Override public void visitAnnotations(AnnotatedNode node) { super.visitAnnotations(node); for (AnnotationNode an : node.getAnnotations()) { addToCache(an.getClassNode()); } } @Override
private static boolean checkIsConditionBlock(MethodCallExpression methodCallExpr) { ClassNode targetType = methodCallExpr.getObjectExpression().getType(); String methodName = methodCallExpr.getMethodAsString(); List<MethodNode> methods = targetType.getMethods(methodName); for (MethodNode method : methods) { for (AnnotationNode annotation : method.getAnnotations()) { if (annotation.getClassNode().getName().equals(ConditionBlock.class.getName())) return true; } } return false; } }
private Expression serialize(AnnotationNode an) { MapExpression map = new MapExpression(); for (String key : an.getMembers().keySet()) { map.addMapEntryExpression(new ConstantExpression(key), serialize(an.getMember(key))); } List<Expression> l = new ArrayList<Expression>(2); l.add(new ClassExpression(an.getClassNode())); l.add(map); return new ArrayExpression(ClassHelper.OBJECT_TYPE, l); } }
@Override @SuppressWarnings("unchecked") public void visitAnnotations(AnnotatedNode node) { for (AnnotationNode an : node.getAnnotations()) { ClassNode cn = an.getClassNode(); // this comparison should be good enough, and also works in phase conversion if (cn.getNameWithoutPackage().equals(Inspect.class.getSimpleName())) { ConstantExpression name = (ConstantExpression)an.getMember("value"); if (name == null || !(name.getValue() instanceof String)) throw new AstInspectorException("@Inspect must have a String argument"); addNode(markedNodes, (String)name.getValue(), node); break; } } super.visitAnnotations(node); }
public void configureAnnotation(AnnotationNode node) { ClassNode type = node.getClassNode(); VMPlugin plugin = VMPluginFactory.getPlugin(); List<AnnotationNode> annotations = type.getAnnotations(); for (AnnotationNode an : annotations) { plugin.configureAnnotationNodeFromDefinition(an, node); } plugin.configureAnnotationNodeFromDefinition(node, node); }
private Class loadTransformClass(String transformClass, AnnotationNode annotation) { try { return transformLoader.loadClass(transformClass, false, true, false); } catch (ClassNotFoundException e) { source.getErrorCollector().addErrorAndContinue( new SimpleMessage( "Could not find class for Transformation Processor " + transformClass + " declared by " + annotation.getClassNode().getName(), source)); } return null; }
private AnnotationVisitor getAnnotationVisitor(AnnotatedNode targetNode, AnnotationNode an, Object visitor) { final String annotationDescriptor = BytecodeHelper.getTypeDescription(an.getClassNode()); if (targetNode instanceof MethodNode) { return ((MethodVisitor) visitor).visitAnnotation(annotationDescriptor, an.hasRuntimeRetention()); } else if (targetNode instanceof FieldNode) { return ((FieldVisitor) visitor).visitAnnotation(annotationDescriptor, an.hasRuntimeRetention()); } else if (targetNode instanceof ClassNode) { return ((ClassVisitor) visitor).visitAnnotation(annotationDescriptor, an.hasRuntimeRetention()); } throwException("Cannot create an AnnotationVisitor. Please report Groovy bug"); return null; }
private void visitParameterAnnotations(Parameter parameter, int paramNumber, MethodVisitor mv) { for (AnnotationNode an : parameter.getAnnotations()) { // skip built-in properties if (an.isBuiltIn()) continue; if (an.hasSourceRetention()) continue; final String annotationDescriptor = BytecodeHelper.getTypeDescription(an.getClassNode()); AnnotationVisitor av = mv.visitParameterAnnotation(paramNumber, annotationDescriptor, an.hasRuntimeRetention()); visitAnnotationAttributes(an, av); av.visitEnd(); } }