Package org.apache.bcel.generic

Examples of org.apache.bcel.generic.ObjectType


            // Base types are both ObjectTypes, and number of dimensions is
            // same.
            // We just need to find the first common supertype of base types
            // and return a new ArrayType using that base type.
            ObjectType firstCommonBaseType = getFirstCommonSuperclass((ObjectType) aBaseType, (ObjectType) bBaseType);
            return new ArrayType(firstCommonBaseType, aArrType.getDimensions());
        }
    }
View Full Code Here


        // Easy case
        if (a.equals(b)) {
            return a;
        }

        ObjectType firstCommonSupertype = (ObjectType) checkFirstCommonSuperclassQueryCache(a, b);
        if (firstCommonSupertype == null) {
            firstCommonSupertype = computeFirstCommonSuperclassOfObjectTypes(a, b);
            firstCommonSuperclassQueryCache.put(a, b, firstCommonSupertype);
        }
View Full Code Here

        return firstCommonSupertype;
    }

    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) {
View Full Code Here

        h = h.getNext();
        final Instruction newInstruction = h.getInstruction();
        if (!(newInstruction instanceof NEW)) {
            return false;
        }
        final ObjectType loadClassType = ((NEW) newInstruction).getLoadClassType(cpg);
        if (!loadClassType.getClassName().equals("java.lang.NullPointerException")) {
            return false;
        }
        h = h.getNext();
        return check(h, NULLCHECK1) || check(h, NULLCHECK2);
View Full Code Here

        if (s.indexOf('/') >= 0) {
            s = s.replace('/', '.');
        }

        Map<String, ObjectType> map = instance.get();
        ObjectType result = map.get(s);
        if (result != null) {
            return result;
        }
        result = ObjectType.getInstance(s);
        map.put(s, result);
View Full Code Here

        if (constantValue instanceof ConstantClass) {
            ConstantClass constantClass = (ConstantClass) constantValue;
            String className = constantClass.getBytes(cpg.getConstantPool());
            value = factory.getClassObjectValue(className);
        } else if (constantValue instanceof ObjectType) {
            ObjectType objectType = (ObjectType) constantValue;
            String className = objectType.getClassName();
            value = factory.getClassObjectValue(className);
        } else {
            value = constantValueMap.get(constantValue);
            if (value == null) {
                value = factory.createFreshValue(ValueNumber.CONSTANT_VALUE);
View Full Code Here

    /**
     * Assures the generic preconditions of a LoadClass instance.
     * The referenced class is loaded and pass2-verified.
     */
    public void visitLoadClass(LoadClass o){
      ObjectType t = o.getLoadClassType(cpg);
      if (t != null){// null means "no class is loaded"
        Verifier v = VerifierFactory.getVerifier(t.getClassName());
        VerificationResult vr = v.doPass1();
        if (vr.getStatus() != VerificationResult.VERIFIED_OK){
          constraintViolated((Instruction) o, "Class '"+o.getLoadClassType(cpg).getClassName()+"' is referenced, but cannot be loaded: '"+vr+"'.");
        }
      }
View Full Code Here

    if(!ignore) {
      body.byte_code(il, method, cp);

      if(main) {
  ObjectType e_type = new ObjectType("java.lang.Exception");
  InstructionHandle start = il.getStart(), end, handler, end_handler;
  LocalVariableGen exc = method.addLocalVariable("$e",
                   e_type,
                   null, null);
  int slot = exc.getIndex();
View Full Code Here

                    if (instanceType != TypeFrame.getNullType() && instanceType != TypeFrame.getBottomType()) {
                        if (!(instanceType instanceof ObjectType)) {
                            throw new DataflowAnalysisException("Field accessed through non-object reference " + instanceType,
                                    methodGen, handle);
                        }
                        ObjectType objType = (ObjectType) instanceType;

                        // If instance class name is not the same as that of the
                        // field,
                        // make it so
                        String instanceClassName = objType.getClassName();
                        if (!instanceClassName.equals(xfield.getClassName())) {
                            xfield = XFactory.getExactXField(instanceClassName, xfield.getName(), xfield.getSignature(),
                                    xfield.isStatic());
                        }
                    }
View Full Code Here

                            if (value instanceof ConstantClass) {
                                ConstantClass v = (ConstantClass) value;
                                initializationOf = ClassName.toSignature(v.getBytes(javaClass.getConstantPool()));
                                foundDeadClassInitialization = true;
                            } else if (value instanceof ObjectType) {
                                ObjectType v = (ObjectType) value;
                                initializationOf = ClassName.toSignature(v.getClassName());
                                foundDeadClassInitialization = true;
                            } else {
                                AnalysisContext.logError("LDC loaded " + value + "at " + location.getHandle().getPosition() + " in " + classContext.getFullyQualifiedMethodName(method));
                            }
View Full Code Here

TOP

Related Classes of org.apache.bcel.generic.ObjectType

Copyright © 2018 www.massapicom. 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.