use of com.querydsl.codegen.utils.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[0]));
writer.end();
}
writer.end();
}
System.out.println(w);
}
use of com.querydsl.codegen.utils.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;
}
use of com.querydsl.codegen.utils.model.Parameter in project querydsl by querydsl.
the class BeanSerializer method serialize.
@Override
public void serialize(EntityType model, SerializerConfig serializerConfig, CodeWriter writer) throws IOException {
String simpleName = model.getSimpleName();
// package
if (!model.getPackageName().isEmpty()) {
writer.packageDecl(model.getPackageName());
}
// imports
Set<String> importedClasses = getAnnotationTypes(model);
for (Type iface : interfaces) {
importedClasses.add(iface.getFullName());
}
importedClasses.add(generatedAnnotationClass.getName());
if (model.hasLists()) {
importedClasses.add(List.class.getName());
}
if (model.hasCollections()) {
importedClasses.add(Collection.class.getName());
}
if (model.hasSets()) {
importedClasses.add(Set.class.getName());
}
if (model.hasMaps()) {
importedClasses.add(Map.class.getName());
}
if (addToString && model.hasArrays()) {
importedClasses.add(Arrays.class.getName());
}
writer.importClasses(importedClasses.toArray(new String[0]));
// javadoc
writer.javadoc(simpleName + javadocSuffix);
// header
for (Annotation annotation : model.getAnnotations()) {
writer.annotation(annotation);
}
writer.line("@", generatedAnnotationClass.getSimpleName(), "(\"", getClass().getName(), "\")");
if (!interfaces.isEmpty()) {
Type superType = null;
if (printSupertype && model.getSuperType() != null) {
superType = model.getSuperType().getType();
}
Type[] ifaces = interfaces.toArray(new Type[0]);
writer.beginClass(model, superType, ifaces);
} else if (printSupertype && model.getSuperType() != null) {
writer.beginClass(model, model.getSuperType().getType());
} else {
writer.beginClass(model);
}
bodyStart(model, writer);
if (addFullConstructor) {
addFullConstructor(model, writer);
}
// fields
for (Property property : model.getProperties()) {
if (propertyAnnotations) {
for (Annotation annotation : property.getAnnotations()) {
writer.annotation(annotation);
}
}
writer.privateField(property.getType(), property.getEscapedName());
}
// accessors
for (Property property : model.getProperties()) {
String propertyName = property.getEscapedName();
// getter
writer.beginPublicMethod(property.getType(), "get" + BeanUtils.capitalize(propertyName));
writer.line("return ", propertyName, ";");
writer.end();
// setter
Parameter parameter = new Parameter(propertyName, property.getType());
writer.beginPublicMethod(Types.VOID, "set" + BeanUtils.capitalize(propertyName), parameter);
writer.line("this.", propertyName, " = ", propertyName, ";");
writer.end();
}
if (addToString) {
addToString(model, writer);
}
bodyEnd(model, writer);
writer.end();
}
use of com.querydsl.codegen.utils.model.Parameter in project querydsl by querydsl.
the class ScalaWriterTest method Primitive.
@Test
public void Primitive() throws IOException {
writer.beginClass(testType);
writer.beginConstructor(new Parameter("a", Types.INT));
writer.end();
writer.end();
System.out.println(w);
assertTrue(w.toString().contains("def this(a: Int) {"));
}
use of com.querydsl.codegen.utils.model.Parameter in project querydsl by querydsl.
the class ScalaWriterTest method Arrays.
@Test
public void Arrays() throws IOException {
// def main(args: Array[String]) {
writer.beginClass(new SimpleType("Main"));
writer.field(Types.STRING.asArrayType(), "stringArray");
writer.beginPublicMethod(Types.VOID, "main", new Parameter("args", Types.STRING.asArrayType()));
writer.line("//");
writer.end();
writer.beginPublicMethod(Types.VOID, "main2", new Parameter("args", new ClassType(TypeCategory.ARRAY, String[].class)));
writer.line("//");
writer.end();
writer.end();
System.out.println(w);
assertTrue(w.toString().contains("var stringArray: Array[String]"));
assertTrue(w.toString().contains("def main(args: Array[String])"));
assertTrue(w.toString().contains("def main2(args: Array[String])"));
}
Aggregations