Permalink
Browse files

Support annotations in TypeNameCheck

  • Loading branch information...
tsjensen committed Jul 28, 2014
1 parent f39f224 commit f3d433723bebb55e09eba1562b6c75407f6fe46f
@@ -68,6 +68,7 @@ public TypeNameCheck()
return new int[] {TokenTypes.CLASS_DEF,
TokenTypes.INTERFACE_DEF,
TokenTypes.ENUM_DEF,
TokenTypes.ANNOTATION_DEF,
};
}
}
@@ -26,6 +26,7 @@
import com.puppycrawl.tools.checkstyle.BaseCheckTestSupport;
import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
public class TypeNameCheckTest
extends BaseCheckTestSupport
@@ -69,6 +70,8 @@ public void testDefault()
TypeNameCheck.DEFAULT_PATTERN),
buildMesssage(7, 17, "inputHeaderEnum",
TypeNameCheck.DEFAULT_PATTERN),
buildMesssage(9, 23, "inputHeaderAnnotation",
TypeNameCheck.DEFAULT_PATTERN),
};
verify(checkConfig, inputFilename, expected);
}
@@ -79,7 +82,7 @@ public void testClassSpecific()
{
final DefaultConfiguration checkConfig =
createCheckConfig(TypeNameCheck.class);
checkConfig.addAttribute("tokens", "CLASS_DEF");
checkConfig.addAttribute("tokens", TokenTypes.getTokenName(TokenTypes.CLASS_DEF));
final String[] expected = {
buildMesssage(3, 7, "inputHeaderClass",
TypeNameCheck.DEFAULT_PATTERN),
@@ -93,7 +96,7 @@ public void testInterfaceSpecific()
{
final DefaultConfiguration checkConfig =
createCheckConfig(TypeNameCheck.class);
checkConfig.addAttribute("tokens", "INTERFACE_DEF");
checkConfig.addAttribute("tokens", TokenTypes.getTokenName(TokenTypes.INTERFACE_DEF));
final String[] expected = {
buildMesssage(5, 22, "inputHeaderInterface",
TypeNameCheck.DEFAULT_PATTERN),
@@ -107,14 +110,28 @@ public void testEnumSpecific()
{
final DefaultConfiguration checkConfig =
createCheckConfig(TypeNameCheck.class);
checkConfig.addAttribute("tokens", "ENUM_DEF");
checkConfig.addAttribute("tokens", TokenTypes.getTokenName(TokenTypes.ENUM_DEF));
final String[] expected = {
buildMesssage(7, 17, "inputHeaderEnum",
TypeNameCheck.DEFAULT_PATTERN),
};
verify(checkConfig, inputFilename, expected);
}
@Test
public void testAnnotationSpecific()
throws Exception
{
final DefaultConfiguration checkConfig =
createCheckConfig(TypeNameCheck.class);
checkConfig.addAttribute("tokens", TokenTypes.getTokenName(TokenTypes.ANNOTATION_DEF));
final String[] expected = {
buildMesssage(9, 23, "inputHeaderAnnotation",
TypeNameCheck.DEFAULT_PATTERN),
};
verify(checkConfig, inputFilename, expected);
}
private String buildMesssage(int lineNumber, int colNumber, String name,
String pattern)
{
@@ -6,4 +6,6 @@
public enum inputHeaderEnum { one, two };
public @interface inputHeaderAnnotation {};
}

0 comments on commit f3d4337

Please sign in to comment.