|
Lines 13-18
Link Here
|
| 13 |
* IBM Corporation - initial API and implementation |
13 |
* IBM Corporation - initial API and implementation |
| 14 |
* Andy Clement (GoPivotal, Inc) aclement@gopivotal.com - Contributions for |
14 |
* Andy Clement (GoPivotal, Inc) aclement@gopivotal.com - Contributions for |
| 15 |
* Bug 383624 - [1.8][compiler] Revive code generation support for type annotations (from Olivier's work) |
15 |
* Bug 383624 - [1.8][compiler] Revive code generation support for type annotations (from Olivier's work) |
|
|
16 |
* Bug 409236 - [1.8][compiler] Type annotations on intersection cast types dropped by code generator |
| 16 |
*******************************************************************************/ |
17 |
*******************************************************************************/ |
| 17 |
package org.eclipse.jdt.core.tests.compiler.regression; |
18 |
package org.eclipse.jdt.core.tests.compiler.regression; |
| 18 |
|
19 |
|
|
Lines 3060-3065
public class TypeAnnotationTest extends AbstractRegressionTest {
Link Here
|
| 3060 |
checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); |
3061 |
checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); |
| 3061 |
} |
3062 |
} |
| 3062 |
|
3063 |
|
|
|
3064 |
public void test070a_codeblocks_castWithIntersectionCast() throws Exception { |
| 3065 |
this.runConformTest( |
| 3066 |
new String[] { |
| 3067 |
"X.java", |
| 3068 |
"import java.io.*;\n" + |
| 3069 |
"public class X {\n" + |
| 3070 |
" public void foo(Object o) {\n" + |
| 3071 |
" I i = (@B(1) I & J) o;\n" + |
| 3072 |
" J j = (I & @B(2) J) o;\n" + |
| 3073 |
" }\n" + |
| 3074 |
"}\n" + |
| 3075 |
"interface I {}\n" + |
| 3076 |
"interface J {}\n", |
| 3077 |
|
| 3078 |
"B.java", |
| 3079 |
"import java.lang.annotation.*;\n" + |
| 3080 |
"@Target(ElementType.TYPE_USE)\n" + |
| 3081 |
"@Retention(RetentionPolicy.RUNTIME)\n" + |
| 3082 |
"@interface B {\n" + |
| 3083 |
" int value() default 1;\n" + |
| 3084 |
"}\n", |
| 3085 |
}, |
| 3086 |
""); |
| 3087 |
String expectedOutput = |
| 3088 |
" // Method descriptor #15 (Ljava/lang/Object;)V\n" + |
| 3089 |
" // Stack: 1, Locals: 4\n" + |
| 3090 |
" public void foo(java.lang.Object o);\n" + |
| 3091 |
" 0 aload_1 [o]\n" + |
| 3092 |
" 1 checkcast I [16]\n" + |
| 3093 |
" 4 checkcast J [18]\n" + |
| 3094 |
" 7 astore_2 [i]\n" + |
| 3095 |
" 8 aload_1 [o]\n" + |
| 3096 |
" 9 checkcast I [16]\n" + |
| 3097 |
" 12 checkcast J [18]\n" + |
| 3098 |
" 15 astore_3 [j]\n" + |
| 3099 |
" 16 return\n" + |
| 3100 |
" Line numbers:\n" + |
| 3101 |
" [pc: 0, line: 4]\n" + |
| 3102 |
" [pc: 8, line: 5]\n" + |
| 3103 |
" [pc: 16, line: 6]\n" + |
| 3104 |
" Local variable table:\n" + |
| 3105 |
" [pc: 0, pc: 17] local: this index: 0 type: X\n" + |
| 3106 |
" [pc: 0, pc: 17] local: o index: 1 type: java.lang.Object\n" + |
| 3107 |
" [pc: 8, pc: 17] local: i index: 2 type: I\n" + |
| 3108 |
" [pc: 16, pc: 17] local: j index: 3 type: J\n" + |
| 3109 |
" RuntimeVisibleTypeAnnotations: \n" + |
| 3110 |
" #27 @B(\n" + |
| 3111 |
" #28 value=(int) 1 (constant type)\n" + |
| 3112 |
" target type = 0x47 CAST\n" + |
| 3113 |
" offset = 1\n" + |
| 3114 |
" type argument index = 0\n" + |
| 3115 |
" )\n" + |
| 3116 |
" #27 @B(\n" + |
| 3117 |
" #28 value=(int) 2 (constant type)\n" + |
| 3118 |
" target type = 0x47 CAST\n" + |
| 3119 |
" offset = 9\n" + |
| 3120 |
" type argument index = 1\n" + |
| 3121 |
" )\n"; |
| 3122 |
checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); |
| 3123 |
} |
| 3124 |
|
| 3125 |
public void test070b_codeblocks_castWithIntersectionCast() throws Exception { |
| 3126 |
this.runConformTest( |
| 3127 |
new String[] { |
| 3128 |
"X.java", |
| 3129 |
"import java.io.*;\n" + |
| 3130 |
"public class X {\n" + |
| 3131 |
" public void foo(Object o) {\n" + |
| 3132 |
" System.out.println(123);\n" + |
| 3133 |
" I<String> i = (I<@B(1) String> & @B(2) J<String>) o;\n" + |
| 3134 |
" }\n" + |
| 3135 |
"}\n" + |
| 3136 |
"interface I<T> {}\n" + |
| 3137 |
"interface J<T> {}\n", |
| 3138 |
|
| 3139 |
"B.java", |
| 3140 |
"import java.lang.annotation.*;\n" + |
| 3141 |
"@Target(ElementType.TYPE_USE)\n" + |
| 3142 |
"@Retention(RetentionPolicy.RUNTIME)\n" + |
| 3143 |
"@interface B {\n" + |
| 3144 |
" int value() default 1;\n" + |
| 3145 |
"}\n", |
| 3146 |
}, |
| 3147 |
""); |
| 3148 |
String expectedOutput = |
| 3149 |
" public void foo(java.lang.Object o);\n" + |
| 3150 |
" 0 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + |
| 3151 |
" 3 bipush 123\n" + |
| 3152 |
" 5 invokevirtual java.io.PrintStream.println(int) : void [22]\n" + |
| 3153 |
" 8 aload_1 [o]\n" + |
| 3154 |
" 9 checkcast I [28]\n" + |
| 3155 |
" 12 checkcast J [30]\n" + |
| 3156 |
" 15 astore_2 [i]\n" + |
| 3157 |
" 16 return\n" + |
| 3158 |
" Line numbers:\n" + |
| 3159 |
" [pc: 0, line: 4]\n" + |
| 3160 |
" [pc: 8, line: 5]\n" + |
| 3161 |
" [pc: 16, line: 6]\n" + |
| 3162 |
" Local variable table:\n" + |
| 3163 |
" [pc: 0, pc: 17] local: this index: 0 type: X\n" + |
| 3164 |
" [pc: 0, pc: 17] local: o index: 1 type: java.lang.Object\n" + |
| 3165 |
" [pc: 16, pc: 17] local: i index: 2 type: I\n" + |
| 3166 |
" Local variable type table:\n" + |
| 3167 |
" [pc: 16, pc: 17] local: i index: 2 type: I<java.lang.String>\n" + |
| 3168 |
" RuntimeVisibleTypeAnnotations: \n" + |
| 3169 |
" #39 @B(\n" + |
| 3170 |
" #40 value=(int) 1 (constant type)\n" + |
| 3171 |
" target type = 0x47 CAST\n" + |
| 3172 |
" offset = 9\n" + |
| 3173 |
" type argument index = 0\n" + |
| 3174 |
" location = [TYPE_ARGUMENT(0)]\n" + |
| 3175 |
" )\n" + |
| 3176 |
" #39 @B(\n" + |
| 3177 |
" #40 value=(int) 2 (constant type)\n" + |
| 3178 |
" target type = 0x47 CAST\n" + |
| 3179 |
" offset = 9\n" + |
| 3180 |
" type argument index = 1\n" + |
| 3181 |
" )\n"; |
| 3182 |
checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); |
| 3183 |
} |
| 3184 |
|
| 3185 |
public void test070c_codeblocks_castTwiceInExpression() throws Exception { |
| 3186 |
this.runConformTest( |
| 3187 |
new String[] { |
| 3188 |
"X.java", |
| 3189 |
"import java.io.*;\n" + |
| 3190 |
"public class X {\n" + |
| 3191 |
" public void foo(Object o) {\n" + |
| 3192 |
" System.out.println(123);\n" + |
| 3193 |
" I i = (@B(1) I)(@B(2) J) o;\n" + |
| 3194 |
" }\n" + |
| 3195 |
"}\n" + |
| 3196 |
"interface I {}\n" + |
| 3197 |
"interface J {}\n", |
| 3198 |
|
| 3199 |
"B.java", |
| 3200 |
"import java.lang.annotation.*;\n" + |
| 3201 |
"@Target(ElementType.TYPE_USE)\n" + |
| 3202 |
"@Retention(RetentionPolicy.RUNTIME)\n" + |
| 3203 |
"@interface B {\n" + |
| 3204 |
" int value() default 1;\n" + |
| 3205 |
"}\n", |
| 3206 |
}, |
| 3207 |
""); |
| 3208 |
String expectedOutput = |
| 3209 |
" 0 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + |
| 3210 |
" 3 bipush 123\n" + |
| 3211 |
" 5 invokevirtual java.io.PrintStream.println(int) : void [22]\n" + |
| 3212 |
" 8 aload_1 [o]\n" + |
| 3213 |
" 9 checkcast J [28]\n" + |
| 3214 |
" 12 checkcast I [30]\n" + |
| 3215 |
" 15 astore_2 [i]\n" + |
| 3216 |
" 16 return\n" + |
| 3217 |
" Line numbers:\n" + |
| 3218 |
" [pc: 0, line: 4]\n" + |
| 3219 |
" [pc: 8, line: 5]\n" + |
| 3220 |
" [pc: 16, line: 6]\n" + |
| 3221 |
" Local variable table:\n" + |
| 3222 |
" [pc: 0, pc: 17] local: this index: 0 type: X\n" + |
| 3223 |
" [pc: 0, pc: 17] local: o index: 1 type: java.lang.Object\n" + |
| 3224 |
" [pc: 16, pc: 17] local: i index: 2 type: I\n" + |
| 3225 |
" RuntimeVisibleTypeAnnotations: \n" + |
| 3226 |
" #37 @B(\n" + |
| 3227 |
" #38 value=(int) 2 (constant type)\n" + |
| 3228 |
" target type = 0x47 CAST\n" + |
| 3229 |
" offset = 9\n" + |
| 3230 |
" type argument index = 0\n" + |
| 3231 |
" )\n" + |
| 3232 |
" #37 @B(\n" + |
| 3233 |
" #38 value=(int) 1 (constant type)\n" + |
| 3234 |
" target type = 0x47 CAST\n" + |
| 3235 |
" offset = 12\n" + |
| 3236 |
" type argument index = 0\n" + |
| 3237 |
" )\n"; |
| 3238 |
checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); |
| 3239 |
} |
| 3240 |
|
| 3241 |
public void test070d_codeblocks_castDoubleIntersectionCastInExpression() throws Exception { |
| 3242 |
this.runConformTest( |
| 3243 |
new String[] { |
| 3244 |
"X.java", |
| 3245 |
"import java.io.*;\n" + |
| 3246 |
"public class X {\n" + |
| 3247 |
" public void foo(Object o) {\n" + |
| 3248 |
" System.out.println(123);\n" + |
| 3249 |
" I i = (@B(1) I & J)(K & @B(2) L) o;\n" + |
| 3250 |
" }\n" + |
| 3251 |
"}\n" + |
| 3252 |
"interface I {}\n" + |
| 3253 |
"interface J {}\n" + |
| 3254 |
"interface K {}\n" + |
| 3255 |
"interface L {}\n", |
| 3256 |
|
| 3257 |
"B.java", |
| 3258 |
"import java.lang.annotation.*;\n" + |
| 3259 |
"@Target(ElementType.TYPE_USE)\n" + |
| 3260 |
"@Retention(RetentionPolicy.RUNTIME)\n" + |
| 3261 |
"@interface B {\n" + |
| 3262 |
" int value() default 1;\n" + |
| 3263 |
"}\n", |
| 3264 |
}, |
| 3265 |
""); |
| 3266 |
String expectedOutput = |
| 3267 |
" public void foo(java.lang.Object o);\n" + |
| 3268 |
" 0 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + |
| 3269 |
" 3 bipush 123\n" + |
| 3270 |
" 5 invokevirtual java.io.PrintStream.println(int) : void [22]\n" + |
| 3271 |
" 8 aload_1 [o]\n" + |
| 3272 |
" 9 checkcast K [28]\n" + |
| 3273 |
" 12 checkcast L [30]\n" + |
| 3274 |
" 15 checkcast I [32]\n" + |
| 3275 |
" 18 checkcast J [34]\n" + |
| 3276 |
" 21 astore_2 [i]\n" + |
| 3277 |
" 22 return\n" + |
| 3278 |
" Line numbers:\n" + |
| 3279 |
" [pc: 0, line: 4]\n" + |
| 3280 |
" [pc: 8, line: 5]\n" + |
| 3281 |
" [pc: 22, line: 6]\n" + |
| 3282 |
" Local variable table:\n" + |
| 3283 |
" [pc: 0, pc: 23] local: this index: 0 type: X\n" + |
| 3284 |
" [pc: 0, pc: 23] local: o index: 1 type: java.lang.Object\n" + |
| 3285 |
" [pc: 22, pc: 23] local: i index: 2 type: I\n" + |
| 3286 |
" RuntimeVisibleTypeAnnotations: \n" + |
| 3287 |
" #41 @B(\n" + |
| 3288 |
" #42 value=(int) 2 (constant type)\n" + |
| 3289 |
" target type = 0x47 CAST\n" + |
| 3290 |
" offset = 9\n" + |
| 3291 |
" type argument index = 1\n" + |
| 3292 |
" )\n" + |
| 3293 |
" #41 @B(\n" + |
| 3294 |
" #42 value=(int) 1 (constant type)\n" + |
| 3295 |
" target type = 0x47 CAST\n" + |
| 3296 |
" offset = 15\n" + |
| 3297 |
" type argument index = 0\n" + |
| 3298 |
" )\n"; |
| 3299 |
checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); |
| 3300 |
} |
| 3301 |
|
| 3063 |
public void test071_codeblocks_constructorInvocationTypeArgument() throws Exception { |
3302 |
public void test071_codeblocks_constructorInvocationTypeArgument() throws Exception { |
| 3064 |
this.runConformTest( |
3303 |
this.runConformTest( |
| 3065 |
new String[] { |
3304 |
new String[] { |