/** * Sets cache file. * @param fileName the cache file. * @throws IOException if there are some problems with file loading. */ public void setCacheFile(String fileName) throws IOException { final Configuration configuration = getConfiguration(); cacheFile = new PropertyCacheFile(configuration, fileName); cacheFile.load(); }
/** * Prints full AST (java + comments + javadoc) of the java file. * @param file java file * @return Full tree * @throws IOException Failed to open a file * @throws CheckstyleException error while parsing the file */ public static String printJavaAndJavadocTree(File file) throws IOException, CheckstyleException { final DetailAST tree = JavaParser.parseFile(file, JavaParser.Options.WITH_COMMENTS); return printJavaAndJavadocTree(tree); }
/** * Parse a file and print the parse tree. * @param file the file to print. * @param options {@link JavaParser.Options} to control the inclusion of comment nodes. * @return the AST of the file in String form. * @throws IOException if the file could not be read. * @throws CheckstyleException if the file is not a Java source. */ public static String printFileAst(File file, JavaParser.Options options) throws IOException, CheckstyleException { return printTree(JavaParser.parseFile(file, options)); }
private Configuration loadConfiguration( String name, Properties props) throws Exception { final String fName = getPath(name); return ConfigurationLoader.loadConfiguration(fName, new PropertiesExpander(props)); }
@Test public void testConfigCheckerWithIgnore() throws Exception { final DefaultConfiguration config = (DefaultConfiguration) ConfigurationLoader.loadConfiguration( getPath("InputConfigurationLoaderCheckerIgnoreSeverity.xml"), new PropertiesExpander(new Properties()), true); final Configuration[] children = config.getChildren(); assertEquals("Invalid children count", 0, children.length); }
public static Configuration loadConfiguration(String path, Properties props) throws CheckstyleException { return ConfigurationLoader.loadConfiguration(path, new PropertiesExpander(props)); }
/** * Returns the module configurations in a specified file. * @param config location of config file, can be either a URL or a filename * @param overridePropsResolver overriding properties * @return the check configurations * @throws CheckstyleException if an error occurs */ public static Configuration loadConfiguration(String config, PropertyResolver overridePropsResolver) throws CheckstyleException { return loadConfiguration(config, overridePropsResolver, IgnoredModulesOptions.EXECUTE); }
/** * Parse block comment DetailAST as Javadoc DetailNode tree. * @param blockComment DetailAST * @return DetailNode tree */ public static DetailNode parseJavadocAsDetailNode(DetailAST blockComment) { final JavadocDetailNodeParser parser = new JavadocDetailNodeParser(); final ParseStatus status = parser.parseJavadocAsDetailNode(blockComment); if (status.getParseErrorMessage() != null) { throw new IllegalArgumentException(getParseErrorMessage(status.getParseErrorMessage())); } return status.getTree(); }
@Override public void finishLocalSetup() { final DefaultContext checkContext = new DefaultContext(); checkContext.add("classLoader", classLoader); checkContext.add("severity", getSeverity()); checkContext.add("tabWidth", String.valueOf(tabWidth)); childContext = checkContext; }
/** * Returns the default PackageObjectFactory with the default package names. * @return the default PackageObjectFactory. */ public static PackageObjectFactory getPackageObjectFactory() throws CheckstyleException { final ClassLoader cl = TestUtil.class.getClassLoader(); final Set<String> packageNames = PackageNamesLoader.getPackageNames(cl); return new PackageObjectFactory(packageNames, cl); }
/** * Puts external resources in cache. * If at least one external resource changed, clears the cache. * @param locations locations of external resources. */ public void putExternalResources(Set<String> locations) { final Set<ExternalResource> resources = loadExternalResources(locations); if (areExternalResourcesChanged(resources)) { reset(); fillCacheWithExternalResources(resources); } }
/** * Creates {@link DefaultConfiguration} for the given {@link Configuration} instance. * @param config {@link Configuration} instance. * @return {@link DefaultConfiguration} for the given {@link Configuration} instance. */ protected static DefaultConfiguration createRootConfig(Configuration config) { final DefaultConfiguration dc = new DefaultConfiguration(ROOT_MODULE_NAME); if (config != null) { dc.addChild(config); } return dc; }
/** * Initiates the walk of an AST. * @param ast the root AST * @param contents the contents of the file the AST was generated from. * @param astState state of AST. */ private void walk(DetailAST ast, FileContents contents, AstState astState) { notifyBegin(ast, contents, astState); processIter(ast, astState); notifyEnd(ast, astState); }
/** * Parse a file and print the parse tree. * @param text the text to parse. * @param options {@link JavaParser.Options} to control the inclusion of comment nodes. * @return the AST of the file in String form. * @throws CheckstyleException if the file is not a Java source. */ public static String printAst(FileText text, JavaParser.Options options) throws CheckstyleException { final DetailAST ast = JavaParser.parseFileText(text, options); return printTree(ast); }
/** * Clears the cache. */ public void clearCache() { if (cacheFile != null) { cacheFile.reset(); } }
@Override public boolean accept(TreeWalkerAuditEvent treeWalkerAuditEvent) { boolean result = true; for (TreeWalkerFilter filter : filters) { if (!filter.accept(treeWalkerAuditEvent)) { result = false; break; } } return result; }
/** * Gets the check message 'as is' from appropriate 'messages.properties' * file. * * @param messageKey the key of message in 'messages.properties' file. * @param arguments the arguments of message in 'messages.properties' file. * @return The message of the check with the arguments applied. */ protected final String getCheckMessage(String messageKey, Object... arguments) { return internalGetCheckMessage(getMessageBundle(), messageKey, arguments); }
/** * Creates a new {@code PackageNamesLoader} instance. * @throws ParserConfigurationException if an error occurs * @throws SAXException if an error occurs */ private PackageNamesLoader() throws ParserConfigurationException, SAXException { super(createIdToResourceNameMap()); }
/** * Creates a new {@code TreeWalker} instance. */ public TreeWalker() { setFileExtensions("java"); }