-
-
Save becurt/3864866 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedReader; | |
import java.io.File; | |
import java.io.FileNotFoundException; | |
import java.io.FileReader; | |
import java.io.IOException; | |
/** | |
* fileを審査する | |
* @author becurt | |
*/ | |
public class FileAnalyze { | |
private File javaFile; | |
private int stepCnt =0; | |
private int lineCnt =0; | |
private int commentCnt =0; | |
private int spaceLineCnt =0; | |
public FileAnalyze(File javaFile) { | |
this.javaFile = javaFile; | |
BufferedReader br = null; | |
try { | |
br = new BufferedReader(new FileReader(this.javaFile)); | |
boolean cmflg=false; | |
try (LinePattern cp=new LinePattern();){ | |
String line; | |
while ((line = br.readLine()) != null) { | |
// 全行カウントアップ | |
lineCnt++; | |
if(cmflg){ | |
//ブロックコメントが終了していないかチェック | |
if(cp.commentEndExistFlg(line)){ | |
//純粋なコメント行かどうかのチェック | |
if(cp.commentLineStatus(line)){ | |
System.out.println(line); | |
commentCnt++; | |
}else{ | |
stepCnt++; | |
} | |
cmflg=false; | |
continue; | |
} | |
System.out.println(line); | |
commentCnt++; | |
continue; | |
} | |
// 空白行カウントアップ | |
if(cp.spaceLineFlg(line)){ | |
spaceLineCnt++; | |
continue; | |
} | |
if(cp.singleCommentExistFlg(line)){ | |
if(cp.singleCommentFlg(line)){ | |
System.out.println(line); | |
commentCnt++; | |
}else{ | |
stepCnt++; | |
} | |
continue; | |
} | |
//ブロックコメントの開始行を見つけた。 | |
if(cp.blockCommentStartExistFlg(line)){ | |
//純粋なコメント行かどうかのチェック | |
if(cp.commentLineStatus(line)){ | |
System.out.println(line); | |
commentCnt++; | |
}else{ | |
stepCnt++; | |
} | |
if(cp.blockCommentStartExistFlg(line) && !cp.commentEndExistFlg(line)){ | |
cmflg=true; | |
} | |
continue; | |
} | |
//コメントでもなく、空白行でもないとき | |
stepCnt++; | |
} | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} catch (Exception e1) { | |
// TODO Auto-generated catch block | |
e1.printStackTrace(); | |
} | |
} catch (FileNotFoundException e) { | |
e.printStackTrace(); | |
} | |
} | |
public int getStepCnt() { | |
return stepCnt; | |
} | |
public int getLineCnt() { | |
return lineCnt; | |
} | |
public int getCommentCnt() { | |
return commentCnt; | |
} | |
public int getSpaceLineCnt() { | |
return spaceLineCnt; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
git clone [email protected]:3864866.git gist-3864866