Skip to content

Commit

Permalink
GROOVY-5239
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed May 27, 2021
1 parent bcf77d1 commit a1041c7
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1365,4 +1365,76 @@ public void testAmbiguous_GRE945_ji() {

runConformTest(sources, "abc");
}

@Test // GROOVY-5239
public void testStaticImportVersusOuterClassMethod1() {
//@formatter:off
String[] sources = {
"Main.groovy",
"import static p.Q.who\n" +
"class C {\n" +
" def who() {\n" +
" 'C'\n" +
" }\n" +
" void test() {\n" +
" print who()\n" +
" new D().test()\n" +
" }\n" +
" class D {\n" +
" void test() {\n" +
" print who()\n" + // resolves to static import
" }\n" +
" }\n" +
"}\n" +
"new C().test()\n",

"p/Q.java",
"package p;\n" +
"public class Q {\n" +
" public static String who() {\n" +
" return \"Q\";\n" +
" }\n" +
"}\n",
};
//@formatter:on

runConformTest(sources, "CC");
}

@Test // GROOVY-5239
public void testStaticImportVersusOuterClassMethod2() {
//@formatter:off
String[] sources = {
"Main.groovy",
"import static p.Q.who\n" +
"class C {\n" +
" def who() {\n" +
" 'C'\n" +
" }\n" +
"}\n" +
"class D extends C {\n" +
" void test() {\n" +
" print who()\n" +
" new E().test()\n" +
" }\n" +
" class E {\n" +
" void test() {\n" +
" print who()\n" + // resolves to static import
" }\n" +
" }\n" +
"}\n" +
"new D().test()\n",

"p/Q.java",
"package p;\n" +
"public class Q {\n" +
" public static String who() {\n" +
" return \"Q\";\n" +
" }\n" +
"}\n",
};
//@formatter:on

runConformTest(sources, "CC");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ protected Expression transformMethodCallExpression(MethodCallExpression mce) {

if (mce.isImplicitThis() || isExplicitThisOrSuper) {
if (mce.isImplicitThis()) {
if (null == currentClass.tryFindPossibleMethod(mce.getMethodAsString(), args)) {
if (currentClass.tryFindPossibleMethod(mce.getMethodAsString(), args) == null // GRECLIPSE add -- GROOVY-5239
&& currentClass.getOuterClasses().stream().noneMatch(oc -> oc.tryFindPossibleMethod(mce.getMethodAsString(), args) != null)) {
Expression ret = findStaticMethodImportFromModule(method, args);
if (ret != null) {
// GRECLIPSE add
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ protected Expression transformMethodCallExpression(MethodCallExpression mce) {
Expression args = transform(mce.getArguments());

if (mce.isImplicitThis()) {
if (currentClass.tryFindPossibleMethod(mce.getMethodAsString(), args) == null) {
if (currentClass.tryFindPossibleMethod(mce.getMethodAsString(), args) == null // GRECLIPSE add -- GROOVY-5239
&& currentClass.getOuterClasses().stream().noneMatch(oc -> oc.tryFindPossibleMethod(mce.getMethodAsString(), args) != null)) {
Expression result = findStaticMethodImportFromModule(method, args);
if (result != null) {
// GRECLIPSE add
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ protected Expression transformMethodCallExpression(MethodCallExpression mce) {
Expression args = transform(mce.getArguments());

if (mce.isImplicitThis()) {
if (currentClass.tryFindPossibleMethod(mce.getMethodAsString(), args) == null) {
if (currentClass.tryFindPossibleMethod(mce.getMethodAsString(), args) == null // GRECLIPSE add -- GROOVY-5239
&& currentClass.getOuterClasses().stream().noneMatch(oc -> oc.tryFindPossibleMethod(mce.getMethodAsString(), args) != null)) {
Expression result = findStaticMethodImportFromModule(method, args);
if (result != null) {
// GRECLIPSE add
Expand Down

0 comments on commit a1041c7

Please sign in to comment.