Refine search
/** * Convenience method to see if an annotated node is {@code @Vetoable}. * * @param node the node to check * @return true if the node is constrained */ public static boolean hasVetoableAnnotation(AnnotatedNode node) { for (AnnotationNode annotation : node.getAnnotations()) { if (constrainedClassNode.equals(annotation.getClassNode())) { return true; } } return false; }
ClassNode repeatable = null; AnnotationNode repeatee = next.getValue().get(0); List<AnnotationNode> repeateeAnnotations = repeatee.getClassNode().getAnnotations(); for (AnnotationNode anno : repeateeAnnotations) { ClassNode annoClassNode = anno.getClassNode(); if (annoClassNode.getName().equals("java.lang.annotation.Repeatable")) { Expression value = anno.getMember("value"); if (value instanceof ClassExpression) { ClassExpression ce = (ClassExpression) value; if (ce.getType() != null && ce.getType().isAnnotationDefinition()) { repeatable = ce.getType(); break; collector.addMember("value", new ListExpression(annos)); node.addAnnotation(collector); node.getAnnotations().removeAll(next.getValue());
private void addListenerToProperty(SourceUnit source, AnnotationNode node, AnnotatedNode parent) { ClassNode declaringClass = parent.getDeclaringClass(); FieldNode field = ((FieldNode) parent); String fieldName = field.getName(); for (PropertyNode propertyNode : declaringClass.getProperties()) { boolean bindable = BindableASTTransformation.hasBindableAnnotation(parent) || BindableASTTransformation.hasBindableAnnotation(parent.getDeclaringClass()); if (propertyNode.getName().equals(fieldName)) { if (field.isStatic()) { //noinspection ThrowableInstanceNeverThrown source.getErrorCollector().addErrorAndContinue(new SyntaxErrorMessage( new SyntaxException("@groovy.beans.Vetoable cannot annotate a static property.", node.getLineNumber(), node.getColumnNumber(), node.getLastLineNumber(), node.getLastColumnNumber()), source)); } else { createListenerSetter(source, bindable, declaringClass, propertyNode); } return; } } //noinspection ThrowableInstanceNeverThrown source.getErrorCollector().addErrorAndContinue(new SyntaxErrorMessage( new SyntaxException("@groovy.beans.Vetoable must be on a property, not a field. Try removing the private, protected, or public modifier.", node.getLineNumber(), node.getColumnNumber(), node.getLastLineNumber(), node.getLastColumnNumber()), source)); }
public static boolean isStaticallyCompiled(AnnotatedNode node) { if (node.getNodeMetaData(STATIC_COMPILE_NODE)!=null) return (Boolean)node.getNodeMetaData(STATIC_COMPILE_NODE); if (node instanceof MethodNode) { return isStaticallyCompiled(node.getDeclaringClass()); } if (node instanceof InnerClassNode) { return isStaticallyCompiled(((InnerClassNode)node).getOuterClass()); } return false; }
private void addError(AnnotatedNode exp, String msg) { sourceUnit.getErrorCollector().addErrorAndContinue( new SyntaxErrorMessage( new SyntaxException(msg + '\n', exp.getLineNumber(), exp.getColumnNumber(), exp.getLastLineNumber(), exp.getLastColumnNumber()), sourceUnit) ); }
private void handle(String name, AnnotatedNode annotated) { for (AnnotationNode ann : (List<AnnotationNode>)annotated.getAnnotations()) { if (ann.getClassNode().getName().endsWith(Argument.class.getName())) { Expression expr = ann.getMember("name"); if (expr == null) { expr = new ConstantExpression(name); ann.setMember("name", expr); } } } } }
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; }
List<AnnotationNode> annotationList = annotatedNode.getAnnotations(); for (AnnotationNode annotation : annotationList) { List<AnnotationNode> annotations = annotation.getClassNode().getAnnotations(AbstractASTTransformation.RETENTION_CLASSNODE); if (annotations.isEmpty()) continue; Expression valueExpression = retentionPolicyAnnotation.getMember("value"); if (!(valueExpression instanceof PropertyExpression)) continue; AnnotationNode newAnnotation = new AnnotationNode(annotation.getClassNode()); for (Map.Entry<String, Expression> member : annotation.getMembers().entrySet()) { newAnnotation.addMember(member.getKey(), member.getValue());
private void changeBaseScriptType(final SourceUnit source, final AnnotatedNode parent, final ClassNode cNode, final ClassNode baseScriptType, final AnnotationNode node) { if (!cNode.isScriptBody()) { addError("Annotation " + MY_TYPE_NAME + " can only be used within a Script.", parent); return; if (!baseScriptType.isScript()) { addError("Declared type " + baseScriptType + " does not extend groovy.lang.Script class!", parent); return; List<AnnotationNode> annotations = parent.getAnnotations(COMMAND_TYPE); if (cNode.getAnnotations(COMMAND_TYPE).isEmpty()) { // #388 prevent "Duplicate annotation for class" AnnotationFormatError cNode.addAnnotations(annotations);
public void visit(ASTNode[] nodes, SourceUnit source) { init(nodes, source); AnnotatedNode parent = (AnnotatedNode) nodes[1]; AnnotationNode node = (AnnotationNode) nodes[0]; boolean legacyMode = LEGACY_TYPE_NAME.equals(node.getClassNode().getName()); if (!MY_TYPE.equals(node.getClassNode()) && !legacyMode) return; Expression value = node.getMember("value"); if (parent instanceof ClassNode) { List<groovy.transform.PackageScopeTarget> targets; if (value == null) targets = Collections.singletonList(legacyMode ? PackageScopeTarget.FIELDS : PackageScopeTarget.CLASS); else targets = determineTargets(value); visitClassNode((ClassNode) parent, targets); parent.getAnnotations(); } else { if (value != null) { addError("Error during " + MY_TYPE_NAME + " processing: " + TARGET_CLASS_NAME + " only allowed at class level.", parent); return; } if (parent instanceof MethodNode) { visitMethodNode((MethodNode) parent); } else if (parent instanceof FieldNode) { visitFieldNode((FieldNode) parent); } } }
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); } } } } }
protected void visitAnnotations(AnnotatedNode node, int target) { if (node.getAnnotations().isEmpty()) { return; this.currentClass.setAnnotated(true); if (!isAnnotationCompatible()) { addError("Annotations are not supported in the current runtime. " + JVM_ERROR_MESSAGE, node); for (AnnotationNode unvisited : node.getAnnotations()) { AnnotationNode visited = visitAnnotation(unvisited); String name = visited.getClassNode().getName(); if (visited.hasRuntimeRetention()) { List<AnnotationNode> seen = runtimeAnnotations.get(name); if (seen == null) { if (!isTargetAnnotation && !visited.isTargetAllowed(target)) { addError("Annotation @" + name + " is not allowed on element " + AnnotationNode.targetToName(target), visited);
AnnotatedNode annotatedNode = (AnnotatedNode) nodes[1]; if (!type().equals(node.getClassNode())) { internalError("Transformation called from wrong annotation: " + node.getClassNode().getName()); } else if (!applyToAllMembers && annotatedNode instanceof MethodNode) { this.visitMethod((MethodNode) annotatedNode); this.visitClass(annotatedNode.getDeclaringClass()); } else if (!applyToAllMembers && annotatedNode instanceof FieldNode) { this.visitField((FieldNode) annotatedNode); this.visitClass(annotatedNode.getDeclaringClass()); } else if (!applyToAllMembers && annotatedNode instanceof DeclarationExpression) { this.visitDeclarationExpression((DeclarationExpression) annotatedNode); this.visitClass(annotatedNode.getDeclaringClass()); } else { final List<ClassNode> classes = tree.getClasses(); for (ClassNode classNode : classes) { if (classNode.isScript()) { visitClass(classNode);
public List<AnnotationNode> getAnnotations(ClassNode type) { if (redirect!=null) return redirect.getAnnotations(type); lazyClassInit(); return super.getAnnotations(type); }
@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); }
private void visitAnnotationsOnNode(AnnotatedNode node, ClassNode owner) { for (AnnotationNode annotationNode : node.getAnnotations()) { Class<? extends ASTTransformation> transformationClass = transformations.get(annotationNode.getClassNode().getName()); if (transformationClass == null) continue; GroovyASTTransformation annotation = transformationClass.getAnnotation(GroovyASTTransformation.class); if (annotation == null) continue; // Set<ASTNode> nodes = owner.getTransforms(annotation.phase()).get(transformationClass); // if (nodes != null && !nodes.isEmpty()) continue; owner.addTransform(transformationClass, annotationNode); } }
private void disableGrabResolvers(List<? extends AnnotatedNode> nodes) { for (AnnotatedNode classNode : nodes) { List<AnnotationNode> annotations = classNode.getAnnotations(); for (AnnotationNode node : new ArrayList<>(annotations)) { if (node.getClassNode().getNameWithoutPackage() .equals("GrabResolver")) { node.setMember("initClass", new ConstantExpression(false)); } } } }
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 addAnnotations(List annotations) { for (Iterator iter = annotations.iterator(); iter.hasNext();) { AnnotationNode node = (AnnotationNode) iter.next(); addAnnotation(node.getClassNode().getName(), node); } }
@Override public void visitAnnotations(AnnotatedNode node) { super.visitAnnotations(node); for (AnnotationNode an : node.getAnnotations()) { addToCache(an.getClassNode()); } } @Override