use of com.querydsl.codegen.utils.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 = Arrays.asList(annotations.getAnnotation(QueryInit.class).value());
}
return new Property(entityType, name, propertyType, inits);
}
use of com.querydsl.codegen.utils.model.Type in project querydsl by querydsl.
the class BeanSerializer method serialize.
@Override
public void serialize(EntityType model, SerializerConfig serializerConfig, CodeWriter writer) throws IOException {
String simpleName = model.getSimpleName();
// package
if (!model.getPackageName().isEmpty()) {
writer.packageDecl(model.getPackageName());
}
// imports
Set<String> importedClasses = getAnnotationTypes(model);
for (Type iface : interfaces) {
importedClasses.add(iface.getFullName());
}
importedClasses.add(generatedAnnotationClass.getName());
if (model.hasLists()) {
importedClasses.add(List.class.getName());
}
if (model.hasCollections()) {
importedClasses.add(Collection.class.getName());
}
if (model.hasSets()) {
importedClasses.add(Set.class.getName());
}
if (model.hasMaps()) {
importedClasses.add(Map.class.getName());
}
if (addToString && model.hasArrays()) {
importedClasses.add(Arrays.class.getName());
}
writer.importClasses(importedClasses.toArray(new String[0]));
// javadoc
writer.javadoc(simpleName + javadocSuffix);
// header
for (Annotation annotation : model.getAnnotations()) {
writer.annotation(annotation);
}
writer.line("@", generatedAnnotationClass.getSimpleName(), "(\"", getClass().getName(), "\")");
if (!interfaces.isEmpty()) {
Type superType = null;
if (printSupertype && model.getSuperType() != null) {
superType = model.getSuperType().getType();
}
Type[] ifaces = interfaces.toArray(new Type[0]);
writer.beginClass(model, superType, ifaces);
} else if (printSupertype && model.getSuperType() != null) {
writer.beginClass(model, model.getSuperType().getType());
} else {
writer.beginClass(model);
}
bodyStart(model, writer);
if (addFullConstructor) {
addFullConstructor(model, writer);
}
// fields
for (Property property : model.getProperties()) {
if (propertyAnnotations) {
for (Annotation annotation : property.getAnnotations()) {
writer.annotation(annotation);
}
}
writer.privateField(property.getType(), property.getEscapedName());
}
// accessors
for (Property property : model.getProperties()) {
String propertyName = property.getEscapedName();
// getter
writer.beginPublicMethod(property.getType(), "get" + BeanUtils.capitalize(propertyName));
writer.line("return ", propertyName, ";");
writer.end();
// setter
Parameter parameter = new Parameter(propertyName, property.getType());
writer.beginPublicMethod(Types.VOID, "set" + BeanUtils.capitalize(propertyName), parameter);
writer.line("this.", propertyName, " = ", propertyName, ";");
writer.end();
}
if (addToString) {
addToString(model, writer);
}
bodyEnd(model, writer);
writer.end();
}
use of com.querydsl.codegen.utils.model.Type in project querydsl by querydsl.
the class DefaultEmbeddableSerializer method introClassHeader.
@Override
@SuppressWarnings(UNCHECKED)
protected void introClassHeader(CodeWriter writer, EntityType model) throws IOException {
Type queryType = typeMappings.getPathType(model, model, true);
TypeCategory category = model.getOriginalCategory();
Class<? extends Path> pathType;
if (model.getProperties().isEmpty()) {
switch(category) {
case COMPARABLE:
pathType = ComparablePath.class;
break;
case ENUM:
pathType = EnumPath.class;
break;
case DATE:
pathType = DatePath.class;
break;
case DATETIME:
pathType = DateTimePath.class;
break;
case TIME:
pathType = TimePath.class;
break;
case NUMERIC:
pathType = NumberPath.class;
break;
case STRING:
pathType = StringPath.class;
break;
case BOOLEAN:
pathType = BooleanPath.class;
break;
default:
pathType = BeanPath.class;
}
} else {
pathType = BeanPath.class;
}
for (Annotation annotation : model.getAnnotations()) {
writer.annotation(annotation);
}
writer.line("@", generatedAnnotationClass.getSimpleName(), "(\"", getClass().getName(), "\")");
if (category == TypeCategory.BOOLEAN || category == TypeCategory.STRING) {
writer.beginClass(queryType, new ClassType(pathType));
} else {
writer.beginClass(queryType, new ClassType(category, pathType, model));
}
// TODO : generate proper serialVersionUID here
writer.privateStaticFinal(Types.LONG_P, "serialVersionUID", model.hashCode() + "L");
}
use of com.querydsl.codegen.utils.model.Type in project querydsl by querydsl.
the class AbstractEvaluatorFactory method toId.
protected String toId(String source, Class<?> returnType, Type[] types, Collection<Object> constants) {
StringBuilder b = new StringBuilder(128);
b.append("Q");
b.append("_").append(source.hashCode());
b.append("_").append(returnType.getName().hashCode());
for (Type type : types) {
b.append("_").append(type.getFullName().hashCode());
}
for (Object constant : constants) {
b.append("_").append(constant.getClass().getName().hashCode());
}
return b.toString().replace('-', '0');
}
use of com.querydsl.codegen.utils.model.Type in project querydsl by querydsl.
the class InnerClassesTest method DirectParameter.
@Test
public void DirectParameter() throws IOException {
Type entityType = new ClassType(Entity.class);
Type type = new SimpleType("com.querydsl.codegen.utils.gen.QEntity", "com.querydsl.codegen.utils.gen", "QEntity", entityType);
StringWriter str = new StringWriter();
JavaWriter writer = new JavaWriter(str);
writer.beginClass(type);
writer.end();
System.err.println(str.toString());
}
Aggregations