private List<StereotypesProvider> getStereotypesProviders(ProcessingEnvironment env) { List<StereotypesProvider> result = new ArrayList<>(); TypeHelper typeHelper = new TypeHelper(env); result.add(new IndexedStereotypesProvider(typeHelper)); result.add(new StandardStereotypesProvider(typeHelper)); result.add(new PackageInfoStereotypesProvider()); return result; }
private void collectStereotypesOnAnnotations(Set<Element> seen, Set<String> stereotypes, Element element) { for (AnnotationMirror annotation : this.typeHelper.getAllAnnotationMirrors(element)) { Element next = collectStereotypes(seen, stereotypes, element, annotation); if (next != null) { collectStereotypesOnAnnotations(seen, stereotypes, next); } } }
@Override public Set<String> getStereotypes(Element element) { Set<String> stereotypes = new LinkedHashSet<>(); ElementKind kind = element.getKind(); if (kind != ElementKind.CLASS && kind != ElementKind.INTERFACE) { return stereotypes; } Set<Element> seen = new HashSet<>(); collectStereotypesOnAnnotations(seen, stereotypes, element); seen = new HashSet<>(); collectStereotypesOnTypes(seen, stereotypes, element); return stereotypes; }
private Element collectStereotypes(Set<Element> seen, Set<String> stereotypes, Element element, AnnotationMirror annotation) { if (isIndexedAnnotation(annotation)) { stereotypes.add(this.typeHelper.getType(element)); } return getCandidateAnnotationElement(seen, annotation); }
private void collectStereotypesOnTypes(Set<Element> seen, Set<String> stereotypes, Element type) { if (!seen.contains(type)) { seen.add(type); if (isAnnotatedWithIndexed(type)) { stereotypes.add(this.typeHelper.getType(type)); } Element superClass = this.typeHelper.getSuperClass(type); if (superClass != null) { collectStereotypesOnTypes(seen, stereotypes, superClass); } this.typeHelper.getDirectInterfaces(type).forEach( i -> collectStereotypesOnTypes(seen, stereotypes, i)); } }
private boolean isAnnotatedWithIndexed(Element type) { for (AnnotationMirror annotation : type.getAnnotationMirrors()) { if (isIndexedAnnotation(annotation)) { return true; } } return false; }
private Element collectStereotypes(Set<Element> seen, Set<String> stereotypes, Element element, AnnotationMirror annotation) { if (isIndexedAnnotation(annotation)) { stereotypes.add(this.typeHelper.getType(element)); } return getCandidateAnnotationElement(seen, annotation); }
private void collectStereotypesOnTypes(Set<Element> seen, Set<String> stereotypes, Element type) { if (!seen.contains(type)) { seen.add(type); if (isAnnotatedWithIndexed(type)) { stereotypes.add(this.typeHelper.getType(type)); } Element superClass = this.typeHelper.getSuperClass(type); if (superClass != null) { collectStereotypesOnTypes(seen, stereotypes, superClass); } this.typeHelper.getDirectInterfaces(type).forEach( i -> collectStereotypesOnTypes(seen, stereotypes, i)); } }
private Element getCandidateAnnotationElement(Set<Element> seen, AnnotationMirror annotation) { Element element = annotation.getAnnotationType().asElement(); if (seen.contains(element)) { return null; } // We need to visit all indexed annotations. if (!isIndexedAnnotation(annotation)) { seen.add(element); } return (!element.toString().startsWith("java.lang") ? element : null); }
private void collectStereotypesOnAnnotations(Set<Element> seen, Set<String> stereotypes, Element element) { for (AnnotationMirror annotation : this.typeHelper.getAllAnnotationMirrors(element)) { Element next = collectStereotypes(seen, stereotypes, element, annotation); if (next != null) { collectStereotypesOnAnnotations(seen, stereotypes, next); } } }
@Override public Set<String> getStereotypes(Element element) { Set<String> stereotypes = new LinkedHashSet<>(); ElementKind kind = element.getKind(); if (kind != ElementKind.CLASS && kind != ElementKind.INTERFACE) { return stereotypes; } Set<Element> seen = new HashSet<>(); collectStereotypesOnAnnotations(seen, stereotypes, element); seen = new HashSet<>(); collectStereotypesOnTypes(seen, stereotypes, element); return stereotypes; }
private boolean isAnnotatedWithIndexed(Element type) { for (AnnotationMirror annotation : type.getAnnotationMirrors()) { if (isIndexedAnnotation(annotation)) { return true; } } return false; }
private List<StereotypesProvider> getStereotypesProviders(ProcessingEnvironment env) { List<StereotypesProvider> result = new ArrayList<>(); TypeHelper typeHelper = new TypeHelper(env); result.add(new IndexedStereotypesProvider(typeHelper)); result.add(new StandardStereotypesProvider(typeHelper)); result.add(new PackageInfoStereotypesProvider()); return result; }
private Element getCandidateAnnotationElement(Set<Element> seen, AnnotationMirror annotation) { Element element = annotation.getAnnotationType().asElement(); if (seen.contains(element)) { return null; } // We need to visit all indexed annotations. if (!isIndexedAnnotation(annotation)) { seen.add(element); } return (!element.toString().startsWith("java.lang") ? element : null); }