게시판 즐겨찾기
편집
드래그 앤 드롭으로
즐겨찾기 아이콘 위치 수정이 가능합니다.
abc = abc; 같은 죽은 코드 검색기
게시물ID : programmer_14398짧은주소 복사하기
작성자 : 오렌지쥬스P
추천 : 0
조회수 : 723회
댓글수 : 6개
등록시간 : 2015/11/12 16:55:57
옵션
  • 창작글
  • 베스트금지
class Event{
public:
Object evtPage;
}

public Event(Object evtPage){
evtPage = evtPage; 
//this->evtPage = evtPage; 했었어야되는데
}

위와같이으로 초기화때나 어느때에 자기자신을 다시 대입하는 코드를 찾는 코드입니다..
다른 컴파일러에서는 잡아줄지 모르겠지만 VS2010에서는 못 잡아주더군요

JAVA코드이고 폴더경로를 써넣고 실행하면 재귀적으로 찾아다닙니다.

코드공유 60% 코드저장 40%의 비중을 둔 글..

아래는 코드

public class CheckItOut {
    static int codeLines;

    public static void main(String[] args) {
      codeLines = 0;
        System.out.println("------ START ------");
        CheckItOut fw = new CheckItOut();
        fw.walk("c:\\<코드가 있는 폴더>\\);
        System.out.println("------ E N D ------");
        System.out.println(String.format("%s Lines", codeLines));
    }
    public void walk( String path ) {
        File root = new File( path );
        File[] list = root.listFiles();
        if (list == null) return;
        for ( File f : list ) {
            String fpath = f.getAbsolutePath();
            if ( f.isDirectory() ) {
                walk( fpath );
            }
            else if( isTarget(fpath) ) {
                    check(fpath);
            }
        }
    }
    public boolean isTarget(String path) {
        String p = path.toLowerCase();
        return (p.endsWith(".c") || p.endsWith(".cpp") || p.endsWith(".java") || p.endsWith(".h"));
    }
    public void check(String path) {
        try {
            BufferedReader r = new BufferedReader(new FileReader(path));
            char []k = {
                ' ', '\t', ';'
            };
            String s, ssub;
            int p, pl, pk[] = new int[k.length];
            String sl[] = new String[3];
            int line;
            line = 0;
            while((s = r.readLine()) != null) {
                p = pl = 0;
                while(true) {
                    for(int i=0; i<k.length; i++) {
                        if((pk[i] = s.indexOf(k[i], pl)) == -1) pk[i] = Integer.MAX_VALUE;
                    }
                    p = pk[0];
                    for(int i=1; i<k.length; i++) p = Math.min(p, pk[i]);
                    if(p == Integer.MAX_VALUE) break;
                    ssub = s.substring(pl, p).trim();
                    if(!ssub.isEmpty()) {
                        for(int i=1; i<3; i++) sl[i-1] = sl[i];
                        sl[2] = s.substring(pl, p).trim();
                        if(sl[2].equals(sl[0]) && "=".equals(sl[1])) {
                            boolean isDup = false;
                            int end = s.indexOf(';', p);
                            if(end != -1) {
                                if(p+1 < end) {
                                    String more = s.substring(p+1, end).trim();
                                    if(more.isEmpty()) isDup = true;
                                }
                                else {
                                    isDup = true;
                                }
                            }
                            if(isDup) System.out.println(String.format("* %s LINE%d >%s< DUPICATED", path, line, sl[0]));
                        }
                    }
                    pl = p + 1;
                }
                line++;
                codeLines++;
            }
        }
        catch(Exception e) {
            e.printStackTrace();
        }
    }
}
전체 추천리스트 보기
새로운 댓글이 없습니다.
새로운 댓글 확인하기
글쓰기
◀뒤로가기
PC버전
맨위로▲
공지 운영 자료창고 청소년보호