16
16
package org .eclipse .jdt .groovy .core .tests .basic ;
17
17
18
18
import static org .eclipse .jdt .groovy .core .tests .GroovyBundle .isAtLeastGroovy ;
19
- import static org .junit .Assume .assumeTrue ;
20
19
21
- import org .junit .Ignore ;
22
20
import org .junit .Test ;
23
21
24
22
public final class InnerClassTests extends GroovyCompilerTestSuite {
@@ -608,7 +606,7 @@ public void testAnonymousInnerClass11() {
608
606
String [] sources = {
609
607
"A.groovy" ,
610
608
"class A {" +
611
- // field with anon. inner initializer argument:
609
+ // field initializer with anon. inner argument:
612
610
" C cee = new C(1, '2', new Runnable() {\n " +
613
611
" void run() {\n " +
614
612
" println 'hi!'\n " +
@@ -652,7 +650,7 @@ public void testAnonymousInnerClass11a() {
652
650
String [] sources = {
653
651
"A.groovy" ,
654
652
"class A {" +
655
- // field with anon. inner initializer argument:
653
+ // field initializer with anon. inner argument:
656
654
" C cee = newC(1, '2', new Runnable() {\n " +
657
655
" void run() {\n " +
658
656
" }\n " +
@@ -697,7 +695,7 @@ public void testAnonymousInnerClass11b() {
697
695
String [] sources = {
698
696
"A.groovy" ,
699
697
"class A {" +
700
- // field with anon. inner initializer argument:
698
+ // field initializer with anon. inner argument:
701
699
" C cee = newC().one(1).two('2').three(new Runnable() {\n " +
702
700
" void run() {\n " +
703
701
" }\n " +
@@ -752,7 +750,7 @@ public void testAnonymousInnerClass12() {
752
750
"A.groovy" ,
753
751
"class A {" +
754
752
" static main(args) {\n " +
755
- // local with anon. inner initializer argument:
753
+ // local initializer with anon. inner argument:
756
754
" C cee = new C(1, '2', new Runnable() {\n " +
757
755
" void run() {\n " +
758
756
" println 'hi!'\n " +
@@ -843,6 +841,30 @@ public void testAnonymousInnerClass14() {
843
841
runNegativeTest (sources , "" );
844
842
}
845
843
844
+ @ Test
845
+ public void testAnonymousInnerClass14a () {
846
+ //@formatter:off
847
+ String [] sources = {
848
+ "C.groovy" ,
849
+ "class C {\n " +
850
+ " static int count\n " +
851
+ " @SuppressWarnings('rawtypes')\n " +
852
+ " static def m() {\n " +
853
+ " new LinkedList() {\n " +
854
+ " @Override\n " +
855
+ " def get(int i) {\n " +
856
+ " setCount(getCount() + 1)\n " +
857
+ " super.get(i)\n " +
858
+ " }\n " +
859
+ " }\n " +
860
+ " }\n " +
861
+ "}\n " ,
862
+ };
863
+ //@formatter:on
864
+
865
+ runNegativeTest (sources , "" );
866
+ }
867
+
846
868
@ Test
847
869
public void testAnonymousInnerClass15 () {
848
870
//@formatter:off
@@ -892,8 +914,6 @@ public void testAnonymousInnerClass16() {
892
914
893
915
@ Test // https://issues.apache.org/jira/browse/GROOVY-5961
894
916
public void testAnonymousInnerClass17 () {
895
- assumeTrue (isAtLeastGroovy (25 ));
896
-
897
917
//@formatter:off
898
918
String [] sources = {
899
919
"Script.groovy" ,
@@ -916,8 +936,6 @@ public void testAnonymousInnerClass17() {
916
936
917
937
@ Test // https://issues.apache.org/jira/browse/GROOVY-5961
918
938
public void testAnonymousInnerClass18 () {
919
- assumeTrue (isAtLeastGroovy (25 ));
920
-
921
939
//@formatter:off
922
940
String [] sources = {
923
941
"Abstract.groovy" ,
@@ -999,7 +1017,7 @@ public void testAnonymousInnerClass20() {
999
1017
runConformTest (sources , "foo" );
1000
1018
}
1001
1019
1002
- @ Test @ Ignore // https://issues.apache.org/jira/browse/GROOVY-6809
1020
+ @ Test // https://issues.apache.org/jira/browse/GROOVY-6809
1003
1021
public void testAnonymousInnerClass21 () {
1004
1022
//@formatter:off
1005
1023
String [] sources = {
@@ -1025,7 +1043,7 @@ public void testAnonymousInnerClass21() {
1025
1043
runConformTest (sources , "works" );
1026
1044
}
1027
1045
1028
- @ Test @ Ignore // https://issues.apache.org/jira/browse/GROOVY-9168
1046
+ @ Test // https://issues.apache.org/jira/browse/GROOVY-9168
1029
1047
public void testAnonymousInnerClass22 () {
1030
1048
//@formatter:off
1031
1049
String [] sources = {
@@ -1050,7 +1068,7 @@ public void testAnonymousInnerClass22() {
1050
1068
runConformTest (sources , "works" );
1051
1069
}
1052
1070
1053
- @ Test @ Ignore // https://issues.apache.org/jira/browse/GROOVY-6809
1071
+ @ Test // https://issues.apache.org/jira/browse/GROOVY-6809
1054
1072
public void testAnonymousInnerClass23 () {
1055
1073
//@formatter:off
1056
1074
String [] sources = {
@@ -1079,7 +1097,7 @@ public void testAnonymousInnerClass23() {
1079
1097
runConformTest (sources , "works" );
1080
1098
}
1081
1099
1082
- @ Test @ Ignore // https://issues.apache.org/jira/browse/GROOVY-6809
1100
+ @ Test // https://issues.apache.org/jira/browse/GROOVY-6809
1083
1101
public void testAnonymousInnerClass23a () {
1084
1102
//@formatter:off
1085
1103
String [] sources = {
@@ -1128,8 +1146,32 @@ public void testAnonymousInnerClass24() {
1128
1146
runConformTest (sources , "works" );
1129
1147
}
1130
1148
1131
- @ Test @ Ignore
1149
+ @ Test // https://issues.apache.org/jira/browse/GROOVY-9168
1132
1150
public void testAnonymousInnerClass24a () {
1151
+ //@formatter:off
1152
+ String [] sources = {
1153
+ "Main.groovy" ,
1154
+ "class Main {\n " +
1155
+ " static main(args) {\n " +
1156
+ " this.meth()\n " +
1157
+ " }\n " +
1158
+ // default argument with anon. inner initializer:
1159
+ " static void meth(Runnable action = new Runnable() {\n " +
1160
+ " @Override void run() {\n " +
1161
+ " print 'works'\n " +
1162
+ " }\n " +
1163
+ " }) {\n " +
1164
+ " action.run()\n " +
1165
+ " }\n " +
1166
+ "}\n " ,
1167
+ };
1168
+ //@formatter:on
1169
+
1170
+ runConformTest (sources , "works" );
1171
+ }
1172
+
1173
+ @ Test // https://issues.apache.org/jira/browse/GROOVY-9168
1174
+ public void testAnonymousInnerClass24b () {
1133
1175
//@formatter:off
1134
1176
String [] sources = {
1135
1177
"Script.groovy" ,
@@ -1267,7 +1309,13 @@ public void testReferenceToUninitializedThis1() {
1267
1309
};
1268
1310
//@formatter:on
1269
1311
1270
- runConformTest (sources , "" , "java.lang.VerifyError: Bad type on operand stack\n " );
1312
+ runNegativeTest (sources ,
1313
+ "----------\n " +
1314
+ "1. ERROR in Outer.groovy (at line 6)\n " +
1315
+ "\t Outer() {\n " +
1316
+ "\t ^\n " +
1317
+ "Groovy:Cannot reference 'this' before supertype constructor has been called.\n " +
1318
+ "----------\n " );
1271
1319
}
1272
1320
1273
1321
@ Test
@@ -1286,10 +1334,10 @@ public void testReferenceToUninitializedThis1a() {
1286
1334
1287
1335
runNegativeTest (sources ,
1288
1336
"----------\n " +
1289
- "1. ERROR in Outer.groovy (at line 1 )\n " +
1290
- "\t class Outer {\n " +
1337
+ "1. ERROR in Outer.groovy (at line 4 )\n " +
1338
+ "\t Outer(Inner inner = new Inner()) {\n " +
1291
1339
"\t ^\n " +
1292
- "Groovy:Apparent variable 'this' was found in a static scope but doesn't refer to a local variable, static field or class .\n " +
1340
+ "Groovy:Cannot reference 'this' before supertype constructor has been called .\n " +
1293
1341
"----------\n " );
1294
1342
}
1295
1343
@@ -1310,8 +1358,8 @@ public void testReferenceToUninitializedThis2() {
1310
1358
"----------\n " +
1311
1359
"1. ERROR in C.groovy (at line 2)\n " +
1312
1360
"\t C(foo = bar()) {\n " +
1313
- "\t ^ ^^^\n " +
1314
- "Groovy:Can't access instance method 'bar' for a constructor parameter default value \n " +
1361
+ "\t ^^^\n " +
1362
+ "Groovy:Cannot reference 'bar' before supertype constructor has been called. \n " +
1315
1363
"----------\n " );
1316
1364
}
1317
1365
@@ -1332,8 +1380,8 @@ public void testReferenceToUninitializedThis2a() {
1332
1380
"----------\n " +
1333
1381
"1. ERROR in C.groovy (at line 2)\n " +
1334
1382
"\t C(foo = this.bar()) {\n " +
1335
- "\t ^^^^\n " +
1336
- "Groovy:Can't access instance method 'bar' for a constructor parameter default value \n " +
1383
+ "\t ^^^^\n " +
1384
+ "Groovy:Cannot reference 'this' before supertype constructor has been called. \n " +
1337
1385
"----------\n " );
1338
1386
}
1339
1387
@@ -1355,12 +1403,7 @@ public void testReferenceToUninitializedThis2b() {
1355
1403
"1. ERROR in C.groovy (at line 2)\n " +
1356
1404
"\t C(foo = this.&bar) {\n " +
1357
1405
"\t ^^^^\n " +
1358
- "Groovy:Apparent variable 'this' was found in a static scope but doesn't refer to a local variable, static field or class.\n " +
1359
- "----------\n " +
1360
- "2. ERROR in C.groovy (at line 2)\n " +
1361
- "\t C(foo = this.&bar) {\n " +
1362
- "\t ^^^^\n " +
1363
- "Groovy:cannot reference this inside of this ((java.lang.Object) this.&bar)(....) before supertype constructor has been called\n " +
1406
+ "Groovy:Cannot reference 'this' before supertype constructor has been called.\n " +
1364
1407
"----------\n " );
1365
1408
}
1366
1409
@@ -1382,7 +1425,7 @@ public void testReferenceToUninitializedThis3() {
1382
1425
"1. ERROR in C.groovy (at line 2)\n " +
1383
1426
"\t C(foo = bar) {\n " +
1384
1427
"\t ^^^\n " +
1385
- "Groovy:Apparent variable 'bar' was found in a static scope but doesn't refer to a local variable, static field or class .\n " +
1428
+ "Groovy:Cannot reference 'bar' before supertype constructor has been called .\n " +
1386
1429
"----------\n " );
1387
1430
}
1388
1431
@@ -1404,12 +1447,7 @@ public void testReferenceToUninitializedThis3a() {
1404
1447
"1. ERROR in C.groovy (at line 2)\n " +
1405
1448
"\t C(foo = this.bar) {\n " +
1406
1449
"\t ^^^^\n " +
1407
- "Groovy:Apparent variable 'this' was found in a static scope but doesn't refer to a local variable, static field or class.\n " +
1408
- "----------\n " +
1409
- "2. ERROR in C.groovy (at line 2)\n " +
1410
- "\t C(foo = this.bar) {\n " +
1411
- "\t ^^^^\n " +
1412
- "Groovy:cannot reference this inside of this ((java.lang.Object) this.bar)(....) before supertype constructor has been called\n " +
1450
+ "Groovy:Cannot reference 'this' before supertype constructor has been called.\n " +
1413
1451
"----------\n " );
1414
1452
}
1415
1453
@@ -1431,12 +1469,7 @@ public void testReferenceToUninitializedThis3b() {
1431
1469
"1. ERROR in C.groovy (at line 2)\n " +
1432
1470
"\t C(foo = this.@bar) {\n " +
1433
1471
"\t ^^^^\n " +
1434
- "Groovy:Apparent variable 'this' was found in a static scope but doesn't refer to a local variable, static field or class.\n " +
1435
- "----------\n " +
1436
- "2. ERROR in C.groovy (at line 2)\n " +
1437
- "\t C(foo = this.@bar) {\n " +
1438
- "\t ^^^^\n " +
1439
- "Groovy:cannot reference this inside of this ((java.lang.Object) this.bar)(....) before supertype constructor has been called\n " +
1472
+ "Groovy:Cannot reference 'this' before supertype constructor has been called.\n " +
1440
1473
"----------\n " );
1441
1474
}
1442
1475
0 commit comments