Javassist 通过AccessFlags查找方法
我想通过标志和其他信息搜索Javassist 通过AccessFlags查找方法,javassist,Javassist,我想通过标志和其他信息搜索声明的方法 例如,我想搜索方法public final void ae(StringTokenizer) 下面是一个示例方法,我希望如何搜索它: private CtMethod findMethod(CtClass clazz, int access, String returns, String[] parameters) throws NotFoundException { /* returns = null = void, other S
声明的方法
例如,我想搜索方法public final void ae(StringTokenizer)代码>
下面是一个示例方法,我希望如何搜索它:
private CtMethod findMethod(CtClass clazz, int access, String returns, String[] parameters) throws NotFoundException {
/*
returns = null = void, other String for returned class name
parameters = easy names of parameters
*/
CtMethod found = null;
for(CtMethod method : clazz.getDeclaredMethods()) {
// Check here all flags and informations - If found, set the `found` variable and return
}
return found;
}
下面是一个示例调用:
CtMethod inputMethod = this.findMethod(theClass, AccessFlag.FINAL, null, new String[] { "StringTokenizer" });
如何检查示例AccessFlag.FINAL | AccessFlag.PUBLIC的显式标志?
您可以通过调用CtMethod::getModifiers来获取修饰符代码>。然后可以检查是否设置了修改器:
if (ctMethod.getModifiers() & (AccessFlag.FINAL | AccessFlag.PUBLIC) != 0) {
found = ctMethod;
break;
}