Search in sources :

Example 36 with Type

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

the class TypeElementHandler method toProperty.

private Property toProperty(EntityType entityType, String name, TypeMirror type, Annotations annotations) {
    // type
    Type propertyType = typeFactory.getType(type, true);
    if (annotations.isAnnotationPresent(QueryType.class)) {
        PropertyType propertyTypeAnn = annotations.getAnnotation(QueryType.class).value();
        if (propertyTypeAnn != PropertyType.NONE) {
            TypeCategory typeCategory = TypeCategory.valueOf(annotations.getAnnotation(QueryType.class).value().name());
            if (typeCategory == null) {
                return null;
            }
            propertyType = propertyType.as(typeCategory);
        } else {
            return null;
        }
    }
    // inits
    List<String> inits = Collections.emptyList();
    if (annotations.isAnnotationPresent(QueryInit.class)) {
        inits = Arrays.asList(annotations.getAnnotation(QueryInit.class).value());
    }
    return new Property(entityType, name, propertyType, inits);
}
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) QueryInit(com.querydsl.core.annotations.QueryInit) TypeCategory(com.querydsl.codegen.utils.model.TypeCategory) PropertyType(com.querydsl.core.annotations.PropertyType) QueryType(com.querydsl.core.annotations.QueryType) Property(com.querydsl.codegen.Property)

Example 37 with Type

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

the class BeanSerializer method serialize.

@Override
public void serialize(EntityType model, SerializerConfig serializerConfig, CodeWriter writer) throws IOException {
    String simpleName = model.getSimpleName();
    // package
    if (!model.getPackageName().isEmpty()) {
        writer.packageDecl(model.getPackageName());
    }
    // imports
    Set<String> importedClasses = getAnnotationTypes(model);
    for (Type iface : interfaces) {
        importedClasses.add(iface.getFullName());
    }
    importedClasses.add(generatedAnnotationClass.getName());
    if (model.hasLists()) {
        importedClasses.add(List.class.getName());
    }
    if (model.hasCollections()) {
        importedClasses.add(Collection.class.getName());
    }
    if (model.hasSets()) {
        importedClasses.add(Set.class.getName());
    }
    if (model.hasMaps()) {
        importedClasses.add(Map.class.getName());
    }
    if (addToString && model.hasArrays()) {
        importedClasses.add(Arrays.class.getName());
    }
    writer.importClasses(importedClasses.toArray(new String[0]));
    // javadoc
    writer.javadoc(simpleName + javadocSuffix);
    // header
    for (Annotation annotation : model.getAnnotations()) {
        writer.annotation(annotation);
    }
    writer.line("@", generatedAnnotationClass.getSimpleName(), "(\"", getClass().getName(), "\")");
    if (!interfaces.isEmpty()) {
        Type superType = null;
        if (printSupertype && model.getSuperType() != null) {
            superType = model.getSuperType().getType();
        }
        Type[] ifaces = interfaces.toArray(new Type[0]);
        writer.beginClass(model, superType, ifaces);
    } else if (printSupertype && model.getSuperType() != null) {
        writer.beginClass(model, model.getSuperType().getType());
    } else {
        writer.beginClass(model);
    }
    bodyStart(model, writer);
    if (addFullConstructor) {
        addFullConstructor(model, writer);
    }
    // fields
    for (Property property : model.getProperties()) {
        if (propertyAnnotations) {
            for (Annotation annotation : property.getAnnotations()) {
                writer.annotation(annotation);
            }
        }
        writer.privateField(property.getType(), property.getEscapedName());
    }
    // accessors
    for (Property property : model.getProperties()) {
        String propertyName = property.getEscapedName();
        // getter
        writer.beginPublicMethod(property.getType(), "get" + BeanUtils.capitalize(propertyName));
        writer.line("return ", propertyName, ";");
        writer.end();
        // setter
        Parameter parameter = new Parameter(propertyName, property.getType());
        writer.beginPublicMethod(Types.VOID, "set" + BeanUtils.capitalize(propertyName), parameter);
        writer.line("this.", propertyName, " = ", propertyName, ";");
        writer.end();
    }
    if (addToString) {
        addToString(model, writer);
    }
    bodyEnd(model, writer);
    writer.end();
}
Also used : Type(com.querydsl.codegen.utils.model.Type) ClassType(com.querydsl.codegen.utils.model.ClassType) Set(java.util.Set) HashSet(java.util.HashSet) Collection(java.util.Collection) Parameter(com.querydsl.codegen.utils.model.Parameter) ArrayList(java.util.ArrayList) List(java.util.List) Arrays(java.util.Arrays) Map(java.util.Map) Annotation(java.lang.annotation.Annotation)

Example 38 with Type

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

the class DefaultEmbeddableSerializer method introClassHeader.

@Override
@SuppressWarnings(UNCHECKED)
protected void introClassHeader(CodeWriter writer, EntityType model) throws IOException {
    Type queryType = typeMappings.getPathType(model, model, true);
    TypeCategory category = model.getOriginalCategory();
    Class<? extends Path> pathType;
    if (model.getProperties().isEmpty()) {
        switch(category) {
            case COMPARABLE:
                pathType = ComparablePath.class;
                break;
            case ENUM:
                pathType = EnumPath.class;
                break;
            case DATE:
                pathType = DatePath.class;
                break;
            case DATETIME:
                pathType = DateTimePath.class;
                break;
            case TIME:
                pathType = TimePath.class;
                break;
            case NUMERIC:
                pathType = NumberPath.class;
                break;
            case STRING:
                pathType = StringPath.class;
                break;
            case BOOLEAN:
                pathType = BooleanPath.class;
                break;
            default:
                pathType = BeanPath.class;
        }
    } else {
        pathType = BeanPath.class;
    }
    for (Annotation annotation : model.getAnnotations()) {
        writer.annotation(annotation);
    }
    writer.line("@", generatedAnnotationClass.getSimpleName(), "(\"", getClass().getName(), "\")");
    if (category == TypeCategory.BOOLEAN || category == TypeCategory.STRING) {
        writer.beginClass(queryType, new ClassType(pathType));
    } else {
        writer.beginClass(queryType, new ClassType(category, pathType, model));
    }
    // TODO : generate proper serialVersionUID here
    writer.privateStaticFinal(Types.LONG_P, "serialVersionUID", model.hashCode() + "L");
}
Also used : Type(com.querydsl.codegen.utils.model.Type) ClassType(com.querydsl.codegen.utils.model.ClassType) TypeCategory(com.querydsl.codegen.utils.model.TypeCategory) ClassType(com.querydsl.codegen.utils.model.ClassType) Annotation(java.lang.annotation.Annotation)

Example 39 with Type

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

the class AbstractEvaluatorFactory method toId.

protected String toId(String source, Class<?> returnType, Type[] types, Collection<Object> constants) {
    StringBuilder b = new StringBuilder(128);
    b.append("Q");
    b.append("_").append(source.hashCode());
    b.append("_").append(returnType.getName().hashCode());
    for (Type type : types) {
        b.append("_").append(type.getFullName().hashCode());
    }
    for (Object constant : constants) {
        b.append("_").append(constant.getClass().getName().hashCode());
    }
    return b.toString().replace('-', '0');
}
Also used : Type(com.querydsl.codegen.utils.model.Type) ClassType(com.querydsl.codegen.utils.model.ClassType) SimpleType(com.querydsl.codegen.utils.model.SimpleType)

Example 40 with Type

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

the class InnerClassesTest method DirectParameter.

@Test
public void DirectParameter() throws IOException {
    Type entityType = new ClassType(Entity.class);
    Type type = new SimpleType("com.querydsl.codegen.utils.gen.QEntity", "com.querydsl.codegen.utils.gen", "QEntity", entityType);
    StringWriter str = new StringWriter();
    JavaWriter writer = new JavaWriter(str);
    writer.beginClass(type);
    writer.end();
    System.err.println(str.toString());
}
Also used : SimpleType(com.querydsl.codegen.utils.model.SimpleType) Type(com.querydsl.codegen.utils.model.Type) ClassType(com.querydsl.codegen.utils.model.ClassType) SimpleType(com.querydsl.codegen.utils.model.SimpleType) StringWriter(java.io.StringWriter) ClassType(com.querydsl.codegen.utils.model.ClassType) Test(org.junit.Test)

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