From 1ab08ad4abff024bdd3fbeb6f08a1a4a61c49b65 Mon Sep 17 00:00:00 2001 From: Michal Kordas Date: Sun, 16 Aug 2015 03:24:08 +0200 Subject: [PATCH] Make methods static. #1555 Fixes `MethodMayBeStatic` inspection violations. Description: >Reports any methods which may safely be made static. A method may be static if it is not synchronized, it does not reference any of its class' non static methods and non static fields and is not overridden in a sub class. --- .../google/checkstyle/test/base/ConfigurationBuilder.java | 2 +- .../tools/checkstyle/ConfigurationLoaderTest.java | 8 ++++---- .../tools/checkstyle/PackageNamesLoaderTest.java | 2 +- .../puppycrawl/tools/checkstyle/api/DetailASTTest.java | 4 ++-- .../puppycrawl/tools/checkstyle/api/FullIdentTest.java | 2 +- .../checkstyle/checks/UniquePropertiesCheckTest.java | 2 +- .../checks/whitespace/FileTabCharacterCheckTest.java | 2 +- .../checkstyle/comments/CompareTreesWithComments.java | 2 +- .../checkstyle/filters/SuppressWarningsFilterTest.java | 2 +- .../filters/SuppressWithNearbyCommentFilterTest.java | 2 +- .../checkstyle/filters/SuppressionCommentFilterTest.java | 2 +- 11 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/it/java/com/google/checkstyle/test/base/ConfigurationBuilder.java b/src/it/java/com/google/checkstyle/test/base/ConfigurationBuilder.java index e2b68fd32..3d7c4b57b 100644 --- a/src/it/java/com/google/checkstyle/test/base/ConfigurationBuilder.java +++ b/src/it/java/com/google/checkstyle/test/base/ConfigurationBuilder.java @@ -37,7 +37,7 @@ public class ConfigurationBuilder extends BaseCheckTestSupport { listFiles(files, ROOT, "java"); } - private Configuration getConfigurationFromXML(String aConfigName, + private static Configuration getConfigurationFromXML(String aConfigName, Properties aProps) throws CheckstyleException { try { return ConfigurationLoader.loadConfiguration(aConfigName, diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/ConfigurationLoaderTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/ConfigurationLoaderTest.java index 379552172..90d10ef13 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/ConfigurationLoaderTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/ConfigurationLoaderTest.java @@ -51,12 +51,12 @@ import com.puppycrawl.tools.checkstyle.api.Configuration; @PrepareForTest({ ConfigurationLoader.class, ConfigurationLoaderTest.class }) public class ConfigurationLoaderTest { - private Configuration loadConfiguration(String name) + private static Configuration loadConfiguration(String name) throws CheckstyleException { return loadConfiguration(name, new Properties()); } - private Configuration loadConfiguration( + private static Configuration loadConfiguration( String name, Properties props) throws CheckstyleException { final String fName = "src/test/resources/com/puppycrawl/tools/checkstyle/configs/" + name; @@ -213,7 +213,7 @@ public class ConfigurationLoaderTest { .containsKey("name.invalidPattern")); } - private void verifyConfigNode( + private static void verifyConfigNode( DefaultConfiguration config, String name, int childrenLength, Properties atts) throws Exception { assertEquals("name.", name, config.getName()); @@ -298,7 +298,7 @@ public class ConfigurationLoaderTest { } } - private Properties initProperties() { + private static Properties initProperties() { final Properties props = new Properties(); props.put("a", "A"); props.put("b", "B"); diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/PackageNamesLoaderTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/PackageNamesLoaderTest.java index fd202777b..3afa734d1 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/PackageNamesLoaderTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/PackageNamesLoaderTest.java @@ -61,7 +61,7 @@ public class PackageNamesLoaderTest { validatePackageNames(packageNames); } - private void validatePackageNames(Set pkgNames) { + private static void validatePackageNames(Set pkgNames) { final String[] checkstylePackages = { "com.puppycrawl.tools.checkstyle.", "com.puppycrawl.tools.checkstyle.checks.", diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/api/DetailASTTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/api/DetailASTTest.java index 919267856..fd4c23ea0 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/api/DetailASTTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/api/DetailASTTest.java @@ -129,7 +129,7 @@ public class DetailASTTest { } } - private void checkFile(String filename) throws Exception { + private static void checkFile(String filename) throws Exception { final FileText text = new FileText(new File(filename), System.getProperty("file.encoding", "UTF-8")); final FileContents contents = new FileContents(text); @@ -139,7 +139,7 @@ public class DetailASTTest { } } - private void checkTree(final DetailAST node, + private static void checkTree(final DetailAST node, final DetailAST parent, final DetailAST prev, final String filename, diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/api/FullIdentTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/api/FullIdentTest.java index df0070721..e700bb25a 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/api/FullIdentTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/api/FullIdentTest.java @@ -24,7 +24,7 @@ import org.junit.Test; public class FullIdentTest { - public void testToString() { + public static void testToString() { DetailAST ast = new DetailAST(); ast.setType(TokenTypes.LITERAL_NEW); ast.setColumnNo(14); diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/UniquePropertiesCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/UniquePropertiesCheckTest.java index 18daf6f3b..c5ba3758f 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/UniquePropertiesCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/UniquePropertiesCheckTest.java @@ -114,7 +114,7 @@ public class UniquePropertiesCheckTest extends BaseFileSetCheckTestSupport { * @param file to be opened * @return detail message of {@link FileNotFoundException} */ - private String getFileNotFoundDetail(File file) throws Exception { + private static String getFileNotFoundDetail(File file) throws Exception { // Create exception to know detail message we should wait in // LocalisedMessage try { diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/whitespace/FileTabCharacterCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/whitespace/FileTabCharacterCheckTest.java index f3b00a9b2..b8e607b4e 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/whitespace/FileTabCharacterCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/whitespace/FileTabCharacterCheckTest.java @@ -96,7 +96,7 @@ public class FileTabCharacterCheckTest * Creates a configuration that is functionally close to that in the docs. * @param verbose verbose mode */ - private DefaultConfiguration createConfig(boolean verbose) { + private static DefaultConfiguration createConfig(boolean verbose) { final DefaultConfiguration checkConfig = createCheckConfig(FileTabCharacterCheck.class); checkConfig.addAttribute("eachLine", Boolean.toString(verbose)); diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/comments/CompareTreesWithComments.java b/src/test/java/com/puppycrawl/tools/checkstyle/comments/CompareTreesWithComments.java index 7d72aefb9..30345e8eb 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/comments/CompareTreesWithComments.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/comments/CompareTreesWithComments.java @@ -23,7 +23,7 @@ public class CompareTreesWithComments extends Check { Assert.assertTrue(isAstEquals(expectedTree, aRootAST)); } - private boolean isAstEquals(DetailAST expected, DetailAST actual) { + private static boolean isAstEquals(DetailAST expected, DetailAST actual) { boolean result = false; if (expected == actual) { result = true; diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/filters/SuppressWarningsFilterTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/filters/SuppressWarningsFilterTest.java index 64a1bda7a..0fcd68157 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/filters/SuppressWarningsFilterTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/filters/SuppressWarningsFilterTest.java @@ -116,7 +116,7 @@ public class SuppressWarningsFilterTest return checker; } - private String[] removeSuppressed(String[] from, String[] remove) { + private static String[] removeSuppressed(String[] from, String[] remove) { final Collection coll = Lists.newArrayList(Arrays.asList(from)); coll.removeAll(Arrays.asList(remove)); diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/filters/SuppressWithNearbyCommentFilterTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/filters/SuppressWithNearbyCommentFilterTest.java index b3ba9a62b..59436f2ad 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/filters/SuppressWithNearbyCommentFilterTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/filters/SuppressWithNearbyCommentFilterTest.java @@ -227,7 +227,7 @@ public class SuppressWithNearbyCommentFilterTest return checker; } - private String[] removeSuppressed(String[] from, String[] remove) { + private static String[] removeSuppressed(String[] from, String[] remove) { final Collection coll = Lists.newArrayList(Arrays.asList(from)); coll.removeAll(Arrays.asList(remove)); diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/filters/SuppressionCommentFilterTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/filters/SuppressionCommentFilterTest.java index 030343e55..f5046357d 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/filters/SuppressionCommentFilterTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/filters/SuppressionCommentFilterTest.java @@ -227,7 +227,7 @@ public class SuppressionCommentFilterTest return checker; } - private String[] removeSuppressed(String[] from, String[] remove) { + private static String[] removeSuppressed(String[] from, String[] remove) { final Collection coll = Lists.newArrayList(Arrays.asList(from)); coll.removeAll(Arrays.asList(remove));