Search in sources :

Example 6 with ElementKind

use of javax.lang.model.element.ElementKind 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 7 with ElementKind

use of javax.lang.model.element.ElementKind in project androidannotations by androidannotations.

the class ModelExtractor method extractAncestorsAnnotations.

private void extractAncestorsAnnotations(AnnotationElementsHolder extractedModel, Set<String> annotationTypesToCheck, Set<TypeElement> rootTypeElements) {
    for (TypeElement rootTypeElement : rootTypeElements) {
        Set<TypeElement> ancestors = new LinkedHashSet<>();
        addAncestorsElements(ancestors, rootTypeElement);
        if (!ancestors.isEmpty()) {
            for (TypeElement ancestor : ancestors) {
                extractAnnotations(extractedModel, annotationTypesToCheck, rootTypeElement, ancestor);
                for (Element ancestorEnclosedElement : ancestor.getEnclosedElements()) {
                    ElementKind enclosedKind = ancestorEnclosedElement.getKind();
                    if (enclosedKind == ElementKind.FIELD || enclosedKind == ElementKind.METHOD) {
                        extractAnnotations(extractedModel, annotationTypesToCheck, rootTypeElement, ancestorEnclosedElement);
                    }
                }
            }
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ElementKind(javax.lang.model.element.ElementKind) TypeElement(javax.lang.model.element.TypeElement) Element(javax.lang.model.element.Element) TypeElement(javax.lang.model.element.TypeElement)

Example 8 with ElementKind

use of javax.lang.model.element.ElementKind in project dagger by square.

the class InjectAdapterProcessor method validateInjectable.

private boolean validateInjectable(Element injectable) {
    Element injectableType = injectable.getEnclosingElement();
    if (injectable.getKind() == ElementKind.CLASS) {
        error("@Inject is not valid on a class: " + elementToString(injectable), injectable);
        return false;
    }
    if (injectable.getKind() == ElementKind.METHOD) {
        error("Method injection is not supported: " + elementToString(injectable), injectable);
        return false;
    }
    if (injectable.getKind() == ElementKind.FIELD && injectable.getModifiers().contains(FINAL)) {
        error("Can't inject a final field: " + elementToString(injectable), injectable);
        return false;
    }
    if (injectable.getKind() == ElementKind.FIELD && injectable.getModifiers().contains(PRIVATE)) {
        error("Can't inject a private field: " + elementToString(injectable), injectable);
        return false;
    }
    if (injectable.getKind() == ElementKind.CONSTRUCTOR && injectable.getModifiers().contains(PRIVATE)) {
        error("Can't inject a private constructor: " + elementToString(injectable), injectable);
        return false;
    }
    ElementKind elementKind = injectableType.getEnclosingElement().getKind();
    boolean isClassOrInterface = elementKind.isClass() || elementKind.isInterface();
    boolean isStatic = injectableType.getModifiers().contains(STATIC);
    if (isClassOrInterface && !isStatic) {
        error("Can't inject a non-static inner class: " + elementToString(injectable), injectableType);
        return false;
    }
    return true;
}
Also used : ElementKind(javax.lang.model.element.ElementKind) TypeElement(javax.lang.model.element.TypeElement) Element(javax.lang.model.element.Element) VariableElement(javax.lang.model.element.VariableElement) ExecutableElement(javax.lang.model.element.ExecutableElement)

Example 9 with ElementKind

use of javax.lang.model.element.ElementKind in project tiger by google.

the class Utils method getPackage.

public static PackageElement getPackage(TypeElement typeElement) {
    Element result = typeElement.getEnclosingElement();
    ElementKind elementKind = result.getKind();
    while (!elementKind.equals(ElementKind.PACKAGE)) {
        Preconditions.checkState(elementKind.isClass() || elementKind.isInterface(), String.format("Utils.getPackage: unexpected kind: %s for type: %s", elementKind, typeElement));
        result = result.getEnclosingElement();
        elementKind = result.getKind();
    }
    return (PackageElement) result;
}
Also used : ElementKind(javax.lang.model.element.ElementKind) TypeElement(javax.lang.model.element.TypeElement) Element(javax.lang.model.element.Element) PackageElement(javax.lang.model.element.PackageElement) VariableElement(javax.lang.model.element.VariableElement) ExecutableElement(javax.lang.model.element.ExecutableElement) PackageElement(javax.lang.model.element.PackageElement)

Example 10 with ElementKind

use of javax.lang.model.element.ElementKind in project tiger by google.

the class NewBindingKey method get.

public static NewBindingKey get(Element element) {
    ElementKind elementKind = element.getKind();
    Preconditions.checkArgument(elementKind.equals(ElementKind.CLASS) || elementKind.equals(ElementKind.PARAMETER), String.format("Unexpected element %s of Kind %s", element, elementKind));
    return get(element.asType(), Utils.getQualifier(element));
}
Also used : ElementKind(javax.lang.model.element.ElementKind)

Aggregations

ElementKind (javax.lang.model.element.ElementKind)21 Element (javax.lang.model.element.Element)9 TypeElement (javax.lang.model.element.TypeElement)9 ExecutableElement (javax.lang.model.element.ExecutableElement)5 PackageElement (javax.lang.model.element.PackageElement)4 LinkedHashSet (java.util.LinkedHashSet)3 VariableElement (javax.lang.model.element.VariableElement)3 MetaModelGenerationException (org.hibernate.jpamodelgen.MetaModelGenerationException)3 HashSet (java.util.HashSet)2 AnnotationMirror (javax.lang.model.element.AnnotationMirror)2 Modifier (javax.lang.model.element.Modifier)2 TypeParameterElement (javax.lang.model.element.TypeParameterElement)2 TypeMirror (javax.lang.model.type.TypeMirror)2 TypeConverter (com.bluelinelabs.logansquare.typeconverters.TypeConverter)1 MoreElements.getAnnotationMirror (com.google.auto.common.MoreElements.getAnnotationMirror)1 Function (com.google.common.base.Function)1 TypeSpec (com.squareup.javapoet.TypeSpec)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 ArrayList (java.util.ArrayList)1