use of com.mysema.codegen.model.Type in project querydsl by querydsl.
the class AbstractQuerydslProcessor method addExternalParents.
private void addExternalParents(EntityType entityType) {
Deque<Type> superTypes = new ArrayDeque<Type>();
if (entityType.getSuperType() != null) {
superTypes.push(entityType.getSuperType().getType());
}
while (!superTypes.isEmpty()) {
Type superType = superTypes.pop();
if (!context.allTypes.containsKey(superType.getFullName())) {
TypeElement typeElement = processingEnv.getElementUtils().getTypeElement(superType.getFullName());
if (typeElement == null) {
throw new IllegalStateException("Found no type for " + superType.getFullName());
}
if (conf.isStrictMode() && !TypeUtils.hasAnnotationOfType(typeElement, conf.getEntityAnnotations())) {
continue;
}
EntityType superEntityType = elementHandler.handleEntityType(typeElement);
if (superEntityType.getSuperType() != null) {
superTypes.push(superEntityType.getSuperType().getType());
}
context.allTypes.put(superType.getFullName(), superEntityType);
}
}
}
use of com.mysema.codegen.model.Type in project querydsl by querydsl.
the class AbstractQuerydslProcessor method serialize.
private void serialize(Serializer serializer, Collection<EntityType> models) {
for (EntityType model : models) {
try {
Type type = conf.getTypeMappings().getPathType(model, model, true);
String packageName = type.getPackageName();
String className = !packageName.isEmpty() ? (packageName + "." + type.getSimpleName()) : type.getSimpleName();
// skip if type is excluded class or in excluded package
if (conf.isExcludedPackage(model.getPackageName()) || conf.isExcludedClass(model.getFullName())) {
continue;
}
Set<TypeElement> elements = context.typeElements.get(model.getFullName());
if (elements == null) {
elements = new HashSet<TypeElement>();
}
for (Property property : model.getProperties()) {
if (property.getType().getCategory() == TypeCategory.CUSTOM) {
Set<TypeElement> customElements = context.typeElements.get(property.getType().getFullName());
if (customElements != null) {
elements.addAll(customElements);
}
}
}
processingEnv.getMessager().printMessage(Kind.NOTE, "Generating " + className + " for " + elements);
JavaFileObject fileObject = processingEnv.getFiler().createSourceFile(className, elements.toArray(new Element[elements.size()]));
Writer writer = fileObject.openWriter();
try {
SerializerConfig serializerConfig = conf.getSerializerConfig(model);
serializer.serialize(model, serializerConfig, new JavaWriter(writer));
} finally {
if (writer != null) {
writer.close();
}
}
} catch (IOException e) {
System.err.println(e.getMessage());
processingEnv.getMessager().printMessage(Kind.ERROR, e.getMessage());
}
}
}
use of com.mysema.codegen.model.Type in project querydsl by querydsl.
the class AbstractQuerydslProcessor method processDelegateMethods.
private Set<TypeElement> processDelegateMethods() {
Set<? extends Element> delegateMethods = getElements(QueryDelegate.class);
Set<TypeElement> typeElements = new HashSet<TypeElement>();
for (Element delegateMethod : delegateMethods) {
ExecutableElement method = (ExecutableElement) delegateMethod;
Element element = delegateMethod.getEnclosingElement();
String name = method.getSimpleName().toString();
Type delegateType = typeFactory.getType(element.asType(), true);
Type returnType = typeFactory.getType(method.getReturnType(), true);
List<Parameter> parameters = elementHandler.transformParams(method.getParameters());
// remove first element
parameters = parameters.subList(1, parameters.size());
EntityType entityType = null;
for (AnnotationMirror annotation : delegateMethod.getAnnotationMirrors()) {
if (TypeUtils.isAnnotationMirrorOfType(annotation, QueryDelegate.class)) {
TypeMirror type = TypeUtils.getAnnotationValueAsTypeMirror(annotation, "value");
if (type != null) {
entityType = typeFactory.getEntityType(type, true);
}
}
}
if (entityType != null) {
registerTypeElement(entityType.getFullName(), (TypeElement) element);
entityType.addDelegate(new Delegate(entityType, delegateType, name, parameters, returnType));
TypeElement typeElement = processingEnv.getElementUtils().getTypeElement(entityType.getFullName());
boolean isAnnotated = false;
for (Class<? extends Annotation> ann : conf.getEntityAnnotations()) {
if (typeElement.getAnnotation(ann) != null) {
isAnnotated = true;
}
}
if (isAnnotated) {
// handle also properties of entity type
typeElements.add(processingEnv.getElementUtils().getTypeElement(entityType.getFullName()));
} else {
// skip handling properties
context.extensionTypes.put(entityType.getFullName(), entityType);
context.allTypes.put(entityType.getFullName(), entityType);
}
}
}
return typeElements;
}
use of com.mysema.codegen.model.Type in project querydsl by querydsl.
the class TypeElementHandler method getType.
private Type getType(VariableElement element) {
Type rv = typeFactory.getType(element.asType(), true);
if (element.getAnnotation(QueryType.class) != null) {
QueryType qt = element.getAnnotation(QueryType.class);
if (qt.value() != PropertyType.NONE) {
TypeCategory typeCategory = TypeCategory.valueOf(qt.value().name());
rv = rv.as(typeCategory);
}
}
return rv;
}
use of com.mysema.codegen.model.Type in project querydsl by querydsl.
the class TypeElementHandler method handleProjectionType.
public EntityType handleProjectionType(TypeElement e) {
Type c = typeFactory.getType(e.asType(), true);
EntityType entityType = new EntityType(c.as(TypeCategory.ENTITY), configuration.getVariableNameFunction());
typeMappings.register(entityType, queryTypeFactory.create(entityType));
List<? extends Element> elements = e.getEnclosedElements();
handleConstructors(entityType, elements);
return entityType;
}
Aggregations