Java Code Examples for org.apache.bcel.generic.ObjectType#getClassName()

The following examples show how to use org.apache.bcel.generic.ObjectType#getClassName() . 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: BCELFactory.java    From commons-bcel with Apache License 2.0 6 votes vote down vote up
private void createConstant( final Object value ) {
    String embed = value.toString();
    if (value instanceof String) {
        embed = '"' + Utility.convertString(embed) + '"';
    } else if (value instanceof Character) {
        embed = "(char)0x" + Integer.toHexString(((Character) value).charValue());
    } else if (value instanceof Float) {
        embed += "f";
    } else if (value instanceof Long) {
        embed += "L";
    } else if (value instanceof ObjectType) {
        final ObjectType ot = (ObjectType) value;
        embed = "new ObjectType(\""+ot.getClassName()+"\")";
    }

    _out.println("il.append(new PUSH(_cp, " + embed + "));");
}
 
Example 2
Source File: InstanceFieldLoadStreamFactory.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public Stream createStream(Location location, ObjectType type, ConstantPoolGen cpg,
        RepositoryLookupFailureCallback lookupFailureCallback) {

    Instruction ins = location.getHandle().getInstruction();
    if (ins.getOpcode() != Const.GETFIELD) {
        return null;
    }

    String fieldClass = type.getClassName();
    try {
        if (fieldClass.startsWith("[")) {
            return null;
        }
        if (!Hierarchy.isSubtype(fieldClass, streamBaseClass)) {
            return null;
        }

        Stream stream = new Stream(location, fieldClass, streamBaseClass);
        stream.setIsOpenOnCreation(true);
        stream.setOpenLocation(location);
        if (bugPatternType != null) {
            stream.setInteresting(bugPatternType);
        }

        // System.out.println("Instance field stream at " + location);
        return stream;
    } catch (ClassNotFoundException e) {
        lookupFailureCallback.reportMissingClass(e);
        return null;
    }
}
 
Example 3
Source File: GenericUtilities.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static ObjectType merge(@CheckForNull GenericObjectType t1, ObjectType t2) {
    if (t1 == null || t2 instanceof GenericObjectType) {
        return t2;
    }
    List<? extends ReferenceType> parameters = t1.getParameters();
    if (parameters == null) {
        return t2;
    }
    return new GenericObjectType(t2.getClassName(), parameters);
}
 
Example 4
Source File: ExceptionObjectType.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Initialize object from an exception set.
 *
 * @param exceptionSet
 *            the exception set
 * @return a Type that is a supertype of all of the exceptions in the
 *         exception set
 */
public static Type fromExceptionSet(ExceptionSet exceptionSet) throws ClassNotFoundException {
    Type commonSupertype = exceptionSet.getCommonSupertype();
    if (commonSupertype.getType() != Const.T_OBJECT) {
        return commonSupertype;
    }

    ObjectType exceptionSupertype = (ObjectType) commonSupertype;

    String className = exceptionSupertype.getClassName();
    if ("java.lang.Throwable".equals(className)) {
        return exceptionSupertype;
    }
    return new ExceptionObjectType(className, exceptionSet);
}
 
Example 5
Source File: MethodReturnValueStreamFactory.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public Stream createStream(Location location, ObjectType type, ConstantPoolGen cpg,
        RepositoryLookupFailureCallback lookupFailureCallback) {

    try {
        Instruction ins = location.getHandle().getInstruction();

        // For now, just support instance methods
        short opcode = ins.getOpcode();
        if (!invokeOpcodeSet.get(opcode)) {
            return null;
        }

        // Is invoked class a subtype of the base class we want
        // FIXME: should test be different for INVOKESPECIAL and
        // INVOKESTATIC?
        InvokeInstruction inv = (InvokeInstruction) ins;
        ReferenceType classType = inv.getReferenceType(cpg);
        if (!Hierarchy.isSubtype(classType, baseClassType)) {
            return null;
        }

        // See if method name and signature match
        String methodName = inv.getMethodName(cpg);
        String methodSig = inv.getSignature(cpg);
        if (!this.methodName.equals(methodName) || !this.methodSig.equals(methodSig)) {
            return null;
        }

        String streamClass = type.getClassName();
        if ("java.sql.CallableStatement".equals(streamClass)) {
            streamClass = "java.sql.PreparedStatement";
        }
        Stream result = new Stream(location, streamClass, streamClass).setIgnoreImplicitExceptions(true).setIsOpenOnCreation(
                true);
        if (!isUninteresting) {
            result.setInteresting(bugType);
        }
        return result;
    } catch (ClassNotFoundException e) {
        lookupFailureCallback.reportMissingClass(e);
    }

    return null;
}
 
Example 6
Source File: UninitializedObjectType.java    From commons-bcel with Apache License 2.0 4 votes vote down vote up
/** Creates a new instance. */
public UninitializedObjectType(final ObjectType t) {
    super(Const.T_UNKNOWN, "<UNINITIALIZED OBJECT OF TYPE '"+t.getClassName()+"'>");
    initialized = t;
}