1 11 package org.eclipse.jdt.core.dom; 12 13 import java.util.HashSet ; 14 15 import org.eclipse.jdt.core.compiler.CharOperation; 16 import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; 17 import org.eclipse.jdt.internal.compiler.lookup.Binding; 18 import org.eclipse.jdt.internal.compiler.lookup.CaptureBinding; 19 import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers; 20 import org.eclipse.jdt.internal.compiler.lookup.FieldBinding; 21 import org.eclipse.jdt.internal.compiler.lookup.ImportBinding; 22 import org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding; 23 import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding; 24 import org.eclipse.jdt.internal.compiler.lookup.TypeVariableBinding; 25 import org.eclipse.jdt.internal.compiler.lookup.VariableBinding; 26 import org.eclipse.jdt.internal.compiler.lookup.WildcardBinding; 27 28 33 class BindingComparator { 34 39 static boolean isEqual(TypeVariableBinding[] bindings, TypeVariableBinding[] otherBindings) { 40 if (bindings == null) { 41 return otherBindings == null; 42 } 43 if (otherBindings == null) { 44 return false; 45 } 46 int length = bindings.length; 47 int otherLength = otherBindings.length; 48 if (length != otherLength) { 49 return false; 50 } 51 for (int i = 0; i < length; i++) { 52 TypeVariableBinding typeVariableBinding = bindings[i]; 53 TypeVariableBinding typeVariableBinding2 = otherBindings[i]; 54 if (!isEqual(typeVariableBinding, typeVariableBinding2)) { 55 return false; 56 } 57 } 58 return true; 59 } 60 61 66 static boolean isEqual(Binding declaringElement, Binding declaringElement2, HashSet visitedTypes) { 67 if (declaringElement instanceof org.eclipse.jdt.internal.compiler.lookup.TypeBinding) { 68 if (!(declaringElement2 instanceof org.eclipse.jdt.internal.compiler.lookup.TypeBinding)){ 69 return false; 70 } 71 return isEqual((org.eclipse.jdt.internal.compiler.lookup.TypeBinding) declaringElement, 72 (org.eclipse.jdt.internal.compiler.lookup.TypeBinding) declaringElement2, 73 visitedTypes); 74 } else if (declaringElement instanceof org.eclipse.jdt.internal.compiler.lookup.MethodBinding) { 75 if (!(declaringElement2 instanceof org.eclipse.jdt.internal.compiler.lookup.MethodBinding)) { 76 return false; 77 } 78 return isEqual((org.eclipse.jdt.internal.compiler.lookup.MethodBinding) declaringElement, 79 (org.eclipse.jdt.internal.compiler.lookup.MethodBinding) declaringElement2, 80 visitedTypes); 81 } else if (declaringElement instanceof VariableBinding) { 82 if (!(declaringElement2 instanceof VariableBinding)) { 83 return false; 84 } 85 return isEqual((VariableBinding) declaringElement, 86 (VariableBinding) declaringElement2); 87 } else if (declaringElement instanceof org.eclipse.jdt.internal.compiler.lookup.PackageBinding) { 88 if (!(declaringElement2 instanceof org.eclipse.jdt.internal.compiler.lookup.PackageBinding)) { 89 return false; 90 } 91 org.eclipse.jdt.internal.compiler.lookup.PackageBinding packageBinding = (org.eclipse.jdt.internal.compiler.lookup.PackageBinding) declaringElement; 92 org.eclipse.jdt.internal.compiler.lookup.PackageBinding packageBinding2 = (org.eclipse.jdt.internal.compiler.lookup.PackageBinding) declaringElement2; 93 return CharOperation.equals(packageBinding.compoundName, packageBinding2.compoundName); 94 } else if (declaringElement instanceof ImportBinding) { 95 if (!(declaringElement2 instanceof ImportBinding)) { 96 return false; 97 } 98 ImportBinding importBinding = (ImportBinding) declaringElement; 99 ImportBinding importBinding2 = (ImportBinding) declaringElement2; 100 return importBinding.isStatic() == importBinding2.isStatic() 101 && importBinding.onDemand == importBinding2.onDemand 102 && CharOperation.equals(importBinding.compoundName, importBinding2.compoundName); 103 } 104 return false; 105 } 106 107 static boolean isEqual(org.eclipse.jdt.internal.compiler.lookup.MethodBinding methodBinding, 108 org.eclipse.jdt.internal.compiler.lookup.MethodBinding methodBinding2) { 109 return isEqual(methodBinding, methodBinding2, new HashSet ()); 110 } 111 112 static boolean isEqual(org.eclipse.jdt.internal.compiler.lookup.MethodBinding methodBinding, 113 org.eclipse.jdt.internal.compiler.lookup.MethodBinding methodBinding2, 114 HashSet visitedTypes) { 115 if (methodBinding == null) { 116 return methodBinding2 == null; 117 } 118 if (methodBinding2 == null) return false; 119 return CharOperation.equals(methodBinding.selector, methodBinding2.selector) 120 && isEqual(methodBinding.returnType, methodBinding2.returnType, visitedTypes) 121 && isEqual(methodBinding.thrownExceptions, methodBinding2.thrownExceptions, visitedTypes) 122 && isEqual(methodBinding.declaringClass, methodBinding2.declaringClass, visitedTypes) 123 && isEqual(methodBinding.typeVariables, methodBinding2.typeVariables, visitedTypes) 124 && isEqual(methodBinding.parameters, methodBinding2.parameters, visitedTypes); 125 } 126 127 static boolean isEqual(VariableBinding variableBinding, VariableBinding variableBinding2) { 128 return (variableBinding.modifiers & ExtraCompilerModifiers.AccJustFlag) == (variableBinding2.modifiers & ExtraCompilerModifiers.AccJustFlag) 129 && CharOperation.equals(variableBinding.name, variableBinding2.name) 130 && isEqual(variableBinding.type, variableBinding2.type) 131 && (variableBinding.id == variableBinding2.id); 132 } 133 134 static boolean isEqual(FieldBinding fieldBinding, FieldBinding fieldBinding2) { 135 HashSet visitedTypes = new HashSet (); 136 return (fieldBinding.modifiers & ExtraCompilerModifiers.AccJustFlag) == (fieldBinding2.modifiers & ExtraCompilerModifiers.AccJustFlag) 137 && CharOperation.equals(fieldBinding.name, fieldBinding2.name) 138 && isEqual(fieldBinding.type, fieldBinding2.type, visitedTypes) 139 && isEqual(fieldBinding.declaringClass, fieldBinding2.declaringClass, visitedTypes); 140 } 141 142 147 static boolean isEqual(org.eclipse.jdt.internal.compiler.lookup.TypeBinding[] bindings, org.eclipse.jdt.internal.compiler.lookup.TypeBinding[] otherBindings) { 148 return isEqual(bindings, otherBindings, new HashSet ()); 149 } 150 155 static boolean isEqual(org.eclipse.jdt.internal.compiler.lookup.TypeBinding[] bindings, org.eclipse.jdt.internal.compiler.lookup.TypeBinding[] otherBindings, HashSet visitedTypes) { 156 if (bindings == null) { 157 return otherBindings == null; 158 } 159 if (otherBindings == null) { 160 return false; 161 } 162 int length = bindings.length; 163 int otherLength = otherBindings.length; 164 if (length != otherLength) { 165 return false; 166 } 167 for (int i = 0; i < length; i++) { 168 if (!isEqual(bindings[i], otherBindings[i], visitedTypes)) { 169 return false; 170 } 171 } 172 return true; 173 } 174 static boolean isEqual(org.eclipse.jdt.internal.compiler.lookup.TypeBinding typeBinding, org.eclipse.jdt.internal.compiler.lookup.TypeBinding typeBinding2, HashSet visitedTypes) { 175 if (typeBinding == typeBinding2) 176 return true; 177 if (typeBinding == null || typeBinding2 == null) 178 return false; 179 180 switch (typeBinding.kind()) { 181 case Binding.BASE_TYPE : 182 if (!typeBinding2.isBaseType()) { 183 return false; 184 } 185 return typeBinding.id == typeBinding2.id; 186 187 case Binding.ARRAY_TYPE : 188 if (!typeBinding2.isArrayType()) { 189 return false; 190 } 191 return typeBinding.dimensions() == typeBinding2.dimensions() 192 && isEqual(typeBinding.leafComponentType(), typeBinding2.leafComponentType(), visitedTypes); 193 194 case Binding.PARAMETERIZED_TYPE : 195 if (!typeBinding2.isParameterizedType()) { 196 return false; 197 } 198 ParameterizedTypeBinding parameterizedTypeBinding = (ParameterizedTypeBinding) typeBinding; 199 ParameterizedTypeBinding parameterizedTypeBinding2 = (ParameterizedTypeBinding) typeBinding2; 200 return CharOperation.equals(parameterizedTypeBinding.compoundName, parameterizedTypeBinding2.compoundName) 201 && (parameterizedTypeBinding.modifiers & (ExtraCompilerModifiers.AccJustFlag | ClassFileConstants.AccInterface | ClassFileConstants.AccEnum | ClassFileConstants.AccAnnotation)) 202 == (parameterizedTypeBinding2.modifiers & (ExtraCompilerModifiers.AccJustFlag | ClassFileConstants.AccInterface | ClassFileConstants.AccEnum | ClassFileConstants.AccAnnotation)) 203 && isEqual(parameterizedTypeBinding.arguments, parameterizedTypeBinding2.arguments, visitedTypes) 204 && isEqual(parameterizedTypeBinding.enclosingType(), parameterizedTypeBinding2.enclosingType(), visitedTypes); 205 206 case Binding.WILDCARD_TYPE : 207 if (!typeBinding2.isWildcard()) { 208 return false; 209 } 210 WildcardBinding wildcardBinding = (WildcardBinding) typeBinding; 211 WildcardBinding wildcardBinding2 = (WildcardBinding) typeBinding2; 212 return isEqual(wildcardBinding.bound, wildcardBinding2.bound, visitedTypes) 213 && wildcardBinding.boundKind == wildcardBinding2.boundKind; 214 215 case Binding.TYPE_PARAMETER : 216 if (!(typeBinding2.isTypeVariable())) { 217 return false; 218 } 219 if (typeBinding.isCapture()) { 220 if (!(typeBinding2.isCapture())) { 221 return false; 222 } 223 CaptureBinding captureBinding = (CaptureBinding) typeBinding; 224 CaptureBinding captureBinding2 = (CaptureBinding) typeBinding2; 225 if (captureBinding.position == captureBinding2.position) { 226 if (visitedTypes.contains(typeBinding)) return true; 227 visitedTypes.add(typeBinding); 228 229 return isEqual(captureBinding.wildcard, captureBinding2.wildcard, visitedTypes) 230 && isEqual(captureBinding.sourceType, captureBinding2.sourceType, visitedTypes); 231 } 232 return false; 233 } 234 TypeVariableBinding typeVariableBinding = (TypeVariableBinding) typeBinding; 235 TypeVariableBinding typeVariableBinding2 = (TypeVariableBinding) typeBinding2; 236 if (CharOperation.equals(typeVariableBinding.sourceName, typeVariableBinding2.sourceName)) { 237 if (visitedTypes.contains(typeBinding)) return true; 238 visitedTypes.add(typeBinding); 239 240 return isEqual(typeVariableBinding.declaringElement, typeVariableBinding2.declaringElement, visitedTypes) 241 && isEqual(typeVariableBinding.superclass(), typeVariableBinding2.superclass(), visitedTypes) 242 && isEqual(typeVariableBinding.superInterfaces(), typeVariableBinding2.superInterfaces(), visitedTypes); 243 } 244 return false; 245 case Binding.GENERIC_TYPE : 246 if (!typeBinding2.isGenericType()) { 247 return false; 248 } 249 ReferenceBinding referenceBinding = (ReferenceBinding) typeBinding; 250 ReferenceBinding referenceBinding2 = (ReferenceBinding) typeBinding2; 251 return CharOperation.equals(referenceBinding.compoundName, referenceBinding2.compoundName) 252 && (referenceBinding.modifiers & (ExtraCompilerModifiers.AccJustFlag | ClassFileConstants.AccInterface | ClassFileConstants.AccEnum | ClassFileConstants.AccAnnotation)) 253 == (referenceBinding2.modifiers & (ExtraCompilerModifiers.AccJustFlag | ClassFileConstants.AccInterface | ClassFileConstants.AccEnum | ClassFileConstants.AccAnnotation)) 254 && isEqual(referenceBinding.typeVariables(), referenceBinding2.typeVariables(), visitedTypes) 255 && isEqual(referenceBinding.enclosingType(), referenceBinding2.enclosingType(), visitedTypes); 256 257 case Binding.RAW_TYPE : 258 default : 259 if (!(typeBinding2 instanceof ReferenceBinding)) { 260 return false; 261 } 262 referenceBinding = (ReferenceBinding) typeBinding; 263 referenceBinding2 = (ReferenceBinding) typeBinding2; 264 char[] constantPoolName = referenceBinding.constantPoolName(); 265 char[] constantPoolName2 = referenceBinding2.constantPoolName(); 266 if (constantPoolName == null) { 268 if (constantPoolName2 != null) { 269 return false; 270 } 271 if (!CharOperation.equals(referenceBinding.computeUniqueKey(), referenceBinding2.computeUniqueKey())) { 272 return false; 273 } 274 } else { 275 if (constantPoolName2 == null) { 276 return false; 277 } 278 if (!CharOperation.equals(constantPoolName, constantPoolName2)) { 279 return false; 280 } 281 } 282 return CharOperation.equals(referenceBinding.compoundName, referenceBinding2.compoundName) 283 && (!referenceBinding2.isGenericType()) 284 && (referenceBinding.isRawType() == referenceBinding2.isRawType()) 285 && ((referenceBinding.modifiers & ~ClassFileConstants.AccSuper) & (ExtraCompilerModifiers.AccJustFlag | ClassFileConstants.AccInterface | ClassFileConstants.AccEnum | ClassFileConstants.AccAnnotation)) 286 == ((referenceBinding2.modifiers & ~ClassFileConstants.AccSuper) & (ExtraCompilerModifiers.AccJustFlag | ClassFileConstants.AccInterface | ClassFileConstants.AccEnum | ClassFileConstants.AccAnnotation)) 287 && isEqual(referenceBinding.enclosingType(), referenceBinding2.enclosingType(), visitedTypes); 288 } 289 } 290 295 static boolean isEqual(org.eclipse.jdt.internal.compiler.lookup.TypeBinding typeBinding, org.eclipse.jdt.internal.compiler.lookup.TypeBinding typeBinding2) { 296 return isEqual(typeBinding, typeBinding2, new HashSet ()); 297 } 298 } 299
| Popular Tags
|