From 2119fed831f232b47c13376497e86cee7f36355b Mon Sep 17 00:00:00 2001 From: Shubham Kumar Date: Wed, 12 Apr 2017 00:49:38 +0530 Subject: Issue #4191: Split and Organize Checkstyle inputs by Test for ParameterName --- .../checks/naming/InputAccessModifier.java | 74 ------- .../checks/naming/InputOverrideAnnotation.java | 31 --- .../naming/InputOverrideAnnotationNoNPE.java | 27 --- .../checks/naming/InputParameterNameReceiver.java | 9 - .../naming/parametername/InputAccessModifier.java | 74 +++++++ .../parametername/InputOverrideAnnotation.java | 31 +++ .../naming/parametername/InputParameterName.java | 225 +++++++++++++++++++++ .../parametername/InputParameterNameCatchOnly.java | 34 ++++ .../InputParameterNameOverrideAnnotationNoNPE.java | 27 +++ .../parametername/InputParameterNameReceiver.java | 9 + 10 files changed, 400 insertions(+), 141 deletions(-) delete mode 100644 src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/InputAccessModifier.java delete mode 100644 src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/InputOverrideAnnotation.java delete mode 100644 src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/InputOverrideAnnotationNoNPE.java delete mode 100644 src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/InputParameterNameReceiver.java create mode 100644 src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/parametername/InputAccessModifier.java create mode 100644 src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/parametername/InputOverrideAnnotation.java create mode 100644 src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/parametername/InputParameterName.java create mode 100644 src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/parametername/InputParameterNameCatchOnly.java create mode 100644 src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/parametername/InputParameterNameOverrideAnnotationNoNPE.java create mode 100644 src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/parametername/InputParameterNameReceiver.java (limited to 'src/test/resources') diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/InputAccessModifier.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/InputAccessModifier.java deleted file mode 100644 index a242550dd..000000000 --- a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/InputAccessModifier.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.puppycrawl.tools.checkstyle.checks.naming; - -public class InputAccessModifier { - - public InputAccessModifier(int pubconstr) {} - - public void v1(int h) { - new Object () { - public void i(int inner) {} - }; - } - - protected void v4(int h) {} - - void v2(int h) {} - - private void v3(int h) {} - - public void i1(int pubpub) {} - - protected void i4(int pubprot) {} - - void i2(int pubpack) {} - - private void i3(int pubpriv) {} - - public interface InterfaceScope { - void v1(int h); - - void i1(int pubifc); - } -} - -class PrivateScope { - - public void v1(int h) {} - - protected void v4(int h) {} - - void v2(int h) {} - - private void v3(int h) {} - - public void i1(int packpub) {} - - protected void i4(int packprot) {} - - void i2(int packpack) {} - - private void i3(int packpriv) { - try { - /* Make sure catch var is ignored */ - } catch (Exception exc) { - } - } - - interface InterfaceScope { - void v1(int h); - - void i1(int packifc); - } - - interface FuncIfc { - void a(int h); - } - - public void l() { - FuncIfc l1 = (int lexp)->{}; - - FuncIfc l2 = (limp)->{}; - } -} - - diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/InputOverrideAnnotation.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/InputOverrideAnnotation.java deleted file mode 100644 index e4e40d126..000000000 --- a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/InputOverrideAnnotation.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.puppycrawl.tools.checkstyle.checks.naming; - -public class InputOverrideAnnotation { - - @Override - public boolean equals(Object o) { - return super.equals(o); - } - - @SuppressWarnings("") - public void foo(Object object) { - - } - - public void foo2(Integer aaaa) {} - - void foo3() {} // No NPE here! - - void foo4(int abc, int bd) {} // No NPE here! - - int foo5(int abc) {return 1;} // No NPE here! - - private int field; - private java.util.Set packageNames; - - InputOverrideAnnotation() {} // No NPE here! - - InputOverrideAnnotation(int field, java.util.Set packageNames) {} // No NPE here! - - -} diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/InputOverrideAnnotationNoNPE.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/InputOverrideAnnotationNoNPE.java deleted file mode 100644 index 8295a120e..000000000 --- a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/InputOverrideAnnotationNoNPE.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.puppycrawl.tools.checkstyle.checks.naming; - -class InputOverrideAnnotationNoNPE -{ - // method with many parameters - void myMethod(int a, int b) { - - } - - // method with many parameters - void myMethod2(int a, int b) { - - } -} - -class Test extends InputOverrideAnnotationNoNPE -{ - @Override - void myMethod(int a, int b) { - - } - - @java.lang.Override - void myMethod2(int a, int b) { - - } -} diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/InputParameterNameReceiver.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/InputParameterNameReceiver.java deleted file mode 100644 index 1047f7f89..000000000 --- a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/InputParameterNameReceiver.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.puppycrawl.tools.checkstyle.checks.naming; - -public class InputParameterNameReceiver { - public void foo4(InputParameterNameReceiver this) {} - - private class Inner { - public Inner(InputParameterNameReceiver InputParameterNameReceiver.this) {} - } -} diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/parametername/InputAccessModifier.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/parametername/InputAccessModifier.java new file mode 100644 index 000000000..0fa58b8d2 --- /dev/null +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/parametername/InputAccessModifier.java @@ -0,0 +1,74 @@ +package com.puppycrawl.tools.checkstyle.checks.naming.parametername; + +public class InputAccessModifier { + + public InputAccessModifier(int pubconstr) {} + + public void v1(int h) { + new Object () { + public void i(int inner) {} + }; + } + + protected void v4(int h) {} + + void v2(int h) {} + + private void v3(int h) {} + + public void i1(int pubpub) {} + + protected void i4(int pubprot) {} + + void i2(int pubpack) {} + + private void i3(int pubpriv) {} + + public interface InterfaceScope { + void v1(int h); + + void i1(int pubifc); + } +} + +class PrivateScope { + + public void v1(int h) {} + + protected void v4(int h) {} + + void v2(int h) {} + + private void v3(int h) {} + + public void i1(int packpub) {} + + protected void i4(int packprot) {} + + void i2(int packpack) {} + + private void i3(int packpriv) { + try { + /* Make sure catch var is ignored */ + } catch (Exception exc) { + } + } + + interface InterfaceScope { + void v1(int h); + + void i1(int packifc); + } + + interface FuncIfc { + void a(int h); + } + + public void l() { + FuncIfc l1 = (int lexp)->{}; + + FuncIfc l2 = (limp)->{}; + } +} + + diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/parametername/InputOverrideAnnotation.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/parametername/InputOverrideAnnotation.java new file mode 100644 index 000000000..3e7a91fce --- /dev/null +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/parametername/InputOverrideAnnotation.java @@ -0,0 +1,31 @@ +package com.puppycrawl.tools.checkstyle.checks.naming.parametername; + +public class InputOverrideAnnotation { + + @Override + public boolean equals(Object o) { + return super.equals(o); + } + + @SuppressWarnings("") + public void foo(Object object) { + + } + + public void foo2(Integer aaaa) {} + + void foo3() {} // No NPE here! + + void foo4(int abc, int bd) {} // No NPE here! + + int foo5(int abc) {return 1;} // No NPE here! + + private int field; + private java.util.Set packageNames; + + InputOverrideAnnotation() {} // No NPE here! + + InputOverrideAnnotation(int field, java.util.Set packageNames) {} // No NPE here! + + +} diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/parametername/InputParameterName.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/parametername/InputParameterName.java new file mode 100644 index 000000000..d38b31e80 --- /dev/null +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/parametername/InputParameterName.java @@ -0,0 +1,225 @@ +//////////////////////////////////////////////////////////////////////////////// +// Test case file for checkstyle. +// Created: Feb-2001 +// Ignore error +//////////////////////////////////////////////////////////////////////////////// +package com.puppycrawl.tools.checkstyle.checks.naming.parametername; +import java.io.*; +/** + * Contains simple mistakes: + * - Long lines + * - Tabs + * - Format of variables and parameters + * - Order of modifiers + * @author Oliver Burn + **/ +final class InputParameterName +{ + // 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 InputParameterName() + { + // 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 InputParameterName2 +{ + /** 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 InputParameterNameEnum1 +{ + /** ABC constant */ + ABC, + + /** XYZ constant */ + XYZ; + + /** Should be mSomeMemeber */ + private int someMember; +} diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/parametername/InputParameterNameCatchOnly.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/parametername/InputParameterNameCatchOnly.java new file mode 100644 index 000000000..966114bdf --- /dev/null +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/parametername/InputParameterNameCatchOnly.java @@ -0,0 +1,34 @@ +package com.puppycrawl.tools.checkstyle.checks.naming.parametername; + +/** + * Test case for skipping over catch names. + **/ +public class InputParameterNameCatchOnly { + int foo() { + if (System.currentTimeMillis() > 1000) + return 1; + + int test = 0; + + try + { + return 1; + } + catch (Exception e) + { + return 0; + } + } + + public InputParameterNameCatchOnly() + { + return; + } + + class InnerFoo + { + public void fooInnerMethod () + { + } + } +} diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/parametername/InputParameterNameOverrideAnnotationNoNPE.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/parametername/InputParameterNameOverrideAnnotationNoNPE.java new file mode 100644 index 000000000..549e770fb --- /dev/null +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/parametername/InputParameterNameOverrideAnnotationNoNPE.java @@ -0,0 +1,27 @@ +package com.puppycrawl.tools.checkstyle.checks.naming.parametername; + +class InputParameterNameOverrideAnnotationNoNPE +{ + // method with many parameters + void InputParameterNameOverrideAnnotationNoNPEMethod(int a, int b) { + + } + + // method with many parameters + void InputParameterNameOverrideAnnotationNoNPEMethod2(int a, int b) { + + } +} + +class Test extends InputParameterNameOverrideAnnotationNoNPE +{ + @Override + void InputParameterNameOverrideAnnotationNoNPEMethod(int a, int b) { + + } + + @java.lang.Override + void InputParameterNameOverrideAnnotationNoNPEMethod2(int a, int b) { + + } +} diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/parametername/InputParameterNameReceiver.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/parametername/InputParameterNameReceiver.java new file mode 100644 index 000000000..cd450bf3c --- /dev/null +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/naming/parametername/InputParameterNameReceiver.java @@ -0,0 +1,9 @@ +package com.puppycrawl.tools.checkstyle.checks.naming.parametername; + +public class InputParameterNameReceiver { + public void foo4(InputParameterNameReceiver this) {} + + private class Inner { + public Inner(InputParameterNameReceiver InputParameterNameReceiver.this) {} + } +} -- cgit v1.2.3