Search in sources :

Example 1 with Parameter

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

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

the class AbstractQuerydslProcessor method processDelegateMethods.

private Set<TypeElement> processDelegateMethods() {
    Set<? extends Element> delegateMethods = getElements(QueryDelegate.class);
    Set<TypeElement> typeElements = new HashSet<TypeElement>();
    for (Element delegateMethod : delegateMethods) {
        ExecutableElement method = (ExecutableElement) delegateMethod;
        Element element = delegateMethod.getEnclosingElement();
        String name = method.getSimpleName().toString();
        Type delegateType = typeFactory.getType(element.asType(), true);
        Type returnType = typeFactory.getType(method.getReturnType(), true);
        List<Parameter> parameters = elementHandler.transformParams(method.getParameters());
        // remove first element
        parameters = parameters.subList(1, parameters.size());
        EntityType entityType = null;
        for (AnnotationMirror annotation : delegateMethod.getAnnotationMirrors()) {
            if (TypeUtils.isAnnotationMirrorOfType(annotation, QueryDelegate.class)) {
                TypeMirror type = TypeUtils.getAnnotationValueAsTypeMirror(annotation, "value");
                if (type != null) {
                    entityType = typeFactory.getEntityType(type, true);
                }
            }
        }
        if (entityType != null) {
            registerTypeElement(entityType.getFullName(), (TypeElement) element);
            entityType.addDelegate(new Delegate(entityType, delegateType, name, parameters, returnType));
            TypeElement typeElement = processingEnv.getElementUtils().getTypeElement(entityType.getFullName());
            boolean isAnnotated = false;
            for (Class<? extends Annotation> ann : conf.getEntityAnnotations()) {
                if (typeElement.getAnnotation(ann) != null) {
                    isAnnotated = true;
                }
            }
            if (isAnnotated) {
                // handle also properties of entity type
                typeElements.add(processingEnv.getElementUtils().getTypeElement(entityType.getFullName()));
            } else {
                // skip handling properties
                context.extensionTypes.put(entityType.getFullName(), entityType);
                context.allTypes.put(entityType.getFullName(), entityType);
            }
        }
    }
    return typeElements;
}
Also used : Type(com.querydsl.codegen.utils.model.Type) NoType(javax.lang.model.type.NoType) DeclaredType(javax.lang.model.type.DeclaredType) TypeMirror(javax.lang.model.type.TypeMirror) QueryDelegate(com.querydsl.core.annotations.QueryDelegate) Parameter(com.querydsl.codegen.utils.model.Parameter)

Example 3 with Parameter

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

the class MetaDataSerializer method constructorsForVariables.

@Override
protected void constructorsForVariables(CodeWriter writer, EntityType model) throws IOException {
    super.constructorsForVariables(writer, model);
    String localName = writer.getRawName(model);
    String genericName = writer.getGenericName(true, model);
    if (!localName.equals(genericName)) {
        writer.suppressWarnings("all");
    }
    writer.beginConstructor(new Parameter("variable", Types.STRING), new Parameter("schema", Types.STRING), new Parameter("table", Types.STRING));
    writer.line(SUPER, "(", writer.getClassConstant(localName) + COMMA + "forVariable(variable), schema, table);");
    constructorContent(writer, model);
    writer.end();
    writer.beginConstructor(new Parameter("variable", Types.STRING), new Parameter("schema", Types.STRING));
    writer.line(SUPER, "(", writer.getClassConstant(localName), COMMA, "forVariable(variable), schema, \"", model.getData().get("table").toString(), "\");");
    constructorContent(writer, model);
    writer.end();
}
Also used : Parameter(com.querydsl.codegen.utils.model.Parameter)

Example 4 with Parameter

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

the class ScalaWriterTest method BeanAccessors.

@Test
public void BeanAccessors() throws IOException {
    writer.beginClass(new SimpleType("Person"));
    writer.beginPublicMethod(Types.STRING, "getName");
    writer.line("\"Daniel Spiewak\"");
    writer.end();
    writer.beginPublicMethod(Types.VOID, "setName", new Parameter("name", Types.STRING));
    writer.line("//");
    writer.end();
    writer.end();
    System.out.println(w);
}
Also used : SimpleType(com.querydsl.codegen.utils.model.SimpleType) Parameter(com.querydsl.codegen.utils.model.Parameter) Test(org.junit.Test)

Example 5 with Parameter

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

the class ScalaWriterTest 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();
    System.out.println(w);
}
Also used : Parameter(com.querydsl.codegen.utils.model.Parameter) Test(org.junit.Test)

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