mrd abd
mrd abd

Reputation: 858

Statement level reflection in java

I'm looking for a mechanism in java (maybe like Reflection) to access the statements in a program. for example i access the statements of a function, then walk throw the statement tree to have analysis on java programs.

In .Net Microsoft provides the Extended Reflection. what is the alternative in java?


For C files, CIL process the .c source files and allow us to access the statements and walk throw the tree (even changing and inserting codes) statically. if there is a tool that process the .java codes and does similar works, can solve my problem.

Upvotes: 2

Views: 231

Answers (1)

Kevin Bowersox
Kevin Bowersox

Reputation: 94499

If you aim to analyze Java code via a Java application you will need a copy of the source code. .java files are essentially text files, so with the source code in hand your program could read the files similar to reading any text file.

There are several tools such as PMD and Clover that will perform this analysis for you. It may save time and resources to use an established tool. Although Clover is no longer a free tool it provides extensive metrics on code complexity. I believe PMD may provide similar metrics.

Upvotes: 2

Related Questions