use of com.querydsl.codegen.utils.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.querydsl.codegen.utils.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.querydsl.codegen.utils.model.Type in project querydsl by querydsl.
the class AbstractQuerydslProcessor method getClassName.
protected String getClassName(EntityType model) {
Type type = conf.getTypeMappings().getPathType(model, model, true);
String packageName = type.getPackageName();
return packageName.isEmpty() ? type.getSimpleName() : (packageName + "." + type.getSimpleName());
}
use of com.querydsl.codegen.utils.model.Type in project querydsl by querydsl.
the class MetaDataTest method setUp.
@Before
public void setUp() {
NamingStrategy namingStrategy = new DefaultNamingStrategy();
String packageName = "com.myproject.domain";
String tableName = "vwServiceName";
String className = namingStrategy.getClassName(tableName);
Type classTypeModel = new SimpleType(TypeCategory.ENTITY, packageName + "." + className, packageName, className, false, false);
classModel = new EntityType(classTypeModel);
// classModel.addAnnotation(new TableImpl(namingStrategy.normalizeTableName(tableName)));
classModel.getData().put("table", namingStrategy.normalizeTableName(tableName));
}
use of com.querydsl.codegen.utils.model.Type in project querydsl by querydsl.
the class MetaDataSerializer method serializeForeignKeys.
protected void serializeForeignKeys(EntityType model, CodeWriter writer, Collection<? extends KeyData> foreignKeys, boolean inverse) throws IOException {
for (KeyData foreignKey : foreignKeys) {
String fieldName;
if (inverse) {
fieldName = namingStrategy.getPropertyNameForInverseForeignKey(foreignKey.getName(), model);
} else {
fieldName = namingStrategy.getPropertyNameForForeignKey(foreignKey.getName(), model);
}
StringBuilder value = new StringBuilder();
if (inverse) {
value.append("createInvForeignKey(");
} else {
value.append("createForeignKey(");
}
if (foreignKey.getForeignColumns().size() == 1) {
value.append(namingStrategy.getPropertyName(foreignKey.getForeignColumns().get(0), model));
value.append(", \"").append(foreignKey.getParentColumns().get(0)).append("\"");
} else {
StringBuilder local = new StringBuilder();
StringBuilder foreign = new StringBuilder();
for (int i = 0; i < foreignKey.getForeignColumns().size(); i++) {
if (i > 0) {
local.append(", ");
foreign.append(", ");
}
local.append(namingStrategy.getPropertyName(foreignKey.getForeignColumns().get(i), model));
foreign.append("\"").append(foreignKey.getParentColumns().get(i)).append("\"");
}
value.append("Arrays.asList(").append(local).append("), Arrays.asList(").append(foreign).append(")");
}
value.append(")");
Type type = new ClassType(ForeignKey.class, foreignKey.getType());
writer.publicFinal(type, fieldName, value.toString());
}
}
Aggregations