public void add(MetricDef metric, SourceCode child) { add(metric, child.getMeasure(metric)); }
@Override public void leaveFile(@Nullable AstNode astNode) { getContext().peekSourceCode().add(metric, lines.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; }
private void increaseComplexity(int i) { getContext().peekSourceCode().add(ErlangMetric.COMPLEXITY, i); } }
@Override public void visitNode(AstNode astNode) { getContext().peekSourceCode().add(PythonMetric.COMPLEXITY, 1); }
@Override public void visitNode(AstNode astNode) { getContext().peekSourceCode().add(metric, 1); }
@Override public void visitNode(AstNode astNode) { for (AstNodeType exclusionAstNodeType : exclusionAstNodeTypes) { if (astNode.hasAncestor(exclusionAstNodeType)) { return; } } getContext().peekSourceCode().add(metric, 1); }
@Override public void visitNode(AstNode astNode) { if (astNode.getFirstAncestor(ErlangGrammarImpl.functionDeclaration) != null) { getContext().peekSourceCode().add(ErlangMetric.STATEMENTS, 1); } } }
@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 visitNode(AstNode ast) { if (ast.getType().equals(ErlangGrammarImpl.functionDeclaration)) { actualArity = getArity(ast.getFirstChild(ErlangGrammarImpl.functionClause)); } if (ast.getType().equals(ErlangGrammarImpl.callExpression) && getArityFromCall(ast).equals(actualArity)) { getContext().peekSourceCode().add(ErlangMetric.BRANCHES_OF_RECURSION, 1); } }
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 visitToken(Token token) { if (!token.getType().equals(EOF) && !token.getType().equals(PythonTokenType.DEDENT) && !token.getType().equals(PythonTokenType.INDENT) && !token.getType().equals(PythonTokenType.NEWLINE)) { /* Handle all the lines of the token */ String[] tokenLines = token.getValue().split("\n", -1); int firstLineAlreadyCounted = lastTokenLine == token.getLine() ? 1 : 0; getContext().peekSourceCode().add(metric, (double)tokenLines.length - firstLineAlreadyCounted); lastTokenLine = token.getLine() + tokenLines.length - 1; } }
@Override public void visitNode(AstNode astNode) { if (astNode.is(Kind.RETURN_STATEMENT) && isLastReturnStatement(astNode)) { return; } getContext().peekSourceCode().add(EcmaScriptMetric.COMPLEXITY, 1); }
@Override public void visitNode(AstNode ast) { AstNode args = ast.getFirstChild(ErlangGrammarImpl.funcDecl).getFirstChild( ErlangGrammarImpl.arguments); int numOfArgs = 0; for (AstNode arg : args.getChildren()) { if (!nonArg.contains(arg.getType())) { numOfArgs++; } } getContext().peekSourceCode().add(ErlangMetric.NUM_OF_FUNC_ARGS, numOfArgs); }
private void checkNodeForPreviousComments(AstNode node) { for (Trivia trivia : node.getToken().getTrivia()) { if (trivia.isComment()) { getContext().peekSourceCode().add(CSharpMetric.PUBLIC_DOC_API, 1); break; } } }
/** * {@inheritDoc} */ @Override public void visitToken(Token token) { if (!EOF.equals(token.getType())) { /* Handle all the lines of the token */ String[] tokenLines = token.getValue().split("\n", -1); int firstLineAlreadyCounted = lastTokenLine == token.getLine() ? 1 : 0; getContext().peekSourceCode().add(metric, tokenLines.length - firstLineAlreadyCounted); lastTokenLine = token.getLine() + tokenLines.length - 1; } }
@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); }
/** * {@inheritDoc} */ @Override public void visitNode(AstNode node) { if (node.hasChildren() && node.getChild(0).is(CSharpPunctuator.SEMICOLON)) { // this is an empty declaration return; } if (node.is(CSharpGrammar.RETURN_STATEMENT) && isLastReturnStatement(node)) { // last return of a block, do not count +1 return; } getContext().peekSourceCode().add(CSharpMetric.COMPLEXITY, 1); }
private void decorateWith(SourceCode sourceCode, MetricDef... metrics) { if (sourceCode.hasChildren()) { for (SourceCode child : sourceCode.getChildren()) { decorateWith(child, metrics); } } for (MetricDef metric : metrics) { if (!metric.aggregateIfThereIsAlreadyAValue() && Double.doubleToRawLongBits(sourceCode.getDouble(metric)) != 0) { continue; } if (sourceCode.hasChildren()) { for (SourceCode child : sourceCode.getChildren()) { if (!metric.isCalculatedMetric() && metric.isThereAggregationFormula()) { sourceCode.add(metric, child); } } } } } }