use of com.querydsl.codegen.utils.model.ClassType in project querydsl by querydsl.
the class ScalaTypeDump method test.
@Test
@Ignore
public void test() throws IOException {
List<Class<?>> classes = new ArrayList<Class<?>>();
classes.add(SimpleExpression.class);
classes.add(ComparableExpression.class);
classes.add(BooleanExpression.class);
classes.add(StringExpression.class);
classes.add(TemporalExpression.class);
classes.add(TimeExpression.class);
classes.add(DateTimeExpression.class);
classes.add(DateExpression.class);
classes.add(EnumExpression.class);
classes.add(NumberExpression.class);
StringWriter w = new StringWriter();
ScalaWriter writer = new ScalaWriter(w);
writer.packageDecl("com.querydsl.scala");
writer.imports(Expression.class.getPackage());
for (Class<?> cl : classes) {
Type type = new ClassType(cl);
Type superClass = new ClassType(cl.getSuperclass());
writer.beginClass(type, superClass);
for (Method m : cl.getDeclaredMethods()) {
List<Parameter> params = new ArrayList<Parameter>();
for (Class<?> paramType : m.getParameterTypes()) {
params.add(new Parameter("arg" + params.size(), new ClassType(paramType)));
}
Type returnType = new ClassType(m.getReturnType());
writer.beginPublicMethod(returnType, ":" + m.getName(), params.toArray(new Parameter[0]));
writer.end();
}
writer.end();
}
System.out.println(w);
}
use of com.querydsl.codegen.utils.model.ClassType in project querydsl by querydsl.
the class TypeMappingsTest method getPathType_of_innerClass.
@Test
public void getPathType_of_innerClass() {
TypeMappings typeMappings = new JavaTypeMappings();
EntityType model = new EntityType(new ClassType(TypeMappingsTest.class));
EntityType type = new EntityType(new ClassType(Entity.class));
typeMappings.register(type, new QueryTypeFactoryImpl("Q", "", "").create(type));
Type pathType = typeMappings.getPathType(type, model, false);
assertEquals("QTypeMappingsTest_Entity", pathType.getSimpleName());
}
use of com.querydsl.codegen.utils.model.ClassType in project querydsl by querydsl.
the class DefaultEvaluatorFactory method createEvaluator.
/**
* Create an Evaluator for the given source and filter
*
* @param <T>
* @param source source of the query
* @param filter filter of the query
* @return evaluator
*/
public <T> Evaluator<List<T>> createEvaluator(QueryMetadata metadata, Expression<? extends T> source, Predicate filter) {
String typeName = ClassUtils.getName(source.getType());
CollQuerySerializer ser = new CollQuerySerializer(templates);
ser.append("java.util.List<" + typeName + "> rv = new java.util.ArrayList<" + typeName + ">();\n");
ser.append("for (" + typeName + " " + source + " : " + source + "_) {\n");
ser.append(" try {\n");
ser.append(" if (").handle(filter).append(") {\n");
ser.append(" rv.add(" + source + ");\n");
ser.append(" }\n");
ser.append(" } catch (NullPointerException npe) { }\n");
ser.append("}\n");
ser.append("return rv;");
Map<Object, String> constantToLabel = ser.getConstantToLabel();
Map<String, Object> constants = getConstants(metadata, constantToLabel);
Type sourceType = new ClassType(TypeCategory.SIMPLE, source.getType());
ClassType sourceListType = new ClassType(TypeCategory.SIMPLE, Iterable.class, sourceType);
return factory.createEvaluator(ser.toString(), sourceListType, new String[] { source + "_" }, new Type[] { sourceListType }, new Class<?>[] { Iterable.class }, constants);
}
use of com.querydsl.codegen.utils.model.ClassType in project querydsl by querydsl.
the class EntityTypeTest method uncapSimpleName_escaped2.
@Test
public void uncapSimpleName_escaped2() {
ClassType typeModel = new ClassType(TypeCategory.ENTITY, Object.class);
EntityType entityModel = new EntityType(typeModel);
assertEquals("object", entityModel.getModifiedSimpleName());
entityModel.addProperty(new Property(entityModel, "OBJECT", "object", typeModel, Collections.<String>emptyList(), false));
assertEquals("object1", entityModel.getModifiedSimpleName());
}
use of com.querydsl.codegen.utils.model.ClassType in project querydsl by querydsl.
the class EntityTypeTest method uncapSimpleName_escaped3.
@Test
public void uncapSimpleName_escaped3() {
ClassType typeModel = new ClassType(TypeCategory.ENTITY, Void.class);
EntityType entityModel = new EntityType(typeModel);
assertEquals("void$", entityModel.getModifiedSimpleName());
}
Aggregations