File tree Expand file tree Collapse file tree 4 files changed +78
-3
lines changed
base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/basic
org.codehaus.groovy25/src/org/codehaus/groovy/control
org.codehaus.groovy30/src/org/codehaus/groovy/control
org.codehaus.groovy40/src/org/codehaus/groovy/control Expand file tree Collapse file tree 4 files changed +78
-3
lines changed Original file line number Diff line number Diff line change @@ -1365,4 +1365,76 @@ public void testAmbiguous_GRE945_ji() {
13651365
13661366 runConformTest (sources , "abc" );
13671367 }
1368+
1369+ @ Test // GROOVY-5239
1370+ public void testStaticImportVersusOuterClassMethod1 () {
1371+ //@formatter:off
1372+ String [] sources = {
1373+ "Main.groovy" ,
1374+ "import static p.Q.who\n " +
1375+ "class C {\n " +
1376+ " def who() {\n " +
1377+ " 'C'\n " +
1378+ " }\n " +
1379+ " void test() {\n " +
1380+ " print who()\n " +
1381+ " new D().test()\n " +
1382+ " }\n " +
1383+ " class D {\n " +
1384+ " void test() {\n " +
1385+ " print who()\n " + // resolves to static import
1386+ " }\n " +
1387+ " }\n " +
1388+ "}\n " +
1389+ "new C().test()\n " ,
1390+
1391+ "p/Q.java" ,
1392+ "package p;\n " +
1393+ "public class Q {\n " +
1394+ " public static String who() {\n " +
1395+ " return \" Q\" ;\n " +
1396+ " }\n " +
1397+ "}\n " ,
1398+ };
1399+ //@formatter:on
1400+
1401+ runConformTest (sources , "CC" );
1402+ }
1403+
1404+ @ Test // GROOVY-5239
1405+ public void testStaticImportVersusOuterClassMethod2 () {
1406+ //@formatter:off
1407+ String [] sources = {
1408+ "Main.groovy" ,
1409+ "import static p.Q.who\n " +
1410+ "class C {\n " +
1411+ " def who() {\n " +
1412+ " 'C'\n " +
1413+ " }\n " +
1414+ "}\n " +
1415+ "class D extends C {\n " +
1416+ " void test() {\n " +
1417+ " print who()\n " +
1418+ " new E().test()\n " +
1419+ " }\n " +
1420+ " class E {\n " +
1421+ " void test() {\n " +
1422+ " print who()\n " + // resolves to static import
1423+ " }\n " +
1424+ " }\n " +
1425+ "}\n " +
1426+ "new D().test()\n " ,
1427+
1428+ "p/Q.java" ,
1429+ "package p;\n " +
1430+ "public class Q {\n " +
1431+ " public static String who() {\n " +
1432+ " return \" Q\" ;\n " +
1433+ " }\n " +
1434+ "}\n " ,
1435+ };
1436+ //@formatter:on
1437+
1438+ runConformTest (sources , "CC" );
1439+ }
13681440}
Original file line number Diff line number Diff line change @@ -253,7 +253,8 @@ protected Expression transformMethodCallExpression(MethodCallExpression mce) {
253253
254254 if (mce .isImplicitThis () || isExplicitThisOrSuper ) {
255255 if (mce .isImplicitThis ()) {
256- if (null == currentClass .tryFindPossibleMethod (mce .getMethodAsString (), args )) {
256+ if (currentClass .tryFindPossibleMethod (mce .getMethodAsString (), args ) == null // GRECLIPSE add -- GROOVY-5239
257+ && currentClass .getOuterClasses ().stream ().noneMatch (oc -> oc .tryFindPossibleMethod (mce .getMethodAsString (), args ) != null )) {
257258 Expression ret = findStaticMethodImportFromModule (method , args );
258259 if (ret != null ) {
259260 // GRECLIPSE add
Original file line number Diff line number Diff line change @@ -252,7 +252,8 @@ protected Expression transformMethodCallExpression(MethodCallExpression mce) {
252252 Expression args = transform (mce .getArguments ());
253253
254254 if (mce .isImplicitThis ()) {
255- if (currentClass .tryFindPossibleMethod (mce .getMethodAsString (), args ) == null ) {
255+ if (currentClass .tryFindPossibleMethod (mce .getMethodAsString (), args ) == null // GRECLIPSE add -- GROOVY-5239
256+ && currentClass .getOuterClasses ().stream ().noneMatch (oc -> oc .tryFindPossibleMethod (mce .getMethodAsString (), args ) != null )) {
256257 Expression result = findStaticMethodImportFromModule (method , args );
257258 if (result != null ) {
258259 // GRECLIPSE add
Original file line number Diff line number Diff line change @@ -252,7 +252,8 @@ protected Expression transformMethodCallExpression(MethodCallExpression mce) {
252252 Expression args = transform (mce .getArguments ());
253253
254254 if (mce .isImplicitThis ()) {
255- if (currentClass .tryFindPossibleMethod (mce .getMethodAsString (), args ) == null ) {
255+ if (currentClass .tryFindPossibleMethod (mce .getMethodAsString (), args ) == null // GRECLIPSE add -- GROOVY-5239
256+ && currentClass .getOuterClasses ().stream ().noneMatch (oc -> oc .tryFindPossibleMethod (mce .getMethodAsString (), args ) != null )) {
256257 Expression result = findStaticMethodImportFromModule (method , args );
257258 if (result != null ) {
258259 // GRECLIPSE add
You can’t perform that action at this time.
0 commit comments