use of com.mysema.codegen.model.Type in project querydsl by querydsl.
the class GenericExporter method addConstructors.
private void addConstructors(Class<?> cl, EntityType type) {
for (Constructor<?> constructor : cl.getConstructors()) {
if (constructor.isAnnotationPresent(QueryProjection.class)) {
List<Parameter> parameters = Lists.newArrayList();
for (int i = 0; i < constructor.getParameterTypes().length; i++) {
Type parameterType = typeFactory.get(constructor.getParameterTypes()[i], constructor.getGenericParameterTypes()[i]);
for (Annotation annotation : constructor.getParameterAnnotations()[i]) {
if (annotation.annotationType().equals(QueryType.class)) {
QueryType queryType = (QueryType) annotation;
parameterType = parameterType.as(TypeCategory.valueOf(queryType.value().name()));
}
}
parameters.add(new Parameter("param" + i, parameterType));
}
type.addConstructor(new com.mysema.codegen.model.Constructor(parameters));
}
}
}
use of com.mysema.codegen.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;
}
use of com.mysema.codegen.model.Type in project querydsl by querydsl.
the class TypeElementHandler method transformParams.
public List<Parameter> transformParams(List<? extends VariableElement> params) {
List<Parameter> parameters = new ArrayList<Parameter>(params.size());
for (VariableElement param : params) {
Type paramType = getType(param);
parameters.add(new Parameter(param.getSimpleName().toString(), paramType));
}
return parameters;
}
use of com.mysema.codegen.model.Type in project querydsl by querydsl.
the class TypeElementHandler method toProperty.
private Property toProperty(EntityType entityType, String name, TypeMirror type, Annotations annotations) {
// type
Type propertyType = typeFactory.getType(type, true);
if (annotations.isAnnotationPresent(QueryType.class)) {
PropertyType propertyTypeAnn = annotations.getAnnotation(QueryType.class).value();
if (propertyTypeAnn != PropertyType.NONE) {
TypeCategory typeCategory = TypeCategory.valueOf(annotations.getAnnotation(QueryType.class).value().name());
if (typeCategory == null) {
return null;
}
propertyType = propertyType.as(typeCategory);
} else {
return null;
}
}
// inits
List<String> inits = Collections.emptyList();
if (annotations.isAnnotationPresent(QueryInit.class)) {
inits = ImmutableList.copyOf(annotations.getAnnotation(QueryInit.class).value());
}
return new Property(entityType, name, propertyType, inits);
}
use of com.mysema.codegen.model.Type in project querydsl by querydsl.
the class Generic2Test method resolve.
@Test
public void resolve() {
TypeFactory factory = new TypeFactory(Collections.<Class<? extends Annotation>>emptyList());
Type type = factory.get(AbstractCollectionAttribute.class);
assertEquals("com.querydsl.codegen.Generic2Test.AbstractCollectionAttribute", type.getGenericName(false));
assertEquals("com.querydsl.codegen.Generic2Test.AbstractCollectionAttribute", type.getGenericName(true));
}
Aggregations