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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3435581/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 00:46:50  来源:igfitidea点击:

How to count lines of Java code using IntelliJ IDEA?

javaintellij-ideametrics

提问by Gary

How to count lines of Java code using IntelliJ IDEA?

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

采纳答案by larham1

The Statisticplugin 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

查看 -> 工具窗口 -> 统计

回答by Dan Dyer

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

过去,我曾使用名称极佳的MetricsReloaded插件来获取此信息。

You can install it from the JetBrains repository.

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

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

安装后,通过以下方式访问:分析 -> 计算指标...

回答by Jenga Blocks

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

现在可以重新加载 2 个版本的指标。在 v9 和 v10 上支持的一种可在此处获得 http://plugins.intellij.net/plugin/?idea&id=93

回答by Neil

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.

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

回答by TheRusskiy

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.

如果只有空格的行也可以被认为是空的,那么您可以使用正则表达式"(\s*\n\s*)+"来不计算它们。

回答by s.froehlich

Although it is not an IntelliJ option, you could use a simple Bash command (ifyour 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

回答by algorhythm

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.

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

回答by AA.

You can to use Count Lines of Code (CLOC)

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

On Settings-> External Toolsadd a new tool

Settings->External Tools添加一个新工具

  • Name: Count Lines of Code
  • Group: Statistics
  • Program: path/to/cloc
  • Parameters: $ProjectFileDir$ or $FileParentDir$
  • 名称:计算代码行数
  • 组: 统计
  • 程序:路径/到/时钟
  • 参数:$ProjectFileDir$ 或 $FileParentDir$

回答by Jaskey

Statisticplugins works fine!

统计插件工作正常!

Here is a quick case:

这是一个快速案例:

  1. Ctrl+Shift+Aand serach for "Statistic" to open the panel.
  2. You will see panel as the screenshot and then click Refreshfor whole project or select your project or file and Refresh on selectionfor only selection.
  1. Ctrl+ Shift+A和检索算法的“统计”,打开面板。
  2. 您将看到面板作为屏幕截图,然后单击Refresh整个项目或选择您的项目或文件, Refresh on selection仅供选择。

statistic

统计