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 .eclipse .jdt .groovy .core .tests .GroovyBundle .isParrotParser ;
20
+ import static org .junit .Assume .assumeTrue ;
19
21
20
22
import org .junit .Ignore ;
21
23
import org .junit .Test ;
@@ -1879,9 +1881,9 @@ public void testAnnotationsOnDefaultArgumentMethod() {
1879
1881
1880
1882
runConformTest (sources , "success" );
1881
1883
1882
- checkGCUDeclaration ("X.groovy" , "public @Anno void foo() {" );
1883
-
1884
1884
checkGCUDeclaration ("X.groovy" , "public @Anno void foo(String s) {" );
1885
+
1886
+ checkGCUDeclaration ("X.groovy" , "public @Anno @groovy.transform.Generated void foo() {" );
1885
1887
}
1886
1888
1887
1889
@ Test
@@ -2013,12 +2015,12 @@ public void testFieldLevelAnnotations_SingleMember1() {
2013
2015
//@formatter:off
2014
2016
String [] sources = {
2015
2017
"p/X.groovy" ,
2016
- "package p; \n " +
2017
- "public class X {\n " +
2018
+ "package p\n " +
2019
+ "class X {\n " +
2018
2020
" @Anno(Target.class)\n " +
2019
- " public int foo = 5 \n " +
2020
- " public static void main(String[]argv ) {\n " +
2021
- " print \" success \" \n " +
2021
+ " public int foo = 42 \n " +
2022
+ " static main(args ) {\n " +
2023
+ " print 'works' \n " +
2022
2024
" }\n " +
2023
2025
"}\n " ,
2024
2026
@@ -2030,15 +2032,125 @@ public void testFieldLevelAnnotations_SingleMember1() {
2030
2032
2031
2033
"p/Target.java" ,
2032
2034
"package p;\n " +
2033
- "class Target {}" ,
2035
+ "class Target {}\n " ,
2034
2036
};
2035
2037
//@formatter:on
2036
2038
2037
- runConformTest (sources , "success " );
2039
+ runConformTest (sources , "works " );
2038
2040
2039
2041
checkGCUDeclaration ("X.groovy" , "public @Anno(Target.class) int foo" );
2040
2042
}
2041
2043
2044
+ @ Test
2045
+ public void testFieldLevelAnnotations_SingleMember2 () {
2046
+ //@formatter:off
2047
+ String [] sources = {
2048
+ "p/X.groovy" ,
2049
+ "package p\n " +
2050
+ "class X {\n " +
2051
+ " @Anno(p.Target.class)\n " +
2052
+ " public int foo = 42\n " +
2053
+ " static main(args) {\n " +
2054
+ " print 'works'\n " +
2055
+ " }\n " +
2056
+ "}\n " ,
2057
+
2058
+ "p/Anno.java" ,
2059
+ "package p;\n " +
2060
+ "import java.lang.annotation.*;\n " +
2061
+ "@Retention(RetentionPolicy.RUNTIME)\n " +
2062
+ "@interface Anno { Class<?> value(); }\n " ,
2063
+
2064
+ "p/Target.java" ,
2065
+ "package p;\n " +
2066
+ "class Target {}\n " ,
2067
+ };
2068
+ //@formatter:on
2069
+
2070
+ runConformTest (sources , "works" );
2071
+
2072
+ checkGCUDeclaration ("X.groovy" , "public @Anno(p.Target.class) int foo" );
2073
+ }
2074
+
2075
+ @ Test
2076
+ public void testFieldLevelAnnotations_SingleMember3 () {
2077
+ //@formatter:off
2078
+ String [] sources = {
2079
+ "p/X.groovy" ,
2080
+ "package p\n " +
2081
+ "class X {\n " +
2082
+ " @Anno(IDontExist.class)\n " +
2083
+ " public int foo = 42\n " +
2084
+ " static main(args) {\n " +
2085
+ " }\n " +
2086
+ "}\n " ,
2087
+
2088
+ "p/Anno.java" ,
2089
+ "package p;\n " +
2090
+ "import java.lang.annotation.*;\n " +
2091
+ "@Retention(RetentionPolicy.RUNTIME)\n " +
2092
+ "@interface Anno { Class<?> value(); }\n " ,
2093
+ };
2094
+ //@formatter:on
2095
+
2096
+ runNegativeTest (sources ,
2097
+ "----------\n " +
2098
+ "1. ERROR in p\\ X.groovy (at line 3)\n " +
2099
+ "\t @Anno(IDontExist.class)\n " +
2100
+ "\t ^^^^^^^^^^\n " +
2101
+ "Groovy:unable to find class 'IDontExist.class' for annotation attribute constant\n " +
2102
+ "----------\n " +
2103
+ "2. ERROR in p\\ X.groovy (at line 3)\n " +
2104
+ "\t @Anno(IDontExist.class)\n " +
2105
+ "\t ^^^^^^^^^^^^^^^^\n " +
2106
+ "Groovy:Only classes and closures can be used for attribute 'value' in @p.Anno\n " +
2107
+ "----------\n " );
2108
+ }
2109
+
2110
+ @ Test
2111
+ public void testFieldLevelAnnotations_SingleMember4 () {
2112
+ //@formatter:off
2113
+ String [] sources = {
2114
+ "p/X.groovy" ,
2115
+ "package p\n " +
2116
+ "class X {\n " +
2117
+ " @SuppressWarnings(DoesNot.EXIST)\n " +
2118
+ " static main(args) {\n " +
2119
+ " }\n " +
2120
+ "}\n " ,
2121
+ };
2122
+ //@formatter:on
2123
+
2124
+ runNegativeTest (sources ,
2125
+ "----------\n " +
2126
+ "1. ERROR in p\\ X.groovy (at line 3)\n " +
2127
+ "\t @SuppressWarnings(DoesNot.EXIST)\n " +
2128
+ "\t ^^^^^^^\n " +
2129
+ "DoesNot cannot be resolved\n " +
2130
+ "----------\n " +
2131
+ "2. ERROR in p\\ X.groovy (at line 3)\n " +
2132
+ "\t @SuppressWarnings(DoesNot.EXIST)\n " +
2133
+ "\t ^^^^^^^\n " +
2134
+ "Groovy:unable to find class 'DoesNot.EXIST' for annotation attribute constant\n " +
2135
+ "----------\n " +
2136
+ "3. ERROR in p\\ X.groovy (at line 3)\n " +
2137
+ "\t @SuppressWarnings(DoesNot.EXIST)\n " +
2138
+ "\t ^^^^^^^\n " +
2139
+ "Groovy:Apparent variable 'DoesNot' was found in a static scope but doesn't refer to a local variable, static field or class.\n " +
2140
+ "----------\n " +
2141
+ "4. ERROR in p\\ X.groovy (at line 3)\n " +
2142
+ "\t @SuppressWarnings(DoesNot.EXIST)\n " +
2143
+ "\t ^^^^^^^^^^^^^\n " +
2144
+ "Groovy:Expected 'DoesNot.EXIST' to be an inline constant of type java.lang.String not a property expression in @java.lang.SuppressWarnings\n " +
2145
+ "----------\n " +
2146
+ // this error was associated with line -1
2147
+ "5. ERROR in p\\ X.groovy (at line 3)\n " +
2148
+ "\t @SuppressWarnings(DoesNot.EXIST)\n " +
2149
+ "\t ^^^^^^^^^^^^^\n " +
2150
+ "Groovy:Attribute 'value' should have type 'java.lang.String'; but found type 'java.lang.Object' in @java.lang.SuppressWarnings\n " +
2151
+ "----------\n " );
2152
+ }
2153
+
2042
2154
@ Test
2043
2155
public void testTypeLevelAnnotations_SelfReferential1 () {
2044
2156
//@formatter:off
@@ -2105,115 +2217,144 @@ public void testTypeLevelAnnotations_SelfReferential3() {
2105
2217
runNegativeTest (sources , "" );
2106
2218
}
2107
2219
2108
- @ Test
2109
- public void testAnnotations_singleMemberAnnotationField1 () {
2220
+ @ Test // https://issues.apache.org/jira/browse/GROOVY-11184
2221
+ public void testExplicitThisTypeAnnotations1 () {
2222
+ assumeTrue (isParrotParser ());
2223
+
2110
2224
//@formatter:off
2111
2225
String [] sources = {
2112
- "p/X.groovy" ,
2113
- "package p;\n " +
2114
- "public class X {\n " +
2115
- " @Anno(p.Target.class)\n " +
2116
- " public int foo = 5\n " +
2117
- " public static void main(String[]argv) {\n " +
2118
- " print \" success\" \n " +
2119
- " }\n " +
2226
+ "C.groovy" ,
2227
+ "class C {\n " +
2228
+ " def m(@p.Anno('') C this, that) {}\n " +
2120
2229
"}\n " ,
2121
2230
2122
2231
"p/Anno.java" ,
2123
2232
"package p;\n " +
2124
2233
"import java.lang.annotation.*;\n " +
2234
+ "@Target({ElementType.TYPE_USE})\n " +
2125
2235
"@Retention(RetentionPolicy.RUNTIME)\n " +
2126
- "@interface Anno { Class<?> value(); }\n " ,
2127
-
2128
- "p/Target.java" ,
2129
- "package p;\n " +
2130
- "class Target {}" ,
2236
+ "@interface Anno { String value(); }\n " ,
2131
2237
};
2132
2238
//@formatter:on
2133
2239
2134
- runConformTest (sources , "success " );
2240
+ runNegativeTest (sources , "" );
2135
2241
2136
- checkGCUDeclaration ("X.groovy" , "public @Anno(p.Target.class) int foo" );
2242
+ checkGCUDeclaration ("C.groovy" ,
2243
+ "public class C {\n " +
2244
+ " public @groovy.transform.Generated C() {\n " +
2245
+ " }\n " +
2246
+ " public java.lang.Object m(@p.Anno(\" \" ) C this, java.lang.Object that) {\n " +
2247
+ " }\n " +
2248
+ "}\n " );
2137
2249
}
2138
2250
2139
- @ Test
2140
- public void testAnnotations_singleMemberAnnotationFailure1 () {
2251
+ @ Test // https://issues.apache.org/jira/browse/GROOVY-11184
2252
+ public void testExplicitThisTypeAnnotations2 () {
2253
+ assumeTrue (isParrotParser ());
2254
+
2141
2255
//@formatter:off
2142
2256
String [] sources = {
2143
- "p/X.groovy" ,
2257
+ "p/C.groovy" ,
2258
+ "package p\n " +
2259
+ "class C {\n " +
2260
+ " def m(@Anno('') p.C this, that) {}\n " +
2261
+ "}\n " ,
2262
+
2263
+ "p/Anno.java" ,
2144
2264
"package p;\n " +
2145
- "public class X {\n " +
2146
- " @Anno(IDontExist.class)\n " +
2147
- " public int foo = 5\n " +
2148
- " public static void main(String[]argv) {\n " +
2149
- " print \" success\" \n " +
2265
+ "import java.lang.annotation.*;\n " +
2266
+ "@Target({ElementType.TYPE_USE})\n " +
2267
+ "@Retention(RetentionPolicy.RUNTIME)\n " +
2268
+ "@interface Anno { String value(); }\n " ,
2269
+ };
2270
+ //@formatter:on
2271
+
2272
+ runNegativeTest (sources , "" );
2273
+
2274
+ checkGCUDeclaration ("C.groovy" ,
2275
+ "package p;\n " +
2276
+ "public class C {\n " +
2277
+ " public @groovy.transform.Generated C() {\n " +
2278
+ " }\n " +
2279
+ " public java.lang.Object m(p.@Anno(\" \" ) C this, java.lang.Object that) {\n " +
2150
2280
" }\n " +
2281
+ "}\n " );
2282
+ }
2283
+
2284
+ @ Test // https://issues.apache.org/jira/browse/GROOVY-11184
2285
+ public void testExplicitThisTypeAnnotations3 () {
2286
+ assumeTrue (isParrotParser ());
2287
+
2288
+ //@formatter:off
2289
+ String [] sources = {
2290
+ "p/C.groovy" ,
2291
+ "package p\n " +
2292
+ "class C {\n " +
2293
+ " def m(@Anno('') C this, that = null) {}\n " +
2151
2294
"}\n " ,
2152
2295
2153
2296
"p/Anno.java" ,
2154
2297
"package p;\n " +
2155
2298
"import java.lang.annotation.*;\n " +
2299
+ "@Target({ElementType.TYPE_USE})\n " +
2156
2300
"@Retention(RetentionPolicy.RUNTIME)\n " +
2157
- "@interface Anno { Class<?> value(); }\n " ,
2301
+ "@interface Anno { String value(); }\n " ,
2158
2302
};
2159
2303
//@formatter:on
2160
2304
2161
- runNegativeTest (sources ,
2162
- "---------- \n " +
2163
- "1. ERROR in p \\ X. groovy (at line 3) \n " +
2164
- "\t @Anno(IDontExist.class) \n " +
2165
- "\t ^^^^^^^^^^ \n " +
2166
- "Groovy:unable to find class 'IDontExist.class' for annotation attribute constant \n " +
2167
- "---------- \n " +
2168
- "2. ERROR in p \\ X.groovy (at line 3) \n " +
2169
- "\t @Anno(IDontExist.class) \n " +
2170
- "\t ^^^^^^^^^^^^^^^^ \n " +
2171
- "Groovy:Only classes and closures can be used for attribute 'value' in @p.Anno \n " +
2172
- "---------- \n " );
2305
+ runNegativeTest (sources , "" );
2306
+
2307
+ checkGCUDeclaration ( "C. groovy" ,
2308
+ "package p; \n " +
2309
+ "public class C { \n " +
2310
+ " public @groovy.transform.Generated C() { \n " +
2311
+ " } \n " +
2312
+ " public java.lang.Object m(@Anno( \" \" ) C this, java.lang.Object that) { \n " +
2313
+ " } \n " +
2314
+ " public @groovy.transform.Generated java.lang.Object m(@Anno( \" \" ) C this) { \n " +
2315
+ " } \n " +
2316
+ "} \n " );
2173
2317
}
2174
2318
2175
- @ Test
2176
- public void testAnnotations_singleMemberAnnotationFailure2 () {
2319
+ @ Test // https://issues.apache.org/jira/browse/GROOVY-11184
2320
+ public void testExplicitThisTypeAnnotations4 () {
2321
+ assumeTrue (isParrotParser ());
2322
+
2177
2323
//@formatter:off
2178
2324
String [] sources = {
2179
- "p/X .groovy" ,
2180
- "package p; \n " +
2181
- "public class X {\n " +
2182
- " @SuppressWarnings(DoesNot.EXIST) \n " +
2183
- " static void main(String... args) { \n " +
2325
+ "p/C .groovy" ,
2326
+ "package p\n " +
2327
+ "class C {\n " +
2328
+ " class D { \n " +
2329
+ " D(@Anno('') C this, that" + ( isAtLeastGroovy ( 50 ) ? " = null" : "" ) + ") {} \n " +
2184
2330
" }\n " +
2185
2331
"}\n " ,
2332
+
2333
+ "p/Anno.java" ,
2334
+ "package p;\n " +
2335
+ "import java.lang.annotation.*;\n " +
2336
+ "@Target({ElementType.TYPE_USE})\n " +
2337
+ "@Retention(RetentionPolicy.RUNTIME)\n " +
2338
+ "@interface Anno { String value(); }\n " ,
2186
2339
};
2187
2340
//@formatter:on
2188
2341
2189
- runNegativeTest (sources ,
2190
- "----------\n " +
2191
- "1. ERROR in p\\ X.groovy (at line 3)\n " +
2192
- "\t @SuppressWarnings(DoesNot.EXIST)\n " +
2193
- "\t ^^^^^^^\n " +
2194
- "DoesNot cannot be resolved\n " +
2195
- "----------\n " +
2196
- "2. ERROR in p\\ X.groovy (at line 3)\n " +
2197
- "\t @SuppressWarnings(DoesNot.EXIST)\n " +
2198
- "\t ^^^^^^^\n " +
2199
- "Groovy:unable to find class 'DoesNot.EXIST' for annotation attribute constant\n " +
2200
- "----------\n " +
2201
- "3. ERROR in p\\ X.groovy (at line 3)\n " +
2202
- "\t @SuppressWarnings(DoesNot.EXIST)\n " +
2203
- "\t ^^^^^^^\n " +
2204
- "Groovy:Apparent variable 'DoesNot' was found in a static scope but doesn't refer to a local variable, static field or class.\n " +
2205
- "----------\n " +
2206
- "4. ERROR in p\\ X.groovy (at line 3)\n " +
2207
- "\t @SuppressWarnings(DoesNot.EXIST)\n " +
2208
- "\t ^^^^^^^^^^^^^\n " +
2209
- "Groovy:Expected 'DoesNot.EXIST' to be an inline constant of type java.lang.String not a property expression in @java.lang.SuppressWarnings\n " +
2210
- "----------\n " +
2211
- // this error was associated with line -1
2212
- "5. ERROR in p\\ X.groovy (at line 3)\n " +
2213
- "\t @SuppressWarnings(DoesNot.EXIST)\n " +
2214
- "\t ^^^^^^^^^^^^^\n " +
2215
- "Groovy:Attribute 'value' should have type 'java.lang.String'; but found type 'java.lang.Object' in @java.lang.SuppressWarnings\n " +
2216
- "----------\n " );
2342
+ runNegativeTest (sources , "" );
2343
+
2344
+ checkGCUDeclaration ("C.groovy" ,
2345
+ "package p;\n " +
2346
+ "public class C {\n " +
2347
+ " public class D {\n " +
2348
+ " public D(@Anno(\" \" ) C C.this, java.lang.Object that) {\n " +
2349
+ " }\n " + (isAtLeastGroovy (50 )
2350
+ ?
2351
+ " public @groovy.transform.Generated D(@Anno(\" \" ) C C.this) {\n " +
2352
+ " }\n "
2353
+ : "" ) +
2354
+ " }\n " +
2355
+ " public @groovy.transform.Generated C() {\n " +
2356
+ " }\n " +
2357
+ "}\n " );
2217
2358
}
2218
2359
2219
2360
@ Test // All types in groovy with TYPE specified for Target and obeyed
0 commit comments