Search in sources :

Example 26 with Type

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

the class ScalaWriter method getGenericName.

@Override
public String getGenericName(boolean asArgType, Type type) {
    if (type.getParameters().isEmpty()) {
        return getRawName(type);
    } else {
        StringBuilder builder = new StringBuilder();
        builder.append(getRawName(type));
        builder.append("[");
        boolean first = true;
        String fullName = type.getFullName();
        for (Type parameter : type.getParameters()) {
            if (!first) {
                builder.append(", ");
            }
            if (parameter == null || parameter.getFullName().equals(fullName)) {
                builder.append("_");
            } else {
                builder.append(getGenericName(false, parameter));
            }
            first = false;
        }
        builder.append("]");
        return builder.toString();
    }
}
Also used : Type(com.querydsl.codegen.utils.model.Type)

Example 27 with Type

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

the class AbstractEvaluatorFactory method createSource.

/**
 * @param source
 * @param projectionType
 * @param names
 * @param types
 * @param id
 * @param constants
 * @return
 * @throws IOException
 */
protected String createSource(String source, ClassType projectionType, String[] names, Type[] types, String id, Map<String, Object> constants) throws IOException {
    // create source
    StringWriter writer = new StringWriter();
    JavaWriter javaw = new JavaWriter(writer);
    SimpleType idType = new SimpleType(id, "", id);
    javaw.beginClass(idType, null);
    Parameter[] params = new Parameter[names.length + constants.size()];
    for (int i = 0; i < names.length; i++) {
        params[i] = new Parameter(names[i], types[i]);
    }
    int i = names.length;
    for (Map.Entry<String, Object> entry : constants.entrySet()) {
        Type type = new ClassType(TypeCategory.SIMPLE, ClassUtils.normalize(entry.getValue().getClass()));
        params[i++] = new Parameter(entry.getKey(), type);
    }
    javaw.beginStaticMethod(projectionType, "eval", params);
    javaw.append(source);
    javaw.end();
    javaw.end();
    return writer.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) Parameter(com.querydsl.codegen.utils.model.Parameter) ClassType(com.querydsl.codegen.utils.model.ClassType) Map(java.util.Map) WeakHashMap(java.util.WeakHashMap)

Example 28 with Type

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

the class PropertyTest method equals_and_hashCode.

@Test
public void equals_and_hashCode() {
    Type typeModel = new SimpleType(TypeCategory.ENTITY, "com.querydsl.DomainClass", "com.querydsl", "DomainClass", false, false);
    EntityType type = new EntityType(typeModel);
    Property p1 = new Property(type, "property", type, Collections.<String>emptyList());
    Property p2 = new Property(type, "property", type, Collections.<String>emptyList());
    assertEquals(p1, p1);
    assertEquals(p1, p2);
    assertEquals(p1.hashCode(), p2.hashCode());
}
Also used : SimpleType(com.querydsl.codegen.utils.model.SimpleType) Type(com.querydsl.codegen.utils.model.Type) SimpleType(com.querydsl.codegen.utils.model.SimpleType) Test(org.junit.Test)

Example 29 with Type

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

the class ScalaTypeDump method test.

@Test
@Ignore
public void test() throws IOException {
    List<Class<?>> classes = new ArrayList<Class<?>>();
    classes.add(SimpleExpression.class);
    classes.add(ComparableExpression.class);
    classes.add(BooleanExpression.class);
    classes.add(StringExpression.class);
    classes.add(TemporalExpression.class);
    classes.add(TimeExpression.class);
    classes.add(DateTimeExpression.class);
    classes.add(DateExpression.class);
    classes.add(EnumExpression.class);
    classes.add(NumberExpression.class);
    StringWriter w = new StringWriter();
    ScalaWriter writer = new ScalaWriter(w);
    writer.packageDecl("com.querydsl.scala");
    writer.imports(Expression.class.getPackage());
    for (Class<?> cl : classes) {
        Type type = new ClassType(cl);
        Type superClass = new ClassType(cl.getSuperclass());
        writer.beginClass(type, superClass);
        for (Method m : cl.getDeclaredMethods()) {
            List<Parameter> params = new ArrayList<Parameter>();
            for (Class<?> paramType : m.getParameterTypes()) {
                params.add(new Parameter("arg" + params.size(), new ClassType(paramType)));
            }
            Type returnType = new ClassType(m.getReturnType());
            writer.beginPublicMethod(returnType, ":" + m.getName(), params.toArray(new Parameter[0]));
            writer.end();
        }
        writer.end();
    }
    System.out.println(w);
}
Also used : Type(com.querydsl.codegen.utils.model.Type) ClassType(com.querydsl.codegen.utils.model.ClassType) StringWriter(java.io.StringWriter) Expression(com.querydsl.core.types.Expression) ArrayList(java.util.ArrayList) Parameter(com.querydsl.codegen.utils.model.Parameter) ScalaWriter(com.querydsl.codegen.utils.ScalaWriter) Method(java.lang.reflect.Method) ClassType(com.querydsl.codegen.utils.model.ClassType) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 30 with Type

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

the class TypeMappingsTest method getPathType_of_innerClass.

@Test
public void getPathType_of_innerClass() {
    TypeMappings typeMappings = new JavaTypeMappings();
    EntityType model = new EntityType(new ClassType(TypeMappingsTest.class));
    EntityType type = new EntityType(new ClassType(Entity.class));
    typeMappings.register(type, new QueryTypeFactoryImpl("Q", "", "").create(type));
    Type pathType = typeMappings.getPathType(type, model, false);
    assertEquals("QTypeMappingsTest_Entity", pathType.getSimpleName());
}
Also used : Type(com.querydsl.codegen.utils.model.Type) ClassType(com.querydsl.codegen.utils.model.ClassType) SimpleType(com.querydsl.codegen.utils.model.SimpleType) 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