1

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.

Rohit
  • 33
  • 3

2 Answers2

1

Generally speaking it's a problem of dependencies analysis/management.

Several tools/topics already exists :

Community
  • 1
  • 1
Aubin
  • 14,617
  • 9
  • 61
  • 84
-1

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:

  1. Searching for all classes which implement Serializable interface: grep -iR 'implements Serializable' *
  2. Count all classes which implement Serializable interface: grep -iR 'implements Serializable' * | wc -l
  3. Do the same as #2, but skip any files within .svn subdirectories: 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.

ŁukaszBachman
  • 33,595
  • 11
  • 64
  • 74
  • 1
    Technically speaking, that won't find all classes that implement `Serializable`, since it won't find source-files that have multiple spaces between `implements` and `Serializable` (or, worse yet, a comment and/or line-break between them), nor source-files that contain `implements List, Serializable`, nor classes that extend classes that implement `Serializable`, nor classes that implement interfaces that extend `Serializable`. – ruakh Nov 27 '11 at 20:46
  • That is correct. I wanted to provide general idea of how this can be achieved. The regular expression itself should be well thought to provide most precise matches. – ŁukaszBachman Nov 28 '11 at 21:31
  • Very bad idea, a complex source as Java, C/C++/C# or Ada can't be well analyzed with lexical tools but grammatical tools – Aubin Oct 13 '12 at 08:27