if (!isAnnotationCompatible()) { addError("Annotations are not supported in the current runtime. " + JVM_ERROR_MESSAGE, node); return; AnnotationNode visited = visitAnnotation(unvisited); String name = visited.getClassNode().getName(); if (visited.hasRuntimeRetention()) { addError("Annotation @" + name + " is not allowed on element " + AnnotationNode.targetToName(target), visited); visitDeprecation(node, visited); visitOverride(node, visited); checkForDuplicateAnnotations(node, runtimeAnnotations);
public void visitField(FieldNode node) { visitAnnotations(node, AnnotationNode.FIELD_TARGET); }
public void visitConstructor(ConstructorNode node) { visitConstructorOrMethod(node, AnnotationNode.CONSTRUCTOR_TARGET); }
private void visitOverride(AnnotatedNode node, AnnotationNode visited) { ClassNode annotationClassNode = visited.getClassNode(); if (annotationClassNode.isResolved() && annotationClassNode.getName().equals("java.lang.Override")) { if (node instanceof MethodNode && !Boolean.TRUE.equals(node.getNodeMetaData(Verifier.DEFAULT_PARAMETER_GENERATED))) { boolean override = false; MethodNode origMethod = (MethodNode) node; ClassNode cNode = origMethod.getDeclaringClass(); if (origMethod.hasDefaultValue()) { List<MethodNode> variants = cNode.getDeclaredMethods(origMethod.getName()); for (MethodNode m : variants) { if (m.getAnnotations().contains(visited) && isOverrideMethod(m)) { override = true; break; } } } else { override = isOverrideMethod(origMethod); } if (!override) { addError("Method '" + origMethod.getName() + "' from class '" + cNode.getName() + "' does not override " + "method from its superclass or interfaces but is annotated with @Override.", visited); } } } }
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); return; } Collection annotations = node.getAnnotations(); for (Iterator it = annotations.iterator(); it.hasNext();) { AnnotationNode annotation = visitAnnotation((AnnotationNode) it.next()); boolean isTargetAnnotation = annotation.getClassNode().isResolved() && annotation.getClassNode().getTypeClass() == Target.class; // Check if the annotation target is correct, unless it's the target annotating an annotation definition // defining on which target elements the annotation applies if (!isTargetAnnotation && !annotation.isTargetAllowed(target)) { addError("Annotation @" + annotation.getClassNode().getName() + " is not allowed on element " + AnnotationNode.targetToName(target), annotation); } visitDeprecation(node, annotation); } }
completionVerifier.visitClass(classNode); ExtendedVerifier xverifier = new ExtendedVerifier(source); xverifier.visitClass(classNode);
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); return; } Collection annotations = node.getAnnotations().values(); for(Iterator it = annotations.iterator(); it.hasNext(); ) { AnnotationNode an = (AnnotationNode) it.next(); AnnotationNode annotation = visitAnnotation(an); if(!annotation.isValid()) { return; } if(!annotation.isTargetAllowed(target)) { addError("Annotation @" + annotation.getClassNode().getName() + " is not allowed on element " + AnnotationNode.targetToName(target), annotation); } } }
private void visitConstructorOrMethod(MethodNode node, int methodTarget) { visitAnnotations(node, methodTarget); for (int i = 0; i < node.getParameters().length; i++) { Parameter parameter = node.getParameters()[i]; visitAnnotations(parameter, AnnotationNode.PARAMETER_TARGET); } if (this.currentClass.isAnnotationDefinition() && !node.isStaticConstructor()) { ErrorCollector errorCollector = new ErrorCollector(this.source.getConfiguration()); AnnotationVisitor visitor = new AnnotationVisitor(this.source, errorCollector); visitor.setReportClass(currentClass); visitor.checkReturnType(node.getReturnType(), node); if (node.getParameters().length > 0) { addError("Annotation members may not have parameters.", node.getParameters()[0]); } if (node.getExceptions().length > 0) { addError("Annotation members may not have a throws clause.", node.getExceptions()[0]); } ReturnStatement code = (ReturnStatement) node.getCode(); if (code != null) { visitor.visitExpression(node.getName(), code.getExpression(), node.getReturnType()); visitor.checkCircularReference(currentClass, node.getReturnType(), code.getExpression()); } this.source.getErrorCollector().addCollectorContents(errorCollector); } Statement code = node.getCode(); if (code != null) { code.visit(this); } }
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); return; } for (AnnotationNode unvisited : node.getAnnotations()) { AnnotationNode visited = visitAnnotation(unvisited); boolean isTargetAnnotation = visited.getClassNode().isResolved() && visited.getClassNode().getName().equals("java.lang.annotation.Target"); // Check if the annotation target is correct, unless it's the target annotating an annotation definition // defining on which target elements the annotation applies if (!isTargetAnnotation && !visited.isTargetAllowed(target)) { addError("Annotation @" + visited.getClassNode().getName() + " is not allowed on element " + AnnotationNode.targetToName(target), visited); } visitDeprecation(node, visited); } }
completionVerifier.visitClass(classNode); ExtendedVerifier xverifier = new ExtendedVerifier(source); xverifier.visitClass(classNode);
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); return; } Collection annotations = node.getAnnotations(); for (Iterator it = annotations.iterator(); it.hasNext();) { AnnotationNode annotation = visitAnnotation((AnnotationNode) it.next()); boolean isTargetAnnotation = annotation.getClassNode().isResolved() && annotation.getClassNode().getTypeClass() == Target.class; // Check if the annotation target is correct, unless it's the target annotating an annotation definition // defining on which target elements the annotation applies if (!isTargetAnnotation && !annotation.isTargetAllowed(target)) { addError("Annotation @" + annotation.getClassNode().getName() + " is not allowed on element " + AnnotationNode.targetToName(target), annotation); } } }
private void visitConstructorOrMethod(MethodNode node, int methodTarget) { visitAnnotations(node, methodTarget); for (int i = 0; i < node.getParameters().length; i++) { Parameter parameter = node.getParameters()[i]; visitAnnotations(parameter, AnnotationNode.PARAMETER_TARGET); } if (this.currentClass.isAnnotationDefinition()) { ErrorCollector errorCollector = new ErrorCollector(this.source.getConfiguration()); AnnotationVisitor visitor = new AnnotationVisitor(this.source, errorCollector); visitor.setReportClass(currentClass); visitor.checkReturnType(node.getReturnType(),node); if (node.getParameters().length>0) { addError ("Annotation members may not have parameters.",node.getParameters()[0]); } if (node.getExceptions().length>0) { addError ("Annotation members may not have a throws clause.",node.getExceptions()[0]); } ReturnStatement code = (ReturnStatement) node.getCode(); if (code!=null) { visitor.visitExpression(node.getName(),code.getExpression(),node.getReturnType()); visitor.checkcircularReference(currentClass,node.getReturnType(),code.getExpression()); } this.source.getErrorCollector().addCollectorContents(errorCollector); } }
completionVerifier.visitClass(classNode); ExtendedVerifier xverifier = new ExtendedVerifier(source); xverifier.visitClass(classNode);
public void visitMethod(MethodNode node) { visitAnnotations(node, AnnotationNode.METHOD_TARGET); for (int i = 0; i < node.getParameters().length; i++) { Parameter parameter = node.getParameters()[i]; visitAnnotations(parameter, AnnotationNode.PARAMETER_TARGET); } if (this.currentClass.isAnnotationDefinition()) { ErrorCollector errorCollector = new ErrorCollector(this.source.getConfiguration()); AnnotationVisitor visitor = new AnnotationVisitor(this.source, errorCollector); visitor.setReportClass(currentClass); visitor.checkReturnType(node.getReturnType(),node); if (node.getParameters().length>0) { addError ("Annotation members may not have parameters.",node.getParameters()[0]); } if (node.getExceptions().length>0) { addError ("Annotation members may not have a throws clause.",node.getExceptions()[0]); } ReturnStatement code = (ReturnStatement) node.getCode(); if (code!=null) { visitor.visitExpression(node.getName(),code.getExpression(),node.getReturnType()); visitor.checkcircularReference(currentClass,node.getReturnType(),code.getExpression()); } this.source.getErrorCollector().addCollectorContents(errorCollector); } }
@Override public void visitDeclarationExpression(DeclarationExpression expression) { visitAnnotations(expression, AnnotationNode.LOCAL_VARIABLE_TARGET); }
public void visitMethod(MethodNode node) { visitConstructorOrMethod(node, AnnotationNode.METHOD_TARGET); }
completionVerifier.visitClass(classNode); ExtendedVerifier xverifier = new ExtendedVerifier(source); xverifier.visitClass(classNode);
private void visitConstructorOrMethod(MethodNode node, int methodTarget) { visitAnnotations(node, methodTarget); for (int i = 0; i < node.getParameters().length; i++) { Parameter parameter = node.getParameters()[i]; visitAnnotations(parameter, AnnotationNode.PARAMETER_TARGET); } if (this.currentClass.isAnnotationDefinition() && !node.isStaticConstructor()) { ErrorCollector errorCollector = new ErrorCollector(this.source.getConfiguration()); AnnotationVisitor visitor = new AnnotationVisitor(this.source, errorCollector); visitor.setReportClass(currentClass); visitor.checkReturnType(node.getReturnType(), node); if (node.getParameters().length > 0) { addError("Annotation members may not have parameters.", node.getParameters()[0]); } if (node.getExceptions().length > 0) { addError("Annotation members may not have a throws clause.", node.getExceptions()[0]); } ReturnStatement code = (ReturnStatement) node.getCode(); if (code != null) { visitor.visitExpression(node.getName(), code.getExpression(), node.getReturnType()); visitor.checkCircularReference(currentClass, node.getReturnType(), code.getExpression()); } this.source.getErrorCollector().addCollectorContents(errorCollector); } }
public void visitClass(ClassNode node) { AnnotationConstantsVisitor acv = new AnnotationConstantsVisitor(); acv.visitClass(node, this.source); this.currentClass = node; if (node.isAnnotationDefinition()) { visitAnnotations(node, AnnotationNode.ANNOTATION_TARGET); } else { visitAnnotations(node, AnnotationNode.TYPE_TARGET); } PackageNode packageNode = node.getPackage(); if (packageNode != null) { visitAnnotations(packageNode, AnnotationNode.PACKAGE_TARGET); } node.visitContents(this); }
public void visitConstructor(ConstructorNode node) { visitConstructorOrMethod(node, AnnotationNode.CONSTRUCTOR_TARGET); }