Search in sources :

Example 16 with Parameter

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());
}
Also used : Parameter(com.querydsl.codegen.utils.model.Parameter) Test(org.junit.Test)

Example 17 with Parameter

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;
}
Also used : DOT(com.querydsl.codegen.utils.Symbols.DOT) Parameter(com.querydsl.codegen.utils.model.Parameter)

Example 18 with Parameter

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"));
}
Also used : SimpleType(com.querydsl.codegen.utils.model.SimpleType) Type(com.querydsl.codegen.utils.model.Type) SimpleType(com.querydsl.codegen.utils.model.SimpleType) StringWriter(java.io.StringWriter) Constructor(com.querydsl.codegen.utils.model.Constructor) JavaWriter(com.querydsl.codegen.utils.JavaWriter) Parameter(com.querydsl.codegen.utils.model.Parameter) StringWriter(java.io.StringWriter) Writer(java.io.Writer) JavaWriter(com.querydsl.codegen.utils.JavaWriter) Test(org.junit.Test)

Example 19 with Parameter

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));
        }
    }
}
Also used : QueryType(com.querydsl.core.annotations.QueryType) Type(com.querydsl.codegen.utils.model.Type) PropertyType(com.querydsl.core.annotations.PropertyType) ArrayList(java.util.ArrayList) Parameter(com.querydsl.codegen.utils.model.Parameter) QueryType(com.querydsl.core.annotations.QueryType) Annotation(java.lang.annotation.Annotation)

Aggregations

Parameter (com.querydsl.codegen.utils.model.Parameter)19 Test (org.junit.Test)11 Type (com.querydsl.codegen.utils.model.Type)7 ClassType (com.querydsl.codegen.utils.model.ClassType)5 SimpleType (com.querydsl.codegen.utils.model.SimpleType)5 ArrayList (java.util.ArrayList)4 StringWriter (java.io.StringWriter)3 Constructor (com.querydsl.codegen.utils.model.Constructor)2 PropertyType (com.querydsl.core.annotations.PropertyType)2 QueryType (com.querydsl.core.annotations.QueryType)2 Annotation (java.lang.annotation.Annotation)2 Map (java.util.Map)2 EntityType (com.querydsl.codegen.EntityType)1 JavaWriter (com.querydsl.codegen.utils.JavaWriter)1 ScalaWriter (com.querydsl.codegen.utils.ScalaWriter)1 DOT (com.querydsl.codegen.utils.Symbols.DOT)1 QueryDelegate (com.querydsl.core.annotations.QueryDelegate)1 Expression (com.querydsl.core.types.Expression)1 Writer (java.io.Writer)1 Method (java.lang.reflect.Method)1