Example usage for org.aspectj.apache.bcel.classfile Method getSignature

List of usage examples for org.aspectj.apache.bcel.classfile Method getSignature

Introduction

In this page you can find the example usage for org.aspectj.apache.bcel.classfile Method getSignature.

Prototype

public final String getSignature() 

Source Link

Usage

From source file:br.jabuti.metrics.AbstractMetric.java

License:Open Source License

protected final boolean findMethodInClass(Program prog, Method m, String className, boolean recursive) {
    RClass rc = prog.get(className);/*ww  w  .j a  v  a 2  s. c  o  m*/
    if (rc == null || !(rc instanceof RClassCode)) {
        return false;
    }

    RClassCode rcc = (RClassCode) rc;
    JavaClass theClazz = rcc.getTheClass();
    Method[] methods = theClazz.getMethods();
    for (int i = 0; i < methods.length; i++) {
        if (methods[i].getName().equals(m.getName()) && methods[i].getSignature().equals(m.getSignature())) {
            return true;
        }
    }

    if (recursive) {
        return findMethodInClass(prog, m, rcc.getSuperClass(), recursive);
    }

    return false;
}

From source file:org.caesarj.mixer.intern.ClassModifyingVisitor.java

License:Open Source License

public void visitMethod(Method method) {
    final ConstantPool cp = method.getConstantPool();
    // we search for outer-class-access functions, which
    // are static, have exactly one argument of this class' type and
    // return an instance of the outer class' type
    if (method.isStatic() && method.getName().startsWith("access$")) {
        String returnType = Type.getReturnType(method.getSignature()).toString();

        if (!Tools.sameClass(returnType, oldOuterClassName))
            return;
        Type[] argTypes = Type.getArgumentTypes(method.getSignature());
        if (argTypes.length != 1)
            return;

        // construct the new signature & use it to overwrite the old one
        String newSignature = "(L" + newClassName + ";)L" + newOuterClassName + ";";
        int index = method.getSignatureIndex();
        cp.setConstant(index, new ConstantUtf8(newSignature));
    }/*from  w  ww  .j av  a 2 s . c o  m*/
    // and we check for constructors 
    else if (method.getName().equals("<init>")) {
        Type[] argTypes = Type.getArgumentTypes(method.getSignature());
        for (int argIdx = 0; argIdx < argTypes.length; argIdx++) {
            // modify the signature if neccessary
            if (Tools.sameClass(argTypes[argIdx].toString(), oldOuterClassName)) {
                // construct the new signature and use it to overwrite the old one
                argTypes[argIdx] = Type.getType("L" + newOuterClassName + ";");
            }
        }
        // construct new signature
        String signature = Type.getMethodSignature(method.getReturnType(), argTypes);
        int signatureIndex = method.getSignatureIndex();
        cp.setConstant(signatureIndex, new ConstantUtf8(signature));
    }
}