@Override public boolean shouldSuppress(int startLineNo, int startColNo, int endLineNo, int endColNo) { return currentContents .hasIntersectionWithComment(startLineNo, startColNo, endLineNo, endColNo); }
/** * Does a regular expression match on the given line and checks that a * possible match is within a comment. * @param pattern The regular expression pattern to use. * @param line The line of test to do the match on. * @param lineNo The line number in the file. * @return True if a match was found inside a comment. */ private boolean matchesComment(Pattern pattern, String line, int lineNo) { final Matcher matcher = pattern.matcher(line); boolean matches = false; if (matcher.find()) { matches = getFileContents().hasIntersectionWithComment(lineNo, matcher.start(), lineNo, matcher.end()); } return matches; }
/** * Detect ignore situation. * @param startLine position of line * @param text file text * @param start line column * @return true is that need to be ignored */ private boolean isIgnore(int startLine, FileText text, LineColumn start) { final LineColumn end; if (matcher.end() == 0) { end = text.lineColumn(0); } else { end = text.lineColumn(matcher.end() - 1); } boolean ignore = false; if (ignoreComments) { final FileContents theFileContents = getFileContents(); final int startColumn = start.getColumn(); final int endLine = end.getLine(); final int endColumn = end.getColumn(); ignore = theFileContents.hasIntersectionWithComment(startLine, startColumn, endLine, endColumn); } return ignore; }
@Test public void testSinglelineCommentIntersect() { // just to make UT coverage 100% final FileContents fileContents = new FileContents( new FileText(new File("filename"), Collections.singletonList(" // "))); fileContents.reportSingleLineComment(1, 2); assertTrue("Should return true when comments intersect", fileContents.hasIntersectionWithComment(1, 5, 1, 6)); }
@Test public void testSinglelineCommentNotIntersect() { // just to make UT coverage 100% final FileContents fileContents = new FileContents( new FileText(new File("filename"), Collections.singletonList(" // "))); fileContents.reportSingleLineComment(1, 2); assertFalse("Should return false when there is no intersection", fileContents.hasIntersectionWithComment(1, 0, 1, 1)); }
@Test public void testHasIntersectionWithSingleLineComment() { final FileContents fileContents = new FileContents( new FileText(new File("filename"), Arrays.asList(" ", " //test ", " //test ", " //test "))); fileContents.reportCppComment(4, 4); assertTrue("Should return true when comments intersect", fileContents.hasIntersectionWithComment(1, 3, 4, 6)); }
@Test public void testHasIntersectionWithBlockComment2() { final FileContents fileContents = new FileContents( new FileText(new File("filename"), Arrays.asList(" /* */ ", " ", " "))); fileContents.reportCComment(1, 2, 1, 5); assertFalse("Should return false when there is no intersection", fileContents.hasIntersectionWithComment(2, 2, 3, 6)); }
@Test public void testHasIntersectionWithBlockComment() { final FileContents fileContents = new FileContents(new FileText(new File("filename"), Arrays.asList(" /* */ ", " ", " /* test ", " */ ", " "))); fileContents.reportCComment(1, 2, 1, 5); fileContents.reportCComment(3, 2, 4, 2); assertTrue("Should return true when comments intersect", fileContents.hasIntersectionWithComment(2, 2, 3, 6)); }
/** * {@inheritDoc} */ @Override public boolean shouldSuppress(int aStartLineNo, int aStartColNo, int aEndLineNo, int aEndColNo) { return ( null != mCurrentContents ) && mCurrentContents.hasIntersectionWithComment( aStartLineNo, aStartColNo, aEndLineNo, aEndColNo ); }
@Override public boolean shouldSuppress(int startLineNo, int startColNo, int endLineNo, int endColNo) { return currentContents .hasIntersectionWithComment(startLineNo, startColNo, endLineNo, endColNo); }
/** * Does a regular expression match on the given line and checks that a * possible match is within a comment. * @param pattern The regular expression pattern to use. * @param line The line of test to do the match on. * @param lineNo The line number in the file. * @return True if a match was found inside a comment. */ private boolean matchesComment(Pattern pattern, String line, int lineNo) { final Matcher matcher = pattern.matcher(line); boolean matches = false; if (matcher.find()) { matches = getFileContents().hasIntersectionWithComment(lineNo, matcher.start(), lineNo, matcher.end()); } return matches; }
/** * Checks line parameter on containing more than 1 ternary operator. * @param line The line to examine. * @param lineNo The line number of the line. * @return true if line is single ternary. */ private boolean isSingleTernaryLine(String line, int lineNo) { int questionsPerLine = 0; final char[] charArrayFromLine = line.toCharArray(); for (int i = 0; i < line.length(); i++) { final char currentSymbol = charArrayFromLine[i]; if (currentSymbol == '?' && !getFileContents().hasIntersectionWithComment(lineNo + 1, i, lineNo + 1, i)) { questionsPerLine++; } if (questionsPerLine > 1) { break; } } return questionsPerLine == 1; }
int hasEndAnno(String lineText, int lineNum, List<QuotedString> quotedStrings) { int startIndex = lineText.indexOf(")"); while (startIndex != -1) { boolean isValidEnd = true; for (QuotedString quoted : quotedStrings) { if (startIndex >= quoted.startIndex && startIndex <= quoted.endIndex) { isValidEnd = false; break; } } if (getFileContents().hasIntersectionWithComment(lineNum, startIndex, lineNum, startIndex)) { isValidEnd = false; } if (isValidEnd) { return startIndex; } startIndex = lineText.indexOf(")", startIndex + 1); } return -1; }
int parenthesesStart = lineText.indexOf("("); while (parenthesesStart != -1 && getFileContents().hasIntersectionWithComment(i, parenthesesStart, i, parenthesesStart)){ parenthesesStart = lineText.indexOf("(", parenthesesStart + 1); while (matcher.find()) { if (getFileContents().hasIntersectionWithComment(i, matcher.start(), i, matcher.end())) { continue;
/** * Detect ignore situation. * @param startLine position of line * @param text file text * @param start line column * @return true is that need to be ignored */ private boolean isIgnore(int startLine, FileText text, LineColumn start) { final LineColumn end; if (matcher.end() == 0) { end = text.lineColumn(0); } else { end = text.lineColumn(matcher.end() - 1); } boolean ignore = false; if (ignoreComments) { final FileContents theFileContents = getFileContents(); final int startColumn = start.getColumn(); final int endLine = end.getLine(); final int endColumn = end.getColumn(); ignore = theFileContents.hasIntersectionWithComment(startLine, startColumn, endLine, endColumn); } return ignore; }