public static ContextualStatementBuilder nestedCall(final Statement statement) { return StatementBuilder.create().nestedCall(statement); }
public static ContextualStatementBuilder nestedCall(final Statement statement) { return StatementBuilder.create().nestedCall(statement); }
methodBody = Stmt.create(subContext).nestedCall(makeSnapshotAsSubclass( retval, method.getReturnType(), method.getReturnType(), methodBodyCallback, typesToRecurseOn, existingSnapshots, unfinishedSnapshots)).returnValue();
methodBody = Stmt.create(subContext).nestedCall(makeSnapshotAsSubclass( retval, method.getReturnType(), method.getReturnType(), methodBodyCallback, typesToRecurseOn, existingSnapshots, unfinishedSnapshots)).returnValue();
@Test public void testNestedCall() { final String s = StatementBuilder.create() .nestedCall( StatementBuilder.create().declareVariable("n", Integer.class).loadVariable("n").invoke("toString")) .invoke("getBytes") .toJavaString(); assertEquals("failed to generate nested call", "n.toString().getBytes()", s); }
@Test public void testAssignInvalidField() { try { final String s = Stmt.create(Context.create().autoImport()).nestedCall( Stmt.newObject(Foo.class)) .loadField("invalid") .assignValue("test") .toJavaString(); fail("expected UndefinedFieldException"); } catch (UndefinedFieldException e) { // expected } }
@Test public void testAssignField() { final String s = Stmt.create(Context.create().autoImport()).nestedCall( Stmt.newObject(Foo.class)).loadField("bar").loadField("name").assignValue("test").toJavaString(); assertEquals("failed to generate nested field assignment", "new Foo().bar.name = \"test\";", s); }