资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

包含java代码注释统计工具的词条

求问怎么统计JAVA代码行数?有什么工具?

源代码行数统计器 1.5

让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:申请域名、网络空间、营销软件、网站建设、城区网站维护、网站推广。

本软件用于统计软件工程源代码行数,

可对指定的子目录下或整个目录树中所有指定类型的源代码文件进行行数统计。

急!急!急!急!急! 在一个文件夹目录下 如果是.java文件就分析出有效代码行数、空行数、注释行数。接下面

我们以前在学校的时候也做过这个,还要用Swing做界面。不过今天是我从新做出来的

JavaSourceUtil.java

import java.io.BufferedReader;

import java.io.File;

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.InputStreamReader;

import java.util.ArrayList;

import java.util.List;

class JavaSourceUtil {

public static void main(String[] args) {

// 统计文件路径

String folderPath = "C:\\Users\\xmi\\Desktop\\AnzDoc\\123\\BatchAssistant\\src\\dcb\\";

// 路径文件

File folder = new File(folderPath);

// 源文件统计工具

JavaSourceUtil util = new JavaSourceUtil();

// 根据路径得到统计结果列表

ListSourceBean cntList = util.countJavaSource(folder);

// 根据统计行数计算注释率、空行率、有效代码率的结果

StringBuffer resultSbuf = util.outputCountResult(cntList);

// 输出统计结果

System.out.println(resultSbuf.toString());

// 保存结果到文件

util.saveFile(resultSbuf, "D:\\java_source_cnt.txt");

}

public StringBuffer outputCountResult(ListSourceBean listBean){

StringBuffer sbuf = new StringBuffer();

SourceBean totalCntBean = new SourceBean("全部文件统计");

for(SourceBean bean : listBean) {

int tolCnt = bean.getTotalLine();

if (tolCnt == 0) {

continue;

}

// 注释率、空行率、有效代码率的结果算出来

sbuf.append(bean.fileName + "代码统计:").append("\r\n");

sbuf.append("空行率:").append(bean.blankLine * 1.0 / tolCnt)

.append("\r\n");

sbuf.append("注释率:")

.append((bean.singlgCmtLine + bean.multCmtLine) * 1.0

/ tolCnt).append("\r\n");

sbuf.append("有效代码率:").append(bean.codeLine * 1.0 / tolCnt)

.append("\r\n\r\n");

totalCntBean.blankLine += bean.blankLine;

totalCntBean.codeLine += bean.codeLine;

totalCntBean.documtLine += bean.documtLine;

totalCntBean.multCmtLine += bean.multCmtLine;

totalCntBean.singlgCmtLine += bean.singlgCmtLine;

}

sbuf.append(totalCntBean.fileName + "代码统计:").append("\r\n");

sbuf.append("总空行率:").append(totalCntBean.blankLine * 1.0 / totalCntBean.getTotalLine())

.append("\r\n");

sbuf.append("总注释率:")

.append((totalCntBean.singlgCmtLine + totalCntBean.multCmtLine) * 1.0

/ totalCntBean.getTotalLine()).append("\r\n");

sbuf.append("总有效代码率:").append(totalCntBean.codeLine * 1.0 / totalCntBean.getTotalLine())

.append("\r\n\r\n");

return sbuf;

}

/**

 * Java代码统计

 * @param folder 基本路径

 * @return 统计结果

 */

public ListSourceBean countJavaSource(File folder){

ListSourceBean cntList = new ArrayListSourceBean();

if (!folder.exists() || !folder.isDirectory()) {

return cntList;

}

File[] files = folder.listFiles();

for (int i = 0; i  files.length; i++) {

if (files[i].isDirectory()) {

cntList.addAll(countJavaSource(folder));

} else {

SourceBean cntBean = countCodeLine(files[i]);

if (cntBean != null) {

cntList.add(cntBean);

}

}

}

return cntList;

}

/**

 * 单个文件代码统计

 * @param javaFile .java文件

 * @return 统计结果

 */

public SourceBean countCodeLine(File javaFile){

if(!javaFile.exists() || !javaFile.isFile() || !javaFile.getName().endsWith(".java")){

return null;

}

SourceBean cntBean = new SourceBean(javaFile.getAbsolutePath());

// 代码状态

int status = 0;

try {

InputStreamReader isr = new InputStreamReader(new FileInputStream(javaFile)); 

String str = "";

BufferedReader bufReader = new BufferedReader(isr);

while((str = bufReader.readLine()) != null){

str = str.trim();

if (str.startsWith("/**")) {

// 文档注释

status = 10;

} else if (str.startsWith("/*")) {

// 多行注释

status = 20;

}

if (isEmpty(str)) {

// 空白航

cntBean.blankLine ++;

} else if (status == 10) {

// 文档注释

cntBean.documtLine ++;

} else if (status == 20) {

// 多行注释

cntBean.multCmtLine ++;

} else if (str.startsWith("//")) {

// 单行注释

cntBean.singlgCmtLine ++;

} else {

// 代码行

cntBean.codeLine ++;

}

if (str.endsWith("*/")) {

// 单行或文本注释结束

status = 0;

}

}

bufReader.close();

} catch (FileNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

return cntBean;

}

/**

 * 空行判断

 * @param strValue

 * @return 是否为空行

 */

public boolean isEmpty(String strValue){

if (strValue == null || strValue.trim().equals("")) {

return true;

}

return false;

}

/**

 * 读取文本文件

 * @param path

 * @return

 */

public void saveFile(StringBuffer builder, String path){

try {

FileOutputStream fos = new FileOutputStream(path);

fos.write(builder.toString().getBytes("utf-8"));

fos.flush();

fos.close();

} catch (FileNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

SourceBean.java

public class SourceBean {

// 空白行

public int blankLine;

// 单行注释

public int singlgCmtLine;

// 多行注释

public int multCmtLine;

// 代码行数

public int codeLine;

// 文挡注释

public int documtLine;

// 文件名

public String fileName;

public SourceBean(String fileName){

this.fileName = fileName;

}

public int getTotalLine(){

int totalLine = blankLine + singlgCmtLine + multCmtLine + codeLine

+ documtLine;

return totalLine;

}

}

是不是很简单!

Java 有什么好的代码行数,注释行数统计工具

package com.syl.demo.test;

import java.io.*;

/**

* java代码行数统计工具类

* Created by 孙义朗 on 2017/11/17 0017.

*/

public class CountCodeLineUtil {

private static int normalLines = 0; //有效程序行数

private static int whiteLines = 0; //空白行数

private static int commentLines = 0; //注释行数

public static void countCodeLine(File file) {

System.out.println("代码行数统计:" + file.getAbsolutePath());

if (file.exists()) {

try {

scanFile(file);

} catch (IOException e) {

e.printStackTrace();

}

} else {

System.out.println("文件不存在!");

System.exit(0);

}

System.out.println(file.getAbsolutePath() + " ,java文件统计:" +

"总有效代码行数: " + normalLines +

" ,总空白行数:" + whiteLines +

" ,总注释行数:" + commentLines +

" ,总行数:" + (normalLines + whiteLines + commentLines));

}

private static void scanFile(File file) throws IOException {

if (file.isDirectory()) {

File[] files = file.listFiles();

for (int i = 0; i files.length; i++) {

scanFile(files[i]);

}

}

if (file.isFile()) {

if (file.getName().endsWith(".java")) {

count(file);

}

}

}

private static void count(File file) {

BufferedReader br = null;

// 判断此行是否为注释行

boolean comment = false;

int temp_whiteLines = 0;

int temp_commentLines = 0;

int temp_normalLines = 0;

try {

br = new BufferedReader(new FileReader(file));

String line = "";

while ((line = br.readLine()) != null) {

line = line.trim();

if (line.matches("^[//s[^//n]]*$")) {

// 空行

whiteLines++;

temp_whiteLines++;

} else if (line.startsWith("/*") !line.endsWith("*/")) {

// 判断此行为"/*"开头的注释行

commentLines++;

comment = true;

} else if (comment == true !line.endsWith("*/")) {

// 为多行注释中的一行(不是开头和结尾)

commentLines++;

temp_commentLines++;

} else if (comment == true line.endsWith("*/")) {

// 为多行注释的结束行

commentLines++;

temp_commentLines++;

comment = false;

} else if (line.startsWith("//")) {

// 单行注释行

commentLines++;

temp_commentLines++;

} else {

// 正常代码行

normalLines++;

temp_normalLines++;

}

}

System.out.println(file.getName() +

" ,有效行数" + temp_normalLines +

" ,空白行数" + temp_whiteLines +

" ,注释行数" + temp_commentLines +

" ,总行数" + (temp_normalLines + temp_whiteLines + temp_commentLines));

} catch (FileNotFoundException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

} finally {

if (br != null) {

try {

br.close();

br = null;

} catch (IOException e) {

e.printStackTrace();

}

}

}

}

//测试

public static void main(String[] args) {

File file = new File("F:\\myweb");

countCodeLine(file);

}

}

告诉我一个统计java代码量的小工具,非空非注的。

网上有个叫SourceCounter的工具可以统计代码,你可以搜一下,作者的邮箱是boomworks@hotmail.com。我这也有这个工具,需要的话可以留个邮箱,给你发也行。软件大小2.71M

代码统计工具,要支持差异统计,如:代码修改行数、删除行数、新增行数等

我想你要的正是TortoiseSVN,使用方法见

他的代码差异统计功能无庸质疑

另外介绍一个也是统计代码差异的工具:StatSVN

StatSVN能够从Subversion版本库中取得信息,然后生成描述项目开发的各种表格和图表。比如:总代码行数;代码行数的时间线;针对每个开发者的代码行数;开发者的活跃程度;开发者最近所提交的;文件数量;平均文件大小;最大文件;哪个文件是修改最多次数的;目录大小;带有文件数量和代码行数的Repository tree。StatSVN当前版本能够生成一组包括表格与图表的静态HTML文档。

java开发工具中的代码管理工具有那些?

Code Review中文应该译作“代码审查”或是“代码评审”,这是一个流程,当开发人员写好代码后,需要让别人来review一下他的代码,这是一种有效发现BUG的方法。由此,我们可以审查代码的风格、逻辑、思路……,找出问题,以及改进代码。因为这是代码刚刚出炉的时候,所以,这也是代码重构,代码调整,代码修改的最佳时候。所以,Code Review是编码实现中最最重要的一个环节。长时间以来,Code Review需要有一些有效的工具来支持,这样我们就可以更容易,更有效率地来进行代码审查工作。下面是5个开源的代码审查工具,他们可以帮助你更容易地进行这项活动。1. Review board: Review board 是一个 基于web 的工具,主要设计给 django 和python的用户。 Review board 可以帮助我们追踪待决代码的改动,并可以让Code-Review更为容易和简练。尽管Review board 最初被设计在VMware项目中使用,但现在其足够地通用。当前,其支持这些代码版本管理软件: SVN, CVS, Perforce, Git, Bazaar, 和Mercurial.Yahoo 是review-board的其中一个用户。“Review board 已经改变了代码评审的方式,其可以强迫高质量的代码标准和风格,并可以成为程序员编程的指导者。每一次,当你访问search.yahoo.com 时,其代码都是使用 Review board工具Review过的。 We’re great fans of your work!”– Yahoo! Web Search 2. Codestriker: Codestriker 也是一个基于Web的应用,其主要使用 GCI-Perl 脚本支持在线的代码审查。Codestriker 可以集成于CVS, Subversion, ClearCase, Perforce 和Visual SourceSafe。并有一些插件可以提供支持其它的源码管理工具。David Sitsky 是 Codestriker 的作者,并也是最活跃的开发人员之一。 Jason Remillard 是另一个活路的开发者,并给这个项目提供了最深远最有意义的贡献。大量的程序员贡献他们的代码给 Codestriker 项目,导致了这个项目空前的繁荣。 3. Groogle: Groogle 是一个基于WEB的代码评审工具。 Groogle 支持和 Subversion 集成。它主要提供如下的功能:各式各样语言的语法高亮。 支持整个版本树的比较。 支持当个文件不同版本的diff功能,并有一个图形的版本树。 邮件通知所有的Reivew的人当前的状态。 认证机制。 4. Rietveld: Rietveld 由Guido van Rossum 开发(他是Python的创造者,现在是Google的员工),这个工具是基于Mondrian 工具,作者一开始是为了Google 开发的,并且,它在很多方面和Review board 很像。它也是一个基于Web的应用,并可以Google App Engine 当主机。它使用了目前最流行的Web开发框架 django 并支持 Subversion 。当前,任何一个使用 Google Code 的项目都可以使用 Rietveld 并且使用 python Subversion 服务器。当然,它同样支持其它的Subversion服务器。 5. JCR JCR 或者叫做 JCodeReview 也是一个基于WEB界面的最初设计给Reivew Java 语言的一个工具。当然,现在,它可以被用于其它的非Java的代码。JCR 主要想协助:审查者。所有的代码更改都会被高亮,以及大多数语言的语法高亮。Code extracts 可以显示代码评审意见。如果你正在Review Java的代码,你可以点击代码中的类名来查看相关的类的声明。 项目所有者。可以 轻松创建并配置需要Review的项目,并不需要集成任何的软件配置管理系统(SCM)。 流程信仰者。 所有的评语都会被记录在数据库中,并且会有状态报告,以及各种各样的统计。 架构师和开发者。 这个系统也可以让我们查看属于单个文件的评语,这样有利于我们重构代码。


本文标题:包含java代码注释统计工具的词条
转载注明:http://cdkjz.cn/article/hjejod.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220