如何使用IntelliJ IDEA来计算Java代码行数?

时间:2021-08-24 20:23:27

I know I've used the feature in the past, but I have no idea how I did this before. It must be something simple, right?

我知道我以前用过这个功能,但是我不知道我以前是怎么做的。一定很简单,对吧?

9 个解决方案

#1


230  

The Statistic plugin worked for me.

统计插件对我有用。

To install it from Intellij:

要从Intellij安装它:

File - Settings - Plugins - Browse repositories... Find it on the list and double-click on it.

文件-设置-插件-浏览存储库…在列表中找到它,双击它。

Open statistics window from:

打开数据窗口:

View -> Tool Windows -> Statistic

视图->工具窗口->统计

#2


101  

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

快速而肮脏的方法是对“\n”进行全球搜索。你可以用任何你喜欢的方式过滤文件扩展等等。

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

Ctrl-Shift-F ->文本查找= '\n' ->查找。

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

编辑:必须检查“正则表达式”。

#3


40  

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

在过去,我使用了出色命名的Metrics Reloaded插件来获取这些信息。

You can install it from the JetBrains repository.

您可以从JetBrains存储库中安装它。

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

一旦安装,通过分析访问:>计算度量…

#4


21  

Just like Neil said:

就像尼尔说:

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

“Ctrl-Shift-F ->文本查找= '\n' ->查找。”

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

只有一个改进,如果您输入“\n+”,您可以搜索非空行

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

如果只有空格的行也被认为是空的,那么您可以使用regex“(\s*\n\s* \s*)+”来不计算它们。

#5


9  

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:

虽然它不是IntelliJ选项,但是您可以使用一个简单的Bash命令(如果您的操作系统是Linux/Unix)。转到源目录并输入:

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

#6


6  

Statistic plugins works fine!

统计插件没问题!

Here is a quick case:

这里有一个简单的例子:

  1. Ctrl+Shift+A and serach for "Statistic" to open the panel.
  2. Ctrl+Shift+A和serach为“statistics”打开面板。
  3. 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.
  4. 您将看到面板作为屏幕截图,然后单击Refresh for whole project或者选择您的项目或文件,并在选择时刷新为only selection。

如何使用IntelliJ IDEA来计算Java代码行数?

#7


5  

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

现在有两个版本的metricsreloaded。在v9和v10上支持的一个版本是http://plugins.intellij.net/plugin/?idea&id=93。

#8


3  

You can to use Count Lines of Code (CLOC)

您可以使用计数代码行(CLOC)

On Settings -> External Tools add a new tool

在设置->外部工具添加一个新的工具

  • Name: Count Lines of Code
  • 名称:计数代码行
  • Group: Statistics
  • 组:统计数据
  • Program: path/to/cloc
  • / / cloc计划:路径
  • Parameters: $ProjectFileDir$ or $FileParentDir$
  • 参数:ProjectFileDir美元或FileParentDir美元

#9


1  

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

要找到包括空行代码的所有内容,请尝试@Neil的解决方案:

Open Find in Path (Ctrl+Shift+F)

在路径中打开查找(Ctrl+Shift+F)

Search for the following regular expression: \n'

搜索以下正则表达式:\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.

注意:如果后面有换行符,则只计算文件的最后一行。

#1


230  

The Statistic plugin worked for me.

统计插件对我有用。

To install it from Intellij:

要从Intellij安装它:

File - Settings - Plugins - Browse repositories... Find it on the list and double-click on it.

文件-设置-插件-浏览存储库…在列表中找到它,双击它。

Open statistics window from:

打开数据窗口:

View -> Tool Windows -> Statistic

视图->工具窗口->统计

#2


101  

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

快速而肮脏的方法是对“\n”进行全球搜索。你可以用任何你喜欢的方式过滤文件扩展等等。

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

Ctrl-Shift-F ->文本查找= '\n' ->查找。

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

编辑:必须检查“正则表达式”。

#3


40  

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

在过去,我使用了出色命名的Metrics Reloaded插件来获取这些信息。

You can install it from the JetBrains repository.

您可以从JetBrains存储库中安装它。

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

一旦安装,通过分析访问:>计算度量…

#4


21  

Just like Neil said:

就像尼尔说:

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

“Ctrl-Shift-F ->文本查找= '\n' ->查找。”

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

只有一个改进,如果您输入“\n+”,您可以搜索非空行

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

如果只有空格的行也被认为是空的,那么您可以使用regex“(\s*\n\s* \s*)+”来不计算它们。

#5


9  

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:

虽然它不是IntelliJ选项,但是您可以使用一个简单的Bash命令(如果您的操作系统是Linux/Unix)。转到源目录并输入:

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

#6


6  

Statistic plugins works fine!

统计插件没问题!

Here is a quick case:

这里有一个简单的例子:

  1. Ctrl+Shift+A and serach for "Statistic" to open the panel.
  2. Ctrl+Shift+A和serach为“statistics”打开面板。
  3. 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.
  4. 您将看到面板作为屏幕截图,然后单击Refresh for whole project或者选择您的项目或文件,并在选择时刷新为only selection。

如何使用IntelliJ IDEA来计算Java代码行数?

#7


5  

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

现在有两个版本的metricsreloaded。在v9和v10上支持的一个版本是http://plugins.intellij.net/plugin/?idea&id=93。

#8


3  

You can to use Count Lines of Code (CLOC)

您可以使用计数代码行(CLOC)

On Settings -> External Tools add a new tool

在设置->外部工具添加一个新的工具

  • Name: Count Lines of Code
  • 名称:计数代码行
  • Group: Statistics
  • 组:统计数据
  • Program: path/to/cloc
  • / / cloc计划:路径
  • Parameters: $ProjectFileDir$ or $FileParentDir$
  • 参数:ProjectFileDir美元或FileParentDir美元

#9


1  

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

要找到包括空行代码的所有内容,请尝试@Neil的解决方案:

Open Find in Path (Ctrl+Shift+F)

在路径中打开查找(Ctrl+Shift+F)

Search for the following regular expression: \n'

搜索以下正则表达式:\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.

注意:如果后面有换行符,则只计算文件的最后一行。