Search in sources :

Example 51 with Element

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;
}
Also used : Element(javax.lang.model.element.Element) TypeElement(javax.lang.model.element.TypeElement) ArrayList(java.util.ArrayList)

Example 52 with Element

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();
}
Also used : TypeElement(javax.lang.model.element.TypeElement) Element(javax.lang.model.element.Element) TypeElement(javax.lang.model.element.TypeElement) DeclaredType(javax.lang.model.type.DeclaredType)

Example 53 with Element

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));
    }
}
Also used : Element(javax.lang.model.element.Element)

Example 54 with Element

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ElementKind(javax.lang.model.element.ElementKind) Element(javax.lang.model.element.Element) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 55 with Element

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);
    }
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) TypeElement(javax.lang.model.element.TypeElement) VariableElement(javax.lang.model.element.VariableElement) TypeElement(javax.lang.model.element.TypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) Element(javax.lang.model.element.Element)

Aggregations

Element (javax.lang.model.element.Element)286 TypeElement (javax.lang.model.element.TypeElement)227 ExecutableElement (javax.lang.model.element.ExecutableElement)148 VariableElement (javax.lang.model.element.VariableElement)96 TypeMirror (javax.lang.model.type.TypeMirror)68 PackageElement (javax.lang.model.element.PackageElement)48 ArrayList (java.util.ArrayList)39 DeclaredType (javax.lang.model.type.DeclaredType)30 IOException (java.io.IOException)29 Map (java.util.Map)26 HashSet (java.util.HashSet)23 LinkedHashSet (java.util.LinkedHashSet)22 List (java.util.List)22 Set (java.util.Set)22 Test (org.junit.Test)21 ElementKind (javax.lang.model.element.ElementKind)20 AnnotationMirror (javax.lang.model.element.AnnotationMirror)19 Elements (javax.lang.model.util.Elements)18 HashMap (java.util.HashMap)16 LinkedHashMap (java.util.LinkedHashMap)15