0

How can I get methodwise line of code given the java source file? I need the logic of getting the LOC in methods.

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52

1 Answers1

0

How do you need that data? For which language, Java I guess, right?

Basically, any static code analyzer tool can help you with that, there're quite a lot of them, for a start, check out this list.

If you need only a brief overview, you could try any IDE-based plugins (like metrics or eclipse-metrics for Eclipse).

If the trend how that property changes is important, you could also try one of the big guys like Sonar.

Nota bene there are quite a lot of definitions for the line of code metric (LOC/ELOC/LLOC, etc., which means the total line of code, effective line of code, logical line of code that contains keywords, ...). Each tool states how it measures that property, check out the documentation.

rlegendi
  • 10,466
  • 3
  • 38
  • 50
  • Thanks for the valuable info rlegendi. I need to write a Java code to calculate the LOC inside methods blocks given the .java source file. – Adrian Dharmaratne Mar 19 '12 at 18:08
  • Yeah, as I said, there are quite a lot of definitions for LoC :-) Here's a simple solution: `Path file = Paths.get(filename); int loc = Files.readAllLines(file, Charset.defaultCharset()).size();` – rlegendi Mar 22 '12 at 12:58