我有一个代码示例,它浏览我的工作区并选择每个类中的每个方法。 我的目的是打印出该方法的绝对路径,但我不知道如何处理它。
类似 method.getAbsolutePath()
的东西不存在。
我的代码:
IPackageFragment[] packages = javaProject.getPackageFragments();
for (IPackageFragment mypackage : packages) {
for (ICompilationUnit unit : mypackage.getCompilationUnits()) {
IType[] allTypes = unit.getAllTypes();
for (IType type : allTypes) {
IMethod[] methods = type.getMethods();
for (IMethod method : methods) {
//System.out.println(MyMethodPath);
//here is want to print the path
}
}
}
}
有人可以帮忙吗?
最佳答案
您可以通过 IMethod.getClassFile 获取类(class),然后可以使用 IClassFile.getPath 来获取绝对路径,或更重要的是:
System.out.println(method.getClassFile().getPath().toString());
关于java - 获取方法的类文件的绝对路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17305607/