From 8a29ca462bcc97753a84235eeb3cbb489768d5db Mon Sep 17 00:00:00 2001 From: Dmytro Kytsmen Date: Tue, 25 Apr 2017 11:46:59 +0300 Subject: Issue #4141: Split and Organize Checkstyle inputs by Test for ConstantName --- .../checks/naming/ConstantNameCheckTest.java | 16 +- .../checks/naming/InputConstantNames.java | 9 - .../naming/InputStaticModifierInInterface.java | 11 - .../naming/constantname/InputConstantName.java | 9 + .../constantname/InputConstantNameInner.java | 79 ++++++++ .../InputConstantNameMemberExtended.java | 83 ++++++++ .../constantname/InputConstantNameSimple.java | 225 +++++++++++++++++++++ ...InputConstantNameStaticModifierInInterface.java | 11 + 8 files changed, 416 insertions(+), 27 deletions(-) delete mode 100644 src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/InputConstantNames.java delete mode 100644 src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/InputStaticModifierInInterface.java create mode 100644 src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/constantname/InputConstantName.java create mode 100644 src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/constantname/InputConstantNameInner.java create mode 100644 src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/constantname/InputConstantNameMemberExtended.java create mode 100644 src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/constantname/InputConstantNameSimple.java create mode 100644 src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/constantname/InputConstantNameStaticModifierInInterface.java (limited to 'src/test') diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/naming/ConstantNameCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/naming/ConstantNameCheckTest.java index 41bad2aae..c3525a8c8 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/naming/ConstantNameCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/naming/ConstantNameCheckTest.java @@ -41,7 +41,9 @@ public class ConstantNameCheckTest @Override protected String getPath(String filename) throws IOException { return super.getPath("checks" + File.separator - + "naming" + File.separator + filename); + + "naming" + File.separator + + "constantname" + File.separator + + filename); } @Override @@ -88,7 +90,7 @@ public class ConstantNameCheckTest "25:29: " + getCheckMessage(MSG_INVALID_PATTERN, "badConstant", pattern), "142:30: " + getCheckMessage(MSG_INVALID_PATTERN, "BAD__NAME", pattern), }; - verify(checkConfig, getPath("InputSimple.java"), expected); + verify(checkConfig, getPath("InputConstantNameSimple.java"), expected); } @Test @@ -105,7 +107,7 @@ public class ConstantNameCheckTest final String[] expected = { "142:30: " + getCheckMessage(MSG_INVALID_PATTERN, "BAD__NAME", pattern), }; - verify(checkConfig, getPath("InputSimple.java"), expected); + verify(checkConfig, getPath("InputConstantNameSimple.java"), expected); } @Test @@ -120,7 +122,7 @@ public class ConstantNameCheckTest "24:16: " + getCheckMessage(MSG_INVALID_PATTERN, "data", pattern), "64:16: " + getCheckMessage(MSG_INVALID_PATTERN, "data", pattern), }; - verify(checkConfig, getPath("InputInner.java"), expected); + verify(checkConfig, getPath("InputConstantNameInner.java"), expected); } @Test @@ -129,7 +131,7 @@ public class ConstantNameCheckTest final DefaultConfiguration checkConfig = createCheckConfig(ConstantNameCheck.class); final String[] expected = CommonUtils.EMPTY_STRING_ARRAY; - verify(checkConfig, getPath("InputConstantNames.java"), expected); + verify(checkConfig, getPath("InputConstantName.java"), expected); } @Test @@ -149,7 +151,7 @@ public class ConstantNameCheckTest "52:9: " + getCheckMessage(MSG_INVALID_PATTERN, "_package", pattern), "53:9: " + getCheckMessage(MSG_INVALID_PATTERN, "_private", pattern), }; - verify(checkConfig, getPath("InputMemberNameExtended.java"), expected); + verify(checkConfig, getPath("InputConstantNameMemberExtended.java"), expected); } @Test @@ -158,7 +160,7 @@ public class ConstantNameCheckTest final DefaultConfiguration checkConfig = createCheckConfig(ConstantNameCheck.class); final String[] expected = CommonUtils.EMPTY_STRING_ARRAY; - verify(checkConfig, getPath("InputStaticModifierInInterface.java"), expected); + verify(checkConfig, getPath("InputConstantNameStaticModifierInInterface.java"), expected); } @Test diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/InputConstantNames.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/InputConstantNames.java deleted file mode 100644 index bfb07917a..000000000 --- a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/InputConstantNames.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.puppycrawl.tools.checkstyle.checks.naming; - -import java.io.ObjectStreamField; - -public class InputConstantNames -{ - private static final long serialVersionUID = 1L; //should be ignored - private static final ObjectStreamField[] serialPersistentFields = {}; // should be ignored too -} diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/InputStaticModifierInInterface.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/InputStaticModifierInInterface.java deleted file mode 100644 index 66a85ff7c..000000000 --- a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/InputStaticModifierInInterface.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.puppycrawl.tools.checkstyle.checks.naming; - - -public interface InputStaticModifierInInterface -{ - static int f() - { - int someName = 5; - return someName; - } -} diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/constantname/InputConstantName.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/constantname/InputConstantName.java new file mode 100644 index 000000000..4fa8ea603 --- /dev/null +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/constantname/InputConstantName.java @@ -0,0 +1,9 @@ +package com.puppycrawl.tools.checkstyle.checks.naming.constantname; + +import java.io.ObjectStreamField; + +public class InputConstantName +{ + private static final long serialVersionUID = 1L; //should be ignored + private static final ObjectStreamField[] serialPersistentFields = {}; // should be ignored too +} diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/constantname/InputConstantNameInner.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/constantname/InputConstantNameInner.java new file mode 100644 index 000000000..09fa19719 --- /dev/null +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/constantname/InputConstantNameInner.java @@ -0,0 +1,79 @@ +//////////////////////////////////////////////////////////////////////////////// +// Test case file for checkstyle. +// Created: 2001 +//////////////////////////////////////////////////////////////////////////////// +package com.puppycrawl.tools.checkstyle.checks.naming.constantname; + +/** + * Tests having inner types + * @author Oliver Burn + **/ +class InputConstantNameInner +{ + // Ignore - two errors + class InnerInner2 + { + // Ignore + public int fData; + } + + // Ignore - 2 errors + interface InnerInterface2 + { + // Ignore - should be all upper case + String data = "zxzc"; + + // Ignore + class InnerInterfaceInnerClass + { + // Ignore - need Javadoc and made private + public int rData; + + /** needs to be made private unless allowProtected. */ + protected int protectedVariable; + + /** needs to be made private unless allowPackage. */ + int packageVariable; + } + } + + /** demonstrate bug in handling static final **/ + protected static Object sWeird = new Object(); + /** demonstrate bug in handling static final **/ + static Object sWeird2 = new Object(); + + /** demonstrate bug in local final variable */ + public interface Inter + { + } + + public static void main() + { + Inter m = new Inter() + { + private static final int CDS = 1; + + private int ABC; + }; + } + + /** annotation field incorrectly named. */ + @interface InnerAnnotation + { + /** Ignore - should be all upper case. */ + String data = "zxzc"; + } + + /** enum with public member variable */ + enum InnerEnum + { + /** First constant */ + A, + + /** Second constant */ + B; + + /** Should be private */ + public int someValue; + } +} diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/constantname/InputConstantNameMemberExtended.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/constantname/InputConstantNameMemberExtended.java new file mode 100644 index 000000000..d54984038 --- /dev/null +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/constantname/InputConstantNameMemberExtended.java @@ -0,0 +1,83 @@ +package com.puppycrawl.tools.checkstyle.checks.naming.constantname; + + + + +public class InputConstantNameMemberExtended +{ + public int mPublic; + protected int mProtected; + int mPackage; + private int mPrivate; + + public int _public; + protected int _protected; + int _package; + private int _private; + + class Inner { + public int mPublic; + protected int mProtected; + int mPackage; + private int mPrivate; + + public int _public; + protected int _protected; + int _package; + private int _private; + } + + Inner anon = new Inner() { + public int mPublic; + protected int mProtected; + int mPackage; + private int mPrivate; + + public int _public; + protected int _protected; + int _package; + private int _private; + }; +} + +interface In +{ + public int mPublic = 0; + int mProtected = 0; + int mPackage = 0; + int mPrivate = 0; + + public int _public = 0; + int _protected = 0; + int _package = 0; + int _private = 0; +} + +enum Direction { + + NORTH(1), + SOUTH(-1), + EAST(-2), + WEST(2); + + public int mPublic = 0; + int mProtected = 0; + int mPackage = 0; + int mPrivate = 0; + + public int _public = 0; + int _protected = 0; + int _package = 0; + int _private = 0; + + Direction(int code){ + this.code=code; + } + protected int code; + public int getCode() { + return this.code; + } + static Direction getOppositeDirection(Direction d){ + return null; + } +} diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/constantname/InputConstantNameSimple.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/constantname/InputConstantNameSimple.java new file mode 100644 index 000000000..6bb66edc8 --- /dev/null +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/constantname/InputConstantNameSimple.java @@ -0,0 +1,225 @@ +//////////////////////////////////////////////////////////////////////////////// +// Test case file for checkstyle. +// Created: Feb-2001 +// Ignore error +//////////////////////////////////////////////////////////////////////////////// +package com.puppycrawl.tools.checkstyle.checks.naming.constantname; +import java.io.*; +/** + * Contains simple mistakes: + * - Long lines + * - Tabs + * - Format of variables and parameters + * - Order of modifiers + * @author Oliver Burn + **/ +final class InputConstantNameSimple +{ + // Long line ---------------------------------------------------------------- + // Contains a tab -> <- + // Contains trailing whitespace -> + + // Name format tests + // + /** Invalid format **/ + public static final int badConstant = 2; + /** Valid format **/ + public static final int MAX_ROWS = 2; + + /** Invalid format **/ + private static int badStatic = 2; + /** Valid format **/ + private static int sNumCreated = 0; + + /** Invalid format **/ + private int badMember = 2; + /** Valid format **/ + private int mNumCreated1 = 0; + /** Valid format **/ + protected int mNumCreated2 = 0; + + /** commas are wrong **/ + private int[] mInts = new int[] {1,2, 3, + 4}; + + // + // Accessor tests + // + /** should be private **/ + public static int sTest1; + /** should be private **/ + protected static int sTest3; + /** should be private **/ + static int sTest2; + + /** should be private **/ + int mTest1; + /** should be private **/ + public int mTest2; + + // + // Parameter name format tests + // + + /** + * @return hack + * @param badFormat1 bad format + * @param badFormat2 bad format + * @param badFormat3 bad format + * @throws java.lang.Exception abc + **/ + int test1(int badFormat1,int badFormat2, + final int badFormat3) + throws java.lang.Exception + { + return 0; + } + + /** method that is 20 lines long **/ + private void longMethod() + { + // a line + // a line + // a line + // a line + // a line + // a line + // a line + // a line + // a line + // a line + // a line + // a line + // a line + // a line + // a line + // a line + // a line + // a line + } + + /** constructor that is 10 lines long **/ + private InputConstantNameSimple() + { + // a line + // a line + // a line + // a line + // a line + // a line + // a line + // a line + } + + /** test local variables */ + private void localVariables() + { + // normal decl + int abc = 0; + int ABC = 0; + + // final decls + final int cde = 0; + final int CDE = 0; + + // decl in for loop init statement + for (int k = 0; k < 1; k++) + { + String innerBlockVariable = ""; + } + for (int I = 0; I < 1; I++) + { + String InnerBlockVariable = ""; + } + } + + /** test method pattern */ + void ALL_UPPERCASE_METHOD() + { + } + + /** test illegal constant **/ + private static final int BAD__NAME = 3; + + // A very, very long line that is OK because it matches the regexp "^.*is OK.*regexp.*$" + // long line that has a tab -> <- and would be OK if tab counted as 1 char + // tabs that count as one char because of their position -> <- -> <-, OK + + /** some lines to test the error column after tabs */ + void errorColumnAfterTabs() + { + // with tab-width 8 all statements below start at the same column, + // with different combinations of ' ' and '\t' before the statement + int tab0 =1; + int tab1 =1; + int tab2 =1; + int tab3 =1; + int tab4 =1; + int tab5 =1; + } + + // FIXME: + /* FIXME: a + * FIXME: + * TODO + */ + /* NOTHING */ + /* YES */ /* FIXME: x */ /* YES!! */ + + /** test long comments **/ + void veryLong() + { + /* + blah blah blah blah + blah blah blah blah + blah blah blah blah + blah blah blah blah + blah blah blah blah + blah blah blah blah + blah blah blah blah + blah blah blah blah + blah blah blah blah + blah blah blah blah + blah blah blah blah + blah blah blah blah + blah blah blah blah + blah blah blah blah + blah blah blah blah + enough talk */ + } + + /** + * @see to lazy to document all args. Testing excessive # args + **/ + void toManyArgs(int aArg1, int aArg2, int aArg3, int aArg4, int aArg5, + int aArg6, int aArg7, int aArg8, int aArg9) + { + } +} + +/** Test class for variable naming in for each clauses. */ +class InputConstantNameSimple2 +{ + /** Some more Javadoc. */ + public void doSomething() + { + //"O" should be named "o" + for (Object O : new java.util.ArrayList()) + { + + } + } +} + +/** Test enum for member naming check */ +enum MyEnum1 +{ + /** ABC constant */ + ABC, + + /** XYZ constant */ + XYZ; + + /** Should be mSomeMemeber */ + private int someMember; +} diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/constantname/InputConstantNameStaticModifierInInterface.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/constantname/InputConstantNameStaticModifierInInterface.java new file mode 100644 index 000000000..7ed9cfe58 --- /dev/null +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/constantname/InputConstantNameStaticModifierInInterface.java @@ -0,0 +1,11 @@ +package com.puppycrawl.tools.checkstyle.checks.naming.constantname; + + +public interface InputConstantNameStaticModifierInInterface +{ + static int f() + { + int someName = 5; + return someName; + } +} -- cgit v1.2.3