use of com.querydsl.codegen.utils.model.Parameter in project querydsl by querydsl.
the class ScalaWriterTest method ReservedWords.
@Test
public void ReservedWords() throws IOException {
writer.beginClass(testType);
writer.beginConstructor(new Parameter("type", Types.INT));
writer.end();
writer.publicField(testType, "class");
writer.beginPublicMethod(testType, "var");
writer.end();
writer.end();
System.out.println(w);
assertTrue(w.toString().contains("`type`: Int"));
assertTrue(w.toString().contains("`class`: JavaWriterTest"));
assertTrue(w.toString().contains("`var`(): JavaWriterTest"));
}
use of com.querydsl.codegen.utils.model.Parameter in project querydsl by querydsl.
the class ScalaWriterTest method CaseClass.
@Test
public void CaseClass() throws IOException {
writer.caseClass("TestType", new Parameter("a", Types.STRING), new Parameter("b", Types.STRING));
System.out.println(w);
assertEquals("case class TestType(a: String, b: String)\n", w.toString());
}
use of com.querydsl.codegen.utils.model.Parameter in project querydsl by querydsl.
the class JavaWriterTest method Arrays.
@Test
public void Arrays() throws IOException {
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("String[] stringArray;"));
assertTrue(w.toString().contains("public void main(String[] args) {"));
assertTrue(w.toString().contains("public void main2(String[] args) {"));
}
use of com.querydsl.codegen.utils.model.Parameter in project querydsl by querydsl.
the class JavaWriterTest method Inner_Classes.
@Test
public void Inner_Classes() throws IOException {
writer.beginClass(testType);
writer.beginClass(testType2);
writer.end();
writer.beginConstructor(new Parameter("a", Types.STRING));
writer.end();
writer.end();
match("/testInnerClasses", w.toString());
}
use of com.querydsl.codegen.utils.model.Parameter in project querydsl by querydsl.
the class AbstractEvaluatorFactory method createSource.
/**
* @param source
* @param projectionType
* @param names
* @param types
* @param id
* @param constants
* @return
* @throws IOException
*/
protected String createSource(String source, ClassType projectionType, String[] names, Type[] types, String id, Map<String, Object> constants) throws IOException {
// create source
StringWriter writer = new StringWriter();
JavaWriter javaw = new JavaWriter(writer);
SimpleType idType = new SimpleType(id, "", id);
javaw.beginClass(idType, null);
Parameter[] params = new Parameter[names.length + constants.size()];
for (int i = 0; i < names.length; i++) {
params[i] = new Parameter(names[i], types[i]);
}
int i = names.length;
for (Map.Entry<String, Object> entry : constants.entrySet()) {
Type type = new ClassType(TypeCategory.SIMPLE, ClassUtils.normalize(entry.getValue().getClass()));
params[i++] = new Parameter(entry.getKey(), type);
}
javaw.beginStaticMethod(projectionType, "eval", params);
javaw.append(source);
javaw.end();
javaw.end();
return writer.toString();
}
Aggregations