org.apache.bcel.generic.Type Java Examples

The following examples show how to use org.apache.bcel.generic.Type. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LocalVariableInfo.java    From commons-bcel with Apache License 2.0 6 votes vote down vote up
/**
 * Adds information about name and type for a given offset.
 *
 * @throws LocalVariableInfoInconsistentException if the new information conflicts
 *         with already gathered information.
 */
private void add(final int offset, final String name, final Type t) throws LocalVariableInfoInconsistentException {
    if (getName(offset) != null) {
        if (!getName(offset).equals(name)) {
            throw new LocalVariableInfoInconsistentException("At bytecode offset '" + offset
                    + "' a local variable has two different names: '" + getName(offset) + "' and '" + name + "'.");
        }
    }
    if (getType(offset) != null) {
        if (!getType(offset).equals(t)) {
            throw new LocalVariableInfoInconsistentException("At bytecode offset '" + offset
                    + "' a local variable has two different types: '" + getType(offset) + "' and '" + t + "'.");
        }
    }
    setName(offset, name);
    setType(offset, t);
}
 
Example #2
Source File: FindRefComparison.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
protected ReferenceType mergeReferenceTypes(ReferenceType aRef, ReferenceType bRef) throws DataflowAnalysisException {
    byte aType = aRef.getType();
    byte bType = bRef.getType();

    if (isExtendedStringType(aType) || isExtendedStringType(bType)) {
        // If both types are the same extended String type,
        // then the same type is returned. Otherwise, extended
        // types are downgraded to plain java.lang.String,
        // and a standard merge is applied.
        if (aType == bType) {
            return aRef;
        }

        if (isExtendedStringType(aType)) {
            aRef = Type.STRING;
        }
        if (isExtendedStringType(bType)) {
            bRef = Type.STRING;
        }
    }

    return super.mergeReferenceTypes(aRef, bRef);
}
 
Example #3
Source File: JavaBuilder.java    From luaj with MIT License 6 votes vote down vote up
private String createLuaStringField(LuaString value) {
	String name = PREFIX_CONSTANT+constants.size();
	FieldGen fg = new FieldGen(Constants.ACC_STATIC | Constants.ACC_FINAL, 
			TYPE_LUAVALUE, name, cp);
	cg.addField(fg.getField());
	LuaString ls = value.checkstring();
	if ( ls.isValidUtf8() ) {
		init.append(new PUSH(cp, value.tojstring()));
		init.append(factory.createInvoke(STR_LUASTRING, "valueOf",
				TYPE_LUASTRING, ARG_TYPES_STRING, Constants.INVOKESTATIC));
	} else {
		char[] c = new char[ls.m_length];
		for ( int j=0; j<ls.m_length; j++ ) 
			c[j] = (char) (0xff & (int) (ls.m_bytes[ls.m_offset+j]));
		init.append(new PUSH(cp, new String(c)));
		init.append(factory.createInvoke(STR_STRING, "toCharArray",
				TYPE_CHARARRAY, Type.NO_ARGS,
				Constants.INVOKEVIRTUAL));
		init.append(factory.createInvoke(STR_LUASTRING, "valueOf",
				TYPE_LUASTRING, ARG_TYPES_CHARARRAY,
				Constants.INVOKESTATIC));
	}
	init.append(factory.createPutStatic(classname, name, TYPE_LUAVALUE));			
	return name;
}
 
Example #4
Source File: LocalVariablesInfo.java    From commons-bcel with Apache License 2.0 6 votes vote down vote up
/**
 * Adds information about the local variable in slot 'slot'. Automatically
 * adds information for slot+1 if 't' is Type.LONG or Type.DOUBLE.
 *
 * @param name variable name
 * @param startPc Range in which the variable is valid.
 * @param length length of ...
 * @param type variable type
 * @throws LocalVariableInfoInconsistentException if the new information conflicts
 *         with already gathered information.
 */
public void add(final int slot, final String name, final int startPc, final int length, final Type type) throws LocalVariableInfoInconsistentException{
    // The add operation on LocalVariableInfo may throw the '...Inconsistent...' exception, we don't throw it explicitely here.

    if (slot < 0 || slot >= localVariableInfos.length) {
        throw new AssertionViolatedException("Slot number for local variable information out of range.");
    }

    localVariableInfos[slot].add(name, startPc, length, type);
    if (type == Type.LONG) {
        localVariableInfos[slot+1].add(name, startPc, length, LONG_Upper.theInstance());
    }
    if (type == Type.DOUBLE) {
        localVariableInfos[slot+1].add(name, startPc, length, DOUBLE_Upper.theInstance());
    }
}
 
Example #5
Source File: GraphicalVerifier.java    From commons-bcel with Apache License 2.0 6 votes vote down vote up
/** Constructor. */
public GraphicalVerifier() {
    final VerifierAppFrame frame = new VerifierAppFrame();
    //Frames �berpr�fen, die voreingestellte Gr��e haben
    //Frames packen, die nutzbare bevorzugte Gr��eninformationen enthalten, z.B. aus ihrem Layout
    if (packFrame) {
        frame.pack();
    } else {
        frame.validate();
    }
    //Das Fenster zentrieren
    final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    final Dimension frameSize = frame.getSize();
    if (frameSize.height > screenSize.height) {
        frameSize.height = screenSize.height;
    }
    if (frameSize.width > screenSize.width) {
        frameSize.width = screenSize.width;
    }
    frame.setLocation((screenSize.width - frameSize.width) / 2,
            (screenSize.height - frameSize.height) / 2);
    frame.setVisible(true);
    frame.getClassNamesJList().setModel(new VerifierFactoryListModel());
    VerifierFactory.getVerifier(Type.OBJECT.getClassName()); // Fill list with java.lang.Object
    frame.getClassNamesJList().setSelectedIndex(0); // default, will verify java.lang.Object
}
 
Example #6
Source File: ObligationAnalysis.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
private Type nullCheck(short opcode, Edge edge, InstructionHandle last, BasicBlock sourceBlock)
        throws DataflowAnalysisException {
    if (DEBUG_NULL_CHECK) {
        System.out.println("checking for nullcheck on edge " + edge);
    }
    Type type = null;
    if ((opcode == Const.IFNULL && edge.getType() == EdgeTypes.IFCMP_EDGE)
            || (opcode == Const.IFNONNULL && edge.getType() == EdgeTypes.FALL_THROUGH_EDGE)) {
        Location location = new Location(last, sourceBlock);
        TypeFrame typeFrame = typeDataflow.getFactAtLocation(location);
        if (typeFrame.isValid()) {
            type = typeFrame.getTopValue();
            if (DEBUG_NULL_CHECK) {
                System.out.println("ifnull comparison of " + type + " to null at " + last);
            }
        }
    }
    return type;
}
 
Example #7
Source File: Pass3aVerifier.java    From commons-bcel with Apache License 2.0 6 votes vote down vote up
/** Checks if the constraints of operands of the said instruction(s) are satisfied. */
@Override
public void visitNEW(final NEW o) {
    indexValid(o, o.getIndex());
    final Constant c = constantPoolGen.getConstant(o.getIndex());
    if (!    (c instanceof ConstantClass)) {
        constraintViolated(o, "Expecting a CONSTANT_Class operand, but found a '"+c+"'.");
    }
    else{
        final ConstantUtf8 cutf8 = (ConstantUtf8) (constantPoolGen.getConstant( ((ConstantClass) c).getNameIndex() ));
        final Type t = Type.getType("L"+cutf8.getBytes()+";");
        if (t instanceof ArrayType) {
            constraintViolated(o, "NEW must not be used to create an array.");
        }
    }

}
 
Example #8
Source File: JavaClassDefinition.java    From contribution with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Finds the narrowest method that is compatible with a method.
 * An invocation of the given method can be resolved as an invocation
 * of the narrowest method.
 * @param aClassName the class for the method.
 * @param aMethodName the name of the method.
 * @param aArgTypes the types for the method.
 * @return the narrowest compatible method.
 */
public MethodDefinition findNarrowestMethod(
    String aClassName,
    String aMethodName,
    Type[] aArgTypes)
{
    MethodDefinition result = null;
    final String javaClassName = mJavaClass.getClassName();
    if (Repository.instanceOf(aClassName, javaClassName)) {
        // check all
        for (int i = 0; i < mMethodDefs.length; i++) {
            // TODO: check access privileges
            if (mMethodDefs[i].isCompatible(aMethodName, aArgTypes)) {
                if (result == null) {
                    result = mMethodDefs[i];
                }
                //else if (mMethodDefs[i].isAsNarrow(result)) {
                else if (result.isCompatible(mMethodDefs[i])) {
                    result = mMethodDefs[i];
                }
            }
        }
    }
    return result;
}
 
Example #9
Source File: BCELifier.java    From commons-bcel with Apache License 2.0 6 votes vote down vote up
static String printType( final String signature ) {
    final Type type = Type.getType(signature);
    final byte t = type.getType();
    if (t <= Const.T_VOID) {
        return "Type." + Const.getTypeName(t).toUpperCase(Locale.ENGLISH);
    } else if (type.toString().equals("java.lang.String")) {
        return "Type.STRING";
    } else if (type.toString().equals("java.lang.Object")) {
        return "Type.OBJECT";
    } else if (type.toString().equals("java.lang.StringBuffer")) {
        return "Type.STRINGBUFFER";
    } else if (type instanceof ArrayType) {
        final ArrayType at = (ArrayType) type;
        return "new ArrayType(" + printType(at.getBasicType()) + ", " + at.getDimensions()
                + ")";
    } else {
        return "new ObjectType(\"" + Utility.signatureToString(signature, false) + "\")";
    }
}
 
Example #10
Source File: TransitiveHull.java    From commons-bcel with Apache License 2.0 6 votes vote down vote up
private void visitRef(final ConstantCP ccp, final boolean method) {
    final String class_name = ccp.getClass(cp);
    add(class_name);

    final ConstantNameAndType cnat = (ConstantNameAndType) cp.getConstant(ccp.getNameAndTypeIndex(),
            Constants.CONSTANT_NameAndType);

    final String signature = cnat.getSignature(cp);

    if (method) {
        final Type type = Type.getReturnType(signature);

        checkType(type);

        for (final Type type1 : Type.getArgumentTypes(signature)) {
            checkType(type1);
        }
    } else {
        checkType(Type.getType(signature));
    }
}
 
Example #11
Source File: TypeFrame.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void pushValue(Type value) {

    super.pushValue(value);

    try {
        exactTypeSet.clear(getStackLocation(0));
    } catch (DataflowAnalysisException e) {
        assert false;
    }

}
 
Example #12
Source File: TestArrayAccess03Creator.java    From commons-bcel with Apache License 2.0 5 votes vote down vote up
private void createMethod_0() {
  final InstructionList il = new InstructionList();
  final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.VOID, Type.NO_ARGS, new String[] {  }, "<init>",
          TEST_PACKAGE+".TestArrayAccess03", il, _cp);

  final InstructionHandle ih_0 = il.append(InstructionFactory.createLoad(Type.OBJECT, 0));
  Assert.assertNotNull(ih_0); // TODO why is this not used
  il.append(_factory.createInvoke("java.lang.Object", "<init>", Type.VOID, Type.NO_ARGS, Const.INVOKESPECIAL));
  final InstructionHandle ih_4 = il.append(InstructionFactory.createReturn(Type.VOID));
  Assert.assertNotNull(ih_4); // TODO why is this not used
  method.setMaxStack();
  method.setMaxLocals();
  _cg.addMethod(method.getMethod());
  il.dispose();
}
 
Example #13
Source File: IncompatibleTypes.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static IncompatibleTypes getPriorityForAssumingCompatibleWithArray(Type rhsType) {
    if (rhsType.equals(Type.OBJECT)) {
        return ARRAY_AND_OBJECT;
    }
    String sig = rhsType.getSignature();
    if ("Ljava/io/Serializable;".equals(sig) || "Ljava/lang/Cloneable;".equals(sig)) {
        return SEEMS_OK;
    }
    return ARRAY_AND_NON_ARRAY;
}
 
Example #14
Source File: FindRefComparison.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void initEntryFact(TypeFrame result) {
    super.initEntryFact(result);
    for (int i = 0; i < methodGen.getMaxLocals(); i++) {
        Type t = result.getValue(i);
        if (t.equals(Type.STRING)) {
            result.setValue(i, parameterStringTypeInstance);
        }
    }
}
 
Example #15
Source File: TypeAnnotation.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
public TypeAnnotation(Type objectType, String roleDescription) {
    this(objectType.getSignature(), roleDescription);
    if (objectType instanceof GenericObjectType) {
        GenericObjectType genericObjectType = (GenericObjectType) objectType;
        if (genericObjectType.getTypeCategory() == GenericUtilities.TypeCategory.PARAMETERIZED) {
            typeParameters = genericObjectType.getGenericParametersAsString();
        }
    }
}
 
Example #16
Source File: UselessSubclassMethod.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
private Method findSuperclassMethod(@DottedClassName String superclassName, Method subclassMethod) throws ClassNotFoundException {

        String methodName = subclassMethod.getName();
        Type[] subArgs = null;
        JavaClass superClass = Repository.lookupClass(superclassName);
        Method[] methods = superClass.getMethods();
        outer: for (Method m : methods) {
            if (m.getName().equals(methodName)) {
                if (subArgs == null) {
                    subArgs = Type.getArgumentTypes(subclassMethod.getSignature());
                }
                Type[] superArgs = Type.getArgumentTypes(m.getSignature());
                if (subArgs.length == superArgs.length) {
                    for (int j = 0; j < subArgs.length; j++) {
                        if (!superArgs[j].equals(subArgs[j])) {
                            continue outer;
                        }
                    }
                    return m;
                }
            }
        }

        if (!"Object".equals(superclassName)) {
            @DottedClassName
            String superSuperClassName = superClass.getSuperclassName();
            if (superSuperClassName.equals(superclassName)) {
                throw new ClassNotFoundException("superclass of " + superclassName + " is itself");
            }
            return findSuperclassMethod(superSuperClassName, subclassMethod);
        }

        return null;
    }
 
Example #17
Source File: ASTLetExpr.java    From commons-bcel with Apache License 2.0 5 votes vote down vote up
/**
 * Fifth pass, produce Java byte code.
 */
@Override
public void byte_code(final InstructionList il, final MethodGen method, final ConstantPoolGen cp) {
  final int size = idents.length;
  final LocalVariableGen[] l = new LocalVariableGen[size];

  for(int i=0; i < size; i++) {
    final String           ident = idents[i].getName();
    final Variable         entry = (Variable)env.get(ident);
    final Type             t     = BasicType.getType((byte)idents[i].getType());
    final LocalVariableGen lg    = method.addLocalVariable(ident, t, null, null);
    final int              slot  = lg.getIndex();

    entry.setLocalVariable(lg);
    InstructionHandle start = il.getEnd();
    exprs[i].byte_code(il, method, cp);
    start = (start == null)? il.getStart() : start.getNext();
    lg.setStart(start);
    il.append(new ISTORE(slot));     ASTFunDecl.pop();
    l[i] = lg;
  }

  body.byte_code(il, method, cp);
  final InstructionHandle end = il.getEnd();
  for(int i=0; i < size; i++) {
      l[i].setEnd(end);
  }
}
 
Example #18
Source File: FindRefComparison.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void visitGETSTATIC(GETSTATIC obj) {
    Type type = obj.getType(getCPG());
    XField xf = XFactory.createXField(obj, cpg);
    if (xf.isFinal()) {
        FieldSummary fieldSummary = AnalysisContext.currentAnalysisContext().getFieldSummary();
        Item summary = fieldSummary.getSummary(xf);
        if (summary.isNull()) {
            pushValue(TypeFrame.getNullType());
            return;
        }

        String slashedClassName = ClassName.fromFieldSignature(type.getSignature());
        if (slashedClassName != null) {
            String dottedClassName = ClassName.toDottedClassName(slashedClassName);
            if (DEFAULT_SUSPICIOUS_SET.contains(dottedClassName)) {
                type = new FinalConstant(dottedClassName, xf);
                consumeStack(obj);
                pushValue(type);
                return;
            }
        }

    }
    if (STRING_SIGNATURE.equals(type.getSignature())) {
        handleLoad(obj);
    } else {
        super.visitGETSTATIC(obj);
    }
}
 
Example #19
Source File: FindRefComparison.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void visitGETFIELD(GETFIELD obj) {
    Type type = obj.getType(getCPG());
    if (STRING_SIGNATURE.equals(type.getSignature())) {
        handleLoad(obj);
    } else {
        XField xf = XFactory.createXField(obj, cpg);
        if (xf.isFinal()) {
            FieldSummary fieldSummary = AnalysisContext.currentAnalysisContext().getFieldSummary();
            Item summary = fieldSummary.getSummary(xf);
            if (summary.isNull()) {
                consumeStack(obj);
                pushValue(TypeFrame.getNullType());
                return;
            }

            String slashedClassName = ClassName.fromFieldSignature(type.getSignature());
            if (slashedClassName != null) {
                String dottedClassName = ClassName.toDottedClassName(slashedClassName);
                if (DEFAULT_SUSPICIOUS_SET.contains(dottedClassName)) {
                    type = new FinalConstant(dottedClassName, xf);
                    consumeStack(obj);
                    pushValue(type);
                    return;
                }
            }
        }
        super.visitGETFIELD(obj);
    }
}
 
Example #20
Source File: OperandStack.java    From commons-bcel with Apache License 2.0 5 votes vote down vote up
/**
 * Pushes a Type object onto the stack.
 */
public void push(final Type type) {
    if (type == null) {
        throw new AssertionViolatedException("Cannot push NULL onto OperandStack.");
    }
    if (type == Type.BOOLEAN || type == Type.CHAR || type == Type.BYTE || type == Type.SHORT) {
        throw new AssertionViolatedException("The OperandStack does not know about '"+type+"'; use Type.INT instead.");
    }
    if (slotsUsed() >= maxStack) {
        throw new AssertionViolatedException(
            "OperandStack too small, should have thrown proper Exception elsewhere. Stack: "+this);
    }
    stack.add(type);
}
 
Example #21
Source File: JavaClass.java    From commons-bcel with Apache License 2.0 5 votes vote down vote up
/**
 * @return A {@link Method} corresponding to
 * java.lang.reflect.Method if any
 */
public Method getMethod( final java.lang.reflect.Method m ) {
    for (final Method method : methods) {
        if (m.getName().equals(method.getName()) && (m.getModifiers() == method.getModifiers())
                && Type.getSignature(m).equals(method.getSignature())) {
            return method;
        }
    }
    return null;
}
 
Example #22
Source File: ReferenceDAO.java    From contribution with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Adds a reference for an invocation in the invoked method definition.
 * The invocation is of the form class.method(args).
 * @param aInvokeRef the invocation reference.
 */
public void addInvokeReference(InvokeReference aInvokeRef)
{
    // find the class for the instruction
    final String className = aInvokeRef.getClassName();
    JavaClass javaClass = Repository.lookupClass(className);
    final String methodName = aInvokeRef.getName();
    final Type[] argTypes = aInvokeRef.getArgTypes();

    // search up the class hierarchy for the class containing the
    // method definition.
    MethodDefinition narrowest = null;
    while ((javaClass != null) && (narrowest == null)) {
        final JavaClassDefinition javaClassDef =
            (JavaClassDefinition) mJavaClasses.get(javaClass);
        if (javaClassDef != null) {
            // find narrowest compatible in the current class
            narrowest =
                javaClassDef.findNarrowestMethod(
                    className,
                    methodName,
                    argTypes);
            if (narrowest != null) {
                narrowest.addReference(aInvokeRef);
            }
        }
        // search the parent
        javaClass = javaClass.getSuperClass();
    }
}
 
Example #23
Source File: FindNoSideEffectMethods.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * @param methodDescriptor
 */
private void sawNoSideEffectCall(MethodDescriptor methodDescriptor) {
    if (uselessVoidCandidate && Type.getReturnType(methodDescriptor.getSignature()) == Type.VOID
            && !methodDescriptor.getName().equals(Const.CONSTRUCTOR_NAME)) {
        /* To reduce false-positives we do not mark method as useless void if it calls
         * another useless void method. If that another method also in the scope of our project
         * then we will report it instead. If there's a cycle of no-side-effect calls, then
         * it's probably some delegation pattern and methods can be extended in future/derived
         * projects to do something useful.
         */
        uselessVoidCandidate = false;
    }
}
 
Example #24
Source File: BCELFactory.java    From commons-bcel with Apache License 2.0 5 votes vote down vote up
@Override
public void visitArrayInstruction( final ArrayInstruction i ) {
    final short opcode = i.getOpcode();
    final Type type = i.getType(_cp);
    final String kind = (opcode < Const.IASTORE) ? "Load" : "Store";
    _out.println("il.append(_factory.createArray" + kind + "(" + BCELifier.printType(type)
            + "));");
}
 
Example #25
Source File: BugInstance.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Nonnull
public BugInstance addFoundAndExpectedType(Type foundType, Type expectedType) {

    add(new TypeAnnotation(foundType, TypeAnnotation.FOUND_ROLE));
    add(new TypeAnnotation(expectedType, TypeAnnotation.EXPECTED_ROLE));
    return this;
}
 
Example #26
Source File: ValueRangeAnalysisFactory.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static Map<Integer, Value> getParameterTypes(MethodDescriptor descriptor) {
    Type[] argumentTypes = Type.getArgumentTypes(descriptor.getSignature());
    int j = 0;
    Map<Integer, Value> result = new HashMap<>();
    if (!descriptor.isStatic()) {
        result.put(j++, new Value("this", null, "L" + descriptor.getSlashedClassName() + ";"));
    }
    for (int i = 0; i < argumentTypes.length; i++) {
        result.put(j, new Value("arg" + i, null, argumentTypes[i].getSignature()));
        j += argumentTypes[i].getSize();
    }
    return result;
}
 
Example #27
Source File: GenericUtilities.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Get String representation of a Type including Generic information
 */
public static final String getString(Type type) {
    if (type instanceof GenericObjectType) {
        return ((GenericObjectType) type).toString(true);
    } else if (type instanceof ArrayType) {
        return TypeCategory.asString((ArrayType) type);
    } else {
        return type.toString();
    }
}
 
Example #28
Source File: GenericUtilitiesTest.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testEclipseJDTInvalidWildcardSignature() {
    final Type type = GenericUtilities.getType("!*");
    assertThat(type, instanceOf(GenericObjectType.class));
    assertEquals("*", ((GenericObjectType) type).getVariable());
    assertNull(((GenericObjectType) type).getExtension());
}
 
Example #29
Source File: GenericUtilities.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public String asString(GenericObjectType obj) {
    StringBuilder b = new StringBuilder(obj.toPlainString());
    b.append("<");
    boolean first = true;
    for (Type t : obj.parameters) {
        if (!first) {
            b.append(",");
        }
        first = false;
        b.append(GenericUtilities.getString(t));
    }
    b.append(">");
    return b.toString();
}
 
Example #30
Source File: BCELFactory.java    From commons-bcel with Apache License 2.0 5 votes vote down vote up
@Override
public void visitAllocationInstruction( final AllocationInstruction i ) {
    Type type;
    if (i instanceof CPInstruction) {
        type = ((CPInstruction) i).getType(_cp);
    } else {
        type = ((NEWARRAY) i).getType();
    }
    final short opcode = ((Instruction) i).getOpcode();
    int dim = 1;
    switch (opcode) {
        case Const.NEW:
            _out.println("il.append(_factory.createNew(\"" + ((ObjectType) type).getClassName()
                    + "\"));");
            break;
        case Const.MULTIANEWARRAY:
            dim = ((MULTIANEWARRAY) i).getDimensions();
            //$FALL-THROUGH$
        case Const.ANEWARRAY:
        case Const.NEWARRAY:
            if (type instanceof ArrayType) {
                type = ((ArrayType) type).getBasicType();
            }
            _out.println("il.append(_factory.createNewArray(" + BCELifier.printType(type)
                    + ", (short) " + dim + "));");
            break;
        default:
            throw new IllegalArgumentException("Unhandled opcode: " + opcode);
    }
}