Search in sources :

Example 1 with BlockDVO

use of com.kyj.fx.voeditor.visual.words.spec.auto.msword.vo.BlockDVO in project Gargoyle by callakrsos.

the class InspectorSourceMeta method doAnalysis.

/**
	 * 2014. 6. 28. KYJ
	 * 
	 * @throws InspectSourceErrException
	 *             브레이스 숫자가 다를경우 발생
	 * @처리내용 : Brace위치 조정 및
	 */
private void doAnalysis() throws Exception {
    /* brace 시작부 */
    List<BraceDVO> startBraceDVOList;
    /* brace 종료부 */
    List<BraceDVO> endBraceDVOList;
    if (svnCatList != null && !svnCatList.isEmpty()) {
        /* 배열의 삭제가 빠르도록 LinkedList로 생성 */
        startBraceDVOList = new LinkedList<BraceDVO>();
        endBraceDVOList = new LinkedList<BraceDVO>();
        Matcher matcher = null;
        for (int index = 0; index < svnCatList.size(); index++) {
            String txt = svnCatList.get(index);
            sb.append(txt).append("\n");
            /* if ~ elseif로 가지 않는다. 한 라인내에 브레이스의 시작과 종료부가 같이 있을경우도 있기 때문 */
            /* 만약 소스내 문자열이 포함되있는경우는 없애고 작업함 문자열내에 브레이스문이 있을가능성이 있기때문 */
            txt = txt.replaceAll(EXCEPT_STING, "");
            txt = txt.trim();
            /* '//' 로 시작하는 주석부분은 제외 */
            if (txt.startsWith("//")) {
                continue;
            }
            // import문일경우 importList에 add
            if (txt.startsWith("import ")) {
                this.importList.add(txt);
            }
            /* brace시작부일경우 + 주석부분에 해당하는 브레이스의 경우 제외 */
            if (txt.contains(START_BRACE)) {
                matcher = startBracePattern.matcher(txt);
                boolean result = matcher.find();
                while (result) {
                    startBraceDVOList.add(new BraceDVO(START_BRACE, index));
                    result = matcher.find();
                }
            }
            /* brace종료부 + 주석부분에 해당하는 브레이스 경우 제외 */
            if (txt.contains(END_BRACE)) {
                matcher = endBracePattern.matcher(txt);
                boolean result = matcher.find();
                while (result) {
                    endBraceDVOList.add(new BraceDVO(END_BRACE, index));
                    result = matcher.find();
                }
            }
        }
        resultDVOList = new LinkedList<BlockDVO>();
        /* 배열이 비어있지않고 브레이스의 숫자가 같은경우 진행 */
        if (!startBraceDVOList.isEmpty() && !endBraceDVOList.isEmpty() && (startBraceDVOList.size() == endBraceDVOList.size())) {
            int startIndex = -1;
            int endIndex = -1;
            /* 시작브레이스의 끝부분 인덱스부터 시작 */
            for (int sbIdx = startBraceDVOList.size() - 1; sbIdx >= 0; sbIdx--) {
                startIndex = startBraceDVOList.get(sbIdx).getIndex();
                /* 종료브레이스는 처음인덱스부터 시작 */
                int endSize = endBraceDVOList.size();
                for (int ebIdx = 0; ebIdx < endSize; ebIdx++) {
                    /**/
                    endIndex = endBraceDVOList.get(ebIdx).getIndex();
                    if (startIndex <= endIndex) {
                        resultDVOList.add(new BlockDVO(startIndex + 1, endIndex + 1));
                        endBraceDVOList.remove(ebIdx);
                        endSize = endBraceDVOList.size();
                        break;
                    }
                }
            }
            Collections.reverse(resultDVOList);
            System.out.println("############");
            int seq = 0;
            for (BlockDVO b : resultDVOList) {
                LOGGER.debug(String.format("seq : %d start : %d  end : %d \n", seq++, b.getStartindex(), b.getEndindex()));
            }
            System.out.println("############");
        } else if (startBraceDVOList.isEmpty() && endBraceDVOList.isEmpty()) {
        // N/A
        } else {
            throw new ProgramSpecSourceErrException("Brace Count is Wrong.");
        }
    } else {
        throw new ProgramSpecSourceNullException("Source is null");
    }
}
Also used : Matcher(java.util.regex.Matcher) ProgramSpecSourceErrException(com.kyj.fx.voeditor.visual.exceptions.ProgramSpecSourceErrException) ProgramSpecSourceNullException(com.kyj.fx.voeditor.visual.exceptions.ProgramSpecSourceNullException) BlockDVO(com.kyj.fx.voeditor.visual.words.spec.auto.msword.vo.BlockDVO)

Example 2 with BlockDVO

use of com.kyj.fx.voeditor.visual.words.spec.auto.msword.vo.BlockDVO in project Gargoyle by callakrsos.

the class JavaSourceAnalysis method compile.

/**
	 * 2014. 6. 21. Administrator
	 *
	 * @param p
	 * @param data
	 * @return
	 * @처리내용 : 패턴과 일치하는 내용을 찾아 반환
	 */
public void compile(Pattern p) {
    String statement = this.inspectorSourceMeta.getSourceCode();
    Matcher m = p.matcher(statement);
    boolean result = m.find();
    int lineNumberSavePoint = 0;
    int lineNumberCnt = 0;
    // 패키지 찾기.
    List<String> packageStrings = ValueUtil.regexMatchs(PACKAGE_REGEX, statement);
    if (isDefaultPackage && ValueUtil.isNotEmpty(packageStrings)) {
        // TODO 수정예상됨. 인덱스를 0으로 강제로 셋팅함. 허나 패키지NAME은 한개이긴함.
        this.packageString = packageStrings.get(0);
        isDefaultPackage = false;
    }
    while (result) {
        String group = m.group();
        /*
			 * 특정 로직부분에 걸리는 부분때문에 추가. ex) return query(sql.toString() , data ,
			 * new RowMapper() { public Object mapRow(ResultSet resultSet, int
			 * row)
			 */
        if (ValueUtil.leftTrim(group).startsWith(",")) {
            result = m.find();
            continue;
        }
        // int catchIndexOf = group.indexOf(PREVENT_CATCH);
        boolean catchIndexOf = group.matches(PREVENT_CATCH);
        // int newIndexOf = group.indexOf(PREVENT_NEW);
        boolean newIndexOf = group.matches(PREVENT_NEW);
        // int ifIndexOf = group.indexOf(PREVENT_IF);
        boolean ifIndexOf = group.matches(PREVENT_IF);
        // int whileIndexOf = group.indexOf(PREVENT_WHILE);
        boolean whileIndexOf = group.matches(PREVENT_WHILE);
        // int returnIndexOf = group.indexOf(PREVENT_RETURN);
        boolean returnIndexOf = group.matches(PREVENT_RETURN);
        /*
			 * if (catchIndexOf == -1 && newIndexOf == -1 && ifIndexOf == -1 &&
			 * whileIndexOf == -1 && returnIndexOf == -1)
			 */
        if (!catchIndexOf && !newIndexOf && !ifIndexOf && !whileIndexOf && !returnIndexOf) {
            int start = m.start();
            int end = m.end();
            String methodName = statement.substring(lineNumberSavePoint, end);
            lineNumberCnt += getLineNumberCnt(methodName);
            lineNumberSavePoint = end + 1;
            BlockDVO blockAndDeleteList = getBlockAndDeleteList(lineNumberCnt);
            /* if문이 true인 경우는 함수가 포함된 라인안에 브레이스가 있는경우임 */
            if (blockAndDeleteList == null) {
                blockAndDeleteList = getBlock(lineNumberCnt, 0);
                lineNumberSavePoint = lineNumberSavePoint - 1;
            }
            LOGGER.debug(String.format(" lineNumberCnt : %d linNuberSavePoint : %d ", lineNumberCnt, lineNumberSavePoint));
            int startLine = blockAndDeleteList.getStartindex();
            int endLine = blockAndDeleteList.getEndindex();
            LOGGER.debug(String.format("startLine : %d  endLine %d \n", startLine, endLine));
            List<String> subList = this.inspectorSourceMeta.getSourceCodeList().subList(startLine - 1, endLine);
            String sourceCode = getString(subList);
            methodList.add(new SourceAnalysisDVO(group.replaceAll("\\{", "").trim(), start, end, startLine, endLine, this.inspectorSourceMeta.getFileName(), sourceCode));
        }
        result = m.find();
    }
}
Also used : Matcher(java.util.regex.Matcher) BlockDVO(com.kyj.fx.voeditor.visual.words.spec.auto.msword.vo.BlockDVO) SourceAnalysisDVO(com.kyj.fx.voeditor.visual.words.spec.auto.msword.vo.SourceAnalysisDVO)

Example 3 with BlockDVO

use of com.kyj.fx.voeditor.visual.words.spec.auto.msword.vo.BlockDVO in project Gargoyle by callakrsos.

the class JavaSourceAnalysis method getBlock.

BlockDVO getBlock(int lineNumberCnt, int loopCnt) {
    /* 무한루프 방지용 */
    if (loopCnt >= 100) {
        return null;
    }
    lineNumberCnt = lineNumberCnt - 1;
    BlockDVO blockAndDeleteList = getBlockAndDeleteList(lineNumberCnt);
    if (blockAndDeleteList == null) {
        loopCnt++;
        blockAndDeleteList = getBlock(lineNumberCnt, loopCnt);
    }
    return blockAndDeleteList;
}
Also used : BlockDVO(com.kyj.fx.voeditor.visual.words.spec.auto.msword.vo.BlockDVO)

Example 4 with BlockDVO

use of com.kyj.fx.voeditor.visual.words.spec.auto.msword.vo.BlockDVO in project Gargoyle by callakrsos.

the class XframeJsAnalysis method compile.

/**
	 * 2014. 6. 21. Administrator
	 *
	 * @param p
	 * @param data
	 * @return
	 * @처리내용 : 패턴과 일치하는 내용을 찾아 반환
	 */
public void compile(Pattern p) {
    String statement = this.inspectorSourceMeta.getSourceCode();
    Matcher m = p.matcher(statement);
    boolean result = m.find();
    int lineNumberSavePoint = 0;
    int lineNumberCnt = 0;
    while (result) {
        String group = m.group().trim();
        int start = m.start();
        int end = m.end();
        lineNumberCnt += getLineNumberCnt(statement.substring(lineNumberSavePoint, end));
        lineNumberSavePoint = end + 1;
        BlockDVO blockAndDeleteList = getBlockAndDeleteList(lineNumberCnt);
        /* if문이 true인 경우는 함수가 포함된 라인안에 브레이스가 있는경우임 */
        if (blockAndDeleteList == null) {
            lineNumberCnt = lineNumberCnt - 1;
            blockAndDeleteList = getBlockAndDeleteList(lineNumberCnt);
            lineNumberSavePoint = lineNumberSavePoint - 1;
        }
        if (blockAndDeleteList == null) {
            ProgramSpecSourceErrException e = new ProgramSpecSourceErrException(" 코드 블록에 문제가 있거나 , 프로그램 버그 발생. ");
            e.addDetailMsgList("2차 체크 코드 블록 BlockDVO null 주석문제일 가능성이 있음.");
            e.addDetailMsgList("group : ");
            e.addDetailMsgList(group);
            e.addDetailMsgList("start : ");
            e.addDetailMsgList(String.valueOf(start));
            e.addDetailMsgList("end : ");
            e.addDetailMsgList(String.valueOf(end));
            e.addDetailMsgList("lineNumberCnt : ");
            e.addDetailMsgList(String.valueOf(lineNumberCnt));
            e.addDetailMsgList("linkedList : ");
            e.addDetailMsgList(listBlock.toString());
            // BaseUtil.alert( "코드 블록에 문제가 있거나 , 프로그램 버그 발생." );
            // return;
            result = m.find();
            continue;
        }
        int startLine = blockAndDeleteList.getStartindex();
        int endLine = blockAndDeleteList.getEndindex();
        List<String> subList = this.inspectorSourceMeta.getSourceCodeList().subList(startLine - 1, endLine);
        String sourceCode = getString(subList);
        methodList.add(new SourceAnalysisDVO(group.replaceAll("\\{", "").trim(), start, end, startLine, endLine, this.inspectorSourceMeta.getFileName(), sourceCode));
        result = m.find();
    }
}
Also used : Matcher(java.util.regex.Matcher) ProgramSpecSourceErrException(com.kyj.fx.voeditor.visual.exceptions.ProgramSpecSourceErrException) BlockDVO(com.kyj.fx.voeditor.visual.words.spec.auto.msword.vo.BlockDVO) SourceAnalysisDVO(com.kyj.fx.voeditor.visual.words.spec.auto.msword.vo.SourceAnalysisDVO)

Aggregations

BlockDVO (com.kyj.fx.voeditor.visual.words.spec.auto.msword.vo.BlockDVO)4 Matcher (java.util.regex.Matcher)3 ProgramSpecSourceErrException (com.kyj.fx.voeditor.visual.exceptions.ProgramSpecSourceErrException)2 SourceAnalysisDVO (com.kyj.fx.voeditor.visual.words.spec.auto.msword.vo.SourceAnalysisDVO)2 ProgramSpecSourceNullException (com.kyj.fx.voeditor.visual.exceptions.ProgramSpecSourceNullException)1