@Override public SourceCode createSourceCode(SourceCode parentSourceCode, AstNode astNode) { seq++; SourceFunction function = new SourceFunction("function:" + seq); function.setStartAtLine(astNode.getTokenLine()); return function; } }, FlexGrammar.FUNCTION_DEF, FlexGrammar.FUNCTION_EXPR));
@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); } }
public SourceFunction(SourceFile sourceFile, String functionSignature, int startAtLine) { super(sourceFile.getKey() + "#" + functionSignature, functionSignature); setStartAtLine(startAtLine); } }
/** * Builds and returns a source code builder callback. * * @param nodeName node type to identify a name. * @param isClass define a SourceClass or SourceFunction. * @return the builder callback. */ private static SourceCodeBuilderCallback buildCallback(AstNodeType nodeName, boolean isClass) { return (SourceCode sourceCode, AstNode astNode) -> { String key = generateKey(astNode, nodeName); sourceCode = isClass ? new SourceClass(key) : new SourceFunction(key); sourceCode.setStartAtLine(astNode.getTokenLine()); return sourceCode; }; }
@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 SourceCode createSourceCode(SourceCode parentSourceCode, AstNode astNode) { String functionKey = getFunctionKey(astNode); SourceFunction function = new SourceFunction(functionKey); function.setStartAtLine(astNode.getTokenLine()); return function; }
@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 SourceCode createSourceCode(SourceCode parentSourceCode, AstNode astNode) { String functionName = astNode.getFirstChild(PythonGrammar.FUNCNAME).getFirstChild().getTokenValue(); SourceFunction function = new SourceFunction(functionName + ":" + astNode.getToken().getLine()); function.setStartAtLine(astNode.getTokenLine()); return function; } }, PythonGrammar.FUNCDEF));
@Override public void leaveNode(AstNode node) { SourceFunction function = (SourceFunction) getContext().peekSourceCode(); if (function.getInt(PHPMetric.COMPLEXITY) > threshold) { getContext().createLineViolation(this, "The Cyclomatic Complexity of this function {0} is {1} which is greater than {2} authorized.", node, FunctionUtils.getFunctionName(node), function.getInt(PHPMetric.COMPLEXITY), threshold); } }
@Override public SourceCode createSourceCode(SourceCode parentSourceCode, AstNode astNode) { AstNode identifier = astNode.getFirstChild(EcmaScriptTokenType.IDENTIFIER, EcmaScriptGrammar.PROPERTY_NAME, Kind.IDENTIFIER); final String functionName = identifier == null ? "anonymous" : identifier.getTokenValue(); final String fileKey = parentSourceCode.isType(SourceFile.class) ? parentSourceCode.getKey() : parentSourceCode.getParent(SourceFile.class).getKey(); SourceFunction function = new SourceFunction(fileKey + ":" + functionName + ":" + astNode.getToken().getLine() + ":" + astNode.getToken().getColumn()); function.setStartAtLine(astNode.getTokenLine()); return function; } }, FUNCTION_NODES));