Skip to content

Commit

Permalink
Pull #5361: fixed RequireThisCheck and enum constants handling
Browse files Browse the repository at this point in the history
  • Loading branch information
rnveach authored and romani committed Dec 15, 2017
1 parent 62d4be2 commit e702daf
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,10 @@ private static void collectDeclarations(Deque<AbstractFrame> frameStack, DetailA
final DetailAST ctorFrameNameIdent = ast.findFirstToken(TokenTypes.IDENT);
frameStack.addFirst(new ConstructorFrame(frame, ctorFrameNameIdent));
break;
case TokenTypes.ENUM_CONSTANT_DEF :
final DetailAST ident = ast.findFirstToken(TokenTypes.IDENT);
((ClassFrame) frame).addStaticMember(ident);
break;
case TokenTypes.LITERAL_CATCH:
final AbstractFrame catchFrame = new CatchFrame(frame, ast);
catchFrame.addIdent(ast.findFirstToken(TokenTypes.PARAMETER_DEF).findFirstToken(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,14 @@ public void testCatchVariables() throws Exception {
verify(checkConfig, getPath("InputRequireThisCatchVariables.java"), expected);
}

@Test
public void testEnumConstant() throws Exception {
final DefaultConfiguration checkConfig = createModuleConfig(RequireThisCheck.class);
checkConfig.addAttribute("validateOnlyOverlapping", "false");
final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
verify(checkConfig, getPath("InputRequireThisEnumConstant.java"), expected);
}

@Test
public void test() throws Exception {
final DefaultConfiguration checkConfig = createModuleConfig(RequireThisCheck.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.puppycrawl.tools.checkstyle.checks.coding.requirethis;

public class InputRequireThisEnumConstant {
private final String TEST = "";

public enum TestEnum {
TEST;

public TestEnum method() {
return TEST;
}
}
}

0 comments on commit e702daf

Please sign in to comment.