Java Code Examples for javassist.bytecode.MethodInfo#getName()

The following examples show how to use javassist.bytecode.MethodInfo#getName() . 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: ClassFileJavassist.java    From jbse with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Finds a method declaration in the classfile.
 * 
 * @param methodSignature a {@link Signature}.
 * @return {@code null} if no method with {@code methodSignature} 
 *         signature is declared in this classfile, otherwise the 
 *         {@link CtBehavior} for it; the class name in {@code methodSignature}
 *         is ignored.
 */
private MethodInfo findMethodDeclaration(Signature methodSignature) {
    if ("<clinit>".equals(methodSignature.getName())) {
        return this.cf.getStaticInitializer();
    }

    final List<MethodInfo> ms = this.cf.getMethods();
    for (MethodInfo m : ms) {
        final String internalName = m.getName();
        if (internalName.equals(methodSignature.getName()) &&
            m.getDescriptor().equals(methodSignature.getDescriptor())) {
            return m;
        }
    }
    return null;
}
 
Example 2
Source File: ClassFileJavassist.java    From jbse with GNU General Public License v3.0 6 votes vote down vote up
private MethodInfo findUniqueMethodDeclarationWithName(String methodName) {
    final List<MethodInfo> ms = this.cf.getMethods();
    MethodInfo retVal = null;
    for (MethodInfo m : ms) {
        final String internalName = m.getName();
        if (internalName.equals(methodName)) {
            if (retVal == null) {
                retVal = m;
            } else {
                //two methods with same name - not unique
                return null;
            }
        }
    }
    return retVal;
}
 
Example 3
Source File: FieldTransformer.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void transformInvokevirtualsIntoPutAndGetfields(ClassFile classfile)
		throws CannotCompileException {
	List methods = classfile.getMethods();
	for (Iterator method_iter = methods.iterator(); method_iter.hasNext();) {
		MethodInfo minfo = (MethodInfo) method_iter.next();
		String methodName = minfo.getName();
		if (methodName.startsWith(EACH_READ_METHOD_PREFIX)
		    || methodName.startsWith(EACH_WRITE_METHOD_PREFIX)
		    || methodName.equals(GETFIELDHANDLER_METHOD_NAME)
		    || methodName.equals(SETFIELDHANDLER_METHOD_NAME)) {
			continue;
		}
		CodeAttribute codeAttr = minfo.getCodeAttribute();
		if (codeAttr == null) {
			return;
		}
		CodeIterator iter = codeAttr.iterator();
		while (iter.hasNext()) {
			try {
				int pos = iter.next();
				pos = transformInvokevirtualsIntoGetfields(classfile, iter,
				                                           pos);
				pos = transformInvokevirtualsIntoPutfields(classfile, iter,
				                                           pos);

			} catch (BadBytecode e) {
				throw new CannotCompileException(e);
			}
		}
	}
}
 
Example 4
Source File: ClassFileJavassist.java    From jbse with GNU General Public License v3.0 5 votes vote down vote up
private void fillMethodsAndConstructors() {
    this.methods = new ArrayList<>();
    this.constructors = new ArrayList<>();
    final List<MethodInfo> ms = this.cf.getMethods();
    for (MethodInfo m : ms) {
        final Signature sig = new Signature(getClassName(), m.getDescriptor(), m.getName());
        this.methods.add(sig);
        if (m.isConstructor()) {
            this.constructors.add(sig);
        }
    }
}
 
Example 5
Source File: JavassistAdapter.java    From panda with Apache License 2.0 4 votes vote down vote up
@Override
public String getMethodName(MethodInfo method) {
    return method.getName();
}
 
Example 6
Source File: JOperation.java    From jadira with Apache License 2.0 4 votes vote down vote up
protected JOperation(MethodInfo methodInfo, JType enclosingType, ClasspathResolver resolver) {
    super(methodInfo == null ? null : methodInfo.getName(), resolver);
    this.methodInfo = methodInfo;
    this.enclosingType = enclosingType;
}