Advertisement
Guest User

Untitled

a guest
Apr 6th, 2020
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.33 KB | None | 0 0
  1. @SupportedAnnotationTypes("*")
  2. @SupportedSourceVersion(SourceVersion.RELEASE_8)
  3. public class AllProcessor extends AbstractProcessor {
  4.     public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
  5.  
  6.         Set<? extends Element> rootElements = roundEnv.getRootElements();
  7.         for (TypeElement type : ElementFilter.typesIn(rootElements)) {
  8.             checkConstructors(type);
  9.         }
  10.         return false;
  11.     }
  12.  
  13.     private void checkConstructors(TypeElement type) {
  14.         boolean pubNonArgConstr = false;
  15.         for (ExecutableElement cons : ElementFilter.constructorsIn(type.getEnclosedElements())) {
  16.             boolean publicConstructor = cons.getModifiers().contains(Modifier.PUBLIC);
  17.             String docComment = processingEnv.getElementUtils().getDocComment(cons);
  18.             if (publicConstructor && docComment == null) {
  19.                 processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "public constructor must has JavaDoc: ", cons);
  20.             }
  21.             if (cons.getParameters().isEmpty() && publicConstructor) {
  22.                 pubNonArgConstr = true;
  23.             }
  24.         }
  25.         if (!pubNonArgConstr) {
  26.             processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "is missing a public default constructor: ", type);
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement