Java Code Examples for org.sonar.squidbridge.AstScanner#scanFile()

The following examples show how to use org.sonar.squidbridge.AstScanner#scanFile() . 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: NodeAstScanner.java    From sonar-flow-plugin with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 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 2
Source File: FlowAstScanner.java    From sonar-flow-plugin with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 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 3
Source File: LuaAstScanner.java    From sonar-lua with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Helper method for testing checks without having to deploy them on a Sonar instance.
 */
public static SourceFile scanSingleFile(File file, SquidAstVisitor<LexerlessGrammar>... visitors) {
  if (!file.isFile()) {
    throw new IllegalArgumentException("File '" + file + "' not found.");
  }

  AstScanner<LexerlessGrammar> scanner = create(new LuaConfiguration(Charsets.UTF_8), Arrays.asList(visitors));
  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();
}