use of com.querydsl.codegen.utils.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\"));"));
}
use of com.querydsl.codegen.utils.model.ClassType in project querydsl by querydsl.
the class TypeFactory method create.
private Type create(boolean entity, Class<?> cl, AnnotationHelper annotationHelper, Annotation annotation, java.lang.reflect.Type genericType, List<?> key) {
if (cl.isPrimitive()) {
cl = PrimitiveUtils.wrap(cl);
}
Type value;
Type[] tempParams = (Type[]) Array.newInstance(Type.class, ReflectionUtils.getTypeParameterCount(genericType));
cache.put(key, new ClassType(cl, tempParams));
Type[] parameters = getParameters(cl, genericType);
if (cl.isArray()) {
Type componentType = get(cl.getComponentType());
if (cl.getComponentType().isPrimitive()) {
componentType = Types.PRIMITIVES.get(componentType);
}
value = componentType.asArrayType();
} else if (cl.isEnum()) {
value = new ClassType(TypeCategory.ENUM, cl);
} else if (Number.class.isAssignableFrom(cl) && Comparable.class.isAssignableFrom(cl)) {
value = new ClassType(TypeCategory.NUMERIC, cl, parameters);
} else if (entity) {
value = createOther(cl, entity, annotationHelper, annotation, parameters);
} else if (Map.class.isAssignableFrom(cl)) {
value = new SimpleType(Types.MAP, parameters[0], asGeneric(parameters[1]));
} else if (List.class.isAssignableFrom(cl)) {
value = new SimpleType(Types.LIST, asGeneric(parameters[0]));
} else if (Set.class.isAssignableFrom(cl)) {
value = new SimpleType(Types.SET, asGeneric(parameters[0]));
} else if (Collection.class.isAssignableFrom(cl)) {
value = new SimpleType(Types.COLLECTION, asGeneric(parameters[0]));
} else {
value = createOther(cl, entity, annotationHelper, annotation, parameters);
}
if (genericType instanceof TypeVariable) {
TypeVariable tv = (TypeVariable) genericType;
if (tv.getBounds().length == 1 && tv.getBounds()[0].equals(Object.class)) {
value = new TypeSuper(tv.getName(), value);
} else {
value = new TypeExtends(tv.getName(), value);
}
}
if (entity && !(value instanceof EntityType)) {
value = new EntityType(value, variableNameFunction);
}
return value;
}
use of com.querydsl.codegen.utils.model.ClassType in project querydsl by querydsl.
the class ScalaWriterTest method setUp.
@Before
public void setUp() {
testType = new ClassType(JavaWriterTest.class);
testType2 = new SimpleType("com.querydsl.codegen.utils.Test", "com.querydsl.codegen.utils", "Test");
testSuperType = new SimpleType("com.querydsl.codegen.utils.Superclass", "com.querydsl.codegen.utils", "Superclass");
testInterface1 = new SimpleType("com.querydsl.codegen.utils.TestInterface1", "com.querydsl.codegen.utils", "TestInterface1");
testInterface2 = new SimpleType("com.querydsl.codegen.utils.TestInterface2", "com.querydsl.codegen.utils", "TestInterface2");
}
use of com.querydsl.codegen.utils.model.ClassType in project querydsl by querydsl.
the class InnerClassesTest method Scala.
@Test
public void Scala() {
StringWriter str = new StringWriter();
ScalaWriter writer = new ScalaWriter(str);
assertEquals("com.querydsl.codegen.utils.InnerClassesTest$Entity", writer.getRawName(new ClassType(Entity.class)));
}
use of com.querydsl.codegen.utils.model.ClassType in project querydsl by querydsl.
the class InnerClassesTest method Java.
@Test
public void Java() {
StringWriter str = new StringWriter();
JavaWriter writer = new JavaWriter(str);
assertEquals("com.querydsl.codegen.utils.InnerClassesTest.Entity", writer.getRawName(new ClassType(Entity.class)));
}
Aggregations