private void saveFilesComplexityDistribution(File sonarFile, SourceFile squidFile) { RangeDistributionBuilder complexityDistribution = new RangeDistributionBuilder(CoreMetrics.FILE_COMPLEXITY_DISTRIBUTION, FILES_DISTRIB_BOTTOM_LIMITS); complexityDistribution.add(squidFile.getDouble(ObjectiveCMetric.COMPLEXITY)); context.saveMeasure(sonarFile, complexityDistribution.build().setPersistenceMode(PersistenceMode.MEMORY)); }
/** * Adds an existing Distribution to the current one. * It will create the entries if they don't exist. * Can be used to add the values of children resources for example * <p/> * Since 2.2, the distribution returned will be invalidated in case the * measure given does not use the same bottom limits * * @param measure the measure to add to the current one * @return the current object */ public RangeDistributionBuilder add(@Nullable Measure<String> measure) { if (measure != null && measure.getData() != null) { Map<Double, Double> map = KeyValueFormat.parse(measure.getData(), KeyValueFormat.newDoubleConverter(), KeyValueFormat.newDoubleConverter()); Number[] limits = map.keySet().toArray(new Number[map.size()]); if (bottomLimits == null) { init(limits); } else if (!areSameLimits(bottomLimits, map.keySet())) { isValid = false; } if (isValid) { for (Map.Entry<Double, Double> entry : map.entrySet()) { addLimitCount(entry.getKey(), entry.getValue().intValue()); } } } return this; }
/** * Saves a measure with the limits of the file. * * @param sonarFile input file. * @param squidFile source file. */ private void saveFilesComplexityDistribution(InputFile sonarFile, SourceFile squidFile) { RangeDistributionBuilder complexityDistribution = new RangeDistributionBuilder( CoreMetrics.FILE_COMPLEXITY_DISTRIBUTION, FILES_DISTRIB_BOTTOM_LIMITS); complexityDistribution.add(squidFile.getDouble(ApexMetric.COMPLEXITY)); context.saveMeasure(sonarFile, buildMeasure(complexityDistribution)); }
/** * Increments an entry by 1 * * @param value the value to use to pick the entry to increment * @return the current object */ public RangeDistributionBuilder add(Number value) { return add(value, 1); }
/** * Shortcut for <code>build(true)</code> * * @return the built measure */ @Override public Measure<String> build() { return build(true); }
/** * Saves a measure with the limits of the function. * * @param sonarFile input file. * @param squidFile source file. */ private void saveFunctionsComplexityDistribution(InputFile sonarFile, SourceFile squidFile) { Collection<SourceCode> squidFunctionsInFile = scanner.getIndex().search( new QueryByParent(squidFile), new QueryByType(SourceFunction.class)); RangeDistributionBuilder complexityDistribution = new RangeDistributionBuilder( CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION, FUNCTIONS_DISTRIB_BOTTOM_LIMITS); squidFunctionsInFile.forEach(squidFunction -> complexityDistribution.add(squidFunction.getDouble(ApexMetric.COMPLEXITY)) ); context.saveMeasure(sonarFile, buildMeasure(complexityDistribution)); }
@Override public void visitNode(Tree tree) { if (isClassTree(tree)) { classes++; classTrees.push((ClassTree) tree); } if (tree.is(Tree.Kind.NEW_CLASS) && ((NewClassTree) tree).classBody() != null) { classes--; } if (tree.is(Tree.Kind.METHOD, Tree.Kind.CONSTRUCTOR) && classTrees.peek().simpleName() != null) { //don't count methods in anonymous classes. MethodTree methodTree = (MethodTree) tree; if (separateAccessorsFromMethods && AccessorsUtils.isAccessor(classTrees.peek(), methodTree)) { accessors++; } else { methods++; int methodComplexity = context.getMethodComplexityNodes(classTrees.peek(), methodTree).size(); methodComplexityDistribution.add(methodComplexity); complexityInMethods += methodComplexity; } } }
private void saveFilesComplexityDistribution(File sonarFile, SourceFile squidFile) { RangeDistributionBuilder complexityDistribution = new RangeDistributionBuilder(CoreMetrics.FILE_COMPLEXITY_DISTRIBUTION, FILES_DISTRIB_BOTTOM_LIMITS); complexityDistribution.add(squidFile.getDouble(EcmaScriptMetric.COMPLEXITY)); context.saveMeasure(sonarFile, complexityDistribution.build().setPersistenceMode(PersistenceMode.MEMORY)); }
private void processFunction(InputFile resource, FunctionInterface func) { if (!func.isAccessor()) { methodsCount++; functionComplexity += func.getComplexity(); functionDist.add(Double.valueOf(func.getComplexity())); addIssue(resource, func); for (FunctionInterface over : func.getOverloadedFunctions()) { processFunction(resource, over); } } statementsCount += func.getStatements().size(); }
private void saveComplexityDistribution(SensorContext sensorContext, WebSourceCode sourceCode) { if (sourceCode.getMeasure(CoreMetrics.COMPLEXITY) != null) { RangeDistributionBuilder complexityFileDistribution = new RangeDistributionBuilder(CoreMetrics.FILE_COMPLEXITY_DISTRIBUTION, FILES_DISTRIB_BOTTOM_LIMITS); complexityFileDistribution.add(sourceCode.getMeasure(CoreMetrics.COMPLEXITY).getValue()); sensorContext.saveMeasure(sourceCode.getResource(), complexityFileDistribution.build().setPersistenceMode(PersistenceMode.MEMORY)); } }
@Override public void visitNode(Tree tree) { if (isClassTree(tree)) { classes++; classTrees.push((ClassTree) tree); } if (tree.is(Tree.Kind.NEW_CLASS) && ((NewClassTree) tree).classBody() != null) { classes--; } if (tree.is(Tree.Kind.METHOD, Tree.Kind.CONSTRUCTOR) && classTrees.peek().simpleName() != null) { //don't count methods in anonymous classes. MethodTree methodTree = (MethodTree) tree; if (separateAccessorsFromMethods && accessorVisitor.isAccessor(classTrees.peek(), methodTree)) { accessors++; } else { methods++; int methodComplexity = context.getMethodComplexity(classTrees.peek(), methodTree); methodComplexityDistribution.add(methodComplexity); complexityInMethods += methodComplexity; } } }
private void saveFunctionsComplexityDistribution(File sonarFile, SourceFile squidFile) { Collection<SourceCode> squidFunctionsInFile = scanner.getIndex().search(new QueryByParent(squidFile), new QueryByType(SourceFunction.class)); RangeDistributionBuilder complexityDistribution = new RangeDistributionBuilder(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION, FUNCTIONS_DISTRIB_BOTTOM_LIMITS); for (SourceCode squidFunction : squidFunctionsInFile) { complexityDistribution.add(squidFunction.getDouble(ObjectiveCMetric.COMPLEXITY)); } context.saveMeasure(sonarFile, complexityDistribution.build().setPersistenceMode(PersistenceMode.MEMORY)); }
private void saveMethodsComplexityDistribution(File sonarFile, SourceFile squidFile) { Collection<SourceCode> squidMethods = scanner.getIndex().search(new QueryByParent(squidFile), new QueryByType(SourceMember.class)); RangeDistributionBuilder complexityMethodDistribution = new RangeDistributionBuilder(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION, METHOD_DISTRIB_BOTTOM_LIMITS); for (SourceCode squidMethod : squidMethods) { complexityMethodDistribution.add(squidMethod.getDouble(CSharpMetric.COMPLEXITY)); } context.saveMeasure(sonarFile, complexityMethodDistribution.build().setPersistenceMode(PersistenceMode.MEMORY)); }
/** * Collects the given class measures and launches {@see #collectFunctionMeasures(MethodNode, PhpFile)} for all its descendant. * * @param file * the php related file * @param classNode * representing the class in the report file * @param methodComplexityDistribution */ private void collectClassMeasures(ClassNode classNode, PhpFile file, RangeDistributionBuilder methodComplexityDistribution) { addMeasureIfNecessary(file, LINES, classNode.getLinesNumber()); addMeasureIfNecessary(file, COMMENT_LINES, classNode.getCommentLineNumber()); addMeasureIfNecessary(file, NCLOC, classNode.getCodeLinesNumber()); // Adds one class to this file addMeasure(file, CLASSES, 1.0); // for all methods in this class. List<MethodNode> methodes = classNode.getMethodes(); if (methodes != null && !methodes.isEmpty()) { for (MethodNode methodNode : methodes) { collectMethodMeasures(methodNode, file); methodComplexityDistribution.add(methodNode.getComplexity()); } } }
private void saveClassesComplexityDistribution(File sonarFile, SourceFile squidFile) { Collection<SourceCode> squidClasses = scanner.getIndex().search(new QueryByParent(squidFile), new QueryByType(SourceClass.class)); RangeDistributionBuilder complexityClassDistribution = new RangeDistributionBuilder(CoreMetrics.CLASS_COMPLEXITY_DISTRIBUTION, CLASS_DISTRIB_BOTTOM_LIMITS); for (SourceCode squidClass : squidClasses) { complexityClassDistribution.add(squidClass.getDouble(CSharpMetric.COMPLEXITY)); } context.saveMeasure(sonarFile, complexityClassDistribution.build().setPersistenceMode(PersistenceMode.MEMORY)); }
/** * Collects the given function measures. * * @param file * the php related file * @param functionNode * representing the class in the report file * @param methodComplexityDistribution */ private void collectFunctionsMeasures(FunctionNode functionNode, PhpFile file, RangeDistributionBuilder methodComplexityDistribution) { addMeasureIfNecessary(file, LINES, functionNode.getLinesNumber()); addMeasureIfNecessary(file, COMMENT_LINES, functionNode.getCommentLineNumber()); addMeasureIfNecessary(file, NCLOC, functionNode.getCodeLinesNumber()); // Adds one class to this file addMeasure(file, FUNCTIONS, 1.0); addMeasure(file, COMPLEXITY, functionNode.getComplexity()); methodComplexityDistribution.add(functionNode.getComplexity()); }
@Override public Measure calculate(FormulaData data, FormulaContext context) { Collection<Measure> measures = data.getChildrenMeasures(context.getTargetMetric()); if (measures == null || measures.isEmpty()) { return null; } RangeDistributionBuilder distribution = new RangeDistributionBuilder(context.getTargetMetric()); for (Measure measure : measures) { distribution.add(measure); } Measure measure = distribution.build(); if (!Scopes.isHigherThanOrEquals(context.getResource().getScope(), minimumScopeToPersist)) { measure.setPersistenceMode(PersistenceMode.MEMORY); } return measure; } }
private void saveFunctionsComplexityAndDistribution(File sonarFile, SourceFile squidFile) { Collection<SourceCode> squidFunctionsInFile = scanner.getIndex().search(new QueryByParent(squidFile), new QueryByType(SourceFunction.class)); RangeDistributionBuilder complexityDistribution = new RangeDistributionBuilder(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION, FUNCTIONS_DISTRIB_BOTTOM_LIMITS); double complexityInFunction = 0; for (SourceCode squidFunction : squidFunctionsInFile) { double functionComplexity = squidFunction.getDouble(EcmaScriptMetric.COMPLEXITY); complexityDistribution.add(functionComplexity); complexityInFunction += functionComplexity; } context.saveMeasure(sonarFile, complexityDistribution.build().setPersistenceMode(PersistenceMode.MEMORY)); context.saveMeasure(sonarFile, CoreMetrics.COMPLEXITY_IN_FUNCTIONS, complexityInFunction); }