private static AnnotationEntry findRequestMappingAnnotation(Method method) { for (AnnotationEntry annotationEntry : method.getAnnotationEntries()) { if (REQUEST_MAPPING_ANNOTATION_TYPE.equals(annotationEntry.getAnnotationType())) { return annotationEntry; } } return null; }
private boolean hasRequestMapping(JavaClass clazz) { Method[] methods = clazz.getMethods(); for (Method m: methods) { AnnotationEntry[] annotations = m.getAnnotationEntries(); for (AnnotationEntry ae: annotations) { if (REQUEST_MAPPING_ANNOTATION_TYPES.contains(ae.getAnnotationType())) { return true; } } } return false; }
private boolean differentAttributes(Method m1, Method m2) { if (m1.getAnnotationEntries().length > 0 || m2.getAnnotationEntries().length > 0) { return true; } int access1 = m1.getAccessFlags() & (Const.ACC_PRIVATE | Const.ACC_PROTECTED | Const.ACC_PUBLIC | Const.ACC_FINAL); int access2 = m2.getAccessFlags() & (Const.ACC_PRIVATE | Const.ACC_PROTECTED | Const.ACC_PUBLIC | Const.ACC_FINAL); m1.getAnnotationEntries(); if (access1 != access2) { return true; } if (!thrownExceptions(m1).equals(thrownExceptions(m2))) { return false; } return false; } }
@Override public void visitMethod(Method obj) { if (!obj.isPrivate() || obj.isSynthetic()) { return; } super.visitMethod(obj); String methodName = getMethodName(); if (!"writeReplace".equals(methodName) && !"readResolve".equals(methodName) && !"readObject".equals(methodName) && !"readObjectNoData".equals(methodName) && !"writeObject".equals(methodName) && methodName.indexOf("debug") == -1 && methodName.indexOf("Debug") == -1 && methodName.indexOf("trace") == -1 && methodName.indexOf("Trace") == -1 && !Const.CONSTRUCTOR_NAME.equals(methodName) && !Const.STATIC_INITIALIZER_NAME.equals(methodName)) { for(AnnotationEntry a : obj.getAnnotationEntries()) { String typeName = a.getAnnotationType(); if ("Ljavax/annotation/PostConstruct;".equals(typeName) || "Ljavax/annotation/PreDestroy;".equals(typeName)) { return; } } definedPrivateMethods.add(MethodAnnotation.fromVisitedMethod(this)); } }
@Override public void visitClassContext(ClassContext classContext) { JavaClass javaClass = classContext.getJavaClass(); method : for (Method m : javaClass.getMethods()) { for (AnnotationEntry ae : m.getAnnotationEntries()) { if (REQUEST_MAPPING_ANNOTATION_TYPES.contains(ae.getAnnotationType())) { bugReporter.reportBug(new BugInstance(this, SPRING_ENDPOINT_TYPE, Priorities.LOW_PRIORITY) // .addClassAndMethod(javaClass, m)); continue method; } } } }
@Override public void visitClassContext(ClassContext classContext) { JavaClass javaClass = classContext.getJavaClass(); for (Method m : javaClass.getMethods()) { for (AnnotationEntry ae : m.getAnnotationEntries()) { //Every method mark with @javax.jws.WebMethod is mark as an Endpoint if (ae.getAnnotationType().equals("Ljavax/jws/WebMethod;")) { bugReporter.reportBug(new BugInstance(this, JAXWS_ENDPOINT_TYPE, Priorities.LOW_PRIORITY) // .addClassAndMethod(javaClass, m)); } } } }
@Override public void visitClassContext(ClassContext classContext) { JavaClass javaClass = classContext.getJavaClass(); for (Method m : javaClass.getMethods()) { for (AnnotationEntry ae : m.getAnnotationEntries()) { //Every method mark with @javax.ws.rs.Path is mark as an Endpoint if (ae.getAnnotationType().equals("Ljavax/ws/rs/Path;")) { bugReporter.reportBug(new BugInstance(this, JAXRS_ENDPOINT_TYPE, Priorities.LOW_PRIORITY) // .addClassAndMethod(javaClass, m)); } } } }
public static boolean methodHasNullableAnnotation(Method m) { for (AnnotationEntry entry : m.getAnnotationEntries()) { String annotationType = entry.getAnnotationType(); if (NULLABLE_ANNOTATIONS.contains(annotationType)) { return true; } } return false; }
private static AnnotationEntry findRequestMappingAnnotation(Method method) { for (AnnotationEntry annotationEntry : method.getAnnotationEntries()) { if (REQUEST_MAPPING_ANNOTATION_TYPE.equals(annotationEntry.getAnnotationType())) { return annotationEntry; } } return null; }
private boolean isAssociationedWithAnnotations(Method m) { if (classHasAnnotation) { return true; } return !CollectionUtils.isEmpty(m.getAnnotationEntries()); }
private boolean hasRuntimeAnnotations(Method obj) { AnnotationEntry[] annotations = obj.getAnnotationEntries(); if (annotations != null) { for (AnnotationEntry entry : annotations) { if (entry.isRuntimeVisible()) { return true; } } } return false; }
private boolean isAssociationedWithAnnotations(Method m) { if (classHasAnnotation) { return true; } return !CollectionUtils.isEmpty(m.getAnnotationEntries()); }
private boolean hasRuntimeAnnotations(Method obj) { AnnotationEntry[] annotations = obj.getAnnotationEntries(); if (annotations != null) { for (AnnotationEntry entry : annotations) { if (entry.isRuntimeVisible()) { return true; } } } return false; }
public static boolean methodHasNullableAnnotation(Method m) { for (AnnotationEntry entry : m.getAnnotationEntries()) { String annotationType = entry.getAnnotationType(); if (NULLABLE_ANNOTATIONS.contains(annotationType)) { return true; } } return false; }
private boolean hasRequestMapping(JavaClass clazz) { Method[] methods = clazz.getMethods(); for (Method m: methods) { AnnotationEntry[] annotations = m.getAnnotationEntries(); for (AnnotationEntry ae: annotations) { if (REQUEST_MAPPING_ANNOTATION_TYPES.contains(ae.getAnnotationType())) { return true; } } } return false; }
@Override public void visitCode(Code obj) { Method m = getMethod(); for (AnnotationEntry annotation : m.getAnnotationEntries()) { String type = annotation.getAnnotationType(); if (type.startsWith("Lorg/junit/") || type.startsWith("Lorg/testng/")) { return; } } stack.resetForMethodEntry(this); super.visitCode(obj); }
@Override public void visitCode(Code obj) { Method m = getMethod(); for (AnnotationEntry annotation : m.getAnnotationEntries()) { String type = annotation.getAnnotationType(); if (type.startsWith("Lorg/junit/") || type.startsWith("Lorg/testng/")) { return; } } stack.resetForMethodEntry(this); super.visitCode(obj); }
@Override public void visitClassContext(ClassContext classContext) { JavaClass javaClass = classContext.getJavaClass(); method : for (Method m : javaClass.getMethods()) { for (AnnotationEntry ae : m.getAnnotationEntries()) { if (REQUEST_MAPPING_ANNOTATION_TYPES.contains(ae.getAnnotationType())) { bugReporter.reportBug(new BugInstance(this, SPRING_ENDPOINT_TYPE, Priorities.LOW_PRIORITY) // .addClassAndMethod(javaClass, m)); continue method; } } } }
@Override public void visitClassContext(ClassContext classContext) { JavaClass javaClass = classContext.getJavaClass(); for (Method m : javaClass.getMethods()) { for (AnnotationEntry ae : m.getAnnotationEntries()) { //Every method mark with @javax.ws.rs.Path is mark as an Endpoint if (ae.getAnnotationType().equals("Ljavax/ws/rs/Path;")) { bugReporter.reportBug(new BugInstance(this, JAXRS_ENDPOINT_TYPE, Priorities.LOW_PRIORITY) // .addClassAndMethod(javaClass, m)); } } } }
private void assertMethodAnnotations(final Method method, final int expectedNumberAnnotations, final int nExpectedArrayValues) { final String methodName= method.getName(); final AnnotationEntry[] annos= method.getAnnotationEntries(); assertEquals("For "+methodName, expectedNumberAnnotations, annos.length); if(expectedNumberAnnotations!=0) { assertArrayElementValue(nExpectedArrayValues, annos[0]); } }