Search in sources :

Example 21 with Element

use of javax.lang.model.element.Element in project immutables by immutables.

the class Round method enclosingTypeOf.

private TypeElement enclosingTypeOf(Element element) {
    for (Element e = element; e != null; ) {
        ElementKind kind = e.getKind();
        if (kind.isClass() || kind.isInterface()) {
            return (TypeElement) e;
        }
        e = e.getEnclosingElement();
    }
    throw new NoSuchElementException();
}
Also used : ElementKind(javax.lang.model.element.ElementKind) TypeElement(javax.lang.model.element.TypeElement) PackageElement(javax.lang.model.element.PackageElement) ExecutableElement(javax.lang.model.element.ExecutableElement) Element(javax.lang.model.element.Element) TypeElement(javax.lang.model.element.TypeElement) NoSuchElementException(java.util.NoSuchElementException)

Example 22 with Element

use of javax.lang.model.element.Element in project immutables by immutables.

the class AccessorAttributesCollector method collectGeneratedCandidateMethods.

private void collectGeneratedCandidateMethods(TypeElement type) {
    TypeElement originalType = CachingElements.getDelegate(type);
    List<? extends Element> accessorsInSourceOrder;
    if (originalType.getKind() == ElementKind.ANNOTATION_TYPE) {
        accessorsInSourceOrder = SourceOrdering.getEnclosedElements(originalType);
    } else {
        AccessorProvider provider = SourceOrdering.getAllAccessorsProvider(processing.getElementUtils(), processing.getTypeUtils(), originalType);
        accessorsInSourceOrder = provider.get();
        accessorMapping = provider.accessorMapping();
    }
    for (ExecutableElement element : ElementFilter.methodsIn(accessorsInSourceOrder)) {
        if (isElegibleAccessorMethod(element)) {
            processGenerationCandidateMethod(element, originalType);
        }
    }
    // inform use during checking for warnings.
    for (Element element : processing.getElementUtils().getAllMembers(originalType)) {
        if (element.getKind() == ElementKind.METHOD) {
            switch(element.getSimpleName().toString()) {
                case HASH_CODE_METHOD:
                case TO_STRING_METHOD:
                case EQUALS_METHOD:
                    processUtilityCandidateMethod((ExecutableElement) element, originalType);
                    break;
                default:
            }
        }
    }
}
Also used : TypeElement(javax.lang.model.element.TypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) VariableElement(javax.lang.model.element.VariableElement) TypeElement(javax.lang.model.element.TypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) Element(javax.lang.model.element.Element) AccessorProvider(org.immutables.generator.SourceOrdering.AccessorProvider)

Example 23 with Element

use of javax.lang.model.element.Element in project immutables by immutables.

the class Round method allAnnotatedElements.

private Set<Element> allAnnotatedElements() {
    Set<Element> elements = Sets.newHashSetWithExpectedSize(100);
    for (TypeElement annotation : annotations()) {
        Set<? extends Element> annotatedElements = round().getElementsAnnotatedWith(annotation);
        checkAnnotation(annotation, annotatedElements);
        elements.addAll(annotatedElements);
    }
    return elements;
}
Also used : TypeElement(javax.lang.model.element.TypeElement) PackageElement(javax.lang.model.element.PackageElement) ExecutableElement(javax.lang.model.element.ExecutableElement) Element(javax.lang.model.element.Element) TypeElement(javax.lang.model.element.TypeElement)

Example 24 with Element

use of javax.lang.model.element.Element in project hibernate-orm by hibernate.

the class TypeUtils method determineAnnotationSpecifiedAccessType.

public static AccessType determineAnnotationSpecifiedAccessType(Element element) {
    final AnnotationMirror accessAnnotationMirror = TypeUtils.getAnnotationMirror(element, Constants.ACCESS);
    AccessType forcedAccessType = null;
    if (accessAnnotationMirror != null) {
        Element accessElement = (Element) TypeUtils.getAnnotationValue(accessAnnotationMirror, DEFAULT_ANNOTATION_PARAMETER_NAME);
        if (accessElement.getKind().equals(ElementKind.ENUM_CONSTANT)) {
            if (accessElement.getSimpleName().toString().equals(AccessType.PROPERTY.toString())) {
                forcedAccessType = AccessType.PROPERTY;
            } else if (accessElement.getSimpleName().toString().equals(AccessType.FIELD.toString())) {
                forcedAccessType = AccessType.FIELD;
            }
        }
    }
    return forcedAccessType;
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) ExecutableElement(javax.lang.model.element.ExecutableElement) Element(javax.lang.model.element.Element) TypeElement(javax.lang.model.element.TypeElement)

Example 25 with Element

use of javax.lang.model.element.Element in project hibernate-orm by hibernate.

the class JPAMetaModelEntityProcessor method process.

@Override
public boolean process(final Set<? extends TypeElement> annotations, final RoundEnvironment roundEnvironment) {
    // see also METAGEN-45
    if (roundEnvironment.processingOver() || annotations.size() == 0) {
        return ALLOW_OTHER_PROCESSORS_TO_CLAIM_ANNOTATIONS;
    }
    if (context.isFullyXmlConfigured()) {
        context.logMessage(Diagnostic.Kind.OTHER, "Skipping the processing of annotations since persistence unit is purely xml configured.");
        return ALLOW_OTHER_PROCESSORS_TO_CLAIM_ANNOTATIONS;
    }
    Set<? extends Element> elements = roundEnvironment.getRootElements();
    for (Element element : elements) {
        if (isJPAEntity(element)) {
            context.logMessage(Diagnostic.Kind.OTHER, "Processing annotated class " + element.toString());
            handleRootElementAnnotationMirrors(element);
        }
    }
    createMetaModelClasses();
    return ALLOW_OTHER_PROCESSORS_TO_CLAIM_ANNOTATIONS;
}
Also used : TypeElement(javax.lang.model.element.TypeElement) 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