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

The following examples show how to use org.apache.bcel.generic.INVOKESTATIC#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: 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 visitINVOKESTATIC(final INVOKESTATIC o) {
    try {
    // INVOKESTATIC is a LoadClass; the Class where the referenced method is declared in,
    // is therefore resolved/verified.
    // INVOKESTATIC is an InvokeInstruction, the argument and return types are resolved/verified,
    // too. So are the allowed method names.
    final String classname = o.getClassName(constantPoolGen);
    final JavaClass jc = Repository.lookupClass(classname);
    final Method m = getMethodRecursive(jc, o);
    if (m == null) {
        constraintViolated(o, "Referenced method '"+o.getMethodName(constantPoolGen)+"' with expected signature '"+
            o.getSignature(constantPoolGen) +"' not found in class '"+jc.getClassName()+"'.");
    } else if (! (m.isStatic())) { // implies it's not abstract, verified in pass 2.
        constraintViolated(o, "Referenced method '"+o.getMethodName(constantPoolGen)+"' has ACC_STATIC unset.");
    }

    } catch (final ClassNotFoundException e) {
    // FIXME: maybe not the best way to handle this
    throw new AssertionViolatedException("Missing class: " + e, e);
    }
}
 
Example 2
Source File: FindRefComparison.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void visitINVOKESTATIC(INVOKESTATIC obj) {
    if (returnsString(obj)) {
        consumeStack(obj);

        String className = obj.getClassName(getCPG());
        if (Values.DOTTED_JAVA_LANG_STRING.equals(className)) {
            pushValue(dynamicStringTypeInstance);
        } else {
            pushReturnType(obj);
        }
    } else {
        super.visitINVOKESTATIC(obj);
    }
}
 
Example 3
Source File: FindSleepWithLockHeld.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
private boolean isSleep(INVOKESTATIC ins, ConstantPoolGen cpg) {
    String className = ins.getClassName(cpg);
    if (!"java.lang.Thread".equals(className)) {
        return false;
    }
    String methodName = ins.getMethodName(cpg);
    String signature = ins.getSignature(cpg);

    return "sleep".equals(methodName) && ("(J)V".equals(signature) || "(JI)V".equals(signature));
}
 
Example 4
Source File: TargetEnumeratingVisitor.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void visitINVOKESTATIC(INVOKESTATIC ins) {
    // Find calls to System.exit(), since this effectively terminates the
    // basic block.

    String className = ins.getClassName(constPoolGen);
    String methodName = ins.getName(constPoolGen);
    String methodSig = ins.getSignature(constPoolGen);

    if ("java.lang.System".equals(className) && "exit".equals(methodName) && "(I)V".equals(methodSig)) {
        isExit = true;
    }
}
 
Example 5
Source File: Hierarchy.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Get the InnerClassAccess for access method called by given INVOKESTATIC.
 *
 * @param inv
 *            the INVOKESTATIC instruction
 * @param cpg
 *            the ConstantPoolGen for the method
 * @return the InnerClassAccess, or null if the instruction is not an
 *         inner-class access
 */
public static InnerClassAccess getInnerClassAccess(INVOKESTATIC inv, ConstantPoolGen cpg) throws ClassNotFoundException {

    String className = inv.getClassName(cpg);
    String methodName = inv.getName(cpg);
    String methodSig = inv.getSignature(cpg);

    InnerClassAccess access = AnalysisContext.currentAnalysisContext().getInnerClassAccessMap()
            .getInnerClassAccess(className, methodName);
    return (access != null && access.getMethodSignature().equals(methodSig)) ? access : null;
}
 
Example 6
Source File: InnerClassAccessMap.java    From spotbugs with GNU Lesser General Public License v2.1 3 votes vote down vote up
/**
 * Get the inner class access object for given invokestatic instruction.
 * Returns null if the called method is not an inner class access.
 *
 * @param inv
 *            the invokestatic instruction
 * @param cpg
 *            the ConstantPoolGen for the method
 * @return the InnerClassAccess, or null if the call is not an inner class
 *         access
 */
public InnerClassAccess getInnerClassAccess(INVOKESTATIC inv, ConstantPoolGen cpg) throws ClassNotFoundException {
    String methodName = inv.getMethodName(cpg);
    if (methodName.startsWith("access$")) {
        String className = inv.getClassName(cpg);

        return getInnerClassAccess(className, methodName);
    }
    return null;
}