Package net.sourceforge.javautil.bytecode.api.type.method.invocation

Source Code of net.sourceforge.javautil.bytecode.api.type.method.invocation.ArrayInitialization

package net.sourceforge.javautil.bytecode.api.type.method.invocation;

import net.sourceforge.javautil.bytecode.api.IBytecodeReferenceable;
import net.sourceforge.javautil.bytecode.api.BytecodeReferenceableAbstract;
import net.sourceforge.javautil.bytecode.api.LiteralValue;
import net.sourceforge.javautil.bytecode.api.TypeDescriptor;
import net.sourceforge.javautil.bytecode.api.type.method.BytecodeContextMethod;

/**
* The construction of an array.
*
* @author elponderador
* @author $Author$
* @version $Id$
*/
public class ArrayInitialization extends BytecodeReferenceableAbstract<BytecodeContextMethod> {
 
  protected final IBytecodeReferenceable[] values;

  public ArrayInitialization(TypeDescriptor rootComponentType, IBytecodeReferenceable... values) {
    super(rootComponentType);
    this.values = values;
  }

  public void load(BytecodeContextMethod context) {
    context.getWriter().newArray(context, descriptor, new LiteralValue(values.length));
   
    for (int idx=0; idx<values.length; idx++) {
      context.getWriter().dup(context);
      new LiteralValue(idx).load(context);
      context.coerce(descriptor, values[idx]);
     
      context.getWriter().arrayStore(context);
    }
  }

}
TOP

Related Classes of net.sourceforge.javautil.bytecode.api.type.method.invocation.ArrayInitialization

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.