Java Code Examples for org.apache.bcel.classfile.Method#getAnnotationEntries()
The following examples show how to use
org.apache.bcel.classfile.Method#getAnnotationEntries() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FindUncalledPrivateMethods.java From spotbugs with GNU Lesser General Public License v2.1 | 6 votes |
@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)); } }
Example 2
Source File: UselessSubclassMethod.java From spotbugs with GNU Lesser General Public License v2.1 | 6 votes |
@SuppressWarnings("PMD.SimplifyBooleanReturns") 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; }
Example 3
Source File: SpringUnvalidatedRedirectDetector.java From Android_Code_Arbiter with GNU Lesser General Public License v3.0 | 5 votes |
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; }
Example 4
Source File: SpringCsrfUnrestrictedRequestMappingDetector.java From Android_Code_Arbiter with GNU Lesser General Public License v3.0 | 5 votes |
private static AnnotationEntry findRequestMappingAnnotation(Method method) { for (AnnotationEntry annotationEntry : method.getAnnotationEntries()) { if (REQUEST_MAPPING_ANNOTATION_TYPE.equals(annotationEntry.getAnnotationType())) { return annotationEntry; } } return null; }
Example 5
Source File: JaxWsEndpointDetector.java From Android_Code_Arbiter with GNU Lesser General Public License v3.0 | 5 votes |
@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)); } } } }
Example 6
Source File: SpringMvcEndpointDetector.java From Android_Code_Arbiter with GNU Lesser General Public License v3.0 | 5 votes |
@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; } } } }
Example 7
Source File: JaxRsEndpointDetector.java From Android_Code_Arbiter with GNU Lesser General Public License v3.0 | 5 votes |
@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)); } } } }
Example 8
Source File: GeneratingAnnotatedClassesTestCase.java From commons-bcel with Apache License 2.0 | 5 votes |
/** * Going further than the last test - when we reload the method back in, * let's change it (adding a new annotation) and then store that, read it * back in and verify both annotations are there ! */ public void testGenerateMethodLevelAnnotations2() throws ClassNotFoundException { // Create HelloWorld final ClassGen cg = createClassGen("HelloWorld"); final ConstantPoolGen cp = cg.getConstantPool(); final InstructionList il = new InstructionList(); buildClassContentsWithAnnotatedMethods(cg, cp, il); dumpClass(cg, "temp2", "HelloWorld.class"); final JavaClass jc2 = getClassFrom("temp2", "HelloWorld"); final ClassGen cg2 = new ClassGen(jc2); // Main method after reading the class back in final Method mainMethod1 = jc2.getMethods()[0]; assertTrue("The 'Method' should have one annotations but has " + mainMethod1.getAnnotationEntries().length, mainMethod1 .getAnnotationEntries().length == 1); final MethodGen mainMethod2 = new MethodGen(mainMethod1, cg2.getClassName(), cg2.getConstantPool()); assertTrue("The 'MethodGen' should have one annotations but has " + mainMethod2.getAnnotationEntries().length, mainMethod2 .getAnnotationEntries().length == 1); mainMethod2.addAnnotationEntry(createFruitAnnotation(cg2 .getConstantPool(), "Pear")); cg2.removeMethod(mainMethod1); cg2.addMethod(mainMethod2.getMethod()); dumpClass(cg2, "temp3", "HelloWorld.class"); final JavaClass jc3 = getClassFrom("temp3", "HelloWorld"); final ClassGen cg3 = new ClassGen(jc3); final Method mainMethod3 = cg3.getMethods()[1]; final int i = mainMethod3.getAnnotationEntries().length; assertTrue("The 'Method' should now have two annotations but has " + i, i == 2); assertTrue(wipe("temp2", "HelloWorld.class")); assertTrue(wipe("temp3", "HelloWorld.class")); }
Example 9
Source File: GeneratingAnnotatedClassesTestCase.java From commons-bcel with Apache License 2.0 | 5 votes |
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]); } }