基于 AST 的 Eclipse 搜索

发布于 2024-08-20 03:35:31 字数 320 浏览 2 评论 0原文

Eclipse 是否有一个插件可以让您根据项目文件的 Java AST(抽象语法树)进行搜索? “Java 搜索”功能似乎并不涵盖以下情况:

“获取所有类中声明为“X”类型的所有字段”

我可以想象基于 AST 的搜索会带来更多可能性,但我也不知道这样的插件是否有实用性能。

更新:正如 Kevin 下面所指出的,Java 搜索功能确实涵盖了我提到的用例。我仍然很好奇是否有人编写了一个允许任意类型 AST 搜索的插件,例如。 “获取所有字符串连接”(带有 + 运算符和 StringLiteral 操作数的 InfixExpression)

Is there a plug-in for Eclipse that lets you search based on the Java AST (Abstract Syntax Tree) of your project files? The "Java Search" feature doesn't seem to cover cases like:

"Get me all the fields declared as type 'X' in all classes"

I can imagine many more possibilities that would open up with an AST-based search, but I don't even know if such a plug-in would have practical performance.

Update: As pointed out by Kevin below, the Java Search feature does cover the use case I mentioned. I'm still curious though about whether or not someone has written a plug-in that allows any arbitrary kind of AST search, ex. "Get all string concatenations" (InfixExpression with + operator and StringLiteral operand)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

情深已缘浅 2024-08-27 03:35:31

有几个 Eclipse 插件提供面向对象的查询语言并旨在回答此类查询。其中一些:

在 Eclipse 之外有 < a href="http://www.javadepend.com/Features.aspx#CQL" rel="nofollow noreferrer">JArchitect 代码查询语言

There are several Eclipse plug-ins that provide object-oriented query languages and aim to answer such queries. Some of them:

Outside Eclipse there is JArchitect Code Query Language

无人接听 2024-08-27 03:35:31

获取所有声明为类型的字段
所有类别中的“X”

我不知道您还有什么想法,但我相信您可以通过执行以下操作来完成此特定搜索:

  • 打开类型 X (Ctrl-Shift-T)
  • 突出显示类名
  • Ctrl-H搜索
  • 搜索类型/匹配位置 ->字段类型

Get me all the fields declared as type
'X' in all classes

I don't know what else you had in mind but I believe you can accomplish this specific search by doing the following:

  • Opening up type X (Ctrl-Shift-T)
  • Highlight the class name
  • Ctrl-H to search
  • Search for Type / Match Locations -> Field Types
橘寄 2024-08-27 03:35:31

这并不完全是您正在寻找的内容,但 nWire for Java 可以为您提供大量源自 AST 的信息。它还具有全文搜索功能,用于搜索任何类型、方法、字段等。找到所需内容后,单击即可显示该组件的所有关联。

请在此处查看演示。

It's not exactly what you're looking for, but nWire for Java can give you a lot of information which is derived from the AST. It also has a full text search for searching any type, method, field, etc. Once you find what you're looking for, a click will show you all the associations of that component.

Check out the demo here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文