Skip to content

Commit

Permalink
Fix for #1300: emulate Groovy scope rules for class header in Java model
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Dec 23, 2021
1 parent b8a747f commit 153cef8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,7 @@ public void testLocalAnnotationClassLiteral() {
runConformTest(sources);
}

@Test
@Test // https://issues.apache.org/jira/browse/GROOVY-8063
public void testLocalAnnotationClassLiteral2() {
//@formatter:off
String[] sources = {
Expand All @@ -1104,17 +1104,7 @@ public void testLocalAnnotationClassLiteral2() {
};
//@formatter:on

runNegativeTest(sources, "----------\n" +
"1. ERROR in Main.groovy (at line 1)\n" +
"\t@Anno(Inner)\n" +
"\t ^^^^^\n" +
"Inner cannot be resolved\n" +
"----------\n" +
"2. ERROR in Main.groovy (at line 1)\n" +
"\t@Anno(Inner)\n" +
"\t ^^^^^\n" +
"Inner cannot be resolved or is not a field\n" +
"----------\n");
runNegativeTest(sources, "");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,30 @@ public void testInnerTypeReferencing6() {
runConformTest(sources, "VALUE");
}

@Test // https://github.com/groovy/groovy-eclipse/issues/1300
public void testInnerTypeReferencing7() {
//@formatter:off
String[] sources = {
"Main.java",
"public class Main {\n" +
" public static void main(String[] args) {\n" +
" Outer.Inner result = new Outer().getResult();\n" +
" }\n" +
"}\n",

"Types.groovy",
"class Outer extends Type<Inner> {\n" + // unqualified reference to Inner
" static class Inner { }\n" +
"}\n" +
"abstract class Type<T> {\n" +
" T result\n" +
"}\n",
};
//@formatter:on

runConformTest(sources);
}

@Test
public void testInnerClass1() {
//@formatter:off
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ protected ImportBinding[] getDefaultImports() {
* static class Inner {}
* }
*/
//for (SourceTypeBinding topLevelType : topLevelTypes) {
// if (topLevelType.hasMemberTypes()) // add synthetic import to help resolve inner types
// importBindings.add(new ImportBinding(topLevelType.compoundName, true, topLevelType, null));
//}
for (SourceTypeBinding topLevelType : topLevelTypes) {
if (topLevelType.hasMemberTypes()) // add synthetic import to help resolve inner types
importBindings.add(new ImportBinding(topLevelType.compoundName, true, topLevelType, null));
}

defaultGroovyImports = importBindings.toArray(new ImportBinding[importBindings.size()]);
}
Expand Down

0 comments on commit 153cef8

Please sign in to comment.