使用 Eclipse 的 JDT 查找项目中的类的有效方法是什么?
Eclipse的SearchEngine
类有很多用于搜索的方法,包括各种风格的search
、searchAllTypeNames
等。searchAllTypeNames
似乎面向查找包中的类。在项目中查找用户定义的类的好策略是什么? (所谓用户定义的类,是指用户为其编写了驻留在该项目中的源代码的类,而不是从其他项目、外部 jar、系统库等导入的类)
- 。 /code> 与自定义
IJavaSearchResultCollector
。 - 获取项目中的所有包(使用
search
?),然后迭代这些包,使用searchAllTypeNames
收集类。 - 手动遍历 AST。
- 还有别的事。
请注意,我实际上并不需要“最有效”的收集类的方式。我更喜欢易于编码且相当高效的东西,而不是需要大量代码才能提高效率的东西。
我欢迎任何有关使用 SearchEngine
方法的相关一般指导。我发现许多选择令人困惑。
Eclipse's SearchEngine
class has many methods for searching, including various flavors of search
, searchAllTypeNames
, etc. searchAllTypeNames
seems to be oriented around finding the classes in a package. What is a good strategy for finding the user-defined classes in a project? (By user-defined classes, I mean classes for which the user has written source code which resides in that project, as opposed to classes which are imported from other projects, external jars, system libraries, etc.)
- Use
search
with a customIJavaSearchResultCollector
. - Obtain all of the packages in the project (using
search
?), then iterate through the packages, collecting the classes usingsearchAllTypeNames
. - Traverse the AST manually.
- Something else.
Note, I don't really need the "most efficient" way of collecting classes. I prefer something that is easy-to-code and reasonably efficient to something that requires large amounts of code to be more efficient.
I welcome any related, general guidance on using the SearchEngine
methods. I find the many options baffling.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您的搜索条件相当具体,因此最好的选择是遍历 Java 模型来查找您的类型。
这是一个您可以使用的小循环:
我建议使用这样的循环,而不是使用搜索引擎,因为据我所知,没有简单的方法可以使用搜索引擎仅查找源类型。
Since your search criteria are fairly specific, your best bet is to traverse the Java model to find your types.
Here is a little loop that you can use:
I recommend a loop like this rather than using the search engine since there is no easy way that I know of to use the search engine to only find source types.