org.sonar.squidbridge.api.SourceProject Java Examples

The following examples show how to use org.sonar.squidbridge.api.SourceProject. 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: FlowAstScanner.java    From sonar-flow-plugin with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Creates the AstScanner. It will set flow and metric checks, next to the default ones.
 * 
 * @param conf
 *          Configuration
 * @param checks
 *          Additional checks to set
 * @param metrics
 *          Additional metrics to set
 * @return
 */
public static AstScanner<Grammar> create(FlowConfiguration conf, Collection<FlowCheck> checks,
    @Nullable List<SquidAstVisitor<Grammar>> metrics) {
  final SquidAstVisitorContextImpl<Grammar> context = new SquidAstVisitorContextImpl<Grammar>(
      new SourceProject("Flow Project"));
  final Parser<Grammar> parser = FlowParser.create(conf);

  AstScanner.Builder<Grammar> builder = AstScanner.<Grammar>builder(context)
      .setBaseParser(parser);
  /* Required commentAnalyzer */
  builder.setCommentAnalyser(new CommentAnalyser());
  /* Metrics */
  ArrayList<SquidAstVisitor<Grammar>> metricList = new ArrayList<SquidAstVisitor<Grammar>>();
  metricList.addAll(MetricList.getFlowVisitors());
  if (metrics != null) {
    metricList.addAll(metrics);
  }
  setMetrics(builder, metricList);
  /* Checks */
  for (FlowCheck flowCheck : checks) {
    builder.withSquidAstVisitor(flowCheck);
  }
  return builder.build();
}
 
Example #2
Source File: NodeAstScanner.java    From sonar-flow-plugin with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Creates the AstScanner. It will set flow and metric checks, next to the default ones.
 * 
 * @param conf
 *          Configuration
 * @param checks
 *          Additional checks to set
 * @param metrics
 *          Additional metrics to set
 * @return
 */
public static AstScanner<Grammar> create(FlowConfiguration conf, Collection<FlowCheck> checks,
    @Nullable List<SquidAstVisitor<Grammar>> metrics) {
  final SquidAstVisitorContextImpl<Grammar> context = new SquidAstVisitorContextImpl<Grammar>(
      new SourceProject("Flow Project"));
  final Parser<Grammar> parser = NodeParser.create(conf);

  AstScanner.Builder<Grammar> builder = AstScanner.<Grammar>builder(context)
      .setBaseParser(parser);
  /* Required commentAnalyzer */
  builder.setCommentAnalyser(new CommentAnalyser());
  /* Metrics */
  ArrayList<SquidAstVisitor<Grammar>> metricList = new ArrayList<SquidAstVisitor<Grammar>>();
  metricList.addAll(MetricList.getDefaultNodeVisitors());
  if (metrics != null) {
    metricList.addAll(metrics);
  }
  setMetrics(builder, metricList);
  /* Checks */
  for (FlowCheck flowCheck : checks) {
    builder.withSquidAstVisitor(flowCheck);
  }
  return builder.build();
}
 
Example #3
Source File: ApexAstScannerTest.java    From enforce-sonarqube-plugin with MIT License 5 votes vote down vote up
@Test
public void testTheNumberOfScannedFiles() {
    AstScanner<Grammar> scanner = ApexAstScanner.create(apexConfiguration);
    scanner.scanFiles(ImmutableList.of(
            new File("src/test/resources/metrics/methods.cls"),
            new File("src/test/resources/metrics/lines.cls")));
    SourceProject project = buildProject(scanner);
    assertThat(project.getInt(ApexMetric.FILES)).isEqualTo(2);
}
 
Example #4
Source File: LuaAstScannerTest.java    From sonar-lua with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void files() {
  AstScanner<LexerlessGrammar> scanner = LuaAstScanner.create(new LuaConfiguration(Charsets.UTF_8), Collections.emptyList());
  scanner.scanFiles(ImmutableList.of(new File("src/test/resources/metrics/comments.lua"),
    new File("src/test/resources/metrics/lines.lua")));
  SourceProject project = (SourceProject) scanner.getIndex().search(new QueryByType(SourceProject.class)).iterator().next();
  assertThat(project.getInt(LuaMetric.FILES)).isEqualTo(2);
}
 
Example #5
Source File: ApexAstScannerTest.java    From enforce-sonarqube-plugin with MIT License 4 votes vote down vote up
private SourceProject buildProject(AstScanner<Grammar> scanner) {
    return (SourceProject) scanner.getIndex().search(new QueryByType(SourceProject.class)).iterator().next();
}