author | jjg |
Thu, 10 Jun 2010 16:08:01 -0700 | |
changeset 5847 | 1908176fd6e3 |
parent 5520 | 86e4b9a9da40 |
child 7681 | 1f0819a3341f |
permissions | -rw-r--r-- |
3150 | 1 |
/* |
5520 | 2 |
* Copyright (c) 2003, 2009, Oracle and/or its affiliates. All rights reserved. |
3150 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
3150 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
3150 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5520 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
3150 | 24 |
*/ |
25 |
||
26 |
package com.sun.tools.javac.code; |
|
27 |
||
28 |
import com.sun.tools.javac.util.*; |
|
29 |
||
30 |
/** A type annotation position. |
|
31 |
* |
|
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
32 |
* <p><b>This is NOT part of any supported API. |
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
33 |
* If you write code that depends on this, you do so at your own risk. |
3150 | 34 |
* This code and its internal interfaces are subject to change or |
35 |
* deletion without notice.</b> |
|
36 |
*/ |
|
37 |
public class TypeAnnotationPosition { |
|
38 |
||
39 |
public TargetType type = TargetType.UNKNOWN; |
|
40 |
||
41 |
// For generic/array types. |
|
42 |
public List<Integer> location = List.nil(); |
|
43 |
||
44 |
// Tree position. |
|
45 |
public int pos = -1; |
|
46 |
||
47 |
// For typecasts, type tests, new (and locals, as start_pc). |
|
3151
41800a86aad3
6854796: update JSR308 impl with latest code from type-annotations repo
jjg
parents:
3150
diff
changeset
|
48 |
public boolean isValidOffset = false; |
3150 | 49 |
public int offset = -1; |
50 |
||
51 |
// For locals. arrays same length |
|
4866
21f0ac9e5a20
6918127: improve handling of TypeAnnotationPosition fields
jjg
parents:
3300
diff
changeset
|
52 |
public int[] lvarOffset = null; |
21f0ac9e5a20
6918127: improve handling of TypeAnnotationPosition fields
jjg
parents:
3300
diff
changeset
|
53 |
public int[] lvarLength = null; |
21f0ac9e5a20
6918127: improve handling of TypeAnnotationPosition fields
jjg
parents:
3300
diff
changeset
|
54 |
public int[] lvarIndex = null; |
3150 | 55 |
|
56 |
// For type parameter bound |
|
4866
21f0ac9e5a20
6918127: improve handling of TypeAnnotationPosition fields
jjg
parents:
3300
diff
changeset
|
57 |
public int bound_index = Integer.MIN_VALUE; |
3150 | 58 |
|
59 |
// For type parameter and method parameter |
|
4866
21f0ac9e5a20
6918127: improve handling of TypeAnnotationPosition fields
jjg
parents:
3300
diff
changeset
|
60 |
public int parameter_index = Integer.MIN_VALUE; |
3150 | 61 |
|
62 |
// For class extends, implements, and throws classes |
|
4866
21f0ac9e5a20
6918127: improve handling of TypeAnnotationPosition fields
jjg
parents:
3300
diff
changeset
|
63 |
public int type_index = Integer.MIN_VALUE; |
3150 | 64 |
|
65 |
// For wildcards |
|
66 |
public TypeAnnotationPosition wildcard_position = null; |
|
67 |
||
68 |
@Override |
|
69 |
public String toString() { |
|
70 |
StringBuilder sb = new StringBuilder(); |
|
71 |
sb.append('['); |
|
72 |
sb.append(type); |
|
73 |
||
74 |
switch (type) { |
|
75 |
// type case |
|
76 |
case TYPECAST: |
|
77 |
case TYPECAST_GENERIC_OR_ARRAY: |
|
78 |
// object creation |
|
79 |
case INSTANCEOF: |
|
80 |
case INSTANCEOF_GENERIC_OR_ARRAY: |
|
81 |
// new expression |
|
82 |
case NEW: |
|
83 |
case NEW_GENERIC_OR_ARRAY: |
|
84 |
case NEW_TYPE_ARGUMENT: |
|
85 |
case NEW_TYPE_ARGUMENT_GENERIC_OR_ARRAY: |
|
86 |
sb.append(", offset = "); |
|
87 |
sb.append(offset); |
|
88 |
break; |
|
89 |
// local variable |
|
90 |
case LOCAL_VARIABLE: |
|
91 |
case LOCAL_VARIABLE_GENERIC_OR_ARRAY: |
|
92 |
sb.append(", {"); |
|
93 |
for (int i = 0; i < lvarOffset.length; ++i) { |
|
94 |
if (i != 0) sb.append("; "); |
|
95 |
sb.append(", start_pc = "); |
|
96 |
sb.append(lvarOffset[i]); |
|
97 |
sb.append(", length = "); |
|
98 |
sb.append(lvarLength[i]); |
|
99 |
sb.append(", index = "); |
|
100 |
sb.append(lvarIndex[i]); |
|
101 |
} |
|
102 |
sb.append("}"); |
|
103 |
break; |
|
104 |
// method receiver |
|
105 |
case METHOD_RECEIVER: |
|
106 |
// Do nothing |
|
107 |
break; |
|
108 |
// type parameters |
|
109 |
case CLASS_TYPE_PARAMETER: |
|
110 |
case METHOD_TYPE_PARAMETER: |
|
111 |
sb.append(", param_index = "); |
|
112 |
sb.append(parameter_index); |
|
113 |
break; |
|
114 |
// type parameters bound |
|
115 |
case CLASS_TYPE_PARAMETER_BOUND: |
|
116 |
case CLASS_TYPE_PARAMETER_BOUND_GENERIC_OR_ARRAY: |
|
117 |
case METHOD_TYPE_PARAMETER_BOUND: |
|
118 |
case METHOD_TYPE_PARAMETER_BOUND_GENERIC_OR_ARRAY: |
|
119 |
sb.append(", param_index = "); |
|
120 |
sb.append(parameter_index); |
|
121 |
sb.append(", bound_index = "); |
|
122 |
sb.append(bound_index); |
|
123 |
break; |
|
124 |
// wildcard |
|
125 |
case WILDCARD_BOUND: |
|
126 |
case WILDCARD_BOUND_GENERIC_OR_ARRAY: |
|
127 |
sb.append(", wild_card = "); |
|
128 |
sb.append(wildcard_position); |
|
129 |
break; |
|
130 |
// Class extends and implements clauses |
|
131 |
case CLASS_EXTENDS: |
|
132 |
case CLASS_EXTENDS_GENERIC_OR_ARRAY: |
|
133 |
sb.append(", type_index = "); |
|
134 |
sb.append(type_index); |
|
135 |
break; |
|
136 |
// throws |
|
137 |
case THROWS: |
|
138 |
sb.append(", type_index = "); |
|
139 |
sb.append(type_index); |
|
140 |
break; |
|
141 |
case CLASS_LITERAL: |
|
4873 | 142 |
case CLASS_LITERAL_GENERIC_OR_ARRAY: |
3150 | 143 |
sb.append(", offset = "); |
144 |
sb.append(offset); |
|
145 |
break; |
|
146 |
// method parameter: not specified |
|
147 |
case METHOD_PARAMETER_GENERIC_OR_ARRAY: |
|
148 |
sb.append(", param_index = "); |
|
149 |
sb.append(parameter_index); |
|
150 |
break; |
|
151 |
// method type argument: wasn't specified |
|
152 |
case METHOD_TYPE_ARGUMENT: |
|
153 |
case METHOD_TYPE_ARGUMENT_GENERIC_OR_ARRAY: |
|
154 |
sb.append(", offset = "); |
|
155 |
sb.append(offset); |
|
156 |
sb.append(", type_index = "); |
|
157 |
sb.append(type_index); |
|
158 |
break; |
|
159 |
// We don't need to worry abut these |
|
160 |
case METHOD_RETURN_GENERIC_OR_ARRAY: |
|
161 |
case FIELD_GENERIC_OR_ARRAY: |
|
162 |
break; |
|
163 |
case UNKNOWN: |
|
164 |
break; |
|
165 |
default: |
|
166 |
// throw new AssertionError("unknown type: " + type); |
|
167 |
} |
|
168 |
||
169 |
// Append location data for generics/arrays. |
|
170 |
if (type.hasLocation()) { |
|
171 |
sb.append(", location = ("); |
|
172 |
sb.append(location); |
|
173 |
sb.append(")"); |
|
174 |
} |
|
175 |
||
176 |
sb.append(", pos = "); |
|
177 |
sb.append(pos); |
|
178 |
||
179 |
sb.append(']'); |
|
180 |
return sb.toString(); |
|
181 |
} |
|
3151
41800a86aad3
6854796: update JSR308 impl with latest code from type-annotations repo
jjg
parents:
3150
diff
changeset
|
182 |
|
41800a86aad3
6854796: update JSR308 impl with latest code from type-annotations repo
jjg
parents:
3150
diff
changeset
|
183 |
/** |
41800a86aad3
6854796: update JSR308 impl with latest code from type-annotations repo
jjg
parents:
3150
diff
changeset
|
184 |
* Indicates whether the target tree of the annotation has been optimized |
41800a86aad3
6854796: update JSR308 impl with latest code from type-annotations repo
jjg
parents:
3150
diff
changeset
|
185 |
* away from classfile or not. |
41800a86aad3
6854796: update JSR308 impl with latest code from type-annotations repo
jjg
parents:
3150
diff
changeset
|
186 |
* @return true if the target has not been optimized away |
41800a86aad3
6854796: update JSR308 impl with latest code from type-annotations repo
jjg
parents:
3150
diff
changeset
|
187 |
*/ |
41800a86aad3
6854796: update JSR308 impl with latest code from type-annotations repo
jjg
parents:
3150
diff
changeset
|
188 |
public boolean emitToClassfile() { |
41800a86aad3
6854796: update JSR308 impl with latest code from type-annotations repo
jjg
parents:
3150
diff
changeset
|
189 |
if (type == TargetType.WILDCARD_BOUND |
41800a86aad3
6854796: update JSR308 impl with latest code from type-annotations repo
jjg
parents:
3150
diff
changeset
|
190 |
|| type == TargetType.WILDCARD_BOUND_GENERIC_OR_ARRAY) |
41800a86aad3
6854796: update JSR308 impl with latest code from type-annotations repo
jjg
parents:
3150
diff
changeset
|
191 |
return wildcard_position.isValidOffset; |
41800a86aad3
6854796: update JSR308 impl with latest code from type-annotations repo
jjg
parents:
3150
diff
changeset
|
192 |
else |
41800a86aad3
6854796: update JSR308 impl with latest code from type-annotations repo
jjg
parents:
3150
diff
changeset
|
193 |
return !type.isLocal() || isValidOffset; |
41800a86aad3
6854796: update JSR308 impl with latest code from type-annotations repo
jjg
parents:
3150
diff
changeset
|
194 |
} |
3150 | 195 |
} |