Search in sources :

Example 1 with ClassType

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

the class CustomTypeTest method customType.

@Test
public void customType() throws IOException {
    SimpleType type = new SimpleType(TypeCategory.ENTITY, "Entity", "", "Entity", false, false);
    EntityType entityType = new EntityType(type);
    entityType.addProperty(new Property(entityType, "property", new ClassType(Double[].class)));
    typeMappings.register(new ClassType(Double[].class), new ClassType(Point.class));
    typeMappings.register(entityType, queryTypeFactory.create(entityType));
    assertTrue(typeMappings.isRegistered(entityType.getProperties().iterator().next().getType()));
    serializer.serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer));
    assertTrue(writer.toString().contains("public final com.querydsl.codegen.Point property = " + "new com.querydsl.codegen.Point(forProperty(\"property\"));"));
}
Also used : SimpleType(com.mysema.codegen.model.SimpleType) JavaWriter(com.mysema.codegen.JavaWriter) ClassType(com.mysema.codegen.model.ClassType) Test(org.junit.Test)

Example 2 with ClassType

use of com.mysema.codegen.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[params.size()]));
            writer.end();
        }
        writer.end();
    }
    System.out.println(w);
}
Also used : ClassType(com.mysema.codegen.model.ClassType) Type(com.mysema.codegen.model.Type) StringWriter(java.io.StringWriter) Expression(com.querydsl.core.types.Expression) ArrayList(java.util.ArrayList) Parameter(com.mysema.codegen.model.Parameter) ScalaWriter(com.mysema.codegen.ScalaWriter) Method(java.lang.reflect.Method) ClassType(com.mysema.codegen.model.ClassType) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with ClassType

use of com.mysema.codegen.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 : ClassType(com.mysema.codegen.model.ClassType) Type(com.mysema.codegen.model.Type) ClassType(com.mysema.codegen.model.ClassType) Test(org.junit.Test)

Example 4 with ClassType

use of com.mysema.codegen.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.mysema.codegen.model.ClassType) Test(org.junit.Test)

Example 5 with ClassType

use of com.mysema.codegen.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.mysema.codegen.model.ClassType) Test(org.junit.Test)

Aggregations

ClassType (com.mysema.codegen.model.ClassType)10 Test (org.junit.Test)7 Type (com.mysema.codegen.model.Type)5 SimpleType (com.mysema.codegen.model.SimpleType)2 TypeCategory (com.mysema.codegen.model.TypeCategory)2 JavaWriter (com.mysema.codegen.JavaWriter)1 ScalaWriter (com.mysema.codegen.ScalaWriter)1 Parameter (com.mysema.codegen.model.Parameter)1 Expression (com.querydsl.core.types.Expression)1 StringWriter (java.io.StringWriter)1 Annotation (java.lang.annotation.Annotation)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Ignore (org.junit.Ignore)1