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;
}
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));
}
}
}
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);
}
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));
}
}
}
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;
}
Aggregations