Mon, 29 Sep 2008 11:38:56 -0700
6739427: -Xlint:processing not recognized as an option
Reviewed-by: darcy, jjg
Contributed-by: lipeng@google.com
1 /*
2 * Copyright 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 */
26 package com.sun.tools.classfile;
28 import java.util.List;
30 /*
31 * <p><b>This is NOT part of any API supported by Sun Microsystems. If
32 * you write code that depends on this, you do so at your own risk.
33 * This code and its internal interfaces are subject to change or
34 * deletion without notice.</b>
35 */
36 public class Type {
37 protected Type() { }
39 protected static void append(StringBuilder sb, String prefix, List<? extends Type> types, String suffix) {
40 sb.append(prefix);
41 String sep = "";
42 for (Type t: types) {
43 sb.append(sep);
44 sb.append(t);
45 sep = ", ";
46 }
47 sb.append(suffix);
48 }
50 protected static void appendIfNotEmpty(StringBuilder sb, String prefix, List<? extends Type> types, String suffix) {
51 if (types != null && types.size() > 0)
52 append(sb, prefix, types, suffix);
53 }
55 public static class SimpleType extends Type {
56 public SimpleType(String name) {
57 this.name = name;
58 }
60 @Override
61 public String toString() {
62 return name;
63 }
65 public final String name;
66 }
68 public static class ArrayType extends Type {
69 public ArrayType(Type elemType) {
70 this.elemType = elemType;
71 }
73 @Override
74 public String toString() {
75 return elemType + "[]";
76 }
78 public final Type elemType;
79 }
81 public static class MethodType extends Type {
82 public MethodType(List<? extends Type> argTypes, Type resultType) {
83 this(null, argTypes, resultType, null);
84 }
86 public MethodType(List<? extends Type> typeArgTypes,
87 List<? extends Type> argTypes,
88 Type returnType,
89 List<? extends Type> throwsTypes) {
90 this.typeArgTypes = typeArgTypes;
91 this.argTypes = argTypes;
92 this.returnType = returnType;
93 this.throwsTypes = throwsTypes;
94 }
96 @Override
97 public String toString() {
98 StringBuilder sb = new StringBuilder();
99 appendIfNotEmpty(sb, "<", typeArgTypes, "> ");
100 sb.append(returnType);
101 append(sb, " (", argTypes, ")");
102 appendIfNotEmpty(sb, " throws ", throwsTypes, "");
103 return sb.toString();
104 }
106 public final List<? extends Type> typeArgTypes;
107 public final List<? extends Type> argTypes;
108 public final Type returnType;
109 public final List<? extends Type> throwsTypes;
110 }
112 public static class ClassSigType extends Type {
113 public ClassSigType(List<Type> typeArgTypes, Type superclassType, List<Type> superinterfaceTypes) {
114 this.typeArgTypes = typeArgTypes;
115 this.superclassType = superclassType;
116 this.superinterfaceTypes = superinterfaceTypes;
117 }
119 @Override
120 public String toString() {
121 StringBuilder sb = new StringBuilder();
122 appendIfNotEmpty(sb, "<", typeArgTypes, ">");
123 if (superclassType != null) {
124 sb.append(" extends ");
125 sb.append(superclassType);
126 }
127 appendIfNotEmpty(sb, " implements ", superinterfaceTypes, "");
128 return sb.toString();
129 }
131 public final List<Type> typeArgTypes;
132 public final Type superclassType;
133 public final List<Type> superinterfaceTypes;
134 }
136 public static class ClassType extends Type {
137 public ClassType(String name, List<Type> typeArgs) {
138 this.name = name;
139 this.typeArgs = typeArgs;
140 }
142 @Override
143 public String toString() {
144 StringBuilder sb = new StringBuilder();
145 sb.append(name);
146 appendIfNotEmpty(sb, "<", typeArgs, ">");
147 return sb.toString();
148 }
150 public final String name;
151 public final List<Type> typeArgs;
152 }
155 public static class InnerClassType extends Type {
156 public InnerClassType(Type outerType, Type innerType) {
157 this.outerType = outerType;
158 this.innerType = innerType;
159 }
161 @Override
162 public String toString() {
163 return outerType + "." + innerType;
164 }
166 public final Type outerType;
167 public final Type innerType;
168 }
170 public static class TypeArgType extends Type {
171 public TypeArgType(String name, Type classBound, List<Type> interfaceBounds) {
172 this.name = name;
173 this.classBound = classBound;
174 this.interfaceBounds = interfaceBounds;
175 }
177 @Override
178 public String toString() {
179 StringBuilder sb = new StringBuilder();
180 sb.append(name);
181 String sep = " extends ";
182 if (classBound != null) {
183 sb.append(sep);
184 sb.append(classBound);
185 sep = " & ";
186 }
187 if (interfaceBounds != null) {
188 for (Type bound: interfaceBounds) {
189 sb.append(sep);
190 sb.append(bound);
191 sep = " & ";
192 }
193 }
194 return sb.toString();
195 }
197 public final String name;
198 public final Type classBound;
199 public final List<Type> interfaceBounds;
200 }
202 public static class WildcardType extends Type {
203 public WildcardType() {
204 this(null, null);
205 }
207 public WildcardType(String kind, Type boundType) {
208 this.kind = kind;
209 this.boundType = boundType;
210 }
212 @Override
213 public String toString() {
214 if (kind == null)
215 return "?";
216 else
217 return "? " + kind + " " + boundType;
218 }
220 public final String kind;
221 public final Type boundType;
222 }
223 }