org.sonar.squidbridge.indexer.QueryByParent Java Examples

The following examples show how to use org.sonar.squidbridge.indexer.QueryByParent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ApexSquidSensor.java    From enforce-sonarqube-plugin with MIT License 5 votes vote down vote up
/**
 * 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));
}
 
Example #2
Source File: FlowSquidSensor.java    From sonar-flow-plugin with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void saveClassComplexity(SensorContext context, AstScanner<Grammar> flowScanner,
    InputFile inputFile, SourceFile squidFile) {
  Collection<SourceCode> classes = flowScanner.getIndex().search(new QueryByParent(squidFile),
      new QueryByType(SourceClass.class));
  Integer complexityInClasses = 0;
  for (SourceCode squidClass : classes) {
    int classComplexity = squidClass.getInt(FlowMetric.INVOKES);
    complexityInClasses += classComplexity;
  }
  context.<Integer>newMeasure().on(inputFile).forMetric(CoreMetrics.COMPLEXITY_IN_CLASSES)
      .withValue(complexityInClasses).save();
}
 
Example #3
Source File: LuaSquidSensor.java    From sonar-lua with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void saveClassComplexity(SensorContext context, InputFile inputFile, SourceFile squidFile) {
  Collection<SourceCode> classes = scanner.getIndex().search(new QueryByParent(squidFile), new QueryByType(SourceClass.class));
  int complexityInClasses = 0;
  for (SourceCode squidClass : classes) {
    int classComplexity = squidClass.getInt(LuaMetric.COMPLEXITY);
    complexityInClasses += classComplexity;
  }
  context.<Integer>newMeasure()
    .on(inputFile)
    .forMetric(CoreMetrics.COMPLEXITY_IN_CLASSES)
    .withValue(complexityInClasses)
    .save();
}
 
Example #4
Source File: LuaSquidSensor.java    From sonar-lua with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void saveFunctionsComplexityDistribution(SensorContext context, InputFile inputFile, SourceFile squidFile) {
  Collection<SourceCode> squidFunctionsInFile = scanner.getIndex().search(new QueryByParent(squidFile), new QueryByType(SourceFunction.class));
  RangeDistributionBuilder complexityDistribution = new RangeDistributionBuilder(FUNCTIONS_DISTRIB_BOTTOM_LIMITS);
  for (SourceCode squidFunction : squidFunctionsInFile) {
    complexityDistribution.add(squidFunction.getDouble(LuaMetric.COMPLEXITY));
  }
  context.<String>newMeasure()
    .on(inputFile)
    .forMetric(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION)
    .withValue(complexityDistribution.build())
    .save();
}