Skip to content

Commit

Permalink
Issue sevntu-checkstyle#669: removed branchContains for modifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
rnveach authored and kariem committed Jul 26, 2018
1 parent cfe2924 commit 655de55
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,10 @@ private static boolean isField(final DetailAST ast) {
current = current.getParent();
}
return current.getType() == TokenTypes.VARIABLE_DEF
&& current.branchContains(TokenTypes.LITERAL_STATIC)
&& current.branchContains(TokenTypes.FINAL);
&& current.findFirstToken(TokenTypes.MODIFIERS)
.findFirstToken(TokenTypes.LITERAL_STATIC) != null
&& current.findFirstToken(TokenTypes.MODIFIERS)
.findFirstToken(TokenTypes.FINAL) != null;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ public void visitToken(DetailAST ast) {
final DetailAST modifiers =
child.findFirstToken(TokenTypes.MODIFIERS);
final boolean isStatic =
modifiers.branchContains(TokenTypes.LITERAL_STATIC);
modifiers.findFirstToken(TokenTypes.LITERAL_STATIC) != null;
final boolean isPrivate =
modifiers.branchContains(TokenTypes.LITERAL_PRIVATE);
modifiers.findFirstToken(TokenTypes.LITERAL_PRIVATE) != null;

if (!isStatic && !isPrivate) {
hasNonStaticMethodOrField = true;
Expand All @@ -94,8 +94,8 @@ public void visitToken(DetailAST ast) {
hasDefaultCtor = false;
final DetailAST modifiers =
child.findFirstToken(TokenTypes.MODIFIERS);
if (!modifiers.branchContains(TokenTypes.LITERAL_PRIVATE)
&& !modifiers.branchContains(TokenTypes.LITERAL_PROTECTED)) {
if (modifiers.findFirstToken(TokenTypes.LITERAL_PRIVATE) == null
&& modifiers.findFirstToken(TokenTypes.LITERAL_PROTECTED) == null) {
// treat package visible as public
// for the purpose of this Check
hasPublicCtor = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@ private Frame createMethodFrame(Frame parentFrame, DetailAST ast) {
final DetailAST modifiersAst = ast.findFirstToken(TokenTypes.MODIFIERS);
final String methodName = ast.findFirstToken(TokenTypes.IDENT).getText();
final Frame frame = new Frame(parentFrame);
if (modifiersAst.branchContains(TokenTypes.LITERAL_PRIVATE)
&& !modifiersAst.branchContains(TokenTypes.LITERAL_STATIC)
if (modifiersAst.findFirstToken(TokenTypes.LITERAL_PRIVATE) != null
&& modifiersAst.findFirstToken(TokenTypes.LITERAL_STATIC) == null
&& !skippedMethods.contains(methodName)) {
frame.isPrivateMethod = true;
frame.ast = ast;
Expand Down Expand Up @@ -360,7 +360,7 @@ private static String getIdentText(DetailAST field) {
*/
private static boolean hasStaticModifier(DetailAST ast) {
return ast.findFirstToken(TokenTypes.MODIFIERS)
.branchContains(TokenTypes.LITERAL_STATIC);
.findFirstToken(TokenTypes.LITERAL_STATIC) != null;
}

/**
Expand Down Expand Up @@ -643,7 +643,7 @@ private static boolean findStaticMethod(Frame startFrame, DetailAST methodCall,
|| parametersAst.branchContains(TokenTypes.ELLIPSIS))) {
final DetailAST modifiersAst = method.findFirstToken(TokenTypes.MODIFIERS);

if (modifiersAst.branchContains(TokenTypes.LITERAL_STATIC)) {
if (modifiersAst.findFirstToken(TokenTypes.LITERAL_STATIC) != null) {
// if a static method is found, we keep searching for a similar
// non-static one to the end of the frame and if a non-static
// method is not found, then the checked method is still
Expand Down

0 comments on commit 655de55

Please sign in to comment.