Search in sources :

Example 1 with Constructor

use of com.querydsl.codegen.utils.model.Constructor in project querydsl by querydsl.

the class TypeElementHandler method handleConstructors.

private void handleConstructors(EntityType entityType, List<? extends Element> elements) {
    for (ExecutableElement constructor : ElementFilter.constructorsIn(elements)) {
        if (configuration.isValidConstructor(constructor)) {
            List<Parameter> parameters = transformParams(constructor.getParameters());
            entityType.addConstructor(new Constructor(parameters));
        }
    }
}
Also used : Constructor(com.querydsl.codegen.utils.model.Constructor) ExecutableElement(javax.lang.model.element.ExecutableElement) Parameter(com.querydsl.codegen.utils.model.Parameter)

Example 2 with Constructor

use of com.querydsl.codegen.utils.model.Constructor 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)

Aggregations

Constructor (com.querydsl.codegen.utils.model.Constructor)2 Parameter (com.querydsl.codegen.utils.model.Parameter)2 JavaWriter (com.querydsl.codegen.utils.JavaWriter)1 SimpleType (com.querydsl.codegen.utils.model.SimpleType)1 Type (com.querydsl.codegen.utils.model.Type)1 StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1 ExecutableElement (javax.lang.model.element.ExecutableElement)1 Test (org.junit.Test)1