Skip to content

Commit

Permalink
Handle static methods in InfiniteRecursion
Browse files Browse the repository at this point in the history
RELNOTES: Handle static methods in InfiniteRecursion

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=234682884
  • Loading branch information
cushon committed Feb 22, 2019
1 parent cbe145a commit 5b5684f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,25 +68,27 @@ public ExpressionTree visitReturn(ReturnTree tree, Void unused) {
return NO_MATCH;
}
ExpressionTree select = ((MethodInvocationTree) expr).getMethodSelect();
switch (select.getKind()) {
case IDENTIFIER:
break;
case MEMBER_SELECT:
ExpressionTree receiver = ((MemberSelectTree) select).getExpression();
if (receiver.getKind() != Kind.IDENTIFIER) {
return NO_MATCH;
}
if (!((IdentifierTree) receiver).getName().contentEquals("this")) {
return NO_MATCH;
}
break;
default:
return NO_MATCH;
}
MethodSymbol sym = ASTHelpers.getSymbol(tree);
if (sym == null || !sym.equals(ASTHelpers.getSymbol(expr))) {
return NO_MATCH;
}
if (!sym.isStatic()) {
switch (select.getKind()) {
case IDENTIFIER:
break;
case MEMBER_SELECT:
ExpressionTree receiver = ((MemberSelectTree) select).getExpression();
if (receiver.getKind() != Kind.IDENTIFIER) {
return NO_MATCH;
}
if (!((IdentifierTree) receiver).getName().contentEquals("this")) {
return NO_MATCH;
}
break;
default:
return NO_MATCH;
}
}
return describeMatch(statement);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,38 @@ public void positive() {
.doTest();
}

@Test
public void positiveStatic() {
compilationHelper
.addSourceLines(
"Test.java",
"class Test {",
" static void f(int x) {}",
" static void f() {",
" // BUG: Diagnostic contains:",
" Test.f();",
" }",
" static void instanceF() {",
" // BUG: Diagnostic contains:",
" new Test().instanceF();",
" }",
" static void subclassF() {",
" // BUG: Diagnostic contains:",
" Subclass.subclassF();",
" }",
" static int g() {",
" return 0;",
" }",
" static int g(int x) {",
" // BUG: Diagnostic contains:",
" return Test.g(x);",
" }",
"",
" class Subclass extends Test {}",
"}")
.doTest();
}

@Test
public void negative() {
compilationHelper
Expand Down

0 comments on commit 5b5684f

Please sign in to comment.