@Test public void testDeprecated() { JavaProjectBuilder builder = new JavaProjectBuilder(); File file = new File("src/test/java/com/ztianzeng/apidoc/utils/QdoxUtilsTest.java"); builder.addSourceTree(file); Collection<JavaClass> classes = builder.getClasses(); JavaClass aClass = classes.stream().findFirst().orElse(null); boolean present = QdoxUtils.getAnnotation(aClass, Deprecated.class).isPresent(); Assert.assertTrue(present); List<JavaMethod> methods = aClass.getMethods(); Assert.assertTrue(QdoxUtils.getAnnotation(methods.get(1), Deprecated.class).isPresent()); Assert.assertFalse(QdoxUtils.getAnnotation(methods.get(2), Deprecated.class).isPresent()); }
public static Optional<JavaAnnotation> getAnnotation(JavaAnnotatedElement annotatedElement, String name) { for (JavaAnnotation annotation : annotatedElement.getAnnotations()) { if (annotation.getType().isA(name)) { return Optional.of(annotation); } } return Optional.empty(); }
QdoxUtils { public static Optional<JavaAnnotation> getAnnotation(JavaAnnotatedElement annotatedElement, String name) { for (JavaAnnotation annotation : annotatedElement.getAnnotations()) { if (annotation.getType().isA(name)) { return Optional.of(annotation); } } return Optional.empty(); } }
QdoxUtils { public static Optional<JavaAnnotation> getAnnotation(JavaAnnotatedElement annotatedElement, String name) { for (JavaAnnotation annotation : annotatedElement.getAnnotations()) { if (annotation.getType().isA(name)) { return Optional.of(annotation); } } return Optional.empty(); } private  QdoxUtils(); }
QdoxUtils { public static Optional<JavaAnnotation> getAnnotation(JavaAnnotatedElement annotatedElement, String name) { for (JavaAnnotation annotation : annotatedElement.getAnnotations()) { if (annotation.getType().isA(name)) { return Optional.of(annotation); } } return Optional.empty(); } private  QdoxUtils(); static Optional<JavaAnnotation> getAnnotation(JavaAnnotatedElement annotatedElement, String name); static Optional<JavaAnnotation> getAnnotation(JavaAnnotatedElement annotatedElement, Type type); }
QdoxUtils { public static Optional<JavaAnnotation> getAnnotation(JavaAnnotatedElement annotatedElement, String name) { for (JavaAnnotation annotation : annotatedElement.getAnnotations()) { if (annotation.getType().isA(name)) { return Optional.of(annotation); } } return Optional.empty(); } private  QdoxUtils(); static Optional<JavaAnnotation> getAnnotation(JavaAnnotatedElement annotatedElement, String name); static Optional<JavaAnnotation> getAnnotation(JavaAnnotatedElement annotatedElement, Type type);  }