Search in sources :

Example 1 with Type

use of com.querydsl.codegen.utils.model.Type in project querydsl by querydsl.

the class ExtendedTypeFactory method createEntityType.

@Nullable
private EntityType createEntityType(TypeMirror typeMirror, List<String> key, boolean deep) {
    entityTypeCache.put(key, null);
    Type value = visitor.visit(typeMirror, deep);
    if (value != null) {
        EntityType entityType = null;
        if (value instanceof EntityType) {
            entityType = (EntityType) value;
        } else {
            entityType = new EntityType(value, variableNameFunction);
            typeMappings.register(entityType, queryTypeFactory.create(entityType));
        }
        entityTypeCache.put(key, entityType);
        if (deep) {
            for (Type superType : getSupertypes(typeMirror, deep)) {
                entityType.addSupertype(new Supertype(superType));
            }
        }
        return entityType;
    } else {
        return null;
    }
}
Also used : EntityType(com.querydsl.codegen.EntityType) ErrorType(javax.lang.model.type.ErrorType) EntityType(com.querydsl.codegen.EntityType) DeclaredType(javax.lang.model.type.DeclaredType) SimpleType(com.querydsl.codegen.utils.model.SimpleType) WildcardType(javax.lang.model.type.WildcardType) ArrayType(javax.lang.model.type.ArrayType) Type(com.querydsl.codegen.utils.model.Type) ExecutableType(javax.lang.model.type.ExecutableType) NoType(javax.lang.model.type.NoType) NullType(javax.lang.model.type.NullType) PrimitiveType(javax.lang.model.type.PrimitiveType) Supertype(com.querydsl.codegen.Supertype) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with Type

use of com.querydsl.codegen.utils.model.Type in project querydsl by querydsl.

the class ExtendedTypeFactory method createType.

@Nullable
private Type createType(TypeMirror typeMirror, List<String> key, boolean deep) {
    typeCache.put(key, null);
    Type type = visitor.visit(typeMirror, deep);
    if (type != null && (type.getCategory() == TypeCategory.ENTITY || type.getCategory() == TypeCategory.CUSTOM)) {
        EntityType entityType = getEntityType(typeMirror, deep);
        typeCache.put(key, entityType);
        return entityType;
    } else {
        typeCache.put(key, type);
        return type;
    }
}
Also used : EntityType(com.querydsl.codegen.EntityType) ErrorType(javax.lang.model.type.ErrorType) EntityType(com.querydsl.codegen.EntityType) DeclaredType(javax.lang.model.type.DeclaredType) SimpleType(com.querydsl.codegen.utils.model.SimpleType) WildcardType(javax.lang.model.type.WildcardType) ArrayType(javax.lang.model.type.ArrayType) Type(com.querydsl.codegen.utils.model.Type) ExecutableType(javax.lang.model.type.ExecutableType) NoType(javax.lang.model.type.NoType) NullType(javax.lang.model.type.NullType) PrimitiveType(javax.lang.model.type.PrimitiveType) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with Type

use of com.querydsl.codegen.utils.model.Type in project querydsl by querydsl.

the class ExtendedTypeFactory method getSupertypes.

private Set<Type> getSupertypes(TypeMirror typeMirror, boolean deep) {
    boolean doubleIndex = doubleIndexEntities;
    doubleIndexEntities = false;
    Set<Type> superTypes = Collections.emptySet();
    typeMirror = normalize(typeMirror);
    if (typeMirror.getKind() == TypeKind.DECLARED) {
        DeclaredType declaredType = (DeclaredType) typeMirror;
        TypeElement e = (TypeElement) declaredType.asElement();
        // class
        if (e.getKind() == ElementKind.CLASS) {
            if (e.getSuperclass().getKind() != TypeKind.NONE) {
                TypeMirror supertype = normalize(e.getSuperclass());
                if (supertype instanceof DeclaredType && ((DeclaredType) supertype).asElement().getAnnotation(QueryExclude.class) != null) {
                    return Collections.emptySet();
                } else {
                    Type superClass = getType(supertype, deep);
                    if (superClass == null) {
                        System.err.println("Got no type for " + supertype);
                    } else if (!superClass.getFullName().startsWith("java")) {
                        superTypes = Collections.singleton(getType(supertype, deep));
                    }
                }
            }
        // interface
        } else {
            superTypes = new LinkedHashSet<Type>(e.getInterfaces().size());
            for (TypeMirror mirror : e.getInterfaces()) {
                Type iface = getType(mirror, deep);
                if (!iface.getFullName().startsWith("java")) {
                    superTypes.add(iface);
                }
            }
        }
    } else {
        return Collections.emptySet();
    }
    doubleIndexEntities = doubleIndex;
    return superTypes;
}
Also used : ErrorType(javax.lang.model.type.ErrorType) EntityType(com.querydsl.codegen.EntityType) DeclaredType(javax.lang.model.type.DeclaredType) SimpleType(com.querydsl.codegen.utils.model.SimpleType) WildcardType(javax.lang.model.type.WildcardType) ArrayType(javax.lang.model.type.ArrayType) Type(com.querydsl.codegen.utils.model.Type) ExecutableType(javax.lang.model.type.ExecutableType) NoType(javax.lang.model.type.NoType) NullType(javax.lang.model.type.NullType) PrimitiveType(javax.lang.model.type.PrimitiveType) TypeMirror(javax.lang.model.type.TypeMirror) TypeElement(javax.lang.model.element.TypeElement) DeclaredType(javax.lang.model.type.DeclaredType)

Example 4 with Type

use of com.querydsl.codegen.utils.model.Type in project querydsl by querydsl.

the class TypeElementHandler method handleProjectionType.

public EntityType handleProjectionType(TypeElement e) {
    Type c = typeFactory.getType(e.asType(), true);
    EntityType entityType = new EntityType(c.as(TypeCategory.ENTITY), configuration.getVariableNameFunction());
    typeMappings.register(entityType, queryTypeFactory.create(entityType));
    List<? extends Element> elements = e.getEnclosedElements();
    handleConstructors(entityType, elements);
    return entityType;
}
Also used : EntityType(com.querydsl.codegen.EntityType) QueryType(com.querydsl.core.annotations.QueryType) EntityType(com.querydsl.codegen.EntityType) Type(com.querydsl.codegen.utils.model.Type) PropertyType(com.querydsl.core.annotations.PropertyType)

Example 5 with Type

use of com.querydsl.codegen.utils.model.Type in project querydsl by querydsl.

the class TypeElementHandler method getType.

private Type getType(VariableElement element) {
    Type rv = typeFactory.getType(element.asType(), true);
    if (element.getAnnotation(QueryType.class) != null) {
        QueryType qt = element.getAnnotation(QueryType.class);
        if (qt.value() != PropertyType.NONE) {
            TypeCategory typeCategory = TypeCategory.valueOf(qt.value().name());
            rv = rv.as(typeCategory);
        }
    }
    return rv;
}
Also used : QueryType(com.querydsl.core.annotations.QueryType) EntityType(com.querydsl.codegen.EntityType) Type(com.querydsl.codegen.utils.model.Type) PropertyType(com.querydsl.core.annotations.PropertyType) TypeCategory(com.querydsl.codegen.utils.model.TypeCategory) QueryType(com.querydsl.core.annotations.QueryType)

Aggregations

Type (com.querydsl.codegen.utils.model.Type)56 SimpleType (com.querydsl.codegen.utils.model.SimpleType)35 ClassType (com.querydsl.codegen.utils.model.ClassType)23 EntityType (com.querydsl.codegen.EntityType)15 Test (org.junit.Test)14 PropertyType (com.querydsl.core.annotations.PropertyType)9 QueryType (com.querydsl.core.annotations.QueryType)9 DeclaredType (javax.lang.model.type.DeclaredType)9 NoType (javax.lang.model.type.NoType)9 Parameter (com.querydsl.codegen.utils.model.Parameter)7 ArrayList (java.util.ArrayList)7 TypeCategory (com.querydsl.codegen.utils.model.TypeCategory)6 StringWriter (java.io.StringWriter)6 ArrayType (javax.lang.model.type.ArrayType)6 ErrorType (javax.lang.model.type.ErrorType)6 ExecutableType (javax.lang.model.type.ExecutableType)6 NullType (javax.lang.model.type.NullType)6 PrimitiveType (javax.lang.model.type.PrimitiveType)6 WildcardType (javax.lang.model.type.WildcardType)6 Annotation (java.lang.annotation.Annotation)5