Skip to content

Instantly share code, notes, and snippets.

@becurt
Forked from skRyo/gist:3859908
Created October 10, 2012 11:15
Show Gist options
  • Save becurt/3864866 to your computer and use it in GitHub Desktop.
Save becurt/3864866 to your computer and use it in GitHub Desktop.
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;
}
}
@becurt
Copy link
Author

becurt commented Oct 10, 2012

git clone git@gist.github.com:3864866.git gist-3864866

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment