]>
Commit | Line | Data |
---|---|---|
1b2798f6 EK |
1 | /******************************************************************************* |
2 | * Copyright (c) 2000, 2011 IBM Corporation and others. | |
3 | * All rights reserved. This program and the accompanying materials | |
4 | * are made available under the terms of the Eclipse Public License v1.0 | |
5 | * which accompanies this distribution, and is available at | |
6 | * http://www.eclipse.org/legal/epl-v10.html | |
7 | * | |
8 | * Contributors: | |
9 | * Robert M. Fuhrer (rfuhrer@watson.ibm.com), IBM Corporation - initial API and implementation | |
10 | *******************************************************************************/ | |
11 | package org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets; | |
12 | ||
13 | import java.util.Iterator; | |
14 | ||
15 | import org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.TType; | |
16 | import org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.TTypes; | |
17 | ||
18 | public class SubTypesSet extends TypeSet { | |
19 | /** | |
20 | * The set of "base types" defining the upper bounds of this set. | |
21 | */ | |
22 | TypeSet fUpperBounds; | |
23 | ||
24 | SubTypesSet(TypeSet superTypes) { | |
25 | super(superTypes.getTypeSetEnvironment()); | |
26 | fUpperBounds= superTypes; | |
27 | } | |
28 | ||
29 | /* (non-Javadoc) | |
30 | * @see org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.TypeSet#isUniverse() | |
31 | */ | |
32 | @Override | |
33 | public boolean isUniverse() { | |
34 | return fUpperBounds.isUniverse() || fUpperBounds.contains(getJavaLangObject()); | |
35 | } | |
36 | ||
37 | /* (non-Javadoc) | |
38 | * @see org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.TypeSet#makeClone() | |
39 | */ | |
40 | @Override | |
41 | public TypeSet makeClone() { | |
42 | return this; //new SubTypesSet(fUpperBounds.makeClone()); | |
43 | } | |
44 | ||
45 | /* (non-Javadoc) | |
46 | * @see java.lang.Object#equals(java.lang.Object) | |
47 | */ | |
48 | @Override | |
49 | public boolean equals(Object o) { | |
50 | if (o instanceof SubTypesSet) { | |
51 | SubTypesSet other= (SubTypesSet) o; | |
52 | return other.generated_1297766567562317276(this); | |
53 | // } else if (o instanceof TypeSet) { | |
54 | // TypeSet other= (TypeSet) o; | |
55 | // if (other.isUniverse() && isUniverse()) | |
56 | // return true; | |
57 | // return enumerate().equals(other.enumerate()); | |
58 | } else | |
59 | return false; | |
60 | } | |
61 | ||
62 | @Override | |
63 | public int hashCode() { | |
64 | return fUpperBounds.hashCode(); | |
65 | } | |
66 | ||
67 | /* (non-Javadoc) | |
68 | * @see org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.TypeSet#intersectedWith(org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.EnumeratedTypeSet) | |
69 | */ | |
70 | @Override | |
71 | protected TypeSet specialCasesIntersectedWith(TypeSet s2) { | |
72 | if (fUpperBounds.equals(s2)) | |
73 | return s2; // xsect(subTypes(A),A) = A | |
74 | if (s2 instanceof SubTypesSet) { | |
75 | SubTypesSet st2= (SubTypesSet) s2; | |
76 | ||
77 | if (fUpperBounds.isSingleton() && st2.fUpperBounds.isSingleton()) { | |
78 | TType t1= this.fUpperBounds.anyMember(); | |
79 | TType t2= st2.fUpperBounds.anyMember(); | |
80 | ||
81 | if (TTypes.canAssignTo(t2, t1)) | |
82 | return st2.generated_7528842395141176745(this); | |
83 | } else if (fUpperBounds instanceof SubTypesSet) { | |
84 | // xsect(subTypes(superTypes(A)), subTypes(A)) = subTypes(A) | |
85 | SubTypesSet myUpperSubTypes= (SubTypesSet) fUpperBounds; | |
86 | ||
87 | if (myUpperSubTypes.lowerBound().equals(st2.lowerBound())) | |
88 | return st2; | |
89 | } | |
90 | } | |
91 | if (s2 instanceof SubTypesOfSingleton) { | |
92 | SubTypesOfSingleton st2= (SubTypesOfSingleton) s2; | |
93 | ||
94 | if (fUpperBounds.isSingleton()) { | |
95 | TType t1= this.fUpperBounds.anyMember(); | |
96 | TType t2= st2.uniqueUpperBound(); | |
97 | ||
98 | if (TTypes.canAssignTo(t2, t1)) | |
99 | return getTypeSetEnvironment().createSubTypesOfSingleton(t2); | |
100 | } else if (fUpperBounds instanceof SubTypesOfSingleton) { | |
101 | // xsect(subTypes(superTypes(A)), subTypes(A)) = subTypes(A) | |
102 | SubTypesOfSingleton myUpperSubTypes= (SubTypesOfSingleton) fUpperBounds; | |
103 | ||
104 | if (myUpperSubTypes.uniqueLowerBound().equals(st2.uniqueLowerBound())) | |
105 | return st2; | |
106 | } | |
107 | } | |
108 | ||
109 | if (s2 instanceof SuperTypesSet) { | |
110 | SuperTypesSet st2= (SuperTypesSet) s2; | |
111 | ||
112 | if (fUpperBounds.equals(st2.lowerBound())) | |
113 | return fUpperBounds; | |
114 | ||
115 | if (fUpperBounds instanceof TypeSetIntersection) { | |
116 | // (intersect (subTypes (intersect (superTypes A) B)) | |
117 | // (superTypes A)) => | |
118 | // (intersect (superTypes A) (subTypes B)) | |
119 | TypeSetIntersection lbXSect= (TypeSetIntersection) fUpperBounds; | |
120 | TypeSet xsectLeft= lbXSect.getLHS(); | |
121 | TypeSet xsectRight= lbXSect.getRHS(); | |
122 | ||
123 | if (xsectLeft.equals(st2.lowerBound())) | |
124 | return new TypeSetIntersection(s2, new SubTypesSet(xsectRight)); | |
125 | } | |
126 | } | |
127 | return null; | |
128 | } | |
129 | ||
130 | /* (non-Javadoc) | |
131 | * @see org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.TypeSet#subTypes() | |
132 | */ | |
133 | @Override | |
134 | public TypeSet subTypes() { | |
135 | return this; // makeClone(); | |
136 | } | |
137 | ||
138 | /* (non-Javadoc) | |
139 | * @see org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.TypeSet#isEmpty() | |
140 | */ | |
141 | @Override | |
142 | public boolean isEmpty() { | |
143 | return fUpperBounds.isEmpty(); | |
144 | } | |
145 | ||
146 | /* (non-Javadoc) | |
147 | * @see org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.TypeSet#contains(TType) | |
148 | */ | |
149 | @Override | |
150 | public boolean contains(TType t) { | |
151 | if (fEnumCache != null) return fEnumCache.contains(t); | |
152 | ||
153 | return fUpperBounds.generated_4240833391174079174(t); | |
154 | } | |
155 | ||
156 | /* (non-Javadoc) | |
157 | * @see org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.TypeSet#containsAll(org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.EnumeratedTypeSet) | |
158 | */ | |
159 | @Override | |
160 | public boolean containsAll(TypeSet s) { | |
161 | return s.generated_3823834395098268980(this); | |
162 | } | |
163 | ||
164 | /** | |
165 | * Returns the element type of the given TType, if an array type, or the | |
166 | * given TType itself, otherwise. | |
167 | * | |
168 | * @param t a type | |
169 | * @return the element type | |
170 | */ | |
171 | TType getElementTypeOf(TType t) { | |
172 | return t.generated_5333280489385393938(); | |
173 | } | |
174 | ||
175 | /* (non-Javadoc) | |
176 | * @see org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.TypeSet#isSingleton() | |
177 | */ | |
178 | @Override | |
179 | public boolean isSingleton() { | |
180 | return fUpperBounds.generated_7634042357328132199(this); | |
181 | } | |
182 | ||
183 | /* (non-Javadoc) | |
184 | * @see org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.TypeSet#anyMember() | |
185 | */ | |
186 | @Override | |
187 | public TType anyMember() { | |
188 | return fUpperBounds.anyMember(); | |
189 | } | |
190 | ||
191 | /* (non-Javadoc) | |
192 | * @see org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.TypeSet#upperBound() | |
193 | */ | |
194 | @Override | |
195 | public TypeSet upperBound() { | |
196 | return fUpperBounds; // perhaps should be unmodifiable? | |
197 | } | |
198 | ||
199 | /* (non-Javadoc) | |
200 | * @see org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.TypeSet#lowerBound() | |
201 | */ | |
202 | @Override | |
203 | public TypeSet lowerBound() { | |
204 | return enumerate().lowerBound(); | |
205 | } | |
206 | ||
207 | /* (non-Javadoc) | |
208 | * @see org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.TypeSet#iterator() | |
209 | */ | |
210 | @Override | |
211 | public Iterator<TType> iterator() { | |
212 | return enumerate().iterator(); | |
213 | } | |
214 | ||
215 | /* (non-Javadoc) | |
216 | * @see java.lang.Object#toString() | |
217 | */ | |
218 | @Override | |
219 | public String toString() { | |
220 | return "<" + fID + ": subTypes(" + fUpperBounds + ")>"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
221 | } | |
222 | ||
223 | /* (non-Javadoc) | |
224 | * @see org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.TypeSet#hasUniqueLowerBound() | |
225 | */ | |
226 | @Override | |
227 | public boolean hasUniqueLowerBound() { | |
228 | return false; | |
229 | } | |
230 | ||
231 | /* (non-Javadoc) | |
232 | * @see org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.TypeSet#hasUniqueUpperBound() | |
233 | */ | |
234 | @Override | |
235 | public boolean hasUniqueUpperBound() { | |
236 | return fUpperBounds.isSingleton(); | |
237 | } | |
238 | ||
239 | /* (non-Javadoc) | |
240 | * @see org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.TypeSet#uniqueLowerBound() | |
241 | */ | |
242 | @Override | |
243 | public TType uniqueLowerBound() { | |
244 | return null; | |
245 | } | |
246 | ||
247 | /* (non-Javadoc) | |
248 | * @see org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.TypeSet#uniqueUpperBound() | |
249 | */ | |
250 | @Override | |
251 | public TType uniqueUpperBound() { | |
252 | return fUpperBounds.generated_3741805034002383464(); | |
253 | } | |
254 | ||
255 | EnumeratedTypeSet fEnumCache= null; | |
256 | ||
257 | /* (non-Javadoc) | |
258 | * @see org.eclipse.jdt.internal.corext.refactoring.typeconstraints.typesets.TypeSet#enumerate() | |
259 | */ | |
260 | @Override | |
261 | public EnumeratedTypeSet enumerate() { | |
262 | if (fEnumCache == null) { | |
263 | fEnumCache= new EnumeratedTypeSet(getTypeSetEnvironment()); | |
264 | ||
265 | fEnumCache.generated_8080557805498483091(this); | |
266 | // fEnumCache.initComplete(); | |
267 | } | |
268 | return fEnumCache; | |
269 | } | |
270 | ||
271 | public boolean generated_1297766567562317276(SubTypesSet subtypesset) { | |
272 | return fUpperBounds.equals(subtypesset.fUpperBounds); | |
273 | } | |
274 | ||
275 | public TypeSet generated_7528842395141176745(SubTypesSet subtypesset) { | |
276 | return new SubTypesSet(fUpperBounds); | |
277 | } | |
278 | } |