Wed, 23 Oct 2013 23:20:32 -0400
8006732: support correct bytecode storage of type annotations in multicatch
Summary: Fix issue with annotations being added before attribution, which causes multicatch not to work right and several tests to fail.
Reviewed-by: jfranck, jjg
jjg@1521 | 1 | /* |
darcy@1534 | 2 | * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. |
jjg@1521 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
jjg@1521 | 4 | * |
jjg@1521 | 5 | * This code is free software; you can redistribute it and/or modify it |
jjg@1521 | 6 | * under the terms of the GNU General Public License version 2 only, as |
jjg@1521 | 7 | * published by the Free Software Foundation. |
jjg@1521 | 8 | * |
jjg@1521 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
jjg@1521 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
jjg@1521 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
jjg@1521 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
jjg@1521 | 13 | * accompanied this code). |
jjg@1521 | 14 | * |
jjg@1521 | 15 | * You should have received a copy of the GNU General Public License version |
jjg@1521 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
jjg@1521 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
jjg@1521 | 18 | * |
jjg@1521 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
jjg@1521 | 20 | * or visit www.oracle.com if you need additional information or have any |
jjg@1521 | 21 | * questions. |
jjg@1521 | 22 | */ |
jjg@1521 | 23 | |
jjg@1521 | 24 | import static com.sun.tools.classfile.TypeAnnotation.TargetType.*; |
jjg@1521 | 25 | |
jjg@1521 | 26 | /* |
jjg@1521 | 27 | * @test |
jjg@1521 | 28 | * @summary Test population of reference info for method return |
jjg@1521 | 29 | * @compile -g Driver.java ReferenceInfoUtil.java MethodReturns.java |
jjg@1521 | 30 | * @run main Driver MethodReturns |
jjg@1521 | 31 | */ |
jjg@1521 | 32 | public class MethodReturns { |
jjg@1521 | 33 | |
jjg@1521 | 34 | // Method returns |
jjg@1521 | 35 | @TADescription(annotation = "TA", type = METHOD_RETURN) |
jjg@1521 | 36 | public String methodReturnAsPrimitive() { |
jjg@1521 | 37 | return "@TA int test() { return 0; }"; |
jjg@1521 | 38 | } |
jjg@1521 | 39 | |
jjg@1521 | 40 | @TADescription(annotation = "TA", type = METHOD_RETURN) |
jjg@1521 | 41 | public String methodReturnAsObject() { |
jjg@1521 | 42 | return "@TA Object test() { return null; }"; |
jjg@1521 | 43 | } |
jjg@1521 | 44 | |
jjg@1521 | 45 | @TADescriptions({ |
jjg@1521 | 46 | @TADescription(annotation = "TA", type = METHOD_RETURN), |
jjg@1521 | 47 | @TADescription(annotation = "TB", type = METHOD_RETURN, |
jjg@1521 | 48 | genericLocation = { 3, 0 }), |
jjg@1521 | 49 | @TADescription(annotation = "TC", type = METHOD_RETURN, |
jjg@1521 | 50 | genericLocation = { 3, 1 }), |
jjg@1521 | 51 | @TADescription(annotation = "TD", type = METHOD_RETURN, |
jjg@1521 | 52 | genericLocation = { 3, 1, 3, 0 }) |
jjg@1521 | 53 | }) |
jjg@1521 | 54 | public String methodReturnAsParametrized() { |
jjg@1521 | 55 | return "@TA Map<@TB String, @TC List<@TD String>> test() { return null; }"; |
jjg@1521 | 56 | } |
jjg@1521 | 57 | |
jjg@1521 | 58 | @TADescriptions({ |
jjg@1521 | 59 | @TADescription(annotation = "TA", type = METHOD_RETURN), |
jjg@1521 | 60 | @TADescription(annotation = "TB", type = METHOD_RETURN, |
jjg@1521 | 61 | genericLocation = { 0, 0 }), |
jjg@1521 | 62 | @TADescription(annotation = "TC", type = METHOD_RETURN, |
jjg@1521 | 63 | genericLocation = { 0, 0, 0, 0 }) |
jjg@1521 | 64 | }) |
jjg@1521 | 65 | public String methodReturnAsArray() { |
jjg@1521 | 66 | return "@TC String @TA [] @TB [] test() { return null; }"; |
jjg@1521 | 67 | } |
jjg@1521 | 68 | |
jjg@1521 | 69 | @TADescriptions({ |
jjg@1521 | 70 | @TADescription(annotation = "TA", type = METHOD_RETURN), |
jjg@1521 | 71 | @TADescription(annotation = "TB", type = METHOD_RETURN, |
jjg@1521 | 72 | genericLocation = { 0, 0 }), |
jjg@1521 | 73 | @TADescription(annotation = "TC", type = METHOD_RETURN, |
jjg@1521 | 74 | genericLocation = { 0, 0, 0, 0 }) |
jjg@1521 | 75 | }) |
jjg@1521 | 76 | public String methodReturnAsArrayOld() { |
jjg@1521 | 77 | return "@TC String test() @TA [] @TB [] { return null; }"; |
jjg@1521 | 78 | } |
jjg@1521 | 79 | |
jjg@1521 | 80 | @TADescriptions({}) |
jjg@1521 | 81 | public String methodWithDeclarationAnnotation() { |
jjg@1521 | 82 | return "@Decl String test() { return null; }"; |
jjg@1521 | 83 | } |
jjg@1521 | 84 | |
jjg@1521 | 85 | @TADescriptions({}) |
jjg@1521 | 86 | public String methodWithNoTargetAnno() { |
jjg@1521 | 87 | return "@A String test() { return null; }"; |
jjg@1521 | 88 | } |
jjg@1521 | 89 | |
jjg@1521 | 90 | // Smoke tests |
jjg@1521 | 91 | @TADescription(annotation = "TA", type = METHOD_RETURN) |
jjg@1521 | 92 | public String interfaceMethodReturnAsObject() { |
jjg@1521 | 93 | return "interface Test { @TA Object test(); }"; |
jjg@1521 | 94 | } |
jjg@1521 | 95 | |
jjg@1521 | 96 | @TADescription(annotation = "TA", type = METHOD_RETURN) |
jjg@1521 | 97 | public String abstractMethodReturnAsObject() { |
jjg@1521 | 98 | return "abstract class Test { abstract @TA Object test(); }"; |
jjg@1521 | 99 | } |
jjg@1521 | 100 | |
jjg@1521 | 101 | |
jjg@1521 | 102 | @TADescriptions({ |
jjg@1521 | 103 | @TADescription(annotation = "TA", type = METHOD_RETURN), |
jjg@1521 | 104 | @TADescription(annotation = "TB", type = METHOD_RETURN, |
jjg@1521 | 105 | genericLocation = { 3, 0 }), |
jjg@1521 | 106 | @TADescription(annotation = "TC", type = METHOD_RETURN, |
jjg@1521 | 107 | genericLocation = { 3, 1 }), |
jjg@1521 | 108 | @TADescription(annotation = "TD", type = METHOD_RETURN, |
jjg@1521 | 109 | genericLocation = { 3, 1, 3, 0 }) |
jjg@1521 | 110 | }) |
jjg@1521 | 111 | public String interfaceMethodReturnAsParametrized() { |
jjg@1521 | 112 | return "interface Test { @TA Map<@TB String, @TC List<@TD String>> test(); }"; |
jjg@1521 | 113 | } |
jjg@1521 | 114 | |
jjg@1521 | 115 | @TADescriptions({ |
jjg@1521 | 116 | @TADescription(annotation = "TA", type = METHOD_RETURN, |
jjg@1521 | 117 | genericLocation = { 3, 0 }), |
jjg@1521 | 118 | @TADescription(annotation = "TB", type = METHOD_RETURN, |
jjg@1521 | 119 | genericLocation = { 3, 0, 2, 0 }), |
jjg@1521 | 120 | @TADescription(annotation = "TC", type = METHOD_RETURN, |
jjg@1521 | 121 | genericLocation = { 3, 0, 2, 0, 1, 0 }), |
jjg@1521 | 122 | @TADescription(annotation = "TD", type = METHOD_RETURN, |
jjg@1521 | 123 | genericLocation = { 3, 0, 2, 0, 1, 0, 3, 0 }), |
jjg@1521 | 124 | @TADescription(annotation = "TE", type = METHOD_RETURN, |
jjg@1521 | 125 | genericLocation = { 3, 0, 2, 0, 1, 0, 3, 1 }), |
jjg@1521 | 126 | @TADescription(annotation = "TF", type = METHOD_RETURN, |
jjg@1521 | 127 | genericLocation = { 3, 0, 2, 0, 1, 0, 3, 1, 2, 0 }) |
jjg@1521 | 128 | }) |
jjg@1521 | 129 | public String methodReturnAsNestedWildcard() { |
jjg@1521 | 130 | return "Set<@TA ? extends @TB GOuter<String, String>. @TC GInner<@TD String, @TE ? super @TF Object>> entrySet() { return null; }"; |
jjg@1521 | 131 | } |
jjg@1521 | 132 | |
jjg@1521 | 133 | @TADescriptions({ |
jjg@1521 | 134 | @TADescription(annotation = "TA", type = METHOD_RETURN, |
jjg@1521 | 135 | genericLocation = { 3, 0, 1, 0, 3, 0 }), |
jjg@1521 | 136 | @TADescription(annotation = "TB", type = METHOD_RETURN, |
jjg@1521 | 137 | genericLocation = { 3, 0, 1, 0, 3, 1 }), |
jjg@1521 | 138 | @TADescription(annotation = "TC", type = METHOD_RETURN, |
jjg@1521 | 139 | genericLocation = { 3, 0, 1, 0, 3, 1, 2, 0 }) |
jjg@1521 | 140 | }) |
jjg@1521 | 141 | public String methodReturnAsNestedWildcard2() { |
jjg@1521 | 142 | return "class GOuter<X, Y> { class GInner<X, Y> {} } " + |
jjg@1521 | 143 | "class Test<K> { Set<GOuter<String, String>.GInner<@TA K, @TB ? extends @TC Object>> entrySet() { return null; } }"; |
jjg@1521 | 144 | } |
jjg@1521 | 145 | |
jjg@1521 | 146 | @TADescriptions({ |
jjg@1521 | 147 | @TADescription(annotation = "TB", type = METHOD_RETURN, |
jjg@1521 | 148 | genericLocation = { 3, 0, 2, 0 }), |
jjg@1521 | 149 | @TADescription(annotation = "TC", type = METHOD_RETURN, |
jjg@1521 | 150 | genericLocation = { 3, 0, 2, 0, 1, 0 }), |
jjg@1521 | 151 | }) |
jjg@1521 | 152 | public String methodReturnAsNestedWildcard3() { |
jjg@1521 | 153 | return "Set<? extends @TB GOuter<String, String>. @TC GInner<String, Object>> entrySet() { return null; }"; |
jjg@1521 | 154 | } |
jjg@1521 | 155 | |
jjg@1521 | 156 | @TADescriptions({ |
jjg@1521 | 157 | @TADescription(annotation = "TC", type = METHOD_RETURN, |
jjg@1521 | 158 | genericLocation = { 3, 0, 2, 0, 1, 0 }), |
jjg@1521 | 159 | }) |
jjg@1521 | 160 | public String methodReturnAsNestedWildcard4() { |
jjg@1521 | 161 | return "Set<? extends GOuter<String, String>. @TC GInner<String, Object>> entrySet() { return null; }"; |
jjg@1521 | 162 | } |
jjg@1521 | 163 | |
jjg@1521 | 164 | @TADescriptions({ |
jjg@1521 | 165 | @TADescription(annotation = "TB", type = METHOD_RETURN, |
jjg@1521 | 166 | genericLocation = { 3, 0, 2, 0 }), |
jjg@1521 | 167 | @TADescription(annotation = "TC", type = METHOD_RETURN, |
jjg@1521 | 168 | genericLocation = { 3, 0, 2, 0, 1, 0 }), |
jjg@1521 | 169 | }) |
jjg@1521 | 170 | public String methodReturnAsNestedWildcard5() { |
jjg@1521 | 171 | return "Set<? extends @TB Outer. @TC Inner> entrySet() { return null; }"; |
jjg@1521 | 172 | } |
jjg@1521 | 173 | |
jjg@1521 | 174 | @TADescriptions({ |
jjg@1521 | 175 | @TADescription(annotation = "TA", type = METHOD_RETURN, |
jjg@1521 | 176 | genericLocation = { 3, 0, 2, 0, 1, 0, 3, 0 }), |
jjg@1521 | 177 | @TADescription(annotation = "TB", type = METHOD_RETURN, |
jjg@1521 | 178 | genericLocation = { 3, 0, 2, 0, 1, 0, 3, 1 }), |
jjg@1521 | 179 | @TADescription(annotation = "TC", type = METHOD_RETURN, |
jjg@1521 | 180 | genericLocation = { 3, 0, 2, 0, 1, 0 }), |
jjg@1521 | 181 | }) |
jjg@1521 | 182 | public String methodReturnAsNestedWildcard6() { |
jjg@1521 | 183 | return "Set<? extends GOuter<String, String>. @TC GInner<@TA String, @TB Object>> entrySet() { return null; }"; |
jjg@1521 | 184 | } |
jjg@1521 | 185 | |
jjg@1521 | 186 | } |