Skip to content

Commit 1ae3081

Browse files
committed
GROOVY-8947
1 parent e9b3d70 commit 1ae3081

9 files changed

Lines changed: 226 additions & 213 deletions

File tree

base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/basic/InnerClassTests.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
*/
1616
package org.eclipse.jdt.groovy.core.tests.basic;
1717

18-
import org.junit.Ignore;
18+
import static org.eclipse.jdt.groovy.core.tests.GroovyBundle.isParrotParser;
19+
import static org.junit.Assume.assumeTrue;
20+
1921
import org.junit.Test;
2022

2123
public final class InnerClassTests extends GroovyCompilerTestSuite {
@@ -323,8 +325,10 @@ public void testInnerClass7() {
323325
runConformTest(sources, "42");
324326
}
325327

326-
@Ignore @Test // GROOVY-8947
328+
@Test // GROOVY-8947
327329
public void testInnerClass8() {
330+
assumeTrue(isParrotParser());
331+
328332
//@formatter:off
329333
String[] sources = {
330334
"Script.groovy",
@@ -334,11 +338,11 @@ public void testInnerClass8() {
334338
" int p\n" +
335339
" }\n" +
336340
" static m(int n) {\n" +
337-
" new Outer().(new Inner(n))\n" + // TODO: no parens
341+
" new Outer().new Inner(n)\n" +
338342
" }\n" +
339343
"}\n" +
340344
"print Outer.m(4).p\n" +
341-
"print new Outer().(new Outer.Inner(2)).p\n", // TODO: no parens, no qualifier
345+
"print new Outer().new Inner(2).p\n",
342346
};
343347
//@formatter:on
344348

base/org.codehaus.groovy30/src/GroovyParser.g4

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,9 @@ pathExpression returns [int t]
904904
pathElement returns [int t]
905905
: nls
906906
(
907+
DOT nls NEW creator[1]
908+
{ $t = 6; }
909+
|
907910
// AT: foo.@bar selects the field (or attribute), not property
908911
(
909912
( DOT // The all-powerful dot.
@@ -918,9 +921,6 @@ pathElement returns [int t]
918921
)
919922
namePart
920923
{ $t = 1; }
921-
|
922-
DOT nls NEW creator[1]
923-
{ $t = 6; }
924924

925925
// Can always append a block, as foo{bar}
926926
| closureOrLambdaExpression

base/org.codehaus.groovy30/src/org/apache/groovy/parser/antlr4/AstBuilder.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3500,6 +3500,11 @@ public Expression visitCreator(CreatorContext ctx) {
35003500
} else {
35013501
throw createParsingFailedException("Unsupported arguments", arguments); // should never reach here
35023502
}
3503+
// GRECLIPSE add -- GROOVY-8947
3504+
if (enclosingInstanceExpression instanceof ConstructorCallExpression && classNode.getName().indexOf('.') < 0) {
3505+
classNode.setName(enclosingInstanceExpression.getType().getName() + '.' + classNode.getName());
3506+
}
3507+
// GRECLIPSE end
35033508
}
35043509

35053510
if (asBoolean(ctx.anonymousInnerClassDeclaration())) {

base/org.codehaus.groovy30/src/org/apache/groovy/parser/antlr4/GroovyParser.interp

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

base/org.codehaus.groovy30/src/org/apache/groovy/parser/antlr4/GroovyParser.java

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -9512,14 +9512,14 @@ public List<? extends NlsContext> nls() {
95129512
public NlsContext nls(int i) {
95139513
return getRuleContext(NlsContext.class,i);
95149514
}
9515-
public NamePartContext namePart() {
9516-
return getRuleContext(NamePartContext.class,0);
9517-
}
95189515
public TerminalNode DOT() { return getToken(GroovyParser.DOT, 0); }
95199516
public TerminalNode NEW() { return getToken(GroovyParser.NEW, 0); }
95209517
public CreatorContext creator() {
95219518
return getRuleContext(CreatorContext.class,0);
95229519
}
9520+
public NamePartContext namePart() {
9521+
return getRuleContext(NamePartContext.class,0);
9522+
}
95239523
public ClosureOrLambdaExpressionContext closureOrLambdaExpression() {
95249524
return getRuleContext(ClosureOrLambdaExpressionContext.class,0);
95259525
}
@@ -9571,15 +9571,29 @@ public final PathElementContext pathElement() throws RecognitionException {
95719571
switch ( getInterpreter().adaptivePredict(_input,150,_ctx) ) {
95729572
case 1:
95739573
{
9574-
setState(1456);
9574+
setState(1446);
9575+
match(DOT);
9576+
setState(1447);
9577+
nls();
9578+
setState(1448);
9579+
match(NEW);
9580+
setState(1449);
9581+
creator(1);
9582+
_localctx.t = 6;
9583+
}
9584+
break;
9585+
9586+
case 2:
9587+
{
9588+
setState(1462);
95759589
_errHandler.sync(this);
95769590
switch (_input.LA(1)) {
95779591
case SPREAD_DOT:
95789592
case SAFE_DOT:
95799593
case SAFE_CHAIN_DOT:
95809594
case DOT:
95819595
{
9582-
setState(1446);
9596+
setState(1452);
95839597
_la = _input.LA(1);
95849598
if ( !(((((_la - 62)) & ~0x3f) == 0 && ((1L << (_la - 62)) & ((1L << (SPREAD_DOT - 62)) | (1L << (SAFE_DOT - 62)) | (1L << (SAFE_CHAIN_DOT - 62)) | (1L << (DOT - 62)))) != 0)) ) {
95859599
_errHandler.recoverInline(this);
@@ -9591,20 +9605,20 @@ public final PathElementContext pathElement() throws RecognitionException {
95919605
_errHandler.reportMatch(this);
95929606
consume();
95939607
}
9594-
setState(1447);
9608+
setState(1453);
95959609
nls();
9596-
setState(1450);
9610+
setState(1456);
95979611
_errHandler.sync(this);
95989612
switch (_input.LA(1)) {
95999613
case AT:
96009614
{
9601-
setState(1448);
9615+
setState(1454);
96029616
match(AT);
96039617
}
96049618
break;
96059619
case LT:
96069620
{
9607-
setState(1449);
9621+
setState(1455);
96089622
nonWildcardTypeArguments();
96099623
}
96109624
break;
@@ -9672,43 +9686,29 @@ public final PathElementContext pathElement() throws RecognitionException {
96729686
break;
96739687
case METHOD_POINTER:
96749688
{
9675-
setState(1452);
9689+
setState(1458);
96769690
match(METHOD_POINTER);
9677-
setState(1453);
9691+
setState(1459);
96789692
nls();
96799693
}
96809694
break;
96819695
case METHOD_REFERENCE:
96829696
{
9683-
setState(1454);
9697+
setState(1460);
96849698
match(METHOD_REFERENCE);
9685-
setState(1455);
9699+
setState(1461);
96869700
nls();
96879701
}
96889702
break;
96899703
default:
96909704
throw new NoViableAltException(this);
96919705
}
9692-
setState(1458);
9706+
setState(1464);
96939707
namePart();
96949708
_localctx.t = 1;
96959709
}
96969710
break;
96979711

9698-
case 2:
9699-
{
9700-
setState(1461);
9701-
match(DOT);
9702-
setState(1462);
9703-
nls();
9704-
setState(1463);
9705-
match(NEW);
9706-
setState(1464);
9707-
creator(1);
9708-
_localctx.t = 6;
9709-
}
9710-
break;
9711-
97129712
case 3:
97139713
{
97149714
setState(1467);
@@ -12797,7 +12797,7 @@ private boolean pathExpression_sempred(PathExpressionContext _localctx, int pred
1279712797
"u\u0578\13u\3v\3v\3v\3v\3v\3v\3v\3v\3v\3v\5v\u0584\nv\3w\3w\3w\3w\5w\u058a"+
1279812798
"\nw\3w\7w\u058d\nw\fw\16w\u0590\13w\3x\3x\6x\u0594\nx\rx\16x\u0595\3x"+
1279912799
"\5x\u0599\nx\3y\3y\3y\5y\u059e\ny\3y\3y\3y\7y\u05a3\ny\fy\16y\u05a6\13"+
12800-
"y\3z\3z\3z\3z\3z\5z\u05ad\nz\3z\3z\3z\3z\5z\u05b3\nz\3z\3z\3z\3z\3z\3"+
12800+
"y\3z\3z\3z\3z\3z\3z\3z\3z\3z\3z\3z\5z\u05b3\nz\3z\3z\3z\3z\5z\u05b9\n"+
1280112801
"z\3z\3z\3z\3z\3z\3z\5z\u05c1\nz\3z\3z\3z\3z\3z\3z\3z\3z\3z\5z\u05cc\n"+
1280212802
"z\3{\3{\3{\3{\5{\u05d2\n{\3|\3|\5|\u05d6\n|\3}\5}\u05d9\n}\3}\3}\5}\u05dd"+
1280312803
"\n}\3}\3}\3~\5~\u05e2\n~\3~\3~\3~\5~\u05e7\n~\3~\3~\3\177\3\177\5\177"+
@@ -13284,16 +13284,16 @@ private boolean pathExpression_sempred(PathExpressionContext _localctx, int pred
1328413284
"\u059d\u059a\3\2\2\2\u059d\u059b\3\2\2\2\u059e\u05a4\3\2\2\2\u059f\u05a0"+
1328513285
"\5\u00f2z\2\u05a0\u05a1\by\1\2\u05a1\u05a3\3\2\2\2\u05a2\u059f\3\2\2\2"+
1328613286
"\u05a3\u05a6\3\2\2\2\u05a4\u05a2\3\2\2\2\u05a4\u05a5\3\2\2\2\u05a5\u00f1"+
13287-
"\3\2\2\2\u05a6\u05a4\3\2\2\2\u05a7\u05c0\5\u0142\u00a2\2\u05a8\u05a9\t"+
13288-
"\23\2\2\u05a9\u05ac\5\u0142\u00a2\2\u05aa\u05ad\7~\2\2\u05ab\u05ad\5\u0122"+
13289-
"\u0092\2\u05ac\u05aa\3\2\2\2\u05ac\u05ab\3\2\2\2\u05ac\u05ad\3\2\2\2\u05ad"+
13290-
"\u05b3\3\2\2\2\u05ae\u05af\7D\2\2\u05af\u05b3\5\u0142\u00a2\2\u05b0\u05b1"+
13291-
"\7E\2\2\u05b1\u05b3\5\u0142\u00a2\2\u05b2\u05a8\3\2\2\2\u05b2\u05ae\3"+
13292-
"\2\2\2\u05b2\u05b0\3\2\2\2\u05b3\u05b4\3\2\2\2\u05b4\u05b5\5\u00f4{\2"+
13293-
"\u05b5\u05b6\bz\1\2\u05b6\u05c1\3\2\2\2\u05b7\u05b8\7X\2\2\u05b8\u05b9"+
13294-
"\5\u0142\u00a2\2\u05b9\u05ba\7\'\2\2\u05ba\u05bb\5\u0118\u008d\2\u05bb"+
13287+
"\3\2\2\2\u05a6\u05a4\3\2\2\2\u05a7\u05c0\5\u0142\u00a2\2\u05a8\u05a9\7"+
13288+
"X\2\2\u05a9\u05aa\5\u0142\u00a2\2\u05aa\u05ab\7\'\2\2\u05ab\u05ac\5\u0118"+
13289+
"\u008d\2\u05ac\u05ad\bz\1\2\u05ad\u05c1\3\2\2\2\u05ae\u05af\t\23\2\2\u05af"+
13290+
"\u05b2\5\u0142\u00a2\2\u05b0\u05b3\7~\2\2\u05b1\u05b3\5\u0122\u0092\2"+
13291+
"\u05b2\u05b0\3\2\2\2\u05b2\u05b1\3\2\2\2\u05b2\u05b3\3\2\2\2\u05b3\u05b9"+
13292+
"\3\2\2\2\u05b4\u05b5\7D\2\2\u05b5\u05b9\5\u0142\u00a2\2\u05b6\u05b7\7"+
13293+
"E\2\2\u05b7\u05b9\5\u0142\u00a2\2\u05b8\u05ae\3\2\2\2\u05b8\u05b4\3\2"+
13294+
"\2\2\u05b8\u05b6\3\2\2\2\u05b9\u05ba\3\2\2\2\u05ba\u05bb\5\u00f4{\2\u05bb"+
1329513295
"\u05bc\bz\1\2\u05bc\u05c1\3\2\2\2\u05bd\u05be\5\u0086D\2\u05be\u05bf\b"+
13296-
"z\1\2\u05bf\u05c1\3\2\2\2\u05c0\u05b2\3\2\2\2\u05c0\u05b7\3\2\2\2\u05c0"+
13296+
"z\1\2\u05bf\u05c1\3\2\2\2\u05c0\u05a8\3\2\2\2\u05c0\u05b8\3\2\2\2\u05c0"+
1329713297
"\u05bd\3\2\2\2\u05c1\u05cc\3\2\2\2\u05c2\u05c3\5\u0126\u0094\2\u05c3\u05c4"+
1329813298
"\bz\1\2\u05c4\u05cc\3\2\2\2\u05c5\u05c6\5\u00f8}\2\u05c6\u05c7\bz\1\2"+
1329913299
"\u05c7\u05cc\3\2\2\2\u05c8\u05c9\5\u00fa~\2\u05c9\u05ca\bz\1\2\u05ca\u05cc"+
@@ -13413,7 +13413,7 @@ private boolean pathExpression_sempred(PathExpressionContext _localctx, int pred
1341313413
"\u041e\u0435\u0439\u043d\u0441\u044a\u0450\u0459\u0466\u0475\u047b\u0487"+
1341413414
"\u0492\u049c\u04a1\u04a9\u04b5\u04b9\u04bd\u04c4\u04c8\u04cc\u04d0\u04e3"+
1341513415
"\u04e7\u04ed\u04f3\u0506\u0521\u0524\u0564\u0574\u0576\u0583\u0589\u058e"+
13416-
"\u0595\u0598\u059d\u05a4\u05ac\u05b2\u05c0\u05cb\u05d1\u05d5\u05d8\u05dc"+
13416+
"\u0595\u0598\u059d\u05a4\u05b2\u05b8\u05c0\u05cb\u05d1\u05d5\u05d8\u05dc"+
1341713417
"\u05e1\u05e6\u05ec\u05fb\u0601\u0606\u060b\u060f\u0612\u0619\u061c\u0625"+
1341813418
"\u062d\u063a\u0646\u0652\u0656\u065a\u065e\u0664\u0669\u066e\u0670\u0675"+
1341913419
"\u067e\u0688\u068a\u0695\u0699\u069c\u06a7\u06b1\u06bb\u06c0\u06c4\u06c9"+

base/org.codehaus.groovy40/src/GroovyParser.g4

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,9 @@ pathExpression returns [int t]
907907
pathElement returns [int t]
908908
: nls
909909
(
910+
DOT nls NEW creator[1]
911+
{ $t = 6; }
912+
|
910913
// AT: foo.@bar selects the field (or attribute), not property
911914
(
912915
( DOT // The all-powerful dot.
@@ -921,9 +924,6 @@ pathElement returns [int t]
921924
)
922925
namePart
923926
{ $t = 1; }
924-
|
925-
DOT nls NEW creator[1]
926-
{ $t = 6; }
927927

928928
// Can always append a block, as foo{bar}
929929
| closureOrLambdaExpression

base/org.codehaus.groovy40/src/org/apache/groovy/parser/antlr4/AstBuilder.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3356,6 +3356,11 @@ public Expression visitCreator(final CreatorContext ctx) {
33563356
} else {
33573357
throw createParsingFailedException("Unsupported arguments", arguments); // should never reach here
33583358
}
3359+
// GRECLIPSE add -- GROOVY-8947
3360+
if (enclosingInstanceExpression instanceof ConstructorCallExpression && classNode.getName().indexOf('.') < 0) {
3361+
classNode.setName(enclosingInstanceExpression.getType().getName() + '.' + classNode.getName());
3362+
}
3363+
// GRECLIPSE end
33593364
}
33603365

33613366
if (asBoolean(ctx.anonymousInnerClassDeclaration())) {

base/org.codehaus.groovy40/src/org/apache/groovy/parser/antlr4/GroovyParser.interp

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)