use of com.querydsl.codegen.utils.model.Parameter in project querydsl by querydsl.
the class JavaWriterTest method Constructors.
@Test
public void Constructors() throws IOException {
writer.beginClass(testType);
writer.beginConstructor(Arrays.asList(new Parameter("a", Types.STRING), new Parameter("b", Types.STRING)), transformer);
writer.end();
writer.beginConstructor(new Parameter("a", Types.STRING));
writer.end();
writer.end();
match("/testConstructors", w.toString());
}
use of com.querydsl.codegen.utils.model.Parameter in project querydsl by querydsl.
the class ScalaWriter method transform.
private <T> Parameter[] transform(Collection<T> parameters, Function<T, Parameter> transformer) {
Parameter[] rv = new Parameter[parameters.size()];
int i = 0;
for (T value : parameters) {
rv[i++] = transformer.apply(value);
}
return rv;
}
use of com.querydsl.codegen.utils.model.Parameter in project querydsl by querydsl.
the class ProjectionSerializerTest method constructors.
@Test
public void constructors() throws IOException {
Type typeModel = new SimpleType(TypeCategory.ENTITY, "com.querydsl.DomainClass", "com.querydsl", "DomainClass", false, false);
EntityType type = new EntityType(typeModel);
// constructor
Parameter firstName = new Parameter("firstName", Types.STRING);
Parameter lastName = new Parameter("lastName", Types.STRING);
Parameter age = new Parameter("age", Types.INTEGER);
type.addConstructor(new Constructor(Arrays.asList(firstName, lastName, age)));
Writer writer = new StringWriter();
ProjectionSerializer serializer = new DefaultProjectionSerializer(new JavaTypeMappings());
serializer.serialize(type, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer));
assertTrue(writer.toString().contains("Expression<String> firstName"));
assertTrue(writer.toString().contains("Expression<String> lastName"));
assertTrue(writer.toString().contains("Expression<Integer> age"));
}
use of com.querydsl.codegen.utils.model.Parameter in project querydsl by querydsl.
the class GenericExporter method addConstructors.
private void addConstructors(Class<?> cl, EntityType type) {
for (Constructor<?> constructor : cl.getConstructors()) {
if (constructor.isAnnotationPresent(QueryProjection.class)) {
List<Parameter> parameters = new ArrayList<>();
for (int i = 0; i < constructor.getParameterTypes().length; i++) {
Type parameterType = typeFactory.get(constructor.getParameterTypes()[i], constructor.getGenericParameterTypes()[i]);
for (Annotation annotation : constructor.getParameterAnnotations()[i]) {
if (annotation.annotationType().equals(QueryType.class)) {
QueryType queryType = (QueryType) annotation;
parameterType = parameterType.as(TypeCategory.valueOf(queryType.value().name()));
}
}
parameters.add(new Parameter("param" + i, parameterType));
}
type.addConstructor(new com.querydsl.codegen.utils.model.Constructor(parameters));
}
}
}
Aggregations