• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 251
  • Last Modified:

obtaining line of codes from a class file

i'm currently developing a metric tool (e.g., depth of inheritance, number of private methods, number of public fields and etc). my input(s) to the tool is(are) java class(es)- (.class extension).

i wonder is it possible to obtain metrics such as LINE OF CODES (line of comments, line of executable codes and etc) just from java classes (files with .class extension).

some samples are appreciated.
0
ervinloh
Asked:
ervinloh
1 Solution
 
mraibleCommented:
I would venture to say that .class files don't have lines of code being that they're binary files.  And also, .class files don't have comments.  The compiler strips them out.

However, you might be able to get fields, methods, etc. using the java.lang.reflection package.

For methods available on a class see:

http://java.sun.com/j2se/1.3/docs/api/java/lang/Class.html

So to answer your question: my guess is no.
0
 
ervinlohAuthor Commented:
to mraible,

getting fields, methods and etc is not a problem. only line of codes is giving me the problems.
0
 
girionisCommented:
 You can get the lines of code from the Java source file (if it is available) and not from the class file itself. Just read the file and check for the "\n" character (newline).

  Hope it helps.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
CEHJCommented:
Can't get source code from class file. Only from source file.
0
 
objectsCommented:
You can use a decompiler to generate source from a class file. However this will not be the same as the source code before it was compiled so i'm not sure of its value for metrics purposes. But it may help you.

0
 
yasser_helmyCommented:
The class file does not have lines. The compiler strips comments and blank line. It also generates binary code instead of the source code, which means the source code is not available any more. The compilation process lossses the information about number of lines, comments, and the explicit code written.
0
 
girionisCommented:
No comment has been added lately, so it's time to clean up this TA.

I will leave a recommendation in the Cleanup topic area that this question is:

- points to mraible

Please leave any comments here within the
next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

girionis
Cleanup Volunteer
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now