/** * Helper method for testing checks without having to deploy them on a Sonar instance. */ public static SourceFile scanSingleFile(File file, SquidAstVisitor<SwiftGrammar>... visitors) { if (!file.isFile()) { throw new IllegalArgumentException("File '" + file + "' not found."); } AstScanner<SwiftGrammar> scanner = create(new SwiftConfiguration(), 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(); }
/** * Helper method for testing checks without having to deploy them on a Sonar instance. */ public static SourceFile scanSingleFile(File file, CSharpConfiguration conf, SquidAstVisitor<Grammar>... visitors) { if (!file.isFile()) { throw new IllegalArgumentException("File '" + file + "' not found."); } AstScanner<Grammar> scanner = create(conf, 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(); }
/** * Helper method for testing checks without having to deploy them on a Sonar instance. */ public static SourceFile scanSingleFile(File file, SquidAstVisitor<ObjectiveCGrammar>... visitors) { if (!file.isFile()) { throw new IllegalArgumentException("File '" + file + "' not found."); } AstScanner<ObjectiveCGrammar> scanner = create(new ObjectiveCConfiguration(), 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(); }
/** * Helper method for testing checks without having to deploy them on a Sonar instance. */ public static SourceFile scanSingleFile(File file, SquidAstVisitor<ObjectiveCGrammar>... visitors) { if (!file.isFile()) { throw new IllegalArgumentException("File '" + file + "' not found."); } AstScanner<ObjectiveCGrammar> scanner = create(new ObjectiveCConfiguration(), 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(); }
/** * Helper method for testing checks without having to deploy them on a Sonar instance. */ public static SourceFile scanSingleFile(File file, SquidAstVisitor<Grammar>... visitors) { if (!file.isFile()) { throw new IllegalArgumentException("File '" + file + "' not found."); } AstScanner<Grammar> scanner = create(new PythonConfiguration(Charsets.UTF_8), 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(); }
/** * 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 scanner = create(new CssConfiguration(Charsets.UTF_8), null, 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(); }
/** * 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 EcmaScriptConfiguration(Charsets.UTF_8), 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(); }
/** * 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 FlexConfiguration(Charsets.UTF_8), 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(); }
/** * Returns a source file from file and visitors. * * @param file source file. * @param visitors list of visitors. * @return a source. * @exception IllegalArgumentException when file is not found. * @exception IllegalStateException when there is more than one sourceFile. */ public static SourceFile scanFile(File file, SquidAstVisitor<Grammar>... visitors) { if (!file.isFile()) { throw new IllegalArgumentException(String.format(FILE_NOT_FOUND, file)); } AstScanner<Grammar> scanner = create(new ApexConfiguration(Charsets.UTF_8), visitors); scanner.scanFile(file); Collection<SourceCode> sources = scanner.getIndex().search(new QueryByType(SourceFile.class)); if (sources.size() != 1) { throw new IllegalStateException(String.format(ONE_SOURCE_FILE, sources.size())); } return (SourceFile) sources.iterator().next(); }