private boolean isCommentedCode(String line) { return codeRecognizer.isLineOfCode(line); }
public final boolean isLineOfCode(String line) { return recognition(line) - threshold > 0; }
public CommentedOutCodeLineCheck() { codeRecognizer = new CodeRecognizer(THRESHOLD, new JavaFootprint()); }
private boolean isCommentedCode(String line) { return codeRecognizer.isLineOfCode(line); }
public final List<String> extractCodeLines(List<String> lines) { List<String> codeLines = Lists.newArrayList(); for (String line : lines) { if (recognition(line) >= threshold) { codeLines.add(line); } } return codeLines; }
private boolean isCommentedCode(String line) { return codeRecognizer.isLineOfCode(line); }
private boolean isCommentedCode(String line) { return codeRecognizer.isLineOfCode(line); }
/** * Detects commented-out code in remaining candidates. */ private void leaveFile() { List<Integer> commentedOutCodeLines = Lists.newArrayList(); for (SyntaxTrivia syntaxTrivia : comments) { String[] lines = syntaxTrivia.comment().split("\r\n?|\n"); for (int i = 0; i < lines.length; i++) { if (codeRecognizer.isLineOfCode(lines[i])) { // Mark all remaining lines from this comment as a commented out lines of code for (int j = i; j < lines.length; j++) { commentedOutCodeLines.add(((InternalSyntaxTrivia) syntaxTrivia).getLine() + j); } break; } } } // Greedy algorithm to split lines on blocks and to report only one violation per block Collections.sort(commentedOutCodeLines); int prev = Integer.MIN_VALUE; for (int i = 0; i < commentedOutCodeLines.size(); i++) { int current = commentedOutCodeLines.get(i); if (prev + 1 < current) { addIssue(current, "This block of commented-out lines of code should be removed."); } prev = current; } comments = null; }
@Override public void visitToken(Token token) { for (Trivia trivia : token.getTrivia()) { String[] lines = regexpToDivideStringByLine.split(FlexCommentAnalyser.getContents(trivia.getToken().getOriginalValue())); for (int lineOffset = 0; lineOffset < lines.length; lineOffset++) { if (codeRecognizer.isLineOfCode(lines[lineOffset])) { addIssueAtLine("Sections of code should not be \"commented out\".", trivia.getToken().getLine() + lineOffset); break; } } } }
public void visitToken(Token token) { for (Trivia trivia : token.getTrivia()) { if (trivia.isComment()) { String[] lines = regexpToDivideStringByLine.split(getContext().getCommentAnalyser().getContents(trivia.getToken().getOriginalValue())); for (int lineOffset = 0; lineOffset < lines.length; lineOffset++) { if (codeRecognizer.isLineOfCode(lines[lineOffset])) { getContext().createLineViolation(this, "Sections of code should not be \"commented out\".", trivia.getToken().getLine() + lineOffset); break; } } } } }
private void computeCommentLine(Line line) { if (line.isThereComment() && !line.isThereBlankComment()) { if (line.isThereJavadoc() || line.isThereLicenseHeaderComment()) { line.setMeasure(Metric.COMMENT_LINES, 1); return; } boolean isCommentedOutCode = codeRecognizer.isLineOfCode(line.getComment()); if (!isCommentedOutCode) { line.setMeasure(Metric.COMMENT_LINES, 1); } else { line.setMeasure(Metric.COMMENTED_OUT_CODE_LINES, 1); } } }
@Override public void visitToken(Token token) { for (Trivia trivia : token.getTrivia()) { if (trivia.isComment() && !isJsDoc(trivia)) { String[] lines = regexpToDivideStringByLine.split(getContext().getCommentAnalyser().getContents(trivia.getToken().getOriginalValue())); for (int lineOffset = 0; lineOffset < lines.length; lineOffset++) { if (codeRecognizer.isLineOfCode(lines[lineOffset])) { getContext().createLineViolation(this, "Sections of code should not be \"commented out\".", trivia.getToken().getLine() + lineOffset); break; } } } } }