private boolean checkIfValidEnumConstsAreUsed(AnnotationNode node) { Map<String, Expression> attributes = node.getMembers(); for (Map.Entry<String, Expression> entry : attributes.entrySet()) { if (!validateEnumConstant(entry.getValue())) return false; } return true; }
private static void copyMembers(final AnnotationNode from, final AnnotationNode to) { Map<String, Expression> members = from.getMembers(); copyMembers(members, to); }
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(") "); }
public void visitAnnotations(AnnotatedNode node) { List<AnnotationNode> annotations = node.getAnnotations(); if (annotations.isEmpty()) return; for (AnnotationNode an : annotations) { // skip built-in properties if (an.isBuiltIn()) continue; for (Map.Entry<String, Expression> member : an.getMembers().entrySet()) { member.setValue(transform(member.getValue())); } } }
public void visitAnnotations(AnnotatedNode node) { List<AnnotationNode> annotations = node.getAnnotations(); if (annotations.isEmpty()) return; for (AnnotationNode an : annotations) { // skip built-in properties if (an.isBuiltIn()) continue; for (Map.Entry<String, Expression> member : an.getMembers().entrySet()) { member.getValue().visit(this); } } }
public void visitAnnotations(AnnotatedNode node) { List<AnnotationNode> annotations = node.getAnnotations(); if (annotations.isEmpty()) return; for (AnnotationNode an : annotations) { // skip built-in properties if (an.isBuiltIn()) continue; for (Map.Entry<String, Expression> member : an.getMembers().entrySet()) { Expression annMemberValue = member.getValue(); annMemberValue.visit(this); } } } }
private static boolean hasClosureMember(AnnotationNode annotation) { Map<String, Expression> members = annotation.getMembers(); for (Map.Entry<String, Expression> member : members.entrySet()) { if (member.getValue() instanceof ClosureExpression) return true; if (member.getValue() instanceof ClassExpression) { ClassExpression classExpression = (ClassExpression) member.getValue(); Class<?> typeClass = classExpression.getType().isResolved() ? classExpression.getType().redirect().getTypeClass() : null; if (typeClass != null && GeneratedClosure.class.isAssignableFrom(typeClass)) return true; } } return false; }
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; }
public void visit(GroovyCodeVisitor visitor) { AnnotationNode node = (AnnotationNode) getValue(); Map<String, Expression> attrs = node.getMembers(); for (Expression expr : attrs.values()) { expr.visit(visitor); } super.visit(visitor); }
private static Visibility getVisForAnnotation(Class<? extends AnnotatedNode> clazz, AnnotationNode visAnno, String visId) { Map<String, Expression> visMembers = visAnno.getMembers(); if (visMembers == null) return Visibility.UNDEFINED; String id = getMemberStringValue(visAnno, "id", null); if ((id == null && visId != null) || (id != null && !id.equals(visId))) return Visibility.UNDEFINED; Visibility vis = null; if (clazz.equals(ConstructorNode.class)) { vis = getVisibility(visMembers.get("constructor")); } else if (clazz.equals(MethodNode.class)) { vis = getVisibility(visMembers.get("method")); } else if (clazz.equals(ClassNode.class)) { vis = getVisibility(visMembers.get("type")); } if (vis == null || vis == Visibility.UNDEFINED) { vis = getVisibility(visMembers.get("value")); } return vis; }
private static void mergeParameters(AnnotationNode to, AnnotationNode from) { for (String name : from.getMembers().keySet()) { if (to.getMember(name) == null) { to.setMember(name, from.getMember(name)); } } }
private static Expression transformInlineConstants(final Expression exp) { if (exp instanceof AnnotationConstantExpression) { ConstantExpression ce = (ConstantExpression) exp; if (ce.getValue() instanceof AnnotationNode) { // replicate a little bit of AnnotationVisitor here // because we can't wait until later to do this AnnotationNode an = (AnnotationNode) ce.getValue(); for (Map.Entry<String, Expression> member : an.getMembers().entrySet()) { member.setValue(transformInlineConstants(member.getValue())); } } } else { return ExpressionUtils.transformInlineConstants(exp); } return exp; }
Set<String> unusedNames = new HashSet<String>(aliasAnnotationUsage.getMembers().keySet()); for (String name : aliasAnnotationUsage.getMembers().keySet()) { if (an.getClassNode().hasMethod(name, Parameter.EMPTY_ARRAY)) { unusedNames.remove(name);
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); } }
private boolean checkIfMandatoryAnnotationValuesPassed(AnnotationNode node) { boolean ok = true; Map attributes = node.getMembers(); ClassNode classNode = node.getClassNode(); for (MethodNode mn : classNode.getMethods()) { String methodName = mn.getName(); // if the annotation attribute has a default, getCode() returns a ReturnStatement with the default value if (mn.getCode() == null && !attributes.containsKey(methodName)) { addError("No explicit/default value found for annotation attribute '" + methodName + "'", node); ok = false; } } return ok; }
for (Map.Entry<String, Expression> member : annotation.getMembers().entrySet()) { newAnnotation.addMember(member.getKey(), member.getValue());
public void visitAnnotations(AnnotatedNode node) { List<AnnotationNode> annotations = node.getAnnotations(); if (annotations.isEmpty()) return; Map<String, AnnotationNode> tmpAnnotations = new HashMap<String, AnnotationNode>(); ClassNode annType; for (AnnotationNode an : annotations) { // skip built-in properties if (an.isBuiltIn()) continue; annType = an.getClassNode(); resolveOrFail(annType, ", unable to find class for annotation", an); for (Map.Entry<String, Expression> member : an.getMembers().entrySet()) { Expression newValue = transform(member.getValue()); Expression adjusted = transformInlineConstants(newValue); member.setValue(adjusted); checkAnnotationMemberValue(adjusted); } if (annType.isResolved()) { Class annTypeClass = annType.getTypeClass(); Retention retAnn = (Retention) annTypeClass.getAnnotation(Retention.class); if (retAnn != null && retAnn.value().equals(RetentionPolicy.RUNTIME) && !isRepeatable(annTypeClass)) { // remember runtime/non-repeatable annos (auto collecting of Repeatable annotations is handled elsewhere) AnnotationNode anyPrevAnnNode = tmpAnnotations.put(annTypeClass.getName(), an); if (anyPrevAnnNode != null) { addError("Cannot specify duplicate annotation on the same member : " + annType.getName(), an); } } } } }
public AnnotationNode visit(AnnotationNode node) { this.annotation = node; this.reportClass = node.getClassNode(); if (!isValidAnnotationClass(node.getClassNode())) { addError("class " + node.getClassNode().getName() + " is not an annotation"); return node; } // check if values have been passed for all annotation attributes that don't have defaults if (!checkIfMandatoryAnnotationValuesPassed(node)) { return node; } // if enum constants have been used, check if they are all valid if (!checkIfValidEnumConstsAreUsed(node)) { return node; } Map<String, Expression> attributes = node.getMembers(); for (Map.Entry<String, Expression> entry : attributes.entrySet()) { String attrName = entry.getKey(); ClassNode attrType = getAttributeType(node, attrName); Expression attrExpr = transformInlineConstants(entry.getValue(), attrType); entry.setValue(attrExpr); visitExpression(attrName, attrExpr, attrType); } VMPluginFactory.getPlugin().configureAnnotation(node); return this.annotation; }
public void visit(ASTNode[] nodes, SourceUnit source) { AnnotationNode annotationInformation = (AnnotationNode) nodes[0]; Map<String,Expression> members = annotationInformation.getMembers(); Expression extensions = members.get("extensions"); AnnotatedNode node = (AnnotatedNode) nodes[1]; StaticTypeCheckingVisitor visitor = null; if (node instanceof ClassNode) { ClassNode classNode = (ClassNode) node; visitor = newVisitor(source, classNode); visitor.setCompilationUnit(compilationUnit); addTypeCheckingExtensions(visitor, extensions); visitor.initialize(); visitor.visitClass(classNode); } else if (node instanceof MethodNode) { MethodNode methodNode = (MethodNode) node; visitor = newVisitor(source, methodNode.getDeclaringClass()); visitor.setCompilationUnit(compilationUnit); addTypeCheckingExtensions(visitor, extensions); visitor.setMethodsToBeVisited(Collections.singleton(methodNode)); visitor.initialize(); visitor.visitMethod(methodNode); } else { source.addError(new SyntaxException(STATIC_ERROR_PREFIX + "Unimplemented node type", node.getLineNumber(), node.getColumnNumber(), node.getLastLineNumber(), node.getLastColumnNumber())); } if (visitor != null) { visitor.performSecondPass(); } }
AnnotatedNode node = (AnnotatedNode) nodes[1]; StaticTypeCheckingVisitor visitor = null; Map<String,Expression> members = annotationInformation.getMembers(); Expression extensions = members.get("extensions"); if (node instanceof ClassNode) {