use of javax.lang.model.element.Element in project spring-framework by spring-projects.
the class TypeHelper method getDirectInterfaces.
/**
* Return the interfaces that are <strong>directly</strong> implemented by the
* specified {@link Element} or an empty list if this {@code element} does not
* implement any interface.
*/
public List<Element> getDirectInterfaces(Element element) {
List<? extends TypeMirror> superTypes = this.types.directSupertypes(element.asType());
List<Element> directInterfaces = new ArrayList<>();
if (superTypes.size() > 1) {
// index 0 is the super class
for (int i = 1; i < superTypes.size(); i++) {
Element e = this.types.asElement(superTypes.get(i));
if (e != null) {
directInterfaces.add(e);
}
}
}
return directInterfaces;
}
use of javax.lang.model.element.Element in project spring-framework by spring-projects.
the class TypeHelper method getType.
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();
}
use of javax.lang.model.element.Element in project spring-framework by spring-projects.
the class IndexedStereotypesProvider method collectStereotypesOnTypes.
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));
}
}
use of javax.lang.model.element.Element in project spring-framework by spring-projects.
the class IndexedStereotypesProvider method getStereotypes.
@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;
}
use of javax.lang.model.element.Element in project spring-boot by spring-projects.
the class ConfigurationMetadataAnnotationProcessor method processNestedType.
private void processNestedType(String prefix, TypeElement element, ExecutableElement source, String name, ExecutableElement getter, VariableElement field, TypeMirror returnType) {
Element returnElement = this.processingEnv.getTypeUtils().asElement(returnType);
boolean isNested = isNested(returnElement, field, element);
AnnotationMirror annotation = getAnnotation(getter, configurationPropertiesAnnotation());
if (returnElement != null && returnElement instanceof TypeElement && annotation == null && isNested) {
String nestedPrefix = ConfigurationMetadata.nestedPrefix(prefix, name);
this.metadataCollector.add(ItemMetadata.newGroup(nestedPrefix, this.typeUtils.getQualifiedName(returnElement), this.typeUtils.getQualifiedName(element), (getter == null ? null : getter.toString())));
processTypeElement(nestedPrefix, (TypeElement) returnElement, source);
}
}
Aggregations