java代码行统计程序

来源:互联网 发布:知乎专栏怎么收藏 编辑:程序博客网 时间:2024/05/22 05:01
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// 注释行统计+1iCommentLines++;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 // 这是个注释行// 注释行统计+1iCommentLines++;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;}


原创粉丝点击