How to count lines of Java code using IntelliJ IDEA?

JavaIntellij IdeaMetrics

Java Problem Overview


How to count lines of Java code using IntelliJ IDEA?

Java Solutions


Solution 1 - Java

The Statistic plugin worked for me.

To install it from Intellij: > File - Settings - Plugins - Browse repositories... Find it on the list and double-click on it.

Access the 'statistic' toolbar via tabs in bottom left of project screen capture of statistic toolbar, bottom left

OLDER VERSIONS: Open statistics window from: > View -> Tool Windows -> Statistic

Solution 2 - Java

Quick and dirty way is to do a global search for '\n'. You can filter it any way you like on file extensions etc.

Ctrl-Shift-F -> Text to find = '\n' -> Find.

Edit: And 'regular expression' has to be checked.

Solution 3 - Java

In the past I have used the excellently named MetricsReloaded plugin to get this information.

You can install it from the JetBrains repository.

Once installed, access via: Analyze -> Calculate Metrics...

Solution 4 - Java

Although it is not an IntelliJ option, you could use a simple Bash command (if your operating system is Linux/Unix). Go to your source directory and type:

find . -type f -name '*.java' | xargs cat | wc -l

Solution 5 - Java

Just like Neil said:

> Ctrl-Shift-F -> Text to find = '\n' -> Find.

With only one improvement, if you enter "\n+", you can search for non-empty lines

If lines with only whitespace can be considered empty too, then you can use the regex "(\s*\n\s*)+" to not count them.

Solution 6 - Java

Statistic plugins works fine!

Here is a quick case:

  1. Ctrl+Shift+A and serach for "Statistic" to open the panel.
  2. You will see panel as the screenshot and then click Refresh for whole project or select your project or file and Refresh on selection for only selection.

statistic

Solution 7 - Java

now 2 versions of metricsreloaded available. One supported on v9 and v10 isavailable here http://plugins.intellij.net/plugin/?idea&id=93

Solution 8 - Java

You can to use Count Lines of Code (CLOC)

On Settings -> External Tools add a new tool

  • Name: Count Lines of Code

  • Group: Statistics

  • Program: path/to/cloc

  • Parameters: $ProjectFileDir$ or $FileParentDir$

Solution 9 - Java

To find all including empty lines of code try @Neil's solution:

Open Find in Path (Ctrl+Shift+F)

Search for the following regular expression: \n'

For lines with at least one character use following expression:

(.+)\n

For lines with at least one word character or digit use following expression:

`(.*)([\w\d]+)(.*)\n`

Notice: But the last line of file is just counted if you have a line break after it.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionGaryView Question on Stackoverflow
Solution 1 - Javalarham1View Answer on Stackoverflow
Solution 2 - JavaNeilView Answer on Stackoverflow
Solution 3 - JavaDan DyerView Answer on Stackoverflow
Solution 4 - Javas.froehlichView Answer on Stackoverflow
Solution 5 - JavaTheRusskiyView Answer on Stackoverflow
Solution 6 - JavaJaskeyLamView Answer on Stackoverflow
Solution 7 - JavaJenga BlocksView Answer on Stackoverflow
Solution 8 - JavaAA.View Answer on Stackoverflow
Solution 9 - JavaalgorhythmView Answer on Stackoverflow