Search in sources :

Example 16 with ClassType

use of com.querydsl.codegen.utils.model.ClassType 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 17 with ClassType

use of com.querydsl.codegen.utils.model.ClassType 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)

Example 18 with ClassType

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

the class DefaultEvaluatorFactory method createEvaluator.

/**
 * Create an Evaluator for the given source and filter
 *
 * @param <T>
 * @param source source of the query
 * @param filter filter of the query
 * @return evaluator
 */
public <T> Evaluator<List<T>> createEvaluator(QueryMetadata metadata, Expression<? extends T> source, Predicate filter) {
    String typeName = ClassUtils.getName(source.getType());
    CollQuerySerializer ser = new CollQuerySerializer(templates);
    ser.append("java.util.List<" + typeName + "> rv = new java.util.ArrayList<" + typeName + ">();\n");
    ser.append("for (" + typeName + " " + source + " : " + source + "_) {\n");
    ser.append("    try {\n");
    ser.append("        if (").handle(filter).append(") {\n");
    ser.append("            rv.add(" + source + ");\n");
    ser.append("        }\n");
    ser.append("    } catch (NullPointerException npe) { }\n");
    ser.append("}\n");
    ser.append("return rv;");
    Map<Object, String> constantToLabel = ser.getConstantToLabel();
    Map<String, Object> constants = getConstants(metadata, constantToLabel);
    Type sourceType = new ClassType(TypeCategory.SIMPLE, source.getType());
    ClassType sourceListType = new ClassType(TypeCategory.SIMPLE, Iterable.class, sourceType);
    return factory.createEvaluator(ser.toString(), sourceListType, new String[] { source + "_" }, new Type[] { sourceListType }, new Class<?>[] { Iterable.class }, constants);
}
Also used : SimpleType(com.querydsl.codegen.utils.model.SimpleType) Type(com.querydsl.codegen.utils.model.Type) ClassType(com.querydsl.codegen.utils.model.ClassType) JoinType(com.querydsl.core.JoinType) ClassType(com.querydsl.codegen.utils.model.ClassType)

Example 19 with ClassType

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

the class EntityTypeTest method uncapSimpleName_escaped2.

@Test
public void uncapSimpleName_escaped2() {
    ClassType typeModel = new ClassType(TypeCategory.ENTITY, Object.class);
    EntityType entityModel = new EntityType(typeModel);
    assertEquals("object", entityModel.getModifiedSimpleName());
    entityModel.addProperty(new Property(entityModel, "OBJECT", "object", typeModel, Collections.<String>emptyList(), false));
    assertEquals("object1", entityModel.getModifiedSimpleName());
}
Also used : ClassType(com.querydsl.codegen.utils.model.ClassType) Test(org.junit.Test)

Example 20 with ClassType

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

the class EntityTypeTest method uncapSimpleName_escaped3.

@Test
public void uncapSimpleName_escaped3() {
    ClassType typeModel = new ClassType(TypeCategory.ENTITY, Void.class);
    EntityType entityModel = new EntityType(typeModel);
    assertEquals("void$", entityModel.getModifiedSimpleName());
}
Also used : ClassType(com.querydsl.codegen.utils.model.ClassType) Test(org.junit.Test)

Aggregations

ClassType (com.querydsl.codegen.utils.model.ClassType)35 Test (org.junit.Test)24 SimpleType (com.querydsl.codegen.utils.model.SimpleType)18 Type (com.querydsl.codegen.utils.model.Type)14 List (java.util.List)7 JavaWriter (com.querydsl.codegen.utils.JavaWriter)6 StringWriter (java.io.StringWriter)6 Parameter (com.querydsl.codegen.utils.model.Parameter)4 TypeCategory (com.querydsl.codegen.utils.model.TypeCategory)3 PrimaryKeyData (com.querydsl.sql.codegen.support.PrimaryKeyData)3 ArrayList (java.util.ArrayList)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 Property (com.querydsl.codegen.Property)2 Cat (com.querydsl.codegen.utils.support.Cat)2 JoinType (com.querydsl.core.JoinType)2 ColumnImpl (com.querydsl.sql.ColumnImpl)2 Annotation (java.lang.annotation.Annotation)2 Before (org.junit.Before)2 EntityType (com.querydsl.codegen.EntityType)1 ScalaWriter (com.querydsl.codegen.utils.ScalaWriter)1