3

I am trying to write a program to analyze Java source code, for example, checking all the callers to some certain method. Since eclipse IDE provides this kind of feature, which is powerful and impressive, I am wondering if they provide some APIs so I can use those features in my program as well.

I checked some materials online. But nearly all of the documents I can find are related with eclipse plug-in development, which is not what I want. I want to use them in a stand-alone program (maybe as part of a compilation chain to do customized style checking).

Is this possible? If so, any link as entrypoint for me to start research would be very appreciated. If not, is there any alternative that I can try? (I used to think about using ANTLR, but it is merely a parser that is quite a few steps away from a source code analyzer)

asked Jun 1, 2012 at 1:07
2
  • Hopefully useful: Sparse (C-only) MELT (plugin-writing toolkit for GCC). Commented Jun 1, 2012 at 1:26
  • @sarnold I forgot to specify that I am interested in Java source code analysing. I am looking at GCC MELT to check if it could be a choice for me. Thanks a lot. Commented Jun 1, 2012 at 1:38

5 Answers 5

1

I don't know about Eclipse itself, but here are some alternatives:

First, the relatively lightweight:

  • Findbugs. Relatively straightforward to write your own analyses if you're a decent Java programmer.
  • PMD. I haven't used it myself, but looks straightforward to write a Java analysis plus - added bonus - they support XPath-style queries of source-code ASTs.

These might be overkill, but the heavy guns for Java analysis are Soot from McGill U. and WALA from IBM.

Darshana
2,5486 gold badges30 silver badges58 bronze badges
answered Jun 1, 2012 at 1:51
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you very much. Soot seems to operate on Java bytecode, not on source code level, which may not be what I desire. I will examine the rest. Thanks.
Right. findbugs has the same issue. PMD, though, has source support as does WALA. For WALA, though, I think their source support is less mature than the bytecode support.
1

If you decide you like JDT, then it's not (terribly) difficult to develop an Eclipse RCP application that would only use the base Eclipse stuff with JDT and function as a standard command line application. There are a number of tutorials and papers on Eclipse RCP.

answered Jun 1, 2012 at 3:19

Comments

0

As an alterantive to Eclipse/ANTLR, see our DMS Software Reengineering Toolkit with its Java Front End. DMS provides general purpose parsing/tree building/pattern matching/source rewriting capabilities; the front end customizes DMS to know language details such as grammar, symbol tables, and flow analysis (for Java, presently limited to methods).

answered Jun 6, 2012 at 8:20

Comments

0

If you want to do "real" static analysis, I'd recommend going for one of the existing frameworks like Soot or Chord. The analysis you need is most likely already implemented there (although those tools usually prefer byte-code). On the other hand, especially the "find all callers"-analysis already exists within Eclipse; you can start looking from the CallHierarchyViewPart.

answered Jun 6, 2012 at 9:28

Comments

0

If you want to create a simple standalone program to do static code analysis then you seem to be on right path to use ANTLR.

Checkstyle also uses ANTLR to perform static code analysis. ANTLR will help you create abstract syntax tree (AST). But then you will have to write code to do different types of checks that you want. You can use 'walk' pattern of AST prepared by ANTLR to visit all tokens & then have a logic to execute on it & store or print the results. To get started, here is one very simple standalone example to perform class name check for abstract classes to make sure it starts with 'Abstract'.

answered Aug 11, 2019 at 0:22

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.