static int iCommentLines=0;
static int iNullLines=0;
static int iValidLines=0;
static int iAllLines=0;
static boolean bCommentBeg=false;
public static void countLine(String line){
iAllLines++;
int i=0;
boolean isNewLine=true; //是否要跳新行
while(i<line.length()){
char c=line.charAt(i);
if(bCommentBeg ){
if( c=='*' && line.charAt(i+1)=='/'){
if(!isNewLine)
;
else
// 注释行统计+1
iCommentLines++;
bCommentBeg=false;
isNewLine=false;
i++;
}
else;
i++;
continue;
}
if(c == ' '){
i++;
continue;
} else if ((c == '\r' && line.charAt(i + 1) == '\n') || c == '\n') {
if(!isNewLine)
;
else // 找到一个空行
iNullLines++;
return;
} else if (c == '/') {
char c2 = line.charAt(++i);
if (c2 == '/') {
if(!isNewLine)
;
else // 这是个注释行
// 注释行统计+1
iCommentLines++;
return;
} else if (c2 == '*') {
// 设置块注释开始标志
bCommentBeg=true;
}
else if(!bCommentBeg){
if(!isNewLine)
;
else iValidLines++;
return;
}
}
else {
if(!isNewLine)
;
else iValidLines++;
return;
}
i++;
}
if(!isNewLine) return;
if(bCommentBeg )
iCommentLines++;
else // 找到一个空行
iNullLines++;
return;
}
java代码行统计程序
最新推荐文章于 2023-05-24 21:35:53 发布