Skip to content

Commit

Permalink
Fix for #1540: traits: transitive this static method call
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Feb 1, 2024
1 parent 6f9a896 commit 9f3799e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,37 @@ public void testPublicStaticMethod10() {
assertDeclaringType(contents, offset, offset + 1, "T");
}

@Test // https://github.com/groovy/groovy-eclipse/issues/1540
public void testPublicStaticMethod11() {
//@formatter:off
String contents =
"trait T {\n" +
" static m() {\n" +
" this.m()\n" +
" def that = this\n" +
" that.m()\n" +
" }\n" +
" def foo() {\n" +
" this.m()\n" +
" def that = this\n" +
" that.m()\n" +
" }\n" +
"}\n";
//@formatter:on

int offset = contents.indexOf("this.m()") + 5;
assertDeclaringType(contents, offset, offset + 1, "T");

/**/offset = contents.indexOf("that.m()") + 5;
assertDeclaringType(contents, offset, offset + 1, "T");

/**/offset = contents.lastIndexOf("this.m()") + 5;
assertDeclaringType(contents, offset, offset + 1, "T");

/**/offset = contents.lastIndexOf("that.m()") + 5;
assertDeclaringType(contents, offset, offset + 1, "T");
}

@Test // https://issues.apache.org/jira/browse/GROOVY-8272
public void testPublicStaticSuperMethod1() {
//@formatter:off
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ protected TypeLookupResult findTypeForNameWithKnownObjectExpression(final String
TypeConfidence confidence = TypeConfidence.EXACT;
int fieldAccessPolicy = (!scope.isFieldAccessDirect() || !(isThisObjectExpression(scope) || isSuperObjectExpression(scope)) ? 0 : isThisObjectExpression(scope) ? 1 : 2);
// GRECLIPSE-1544: "Type.staticMethod()" or "def type = Type.class; type.staticMethod()" or ".&" variations; StatementAndExpressionCompletionProcessor circa line 275 has similar check for proposals
ClassNode declaring = isStaticObjectExpression && (!Traits.isTrait(getBaseDeclaringType(declaringType)) || "$static$self".equals(getObjectExpression(scope).getText())) ? getBaseDeclaringType(declaringType) : declaringType;
ClassNode declaring = isStaticObjectExpression && (!Traits.isTrait(getBaseDeclaringType(declaringType)) || getObjectExpression(scope) instanceof Variable) ? getBaseDeclaringType(declaringType) : declaringType;
ASTNode declaration = findDeclaration(name, declaring, isLhsExpression, isStaticObjectExpression, fieldAccessPolicy, scope.getEnclosingNode() instanceof MethodPointerExpression ? UNKNOWN_TYPES : scope.getMethodCallArgumentTypes());
if (declaration instanceof MethodNode && scope.getEnclosingNode() instanceof PropertyExpression && !scope.isMethodCall() &&
(!AccessorSupport.isGetter((MethodNode) declaration) || name.equals(((MethodNode) declaration).getName()))) {
Expand Down

0 comments on commit 9f3799e

Please sign in to comment.