use of com.querydsl.codegen.utils.model.Type in project querydsl by querydsl.
the class ScalaWriter method getGenericName.
@Override
public String getGenericName(boolean asArgType, Type type) {
if (type.getParameters().isEmpty()) {
return getRawName(type);
} else {
StringBuilder builder = new StringBuilder();
builder.append(getRawName(type));
builder.append("[");
boolean first = true;
String fullName = type.getFullName();
for (Type parameter : type.getParameters()) {
if (!first) {
builder.append(", ");
}
if (parameter == null || parameter.getFullName().equals(fullName)) {
builder.append("_");
} else {
builder.append(getGenericName(false, parameter));
}
first = false;
}
builder.append("]");
return builder.toString();
}
}
use of com.querydsl.codegen.utils.model.Type in project querydsl by querydsl.
the class AbstractEvaluatorFactory method createSource.
/**
* @param source
* @param projectionType
* @param names
* @param types
* @param id
* @param constants
* @return
* @throws IOException
*/
protected String createSource(String source, ClassType projectionType, String[] names, Type[] types, String id, Map<String, Object> constants) throws IOException {
// create source
StringWriter writer = new StringWriter();
JavaWriter javaw = new JavaWriter(writer);
SimpleType idType = new SimpleType(id, "", id);
javaw.beginClass(idType, null);
Parameter[] params = new Parameter[names.length + constants.size()];
for (int i = 0; i < names.length; i++) {
params[i] = new Parameter(names[i], types[i]);
}
int i = names.length;
for (Map.Entry<String, Object> entry : constants.entrySet()) {
Type type = new ClassType(TypeCategory.SIMPLE, ClassUtils.normalize(entry.getValue().getClass()));
params[i++] = new Parameter(entry.getKey(), type);
}
javaw.beginStaticMethod(projectionType, "eval", params);
javaw.append(source);
javaw.end();
javaw.end();
return writer.toString();
}
use of com.querydsl.codegen.utils.model.Type in project querydsl by querydsl.
the class PropertyTest method equals_and_hashCode.
@Test
public void equals_and_hashCode() {
Type typeModel = new SimpleType(TypeCategory.ENTITY, "com.querydsl.DomainClass", "com.querydsl", "DomainClass", false, false);
EntityType type = new EntityType(typeModel);
Property p1 = new Property(type, "property", type, Collections.<String>emptyList());
Property p2 = new Property(type, "property", type, Collections.<String>emptyList());
assertEquals(p1, p1);
assertEquals(p1, p2);
assertEquals(p1.hashCode(), p2.hashCode());
}
use of com.querydsl.codegen.utils.model.Type 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.Type 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());
}
Aggregations