Skip to content

Commit

Permalink
Issue checkstyle#10548: Migrate to Inline Config Parser in IllegalTyp…
Browse files Browse the repository at this point in the history
…eCheckTest
  • Loading branch information
shashwatj07 authored and romani committed Aug 18, 2021
1 parent 1b326d6 commit 67675f2
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 32 deletions.
1 change: 0 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1608,7 +1608,6 @@

<exclude>**/PackageNameCheckTest.class</exclude>

<exclude>**/IllegalTypeCheckTest.class</exclude>

<exclude>**/NoLineWrapCheckTest.class</exclude>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public void testValidateAbstractClassNamesSetToTrue() throws Exception {
"50:12: " + getCheckMessage(MSG_KEY, "AbstractClass"),
};

verify(checkConfig, getPath("InputIllegalTypeTestAbstractClassNamesTrue.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputIllegalTypeTestAbstractClassNamesTrue.java"), expected);
}

@Test
Expand All @@ -60,7 +61,8 @@ public void testValidateAbstractClassNamesSetToFalse() throws Exception {
checkConfig.addProperty("validateAbstractClassNames", "false");
final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;

verify(checkConfig, getPath("InputIllegalTypeTestAbstractClassNamesFalse.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputIllegalTypeTestAbstractClassNamesFalse.java"), expected);
}

@Test
Expand All @@ -73,7 +75,8 @@ public void testDefaults() throws Exception {
"62:5: " + getCheckMessage(MSG_KEY, "HashMap"),
};

verify(checkConfig, getPath("InputIllegalTypeTestDefaults.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputIllegalTypeTestDefaults.java"), expected);
}

@Test
Expand All @@ -88,7 +91,8 @@ public void testDefaultsEmptyStringMemberModifiers() throws Exception {
"62:5: " + getCheckMessage(MSG_KEY, "HashMap"),
};

verify(checkConfig, getPath("InputIllegalTypeEmptyStringMemberModifiers.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputIllegalTypeEmptyStringMemberModifiers.java"), expected);
}

@Test
Expand All @@ -107,7 +111,8 @@ public void testIgnoreMethodNames() throws Exception {
"62:5: " + getCheckMessage(MSG_KEY, "HashMap"),
};

verify(checkConfig, getPath("InputIllegalTypeTestIgnoreMethodNames.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputIllegalTypeTestIgnoreMethodNames.java"), expected);
}

@Test
Expand All @@ -122,7 +127,8 @@ public void testFormat() throws Exception {
"62:5: " + getCheckMessage(MSG_KEY, "HashMap"),
};

verify(checkConfig, getPath("InputIllegalTypeTestFormat.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputIllegalTypeTestFormat.java"), expected);
}

@Test
Expand All @@ -141,7 +147,8 @@ public void testLegalAbstractClassNames() throws Exception {
"62:5: " + getCheckMessage(MSG_KEY, "HashMap"),
};

verify(checkConfig, getPath("InputIllegalTypeTestLegalAbstractClassNames.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputIllegalTypeTestLegalAbstractClassNames.java"), expected);
}

@Test
Expand All @@ -155,7 +162,8 @@ public void testSameFileNameFalsePositive() throws Exception {
"43:5: " + getCheckMessage(MSG_KEY, "java.util.List"),
};

verify(checkConfig, getPath("InputIllegalTypeSameFileNameFalsePositive.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputIllegalTypeSameFileNameFalsePositive.java"), expected);
}

@Test
Expand All @@ -173,7 +181,8 @@ public void testSameFileNameGeneral() throws Exception {
"43:13: " + getCheckMessage(MSG_KEY, "ArrayList"),
"44:13: " + getCheckMessage(MSG_KEY, "Boolean"),
};
verify(checkConfig, getPath("InputIllegalTypeTestSameFileNameGeneral.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputIllegalTypeTestSameFileNameGeneral.java"), expected);
}

@Test
Expand All @@ -188,7 +197,8 @@ public void testArrayTypes() throws Exception {
"29:12: " + getCheckMessage(MSG_KEY, "Boolean[][]"),
"30:9: " + getCheckMessage(MSG_KEY, "Boolean[][]"),
};
verify(checkConfig, getPath("InputIllegalTypeArrays.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputIllegalTypeArrays.java"), expected);
}

@Test
Expand All @@ -202,7 +212,8 @@ public void testPlainAndArrayTypes() throws Exception {
"35:12: " + getCheckMessage(MSG_KEY, "Boolean[][]"),
"36:9: " + getCheckMessage(MSG_KEY, "Boolean[][]"),
};
verify(checkConfig, getPath("InputIllegalTypeTestPlainAndArraysTypes.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputIllegalTypeTestPlainAndArraysTypes.java"), expected);
}

@Test
Expand Down Expand Up @@ -230,7 +241,8 @@ public void testGenerics() throws Exception {
"55:20: " + getCheckMessage(MSG_KEY, "Boolean"),
"68:28: " + getCheckMessage(MSG_KEY, "Boolean"),
};
verify(checkConfig, getPath("InputIllegalTypeTestGenerics.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputIllegalTypeTestGenerics.java"), expected);
}

@Test
Expand All @@ -250,7 +262,8 @@ public void testExtendsImplements() throws Exception {
"39:28: " + getCheckMessage(MSG_KEY, "Boolean"),
"40:13: " + getCheckMessage(MSG_KEY, "Serializable"),
};
verify(checkConfig, getPath("InputIllegalTypeTestExtendsImplements.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputIllegalTypeTestExtendsImplements.java"), expected);
}

@Test
Expand All @@ -262,7 +275,8 @@ public void testStarImports() throws Exception {
"25:5: " + getCheckMessage(MSG_KEY, "List"),
};

verify(checkConfig, getPath("InputIllegalTypeTestStarImports.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputIllegalTypeTestStarImports.java"), expected);
}

@Test
Expand All @@ -276,7 +290,8 @@ public void testStaticImports() throws Exception {
"30:31: " + getCheckMessage(MSG_KEY, "SomeStaticClass"),
};

verify(checkConfig, getPath("InputIllegalTypeTestStaticImports.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputIllegalTypeTestStaticImports.java"), expected);
}

@Test
Expand All @@ -295,7 +310,8 @@ public void testMemberModifiers() throws Exception {
"49:15: " + getCheckMessage(MSG_KEY, "AbstractClass"),
};

verify(checkConfig, getPath("InputIllegalTypeTestMemberModifiers.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputIllegalTypeTestMemberModifiers.java"), expected);
}

@Test
Expand All @@ -304,7 +320,8 @@ public void testPackageClassName() throws Exception {
checkConfig.addProperty("illegalClassNames", "com.PackageClass");
final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;

verify(checkConfig, getNonCompilablePath("InputIllegalTypePackageClassName.java"),
verifyWithInlineConfigParser(checkConfig,
getNonCompilablePath("InputIllegalTypePackageClassName.java"),
expected);
}

Expand Down Expand Up @@ -335,7 +352,7 @@ public void testIllegalTypeEnhancedInstanceof() throws Exception {
"41:32: " + getCheckMessage(MSG_KEY, "TreeSet"),
};

verify(checkConfig,
verifyWithInlineConfigParser(checkConfig,
getNonCompilablePath("InputIllegalTypeTestEnhancedInstanceof.java"),
expected);
}
Expand All @@ -358,7 +375,7 @@ public void testIllegalTypeRecordsAndCompactCtors() throws Exception {
"48:13: " + getCheckMessage(MSG_KEY, "LinkedHashMap"),
};

verify(checkConfig,
verifyWithInlineConfigParser(checkConfig,
getNonCompilablePath("InputIllegalTypeRecordsAndCompactCtors.java"),
expected);
}
Expand All @@ -372,7 +389,7 @@ public void testIllegalTypeNewArrayStructure() throws Exception {
"26:13: " + getCheckMessage(MSG_KEY, "HashMap"),
};

verify(checkConfig,
verifyWithInlineConfigParser(checkConfig,
getPath("InputIllegalTypeNewArrayStructure.java"),
expected);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void InputIllegalTypeEnhancedInstanceof() {
}
}

public void InputIllegalTypeEnhancedInstanceof(TreeSet treeSet) {
public void InputIllegalTypeEnhancedInstanceof(TreeSet treeSet) { // violation
if (treeSet instanceof TreeSet t) { // violation
System.out.println(t);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
legalAbstractClassNames = (default)
ignoredMethodNames = (default)getEnvironment, getInitialContext
illegalAbstractClassNameFormat = (default)^(.*[.])?Abstract.*$
memberModifiers = (default)
memberModifiers =
tokens = (default)ANNOTATION_FIELD_DEF, CLASS_DEF, INTERFACE_DEF, METHOD_CALL, METHOD_DEF, \
METHOD_REF, PARAMETER_DEF, VARIABLE_DEF, PATTERN_VARIABLE_DEF, RECORD_DEF, \
RECORD_COMPONENT_DEF
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,24 @@ public abstract class InputIllegalTypeTestGenerics {
private Set<Boolean> privateSet; // OK
private java.util.List<Map<Boolean, Foo>> privateList; // OK
public Set<Boolean> set; // violation
public java.util.List<Map<Boolean, Foo>> list; // violation
public java.util.List<Map<Boolean, Foo>> list; // 2 violations

private void methodCall() {
Bounded.<Boolean>foo(); // violation
final Consumer<Foo> consumer = Foo<Boolean>::foo; // violation
final Consumer<Foo> consumer = Foo<Boolean>::foo; // 2 violations
}

public <T extends Boolean, U extends Serializable> void typeParameter(T a) {} // violation
public <T extends Boolean, U extends Serializable> void typeParameter(T a) {} // 2 violations

public void fullName(java.util.ArrayList<? super Boolean> a) {} // violation

public abstract Set<Boolean> shortName(Set<? super Set<Boolean>> a); // violation
public abstract Set<Boolean> shortName(Set<? super Set<Boolean>> a); // 2 violations

public Set<? extends Foo<Boolean>> typeArgument() { // violation
public Set<? extends Foo<Boolean>> typeArgument() { // 2 violations
return new TreeSet<Foo<Boolean>>(); // OK
}

public class MyClass<Foo extends Boolean> {} // violation
public class MyClass<Foo extends Boolean> {} // 2 violations

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class InputIllegalTypeTestIgnoreMethodNames implements InputIllegalTypeSu
private NotAnAbstractClass b = null; /*another comment*/

private com.puppycrawl.tools.checkstyle.checks.coding.illegaltype.InputIllegalType.AbstractClass
c = null; // ^ violation above
c = null; // violation above
private java.util.List d = null;

private abstract class AbstractClass {/*one more comment*/}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class InputIllegalTypeTestLegalAbstractClassNames implements InputIllegal
private NotAnAbstractClass b = null; /*another comment*/

private com.puppycrawl.tools.checkstyle.checks.coding.illegaltype.InputIllegalType.AbstractClass
c = null; // ^ violation above
c = null; // violation above
private java.util.List d = null;

private abstract class AbstractClass {/*one more comment*/}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
IllegalType
validateAbstractClassNames = (default)false
illegalClassNames = Boolean[], Boolean[][]
illegalClassNames = Boolean, Boolean[][]
legalAbstractClassNames = (default)
ignoredMethodNames = (default)getEnvironment, getInitialContext
illegalAbstractClassNameFormat = (default)^(.*[.])?Abstract.*$
Expand Down

0 comments on commit 67675f2

Please sign in to comment.