Skip to content

Commit

Permalink
Support annotations in TypeNameCheck
Browse files Browse the repository at this point in the history
  • Loading branch information
tsjensen committed Jul 28, 2014
1 parent f39f224 commit f3d4337
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public int[] getDefaultTokens()
return new int[] {TokenTypes.CLASS_DEF,
TokenTypes.INTERFACE_DEF,
TokenTypes.ENUM_DEF,
TokenTypes.ANNOTATION_DEF,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ public interface inputHeaderInterface {};

public enum inputHeaderEnum { one, two };

public @interface inputHeaderAnnotation {};

}

0 comments on commit f3d4337

Please sign in to comment.