public static Statement newObject(final MetaClass type, Object... parms) { return StatementBuilder.create().newObject(type, parms); }
public static ObjectBuilder newObject(final MetaClass type) { return StatementBuilder.create().newObject(type); }
public static ObjectBuilder newObject(final TypeLiteral<?> type) { return StatementBuilder.create().newObject(type); }
public static Statement newObject(final MetaClass type, Object... parms) { return StatementBuilder.create().newObject(type, parms); }
public static ObjectBuilder newObject(final Class<?> type) { return StatementBuilder.create().newObject(type); }
public static ObjectBuilder newObject(final TypeLiteral<?> type) { return StatementBuilder.create().newObject(type); }
public static ObjectBuilder newObject(final MetaClass type) { return StatementBuilder.create().newObject(type); }
public static Statement newObject(final Class<?> type, Object... parms) { return StatementBuilder.create().newObject(type, parms); }
public static Statement newObject(final TypeLiteral<?> type, Object... parms) { return StatementBuilder.create().newObject(type, parms); }
public static Statement newObject(final Class<?> type, Object... parms) { return StatementBuilder.create().newObject(type, parms); }
public static ObjectBuilder newObject(final Class<?> type) { return StatementBuilder.create().newObject(type); }
public static Statement newObject(final TypeLiteral<?> type, Object... parms) { return StatementBuilder.create().newObject(type, parms); }
@Test public void testObjectCreationWithParameterizedType() { final String s = StatementBuilder.create().newObject(new TypeLiteral<ArrayList<String>>() { }).toJavaString(); assertEquals("failed to generate new object with parameterized type", "new java.util.ArrayList<String>()", s); }
@Test public void testObjectCreationWithLiteralParameter() { final String s = StatementBuilder.create().newObject(String.class).withParameters("original").toJavaString(); assertEquals("failed to generate new object with parameters", "new String(\"original\")", s); }
@Test public void testObjectCreationWithAutoImportedParameterizedType() { final Context c = Context.create().autoImport(); final String s = StatementBuilder.create(c).newObject(new TypeLiteral<ArrayList<Date>>() { }).toJavaString(); assertEquals("failed to generate new object with parameterized type", "new ArrayList<Date>()", s); }
@Test public void testForeachLoopWithStringInList() { Statement createObject = StatementBuilder.create().newObject(String.class); Statement createAnotherObject = StatementBuilder.create().newObject(Object.class); String foreachWithList = StatementBuilder.create() .declareVariable("list", List.class) .loadVariable("list") .foreach("element") .append(createObject) .append(createAnotherObject) .finish().toJavaString(); assertEquals("Failed to generate foreach loop using a List<?>", FOREACH_OBJECT_IN_LIST_TWO_STATEMENTS, foreachWithList); }
@Test public void testObjectCreationWithFullyQualifiedParameterizedTypeAndClassImport() { final Context c = Context.create().addImport(MetaClassFactory.get(ArrayList.class)); final String s = StatementBuilder.create(c).newObject(new TypeLiteral<ArrayList<Date>>() { }).toJavaString(); assertEquals("failed to generate new object with parameterized type", "new ArrayList<java.util.Date>()", s); }
@Test public void testObjectCreationWithParameterizedTypeAndClassImport() { final Context c = Context.create().addImport(MetaClassFactory.get(ArrayList.class)); final String s = StatementBuilder.create(c).newObject(new TypeLiteral<ArrayList<String>>() { }).toJavaString(); assertEquals("failed to generate new object with parameterized type", "new ArrayList<String>()", s); }
@Test public void testObjectCreationWithNestedParameterizedTypeAndClassImports() { final Context c = Context.create() .addImport(MetaClassFactory.get(ArrayList.class)) .addImport(MetaClassFactory.get(HashMap.class)); final String s = StatementBuilder.create(c) .newObject(new TypeLiteral<ArrayList<ArrayList<HashMap<String, Integer>>>>() { }).toJavaString(); assertEquals("failed to generate new object with parameterized type", "new ArrayList<ArrayList<HashMap<String, Integer>>>()", s); }
@Test public void testForeachLoopWithStringInArray() { Statement createObject = StatementBuilder.create().newObject(String.class); String foreachWithStringArray = StatementBuilder.create(Context.create().addVariable("list", String[].class)) .loadVariable("list") .foreach("element") .append(createObject) .finish() .toJavaString(); assertEquals("Failed to generate foreach loop using a String[]", FOREACH_STRING_IN_ARRAY_ONE_STATEMENT, foreachWithStringArray); }