private void updateParamsAndMcCabeIndex()

in codeanalyzer/src/main/java/nl/obren/sokrates/sourcecode/lang/lua/LuaHeuristicUnitsExtractor.java [112:143]


    private void updateParamsAndMcCabeIndex(String body) {
        CommentsAndEmptyLinesCleaner cleaner = getCommentsAndEmptyLinesCleanerExtraString();
        String content = cleaner.cleanKeepEmptyLines(body);

        String bodyForSearch = " " + content.replace("\n", " ");
        bodyForSearch = bodyForSearch.replace("(", " (");
        bodyForSearch = bodyForSearch.replace("{", " {");

        int startOfParamsSearchIndex = body.indexOf("(");
        int endOfParamsSearchIndex = body.indexOf(")", startOfParamsSearchIndex + 1);
        if (unit.getShortName().contains("(")) {
            unit.setShortName(unit.getShortName().substring(0, unit.getShortName().indexOf("(")).trim() + "()");
        }
        if (startOfParamsSearchIndex > 0 && endOfParamsSearchIndex > 0 && endOfParamsSearchIndex > startOfParamsSearchIndex) {
            String trimedParams = body.substring(startOfParamsSearchIndex + 1, endOfParamsSearchIndex).trim();
            if (!trimedParams.isEmpty()) {
                String[] params = trimedParams.split("\\,");
                unit.setNumberOfParameters(params.length);
            }
        }

        int mcCabeIndex = 1;
        mcCabeIndex += StringUtils.countMatches(bodyForSearch, " if ");
        mcCabeIndex += StringUtils.countMatches(bodyForSearch, " elseif ");
        mcCabeIndex += StringUtils.countMatches(bodyForSearch, " while ");
        mcCabeIndex += StringUtils.countMatches(bodyForSearch, " repeat ");
        mcCabeIndex += StringUtils.countMatches(bodyForSearch, " for ");
        mcCabeIndex += StringUtils.countMatches(bodyForSearch, " && ");
        mcCabeIndex += StringUtils.countMatches(bodyForSearch, " || ");

        unit.setMcCabeIndex(mcCabeIndex);
    }