Java Code Examples for org.apache.bcel.generic.Type#OBJECT

The following examples show how to use org.apache.bcel.generic.Type#OBJECT . 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: TestArrayAccess04Creator.java    From commons-bcel with Apache License 2.0 6 votes vote down vote up
private void createMethod_1() {
  final InstructionList il = new InstructionList();
  final MethodGen method = new MethodGen(Const.ACC_PUBLIC | Const.ACC_STATIC, Type.VOID, new Type[] { Type.OBJECT },
          new String[] { "arg0" }, "test", TEST_PACKAGE+".TestArrayAccess04", il, _cp);

  final InstructionHandle ih_0 = il.append(new PUSH(_cp, 1));
  Assert.assertNotNull(ih_0); // TODO why is this not used
  il.append(_factory.createNewArray(Type.OBJECT, (short) 1));
  il.append(InstructionFactory.createStore(Type.OBJECT, 1));
  final InstructionHandle ih_5 = il.append(new PUSH(_cp, 1));
  Assert.assertNotNull(ih_5); // TODO why is this not used
  il.append(InstructionFactory.createStore(Type.INT, 2));
  final InstructionHandle ih_7 = il.append(InstructionFactory.createLoad(Type.OBJECT, 1));
  Assert.assertNotNull(ih_7); // TODO why is this not used
  il.append(new PUSH(_cp, 0));
  il.append(InstructionFactory.createLoad(Type.INT, 2));
  il.append(InstructionConst.AASTORE);
  final InstructionHandle ih_11 = il.append(InstructionFactory.createReturn(Type.VOID));
  Assert.assertNotNull(ih_11); // TODO why is this not used
  method.setMaxStack();
  method.setMaxLocals();
  _cg.addMethod(method.getMethod());
  il.dispose();
}
 
Example 2
Source File: TestArrayAccess03Creator.java    From commons-bcel with Apache License 2.0 6 votes vote down vote up
private void createMethod_1() {
  final InstructionList il = new InstructionList();
  final MethodGen method = new MethodGen(Const.ACC_PUBLIC | Const.ACC_STATIC, Type.VOID, new Type[] { Type.OBJECT },
          new String[] { "arg0" }, "test", TEST_PACKAGE+".TestArrayAccess03", il, _cp);

  final InstructionHandle ih_0 = il.append(new PUSH(_cp, 1));
  Assert.assertNotNull(ih_0); // TODO why is this not used
  il.append(_factory.createNewArray(new ObjectType(TEST_PACKAGE+".TestArrayAccess03"), (short) 1));
  il.append(InstructionFactory.createStore(Type.OBJECT, 1));
  final InstructionHandle ih_5 = il.append(InstructionFactory.createLoad(Type.OBJECT, 0));
  Assert.assertNotNull(ih_5); // TODO why is this not used
  il.append(new PUSH(_cp, 0));
  il.append(_factory.createNew(TEST_PACKAGE+".TestArrayAccess03"));
  il.append(InstructionConst.DUP);
  il.append(_factory.createInvoke(TEST_PACKAGE+".TestArrayAccess03", "<init>", Type.VOID, Type.NO_ARGS, Const.INVOKESPECIAL));
  il.append(InstructionConst.AASTORE);
  final InstructionHandle ih_15 = il.append(InstructionFactory.createReturn(Type.VOID));
  Assert.assertNotNull(ih_15); // TODO why is this not used
  method.setMaxStack();
  method.setMaxLocals();
  _cg.addMethod(method.getMethod());
  il.dispose();
}
 
Example 3
Source File: Subtypes2.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
private ReferenceType computeFirstCommonSuperclassOfReferenceTypes(ReferenceType a, ReferenceType b)
        throws ClassNotFoundException {
    boolean aIsArrayType = (a instanceof ArrayType);
    boolean bIsArrayType = (b instanceof ArrayType);

    if (aIsArrayType && bIsArrayType) {
        // Merging array types - kind of a pain.

        ArrayType aArrType = (ArrayType) a;
        ArrayType bArrType = (ArrayType) b;

        if (aArrType.getDimensions() == bArrType.getDimensions()) {
            return computeFirstCommonSuperclassOfSameDimensionArrays(aArrType, bArrType);
        } else {
            return computeFirstCommonSuperclassOfDifferentDimensionArrays(aArrType, bArrType);
        }
    }

    if (aIsArrayType || bIsArrayType) {
        // One of a and b is an array type, but not both.
        // Common supertype is Object.
        return Type.OBJECT;
    }

    // Neither a nor b is an array type.
    // Find first common supertypes of ObjectTypes.
    return getFirstCommonSuperclass((ObjectType) a, (ObjectType) b);
}
 
Example 4
Source File: Subtypes2.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
private ObjectType computeFirstCommonSuperclassOfObjectTypes(ObjectType a, ObjectType b) throws ClassNotFoundException {
    ObjectType firstCommonSupertype;
    ClassDescriptor aDesc = DescriptorFactory.getClassDescriptor(a);
    ClassDescriptor bDesc = DescriptorFactory.getClassDescriptor(b);

    ClassVertex aVertex = resolveClassVertex(aDesc);
    ClassVertex bVertex = resolveClassVertex(bDesc);

    Set<ClassDescriptor> aSuperTypes = computeKnownSupertypes(aDesc);
    Set<ClassDescriptor> bSuperTypes = computeKnownSupertypes(bDesc);
    if (bSuperTypes.contains(aDesc)) {
        return a;
    }
    if (aSuperTypes.contains(bDesc)) {
        return b;
    }
    ArrayList<ClassVertex> aSuperList = getAllSuperclassVertices(aVertex);
    ArrayList<ClassVertex> bSuperList = getAllSuperclassVertices(bVertex);

    // Work backwards until the lists diverge.
    // The last element common to both lists is the first
    // common superclass.
    int aIndex = aSuperList.size() - 1;
    int bIndex = bSuperList.size() - 1;

    ClassVertex lastCommonInBackwardsSearch = null;
    while (aIndex >= 0 && bIndex >= 0) {
        if (aSuperList.get(aIndex) != bSuperList.get(bIndex)) {
            break;
        }
        lastCommonInBackwardsSearch = aSuperList.get(aIndex);
        aIndex--;
        bIndex--;
    }
    if (lastCommonInBackwardsSearch == null) {
        firstCommonSupertype = Type.OBJECT;
    } else {
        firstCommonSupertype = ObjectTypeFactory.getInstance(lastCommonInBackwardsSearch.getClassDescriptor()
                .toDottedClassName());
    }
    if (firstCommonSupertype.equals(Type.OBJECT)) {
        // see if we can't do better
        ClassDescriptor objDesc = DescriptorFactory.getClassDescriptor(Type.OBJECT);
        aSuperTypes.retainAll(bSuperTypes);
        aSuperTypes.remove(objDesc);
        for (ClassDescriptor c : aSuperTypes) {
            if (c.getPackageName().equals(aDesc.getPackageName()) || c.getPackageName().equals(bDesc.getPackageName())) {
                return ObjectTypeFactory.getInstance(c.toDottedClassName());
            }
        }

        if (!aSuperTypes.isEmpty()) {
            return ObjectTypeFactory.getInstance(aSuperTypes.iterator().next().toDottedClassName());
        }
    }

    return firstCommonSupertype;
}
 
Example 5
Source File: GenericUtilities.java    From spotbugs with GNU Lesser General Public License v2.1 votes vote down vote up
@Override
public ReferenceType produce(GenericObjectType obj) {
    return Type.OBJECT;
}
 
Example 6
Source File: GenericUtilities.java    From spotbugs with GNU Lesser General Public License v2.1 votes vote down vote up
@Override
public ReferenceType produce(GenericObjectType obj) {
    return Type.OBJECT;
}
 
Example 7
Source File: GenericUtilities.java    From spotbugs with GNU Lesser General Public License v2.1 votes vote down vote up
@Override
public ReferenceType produce(GenericObjectType obj) {
    return Type.OBJECT;
}