Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @SupportedAnnotationTypes("*")
- @SupportedSourceVersion(SourceVersion.RELEASE_8)
- public class AllProcessor extends AbstractProcessor {
- public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
- Set<? extends Element> rootElements = roundEnv.getRootElements();
- for (TypeElement type : ElementFilter.typesIn(rootElements)) {
- checkConstructors(type);
- }
- return false;
- }
- private void checkConstructors(TypeElement type) {
- boolean pubNonArgConstr = false;
- for (ExecutableElement cons : ElementFilter.constructorsIn(type.getEnclosedElements())) {
- boolean publicConstructor = cons.getModifiers().contains(Modifier.PUBLIC);
- String docComment = processingEnv.getElementUtils().getDocComment(cons);
- if (publicConstructor && docComment == null) {
- processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "public constructor must has JavaDoc: ", cons);
- }
- if (cons.getParameters().isEmpty() && publicConstructor) {
- pubNonArgConstr = true;
- }
- }
- if (!pubNonArgConstr) {
- processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "is missing a public default constructor: ", type);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement