public void checkcircularReference(ClassNode searchClass, ClassNode attrType,Expression startExp) { if (!isValidAnnotationClass(attrType)) return; AnnotationConstantExpression ace = (AnnotationConstantExpression) startExp; AnnotationNode annotationNode = (AnnotationNode) ace.getValue(); if (annotationNode.getClassNode().equals(searchClass)) { addError ("Cirecular reference discovered in "+searchClass.getName(),startExp); return; } ClassNode cn = annotationNode.getClassNode(); List methods = cn.getMethods(); for(Iterator it=methods.iterator(); it.hasNext();) { MethodNode method = (MethodNode) it.next(); if (method.getReturnType().equals(searchClass)) { addError ("Cirecular reference discovered in "+cn.getName(),startExp); } ReturnStatement code = (ReturnStatement) method.getCode(); if (code==null) continue; checkcircularReference(searchClass,method.getReturnType(),code.getExpression()); } }
public void checkcircularReference(ClassNode searchClass, ClassNode attrType,Expression startExp) { if (!isValidAnnotationClass(attrType)) return; AnnotationConstantExpression ace = (AnnotationConstantExpression) startExp; AnnotationNode annotationNode = (AnnotationNode) ace.getValue(); if (annotationNode.getClassNode().equals(searchClass)) { addError ("Cirecular reference discovered in "+searchClass.getName(),startExp); return; } ClassNode cn = annotationNode.getClassNode(); List methods = cn.getMethods(); for(Iterator it=methods.iterator(); it.hasNext();) { MethodNode method = (MethodNode) it.next(); if (method.getReturnType().equals(searchClass)) { addError ("Cirecular reference discovered in "+cn.getName(),startExp); } ReturnStatement code = (ReturnStatement) method.getCode(); if (code==null) continue; checkcircularReference(searchClass,method.getReturnType(),code.getExpression()); } }
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); } }
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); } }