org.apache.bcel.Repository Java Examples

The following examples show how to use org.apache.bcel.Repository. 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: Util.java    From spotbugs with GNU Lesser General Public License v2.1 7 votes vote down vote up
/**
 * Determine the outer class of obj.
 *
 * @param obj
 * @return JavaClass for outer class, or null if obj is not an outer class
 * @throws ClassNotFoundException
 */

@CheckForNull
public static JavaClass getOuterClass(JavaClass obj) throws ClassNotFoundException {
    for (Attribute a : obj.getAttributes()) {
        if (a instanceof InnerClasses) {
            for (InnerClass ic : ((InnerClasses) a).getInnerClasses()) {
                if (obj.getClassNameIndex() == ic.getInnerClassIndex()) {
                    // System.out.println("Outer class is " +
                    // ic.getOuterClassIndex());
                    ConstantClass oc = (ConstantClass) obj.getConstantPool().getConstant(ic.getOuterClassIndex());
                    String ocName = oc.getBytes(obj.getConstantPool());
                    return Repository.lookupClass(ocName);
                }
            }
        }
    }
    return null;
}
 
Example #2
Source File: Hierarchy.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Find a field with given name defined in given class.
 *
 * @param className
 *            the name of the class
 * @param fieldName
 *            the name of the field
 * @return the Field, or null if no such field could be found
 */
public static Field findField(String className, String fieldName) throws ClassNotFoundException {
    JavaClass jclass = Repository.lookupClass(className);

    while (jclass != null) {
        Field[] fieldList = jclass.getFields();
        for (Field field : fieldList) {
            if (field.getName().equals(fieldName)) {
                return field;
            }
        }

        jclass = jclass.getSuperClass();
    }

    return null;
}
 
Example #3
Source File: Pass2Verifier.java    From ApkToolPlus with Apache License 2.0 6 votes vote down vote up
/**
 * Pass 2 is the pass where static properties of the
 * class file are checked without looking into "Code"
 * arrays of methods.
 * This verification pass is usually invoked when
 * a class is resolved; and it may be possible that
 * this verification pass has to load in other classes
 * such as superclasses or implemented interfaces.
 * Therefore, Pass 1 is run on them.<BR>
 * Note that most referenced classes are <B>not</B> loaded
 * in for verification or for an existance check by this
 * pass; only the syntactical correctness of their names
 * and descriptors (a.k.a. signatures) is checked.<BR>
 * Very few checks that conceptually belong here
 * are delayed until pass 3a in JustIce. JustIce does
 * not only check for syntactical correctness but also
 * for semantical sanity - therefore it needs access to
 * the "Code" array of methods in a few cases. Please
 * see the pass 3a documentation, too.
 *
 * @see org.apache.bcel.verifier.statics.Pass3aVerifier
 */
public VerificationResult do_verify(){
	VerificationResult vr1 = myOwner.doPass1();
	if (vr1.equals(VerificationResult.VR_OK)){
		
		// For every method, we could have information about the local variables out of LocalVariableTable attributes of
		// the Code attributes.
		localVariablesInfos = new LocalVariablesInfo[Repository.lookupClass(myOwner.getClassName()).getMethods().length];

		VerificationResult vr = VerificationResult.VR_OK; // default.
		try{
			constant_pool_entries_satisfy_static_constraints();
			field_and_method_refs_are_valid();
			every_class_has_an_accessible_superclass();
			final_methods_are_not_overridden();
		}
		catch (ClassConstraintException cce){
			vr = new VerificationResult(VerificationResult.VERIFIED_REJECTED, cce.getMessage());
		}
		return vr;
	}
	else
		return VerificationResult.VR_NOTYET;
}
 
Example #4
Source File: FindStrings.java    From uyuni with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Main class, to find strings in class files.
 * @param args Arguments to program.
 */
public static void main(String[] args) {
    try {
        JavaClass clazz = Repository.lookupClass(args[0]);
        ConstantPool cp = clazz.getConstantPool();
        Constant[] consts = cp.getConstantPool();


        for (int i = 0; i < consts.length; i++) {

            if (consts[i] instanceof ConstantString) {
                System.out.println("Found String: " +
                        ((ConstantString)consts[i]).getBytes(cp));
            }
        }
    }
    catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #5
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 #6
Source File: TransitiveHull.java    From commons-bcel with Apache License 2.0 6 votes vote down vote up
public static void main(final String[] argv) {
    JavaClass java_class;

    try {
        if (argv.length == 0) {
            System.err.println("transitive: No input files specified");
        } else {
            if ((java_class = Repository.lookupClass(argv[0])) == null) {
                java_class = new ClassParser(argv[0]).parse();
            }

            final TransitiveHull hull = new TransitiveHull(java_class);

            hull.start();
            System.out.println(Arrays.asList(hull.getClassNames()));
        }
    } catch (final Exception e) {
        e.printStackTrace();
    }
}
 
Example #7
Source File: TransitiveHull.java    From commons-bcel with Apache License 2.0 6 votes vote down vote up
private void add(String class_name) {
    class_name = class_name.replace('/', '.');

    for (final String anIgnored : ignored) {
        if (Pattern.matches(anIgnored, class_name)) {
            return;
        }
    }

    try {
        final JavaClass clazz = Repository.lookupClass(class_name);

        if (set.add(clazz)) {
            queue.enqueue(clazz);
        }
    } catch (final ClassNotFoundException e) {
        throw new IllegalStateException("Missing class: " + e.toString());
    }
}
 
Example #8
Source File: ParserTest.java    From JQF with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Fuzz
public void verifyJavaClass(@From(JavaClassGenerator.class) JavaClass javaClass) throws IOException {
    try {
        Repository.addClass(javaClass);
        Verifier verifier = StatelessVerifierFactory.getVerifier(javaClass.getClassName());
        VerificationResult result;
        result = verifier.doPass1();
        assumeThat(result.getMessage(), result.getStatus(), is(VerificationResult.VERIFIED_OK));
        result = verifier.doPass2();
        assumeThat(result.getMessage(), result.getStatus(), is(VerificationResult.VERIFIED_OK));
        for (int i = 0; i < javaClass.getMethods().length; i++) {
            result = verifier.doPass3a(i);
            assumeThat(result.getMessage(), result.getStatus(), is(VerificationResult.VERIFIED_OK));
        }
    } finally {
        Repository.clearCache();
    }
}
 
Example #9
Source File: FindStrings.java    From spacewalk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Main class, to find strings in class files.
 * @param args Arguments to program.
 */
public static void main(String[] args) {
    try {
        JavaClass clazz = Repository.lookupClass(args[0]);
        ConstantPool cp = clazz.getConstantPool();
        Constant[] consts = cp.getConstantPool();


        for (int i = 0; i < consts.length; i++) {

            if (consts[i] instanceof ConstantString) {
                System.out.println("Found String: " +
                        ((ConstantString)consts[i]).getBytes(cp));
            }
        }
    }
    catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #10
Source File: JavaClassDefinition.java    From contribution with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Finds the narrowest method that is compatible with a method.
 * An invocation of the given method can be resolved as an invocation
 * of the narrowest method.
 * @param aClassName the class for the method.
 * @param aMethodName the name of the method.
 * @param aArgTypes the types for the method.
 * @return the narrowest compatible method.
 */
public MethodDefinition findNarrowestMethod(
    String aClassName,
    String aMethodName,
    Type[] aArgTypes)
{
    MethodDefinition result = null;
    final String javaClassName = mJavaClass.getClassName();
    if (Repository.instanceOf(aClassName, javaClassName)) {
        // check all
        for (int i = 0; i < mMethodDefs.length; i++) {
            // TODO: check access privileges
            if (mMethodDefs[i].isCompatible(aMethodName, aArgTypes)) {
                if (result == null) {
                    result = mMethodDefs[i];
                }
                //else if (mMethodDefs[i].isAsNarrow(result)) {
                else if (result.isCompatible(mMethodDefs[i])) {
                    result = mMethodDefs[i];
                }
            }
        }
    }
    return result;
}
 
Example #11
Source File: ReferenceDAO.java    From contribution with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Finds the definition of the field of a field reference.
 * @param aFieldRef the reference to a field.
 * @return the definition of the field for aFieldRef.
 */
public FieldDefinition findFieldDef(FieldReference aFieldRef)
{
    final String className = aFieldRef.getClassName();
    JavaClass javaClass = Repository.lookupClass(className);
    final String fieldName = aFieldRef.getName();
    // search up the class hierarchy for the class containing the
    // method definition.
    FieldDefinition result = null;
    while ((javaClass != null) && (result == null)) {
        final JavaClassDefinition javaClassDef =
            (JavaClassDefinition) mJavaClasses.get(javaClass);
        if (javaClassDef != null) {
            result = javaClassDef.findFieldDef(fieldName);
        }
        //search the parent
        javaClass = javaClass.getSuperClass();
    }
    return result;
}
 
Example #12
Source File: ReferenceDAO.java    From contribution with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Adds a reference to a field.
 * @param aFieldRef the field reference.
 */
public void addFieldReference(FieldReference aFieldRef)
{
    final String className = aFieldRef.getClassName();
    JavaClass javaClass = Repository.lookupClass(className);
    final String fieldName = aFieldRef.getName();
    // search up the class hierarchy for the class containing the
    // method definition.
    FieldDefinition fieldDef = null;
    while ((javaClass != null) && (fieldDef == null)) {
        final JavaClassDefinition javaClassDef =
            (JavaClassDefinition) mJavaClasses.get(javaClass);
        if (javaClassDef != null) {
            fieldDef = javaClassDef.findFieldDef(fieldName);
            if (fieldDef != null) {
                fieldDef.addReference(aFieldRef);
            }
        }
        //search the parent
        javaClass = javaClass.getSuperClass();
    }
}
 
Example #13
Source File: ClassFileSetCheck.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/** @see com.puppycrawl.tools.checkstyle.bcel.IObjectSetVisitor */
public void visitSet(Set aSet)
{
    // register the JavaClasses in the Repository
    Repository.clearCache();
    Iterator it = aSet.iterator();
    while (it.hasNext()) {
        final JavaClass javaClass = (JavaClass) it.next();
        Repository.addClass(javaClass);
    }

    // visit the visitors
    it = getObjectSetVisitors().iterator();
    while (it.hasNext()) {
        final IObjectSetVisitor visitor = (IObjectSetVisitor) it.next();
        visitor.visitSet(aSet);
    }
}
 
Example #14
Source File: JavaClassDefinition.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Finds the narrowest method that is compatible with a method.
 * An invocation of the given method can be resolved as an invocation
 * of the narrowest method.
 * @param aClassName the class for the method.
 * @param aMethodName the name of the method.
 * @param aArgTypes the types for the method.
 * @return the narrowest compatible method.
 */
public MethodDefinition findNarrowestMethod(
    String aClassName,
    String aMethodName,
    Type[] aArgTypes)
{
    MethodDefinition result = null;
    final String javaClassName = mJavaClass.getClassName();
    if (Repository.instanceOf(aClassName, javaClassName)) {
        // check all
        for (int i = 0; i < mMethodDefs.length; i++) {
            // TODO: check access privileges
            if (mMethodDefs[i].isCompatible(aMethodName, aArgTypes)) {
                if (result == null) {
                    result = mMethodDefs[i];
                }
                //else if (mMethodDefs[i].isAsNarrow(result)) {
                else if (result.isCompatible(mMethodDefs[i])) {
                    result = mMethodDefs[i];
                }
            }
        }
    }
    return result;
}
 
Example #15
Source File: ReferenceDAO.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Finds the definition of the field of a field reference.
 * @param aFieldRef the reference to a field.
 * @return the definition of the field for aFieldRef.
 */
public FieldDefinition findFieldDef(FieldReference aFieldRef)
{
    final String className = aFieldRef.getClassName();
    JavaClass javaClass = Repository.lookupClass(className);
    final String fieldName = aFieldRef.getName();
    // search up the class hierarchy for the class containing the
    // method definition.
    FieldDefinition result = null;
    while ((javaClass != null) && (result == null)) {
        final JavaClassDefinition javaClassDef =
            (JavaClassDefinition) mJavaClasses.get(javaClass);
        if (javaClassDef != null) {
            result = javaClassDef.findFieldDef(fieldName);
        }
        //search the parent
        javaClass = javaClass.getSuperClass();
    }
    return result;
}
 
Example #16
Source File: ReferenceDAO.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Adds a reference to a field.
 * @param aFieldRef the field reference.
 */
public void addFieldReference(FieldReference aFieldRef)
{
    final String className = aFieldRef.getClassName();
    JavaClass javaClass = Repository.lookupClass(className);
    final String fieldName = aFieldRef.getName();
    // search up the class hierarchy for the class containing the
    // method definition.
    FieldDefinition fieldDef = null;
    while ((javaClass != null) && (fieldDef == null)) {
        final JavaClassDefinition javaClassDef =
            (JavaClassDefinition) mJavaClasses.get(javaClass);
        if (javaClassDef != null) {
            fieldDef = javaClassDef.findFieldDef(fieldName);
            if (fieldDef != null) {
                fieldDef.addReference(aFieldRef);
            }
        }
        //search the parent
        javaClass = javaClass.getSuperClass();
    }
}
 
Example #17
Source File: DeepSubtypeAnalysis.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static double isDeepSerializable(@DottedClassName String refSig) throws ClassNotFoundException {
    if (storedException != null) {
        throw storedException;
    }

    if (isPrimitiveComponentClass(refSig)) {
        if (DEBUG) {
            System.out.println("regSig \"" + refSig + "\" is primitive component class");
        }
        return 1.0;
    }

    String refName = getComponentClass(refSig);
    if (Values.DOTTED_JAVA_LANG_OBJECT.equals(refName)) {
        return 0.99;
    }

    JavaClass refJavaClass = Repository.lookupClass(refName);
    return isDeepSerializable(refJavaClass);
}
 
Example #18
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 visitINVOKEVIRTUAL(final INVOKEVIRTUAL o) {
    try {
    // INVOKEVIRTUAL is a LoadClass; the Class where the referenced method is declared in,
    // is therefore resolved/verified.
    // INVOKEVIRTUAL 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()+"'.");
    }
    if (! (jc.isClass())) {
        constraintViolated(o, "Referenced class '"+jc.getClassName()+"' is an interface, but not a class as expected.");
    }

    } catch (final ClassNotFoundException e) {
    // FIXME: maybe not the best way to handle this
    throw new AssertionViolatedException("Missing class: " + e, e);
    }
}
 
Example #19
Source File: MethodDefinition.java    From contribution with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Determine whether this method definition has a reference from a class or
 * a superclass.
 * @param aJavaClass the JavaClass to check against.
 * @return true if there is a reference to this method definition from a
 * aJavaClass or a superclass of aJavaClass.
 */
public boolean hasReference(JavaClass aJavaClass)
{
    final Iterator it = getReferences().iterator();
    while (it.hasNext()) {
        final InvokeReference invokeRef = (InvokeReference) it.next();
        final String invokeClassName = invokeRef.getClassName();
        if (Repository.instanceOf(aJavaClass, invokeClassName)) {
            return true;
        }
    }
    return false;
}
 
Example #20
Source File: MethodGenTestCase.java    From commons-bcel with Apache License 2.0 5 votes vote down vote up
@Test
public void testAnnotationsAreUnpacked() throws Exception {
    final JavaClass jc = Repository.lookupClass(Bar.Inner.class);
    final ClassGen cg = new ClassGen(jc);
    final MethodGen mg = new MethodGen(cg.getMethodAt(0), cg.getClassName(), cg.getConstantPool());
    final List<AnnotationEntryGen> firstParamAnnotations = mg.getAnnotationsOnParameter(0);
    Assert.assertEquals("Wrong number of annotations in the first parameter", 1, firstParamAnnotations.size());
    final List<AnnotationEntryGen> secondParamAnnotations = mg.getAnnotationsOnParameter(1);
    Assert.assertEquals("Wrong number of annotations in the second parameter", 1, secondParamAnnotations.size());
}
 
Example #21
Source File: ReferenceDAO.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Adds a reference for an invocation in the invoked method definition.
 * The invocation is of the form class.method(args).
 * @param aInvokeRef the invocation reference.
 */
public void addInvokeReference(InvokeReference aInvokeRef)
{
    // find the class for the instruction
    final String className = aInvokeRef.getClassName();
    JavaClass javaClass = Repository.lookupClass(className);
    final String methodName = aInvokeRef.getName();
    final Type[] argTypes = aInvokeRef.getArgTypes();

    // search up the class hierarchy for the class containing the
    // method definition.
    MethodDefinition narrowest = null;
    while ((javaClass != null) && (narrowest == null)) {
        final JavaClassDefinition javaClassDef =
            (JavaClassDefinition) mJavaClasses.get(javaClass);
        if (javaClassDef != null) {
            // find narrowest compatible in the current class
            narrowest =
                javaClassDef.findNarrowestMethod(
                    className,
                    methodName,
                    argTypes);
            if (narrowest != null) {
                narrowest.addReference(aInvokeRef);
            }
        }
        // search the parent
        javaClass = javaClass.getSuperClass();
    }
}
 
Example #22
Source File: MethodDefinition.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Determine whether this method definition has a reference from a class or
 * a superclass.
 * @param aJavaClass the JavaClass to check against.
 * @return true if there is a reference to this method definition from a
 * aJavaClass or a superclass of aJavaClass.
 */
public boolean hasReference(JavaClass aJavaClass)
{
    final Iterator it = getReferences().iterator();
    while (it.hasNext()) {
        final InvokeReference invokeRef = (InvokeReference) it.next();
        final String invokeClassName = invokeRef.getClassName();
        if (Repository.instanceOf(aJavaClass, invokeClassName)) {
            return true;
        }
    }
    return false;
}
 
Example #23
Source File: ReferenceDAO.java    From contribution with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Adds a reference for an invocation in the invoked method definition.
 * The invocation is of the form class.method(args).
 * @param aInvokeRef the invocation reference.
 */
public void addInvokeReference(InvokeReference aInvokeRef)
{
    // find the class for the instruction
    final String className = aInvokeRef.getClassName();
    JavaClass javaClass = Repository.lookupClass(className);
    final String methodName = aInvokeRef.getName();
    final Type[] argTypes = aInvokeRef.getArgTypes();

    // search up the class hierarchy for the class containing the
    // method definition.
    MethodDefinition narrowest = null;
    while ((javaClass != null) && (narrowest == null)) {
        final JavaClassDefinition javaClassDef =
            (JavaClassDefinition) mJavaClasses.get(javaClass);
        if (javaClassDef != null) {
            // find narrowest compatible in the current class
            narrowest =
                javaClassDef.findNarrowestMethod(
                    className,
                    methodName,
                    argTypes);
            if (narrowest != null) {
                narrowest.addReference(aInvokeRef);
            }
        }
        // search the parent
        javaClass = javaClass.getSuperClass();
    }
}
 
Example #24
Source File: VerifierAppFrame.java    From commons-bcel with Apache License 2.0 5 votes vote down vote up
synchronized void pass3aJList_valueChanged( final ListSelectionEvent e ) {
    if (e.getValueIsAdjusting()) {
        return;
    }
    final Verifier v = VerifierFactory.getVerifier(current_class);
    final StringBuilder all3amsg = new StringBuilder();
    boolean all3aok = true;
    boolean rejected = false;
    for (int i = 0; i < pass3aJList.getModel().getSize(); i++) {
        if (pass3aJList.isSelectedIndex(i)) {
            final VerificationResult vr = v.doPass3a(i);
            if (vr.getStatus() == VerificationResult.VERIFIED_REJECTED) {
                all3aok = false;
                rejected = true;
            }
            JavaClass jc = null;
            try {
                jc = Repository.lookupClass(v.getClassName());
                all3amsg.append("Method '").append(jc.getMethods()[i]).append("': ")
                        .append(vr.getMessage().replace('\n', ' ') ).append("\n\n");
            } catch (final ClassNotFoundException ex) {
                // FIXME: handle the error
                ex.printStackTrace();
            }
        }
    }
    pass3aTextPane.setText(all3amsg.toString());
    pass3aTextPane.setBackground(all3aok ? Color.green : (rejected ? Color.red : Color.yellow));
}
 
Example #25
Source File: ObjectType.java    From commons-bcel with Apache License 2.0 5 votes vote down vote up
/**
 * Java Virtual Machine Specification edition 2, � 5.4.4 Access Control
 * @throws ClassNotFoundException if the class referenced by this type
 *   can't be found
 */
public boolean accessibleTo( final ObjectType accessor ) throws ClassNotFoundException {
    final JavaClass jc = Repository.lookupClass(className);
    if (jc.isPublic()) {
        return true;
    }
    final JavaClass acc = Repository.lookupClass(accessor.className);
    return acc.getPackageName().equals(jc.getPackageName());
}
 
Example #26
Source File: Lookup.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static @DottedClassName String findSuperImplementor(@DottedClassName String clazz, String name, String signature,
        BugReporter bugReporter) {
    try {
        JavaClass c = findImplementor(Repository.getSuperClasses(clazz), name, signature);
        return (c != null) ? c.getClassName() : clazz;
    } catch (ClassNotFoundException e) {
        bugReporter.reportMissingClass(e);
        return clazz;
    }
}
 
Example #27
Source File: JavaClassAndMethod.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Constructor.
 *
 * @param method
 *            an XMethod specifying a specific method in a specific class
 * @throws ClassNotFoundException
 */
public JavaClassAndMethod(XMethod method) throws ClassNotFoundException {

    this.javaClass = Repository.lookupClass(method.getClassName());
    for (Method m : javaClass.getMethods()) {
        if (m.getName().equals(method.getName()) && m.getSignature().equals(method.getSignature())
                && m.isStatic() == method.isStatic()) {
            this.method = m;
            return;
        }
    }
    throw new IllegalArgumentException("Can't find " + method);
}
 
Example #28
Source File: VerifyDialog.java    From commons-bcel with Apache License 2.0 5 votes vote down vote up
/** Machine-generated. */
public void flushButton_ActionPerformed( final java.awt.event.ActionEvent actionEvent ) {
    VerifierFactory.getVerifier(class_name).flush();
    Repository.removeClass(class_name); // Make sure it will be reloaded.
    getPass1Panel().setBackground(Color.gray);
    getPass1Panel().repaint();
    getPass2Panel().setBackground(Color.gray);
    getPass2Panel().repaint();
    getPass3Panel().setBackground(Color.gray);
    getPass3Panel().repaint();
}
 
Example #29
Source File: MethodGenTestCase.java    From commons-bcel with Apache License 2.0 5 votes vote down vote up
private void testInvalidNullMethodBody(final String className) throws ClassNotFoundException {
    final JavaClass jc = Repository.lookupClass(className);
    final ClassGen classGen = new ClassGen(jc);
    for (final Method method : jc.getMethods()) {
        new MethodGen(method, jc.getClassName(), classGen.getConstantPool());
    }
}
 
Example #30
Source File: ObjectType.java    From commons-bcel with Apache License 2.0 5 votes vote down vote up
/**
 * If "this" doesn't reference a class, it references an interface
 * or a non-existant entity.
 * @deprecated (since 6.0) this method returns an inaccurate result
 *   if the class or interface referenced cannot
 *   be found: use referencesClassExact() instead
 */
@Deprecated
public boolean referencesClass() {
    try {
        final JavaClass jc = Repository.lookupClass(className);
        return jc.isClass();
    } catch (final ClassNotFoundException e) {
        return false;
    }
}