author | tonyp |
Wed, 19 Aug 2009 12:53:25 -0400 | |
changeset 3691 | c84b8483cd2c |
parent 2678 | 57cf2a1c1a05 |
permissions | -rw-r--r-- |
8 | 1 |
/* |
2678
57cf2a1c1a05
6831313: update jaxws in OpenJDK7 to 2.1 plus bug fixes from OpenJDK 6
tbell
parents:
8
diff
changeset
|
2 |
* Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved. |
8 | 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 |
package com.sun.codemodel.internal; |
|
26 |
||
27 |
import java.util.Iterator; |
|
28 |
import java.util.List; |
|
29 |
import java.util.Collections; |
|
30 |
import java.util.ArrayList; |
|
31 |
||
32 |
/** |
|
33 |
* Represents X<Y>. |
|
34 |
* |
|
35 |
* TODO: consider separating the decl and the use. |
|
36 |
* |
|
37 |
* @author |
|
38 |
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com) |
|
39 |
*/ |
|
40 |
class JNarrowedClass extends JClass { |
|
41 |
/** |
|
42 |
* A generic class with type parameters. |
|
43 |
*/ |
|
44 |
final JClass basis; |
|
45 |
/** |
|
46 |
* Arguments to those parameters. |
|
47 |
*/ |
|
48 |
private final List<JClass> args; |
|
49 |
||
50 |
JNarrowedClass(JClass basis, JClass arg) { |
|
51 |
this(basis,Collections.singletonList(arg)); |
|
52 |
} |
|
53 |
||
54 |
JNarrowedClass(JClass basis, List<JClass> args) { |
|
55 |
super(basis.owner()); |
|
56 |
this.basis = basis; |
|
57 |
assert !(basis instanceof JNarrowedClass); |
|
58 |
this.args = args; |
|
59 |
} |
|
60 |
||
61 |
public JClass narrow( JClass clazz ) { |
|
62 |
List<JClass> newArgs = new ArrayList<JClass>(args); |
|
63 |
newArgs.add(clazz); |
|
64 |
return new JNarrowedClass(basis,newArgs); |
|
65 |
} |
|
66 |
||
67 |
public JClass narrow( JClass... clazz ) { |
|
68 |
List<JClass> newArgs = new ArrayList<JClass>(args); |
|
69 |
for (JClass c : clazz) |
|
70 |
newArgs.add(c); |
|
71 |
return new JNarrowedClass(basis,newArgs); |
|
72 |
} |
|
73 |
||
74 |
public String name() { |
|
75 |
StringBuffer buf = new StringBuffer(); |
|
76 |
buf.append(basis.name()); |
|
77 |
buf.append('<'); |
|
78 |
boolean first = true; |
|
79 |
for (JClass c : args) { |
|
80 |
if(first) |
|
81 |
first = false; |
|
82 |
else |
|
83 |
buf.append(','); |
|
84 |
buf.append(c.name()); |
|
85 |
} |
|
86 |
buf.append('>'); |
|
87 |
return buf.toString(); |
|
88 |
} |
|
89 |
||
90 |
public String fullName() { |
|
91 |
StringBuilder buf = new StringBuilder(); |
|
92 |
buf.append(basis.fullName()); |
|
93 |
buf.append('<'); |
|
94 |
boolean first = true; |
|
95 |
for (JClass c : args) { |
|
96 |
if(first) |
|
97 |
first = false; |
|
98 |
else |
|
99 |
buf.append(','); |
|
100 |
buf.append(c.fullName()); |
|
101 |
} |
|
102 |
buf.append('>'); |
|
103 |
return buf.toString(); |
|
104 |
} |
|
105 |
||
106 |
public String binaryName() { |
|
107 |
StringBuilder buf = new StringBuilder(); |
|
108 |
buf.append(basis.binaryName()); |
|
109 |
buf.append('<'); |
|
110 |
boolean first = true; |
|
111 |
for (JClass c : args) { |
|
112 |
if(first) |
|
113 |
first = false; |
|
114 |
else |
|
115 |
buf.append(','); |
|
116 |
buf.append(c.binaryName()); |
|
117 |
} |
|
118 |
buf.append('>'); |
|
119 |
return buf.toString(); |
|
120 |
} |
|
121 |
||
122 |
public void generate(JFormatter f) { |
|
123 |
f.t(basis).p('<').g(args).p(JFormatter.CLOSE_TYPE_ARGS); |
|
124 |
} |
|
125 |
||
126 |
@Override |
|
127 |
void printLink(JFormatter f) { |
|
128 |
basis.printLink(f); |
|
129 |
f.p("{@code <}"); |
|
130 |
boolean first = true; |
|
131 |
for( JClass c : args ) { |
|
132 |
if(first) |
|
133 |
first = false; |
|
134 |
else |
|
135 |
f.p(','); |
|
136 |
c.printLink(f); |
|
137 |
} |
|
138 |
f.p("{@code >}"); |
|
139 |
} |
|
140 |
||
141 |
public JPackage _package() { |
|
142 |
return basis._package(); |
|
143 |
} |
|
144 |
||
145 |
public JClass _extends() { |
|
146 |
JClass base = basis._extends(); |
|
147 |
if(base==null) return base; |
|
148 |
return base.substituteParams(basis.typeParams(),args); |
|
149 |
} |
|
150 |
||
151 |
public Iterator<JClass> _implements() { |
|
152 |
return new Iterator<JClass>() { |
|
153 |
private final Iterator<JClass> core = basis._implements(); |
|
154 |
public void remove() { |
|
155 |
core.remove(); |
|
156 |
} |
|
157 |
public JClass next() { |
|
158 |
return core.next().substituteParams(basis.typeParams(),args); |
|
159 |
} |
|
160 |
public boolean hasNext() { |
|
161 |
return core.hasNext(); |
|
162 |
} |
|
163 |
}; |
|
164 |
} |
|
165 |
||
166 |
public JClass erasure() { |
|
167 |
return basis; |
|
168 |
} |
|
169 |
||
170 |
public boolean isInterface() { |
|
171 |
return basis.isInterface(); |
|
172 |
} |
|
173 |
||
174 |
public boolean isAbstract() { |
|
175 |
return basis.isAbstract(); |
|
176 |
} |
|
177 |
||
178 |
public boolean isArray() { |
|
179 |
return false; |
|
180 |
} |
|
181 |
||
182 |
||
183 |
// |
|
184 |
// Equality is based on value |
|
185 |
// |
|
186 |
||
187 |
public boolean equals(Object obj) { |
|
188 |
if(!(obj instanceof JNarrowedClass)) return false; |
|
189 |
return fullName().equals(((JClass)obj).fullName()); |
|
190 |
} |
|
191 |
||
192 |
public int hashCode() { |
|
193 |
return fullName().hashCode(); |
|
194 |
} |
|
195 |
||
196 |
protected JClass substituteParams(JTypeVar[] variables, List<JClass> bindings) { |
|
197 |
JClass b = basis.substituteParams(variables,bindings); |
|
198 |
boolean different = b!=basis; |
|
199 |
||
200 |
List<JClass> clazz = new ArrayList<JClass>(args.size()); |
|
201 |
for( int i=0; i<clazz.size(); i++ ) { |
|
202 |
JClass c = args.get(i).substituteParams(variables,bindings); |
|
203 |
clazz.set(i,c); |
|
204 |
different |= c != args.get(i); |
|
205 |
} |
|
206 |
||
207 |
if(different) |
|
208 |
return new JNarrowedClass(b,clazz); |
|
209 |
else |
|
210 |
return this; |
|
211 |
} |
|
212 |
||
213 |
public List<JClass> getTypeParameters() { |
|
214 |
return args; |
|
215 |
} |
|
216 |
} |