List of usage examples for org.aspectj.apache.bcel.classfile Method getName
public final String getName()
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);//from www . j a v a 2s .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
/** * Remove all methods from <code>clazz</code> whose names start * with '$new'./*from www . j ava2 s . c o m*/ * @param clazz The class to modify * @return The class with removed methods */ protected JavaClass removeFactoryMethods(JavaClass clazz) { ClassGen gen = new ClassGen(clazz); Method[] methods = gen.getMethods(); for (int i = 0; i < methods.length; i++) { Method method = methods[i]; if (method.getName().startsWith(CaesarConstants.FACTORY_METHOD_PREFIX)) { gen.removeMethod(method); } } return gen.getJavaClass(); }
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 ww w . j a v 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)); } }