public void testLoop() throws Exception { ClassNode classNode = new ClassNode("Foo", ACC_PUBLIC, ClassHelper.OBJECT_TYPE); classNode.addConstructor(new ConstructorNode(ACC_PUBLIC, null)); Parameter[] parameters = {new Parameter(ClassHelper.OBJECT_TYPE.makeArray(), "coll")}; Statement loopStatement = createPrintlnStatement(new VariableExpression("i")); ForStatement statement = new ForStatement(new Parameter(ClassHelper.OBJECT_TYPE, "i"), new VariableExpression("coll"), loopStatement); classNode.addMethod(new MethodNode("iterateDemo", ACC_PUBLIC, ClassHelper.VOID_TYPE, parameters, ClassNode.EMPTY_ARRAY, statement)); Class fooClass = loadClass(classNode); assertTrue("Loaded a new class", fooClass != null); Object bean = fooClass.newInstance(); assertTrue("Managed to create bean", bean != null); System.out.println("################ Now about to invoke a method with looping"); Object[] array = {new Integer(1234), "abc", "def"}; try { InvokerHelper.invokeMethod(bean, "iterateDemo", new Object[]{array}); } catch (InvokerInvocationException e) { System.out.println("Caught: " + e.getCause()); e.getCause().printStackTrace(); fail("Should not have thrown an exception"); } System.out.println("################ Done"); }
block = statement(node); ForStatement forStatement = new ForStatement(forParameter, collectionExpression, block); configureAST(forStatement, forNode); return forStatement;
protected void assertIterate(String methodName, Expression listExpression) throws Exception { ClassNode classNode = new ClassNode("Foo", ACC_PUBLIC, ClassHelper.OBJECT_TYPE); classNode.addConstructor(new ConstructorNode(ACC_PUBLIC, null)); classNode.addProperty(new PropertyNode("bar", ACC_PUBLIC, ClassHelper.STRING_TYPE, classNode, null, null, null)); Statement loopStatement = createPrintlnStatement(new VariableExpression("i")); BlockStatement block = new BlockStatement(); block.addStatement(new ExpressionStatement(new DeclarationExpression(new VariableExpression("list"), Token.newSymbol("=", 0, 0), listExpression))); block.addStatement(new ForStatement(new Parameter(ClassHelper.DYNAMIC_TYPE, "i"), new VariableExpression("list"), loopStatement)); classNode.addMethod(new MethodNode(methodName, ACC_PUBLIC, ClassHelper.VOID_TYPE, Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, block)); Class fooClass = loadClass(classNode); assertTrue("Loaded a new class", fooClass != null); Object bean = fooClass.newInstance(); assertTrue("Managed to create bean", bean != null); System.out.println("################ Now about to invoke method"); try { InvokerHelper.invokeMethod(bean, methodName, null); } catch (InvokerInvocationException e) { System.out.println("Caught: " + e.getCause()); e.getCause().printStackTrace(); fail("Should not have thrown an exception"); } System.out.println("################ Done"); }
private void createMapVariant(MethodNode mNode, AnnotationNode anno, Parameter mapParam, List<Parameter> genParams, ClassNode cNode, BlockStatement inner, ArgumentListExpression args, List<String> propNames) { Parameter namedArgKey = param(STRING_TYPE, "namedArgKey"); inner.addStatement( new ForStatement( namedArgKey, callX(varX(mapParam), "keySet"),
add.setMethodTarget(ARRAYLIST_ADD_METHOD); ForStatement stmt = new ForStatement( iterator, receiver,
add.setMethodTarget(StaticCompilationVisitor.ARRAYLIST_ADD_METHOD); ForStatement stmt = new ForStatement( iterator, tmpReceiver,
block = statement(node); ForStatement forStatement = new ForStatement(forParameter, collectionExpression, block); configureAST(forStatement, forNode); return forStatement;
block = statement(node); ForStatement forStatement = new ForStatement(forParameter, collectionExpression, block); configureAST(forStatement, forNode); return forStatement;
block = statement(node); ForStatement forStatement = new ForStatement(forParameter, collectionExpression, block); configureAST(forStatement, forNode); return forStatement;
block = statement(node); ForStatement forStatement = new ForStatement(forParameter, collectionExpression, block); configureAST(forStatement, forNode); return forStatement;