@Override public void leaveFile(@Nullable AstNode astNode) { getContext().peekSourceCode().add(metric, lines.size()); } }
@Override public void leaveFile(AstNode astNode) { if (enableNoSonar) { ((SourceFile) getContext().peekSourceCode()).addNoSonarTagLines(noSonar); } if (commentMetric != null) { getContext().peekSourceCode().add(commentMetric, comments.size()); } }
@Override public void leaveFile(AstNode astNode) { if (astNode == null) { // file wasn't parsed return; } getContext().peekSourceCode().add(ErlangMetric.PUBLIC_API, numOfPublicAPIs); getContext().peekSourceCode().add(ErlangMetric.PUBLIC_DOC_API, numOfPublicDocAPIs); double density = (numOfPublicAPIs > 0) ? numOfPublicDocAPIs / numOfPublicAPIs : 0; getContext().peekSourceCode().add(ErlangMetric.PUBLIC_DOCUMENTED_API_DENSITY, density); functions = null; }
@Override public void leaveFile(AstNode astNode) { int fileLength = getContext().peekSourceCode().getInt(CSharpMetric.LINES); for (int line = 1; line <= fileLength; line++) { fileLinesContext.setIntValue(CoreMetrics.NCLOC_DATA_KEY, line, linesOfCode.contains(line) ? 1 : 0); fileLinesContext.setIntValue(CoreMetrics.COMMENT_LINES_DATA_KEY, line, linesOfComments.contains(line) ? 1 : 0); } fileLinesContext.save(); linesOfCode.clear(); linesOfComments.clear(); }
@Override public void visitNode(AstNode astNode) { for (AstNodeType exclusionAstNodeType : exclusionAstNodeTypes) { if (astNode.hasAncestor(exclusionAstNodeType)) { return; } } getContext().peekSourceCode().add(metric, 1); }
@Override public void leaveFile(AstNode astNode) { Preconditions.checkState(getContext().peekSourceCode().isType(SourceFile.class)); getContext().popSourceCode(); }
private boolean checkNodeForPublicModifier(AstNode currentNode, AstNodeType wantedChildrenType) { List<AstNode> modifiers = currentNode.getChildren(wantedChildrenType); for (AstNode astNode : modifiers) { if (astNode.getToken().getType().equals(CSharpKeyword.PUBLIC)) { getContext().peekSourceCode().add(CSharpMetric.PUBLIC_API, 1); return true; } } return false; }
/** * {@inheritDoc} */ @Override public void visitNode(AstNode astNode) { getContext().addSourceCode(callback.createSourceCode(getContext().peekSourceCode(), astNode)); }
@Override public void visitNode(AstNode astNode) { if (astNode.is(Kind.RETURN_STATEMENT) && isLastReturnStatement(astNode)) { return; } getContext().peekSourceCode().add(EcmaScriptMetric.COMPLEXITY, 1); }
@Override public void leaveFile(AstNode astNode) { SourceFile sourceFile = (SourceFile) getContext().peekSourceCode(); int complexity = ChecksHelper.getRecursiveMeasureInt(sourceFile, PythonMetric.COMPLEXITY); if (complexity > maximumFileComplexityThreshold) { getContext().createFileViolation(this, "File has a complexity of {0,number,integer} which is greater than {1,number,integer} authorized.", complexity, maximumFileComplexityThreshold); } }
@Override public void leaveNode(AstNode node) { SourceClass sourceClass = (SourceClass) getContext().peekSourceCode(); int complexity = ChecksHelper.getRecursiveMeasureInt(sourceClass, PythonMetric.COMPLEXITY); if (complexity > maximumClassComplexityThreshold) { getContext().createLineViolation(this, "Class has a complexity of {0,number,integer} which is greater than {1,number,integer} authorized.", node, complexity, maximumClassComplexityThreshold); } }
@Override public void leaveFile(AstNode node) { Set<CheckMessage> violationsOnCurrentFile = new HashSet<CheckMessage>(getContext().peekSourceCode().getCheckMessages()); for (CheckMessage violation : violationsOnCurrentFile) { violationCounter.increment(getRelativePath(getContext().getFile()), violation.getChecker().getClass().getSimpleName(), violation.getLine() == null ? -1 : violation.getLine()); } }
/** * {@inheritDoc} */ @Override public void visitToken(Token token) { if (EOF.equals(token.getType())) { getContext().peekSourceCode().setMeasure(metric, token.getLine()); } }
private void checkNodeForPreviousComments(AstNode node) { for (Trivia trivia : node.getToken().getTrivia()) { if (trivia.isComment()) { getContext().peekSourceCode().add(CSharpMetric.PUBLIC_DOC_API, 1); break; } } }
@Override public void leaveNode(AstNode node) { SourceFunction function = (SourceFunction) getContext().peekSourceCode(); if (function.getInt(PythonMetric.COMPLEXITY) > maximumFunctionComplexityThreshold) { getContext().createLineViolation(this, "Function has a complexity of {0,number,integer} which is greater than {1,number,integer} authorized.", node, function.getInt(PythonMetric.COMPLEXITY), maximumFunctionComplexityThreshold); } }
@Override public void leaveNode(AstNode node) { SourceFunction function = (SourceFunction) getContext().peekSourceCode(); if (function.getInt(FlexMetric.COMPLEXITY) > maximumFunctionComplexityThreshold) { getContext().createLineViolation(this, "Function has a complexity of {0,number,integer} which is greater than {1,number,integer} authorized.", node, function.getInt(FlexMetric.COMPLEXITY), maximumFunctionComplexityThreshold); } }
@Override public void leaveNode(AstNode node) { SourceFunction function = (SourceFunction) getContext().peekSourceCode(); if (function.getInt(EcmaScriptMetric.COMPLEXITY) > maximumFunctionComplexityThreshold) { getContext().createLineViolation(this, "Function has a complexity of {0,number,integer} which is greater than {1,number,integer} authorized.", node, function.getInt(EcmaScriptMetric.COMPLEXITY), maximumFunctionComplexityThreshold); } }
@Override public void leaveNode(AstNode node) { SourceClass sourceClass = (SourceClass) getContext().peekSourceCode(); int complexity = ChecksHelper.getRecursiveMeasureInt(sourceClass, PHPMetric.COMPLEXITY); if (complexity > max) { getContext().createLineViolation(this, "The Cyclomatic Complexity of this class \"{0}\" is {1} which is greater than {2} authorized, split this class.", node, node.getFirstChild(PHPGrammar.IDENTIFIER).getTokenOriginalValue(), complexity, max); } }
@Override public void visitNode(AstNode astNode) { if (astNode.is(FlexGrammar.FUNCTION_DEF) && isAccessor(astNode)) { return; } else if (astNode.is(FlexGrammar.RETURN_STATEMENT) && isLastReturnStatement(astNode)) { return; } getContext().peekSourceCode().add(FlexMetric.COMPLEXITY, 1); }
@Override public void leaveFile(AstNode astNode) { SourceFile sourceFile = (SourceFile) getContext().peekSourceCode(); int fileComplexity = ChecksHelper.getRecursiveMeasureInt(sourceFile, getComplexityMetric()); if (fileComplexity > getMaximumFileComplexity()) { getContext().createFileViolation(this, "The file is too complex ({0} while maximum allowed is set to {1}).", fileComplexity, getMaximumFileComplexity()); } }