Search in sources :

Example 6 with Parameter

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"));
}
Also used : Parameter(com.querydsl.codegen.utils.model.Parameter) Test(org.junit.Test)

Example 7 with Parameter

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());
}
Also used : Parameter(com.querydsl.codegen.utils.model.Parameter) Test(org.junit.Test)

Example 8 with Parameter

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) {"));
}
Also used : SimpleType(com.querydsl.codegen.utils.model.SimpleType) Parameter(com.querydsl.codegen.utils.model.Parameter) ClassType(com.querydsl.codegen.utils.model.ClassType) Test(org.junit.Test)

Example 9 with Parameter

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());
}
Also used : Parameter(com.querydsl.codegen.utils.model.Parameter) Test(org.junit.Test)

Example 10 with Parameter

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();
}
Also used : SimpleType(com.querydsl.codegen.utils.model.SimpleType) Type(com.querydsl.codegen.utils.model.Type) ClassType(com.querydsl.codegen.utils.model.ClassType) SimpleType(com.querydsl.codegen.utils.model.SimpleType) StringWriter(java.io.StringWriter) Parameter(com.querydsl.codegen.utils.model.Parameter) ClassType(com.querydsl.codegen.utils.model.ClassType) Map(java.util.Map) WeakHashMap(java.util.WeakHashMap)

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