Java Code Examples for org.sonar.squidbridge.SquidAstVisitor

The following examples show how to use org.sonar.squidbridge.SquidAstVisitor. These examples are extracted from open source projects. 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 Project: enforce-sonarqube-plugin   Source File: ApexSquidSensor.java    License: MIT License 6 votes vote down vote up
/**
 * Saves issues form input file and source file.
 *
 * @param sonarFile input file.
 * @param squidFile source file.
 */
private void saveIssues(InputFile sonarFile, SourceFile squidFile) {
    Collection<CheckMessage> messages = squidFile.getCheckMessages();
    messages.forEach(message -> {
        RuleKey ruleKey = checks.ruleKey((SquidAstVisitor<Grammar>) message.getCheck());
        Issuable issuable = resourcePerspectives.as(Issuable.class, sonarFile);

        if (issuable != null) {
            Issue issue = issuable.newIssueBuilder()
                    .ruleKey(ruleKey)
                    .line(message.getLine())
                    .message(message.getText(Locale.ENGLISH))
                    .build();
            issuable.addIssue(issue);
        }
    });
}
 
Example 2
/**
 * 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 3
/**
 * 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 4
/**
 * Helper method for testing checks without having to deploy them on a Sonar instance.
 */
public static SourceFile scanSingleFile(File file, Collection<FlowCheck> nodeChecks,
    List<SquidAstVisitor<Grammar>> metrics) {
  if (!file.isFile()) {
    throw new IllegalArgumentException("File '" + file + "' not found.");
  }

  AstScanner<Grammar> scanner = create(new FlowConfiguration(Charsets.UTF_8), nodeChecks,
      metrics);
  scanner.scanFile(file);
  Collection<SourceCode> sources = scanner.getIndex().search(new QueryByType(SourceFile.class));
  if (sources.size() != 1) {
    throw new IllegalStateException(
        "Only one SourceFile was expected whereas " + sources.size() + " has been returned.");
  }
  return (SourceFile) sources.iterator().next();
}
 
Example 5
@Test
public void branchPropertiesCheckInvalidA() {
  List<SquidAstVisitor<Grammar>> metrics = new ArrayList<SquidAstVisitor<Grammar>>();
  metrics.add(new SimpleMetricVisitor());
  List<FlowCheck> checks = new ArrayList<FlowCheck>();
  checks.add(new BranchPropertiesCheck());

  final String expectedMessageA 
      = "Both switch and evaluate labels are defined in properties of BRANCH";

  // Check violation flow A: both switch and evaluate labels defined
  SourceFile sfViolationA = FlowAstScanner
      .scanSingleFile(new File("src/test/resources/WmTestPackage/ns/I8cFlowSonarPluginTest"
          + "/pub/checkBranchPropertiesInvalidA/flow.xml"), checks, metrics);
  List<CheckMessage> violationAMessages = new ArrayList<CheckMessage>(
      sfViolationA.getCheckMessages());
  assertEquals(1, violationAMessages.size());
  assertTrue("Returned check message not as expected",
      expectedMessageA.equals(violationAMessages.get(0).getDefaultMessage()));
}
 
Example 6
@Test
public void branchPropertiesCheckInvalidB() {
  List<SquidAstVisitor<Grammar>> metrics = new ArrayList<SquidAstVisitor<Grammar>>();
  metrics.add(new SimpleMetricVisitor());
  List<FlowCheck> checks = new ArrayList<FlowCheck>();
  checks.add(new BranchPropertiesCheck());

  final String expectedMessageB 
      = "Evaluate labels must be true when no switch parameter is defined in BRANCH";

  // Check violation flow B: neither switch nor evaluate labels defined
  SourceFile sfViolationB = FlowAstScanner
      .scanSingleFile(new File("src/test/resources/WmTestPackage/ns/I8cFlowSonarPluginTest"
          + "/pub/checkBranchPropertiesInvalidB/flow.xml"), checks, metrics);
  List<CheckMessage> violationBMessages = new ArrayList<CheckMessage>(
      sfViolationB.getCheckMessages());
  assertEquals(1, violationBMessages.size());
  assertTrue("Returned check message not as expected",
      expectedMessageB.equals(violationBMessages.get(0).getDefaultMessage()));
}
 
Example 7
@Test
public void tryCatchCheckInvalid() {
  List<SquidAstVisitor<Grammar>> metrics = new ArrayList<SquidAstVisitor<Grammar>>();
  metrics.add(new SimpleMetricVisitor());
  List<FlowCheck> checks = new ArrayList<FlowCheck>();
  checks.add(new TryCatchCheck());

  // check invalid flow
  String invalidFlowPath = "src/test/resources/WmTestPackage/ns/I8cFlowSonarPluginTest"
      + "/pub/checkTryCatchInvalid/flow.xml";
  String expectedMessage = "Create try-catch sequence";

  SourceFile sfViolation = FlowAstScanner.scanSingleFile(new File(invalidFlowPath), checks,
      metrics);
  List<CheckMessage> violationMessages = new ArrayList<CheckMessage>(
      sfViolation.getCheckMessages());
  assertEquals(1, violationMessages.size());
  assertTrue("Returned check message not as expected",
      expectedMessage.equals(violationMessages.get(0).getDefaultMessage()));

}
 
Example 8
@Test
public void emptyFlowCheck() {
  List<SquidAstVisitor<Grammar>> metrics = new ArrayList<SquidAstVisitor<Grammar>>();
  metrics.add(new SimpleMetricVisitor());
  List<FlowCheck> checks = new ArrayList<FlowCheck>();
  checks.add(new EmptyFlowCheck());

  String invalidPath = "src/test/resources/WmTestPackage/ns/I8cFlowSonarPluginTest"
      + "/pub/checkEmptyFlowInvalid/flow.xml";
  String expectedMessage 
      = "Service doesn't contain any flow steps. Remove service or add flow steps.";

  SourceFile sfViolation = FlowAstScanner.scanSingleFile(new File(invalidPath), checks, metrics);
  List<CheckMessage> violationMessages = new ArrayList<CheckMessage>(
      sfViolation.getCheckMessages());
  assertEquals(1, violationMessages.size());
  assertTrue("Returned check message not as expected",
      expectedMessage.equals(violationMessages.get(0).getDefaultMessage()));
}
 
Example 9
@Test
public void qualifiedNameCheckValid() {
  Configuration cfg = mock(Configuration.class);
  Mockito.when(cfg.get(QualifiedNameCheck.QUALIFIED_NAME_KEY)).thenReturn(Optional.of(QualifiedNameCheck.QUALIFIED_NAME_DEFVALUE));
  FlowLanguage.setConfig(cfg);
  List<SquidAstVisitor<Grammar>> metrics = new ArrayList<SquidAstVisitor<Grammar>>();
  metrics.add(new SimpleMetricVisitor());
  List<FlowCheck> checks = new ArrayList<FlowCheck>();
  QualifiedNameCheck qnc = new QualifiedNameCheck();
  checks.add(qnc);
  String validPath = "src/test/resources/WmTestPackage/ns/I8cFlowSonarPluginTest"
      + "/pub/checkQualityNameInvalid/flow.xml";

  SourceFile sfCorrect = FlowAstScanner.scanSingleFile(new File(validPath), checks, metrics);
  Set<CheckMessage> scmCorrect = sfCorrect.getCheckMessages();
  assertEquals(0, scmCorrect.size());  
}
 
Example 10
@Test
public void qualifiedNameCheckInvalid() {
  Configuration cfg = mock(Configuration.class);
  Mockito.when(cfg.get(QualifiedNameCheck.QUALIFIED_NAME_KEY)).thenReturn(Optional.of("test.*"));
  FlowLanguage.setConfig(cfg);
  List<SquidAstVisitor<Grammar>> metrics = new ArrayList<SquidAstVisitor<Grammar>>();
  metrics.add(new SimpleMetricVisitor());
  List<FlowCheck> checks = new ArrayList<FlowCheck>();
  QualifiedNameCheck qnc = new QualifiedNameCheck();
  checks.add(qnc);
  String validPath = "src/test/resources/WmTestPackage/ns/I8cFlowSonarPluginTest"
      + "/pub/checkQualityNameInvalid/flow.xml";

  SourceFile sfCorrect = FlowAstScanner.scanSingleFile(new File(validPath), checks, metrics);
  Set<CheckMessage> scmCorrect = sfCorrect.getCheckMessages();
  assertEquals(1, scmCorrect.size());  
}
 
Example 11
@Test
public void savePipelineCheck() {
  List<SquidAstVisitor<Grammar>> metrics = new ArrayList<SquidAstVisitor<Grammar>>();
  metrics.add(new SimpleMetricVisitor());
  List<FlowCheck> checks = new ArrayList<FlowCheck>();
  checks.add(new SavePipelineCheck());

  String invalidPath = "src/test/resources/WmTestPackage/ns/I8cFlowSonarPluginTest"
      + "/pub/checkSavePipelineInvalid/flow.xml";
  String expectedMessage = "Remove service pub.flow:savePipeline";

  SourceFile sfViolation = FlowAstScanner.scanSingleFile(new File(invalidPath), checks, metrics);
  List<CheckMessage> violationMessages = new ArrayList<CheckMessage>(
      sfViolation.getCheckMessages());
  assertEquals(1, violationMessages.size());
  assertTrue("Returned check message not as expected",
      expectedMessage.equals(violationMessages.get(0).getDefaultMessage()));

}
 
Example 12
@Test
public void emptyMapCheckInvalid() {
  List<SquidAstVisitor<Grammar>> metrics = new ArrayList<SquidAstVisitor<Grammar>>();
  metrics.add(new SimpleMetricVisitor());
  List<FlowCheck> checks = new ArrayList<FlowCheck>();
  checks.add(new EmptyMapCheck());

  // Invalid
  String invalidPath = "src/test/resources/WmTestPackage/ns/I8cFlowSonarPluginTest"
      + "/pub/checkEmptyMapInvalid/flow.xml";
  String expectedMessage 
      = "This map step in the flow is empty, create content or remove the map.";

  SourceFile sfViolation = FlowAstScanner.scanSingleFile(new File(invalidPath), checks, metrics);
  List<CheckMessage> violationMessages = new ArrayList<CheckMessage>(
      sfViolation.getCheckMessages());
  assertEquals(1, violationMessages.size());
  assertTrue("Returned check message not as expected",
      expectedMessage.equals(violationMessages.get(0).getDefaultMessage()));
}
 
Example 13
@Test
public void emptyMapCheckValid() {
  List<SquidAstVisitor<Grammar>> metrics = new ArrayList<SquidAstVisitor<Grammar>>();
  metrics.add(new SimpleMetricVisitor());
  List<FlowCheck> checks = new ArrayList<FlowCheck>();
  checks.add(new EmptyMapCheck());

  // Valid
  String invalidPath = "src/test/resources/WmTestPackage/ns/I8cFlowSonarPluginTest"
      + "/pub/checkEmptyMapValid/flow.xml";

  SourceFile sfViolation = FlowAstScanner.scanSingleFile(new File(invalidPath), checks, metrics);
  List<CheckMessage> violationMessages = new ArrayList<CheckMessage>(
      sfViolation.getCheckMessages());
  assertEquals(0, violationMessages.size());
}
 
Example 14
@Test
public void exitCheck() {
  List<SquidAstVisitor<Grammar>> metrics = new ArrayList<SquidAstVisitor<Grammar>>();
  metrics.add(new SimpleMetricVisitor());
  List<FlowCheck> checks = new ArrayList<FlowCheck>();
  checks.add(new ExitCheck());

  String invalidPath = "src/test/resources/WmTestPackage/ns/I8cFlowSonarPluginTest"
      + "/pub/checkExitStepInvalid/flow.xml";

  SourceFile sfViolation = FlowAstScanner.scanSingleFile(new File(invalidPath), checks, metrics);
  List<CheckMessage> violationMessages = new ArrayList<CheckMessage>(
      sfViolation.getCheckMessages());
  assertEquals(2, violationMessages.size());
  // TODO check both violation messages
}
 
Example 15
@Test
public void disabledCheck() {
  List<SquidAstVisitor<Grammar>> metrics = new ArrayList<SquidAstVisitor<Grammar>>();
  metrics.add(new SimpleMetricVisitor());
  List<FlowCheck> checks = new ArrayList<FlowCheck>();
  checks.add(new DisabledCheck());

  String invalidPath = "src/test/resources/WmTestPackage/ns/I8cFlowSonarPluginTest"
      + "/pub/checkDisabledInvalid/flow.xml";
  String expectedMessage = "Remove disabled code";

  SourceFile sfViolation = FlowAstScanner.scanSingleFile(new File(invalidPath), checks, metrics);
  List<CheckMessage> violationMessages = new ArrayList<CheckMessage>(
      sfViolation.getCheckMessages());
  assertEquals(1, violationMessages.size());
  assertTrue("Returned check message not as expected",
      expectedMessage.equals(violationMessages.get(0).getDefaultMessage()));
}
 
Example 16
@Override
public void execute(SensorContext context) {
  FileSystem fileSystem = context.fileSystem();
  FilePredicates predicates = fileSystem.predicates();
  List<SquidAstVisitor<LexerlessGrammar>> visitors = new ArrayList<>(checks.all());
  visitors.add(new FileLinesVisitor(fileLinesContextFactory, fileSystem));
  LuaConfiguration configuration = new LuaConfiguration(fileSystem.encoding());

  scanner = LuaAstScanner.create(configuration, visitors);

  Iterable<java.io.File> files = fileSystem.files(
    predicates.and(
      predicates.hasType(InputFile.Type.MAIN),
      predicates.hasLanguage(Lua.KEY),
      inputFile -> !inputFile.absolutePath().endsWith("mxml")
    ));
  scanner.scanFiles(ImmutableList.copyOf(files));

  Collection<SourceCode> squidSourceFiles = scanner.getIndex().search(new QueryByType(SourceFile.class));
  save(context, squidSourceFiles);
}
 
Example 17
Source Project: enforce-sonarqube-plugin   Source File: ApexSquidSensor.java    License: MIT License 5 votes vote down vote up
/**
 * Default construct to initialize the variables.
 *
 * @param fileSystem source files.
 * @param perspectives perspective from resources.
 * @param checkFactory factory to create a check.
 */
public ApexSquidSensor(FileSystem fileSystem, ResourcePerspectives perspectives, CheckFactory checkFactory) {
    this.checks = checkFactory
            .<SquidAstVisitor<Grammar>>create(CheckList.REPOSITORY_KEY)
            .addAnnotatedChecks(CheckList.getChecks());
    this.fileSystem = fileSystem;
    this.resourcePerspectives = perspectives;

    FilePredicates predicates = fileSystem.predicates();
    filePredicate = predicates.and(
            predicates.hasType(InputFile.Type.MAIN),
            predicates.hasLanguage(Apex.KEY));
}
 
Example 18
Source Project: enforce-sonarqube-plugin   Source File: ApexSquidSensor.java    License: MIT License 5 votes vote down vote up
/**
 * Analyzes files for a given project.
 *
 * @param project current project.
 * @param context sensor context.
 */
@Override
public void analyse(Project project, SensorContext context) {
    this.context = context;

    List<SquidAstVisitor<Grammar>> visitors = Lists.newArrayList(checks.all());
    scanner = ApexAstScanner.create(createConfiguration(),
            visitors.toArray(new SquidAstVisitor[visitors.size()]));
    scanner.scanFiles(Lists.newArrayList(fileSystem.files(filePredicate)));

    Collection<SourceCode> squidSourceFiles = scanner.getIndex()
            .search(new QueryByType(SourceFile.class));
    save(squidSourceFiles);
}
 
Example 19
private static void setMetrics(Builder<Grammar> builder,
    List<SquidAstVisitor<Grammar>> visitors) {
  builder.withMetrics(FlowMetric.values());
  builder.setFilesMetric(FlowMetric.FILES);
  for (SquidAstVisitor<Grammar> v : visitors) {
    builder.withSquidAstVisitor(v);
  }
}
 
Example 20
/**
 * Helper method for testing checks without having to deploy them on a Sonar instance.
 */
public static SourceFile scanSingleFile(File file, List<FlowCheck> flowChecks,
    List<SquidAstVisitor<Grammar>> metrics) {
  if (!file.isFile()) {
    throw new IllegalArgumentException("File '" + file + "' not found.");
  }

  AstScanner<Grammar> scanner = create(new FlowConfiguration(Charsets.UTF_8), flowChecks,
      metrics);
  scanner.scanFile(file);
  Collection<SourceCode> sources = scanner.getIndex().search(new QueryByType(SourceFile.class));
  if (sources.size() != 1) {
    throw new IllegalStateException(
        "Only one SourceFile was expected whereas " + sources.size() + " has been returned.");
  }
  for (SourceCode squidSourceFile : sources) {
    logger.debug("+++Checking Dependencies +++");
    @SuppressWarnings("unchecked")
    ArrayList<String> dependencies = (ArrayList<String>) squidSourceFile
        .getData(FlowMetric.DEPENDENCIES);
    if (dependencies != null) {
      for (String dependency : dependencies) {
        logger.debug("+++Dependency: " + dependency);
      }
    }
  }
  return (SourceFile) sources.iterator().next();
}
 
Example 21
private static void setMetrics(Builder<Grammar> builder,
    List<SquidAstVisitor<Grammar>> visitors) {
  builder.withMetrics(FlowMetric.values());
  builder.setFilesMetric(FlowMetric.FILES);
  for (SquidAstVisitor<Grammar> v : visitors) {
    builder.withSquidAstVisitor(v);
  }
}
 
Example 22
/**
 * This static method returns the list of available flow visitors.
 * @return List of available flow visitors
 */
public static List<SquidAstVisitor<Grammar>> getFlowVisitors() {
  return ImmutableList.<SquidAstVisitor<Grammar>>builder()
      .addAll(getDefaultFlowVisitors())
      .add(new FlowLinesOfCodeVisitor<Grammar>(FlowMetric.LINES_OF_CODE))
      .add(new FlowCommentLinesVisitor<Grammar>(FlowMetric.COMMENT_LINES))
      .add(new FlowDependencyVisitor<Grammar>()).build();
}
 
Example 23
/**
 * This static method returns the list of the required default flow visitors.
 * @return List of available required default flow visitors
 */
public static List<SquidAstVisitor<Grammar>> getDefaultFlowVisitors() {
  return ImmutableList.<SquidAstVisitor<Grammar>>builder()
      .add(ComplexityVisitor.<Grammar>builder().setMetricDef(FlowMetric.COMPLEXITY)
          .subscribeTo(complexityAstNodeType).build())
      .add(new LinesVisitor<Grammar>(FlowMetric.LINES)).build();
}
 
Example 24
/**
 * This static method returns the list of the required default node visitors.
 * @return List of available required default node visitors
 */
public static List<SquidAstVisitor<Grammar>> getDefaultNodeVisitors() {
  return ImmutableList.<SquidAstVisitor<Grammar>>builder()
      .add(ComplexityVisitor.<Grammar>builder().setMetricDef(FlowMetric.COMPLEXITY)
          .subscribeTo(complexityAstNodeType).build())
      .add(new LinesVisitor<Grammar>(FlowMetric.LINES)).build();
}
 
Example 25
@Test
public void gitFolderTest() {
  logger.debug("Scanning file");
  List<SquidAstVisitor<Grammar>> metrics = new ArrayList<SquidAstVisitor<Grammar>>();
  metrics.add(new SimpleMetricVisitor());
  List<FlowCheck> checks = new ArrayList<FlowCheck>();
  FlowAstScanner.scanSingleFile(new File("src/test/resources/WmTestPackage/.gitx/someFile"), checks,
      metrics);

}
 
Example 26
@Test
public void scanFile() {
  logger.debug("Scanning file");
  List<SquidAstVisitor<Grammar>> metrics = new ArrayList<SquidAstVisitor<Grammar>>();
  metrics.add(new SimpleMetricVisitor());
  List<FlowCheck> checks = new ArrayList<FlowCheck>();
  NodeAstScanner.scanSingleFile(nodeFile, checks, metrics);
}
 
Example 27
@Test
public void branchPropertiesCheckValid() {
  List<SquidAstVisitor<Grammar>> metrics = new ArrayList<SquidAstVisitor<Grammar>>();
  metrics.add(new SimpleMetricVisitor());
  List<FlowCheck> checks = new ArrayList<FlowCheck>();
  checks.add(new BranchPropertiesCheck());

  // Check correct flow
  SourceFile sfCorrect = FlowAstScanner
      .scanSingleFile(new File("src/test/resources/WmTestPackage/ns/I8cFlowSonarPluginTest"
          + "/pub/checkBranchPropertiesValid/flow.xml"), checks, metrics);
  Set<CheckMessage> scmCorrect = sfCorrect.getCheckMessages();
  assertEquals(0, scmCorrect.size());
}
 
Example 28
@Test
public void tryCatchCheckValid() {
  List<SquidAstVisitor<Grammar>> metrics = new ArrayList<SquidAstVisitor<Grammar>>();
  metrics.add(new SimpleMetricVisitor());
  List<FlowCheck> checks = new ArrayList<FlowCheck>();
  checks.add(new TryCatchCheck());

  // check valid flow
  String validFlowPath 
      = "src/test/resources/WmTestPackage/ns/I8cFlowSonarPluginTest/pub/checkTryCatchValid/flow.xml";
  SourceFile sfCorrect = FlowAstScanner.scanSingleFile(new File(validFlowPath), checks, metrics);
  Set<CheckMessage> scmCorrect = sfCorrect.getCheckMessages();
  assertEquals(0, scmCorrect.size());

}
 
Example 29
@Test
public void interfaceCommentsCheckInvalid() {
  List<SquidAstVisitor<Grammar>> metrics = new ArrayList<SquidAstVisitor<Grammar>>();
  metrics.add(new SimpleMetricVisitor());
  List<FlowCheck> checks = new ArrayList<FlowCheck>();
  checks.add(new InterfaceCommentsCheck());

  String invalidPath = "src/test/resources/WmTestPackage/ns/I8cFlowSonarPluginTest"
      + "/pub/checkInterfaceCommentsInvalid/node.ndf";

  SourceFile sfCorrect = NodeAstScanner.scanSingleFile(new File(invalidPath), checks, metrics);
  Set<CheckMessage> scmCorrect = sfCorrect.getCheckMessages();
  assertEquals(2, scmCorrect.size());
}
 
Example 30
@Test
public void interfaceCommentsCheckInvalid2() {
  List<SquidAstVisitor<Grammar>> metrics = new ArrayList<SquidAstVisitor<Grammar>>();
  metrics.add(new SimpleMetricVisitor());
  List<FlowCheck> checks = new ArrayList<FlowCheck>();
  checks.add(new InterfaceCommentsCheck());

  String invalidPath = "src/test/resources/WmTestPackage/ns/I8cFlowSonarPluginTest"
      + "/pub/checkInterfaceCommentsInvalid2/node.ndf";

  SourceFile sfCorrect = NodeAstScanner.scanSingleFile(new File(invalidPath), checks, metrics);
  Set<CheckMessage> scmCorrect = sfCorrect.getCheckMessages();
  assertEquals(4, scmCorrect.size());
}