java - 如何使用 IJavaProject#findType() 获取java项目中的所有方法?

标签 java eclipse

我需要从 Eclipse 上的 java 项目获取所有方法,因此我想使用 IType#getMethods() 来执行此操作。但是,为此,在我的代码中,我需要使用 IJavaProject#findType() 来实例化 IType 类。这样,我很难知道哪个参数传递给 IJavaProject#findType() 来指定我想要获取方法。我怎样才能做到这一点?代码如下。

public void getAllMethods(ExecutionEvent event) throws CoreException{

TreeSelection selection = (TreeSelection)HandlerUtil.getCurrentSelection(event);
IJavaElement je = (IJavaElement)selection.getFirstElement();
IJavaProject jproj = je.getJavaProject();
IProject p = (IProject)jproj.getResource();
IJavaProject javaProject = JavaCore.create(p);

IType itype = javaProject.findType(""); //which parameter to pass here?
IMethod[] allMethods = itype.getMethods();

for(int i=0; i<allMethods.length;i++)
        System.out.println(allMethods[i].getElementName());
}

最佳答案

基本上,您可以传递类的完全限定名称。对于此重载签名和其他重载签名,请参阅文档 here

关于java - 如何使用 IJavaProject#findType() 获取java项目中的所有方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40132863/

相关文章:

Java - 逐字符读取文件并计算行数

java - 谁可以将所有路径打印到txt文件中

JAVA SWT DateTime 限制最大值

eclipse - PyDev在Eclipse中导入

eclipse - 如何安装 MercurialEclipse 插件?

java - 我的可比方法有什么问题?尝试对对象中的 int 字段进行排序

java - 替代 Java 中的无符号类型

java - Hadoop - MultipleOutputs.write - OutofMemory - Java 堆空间

java - Android ACRA 和 ProGuard

java - Eclipse Java 编辑器模板...为什么没有类型变量?