Skip to content

Commit

Permalink
Issue checkstyle#10548: Migrate to Inline Config Parser in HiddenFiel…
Browse files Browse the repository at this point in the history
…dCheckTest
  • Loading branch information
shashwatj07 committed Aug 19, 2021
1 parent 0b64c4d commit 8c0fde8
Show file tree
Hide file tree
Showing 13 changed files with 258 additions and 248 deletions.
1 change: 0 additions & 1 deletion pom.xml
Expand Up @@ -1586,7 +1586,6 @@

<exclude>**/AvoidStaticImportCheckTest.class</exclude>

<exclude>**/HiddenFieldCheckTest.class</exclude>

<exclude>**/ParameterNumberCheckTest.class</exclude>

Expand Down
Expand Up @@ -67,7 +67,8 @@ public void testStaticVisibilityFromLambdas() throws Exception {
"231:55: " + getCheckMessage(MSG_KEY, "someObject"),
"239:52: " + getCheckMessage(MSG_KEY, "someObject"),
};
verify(checkConfig, getPath("InputHiddenFieldLambdas.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputHiddenFieldLambdas.java"), expected);
}

@Test
Expand All @@ -81,7 +82,8 @@ public void testStaticVisibilityFromAnonymousClasses() throws Exception {
"46:53: " + getCheckMessage(MSG_KEY, "other"),
"58:26: " + getCheckMessage(MSG_KEY, "someField"),
};
verify(checkConfig, getPath("InputHiddenFieldStaticVisibility.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputHiddenFieldStaticVisibility.java"), expected);
}

@Test
Expand Down Expand Up @@ -110,7 +112,8 @@ public void testNoParameters()
"229:13: " + getCheckMessage(MSG_KEY, "hidden"),
"235:13: " + getCheckMessage(MSG_KEY, "hiddenStatic"),
};
verify(checkConfig, getPath("InputHiddenField1.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputHiddenField1.java"), expected);
}

@Test
Expand Down Expand Up @@ -155,7 +158,8 @@ public void testDefault()
"290:42: " + getCheckMessage(MSG_KEY, "prop2"),
"302:19: " + getCheckMessage(MSG_KEY, "i"),
};
verify(checkConfig, getPath("InputHiddenField2.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputHiddenField2.java"), expected);
}

/** Tests ignoreFormat property. */
Expand Down Expand Up @@ -197,7 +201,8 @@ public void testIgnoreFormat()
"279:29: " + getCheckMessage(MSG_KEY, "prop"),
"290:42: " + getCheckMessage(MSG_KEY, "prop2"),
};
verify(checkConfig, getPath("InputHiddenField3.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputHiddenField3.java"), expected);
}

/** Tests ignoreSetter property. */
Expand Down Expand Up @@ -240,7 +245,8 @@ public void testIgnoreSetter()
"265:41: " + getCheckMessage(MSG_KEY, "prop"),
"290:42: " + getCheckMessage(MSG_KEY, "prop2"),
};
verify(checkConfig, getPath("InputHiddenField4.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputHiddenField4.java"), expected);
}

/** Tests ignoreSetter and setterCanReturnItsClass properties. */
Expand Down Expand Up @@ -282,7 +288,8 @@ public void testIgnoreChainSetter()
"235:13: " + getCheckMessage(MSG_KEY, "hiddenStatic"),
"242:41: " + getCheckMessage(MSG_KEY, "x"),
};
verify(checkConfig, getPath("InputHiddenField5.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputHiddenField5.java"), expected);
}

/** Tests ignoreConstructorParameter property. */
Expand Down Expand Up @@ -326,7 +333,8 @@ public void testIgnoreConstructorParameter()
"289:42: " + getCheckMessage(MSG_KEY, "prop2"),
"301:19: " + getCheckMessage(MSG_KEY, "i"),
};
verify(checkConfig, getPath("InputHiddenField6.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputHiddenField6.java"), expected);
}

/** Test against a class with field declarations in different order. */
Expand Down Expand Up @@ -357,7 +365,8 @@ public void testReordered()
"137:13: " + getCheckMessage(MSG_KEY, "hidden"),
"143:13: " + getCheckMessage(MSG_KEY, "hiddenStatic"),
};
verify(checkConfig, getPath("InputHiddenFieldReorder.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputHiddenFieldReorder.java"), expected);
}

@Test
Expand Down Expand Up @@ -402,14 +411,16 @@ public void testIgnoreAbstractMethods() throws Exception {
"290:42: " + getCheckMessage(MSG_KEY, "prop2"),
"302:19: " + getCheckMessage(MSG_KEY, "i"),
};
verify(checkConfig, getPath("InputHiddenField7.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputHiddenField7.java"), expected);
}

@Test
public void testReceiverParameter() throws Exception {
final DefaultConfiguration checkConfig = createModuleConfig(HiddenFieldCheck.class);
final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
verify(checkConfig, getPath("InputHiddenFieldReceiver.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputHiddenFieldReceiver.java"), expected);
}

@Test
Expand All @@ -422,7 +433,7 @@ public void testHiddenFieldEnhancedInstanceof() throws Exception {
"26:39: " + getCheckMessage(MSG_KEY, "price"),
"37:35: " + getCheckMessage(MSG_KEY, "hiddenStaticField"),
};
verify(checkConfig,
verifyWithInlineConfigParser(checkConfig,
getNonCompilablePath("InputHiddenFieldEnhancedInstanceof.java"), expected);
}

Expand All @@ -447,7 +458,7 @@ public void testHiddenFieldSwitchExpression() throws Exception {
"67:21: " + getCheckMessage(MSG_KEY, "a"),
"71:21: " + getCheckMessage(MSG_KEY, "b"),
};
verify(checkConfig,
verifyWithInlineConfigParser(checkConfig,
getNonCompilablePath("InputHiddenFieldSwitchExpression.java"), expected);
}

Expand All @@ -467,7 +478,7 @@ public void testHiddenFieldRecords() throws Exception {
"81:21: " + getCheckMessage(MSG_KEY, "x"),
"85:20: " + getCheckMessage(MSG_KEY, "string"),
};
verify(checkConfig,
verifyWithInlineConfigParser(checkConfig,
getNonCompilablePath("InputHiddenFieldRecords.java"), expected);
}

Expand Down
Expand Up @@ -22,8 +22,8 @@ public class Keyboard {
private final int price = 2;

// Pattern variable price hides field price
public boolean doStuff(Float f) { // violation
return f instanceof Float price &&
public boolean doStuff(Float f) {
return f instanceof Float price && // violation
price.floatValue() > 0 &&
model != null &&
price.intValue() == 5;
Expand All @@ -34,7 +34,7 @@ public boolean doStuff(Float f) { // violation
static String hiddenStaticField = "hiddenStaticField";
static {
// Pattern variable hiddenStaticField hides static field hiddenStaticField
if (OBJ instanceof String hiddenStaticField) { //violation
if (OBJ instanceof String hiddenStaticField) { // violation
System.out.println(hiddenStaticField
.toLowerCase(Locale.forLanguageTag(hiddenStaticField)));
boolean stringCheck = "test".equals(hiddenStaticField);
Expand Down
Expand Up @@ -36,12 +36,12 @@ public InputHiddenField1(int hidden) //parameter shadows field

public void shadow()
{
int hidden = 0; //shadows field
int hidden = 0; //shadows field // violation
}

public void shadowFor()
{
for (int hidden = 0; hidden < 1; hidden++) { //shadows field
for (int hidden = 0; hidden < 1; hidden++) { //shadows field // violation
}
}

Expand All @@ -55,7 +55,7 @@ public class Inner

public Inner()
{
int innerHidden = 0; //shadows field
int innerHidden = 0; //shadows field // violation
}

public Inner(int innerHidden) //shadows field
Expand All @@ -64,16 +64,16 @@ public Inner(int innerHidden) //shadows field

private void innerShadow()
{
int innerHidden = 0; //shadows inner field
int hidden = 0; //shadows outer field
int innerHidden = 0; //shadows inner field // violation
int hidden = 0; //shadows outer field // violation
}

private void innerShadowFor()
{
for (int innerHidden = 0; innerHidden < 1; innerHidden++) {
for (int innerHidden = 0; innerHidden < 1; innerHidden++) { // violation
}
//shadows outer field
for (int hidden = 0; hidden < 1; hidden++) {
for (int hidden = 0; hidden < 1; hidden++) { // violation
}
}

Expand All @@ -85,13 +85,13 @@ private void shadowParam(
}

{
int innerHidden = 0;//shadows inner field
int hidden = 0; //shadows outer field
int innerHidden = 0;//shadows inner field // violation
int hidden = 0; //shadows outer field // violation
}
}

{
int hidden = 0;//shadows field
int hidden = 0;//shadows field // violation
}
}

Expand Down Expand Up @@ -147,21 +147,21 @@ class StaticFields1

public static void staticMethod()
{
int hidden;
int hidden; // violation
}

public void method()
{
int hidden;
int hidden; // violation
}

static
{
int hidden;
int hidden; // violation
}

{
int hidden;
int hidden; // violation
}
}

Expand Down Expand Up @@ -209,7 +209,7 @@ enum HiddenEnum11
public void doSomething()
{
//Should be flagged as hiding enum constant member
int hidden = 0;
int hidden = 0; // violation
}
};

Expand All @@ -226,13 +226,13 @@ public void doSomething()
public void doSomething()
{
//Should be flagged as hiding static member
int hidden = 0;
int hidden = 0; // violation
}

public static void doSomethingStatic()
{
//Should be flagged as hiding static member
int hiddenStatic = 0;
int hiddenStatic = 0; // violation
}
}

Expand Down

0 comments on commit 8c0fde8

Please sign in to comment.