Java 在 Eclipse 中计算行号
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1043666/
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
Counting Line Numbers in Eclipse
提问by user128807
I have a Java project in Eclipse with ~10 packages and ~10 class files per package. Is there a way to determine total lines of code for the whole project from within Eclipse? I am familiar with other tools (e.g., Code Analyzer, wc, etc.) but I want to know if there is a way to do this within Eclipse (or get confirmation that there is no way to do it).
我在 Eclipse 中有一个 Java 项目,每个包有 ~10 个包和 ~10 个类文件。有没有办法从 Eclipse 中确定整个项目的总代码行数?我熟悉其他工具(例如,代码分析器、wc 等),但我想知道是否有办法在 Eclipse 中执行此操作(或确认无法执行此操作)。
采纳答案by AlbertoPL
Here's a good metrics plugin that displays number of lines of code and much more:
这是一个很好的指标插件,可以显示代码行数等等:
http://metrics.sourceforge.net/
http://metrics.sourceforge.net/
It says it requires Eclipse 3.1, although I imagine they mean 3.1+
它说它需要 Eclipse 3.1,虽然我想他们的意思是 3.1+
Here's another metrics plugin that's been tested on Ganymede:
这是在 Ganymede 上测试过的另一个指标插件:
回答by akarnokd
I think if you have MyEclipse, it adds a label to the Project Properties page which contains the total number of source code lines. Might not help you as MyEclipse is not free though.
我想如果你有 MyEclipse,它会向包含源代码行总数的项目属性页面添加一个标签。可能对您没有帮助,因为 MyEclipse 不是免费的。
Unfortunately, that wasn't enough in my case so I wrote a source analyzer to gather statistics not gathered by other solutions (for example the metrics mentioned by AlbertoPL).
不幸的是,这对我来说还不够,所以我编写了一个源分析器来收集其他解决方案没有收集的统计数据(例如 AlbertoPL 提到的指标)。
回答by Rich Seller
Are you interested in counting the executable lines rather than the total file line count? If so you could try a code coverage tool such as EclEmma. As a side effect of the code coverage stats you get stats on the number of executable lines and blocks (and methods and classes). These are rolled up from the method level upwards, so you can see line counts for the packages, source roots and projects as well.
您是否对计算可执行行数而不是总文件行数感兴趣?如果是这样,您可以尝试使用代码覆盖工具,例如EclEmma。作为代码覆盖率统计的副作用,您可以获得有关可执行行和块(以及方法和类)数量的统计数据。这些是从方法级别向上汇总的,因此您还可以查看包、源代码根和项目的行数。
回答by Brian Sweeney
Search
> File Search
Search
> File Search
Check the Regular expression
box.
选中该Regular expression
框。
Use this expression:
使用这个表达式:
\n[\s]*
\n[\s]*
Select whatever file types (*.java
, *.xml
, etc..) and working sets are appropriate for you.
选择适合您的任何文件类型(*.java
、*.xml
等)和工作集。
回答by Gábor Lipták
You could use former Instantiations product CodePro AnalytiX. This eclipse plugin provides you suchlike statistics in code metrics view. This is provided by Google free of charge.
您可以使用以前的 Instantiations 产品CodePro AnalytiX。这个 eclipse 插件在代码度量视图中为您提供了类似的统计信息。这是由 Google 免费提供的。
回答by Ashish
回答by Yann
Under linux, the simpler is:
在linux下,更简单的是:
- go to the root folder of your project
- use
find
to do a recursive search of *.java files - use
wc -l
to count lines:
- 转到项目的根文件夹
- 用于
find
对 *.java 文件进行递归搜索 - 用于
wc -l
计算行数:
To resume, just do:
要恢复,只需执行以下操作:
find . -name '*.java' | xargs wc -l
回答by user5146215
You could use a batch file with the following script:
您可以使用带有以下脚本的批处理文件:
@echo off
SET count=1
FOR /f "tokens=*" %%G IN ('dir "%CD%\src\*.java" /b /s') DO (type "%%G") >> lines.txt
SET count=1
FOR /f "tokens=*" %%G IN ('type lines.txt') DO (set /a lines+=1)
echo Your Project has currently totaled %lines% lines of code.
del lines.txt
PAUSE
回答by GrabNewTech
A very simple plugin for counting actual lines of source code is step countereclipse plugin. Please download and try.
一个非常简单的用于计算源代码实际行数的插件是step countereclipse 插件。请下载并尝试。
Place the downloaded jar file under eclipse\plugin folder and restart eclipse.
将下载的jar文件放到eclipse\plugin文件夹下,重启eclipse。
Rightclick and select step counter
右键单击并选择计步器