Java Code Examples for org.apache.bcel.Const#T_ARRAY

The following examples show how to use org.apache.bcel.Const#T_ARRAY . 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: ArrayType.java    From commons-bcel with Apache License 2.0 6 votes vote down vote up
/**
 * Constructor for array of given type
 *
 * @param type type of array (may be an array itself)
 */
public ArrayType(final Type type, final int dimensions) {
    super(Const.T_ARRAY, "<dummy>");
    if ((dimensions < 1) || (dimensions > Const.MAX_BYTE)) {
        throw new ClassGenException("Invalid number of dimensions: " + dimensions);
    }
    switch (type.getType()) {
        case Const.T_ARRAY:
            final ArrayType array = (ArrayType) type;
            this.dimensions = dimensions + array.dimensions;
            basicType = array.basicType;
            break;
        case Const.T_VOID:
            throw new ClassGenException("Invalid type: void[]");
        default: // Basic type or reference
            this.dimensions = dimensions;
            basicType = type;
            break;
    }
    final StringBuilder buf = new StringBuilder();
    for (int i = 0; i < this.dimensions; i++) {
        buf.append('[');
    }
    buf.append(basicType.getSignature());
    super.setSignature(buf.toString());
}
 
Example 2
Source File: InstructionFactory.java    From commons-bcel with Apache License 2.0 6 votes vote down vote up
public Instruction createAppend( final Type type ) {
    final byte t = type.getType();
    if (isString(type)) {
        return createInvoke(append_mos[0], Const.INVOKEVIRTUAL);
    }
    switch (t) {
        case Const.T_BOOLEAN:
        case Const.T_CHAR:
        case Const.T_FLOAT:
        case Const.T_DOUBLE:
        case Const.T_BYTE:
        case Const.T_SHORT:
        case Const.T_INT:
        case Const.T_LONG:
            return createInvoke(append_mos[t], Const.INVOKEVIRTUAL);
        case Const.T_ARRAY:
        case Const.T_OBJECT:
            return createInvoke(append_mos[1], Const.INVOKEVIRTUAL);
        default:
            throw new IllegalArgumentException("No append for this type? " + type);
    }
}
 
Example 3
Source File: InstructionFactory.java    From commons-bcel with Apache License 2.0 6 votes vote down vote up
/** Create typed return
 */
public static ReturnInstruction createReturn( final Type type ) {
    switch (type.getType()) {
        case Const.T_ARRAY:
        case Const.T_OBJECT:
            return InstructionConst.ARETURN;
        case Const.T_INT:
        case Const.T_SHORT:
        case Const.T_BOOLEAN:
        case Const.T_CHAR:
        case Const.T_BYTE:
            return InstructionConst.IRETURN;
        case Const.T_FLOAT:
            return InstructionConst.FRETURN;
        case Const.T_DOUBLE:
            return InstructionConst.DRETURN;
        case Const.T_LONG:
            return InstructionConst.LRETURN;
        case Const.T_VOID:
            return InstructionConst.RETURN;
        default:
            throw new IllegalArgumentException("Invalid type: " + type);
    }
}
 
Example 4
Source File: InstructionFactory.java    From commons-bcel with Apache License 2.0 6 votes vote down vote up
/**
 * @param index index of local variable
 */
public static LocalVariableInstruction createStore( final Type type, final int index ) {
    switch (type.getType()) {
        case Const.T_BOOLEAN:
        case Const.T_CHAR:
        case Const.T_BYTE:
        case Const.T_SHORT:
        case Const.T_INT:
            return new ISTORE(index);
        case Const.T_FLOAT:
            return new FSTORE(index);
        case Const.T_DOUBLE:
            return new DSTORE(index);
        case Const.T_LONG:
            return new LSTORE(index);
        case Const.T_ARRAY:
        case Const.T_OBJECT:
            return new ASTORE(index);
        default:
            throw new IllegalArgumentException("Invalid type " + type);
    }
}
 
Example 5
Source File: InstructionFactory.java    From commons-bcel with Apache License 2.0 6 votes vote down vote up
/**
 * @param index index of local variable
 */
public static LocalVariableInstruction createLoad( final Type type, final int index ) {
    switch (type.getType()) {
        case Const.T_BOOLEAN:
        case Const.T_CHAR:
        case Const.T_BYTE:
        case Const.T_SHORT:
        case Const.T_INT:
            return new ILOAD(index);
        case Const.T_FLOAT:
            return new FLOAD(index);
        case Const.T_DOUBLE:
            return new DLOAD(index);
        case Const.T_LONG:
            return new LLOAD(index);
        case Const.T_ARRAY:
        case Const.T_OBJECT:
            return new ALOAD(index);
        default:
            throw new IllegalArgumentException("Invalid type " + type);
    }
}
 
Example 6
Source File: InstructionFactory.java    From commons-bcel with Apache License 2.0 6 votes vote down vote up
/**
 * @param type type of elements of array, i.e., array.getElementType()
 */
public static ArrayInstruction createArrayLoad( final Type type ) {
    switch (type.getType()) {
        case Const.T_BOOLEAN:
        case Const.T_BYTE:
            return InstructionConst.BALOAD;
        case Const.T_CHAR:
            return InstructionConst.CALOAD;
        case Const.T_SHORT:
            return InstructionConst.SALOAD;
        case Const.T_INT:
            return InstructionConst.IALOAD;
        case Const.T_FLOAT:
            return InstructionConst.FALOAD;
        case Const.T_DOUBLE:
            return InstructionConst.DALOAD;
        case Const.T_LONG:
            return InstructionConst.LALOAD;
        case Const.T_ARRAY:
        case Const.T_OBJECT:
            return InstructionConst.AALOAD;
        default:
            throw new IllegalArgumentException("Invalid type " + type);
    }
}
 
Example 7
Source File: InstructionFactory.java    From commons-bcel with Apache License 2.0 6 votes vote down vote up
/**
 * @param type type of elements of array, i.e., array.getElementType()
 */
public static ArrayInstruction createArrayStore( final Type type ) {
    switch (type.getType()) {
        case Const.T_BOOLEAN:
        case Const.T_BYTE:
            return InstructionConst.BASTORE;
        case Const.T_CHAR:
            return InstructionConst.CASTORE;
        case Const.T_SHORT:
            return InstructionConst.SASTORE;
        case Const.T_INT:
            return InstructionConst.IASTORE;
        case Const.T_FLOAT:
            return InstructionConst.FASTORE;
        case Const.T_DOUBLE:
            return InstructionConst.DASTORE;
        case Const.T_LONG:
            return InstructionConst.LASTORE;
        case Const.T_ARRAY:
        case Const.T_OBJECT:
            return InstructionConst.AASTORE;
        default:
            throw new IllegalArgumentException("Invalid type " + type);
    }
}
 
Example 8
Source File: InstructionFactory.java    From commons-bcel with Apache License 2.0 6 votes vote down vote up
/** Create "null" value for reference types, 0 for basic types like int
 */
public static Instruction createNull( final Type type ) {
    switch (type.getType()) {
        case Const.T_ARRAY:
        case Const.T_OBJECT:
            return InstructionConst.ACONST_NULL;
        case Const.T_INT:
        case Const.T_SHORT:
        case Const.T_BOOLEAN:
        case Const.T_CHAR:
        case Const.T_BYTE:
            return InstructionConst.ICONST_0;
        case Const.T_FLOAT:
            return InstructionConst.FCONST_0;
        case Const.T_DOUBLE:
            return InstructionConst.DCONST_0;
        case Const.T_LONG:
            return InstructionConst.LCONST_0;
        case Const.T_VOID:
            return InstructionConst.NOP;
        default:
            throw new IllegalArgumentException("Invalid type: " + type);
    }
}
 
Example 9
Source File: Type.java    From commons-bcel with Apache License 2.0 6 votes vote down vote up
static int getTypeSize( final String signature ) throws StringIndexOutOfBoundsException {
    final byte type = Utility.typeOfSignature(signature);
    if (type <= Const.T_VOID) {
        return encode(BasicType.getType(type).getSize(), 1);
    } else if (type == Const.T_ARRAY) {
        int dim = 0;
        do { // Count dimensions
            dim++;
        } while (signature.charAt(dim) == '[');
        // Recurse, but just once, if the signature is ok
        final int consumed = consumed(getTypeSize(signature.substring(dim)));
        return encode(1, dim + consumed);
    } else { // type == T_REFERENCE
        final int index = signature.indexOf(';'); // Look for closing `;'
        if (index < 0) {
            throw new ClassFormatException("Invalid signature: " + signature);
        }
        return encode(1, index + 1);
    }
}
 
Example 10
Source File: Type.java    From commons-bcel with Apache License 2.0 5 votes vote down vote up
/**
 * Convert signature to a Type object.
 * @param signature signature string such as Ljava/lang/String;
 * @return type object
 */
// @since 6.0 no longer final
public static Type getType( final String signature ) throws StringIndexOutOfBoundsException {
    final byte type = Utility.typeOfSignature(signature);
    if (type <= Const.T_VOID) {
        //corrected concurrent private static field acess
        wrap(consumed_chars, 1);
        return BasicType.getType(type);
    } else if (type == Const.T_ARRAY) {
        int dim = 0;
        do { // Count dimensions
            dim++;
        } while (signature.charAt(dim) == '[');
        // Recurse, but just once, if the signature is ok
        final Type t = getType(signature.substring(dim));
        //corrected concurrent private static field acess
        //  consumed_chars += dim; // update counter - is replaced by
        final int _temp = unwrap(consumed_chars) + dim;
        wrap(consumed_chars, _temp);
        return new ArrayType(t, dim);
    } else { // type == T_REFERENCE
        // Utility.typeSignatureToString understands how to parse generic types.
        final String parsedSignature = Utility.typeSignatureToString(signature, false);
        wrap(consumed_chars, parsedSignature.length() + 2); // "Lblabla;" `L' and `;' are removed
        return ObjectType.getInstance(parsedSignature.replace('/', '.'));
    }
}
 
Example 11
Source File: Utility.java    From commons-bcel with Apache License 2.0 5 votes vote down vote up
/**
 * Return type of signature as a byte value as defined in <em>Constants</em>
 *
 * @param  signature in format described above
 * @return type of signature
 * @see    Const
 *
 * @throws ClassFormatException if signature isn't a known type
 */
public static byte typeOfSignature( final String signature ) throws ClassFormatException {
    try {
        switch (signature.charAt(0)) {
            case 'B':
                return Const.T_BYTE;
            case 'C':
                return Const.T_CHAR;
            case 'D':
                return Const.T_DOUBLE;
            case 'F':
                return Const.T_FLOAT;
            case 'I':
                return Const.T_INT;
            case 'J':
                return Const.T_LONG;
            case 'L':
            case 'T':
                return Const.T_REFERENCE;
            case '[':
                return Const.T_ARRAY;
            case 'V':
                return Const.T_VOID;
            case 'Z':
                return Const.T_BOOLEAN;
            case 'S':
                return Const.T_SHORT;
            case '!':
            case '+':
            case '*':
                return typeOfSignature(signature.substring(1));
            default:
                throw new ClassFormatException("Invalid method signature: " + signature);
        }
    } catch (final StringIndexOutOfBoundsException e) {
        throw new ClassFormatException("Invalid method signature: " + signature, e);
    }
}
 
Example 12
Source File: StandardTypeMerger.java    From spotbugs with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Determine if the given typecode refers to a reference type. This
 * implementation just checks that the type code is T_OBJECT, T_ARRAY,
 * T_NULL, or T_EXCEPTION. Subclasses should override this if they have
 * defined new object types with different type codes.
 */
protected boolean isReferenceType(byte type) {
    return type == Const.T_OBJECT || type == Const.T_ARRAY || type == T_NULL || type == T_EXCEPTION;
}