Search in sources :

Example 1 with Parameter

use of com.mysema.codegen.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 : NoType(javax.lang.model.type.NoType) Type(com.mysema.codegen.model.Type) DeclaredType(javax.lang.model.type.DeclaredType) TypeMirror(javax.lang.model.type.TypeMirror) QueryDelegate(com.querydsl.core.annotations.QueryDelegate) Parameter(com.mysema.codegen.model.Parameter)

Example 2 with Parameter

use of com.mysema.codegen.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.mysema.codegen.model.Constructor) ExecutableElement(javax.lang.model.element.ExecutableElement) Parameter(com.mysema.codegen.model.Parameter)

Example 3 with Parameter

use of com.mysema.codegen.model.Parameter 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[params.size()]));
            writer.end();
        }
        writer.end();
    }
    System.out.println(w);
}
Also used : ClassType(com.mysema.codegen.model.ClassType) Type(com.mysema.codegen.model.Type) StringWriter(java.io.StringWriter) Expression(com.querydsl.core.types.Expression) ArrayList(java.util.ArrayList) Parameter(com.mysema.codegen.model.Parameter) ScalaWriter(com.mysema.codegen.ScalaWriter) Method(java.lang.reflect.Method) ClassType(com.mysema.codegen.model.ClassType) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with Parameter

use of com.mysema.codegen.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 = Lists.newArrayList();
            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.mysema.codegen.model.Constructor(parameters));
        }
    }
}
Also used : Type(com.mysema.codegen.model.Type) Parameter(com.mysema.codegen.model.Parameter) Annotation(java.lang.annotation.Annotation)

Example 5 with Parameter

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

the class TypeElementHandler method transformParams.

public List<Parameter> transformParams(List<? extends VariableElement> params) {
    List<Parameter> parameters = new ArrayList<Parameter>(params.size());
    for (VariableElement param : params) {
        Type paramType = getType(param);
        parameters.add(new Parameter(param.getSimpleName().toString(), paramType));
    }
    return parameters;
}
Also used : QueryType(com.querydsl.core.annotations.QueryType) Type(com.mysema.codegen.model.Type) PropertyType(com.querydsl.core.annotations.PropertyType) EntityType(com.querydsl.codegen.EntityType) Parameter(com.mysema.codegen.model.Parameter) VariableElement(javax.lang.model.element.VariableElement)

Aggregations

Parameter (com.mysema.codegen.model.Parameter)5 Type (com.mysema.codegen.model.Type)4 ScalaWriter (com.mysema.codegen.ScalaWriter)1 ClassType (com.mysema.codegen.model.ClassType)1 Constructor (com.mysema.codegen.model.Constructor)1 EntityType (com.querydsl.codegen.EntityType)1 PropertyType (com.querydsl.core.annotations.PropertyType)1 QueryDelegate (com.querydsl.core.annotations.QueryDelegate)1 QueryType (com.querydsl.core.annotations.QueryType)1 Expression (com.querydsl.core.types.Expression)1 StringWriter (java.io.StringWriter)1 Annotation (java.lang.annotation.Annotation)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 ExecutableElement (javax.lang.model.element.ExecutableElement)1 VariableElement (javax.lang.model.element.VariableElement)1 DeclaredType (javax.lang.model.type.DeclaredType)1 NoType (javax.lang.model.type.NoType)1 TypeMirror (javax.lang.model.type.TypeMirror)1 Ignore (org.junit.Ignore)1