如何在 Eclipse 中搜索对 AST 或 CompilationUnit 上字段的引用?
嗨,
我正在开发一个 Eclipse 插件。我 需要找到所有参考文献 使用 AST 或 jdt.core.dom 的源 或类似的东西。我需要这个 诸如
ASTNodes
之类的引用,以便 获取父节点并检查几个 表达式中的事物 where 涉及参考文献。 预先感谢。
编辑:
我想更具体一点,我的问题是我尝试捕获一些对常量的引用,但是...我不知道如何才能捕获此引用的匹配项。我需要检查涉及对确定常量的引用的表达式。我只得到使用它们的方法的来源。
我认为问题在于范围或模式:
pattern = SearchPattern.createPattern(field, IJavaSearchConstants.REFERENCES);
scope = SearchEngine.createJavaSearchScope(declaringType.getMethods());
预先感谢!
Hi,
I'm developing an Eclipse plugin. I
need to find all the references in the
source using AST's orjdt.core.dom
or something like that. I need this
references likeASTNodes
in order to
get the parent node and check several
things in the expression where
references are involved.
Thanks beforehand.
Edited:
I want to concrete a little more, My problem is that I try to catch some references to a constant but... I have not idea how I can do to catch in the matches this references. I need check the expressions which the references to a determined constant are involved. I only get the source of the method where they are used.
I think the problem is the scope or the pattern:
pattern = SearchPattern.createPattern(field, IJavaSearchConstants.REFERENCES);
scope = SearchEngine.createJavaSearchScope(declaringType.getMethods());
Thanks beforehand!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我用过类似的东西:
方法,返回一个 IMethod
IMethod,记录这些 IMethod
从其编译单元
搜索声明或引用的 AST 类似于以下代码。
获得 IMethod 引用后,您可以使用以下方法访问 AST:
请参阅 http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse.jdt.doc.isv/guide/jdt_int_core.htm 了解有关 java 搜索的更多详细信息、java 模型和 AST。
I used something like:
method, returns an IMethod
IMethod, record those IMethods
AST from its compilation unit
Searching for declarations or references looks like the following code.
Once you have your IMethod references, you can get to the AST using:
See http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse.jdt.doc.isv/guide/jdt_int_core.htm for more details on java search, the java model, and the AST.