in codeanalyzer/src/main/java/nl/obren/sokrates/sourcecode/lang/vb/VisualBasicHeuristicUnitsExtractor.java [78:111]
private void updateParamsAndMcCabeIndex(UnitInfo unit, String body) {
CommentsAndEmptyLinesCleaner cleaner = analyzer.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, " End If ");
mcCabeIndex += StringUtils.countMatches(bodyForSearch, " ElseIf ");
mcCabeIndex += StringUtils.countMatches(bodyForSearch, " Catch ");
mcCabeIndex += StringUtils.countMatches(bodyForSearch, " Finally ");
mcCabeIndex += StringUtils.countMatches(bodyForSearch, " While ");
mcCabeIndex += StringUtils.countMatches(bodyForSearch, " Loop ");
mcCabeIndex += StringUtils.countMatches(bodyForSearch, " For ");
mcCabeIndex += StringUtils.countMatches(bodyForSearch, " And ");
mcCabeIndex += StringUtils.countMatches(bodyForSearch, " Or ");
unit.setMcCabeIndex(mcCabeIndex);
}