/** * Create a new {@code MetadataProcessor} instance. * @param processingEnvironment the processing environment of the build * @param previousMetadata any previous metadata or {@code null} */ public MetadataCollector(ProcessingEnvironment processingEnvironment, CandidateComponentsMetadata previousMetadata) { this.processingEnvironment = processingEnvironment; this.previousMetadata = previousMetadata; this.typeHelper = new TypeHelper(processingEnvironment); }
@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; } for (AnnotationMirror annotation : this.typeHelper.getAllAnnotationMirrors(element)) { String type = this.typeHelper.getType(annotation); if (type.startsWith("javax.")) { stereotypes.add(type); } } return stereotypes; }
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 void markAsProcessed(Element element) { if (element instanceof TypeElement) { this.processedSourceTypes.add(this.typeHelper.getType(element)); } }
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); } } }
public String getType(TypeMirror type) { if (type == null) { return null; } if (type instanceof DeclaredType) { DeclaredType declaredType = (DeclaredType) type; Element enclosingElement = declaredType.asElement().getEnclosingElement(); if (enclosingElement != null && enclosingElement instanceof TypeElement) { return getQualifiedName(enclosingElement) + "$" + declaredType.asElement().getSimpleName().toString(); } else { return getQualifiedName(declaredType.asElement()); } } return type.toString(); }
public String getType(AnnotationMirror annotation) { return getType(annotation != null ? annotation.getAnnotationType() : 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); } } }
public String getType(TypeMirror type) { if (type == null) { return null; } if (type instanceof DeclaredType) { DeclaredType declaredType = (DeclaredType) type; Element enclosingElement = declaredType.asElement().getEnclosingElement(); if (enclosingElement != null && enclosingElement instanceof TypeElement) { return getQualifiedName(enclosingElement) + "$" + declaredType.asElement().getSimpleName().toString(); } else { return getQualifiedName(declaredType.asElement()); } } return type.toString(); }
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)); } }
public String getType(Element element) { return getType(element != null ? element.asType() : null); }
@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; } for (AnnotationMirror annotation : this.typeHelper.getAllAnnotationMirrors(element)) { String type = this.typeHelper.getType(annotation); if (type.startsWith("javax.")) { stereotypes.add(type); } } return stereotypes; }
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 addMetadataFor(Element element) { Set<String> stereotypes = new LinkedHashSet<>(); this.stereotypesProviders.forEach(p -> stereotypes.addAll(p.getStereotypes(element))); if (!stereotypes.isEmpty()) { this.metadataCollector.add(new ItemMetadata(this.typeHelper.getType(element), stereotypes)); } }
@Override public synchronized void init(ProcessingEnvironment env) { this.stereotypesProviders = getStereotypesProviders(env); this.typeHelper = new TypeHelper(env); this.metadataStore = new MetadataStore(env); this.metadataCollector = new MetadataCollector(env, this.metadataStore.readMetadata()); }
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); }
/** * Create a new {@code MetadataProcessor} instance. * @param processingEnvironment the processing environment of the build * @param previousMetadata any previous metadata or {@code null} */ public MetadataCollector(ProcessingEnvironment processingEnvironment, CandidateComponentsMetadata previousMetadata) { this.processingEnvironment = processingEnvironment; this.previousMetadata = previousMetadata; this.typeHelper = new TypeHelper(processingEnvironment); }
private void markAsProcessed(Element element) { if (element instanceof TypeElement) { this.processedSourceTypes.add(this.typeHelper.getType(element)); } }
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; }
public String getType(Element element) { return getType(element != null ? element.asType() : null); }