Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #669: removed branchContains for modifiers #670

Merged
merged 1 commit into from
May 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.lineNo = ast.getLineNo();
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