Lines 10-15
Link Here
|
10 |
*******************************************************************************/ |
10 |
*******************************************************************************/ |
11 |
package org.eclipse.jdt.core.dom; |
11 |
package org.eclipse.jdt.core.dom; |
12 |
|
12 |
|
|
|
13 |
import java.util.HashSet; |
14 |
|
13 |
import org.eclipse.jdt.core.compiler.CharOperation; |
15 |
import org.eclipse.jdt.core.compiler.CharOperation; |
14 |
import org.eclipse.jdt.internal.compiler.env.IConstants; |
16 |
import org.eclipse.jdt.internal.compiler.env.IConstants; |
15 |
import org.eclipse.jdt.internal.compiler.lookup.Binding; |
17 |
import org.eclipse.jdt.internal.compiler.lookup.Binding; |
Lines 61-81
Link Here
|
61 |
* @param declaringElement2 |
63 |
* @param declaringElement2 |
62 |
* @return true if both parameters are equals, false otherwise |
64 |
* @return true if both parameters are equals, false otherwise |
63 |
*/ |
65 |
*/ |
64 |
static boolean isEqual(Binding declaringElement, Binding declaringElement2, boolean checkTypeVariables) { |
66 |
static boolean isEqual(Binding declaringElement, Binding declaringElement2, HashSet visitedTypes) { |
65 |
if (declaringElement instanceof org.eclipse.jdt.internal.compiler.lookup.TypeBinding) { |
67 |
if (declaringElement instanceof org.eclipse.jdt.internal.compiler.lookup.TypeBinding) { |
66 |
if (!(declaringElement2 instanceof org.eclipse.jdt.internal.compiler.lookup.TypeBinding)){ |
68 |
if (!(declaringElement2 instanceof org.eclipse.jdt.internal.compiler.lookup.TypeBinding)){ |
67 |
return false; |
69 |
return false; |
68 |
} |
70 |
} |
69 |
return isEqual((org.eclipse.jdt.internal.compiler.lookup.TypeBinding) declaringElement, |
71 |
return isEqual((org.eclipse.jdt.internal.compiler.lookup.TypeBinding) declaringElement, |
70 |
(org.eclipse.jdt.internal.compiler.lookup.TypeBinding) declaringElement2, |
72 |
(org.eclipse.jdt.internal.compiler.lookup.TypeBinding) declaringElement2, |
71 |
checkTypeVariables); |
73 |
visitedTypes); |
72 |
} else if (declaringElement instanceof org.eclipse.jdt.internal.compiler.lookup.MethodBinding) { |
74 |
} else if (declaringElement instanceof org.eclipse.jdt.internal.compiler.lookup.MethodBinding) { |
73 |
if (!(declaringElement2 instanceof org.eclipse.jdt.internal.compiler.lookup.MethodBinding)) { |
75 |
if (!(declaringElement2 instanceof org.eclipse.jdt.internal.compiler.lookup.MethodBinding)) { |
74 |
return false; |
76 |
return false; |
75 |
} |
77 |
} |
76 |
return isEqual((org.eclipse.jdt.internal.compiler.lookup.MethodBinding) declaringElement, |
78 |
return isEqual((org.eclipse.jdt.internal.compiler.lookup.MethodBinding) declaringElement, |
77 |
(org.eclipse.jdt.internal.compiler.lookup.MethodBinding) declaringElement2, |
79 |
(org.eclipse.jdt.internal.compiler.lookup.MethodBinding) declaringElement2, |
78 |
checkTypeVariables); |
80 |
visitedTypes); |
79 |
} else if (declaringElement instanceof VariableBinding) { |
81 |
} else if (declaringElement instanceof VariableBinding) { |
80 |
if (!(declaringElement2 instanceof VariableBinding)) { |
82 |
if (!(declaringElement2 instanceof VariableBinding)) { |
81 |
return false; |
83 |
return false; |
Lines 104-126
Link Here
|
104 |
|
106 |
|
105 |
static boolean isEqual(org.eclipse.jdt.internal.compiler.lookup.MethodBinding methodBinding, |
107 |
static boolean isEqual(org.eclipse.jdt.internal.compiler.lookup.MethodBinding methodBinding, |
106 |
org.eclipse.jdt.internal.compiler.lookup.MethodBinding methodBinding2) { |
108 |
org.eclipse.jdt.internal.compiler.lookup.MethodBinding methodBinding2) { |
107 |
return isEqual(methodBinding, methodBinding2, true); |
109 |
return isEqual(methodBinding, methodBinding2, new HashSet()); |
108 |
} |
110 |
} |
109 |
|
111 |
|
110 |
static boolean isEqual(org.eclipse.jdt.internal.compiler.lookup.MethodBinding methodBinding, |
112 |
static boolean isEqual(org.eclipse.jdt.internal.compiler.lookup.MethodBinding methodBinding, |
111 |
org.eclipse.jdt.internal.compiler.lookup.MethodBinding methodBinding2, |
113 |
org.eclipse.jdt.internal.compiler.lookup.MethodBinding methodBinding2, |
112 |
boolean checkTypeVariables) { |
114 |
HashSet visitedTypes) { |
113 |
if (checkTypeVariables) { |
|
|
114 |
if (!isEqual(methodBinding.typeVariables, methodBinding2.typeVariables, true) |
115 |
|| !isEqual(methodBinding.parameters, methodBinding2.parameters, true)) { |
116 |
return false; |
117 |
} |
118 |
} |
119 |
return (methodBinding == null && methodBinding2 == null) |
115 |
return (methodBinding == null && methodBinding2 == null) |
120 |
|| (CharOperation.equals(methodBinding.selector, methodBinding2.selector) |
116 |
|| (CharOperation.equals(methodBinding.selector, methodBinding2.selector) |
121 |
&& isEqual(methodBinding.returnType, methodBinding2.returnType, checkTypeVariables) |
117 |
&& isEqual(methodBinding.returnType, methodBinding2.returnType, visitedTypes) |
122 |
&& isEqual(methodBinding.thrownExceptions, methodBinding2.thrownExceptions, checkTypeVariables) |
118 |
&& isEqual(methodBinding.thrownExceptions, methodBinding2.thrownExceptions, visitedTypes) |
123 |
&& isEqual(methodBinding.declaringClass, methodBinding2.declaringClass, true)); |
119 |
&& isEqual(methodBinding.declaringClass, methodBinding2.declaringClass, visitedTypes) |
|
|
120 |
&& isEqual(methodBinding.typeVariables, methodBinding2.typeVariables, visitedTypes) |
121 |
&& isEqual(methodBinding.parameters, methodBinding2.parameters, visitedTypes)); |
124 |
} |
122 |
} |
125 |
|
123 |
|
126 |
static boolean isEqual(VariableBinding variableBinding, VariableBinding variableBinding2) { |
124 |
static boolean isEqual(VariableBinding variableBinding, VariableBinding variableBinding2) { |
Lines 131-140
Link Here
|
131 |
} |
129 |
} |
132 |
|
130 |
|
133 |
static boolean isEqual(FieldBinding fieldBinding, FieldBinding fieldBinding2) { |
131 |
static boolean isEqual(FieldBinding fieldBinding, FieldBinding fieldBinding2) { |
|
|
132 |
HashSet visitedTypes = new HashSet(); |
134 |
return (fieldBinding.modifiers & CompilerModifiers.AccJustFlag) == (fieldBinding2.modifiers & CompilerModifiers.AccJustFlag) |
133 |
return (fieldBinding.modifiers & CompilerModifiers.AccJustFlag) == (fieldBinding2.modifiers & CompilerModifiers.AccJustFlag) |
135 |
&& CharOperation.equals(fieldBinding.name, fieldBinding2.name) |
134 |
&& CharOperation.equals(fieldBinding.name, fieldBinding2.name) |
136 |
&& isEqual(fieldBinding.type, fieldBinding2.type, true) |
135 |
&& isEqual(fieldBinding.type, fieldBinding2.type, visitedTypes) |
137 |
&& isEqual(fieldBinding.declaringClass, fieldBinding2.declaringClass, true); |
136 |
&& isEqual(fieldBinding.declaringClass, fieldBinding2.declaringClass, visitedTypes); |
138 |
} |
137 |
} |
139 |
|
138 |
|
140 |
/** |
139 |
/** |
Lines 143-156
Link Here
|
143 |
* @return true if both parameters are equals, false otherwise |
142 |
* @return true if both parameters are equals, false otherwise |
144 |
*/ |
143 |
*/ |
145 |
static boolean isEqual(org.eclipse.jdt.internal.compiler.lookup.TypeBinding[] bindings, org.eclipse.jdt.internal.compiler.lookup.TypeBinding[] otherBindings) { |
144 |
static boolean isEqual(org.eclipse.jdt.internal.compiler.lookup.TypeBinding[] bindings, org.eclipse.jdt.internal.compiler.lookup.TypeBinding[] otherBindings) { |
146 |
return isEqual(bindings, otherBindings, true); |
145 |
return isEqual(bindings, otherBindings, new HashSet()); |
147 |
} |
146 |
} |
148 |
/** |
147 |
/** |
149 |
* @param bindings |
148 |
* @param bindings |
150 |
* @param otherBindings |
149 |
* @param otherBindings |
151 |
* @return true if both parameters are equals, false otherwise |
150 |
* @return true if both parameters are equals, false otherwise |
152 |
*/ |
151 |
*/ |
153 |
static boolean isEqual(org.eclipse.jdt.internal.compiler.lookup.TypeBinding[] bindings, org.eclipse.jdt.internal.compiler.lookup.TypeBinding[] otherBindings, boolean checkTypeVariables) { |
152 |
static boolean isEqual(org.eclipse.jdt.internal.compiler.lookup.TypeBinding[] bindings, org.eclipse.jdt.internal.compiler.lookup.TypeBinding[] otherBindings, HashSet visitedTypes) { |
154 |
if (bindings == null) { |
153 |
if (bindings == null) { |
155 |
return otherBindings == null; |
154 |
return otherBindings == null; |
156 |
} else if (otherBindings == null) { |
155 |
} else if (otherBindings == null) { |
Lines 162-168
Link Here
|
162 |
return false; |
161 |
return false; |
163 |
} |
162 |
} |
164 |
for (int i = 0; i < length; i++) { |
163 |
for (int i = 0; i < length; i++) { |
165 |
if (!isEqual(bindings[i], otherBindings[i], checkTypeVariables)) { |
164 |
if (!isEqual(bindings[i], otherBindings[i], visitedTypes)) { |
166 |
return false; |
165 |
return false; |
167 |
} |
166 |
} |
168 |
} |
167 |
} |
Lines 170-180
Link Here
|
170 |
} |
169 |
} |
171 |
} |
170 |
} |
172 |
// TODO (olivier) should optimize to use switch(binding.kind()) & modifier bitmask comparisons |
171 |
// TODO (olivier) should optimize to use switch(binding.kind()) & modifier bitmask comparisons |
173 |
static boolean isEqual(org.eclipse.jdt.internal.compiler.lookup.TypeBinding typeBinding, org.eclipse.jdt.internal.compiler.lookup.TypeBinding typeBinding2, boolean checkTypeVariables) { |
172 |
static boolean isEqual(org.eclipse.jdt.internal.compiler.lookup.TypeBinding typeBinding, org.eclipse.jdt.internal.compiler.lookup.TypeBinding typeBinding2, HashSet visitedTypes) { |
174 |
if (typeBinding == typeBinding2) |
173 |
if (typeBinding == typeBinding2) |
175 |
return true; |
174 |
return true; |
176 |
if (typeBinding == null || typeBinding2 == null) |
175 |
if (typeBinding == null || typeBinding2 == null) |
177 |
return false; |
176 |
return false; |
|
|
177 |
|
178 |
if (visitedTypes.contains(typeBinding)) return true; |
179 |
visitedTypes.add(typeBinding); |
178 |
|
180 |
|
179 |
switch (typeBinding.kind()) { |
181 |
switch (typeBinding.kind()) { |
180 |
case Binding.BASE_TYPE : |
182 |
case Binding.BASE_TYPE : |
Lines 188-194
Link Here
|
188 |
return false; |
190 |
return false; |
189 |
} |
191 |
} |
190 |
return typeBinding.dimensions() == typeBinding2.dimensions() |
192 |
return typeBinding.dimensions() == typeBinding2.dimensions() |
191 |
&& isEqual(typeBinding.leafComponentType(), typeBinding2.leafComponentType(), checkTypeVariables); |
193 |
&& isEqual(typeBinding.leafComponentType(), typeBinding2.leafComponentType(), visitedTypes); |
192 |
|
194 |
|
193 |
case Binding.PARAMETERIZED_TYPE : |
195 |
case Binding.PARAMETERIZED_TYPE : |
194 |
if (!typeBinding2.isParameterizedType()) { |
196 |
if (!typeBinding2.isParameterizedType()) { |
Lines 196-209
Link Here
|
196 |
} |
198 |
} |
197 |
ParameterizedTypeBinding parameterizedTypeBinding = (ParameterizedTypeBinding) typeBinding; |
199 |
ParameterizedTypeBinding parameterizedTypeBinding = (ParameterizedTypeBinding) typeBinding; |
198 |
ParameterizedTypeBinding parameterizedTypeBinding2 = (ParameterizedTypeBinding) typeBinding2; |
200 |
ParameterizedTypeBinding parameterizedTypeBinding2 = (ParameterizedTypeBinding) typeBinding2; |
199 |
if (checkTypeVariables) { |
|
|
200 |
if (!isEqual(parameterizedTypeBinding.arguments, parameterizedTypeBinding2.arguments, false)) { |
201 |
return false; |
202 |
} |
203 |
} |
204 |
return CharOperation.equals(parameterizedTypeBinding.compoundName, parameterizedTypeBinding2.compoundName) |
201 |
return CharOperation.equals(parameterizedTypeBinding.compoundName, parameterizedTypeBinding2.compoundName) |
205 |
&& (parameterizedTypeBinding.modifiers & (CompilerModifiers.AccJustFlag | IConstants.AccInterface | IConstants.AccEnum | IConstants.AccAnnotation)) |
202 |
&& (parameterizedTypeBinding.modifiers & (CompilerModifiers.AccJustFlag | IConstants.AccInterface | IConstants.AccEnum | IConstants.AccAnnotation)) |
206 |
== (parameterizedTypeBinding2.modifiers & (CompilerModifiers.AccJustFlag | IConstants.AccInterface | IConstants.AccEnum | IConstants.AccAnnotation)); |
203 |
== (parameterizedTypeBinding2.modifiers & (CompilerModifiers.AccJustFlag | IConstants.AccInterface | IConstants.AccEnum | IConstants.AccAnnotation)) |
|
|
204 |
&& isEqual(parameterizedTypeBinding.arguments, parameterizedTypeBinding2.arguments, visitedTypes); |
207 |
|
205 |
|
208 |
case Binding.WILDCARD_TYPE : |
206 |
case Binding.WILDCARD_TYPE : |
209 |
if (!typeBinding2.isWildcard()) { |
207 |
if (!typeBinding2.isWildcard()) { |
Lines 211-217
Link Here
|
211 |
} |
209 |
} |
212 |
WildcardBinding wildcardBinding = (WildcardBinding) typeBinding; |
210 |
WildcardBinding wildcardBinding = (WildcardBinding) typeBinding; |
213 |
WildcardBinding wildcardBinding2 = (WildcardBinding) typeBinding2; |
211 |
WildcardBinding wildcardBinding2 = (WildcardBinding) typeBinding2; |
214 |
return isEqual(wildcardBinding.bound, wildcardBinding2.bound, checkTypeVariables) |
212 |
return isEqual(wildcardBinding.bound, wildcardBinding2.bound, visitedTypes) |
215 |
&& wildcardBinding.boundKind == wildcardBinding2.boundKind; |
213 |
&& wildcardBinding.boundKind == wildcardBinding2.boundKind; |
216 |
|
214 |
|
217 |
case Binding.TYPE_PARAMETER : |
215 |
case Binding.TYPE_PARAMETER : |
Lines 225-243
Link Here
|
225 |
CaptureBinding captureBinding = (CaptureBinding) typeBinding; |
223 |
CaptureBinding captureBinding = (CaptureBinding) typeBinding; |
226 |
CaptureBinding captureBinding2 = (CaptureBinding) typeBinding2; |
224 |
CaptureBinding captureBinding2 = (CaptureBinding) typeBinding2; |
227 |
return captureBinding.position == captureBinding2.position |
225 |
return captureBinding.position == captureBinding2.position |
228 |
&& isEqual(captureBinding.wildcard, captureBinding2.wildcard, checkTypeVariables) |
226 |
&& isEqual(captureBinding.wildcard, captureBinding2.wildcard, visitedTypes) |
229 |
&& isEqual(captureBinding.sourceType, captureBinding2.sourceType, true); |
227 |
&& isEqual(captureBinding.sourceType, captureBinding2.sourceType, visitedTypes); |
230 |
} |
228 |
} |
231 |
TypeVariableBinding typeVariableBinding = (TypeVariableBinding) typeBinding; |
229 |
TypeVariableBinding typeVariableBinding = (TypeVariableBinding) typeBinding; |
232 |
TypeVariableBinding typeVariableBinding2 = (TypeVariableBinding) typeBinding2; |
230 |
TypeVariableBinding typeVariableBinding2 = (TypeVariableBinding) typeBinding2; |
233 |
if (checkTypeVariables) { |
231 |
return CharOperation.equals(typeVariableBinding.sourceName, typeVariableBinding2.sourceName) |
234 |
return CharOperation.equals(typeVariableBinding.sourceName, typeVariableBinding2.sourceName) |
232 |
&& isEqual(typeVariableBinding.declaringElement, typeVariableBinding2.declaringElement, visitedTypes) |
235 |
&& isEqual(typeVariableBinding.declaringElement, typeVariableBinding2.declaringElement, false) |
233 |
&& isEqual(typeVariableBinding.superclass(), typeVariableBinding2.superclass(), visitedTypes) |
236 |
&& isEqual(typeVariableBinding.superclass(), typeVariableBinding2.superclass(), true) |
234 |
&& isEqual(typeVariableBinding.superInterfaces(), typeVariableBinding2.superInterfaces(), visitedTypes); |
237 |
&& isEqual(typeVariableBinding.superInterfaces(), typeVariableBinding2.superInterfaces(), true); |
|
|
238 |
} else { |
239 |
return CharOperation.equals(typeVariableBinding.sourceName, typeVariableBinding2.sourceName); |
240 |
} |
241 |
|
235 |
|
242 |
case Binding.GENERIC_TYPE : |
236 |
case Binding.GENERIC_TYPE : |
243 |
if (!typeBinding2.isGenericType()) { |
237 |
if (!typeBinding2.isGenericType()) { |
Lines 245-258
Link Here
|
245 |
} |
239 |
} |
246 |
ReferenceBinding referenceBinding = (ReferenceBinding) typeBinding; |
240 |
ReferenceBinding referenceBinding = (ReferenceBinding) typeBinding; |
247 |
ReferenceBinding referenceBinding2 = (ReferenceBinding) typeBinding2; |
241 |
ReferenceBinding referenceBinding2 = (ReferenceBinding) typeBinding2; |
248 |
if (checkTypeVariables) { |
|
|
249 |
if (!isEqual(referenceBinding.typeVariables(), referenceBinding2.typeVariables(), true)) { |
250 |
return false; |
251 |
} |
252 |
} |
253 |
return CharOperation.equals(referenceBinding.compoundName, referenceBinding2.compoundName) |
242 |
return CharOperation.equals(referenceBinding.compoundName, referenceBinding2.compoundName) |
254 |
&& (referenceBinding.modifiers & (CompilerModifiers.AccJustFlag | IConstants.AccInterface | IConstants.AccEnum | IConstants.AccAnnotation)) |
243 |
&& (referenceBinding.modifiers & (CompilerModifiers.AccJustFlag | IConstants.AccInterface | IConstants.AccEnum | IConstants.AccAnnotation)) |
255 |
== (referenceBinding2.modifiers & (CompilerModifiers.AccJustFlag | IConstants.AccInterface | IConstants.AccEnum | IConstants.AccAnnotation)); |
244 |
== (referenceBinding2.modifiers & (CompilerModifiers.AccJustFlag | IConstants.AccInterface | IConstants.AccEnum | IConstants.AccAnnotation)) |
|
|
245 |
&& isEqual(referenceBinding.typeVariables(), referenceBinding2.typeVariables(), visitedTypes); |
256 |
|
246 |
|
257 |
case Binding.RAW_TYPE : |
247 |
case Binding.RAW_TYPE : |
258 |
default : |
248 |
default : |
Lines 276-281
Link Here
|
276 |
* @return true if both parameters are equals, false otherwise |
266 |
* @return true if both parameters are equals, false otherwise |
277 |
*/ |
267 |
*/ |
278 |
static boolean isEqual(org.eclipse.jdt.internal.compiler.lookup.TypeBinding typeBinding, org.eclipse.jdt.internal.compiler.lookup.TypeBinding typeBinding2) { |
268 |
static boolean isEqual(org.eclipse.jdt.internal.compiler.lookup.TypeBinding typeBinding, org.eclipse.jdt.internal.compiler.lookup.TypeBinding typeBinding2) { |
279 |
return isEqual(typeBinding, typeBinding2, true); |
269 |
return isEqual(typeBinding, typeBinding2, new HashSet()); |
280 |
} |
270 |
} |
281 |
} |
271 |
} |