use of com.querydsl.codegen.utils.model.Type in project querydsl by querydsl.
the class TypeResolver method resolveWithParameters.
private static Type resolveWithParameters(Type type, Type declaringType, EntityType context) {
Type[] params = new Type[type.getParameters().size()];
boolean transformed = false;
for (int i = 0; i < type.getParameters().size(); i++) {
Type param = type.getParameters().get(i);
if (param != null && !param.getFullName().equals(type.getFullName())) {
params[i] = resolve(param, declaringType, context);
if (!params[i].equals(param)) {
transformed = true;
}
}
}
if (transformed) {
return new SimpleType(type, params);
} else {
return type;
}
}
use of com.querydsl.codegen.utils.model.Type in project querydsl by querydsl.
the class ProjectionSerializerTest method customGeneratedAnnotation.
@Test
public void customGeneratedAnnotation() throws IOException {
Type typeModel = new SimpleType(TypeCategory.ENTITY, "com.querydsl.DomainClass", "com.querydsl", "DomainClass", false, false);
EntityType type = new EntityType(typeModel);
Writer writer = new StringWriter();
ProjectionSerializer serializer = new DefaultProjectionSerializer(new JavaTypeMappings(), Generated.class);
serializer.serialize(type, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer));
String generatedSource = writer.toString();
assertThat(generatedSource, containsString("import com.querydsl.core.annotations.Generated"));
assertThat(generatedSource, containsString("@Generated(\"com.querydsl.codegen.DefaultProjectionSerializer\")\npublic class"));
}
use of com.querydsl.codegen.utils.model.Type in project querydsl by querydsl.
the class ProjectionSerializerTest method defaultGeneratedAnnotation.
@Test
public void defaultGeneratedAnnotation() throws IOException {
Type typeModel = new SimpleType(TypeCategory.ENTITY, "com.querydsl.DomainClass", "com.querydsl", "DomainClass", false, false);
EntityType type = new EntityType(typeModel);
Writer writer = new StringWriter();
ProjectionSerializer serializer = new DefaultProjectionSerializer(new JavaTypeMappings());
serializer.serialize(type, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer));
String generatedSource = writer.toString();
assertThat(generatedSource, containsString(String.format("import %s;", GeneratedAnnotationResolver.resolveDefault().getName())));
assertThat(generatedSource, containsString("@Generated(\"com.querydsl.codegen.DefaultProjectionSerializer\")\npublic class"));
}
use of com.querydsl.codegen.utils.model.Type in project querydsl by querydsl.
the class ProjectionSerializerTest method constructors.
@Test
public void constructors() throws IOException {
Type typeModel = new SimpleType(TypeCategory.ENTITY, "com.querydsl.DomainClass", "com.querydsl", "DomainClass", false, false);
EntityType type = new EntityType(typeModel);
// constructor
Parameter firstName = new Parameter("firstName", Types.STRING);
Parameter lastName = new Parameter("lastName", Types.STRING);
Parameter age = new Parameter("age", Types.INTEGER);
type.addConstructor(new Constructor(Arrays.asList(firstName, lastName, age)));
Writer writer = new StringWriter();
ProjectionSerializer serializer = new DefaultProjectionSerializer(new JavaTypeMappings());
serializer.serialize(type, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer));
assertTrue(writer.toString().contains("Expression<String> firstName"));
assertTrue(writer.toString().contains("Expression<String> lastName"));
assertTrue(writer.toString().contains("Expression<Integer> age"));
}
use of com.querydsl.codegen.utils.model.Type in project querydsl by querydsl.
the class GenericExporter method getPropertyType.
private Type getPropertyType(Class<?> cl, AnnotatedElement annotated, Class<?> type, java.lang.reflect.Type genericType) {
Type propertyType = null;
if (annotated.isAnnotationPresent(embeddedAnnotation)) {
Class<?> embeddableType = type;
if (Collection.class.isAssignableFrom(type)) {
embeddableType = ReflectionUtils.getTypeParameterAsClass(genericType, 0);
} else if (Map.class.isAssignableFrom(type)) {
embeddableType = ReflectionUtils.getTypeParameterAsClass(genericType, 1);
}
if (!embeddableType.getName().startsWith("java.")) {
typeFactory.addEmbeddableType(embeddableType);
if (!embeddableTypes.containsKey(embeddableType) && !entityTypes.containsKey(embeddableType) && !superTypes.containsKey(embeddableType)) {
EntityType entityType = createEntityType(embeddableType, embeddableTypes);
addProperties(embeddableType, entityType);
if (embeddableType == type) {
propertyType = entityType;
}
}
}
}
if (propertyType == null) {
propertyType = typeFactory.get(type, annotated, genericType);
if (propertyType instanceof EntityType && !allTypes.containsKey(ClassUtils.getFullName(type))) {
String fullName = ClassUtils.getFullName(type);
if (!allTypes.containsKey(fullName)) {
allTypes.put(fullName, (EntityType) propertyType);
}
}
}
return propertyType;
}
Aggregations