public final double recognition(String line) { double probability = 0; for (Detector pattern : language.getDetectors()) { probability = 1 - (1 - probability) * (1 - pattern.recognition(line)); } return probability; }
private boolean isCommentedCode(String line) { return codeRecognizer.isLineOfCode(line); }
public final boolean isLineOfCode(String line) { return recognition(line) - threshold > 0; }
@Override public Set<Detector> getDetectors() { return ImmutableSet.of( new EndWithDetector(0.95, '}', ';', '{'), new KeywordsDetector(0.3, FlexKeyword.keywordValues()), new ContainsDetector(0.95, "++", "--"), new ContainsDetector(0.95, "*=", "/=", "%=", "+=", "-=", "<<=", ">>=", ">>>=", "&=", "^=", "|="), new ContainsDetector(0.95, "==", "!=", "===", "!==")); }
public JavaFootprint() { detectors.add(new EndWithDetector(0.95, '}', ';', '{')); detectors.add(new KeywordsDetector(0.7, "||", "&&")); detectors.add(new KeywordsDetector(0.3, "public", "abstract", "class", "implements", "extends", "return", "throw", "private", "protected", "enum", "continue", "assert", "package", "synchronized", "boolean", "this", "double", "instanceof", "final", "interface", "static", "void", "long", "int", "float", "super", "true", "case:")); detectors.add(new ContainsDetector(0.95, "++", "for(", "if(", "while(", "catch(", "switch(", "try{", "else{")); detectors.add(new CamelCaseDetector(0.5)); }
@Override public Set<Detector> getDetectors() { return ImmutableSet.of( new EndWithDetector(0.95, '}', ';', '{'), new KeywordsDetector(0.3, EcmaScriptKeyword.keywordValues()), new ContainsDetectorJS(0.95, "*=", "/=", "%=", "+=", "-=", "<<=", ">>=", ">>>=", "&=", "^=", "|="), new ContainsDetectorJS(0.95, "!=", "!==")); }
@Override public int scan(String line) { char previousChar = ' '; char indexChar; for (int i = 0; i < line.length(); i++) { indexChar = line.charAt(i); if (isLowerCaseThenUpperCase(previousChar, indexChar)) { return 1; } previousChar = indexChar; } return 0; }
public CommentedOutCodeLineCheck() { codeRecognizer = new CodeRecognizer(THRESHOLD, new JavaFootprint()); }
@Override public Set<Detector> getDetectors() { return ImmutableSet.of( new EndWithDetector(0.95, '}', ';', '{'), new KeywordsDetector(0.3, PHPKeyword.getKeywordValues()), new ContainsDetector(0.95, "*=", "/=", "%=", "+=", "-=", "<<=", ">>=", "&=", "^=", "|="), new ContainsDetector(0.95, "!=", "!==")); }
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; }
public Set<Detector> getDetectors() { return ImmutableSet.of( new EndWithDetector(0.95, '}', ';', '{'), new KeywordsDetector(0.3, FlexKeyword.keywordValues()), new ContainsDetector(0.95, "++", "--"), new ContainsDetector(0.95, "*=", "/=", "%=", "+=", "-=", "<<=", ">>=", ">>>=", "&=", "^=", "|="), new ContainsDetector(0.95, "==", "!=", "===", "!==")); }
private boolean isCommentedCode(String line) { return codeRecognizer.isLineOfCode(line); }
@Override public Set<Detector> getDetectors() { return ImmutableSet.of( new EndWithDetector(0.95, '}', ';', '{'), new KeywordsDetector(0.3, PHPKeyword.getKeywordValues()), new ContainsDetector(0.95, "*=", "/=", "%=", "+=", "-=", "<<=", ">>=", "&=", "^=", "|="), new ContainsDetector(0.95, "!=", "!==")); }
private boolean isCommentedCode(String line) { return codeRecognizer.isLineOfCode(line); }
@Override public Set<Detector> getDetectors() { return ImmutableSet.of( new EndWithDetector(0.95, '}', ';', '{'), new KeywordsDetector(0.3, PHPKeyword.getKeywordValues()), new ContainsDetector(0.95, "*=", "/=", "%=", "+=", "-=", "<<=", ">>=", "&=", "^=", "|="), new ContainsDetector(0.95, "!=", "!==")); }
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); } } }
public Set<Detector> getDetectors() { Set<Detector> detectors = Sets.newHashSet(); detectors.add(new EndWithDetector(0.95, '}', ';', '{')); detectors.add(new KeywordsDetector(0.7, "||", "&&")); detectors.add(new KeywordsDetector(0.3, CSharpKeyword.keywordValues())); detectors.add(new ContainsDetector(0.95, "++", "for(", "if(", "while(", "catch(", "switch(", "try{", "else{")); return detectors; }
@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; } } } }