以编程方式在工作区中查找接口的引用
只是想知道哪种工具/方法可以轻松/轻松地解决以下问题?需要通过 ANT 脚本调用。
Eclipse 工作区有几个项目,例如项目 A - 项目 O(数量为 15)。其中大部分是 Java 项目。这里的要点是,我需要在不使用 Eclipse IDE 的情况下收集一些数据,而是通过编程方式收集一些数据。
在projectA(这是一个java项目)中,有一个接口(例如InterFaceA),它正在其他各种项目中实现。
重点是我需要列出所有 15 个项目中已实现 InterfaceA 的所有类。
我遇到了一些工具,例如扩展 Javadoc、eclipse AST、javaCC、ANTLR,但没有找到现成的解决方案。
想到了下面的办法,但发现很难实施。
- 找出所有声明的变量、字段、方法级别,即整个java文件/类,并找出它们的类型,并在其中找出实现InterfaceA的类。
- 是否可以像 eclipse 这样在整个工作区中查找 interfaceA 的引用,但是通过代码?如果我能得到 Eclipse 如何如此快地做到这一点的源代码,我将不胜感激。
我可以请求一个直接的解决方案吗?可以使用 eclipse AST 以良好且直观的方式完成此任务吗?
PS:现有代码没有得到很好的维护。因此,可能性就像接口 A 可能没有用实例变量声明,而只是在使用之前用作局部变量等等。 另外还有很多内部类等。
提前致谢。
Just wondering which tool / approach can solve the following issue easily / with less effort? The need is to invoke via ANT script.
The eclipse workspace has a couple of projects, say projectA - projectO (15 in number). Most of them are Java Projects. The point here I need to gather some data without using the eclipse IDE, rather through programmatically.
In projectA, which is a java project, has an Interface, say InterFaceA, which is being implemented in various other projects.
The point is I need to list out all the classes from all the 15 projects which have implemented the InterfaceA.
I came across couple of tools, like extending the Javadoc, eclipse AST, javaCC, ANTLR, but not finding a readymade solution.
Thought of below approaches, but finding it hard to implement.
- Find out all the variables declared, field, method level, i.e. throughout the java file / class and find out their type and among them find out the class that implements the InterfaceA.
- Do something like eclipse find references in the whole workspace for the interfaceA, but through code? Would appreciate if I get the source how eclipse does that so fast.
Can I request for a direct solution, may be using eclipse AST to get this done in a nice and intuitive manner?
P.S.: The existing code isn't neatly maintained. So, the possibilities are like the interfaceA may NOT have been declared with an instance variable, but just used as a local variable just before it's being used and so on.
Plus there are many inner classes, etc.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一般来说,这是一个依赖分析/管理的问题。
已经存在几个工具/主题:
Generally speaking it's a problem of dependencies analysis/management.
Several tools/topics already exists :
对我来说,最简单的方法是在 Linux shell 中使用 grep 和 wc 等工具来完成此操作。
GREP 会让您找到您喜欢的任何类型的模式(毕竟您有源代码,因此深入研究它应该不会有任何问题),即“实现 InterFaceA”或“扩展 SomeClassB”。
感谢 WC,您可以计算模式的出现次数。两者结合将为您带来巨大的可能性。
例如:
grep -iR 'implements Serialized' *
grep -iR 'implements Serializable' * | wc -l
grep -iR 'implements Serialized' * | grep -v .svn | grep -v .svn | grep -v .svn | grep -v .svn厕所-l
现在,要将其与 ANT 连接起来,您只需创建一个 ANT 任务来执行 bash 命令。您应该不难找到很多如何做到这一点的示例。
如果您不使用 Linux,Windows 下也有等效的工具。只需在网络上搜索,您就会找到类似于此的内容。
希望有帮助。
For me the easiest way would be to do that in Linux shell with tools such as grep and wc.
GREP will let you find any kind of patterns that you like (after all you have source code, so digging through it shouldn't be any problem), i.e. 'implements InterFaceA' or 'extends SomeClassB'.
Thanks to WC you can count occurrence of a pattern. Combining the two will give you an immense possibilities.
For example:
grep -iR 'implements Serializable' *
grep -iR 'implements Serializable' * | wc -l
grep -iR 'implements Serializable' * | grep -v .svn | wc -l
Now, to wire it up with ANT you can simply create an ANT task which will execute bash command. You should have no difficulties to find lots of examples of how to do that.
If you don't use Linux, there are equivalent tools available under Windows. Just search the web and you will find something similar to this.
Hope that helps.