我想获取给定 MethodDeclaration 对象的 java 方法签名的字节码。我正在使用 Eclipse jdt 解析 java 类并迭代 MethodDeclaration,如下所示:
private static void processJavaFile(String javaFilePath) {
List<MethodDeclaration> methodDeclarations = new ArrayList<MethodDeclaration>();
FileInputStream reader = null;
try {
File javaFile = new File(javaFilePath);
reader = new FileInputStream(javaFile);
byte[] bs = new byte[reader.available()];
reader.read(bs, 0, reader.available());
String javaContent = new String(bs);
CompilationUnit unit = ASTUtil.getCompilationUnit(javaContent, 4);
MethodVisitor methodVisitor = new MethodVisitor();
unit.accept(methodVisitor);
methodDeclarations = methodVisitor.getMethods();
for (MethodDeclaration methodDeclaration :methodDeclarations){
////////////////////////////////////////////////////////////////////////
// ???? I want to get the byte code of the method signature here ???? //
////////////////////////////////////////////////////////////////////////
}
} catch (Exception e) {
e.printStackTrace();
}
}