Java Code Examples for com.puppycrawl.tools.checkstyle.DefaultConfiguration#addAttribute()
The following examples show how to use
com.puppycrawl.tools.checkstyle.DefaultConfiguration#addAttribute() .
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: UnusedPrivateMethodCheckTest.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
public void testAllowSerializationMethods() throws Exception { final DefaultConfiguration checkConfig = createCheckConfig(UnusedPrivateMethodCheck.class); checkConfig.addAttribute("allowSerializationMethods", "true"); final String[] expected = { "7:18: Unused private method 'methodUnused0'.", "91:18: Unused private method 'writeObject'.", "95:18: Unused private method 'writeObject'.", "99:18: Unused private method 'writeObject'.", "103:18: Unused private method 'readObject'.", "107:18: Unused private method 'readObject'.", "111:17: Unused private method 'writeReplace'.", "116:20: Unused private method 'writeReplace'.", "121:17: Unused private method 'readResolve'.", "126:20: Unused private method 'readResolve'.", "134:17: Unused private method 'writeObject'.", "139:18: Unused private method 'readObject'.", "143:20: Unused private method 'readResolve'.", "151:17: Unused private method 'readObject'.", }; verify(checkConfig, getPath("usage/InputUnusedMethod.java"), expected); }
Example 2
Source File: OneMethodPrivateFieldCheckTest.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
public void testIgnoreFormat() throws Exception { final DefaultConfiguration checkConfig = createCheckConfig(OneMethodPrivateFieldCheck.class); checkConfig.addAttribute("ignoreFormat", "2$"); final String[] expected = { "6:24: Field 'SFIELD0' is used in only one method.", "7:24: Field 'SFIELD1' is used in only one method.", "9:24: Field 'SFIELD3' is used in only one method.", "11:17: Field 'mField0' is used in only one method.", "12:17: Field 'mField1' is used in only one method.", "47:17: Field 'mField0' is used in only one method.", "48:17: Field 'mField1' is used in only one method.", "105:19: Field 'mField' is used in only one method.", }; verify(checkConfig, getPath("usage/InputOneMethodPrivateField.java"), expected); }
Example 3
Source File: UnusedPrivateMethodCheckTest.java From contribution with GNU Lesser General Public License v2.1 | 6 votes |
public void testAllowSerializationMethods() throws Exception { final DefaultConfiguration checkConfig = createCheckConfig(UnusedPrivateMethodCheck.class); checkConfig.addAttribute("allowSerializationMethods", "true"); final String[] expected = { "7:18: Unused private method 'methodUnused0'.", "91:18: Unused private method 'writeObject'.", "95:18: Unused private method 'writeObject'.", "99:18: Unused private method 'writeObject'.", "103:18: Unused private method 'readObject'.", "107:18: Unused private method 'readObject'.", "111:17: Unused private method 'writeReplace'.", "116:20: Unused private method 'writeReplace'.", "121:17: Unused private method 'readResolve'.", "126:20: Unused private method 'readResolve'.", "134:17: Unused private method 'writeObject'.", "139:18: Unused private method 'readObject'.", "143:20: Unused private method 'readResolve'.", "151:17: Unused private method 'readObject'.", }; verify(checkConfig, getPath("usage/InputUnusedMethod.java"), expected); }
Example 4
Source File: OneMethodPrivateFieldCheckTest.java From contribution with GNU Lesser General Public License v2.1 | 6 votes |
public void testIgnoreFormat() throws Exception { final DefaultConfiguration checkConfig = createCheckConfig(OneMethodPrivateFieldCheck.class); checkConfig.addAttribute("ignoreFormat", "2$"); final String[] expected = { "6:24: Field 'SFIELD0' is used in only one method.", "7:24: Field 'SFIELD1' is used in only one method.", "9:24: Field 'SFIELD3' is used in only one method.", "11:17: Field 'mField0' is used in only one method.", "12:17: Field 'mField1' is used in only one method.", "47:17: Field 'mField0' is used in only one method.", "48:17: Field 'mField1' is used in only one method.", "105:19: Field 'mField' is used in only one method.", }; verify(checkConfig, getPath("usage/InputOneMethodPrivateField.java"), expected); }
Example 5
Source File: UnusedLocalVariableCheckTest.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
public void testIgnoreFormat() throws Exception { final DefaultConfiguration checkConfig = createCheckConfig(UnusedLocalVariableCheck.class); checkConfig.addAttribute("ignoreFormat", "Array$"); final String[] expected = { "13:13: Unused local variable 'mUnreadPrimitive'.", "24:16: Unused local variable 'unreadObject'.", "45:13: Unused local variable 'java'.", }; verify(checkConfig, getPath("usage/InputUnusedLocal.java"), expected); }
Example 6
Source File: UnusedPrivateFieldCheckTest.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
public void testIgnoreFormat() throws Exception { final DefaultConfiguration checkConfig = createCheckConfig(UnusedPrivateFieldCheck.class); checkConfig.addAttribute("ignoreFormat", "Array$"); final String[] expected = { "10:17: Unused private field 'mUnreadPrimitive'.", "20:17: Unused private field 'mUnused2'.", "22:30: Unused private field 'SUNUSED'.", "64:17: Unused private field 'mUnused'.", }; verify(checkConfig, getPath("usage/InputUnusedField.java"), expected); }
Example 7
Source File: UnusedParameterCheckTest.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
public void testException() throws Exception { final DefaultConfiguration checkConfig = createCheckConfig(UnusedParameterCheck.class); checkConfig.addAttribute("ignoreCatch", Boolean.FALSE.toString()); final String[] expected = { "8:57: Unused parameter 'aUnreadPrimitive'.", "16:16: Unused parameter 'aUnreadObject'.", "25:26: Unused parameter 'unreadException'.", "29:66: Unused parameter 'aUnreadArray'.", }; verify(checkConfig, getPath("usage/InputUnusedParameter.java"), expected); }
Example 8
Source File: UnusedParameterCheckTest.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
public void testIgnoreFormat() throws Exception { final DefaultConfiguration checkConfig = createCheckConfig(UnusedParameterCheck.class); checkConfig.addAttribute("ignoreFormat", "Array$"); final String[] expected = { "8:57: Unused parameter 'aUnreadPrimitive'.", "16:16: Unused parameter 'aUnreadObject'.", }; verify(checkConfig, getPath("usage/InputUnusedParameter.java"), expected); }
Example 9
Source File: UnusedParameterCheckTest.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
public void testIgnoreNonLocal() throws Exception { final DefaultConfiguration checkConfig = createCheckConfig(UnusedParameterCheck.class); checkConfig.addAttribute("ignoreNonLocal", "true"); final String[] expected = { "8:57: Unused parameter 'aUnreadPrimitive'.", "29:66: Unused parameter 'aUnreadArray'.", }; verify(checkConfig, getPath("usage/InputUnusedParameter.java"), expected); }
Example 10
Source File: UnusedLocalVariableCheckTest.java From contribution with GNU Lesser General Public License v2.1 | 5 votes |
public void testIgnoreFormat() throws Exception { final DefaultConfiguration checkConfig = createCheckConfig(UnusedLocalVariableCheck.class); checkConfig.addAttribute("ignoreFormat", "Array$"); final String[] expected = { "13:13: Unused local variable 'mUnreadPrimitive'.", "24:16: Unused local variable 'unreadObject'.", "45:13: Unused local variable 'java'.", }; verify(checkConfig, getPath("usage/InputUnusedLocal.java"), expected); }
Example 11
Source File: UnusedPrivateFieldCheckTest.java From contribution with GNU Lesser General Public License v2.1 | 5 votes |
public void testIgnoreFormat() throws Exception { final DefaultConfiguration checkConfig = createCheckConfig(UnusedPrivateFieldCheck.class); checkConfig.addAttribute("ignoreFormat", "Array$"); final String[] expected = { "10:17: Unused private field 'mUnreadPrimitive'.", "20:17: Unused private field 'mUnused2'.", "22:30: Unused private field 'SUNUSED'.", "64:17: Unused private field 'mUnused'.", }; verify(checkConfig, getPath("usage/InputUnusedField.java"), expected); }
Example 12
Source File: UnusedParameterCheckTest.java From contribution with GNU Lesser General Public License v2.1 | 5 votes |
public void testException() throws Exception { final DefaultConfiguration checkConfig = createCheckConfig(UnusedParameterCheck.class); checkConfig.addAttribute("ignoreCatch", Boolean.FALSE.toString()); final String[] expected = { "8:57: Unused parameter 'aUnreadPrimitive'.", "16:16: Unused parameter 'aUnreadObject'.", "25:26: Unused parameter 'unreadException'.", "29:66: Unused parameter 'aUnreadArray'.", }; verify(checkConfig, getPath("usage/InputUnusedParameter.java"), expected); }
Example 13
Source File: UnusedParameterCheckTest.java From contribution with GNU Lesser General Public License v2.1 | 5 votes |
public void testIgnoreFormat() throws Exception { final DefaultConfiguration checkConfig = createCheckConfig(UnusedParameterCheck.class); checkConfig.addAttribute("ignoreFormat", "Array$"); final String[] expected = { "8:57: Unused parameter 'aUnreadPrimitive'.", "16:16: Unused parameter 'aUnreadObject'.", }; verify(checkConfig, getPath("usage/InputUnusedParameter.java"), expected); }
Example 14
Source File: UnusedParameterCheckTest.java From contribution with GNU Lesser General Public License v2.1 | 5 votes |
public void testIgnoreNonLocal() throws Exception { final DefaultConfiguration checkConfig = createCheckConfig(UnusedParameterCheck.class); checkConfig.addAttribute("ignoreNonLocal", "true"); final String[] expected = { "8:57: Unused parameter 'aUnreadPrimitive'.", "29:66: Unused parameter 'aUnreadArray'.", }; verify(checkConfig, getPath("usage/InputUnusedParameter.java"), expected); }
Example 15
Source File: Main.java From diff-check with GNU Lesser General Public License v2.1 | 4 votes |
/** * Executes required Checkstyle actions based on passed parameters. * @param cliOptions * pojo object that contains all options * @return number of violations of ERROR level * @throws IOException * when output file could not be found * @throws CheckstyleException * when properties file could not be loaded */ private static int runCheckstyle(CliOptions cliOptions) throws CheckstyleException, IOException { // setup the properties final Properties props; if (cliOptions.propertiesLocation == null) { props = System.getProperties(); } else { props = loadProperties(new File(cliOptions.propertiesLocation)); } // create a configuration final ThreadModeSettings multiThreadModeSettings = new ThreadModeSettings( cliOptions.checkerThreadsNumber, cliOptions.treeWalkerThreadsNumber); final ConfigurationLoader.IgnoredModulesOptions ignoredModulesOptions; if (cliOptions.executeIgnoredModules) { ignoredModulesOptions = ConfigurationLoader.IgnoredModulesOptions.EXECUTE; } else { ignoredModulesOptions = ConfigurationLoader.IgnoredModulesOptions.OMIT; } final Configuration config = ConfigurationLoader.loadConfiguration( cliOptions.configLocation, new PropertiesExpander(props), ignoredModulesOptions, multiThreadModeSettings); // create RootModule object and run it final int errorCounter; final ClassLoader moduleClassLoader = Checker.class.getClassLoader(); final RootModule rootModule = getRootModule(config.getName(), moduleClassLoader); try { final AuditListener listener; if (cliOptions.generateXpathSuppressionsFile) { // create filter to print generated xpath suppressions file final Configuration treeWalkerConfig = getTreeWalkerConfig(config); if (treeWalkerConfig != null) { final DefaultConfiguration moduleConfig = new DefaultConfiguration( XpathFileGeneratorAstFilter.class.getName()); moduleConfig.addAttribute(OPTION_TAB_WIDTH_NAME, Integer.toString(cliOptions.tabWidth)); ((DefaultConfiguration) treeWalkerConfig).addChild(moduleConfig); } listener = new XpathFileGeneratorAuditListener(System.out, AutomaticBean.OutputStreamOptions.NONE); } else { listener = createListener(cliOptions.format, cliOptions.outputLocation); } rootModule.setModuleClassLoader(moduleClassLoader); rootModule.configure(config); rootModule.addListener(listener); if (CollectionUtils.isNotEmpty(DIFF_ENTRY_LIST) && rootModule instanceof Checker) { Checker checker = (Checker) rootModule; checker.addFilter(new DiffLineFilter(DIFF_ENTRY_LIST)); } // run RootModule errorCounter = rootModule.process(cliOptions.files); } finally { rootModule.destroy(); } return errorCounter; }