Search in sources :

Example 1 with AccessorProvider

use of org.immutables.generator.SourceOrdering.AccessorProvider in project immutables by immutables.

the class Accessors method collectAccessors.

private void collectAccessors(TypeElement type, Map<String, Accessor> accesors) {
    List<? extends Element> allMembers = elements.getAllMembers(type);
    for (VariableElement field : ElementFilter.fieldsIn(allMembers)) {
        if (isAccessible(field)) {
            Accessor accessor = new Accessor(field);
            accesors.put(accessor.name, accessor);
        }
    }
    // toString, hashCode from Object
    for (ExecutableElement method : ElementFilter.methodsIn(allMembers)) {
        TypeElement definingType = (TypeElement) method.getEnclosingElement();
        if (definingType.getQualifiedName().contentEquals(Object.class.getCanonicalName()) || isSimpleAccessor(method) && isAccessible(method)) {
            Accessor accessor = new Accessor(method);
            accesors.put(accessor.name, accessor);
        }
    }
    // For other accessors we use shared utility
    AccessorProvider provider = SourceOrdering.getAllAccessorsProvider(elements, types, type);
    for (ExecutableElement method : provider.get()) {
        // this should be already checked, but we check for completeness
        if (isSimpleAccessor(method) && isAccessible(method)) {
            Accessor accessor = new Accessor(method);
            accesors.put(accessor.name, accessor);
        }
    }
}
Also used : AccessorProvider(org.immutables.generator.SourceOrdering.AccessorProvider)

Example 2 with AccessorProvider

use of org.immutables.generator.SourceOrdering.AccessorProvider 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)

Aggregations

AccessorProvider (org.immutables.generator.SourceOrdering.AccessorProvider)2 Element (javax.lang.model.element.Element)1 ExecutableElement (javax.lang.model.element.ExecutableElement)1 TypeElement (javax.lang.model.element.TypeElement)1 VariableElement (javax.lang.model.element.VariableElement)1