gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 12:08:12 28 4
gpt4 key购买 nike

我需要从 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com