private void writeOutTypeCollection(BytecodeContext bc) throws TransformerException {

	GeneratorAdapter adapter = bc.getAdapter();

	// VariableReference item=VariableInterpreter.getVariableReference(pc,index);
	int index = -1;
	Attribute attrIndex = getAttribute("index");
	if (attrIndex == null) attrIndex = getAttribute("key");
	if (attrIndex != null) {
	    index = adapter.newLocal(Types.VARIABLE_REFERENCE);
	    adapter.loadArg(0);
	    attrIndex.getValue().writeOut(bc, Expression.MODE_REF);
	    adapter.invokeStatic(Types.VARIABLE_INTERPRETER, GET_VARIABLE_REFERENCE);
	    adapter.storeLocal(index);
	}

	// VariableReference item=VariableInterpreter.getVariableReference(pc,item);
	int item = -1;
	Attribute attrItem = getAttribute("item");
	if (attrItem == null) attrItem = getAttribute("value");
	if (attrItem != null) {
	    item = adapter.newLocal(Types.VARIABLE_REFERENCE);
	    adapter.loadArg(0);
	    attrItem.getValue().writeOut(bc, Expression.MODE_REF);
	    adapter.invokeStatic(Types.VARIABLE_INTERPRETER, GET_VARIABLE_REFERENCE);
	    adapter.storeLocal(item);
	}
	boolean hasIndexAndItem = index != -1 && item != -1;
	boolean hasItem = item != -1;

	WhileVisitor whileVisitor = new WhileVisitor();
	loopVisitor = whileVisitor;
	// java.util.Iterator it=Caster.toIterator(@collection');
	int it = adapter.newLocal(Types.ITERATOR);
	Attribute coll = getAttribute("struct");
	if (coll == null) coll = getAttribute("collection");
	coll.getValue().writeOut(bc, Expression.MODE_REF);

	// item and index
	int entry = -1;
	if (hasIndexAndItem) {
	    entry = adapter.newLocal(Types.MAP_ENTRY);
	    // Caster.toCollection(collection)
	    adapter.invokeStatic(Types.CASTER, Methods_Caster.TO_COLLECTION);
	    // coll.entryIterator();
	    adapter.invokeInterface(Types.COLLECTION, ENTRY_ITERATOR);
	}
	else {
	    // if(hasItem) adapter.invokeStatic(ForEach.FOR_EACH_UTIL,ForEach.FOR_EACH);
	    // else
	    adapter.invokeStatic(ForEach.FOR_EACH_UTIL, ForEach.LOOP_COLLECTION);
	}

	adapter.storeLocal(it);

	// while(it.hasNext()) {
	whileVisitor.visitBeforeExpression(bc);
	adapter.loadLocal(it);
	adapter.invokeInterface(Types.ITERATOR, HAS_NEXT);

	whileVisitor.visitAfterExpressionBeforeBody(bc);
	if (hasIndexAndItem) {
	    // entry=it.next();
	    adapter.loadLocal(it);
	    adapter.invokeInterface(Types.ITERATOR, NEXT);
	    adapter.storeLocal(entry);

	    // keyRef.set(pc,entry.getKey())
	    adapter.loadLocal(index);
	    adapter.loadArg(0);
	    adapter.loadLocal(entry);
	    adapter.invokeInterface(Types.MAP_ENTRY, GET_KEY);
	    adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_STRING);
	    adapter.invokeVirtual(Types.VARIABLE_REFERENCE, SET);
	    adapter.pop();

	    // valueRef.set(pc,entry.getKey())
	    adapter.loadLocal(item);
	    adapter.loadArg(0);
	    adapter.loadLocal(entry);
	    adapter.invokeInterface(Types.MAP_ENTRY, GET_VALUE);
	    adapter.invokeVirtual(Types.VARIABLE_REFERENCE, SET);
	    adapter.pop();

	}
	else {
	    if (index == -1) adapter.loadLocal(item);
	    else adapter.loadLocal(index);

	    adapter.loadArg(0);
	    adapter.loadLocal(it);
	    adapter.invokeInterface(Types.ITERATOR, NEXT);

	    adapter.invokeVirtual(Types.VARIABLE_REFERENCE, SET);
	    adapter.pop();
	}
	getBody().writeOut(bc);
	whileVisitor.visitAfterBody(bc, getEnd());

	// Reset
	adapter.loadLocal(it);
	adapter.invokeStatic(ForEach.FOR_EACH_UTIL, ForEach.RESET);
    }
private void writeOutTypeCollection ( BytecodeContext bc ) throws TransformerException { GeneratorAdapter adapter = bc . getAdapter ( ) ; int index = - 1 ; Attribute attrIndex = getAttribute ( "index" ) ; if ( attrIndex == null ) attrIndex = getAttribute ( "key" ) ; if ( attrIndex != null ) { index = adapter . newLocal ( Types . VARIABLE_REFERENCE ) ; adapter . loadArg ( 0 ) ; attrIndex . getValue ( ) . writeOut ( bc , Expression . MODE_REF ) ; adapter . invokeStatic ( Types . VARIABLE_INTERPRETER , GET_VARIABLE_REFERENCE ) ; adapter . storeLocal ( index ) ; } int item = - 1 ; Attribute attrItem = getAttribute ( "item" ) ; if ( attrItem == null ) attrItem = getAttribute ( "value" ) ; if ( attrItem != null ) { item = adapter . newLocal ( Types . VARIABLE_REFERENCE ) ; adapter . loadArg ( 0 ) ; attrItem . getValue ( ) . writeOut ( bc , Expression . MODE_REF ) ; adapter . invokeStatic ( Types . VARIABLE_INTERPRETER , GET_VARIABLE_REFERENCE ) ; adapter . storeLocal ( item ) ; } boolean hasIndexAndItem = index != - 1 && item != - 1 ; boolean hasItem = item != - 1 ; WhileVisitor whileVisitor = new WhileVisitor ( ) ; loopVisitor = whileVisitor ; int it = adapter . newLocal ( Types . ITERATOR ) ; Attribute coll = getAttribute ( "struct" ) ; if ( coll == null ) coll = getAttribute ( "collection" ) ; coll . getValue ( ) . writeOut ( bc , Expression . MODE_REF ) ; int entry = - 1 ; if ( hasIndexAndItem ) { entry = adapter . newLocal ( Types . MAP_ENTRY ) ; adapter . invokeStatic ( Types . CASTER , Methods_Caster . TO_COLLECTION ) ; adapter . invokeInterface ( Types . COLLECTION , ENTRY_ITERATOR ) ; } else { adapter . invokeStatic ( ForEach . FOR_EACH_UTIL , ForEach . LOOP_COLLECTION ) ; } adapter . storeLocal ( it ) ; whileVisitor . visitBeforeExpression ( bc ) ; adapter . loadLocal ( it ) ; adapter . invokeInterface ( Types . ITERATOR , HAS_NEXT ) ; whileVisitor . visitAfterExpressionBeforeBody ( bc ) ; if ( hasIndexAndItem ) { adapter . loadLocal ( it ) ; adapter . invokeInterface ( Types . ITERATOR , NEXT ) ; adapter . storeLocal ( entry ) ; adapter . loadLocal ( index ) ; adapter . loadArg ( 0 ) ; adapter . loadLocal ( entry ) ; adapter . invokeInterface ( Types . MAP_ENTRY , GET_KEY ) ; adapter . invokeStatic ( Types . CASTER , Methods . METHOD_TO_STRING ) ; adapter . invokeVirtual ( Types . VARIABLE_REFERENCE , SET ) ; adapter . pop ( ) ; adapter . loadLocal ( item ) ; adapter . loadArg ( 0 ) ; adapter . loadLocal ( entry ) ; adapter . invokeInterface ( Types . MAP_ENTRY , GET_VALUE ) ; adapter . invokeVirtual ( Types . VARIABLE_REFERENCE , SET ) ; adapter . pop ( ) ; } else { if ( index == - 1 ) adapter . loadLocal ( item ) ; else adapter . loadLocal ( index ) ; adapter . loadArg ( 0 ) ; adapter . loadLocal ( it ) ; adapter . invokeInterface ( Types . ITERATOR , NEXT ) ; adapter . invokeVirtual ( Types . VARIABLE_REFERENCE , SET ) ; adapter . pop ( ) ; } getBody ( ) . writeOut ( bc ) ; whileVisitor . visitAfterBody ( bc , getEnd ( ) ) ; adapter . loadLocal ( it ) ; adapter . invokeStatic ( ForEach . FOR_EACH_UTIL , ForEach . RESET ) ; }
write out collection loop

@param adapter
@throws TemplateException