Search in sources :

Example 1 with TypeHierarchyCollector

use of org.immutables.generator.TypeHierarchyCollector in project immutables by immutables.

the class TypeIntrospectionBase method collectTypeHierarchy.

protected TypeHierarchyCollector collectTypeHierarchy(TypeMirror typeMirror) {
    TypeHierarchyCollector collector = new TypeHierarchyCollector();
    collector.collectFrom(typeMirror);
    return collector;
}
Also used : TypeHierarchyCollector(org.immutables.generator.TypeHierarchyCollector)

Example 2 with TypeHierarchyCollector

use of org.immutables.generator.TypeHierarchyCollector in project immutables by immutables.

the class TypeIntrospectionBase method introspectTypeMirror.

protected void introspectTypeMirror(TypeMirror typeMirror) {
    TypeHierarchyCollector collector = collectTypeHierarchy(typeMirror);
    this.extendedClassesNames = collector.extendedClassNames();
    this.implementedInterfacesNames = collector.implementedInterfaceNames();
    this.unresolvedYetArguments = collector.unresolvedYetArguments();
}
Also used : TypeHierarchyCollector(org.immutables.generator.TypeHierarchyCollector)

Example 3 with TypeHierarchyCollector

use of org.immutables.generator.TypeHierarchyCollector in project immutables by immutables.

the class ValueAttribute method introspectType.

@Override
protected void introspectType() {
    TypeMirror typeMirror = returnType;
    // Special case for primitive Optional, may become a pattern for specialized types
    if (typeKind.isOptionalSpecializedJdk()) {
        typeParameters = ImmutableList.of(optionalSpecializedType());
        // no delegation to introspect further
        return;
    }
    if (isContainerType()) {
        if (typeMirror.getKind() == TypeKind.DECLARED || typeMirror.getKind() == TypeKind.ERROR) {
            DeclaredType declaredType = (DeclaredType) typeMirror;
            List<? extends TypeMirror> typeArguments = declaredType.getTypeArguments();
            if (!typeArguments.isEmpty()) {
                final TypeMirror typeArgument = typeArguments.get(0);
                if (isSetType() && protoclass().environment().hasOrdinalModule()) {
                    this.generateOrdinalValueSet = new TypeIntrospectionBase() {

                        @Override
                        protected TypeMirror internalTypeMirror() {
                            return typeArgument;
                        }

                        @Override
                        protected TypeHierarchyCollector collectTypeHierarchy(TypeMirror typeMirror) {
                            TypeHierarchyCollector collector = containingType.createTypeHierarchyCollector(reporter, element);
                            collector.collectFrom(typeMirror);
                            return collector;
                        }
                    }.isOrdinalValue();
                }
                if (isMapType()) {
                    TypeMirror typeSecondArgument = typeArguments.get(1);
                    if (typeSecondArgument.getKind() == TypeKind.DECLARED) {
                        TypeElement typeElement = (TypeElement) ((DeclaredType) typeSecondArgument).asElement();
                        this.containedSecondaryTypeElement = typeElement;
                    }
                }
                typeMirror = typeArgument;
            }
        }
    } else if (isArrayType()) {
        arrayComponent = ((ArrayType) typeMirror).getComponentType();
        typeMirror = arrayComponent;
    }
    if (typeMirror.getKind() == TypeKind.DECLARED) {
        TypeElement typeElement = (TypeElement) ((DeclaredType) typeMirror).asElement();
        this.containedTypeElement = typeElement;
    }
    introspectTypeMirror(typeMirror);
    introspectSupertypes();
}
Also used : ArrayType(javax.lang.model.type.ArrayType) TypeHierarchyCollector(org.immutables.generator.TypeHierarchyCollector) TypeMirror(javax.lang.model.type.TypeMirror) TypeElement(javax.lang.model.element.TypeElement) DeclaredType(javax.lang.model.type.DeclaredType)

Example 4 with TypeHierarchyCollector

use of org.immutables.generator.TypeHierarchyCollector in project immutables by immutables.

the class Metaservices method useIntrospectedInterfacesForServices.

private Set<String> useIntrospectedInterfacesForServices(TypeElement typeElement) {
    TypeHierarchyCollector typeHierarchyCollector = new TypeHierarchyCollector();
    typeHierarchyCollector.collectFrom(typeElement.asType());
    return typeHierarchyCollector.implementedInterfaceNames();
}
Also used : TypeHierarchyCollector(org.immutables.generator.TypeHierarchyCollector)

Aggregations

TypeHierarchyCollector (org.immutables.generator.TypeHierarchyCollector)4 TypeElement (javax.lang.model.element.TypeElement)1 ArrayType (javax.lang.model.type.ArrayType)1 DeclaredType (javax.lang.model.type.DeclaredType)1 TypeMirror (javax.lang.model.type.TypeMirror)1