@Test public void testCalculateStrCompLOC() throws IOException { assertEquals(7, sca.calculateLOC(TEST_CLASS, TYPE_STRCOMP)); }
public int calculateLOC(String filepath, String analyzerType) throws IOException { if(analyzerType.equals("regex")) { String sourceCode = fileReader.readFileIntoString(filepath); Pattern pattern = Pattern.compile("(( Matcher nonCodeLinesMatcher = pattern.matcher(sourceCode); int nonCodeLinesCounter = 0; while (nonCodeLinesMatcher.find()) { nonCodeLinesCounter++; } int sourceFileLength = sourceCode.split("\n").length; int loc = sourceFileLength - nonCodeLinesCounter; return loc; } else if (analyzerType.equals("strcomp")) { List<String> sourceCodeList = fileReader.readFileIntoList(filepath); int nonCodeLinesCounter = 0; for (String line : sourceCodeList) { line = line.trim(); if (line.startsWith(" nonCodeLinesCounter++; } int loc = sourceCodeList.size() - nonCodeLinesCounter; return loc; } return -1; }
SourceCodeAnalyzer { public int calculateLOC(String filepath, String analyzerType) throws IOException { if(analyzerType.equals("regex")) { String sourceCode = fileReader.readFileIntoString(filepath); Pattern pattern = Pattern.compile("(( Matcher nonCodeLinesMatcher = pattern.matcher(sourceCode); int nonCodeLinesCounter = 0; while (nonCodeLinesMatcher.find()) { nonCodeLinesCounter++; } int sourceFileLength = sourceCode.split("\n").length; int loc = sourceFileLength - nonCodeLinesCounter; return loc; } else if (analyzerType.equals("strcomp")) { List<String> sourceCodeList = fileReader.readFileIntoList(filepath); int nonCodeLinesCounter = 0; for (String line : sourceCodeList) { line = line.trim(); if (line.startsWith(" nonCodeLinesCounter++; } int loc = sourceCodeList.size() - nonCodeLinesCounter; return loc; } return -1; } }
SourceCodeAnalyzer { public int calculateLOC(String filepath, String analyzerType) throws IOException { if(analyzerType.equals("regex")) { String sourceCode = fileReader.readFileIntoString(filepath); Pattern pattern = Pattern.compile("(( Matcher nonCodeLinesMatcher = pattern.matcher(sourceCode); int nonCodeLinesCounter = 0; while (nonCodeLinesMatcher.find()) { nonCodeLinesCounter++; } int sourceFileLength = sourceCode.split("\n").length; int loc = sourceFileLength - nonCodeLinesCounter; return loc; } else if (analyzerType.equals("strcomp")) { List<String> sourceCodeList = fileReader.readFileIntoList(filepath); int nonCodeLinesCounter = 0; for (String line : sourceCodeList) { line = line.trim(); if (line.startsWith(" nonCodeLinesCounter++; } int loc = sourceCodeList.size() - nonCodeLinesCounter; return loc; } return -1; } SourceCodeAnalyzer(String fileReaderType); }
SourceCodeAnalyzer { public int calculateLOC(String filepath, String analyzerType) throws IOException { if(analyzerType.equals("regex")) { String sourceCode = fileReader.readFileIntoString(filepath); Pattern pattern = Pattern.compile("(( Matcher nonCodeLinesMatcher = pattern.matcher(sourceCode); int nonCodeLinesCounter = 0; while (nonCodeLinesMatcher.find()) { nonCodeLinesCounter++; } int sourceFileLength = sourceCode.split("\n").length; int loc = sourceFileLength - nonCodeLinesCounter; return loc; } else if (analyzerType.equals("strcomp")) { List<String> sourceCodeList = fileReader.readFileIntoList(filepath); int nonCodeLinesCounter = 0; for (String line : sourceCodeList) { line = line.trim(); if (line.startsWith(" nonCodeLinesCounter++; } int loc = sourceCodeList.size() - nonCodeLinesCounter; return loc; } return -1; } SourceCodeAnalyzer(String fileReaderType); int calculateLOC(String filepath, String analyzerType); int calculateNOM(String filepath, String analyzerType); int calculateNOC(String filepath, String analyzerType); }
SourceCodeAnalyzer { public int calculateLOC(String filepath, String analyzerType) throws IOException { if(analyzerType.equals("regex")) { String sourceCode = fileReader.readFileIntoString(filepath); Pattern pattern = Pattern.compile("(( Matcher nonCodeLinesMatcher = pattern.matcher(sourceCode); int nonCodeLinesCounter = 0; while (nonCodeLinesMatcher.find()) { nonCodeLinesCounter++; } int sourceFileLength = sourceCode.split("\n").length; int loc = sourceFileLength - nonCodeLinesCounter; return loc; } else if (analyzerType.equals("strcomp")) { List<String> sourceCodeList = fileReader.readFileIntoList(filepath); int nonCodeLinesCounter = 0; for (String line : sourceCodeList) { line = line.trim(); if (line.startsWith(" nonCodeLinesCounter++; } int loc = sourceCodeList.size() - nonCodeLinesCounter; return loc; } return -1; } SourceCodeAnalyzer(String fileReaderType); int calculateLOC(String filepath, String analyzerType); int calculateNOM(String filepath, String analyzerType); int calculateNOC(String filepath, String analyzerType);  }