|
1 /* |
|
2 * Copyright 2003-2008 Sun Microsystems, Inc. All Rights Reserved. |
|
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 |
|
7 * published by the Free Software Foundation. Sun designates this |
|
8 * particular file as subject to the "Classpath" exception as provided |
|
9 * by Sun in the LICENSE file that accompanied this code. |
|
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 * |
|
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 * CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 * have any questions. |
|
24 */ |
|
25 |
|
26 package com.sun.tools.javac.code; |
|
27 |
|
28 import com.sun.tools.javac.util.*; |
|
29 |
|
30 /** A type annotation position. |
|
31 * |
|
32 * <p><b>This is NOT part of any API supported by Sun Microsystems. If |
|
33 * you write code that depends on this, you do so at your own risk. |
|
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). |
|
48 public int offset = -1; |
|
49 |
|
50 // For locals. arrays same length |
|
51 public int[] lvarOffset = new int[] { -1 }; |
|
52 public int[] lvarLength = new int[] { -1 }; |
|
53 public int[] lvarIndex = new int[] { -1 }; |
|
54 |
|
55 // For type parameter bound |
|
56 public int bound_index = -1; |
|
57 |
|
58 // For type parameter and method parameter |
|
59 public int parameter_index = -1; |
|
60 |
|
61 // For class extends, implements, and throws classes |
|
62 public int type_index = -2; |
|
63 |
|
64 // For wildcards |
|
65 public TypeAnnotationPosition wildcard_position = null; |
|
66 |
|
67 @Override |
|
68 public String toString() { |
|
69 StringBuilder sb = new StringBuilder(); |
|
70 sb.append('['); |
|
71 sb.append(type); |
|
72 |
|
73 switch (type) { |
|
74 // type case |
|
75 case TYPECAST: |
|
76 case TYPECAST_GENERIC_OR_ARRAY: |
|
77 // object creation |
|
78 case INSTANCEOF: |
|
79 case INSTANCEOF_GENERIC_OR_ARRAY: |
|
80 // new expression |
|
81 case NEW: |
|
82 case NEW_GENERIC_OR_ARRAY: |
|
83 case NEW_TYPE_ARGUMENT: |
|
84 case NEW_TYPE_ARGUMENT_GENERIC_OR_ARRAY: |
|
85 sb.append(", offset = "); |
|
86 sb.append(offset); |
|
87 break; |
|
88 // local variable |
|
89 case LOCAL_VARIABLE: |
|
90 case LOCAL_VARIABLE_GENERIC_OR_ARRAY: |
|
91 sb.append(", {"); |
|
92 for (int i = 0; i < lvarOffset.length; ++i) { |
|
93 if (i != 0) sb.append("; "); |
|
94 sb.append(", start_pc = "); |
|
95 sb.append(lvarOffset[i]); |
|
96 sb.append(", length = "); |
|
97 sb.append(lvarLength[i]); |
|
98 sb.append(", index = "); |
|
99 sb.append(lvarIndex[i]); |
|
100 } |
|
101 sb.append("}"); |
|
102 break; |
|
103 // method receiver |
|
104 case METHOD_RECEIVER: |
|
105 // Do nothing |
|
106 break; |
|
107 // type parameters |
|
108 case CLASS_TYPE_PARAMETER: |
|
109 case METHOD_TYPE_PARAMETER: |
|
110 sb.append(", param_index = "); |
|
111 sb.append(parameter_index); |
|
112 break; |
|
113 // type parameters bound |
|
114 case CLASS_TYPE_PARAMETER_BOUND: |
|
115 case CLASS_TYPE_PARAMETER_BOUND_GENERIC_OR_ARRAY: |
|
116 case METHOD_TYPE_PARAMETER_BOUND: |
|
117 case METHOD_TYPE_PARAMETER_BOUND_GENERIC_OR_ARRAY: |
|
118 sb.append(", param_index = "); |
|
119 sb.append(parameter_index); |
|
120 sb.append(", bound_index = "); |
|
121 sb.append(bound_index); |
|
122 break; |
|
123 // wildcard |
|
124 case WILDCARD_BOUND: |
|
125 case WILDCARD_BOUND_GENERIC_OR_ARRAY: |
|
126 sb.append(", wild_card = "); |
|
127 sb.append(wildcard_position); |
|
128 break; |
|
129 // Class extends and implements clauses |
|
130 case CLASS_EXTENDS: |
|
131 case CLASS_EXTENDS_GENERIC_OR_ARRAY: |
|
132 sb.append(", type_index = "); |
|
133 sb.append(type_index); |
|
134 break; |
|
135 // throws |
|
136 case THROWS: |
|
137 sb.append(", type_index = "); |
|
138 sb.append(type_index); |
|
139 break; |
|
140 case CLASS_LITERAL: |
|
141 sb.append(", offset = "); |
|
142 sb.append(offset); |
|
143 break; |
|
144 // method parameter: not specified |
|
145 case METHOD_PARAMETER_GENERIC_OR_ARRAY: |
|
146 sb.append(", param_index = "); |
|
147 sb.append(parameter_index); |
|
148 break; |
|
149 // method type argument: wasn't specified |
|
150 case METHOD_TYPE_ARGUMENT: |
|
151 case METHOD_TYPE_ARGUMENT_GENERIC_OR_ARRAY: |
|
152 sb.append(", offset = "); |
|
153 sb.append(offset); |
|
154 sb.append(", type_index = "); |
|
155 sb.append(type_index); |
|
156 break; |
|
157 // We don't need to worry abut these |
|
158 case METHOD_RETURN_GENERIC_OR_ARRAY: |
|
159 case FIELD_GENERIC_OR_ARRAY: |
|
160 break; |
|
161 case UNKNOWN: |
|
162 break; |
|
163 default: |
|
164 // throw new AssertionError("unknown type: " + type); |
|
165 } |
|
166 |
|
167 // Append location data for generics/arrays. |
|
168 if (type.hasLocation()) { |
|
169 sb.append(", location = ("); |
|
170 sb.append(location); |
|
171 sb.append(")"); |
|
172 } |
|
173 |
|
174 sb.append(", pos = "); |
|
175 sb.append(pos); |
|
176 |
|
177 sb.append(']'); |
|
178 return sb.toString(); |
|
179 } |
|
180 } |