| 1 | /******************************************************************************* |
|---|---|
| 2 | * Copyright (c) 2000, 2021 IBM Corporation and others. |
| 3 | * |
| 4 | * This program and the accompanying materials |
| 5 | * are made available under the terms of the Eclipse Public License 2.0 |
| 6 | * which accompanies this distribution, and is available at |
| 7 | * https://www.eclipse.org/legal/epl-2.0/ |
| 8 | * |
| 9 | * SPDX-License-Identifier: EPL-2.0 |
| 10 | * |
| 11 | |
| 12 | * Contributors: |
| 13 | * IBM Corporation - initial API and implementation |
| 14 | * Stephan Herrmann - Contribution for |
| 15 | * Bug 342671 - ClassCastException: org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding cannot be cast to org.eclipse.jdt.internal.compiler.lookup.ArrayBinding |
| 16 | * Bug 429813 - [1.8][dom ast] IMethodBinding#getJavaElement() should return IMethod for lambda |
| 17 | *******************************************************************************/ |
| 18 | package org.eclipse.jdt.core.dom; |
| 19 | |
| 20 | import java.util.HashMap; |
| 21 | import java.util.Map; |
| 22 | import java.util.concurrent.ConcurrentHashMap; |
| 23 | |
| 24 | import org.eclipse.jdt.core.WorkingCopyOwner; |
| 25 | import org.eclipse.jdt.core.compiler.CharOperation; |
| 26 | import org.eclipse.jdt.core.dom.MethodBinding.LambdaMethod; |
| 27 | import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration; |
| 28 | import org.eclipse.jdt.internal.compiler.ast.AbstractVariableDeclaration; |
| 29 | import org.eclipse.jdt.internal.compiler.ast.AllocationExpression; |
| 30 | import org.eclipse.jdt.internal.compiler.ast.ArrayAllocationExpression; |
| 31 | import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; |
| 32 | import org.eclipse.jdt.internal.compiler.ast.ExplicitConstructorCall; |
| 33 | import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration; |
| 34 | import org.eclipse.jdt.internal.compiler.ast.FieldReference; |
| 35 | import org.eclipse.jdt.internal.compiler.ast.ImportReference; |
| 36 | import org.eclipse.jdt.internal.compiler.ast.JavadocAllocationExpression; |
| 37 | import org.eclipse.jdt.internal.compiler.ast.JavadocFieldReference; |
| 38 | import org.eclipse.jdt.internal.compiler.ast.JavadocImplicitTypeReference; |
| 39 | import org.eclipse.jdt.internal.compiler.ast.JavadocMessageSend; |
| 40 | import org.eclipse.jdt.internal.compiler.ast.JavadocModuleReference; |
| 41 | import org.eclipse.jdt.internal.compiler.ast.JavadocQualifiedTypeReference; |
| 42 | import org.eclipse.jdt.internal.compiler.ast.JavadocSingleNameReference; |
| 43 | import org.eclipse.jdt.internal.compiler.ast.JavadocSingleTypeReference; |
| 44 | import org.eclipse.jdt.internal.compiler.ast.Literal; |
| 45 | import org.eclipse.jdt.internal.compiler.ast.LocalDeclaration; |
| 46 | import org.eclipse.jdt.internal.compiler.ast.MemberValuePair; |
| 47 | import org.eclipse.jdt.internal.compiler.ast.MessageSend; |
| 48 | import org.eclipse.jdt.internal.compiler.ast.ModuleReference; |
| 49 | import org.eclipse.jdt.internal.compiler.ast.ParameterizedQualifiedTypeReference; |
| 50 | import org.eclipse.jdt.internal.compiler.ast.QualifiedNameReference; |
| 51 | import org.eclipse.jdt.internal.compiler.ast.QualifiedSuperReference; |
| 52 | import org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference; |
| 53 | import org.eclipse.jdt.internal.compiler.ast.Receiver; |
| 54 | import org.eclipse.jdt.internal.compiler.ast.SingleNameReference; |
| 55 | import org.eclipse.jdt.internal.compiler.ast.SingleTypeReference; |
| 56 | import org.eclipse.jdt.internal.compiler.ast.ThisReference; |
| 57 | import org.eclipse.jdt.internal.compiler.ast.TypeReference; |
| 58 | import org.eclipse.jdt.internal.compiler.impl.Constant; |
| 59 | import org.eclipse.jdt.internal.compiler.lookup.ArrayBinding; |
| 60 | import org.eclipse.jdt.internal.compiler.lookup.Binding; |
| 61 | import org.eclipse.jdt.internal.compiler.lookup.BlockScope; |
| 62 | import org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope; |
| 63 | import org.eclipse.jdt.internal.compiler.lookup.ElementValuePair; |
| 64 | import org.eclipse.jdt.internal.compiler.lookup.FieldBinding; |
| 65 | import org.eclipse.jdt.internal.compiler.lookup.LocalVariableBinding; |
| 66 | import org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment; |
| 67 | import org.eclipse.jdt.internal.compiler.lookup.MethodScope; |
| 68 | import org.eclipse.jdt.internal.compiler.lookup.ParameterizedGenericMethodBinding; |
| 69 | import org.eclipse.jdt.internal.compiler.lookup.ProblemFieldBinding; |
| 70 | import org.eclipse.jdt.internal.compiler.lookup.ProblemPackageBinding; |
| 71 | import org.eclipse.jdt.internal.compiler.lookup.ProblemReasons; |
| 72 | import org.eclipse.jdt.internal.compiler.lookup.ProblemReferenceBinding; |
| 73 | import org.eclipse.jdt.internal.compiler.lookup.RecordComponentBinding; |
| 74 | import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding; |
| 75 | import org.eclipse.jdt.internal.compiler.lookup.Scope; |
| 76 | import org.eclipse.jdt.internal.compiler.lookup.SyntheticArgumentBinding; |
| 77 | import org.eclipse.jdt.internal.compiler.lookup.TagBits; |
| 78 | import org.eclipse.jdt.internal.compiler.lookup.TypeConstants; |
| 79 | import org.eclipse.jdt.internal.compiler.lookup.TypeIds; |
| 80 | import org.eclipse.jdt.internal.compiler.lookup.VoidTypeBinding; |
| 81 | import org.eclipse.jdt.internal.compiler.problem.AbortCompilation; |
| 82 | import org.eclipse.jdt.internal.core.util.Util; |
| 83 | |
| 84 | /** |
| 85 | * Internal class for resolving bindings using old ASTs. |
| 86 | * <p> |
| 87 | * IMPORTANT: The methods on this class are synchronized. This is required |
| 88 | * because there may be multiple clients in separate threads concurrently |
| 89 | * reading an AST and asking for bindings for its nodes. These requests all |
| 90 | * end up invoking instance methods on this class. There are various internal |
| 91 | * tables and caches which are built and maintained in the course of looking |
| 92 | * up bindings. To ensure that they remain coherent in the presence of multiple |
| 93 | * threads, the methods are synchronized on the DefaultBindingResolver instance. |
| 94 | * </p> |
| 95 | */ |
| 96 | @SuppressWarnings({ "rawtypes", "unchecked" }) |
| 97 | class DefaultBindingResolver extends BindingResolver { |
| 98 | |
| 99 | /* |
| 100 | * Holds on binding tables that can be shared by several ASTs. |
| 101 | */ |
| 102 | static class BindingTables { |
| 103 | |
| 104 | /** |
| 105 | * This map is used to get a binding from its binding key. |
| 106 | */ |
| 107 | Map bindingKeysToBindings; |
| 108 | /** |
| 109 | * This map is used to keep the correspondence between new bindings and the |
| 110 | * compiler bindings to their internal counterpart. |
| 111 | * This is an identity map. We should only create one object for one binding. |
| 112 | */ |
| 113 | Map compilerBindingsToASTBindings; |
| 114 | |
| 115 | /** |
| 116 | * This map is used to keep the correspondence between new annotation instances to their internal counterpart. |
| 117 | * This is an identity map. We should only create one object for one annotation. |
| 118 | */ |
| 119 | Map compilerAnnotationBindingsToASTBindings; |
| 120 | |
| 121 | BindingTables() { |
| 122 | this.compilerBindingsToASTBindings = new ConcurrentHashMap(); |
| 123 | this.compilerAnnotationBindingsToASTBindings = new ConcurrentHashMap(); |
| 124 | this.bindingKeysToBindings = new ConcurrentHashMap(); |
| 125 | } |
| 126 | |
| 127 | } |
| 128 | /** |
| 129 | * This map is used to retrieve the corresponding block scope for a ast node |
| 130 | */ |
| 131 | Map astNodesToBlockScope; |
| 132 | |
| 133 | /** |
| 134 | * This map is used to get an ast node from its binding (new binding) or DOM |
| 135 | */ |
| 136 | Map bindingsToAstNodes; |
| 137 | |
| 138 | /* |
| 139 | * The shared binding tables accros ASTs. |
| 140 | */ |
| 141 | BindingTables bindingTables; |
| 142 | |
| 143 | /** |
| 144 | * This map is used to retrieve an old ast node using the new ast node. This is not an |
| 145 | * identity map, as several nested DOM nodes may be associated with the same "larger" |
| 146 | * compiler AST node. |
| 147 | * E.g., an ArrayAllocationExpression "new MyType[1]" will appear as the right-hand value |
| 148 | * for the SimpleType "MyType", the ArrayType "MyType[1]", and the ArrayCreation "new MyType[1]". |
| 149 | */ |
| 150 | Map newAstToOldAst; |
| 151 | |
| 152 | /** |
| 153 | * Compilation unit scope |
| 154 | */ |
| 155 | private CompilationUnitScope scope; |
| 156 | |
| 157 | /** |
| 158 | * The working copy owner that defines the context in which this resolver is creating the bindings. |
| 159 | */ |
| 160 | WorkingCopyOwner workingCopyOwner; |
| 161 | |
| 162 | /** |
| 163 | * Toggle controlling whether DOM bindings should be created when missing internal compiler bindings.. |
| 164 | */ |
| 165 | boolean isRecoveringBindings; |
| 166 | |
| 167 | /** |
| 168 | * Set to <code>true</code> if initialized from a java project |
| 169 | */ |
| 170 | boolean fromJavaProject; |
| 171 | |
| 172 | /** |
| 173 | * Constructor for DefaultBindingResolver. |
| 174 | */ |
| 175 | DefaultBindingResolver(CompilationUnitScope scope, WorkingCopyOwner workingCopyOwner, BindingTables bindingTables, boolean isRecoveringBindings, boolean fromJavaProject) { |
| 176 | this.newAstToOldAst = new HashMap(); |
| 177 | this.astNodesToBlockScope = new HashMap(); |
| 178 | this.bindingsToAstNodes = new HashMap(); |
| 179 | this.bindingTables = bindingTables; |
| 180 | this.scope = scope; |
| 181 | this.workingCopyOwner = workingCopyOwner; |
| 182 | this.isRecoveringBindings = isRecoveringBindings; |
| 183 | this.fromJavaProject = fromJavaProject; |
| 184 | } |
| 185 | |
| 186 | DefaultBindingResolver(LookupEnvironment lookupEnvironment, WorkingCopyOwner workingCopyOwner, BindingTables bindingTables, boolean isRecoveringBindings, boolean fromJavaProject) { |
| 187 | this.newAstToOldAst = new HashMap(); |
| 188 | this.astNodesToBlockScope = new HashMap(); |
| 189 | this.bindingsToAstNodes = new HashMap(); |
| 190 | this.bindingTables = bindingTables; |
| 191 | this.scope = new CompilationUnitScope(new CompilationUnitDeclaration(null, null, -1), lookupEnvironment); |
| 192 | this.workingCopyOwner = workingCopyOwner; |
| 193 | this.isRecoveringBindings = isRecoveringBindings; |
| 194 | this.fromJavaProject = fromJavaProject; |
| 195 | } |
| 196 | |
| 197 | @Override |
| 198 | synchronized ASTNode findDeclaringNode(IBinding binding) { |
| 199 | if (binding == null) { |
| 200 | return null; |
| 201 | } |
| 202 | if (binding instanceof IMethodBinding) { |
| 203 | IMethodBinding methodBinding = (IMethodBinding) binding; |
| 204 | return (ASTNode) this.bindingsToAstNodes.get(methodBinding.getMethodDeclaration()); |
| 205 | } else if (binding instanceof ITypeBinding) { |
| 206 | ITypeBinding typeBinding = (ITypeBinding) binding; |
| 207 | return (ASTNode) this.bindingsToAstNodes.get(typeBinding.getTypeDeclaration()); |
| 208 | } else if (binding instanceof IVariableBinding) { |
| 209 | IVariableBinding variableBinding = (IVariableBinding) binding; |
| 210 | return (ASTNode) this.bindingsToAstNodes.get(variableBinding.getVariableDeclaration()); |
| 211 | } |
| 212 | return (ASTNode) this.bindingsToAstNodes.get(binding); |
| 213 | } |
| 214 | |
| 215 | @Override |
| 216 | synchronized ASTNode findDeclaringNode(String bindingKey) { |
| 217 | if (bindingKey == null) { |
| 218 | return null; |
| 219 | } |
| 220 | Object binding = this.bindingTables.bindingKeysToBindings.get(bindingKey); |
| 221 | if (binding == null) |
| 222 | return null; |
| 223 | return (ASTNode) this.bindingsToAstNodes.get(binding); |
| 224 | } |
| 225 | |
| 226 | IBinding getBinding(org.eclipse.jdt.internal.compiler.lookup.Binding binding) { |
| 227 | switch (binding.kind()) { |
| 228 | case Binding.PACKAGE: |
| 229 | return getPackageBinding((org.eclipse.jdt.internal.compiler.lookup.PackageBinding) binding); |
| 230 | case Binding.TYPE: |
| 231 | case Binding.BASE_TYPE: |
| 232 | case Binding.GENERIC_TYPE: |
| 233 | case Binding.PARAMETERIZED_TYPE: |
| 234 | case Binding.RAW_TYPE: |
| 235 | return getTypeBinding((org.eclipse.jdt.internal.compiler.lookup.TypeBinding) binding); |
| 236 | case Binding.ARRAY_TYPE: |
| 237 | case Binding.TYPE_PARAMETER: |
| 238 | return new TypeBinding(this, (org.eclipse.jdt.internal.compiler.lookup.TypeBinding) binding); |
| 239 | case Binding.METHOD: |
| 240 | return getMethodBinding((org.eclipse.jdt.internal.compiler.lookup.MethodBinding) binding); |
| 241 | case Binding.MODULE: |
| 242 | return getModuleBinding((org.eclipse.jdt.internal.compiler.lookup.ModuleBinding) binding); |
| 243 | case Binding.FIELD: |
| 244 | case Binding.LOCAL: |
| 245 | case Binding.RECORD_COMPONENT: |
| 246 | return getVariableBinding((org.eclipse.jdt.internal.compiler.lookup.VariableBinding) binding); |
| 247 | } |
| 248 | return null; |
| 249 | } |
| 250 | |
| 251 | Util.BindingsToNodesMap getBindingsToNodesMap() { |
| 252 | return new Util.BindingsToNodesMap() { |
| 253 | @Override |
| 254 | public org.eclipse.jdt.internal.compiler.ast.ASTNode get(Binding binding) { |
| 255 | return (org.eclipse.jdt.internal.compiler.ast.ASTNode) |
| 256 | DefaultBindingResolver.this.newAstToOldAst.get(DefaultBindingResolver.this.bindingsToAstNodes.get(binding)); |
| 257 | } |
| 258 | }; |
| 259 | } |
| 260 | |
| 261 | @Override |
| 262 | synchronized org.eclipse.jdt.internal.compiler.ast.ASTNode getCorrespondingNode(ASTNode currentNode) { |
| 263 | return (org.eclipse.jdt.internal.compiler.ast.ASTNode) this.newAstToOldAst.get(currentNode); |
| 264 | } |
| 265 | |
| 266 | @Override |
| 267 | synchronized IMethodBinding getMethodBinding(org.eclipse.jdt.internal.compiler.lookup.MethodBinding methodBinding) { |
| 268 | return getMethodOrLambdaBinding(methodBinding, null, null); |
| 269 | } |
| 270 | |
| 271 | private synchronized IMethodBinding getMethodOrLambdaBinding(org.eclipse.jdt.internal.compiler.lookup.MethodBinding methodBinding, |
| 272 | org.eclipse.jdt.internal.compiler.lookup.MethodBinding descriptor, |
| 273 | IBinding enclosingBinding) |
| 274 | { |
| 275 | if (methodBinding != null && !methodBinding.isValidBinding()) { |
| 276 | org.eclipse.jdt.internal.compiler.lookup.ProblemMethodBinding problemMethodBinding = |
| 277 | (org.eclipse.jdt.internal.compiler.lookup.ProblemMethodBinding) methodBinding; |
| 278 | methodBinding = problemMethodBinding.closestMatch; |
| 279 | } |
| 280 | |
| 281 | if (methodBinding != null) { |
| 282 | if (!this.isRecoveringBindings && ((methodBinding.tagBits & TagBits.HasMissingType) != 0)) { |
| 283 | return null; |
| 284 | } |
| 285 | IMethodBinding binding = (IMethodBinding) this.bindingTables.compilerBindingsToASTBindings.get(methodBinding); |
| 286 | if (binding != null) { |
| 287 | return binding; |
| 288 | } |
| 289 | if (descriptor != null && enclosingBinding != null) { |
| 290 | binding = new MethodBinding.LambdaMethod(this, descriptor, methodBinding, enclosingBinding); |
| 291 | } else { |
| 292 | binding = new MethodBinding(this, methodBinding); |
| 293 | } |
| 294 | this.bindingTables.compilerBindingsToASTBindings.put(methodBinding, binding); |
| 295 | return binding; |
| 296 | } |
| 297 | return null; |
| 298 | } |
| 299 | |
| 300 | @Override |
| 301 | synchronized IMemberValuePairBinding getMemberValuePairBinding(ElementValuePair valuePair) { |
| 302 | if (valuePair == null || valuePair.binding == null) return null; |
| 303 | IMemberValuePairBinding binding = |
| 304 | (IMemberValuePairBinding) this.bindingTables.compilerBindingsToASTBindings.get(valuePair); |
| 305 | if (binding != null) |
| 306 | return binding; |
| 307 | binding = new MemberValuePairBinding(valuePair, this); |
| 308 | this.bindingTables.compilerBindingsToASTBindings.put(valuePair, binding); |
| 309 | return binding; |
| 310 | } |
| 311 | |
| 312 | /** |
| 313 | * @see org.eclipse.jdt.core.dom.BindingResolver#getModuleBinding(org.eclipse.jdt.internal.compiler.lookup.ModuleBinding) |
| 314 | */ |
| 315 | @Override |
| 316 | synchronized IModuleBinding getModuleBinding(org.eclipse.jdt.internal.compiler.lookup.ModuleBinding moduleBinding) { |
| 317 | if (moduleBinding != null) { |
| 318 | IModuleBinding binding = (IModuleBinding) this.bindingTables.compilerBindingsToASTBindings.get(moduleBinding); |
| 319 | if (binding == null) { |
| 320 | binding = new ModuleBinding(this, moduleBinding); |
| 321 | this.bindingTables.compilerBindingsToASTBindings.put(moduleBinding, binding); |
| 322 | } |
| 323 | return binding; |
| 324 | } |
| 325 | return null; |
| 326 | } |
| 327 | |
| 328 | @Override |
| 329 | synchronized IPackageBinding getPackageBinding(org.eclipse.jdt.internal.compiler.lookup.PackageBinding packageBinding) { |
| 330 | if (packageBinding == null || packageBinding instanceof ProblemPackageBinding) { |
| 331 | return null; |
| 332 | } |
| 333 | IPackageBinding binding = (IPackageBinding) this.bindingTables.compilerBindingsToASTBindings.get(packageBinding); |
| 334 | if (binding != null) { |
| 335 | return binding; |
| 336 | } |
| 337 | binding = packageBinding instanceof ProblemPackageBinding ? new RecoveredPackageBinding(packageBinding, this) : |
| 338 | new PackageBinding(packageBinding, this); |
| 339 | this.bindingTables.compilerBindingsToASTBindings.put(packageBinding, binding); |
| 340 | return binding; |
| 341 | } |
| 342 | private int getTypeCount(ParameterizedQualifiedTypeReference typeReference) { |
| 343 | TypeReference[][] typeArguments = typeReference.typeArguments; |
| 344 | int value = 0; |
| 345 | org.eclipse.jdt.internal.compiler.ast.Annotation[][] typeAnnotations = typeReference.annotations; |
| 346 | int length = typeReference.tokens.length; |
| 347 | for (int i = 0; i < length; ++i) { |
| 348 | if (value != 0 || (typeArguments != null && typeArguments[i] != null) || |
| 349 | (typeAnnotations != null && typeAnnotations[i] != null )) { |
| 350 | value++; |
| 351 | } |
| 352 | } |
| 353 | return value; |
| 354 | } |
| 355 | |
| 356 | @Override |
| 357 | synchronized ITypeBinding getTypeBinding(VariableDeclaration variableDeclaration) { |
| 358 | ITypeBinding binding = (ITypeBinding) this.bindingTables.compilerBindingsToASTBindings.get(variableDeclaration); |
| 359 | if (binding != null) { |
| 360 | return binding; |
| 361 | } |
| 362 | binding = new RecoveredTypeBinding(this, variableDeclaration); |
| 363 | this.bindingTables.compilerBindingsToASTBindings.put(variableDeclaration, binding); |
| 364 | return binding; |
| 365 | } |
| 366 | |
| 367 | @Override |
| 368 | synchronized ITypeBinding getTypeBinding(Type type) { |
| 369 | ITypeBinding binding = (ITypeBinding) this.bindingTables.compilerBindingsToASTBindings.get(type); |
| 370 | if (binding != null) { |
| 371 | return binding; |
| 372 | } |
| 373 | binding = new RecoveredTypeBinding(this, type); |
| 374 | this.bindingTables.compilerBindingsToASTBindings.put(type, binding); |
| 375 | return binding; |
| 376 | } |
| 377 | |
| 378 | @Override |
| 379 | synchronized ITypeBinding getTypeBinding(org.eclipse.jdt.internal.compiler.lookup.TypeBinding referenceBinding) { |
| 380 | return internalGetTypeBinding(referenceBinding, null); |
| 381 | } |
| 382 | |
| 383 | private synchronized ITypeBinding internalGetTypeBinding(org.eclipse.jdt.internal.compiler.lookup.TypeBinding referenceBinding, IBinding declaringMember) { |
| 384 | // may also create an TypeBinding.AnonymousTypeBinding |
| 385 | if (referenceBinding == null) { |
| 386 | return null; |
| 387 | } else if (!referenceBinding.isValidBinding()) { |
| 388 | switch(referenceBinding.problemId()) { |
| 389 | case ProblemReasons.NotVisible : |
| 390 | case ProblemReasons.NonStaticReferenceInStaticContext : |
| 391 | if (referenceBinding instanceof ProblemReferenceBinding) { |
| 392 | ProblemReferenceBinding problemReferenceBinding = (ProblemReferenceBinding) referenceBinding; |
| 393 | org.eclipse.jdt.internal.compiler.lookup.TypeBinding binding2 = problemReferenceBinding.closestMatch(); |
| 394 | ITypeBinding binding = (ITypeBinding) this.bindingTables.compilerBindingsToASTBindings.get(binding2); |
| 395 | if (binding != null) { |
| 396 | return binding; |
| 397 | } |
| 398 | binding = TypeBinding.createTypeBinding(this, binding2, declaringMember); |
| 399 | this.bindingTables.compilerBindingsToASTBindings.put(binding2, binding); |
| 400 | return binding; |
| 401 | } |
| 402 | break; |
| 403 | case ProblemReasons.NotFound : |
| 404 | if (!this.isRecoveringBindings) { |
| 405 | return null; |
| 406 | } |
| 407 | ITypeBinding binding = (ITypeBinding) this.bindingTables.compilerBindingsToASTBindings.get(referenceBinding); |
| 408 | if (binding != null) { |
| 409 | return binding; |
| 410 | } |
| 411 | if ((referenceBinding.tagBits & TagBits.HasMissingType) != 0) { |
| 412 | binding = TypeBinding.createTypeBinding(this, referenceBinding, declaringMember); |
| 413 | } else { |
| 414 | binding = new RecoveredTypeBinding(this, referenceBinding); |
| 415 | } |
| 416 | this.bindingTables.compilerBindingsToASTBindings.put(referenceBinding, binding); |
| 417 | return binding; |
| 418 | } |
| 419 | return null; |
| 420 | } else { |
| 421 | if ((referenceBinding.tagBits & TagBits.HasMissingType) != 0 && !this.isRecoveringBindings) { |
| 422 | return null; |
| 423 | } |
| 424 | ITypeBinding binding = (ITypeBinding) this.bindingTables.compilerBindingsToASTBindings.get(referenceBinding); |
| 425 | if (binding != null) { |
| 426 | return binding; |
| 427 | } |
| 428 | binding = TypeBinding.createTypeBinding(this, referenceBinding, declaringMember); |
| 429 | this.bindingTables.compilerBindingsToASTBindings.put(referenceBinding, binding); |
| 430 | return binding; |
| 431 | } |
| 432 | } |
| 433 | |
| 434 | @Override |
| 435 | synchronized ITypeBinding getTypeBinding(RecoveredTypeBinding recoveredTypeBinding, int dimensions) { |
| 436 | if (recoveredTypeBinding== null) { |
| 437 | return null; |
| 438 | } |
| 439 | return new RecoveredTypeBinding(this, recoveredTypeBinding, dimensions); |
| 440 | } |
| 441 | |
| 442 | synchronized IVariableBinding getVariableBinding(org.eclipse.jdt.internal.compiler.lookup.VariableBinding variableBinding, VariableDeclaration variableDeclaration) { |
| 443 | if (this.isRecoveringBindings) { |
| 444 | if (variableBinding != null) { |
| 445 | if (variableBinding.isValidBinding()) { |
| 446 | IVariableBinding binding = (IVariableBinding) this.bindingTables.compilerBindingsToASTBindings.get(variableBinding); |
| 447 | if (binding != null) { |
| 448 | return binding; |
| 449 | } |
| 450 | if (variableBinding.type != null) { |
| 451 | binding = new VariableBinding(this, variableBinding); |
| 452 | } else { |
| 453 | binding = new RecoveredVariableBinding(this, variableDeclaration); |
| 454 | } |
| 455 | this.bindingTables.compilerBindingsToASTBindings.put(variableBinding, binding); |
| 456 | return binding; |
| 457 | } else { |
| 458 | /* |
| 459 | * http://dev.eclipse.org/bugs/show_bug.cgi?id=24449 |
| 460 | */ |
| 461 | if (variableBinding instanceof ProblemFieldBinding) { |
| 462 | ProblemFieldBinding problemFieldBinding = (ProblemFieldBinding) variableBinding; |
| 463 | switch(problemFieldBinding.problemId()) { |
| 464 | case ProblemReasons.NotVisible : |
| 465 | case ProblemReasons.NonStaticReferenceInStaticContext : |
| 466 | case ProblemReasons.NonStaticReferenceInConstructorInvocation : |
| 467 | ReferenceBinding declaringClass = problemFieldBinding.declaringClass; |
| 468 | FieldBinding exactBinding = declaringClass.getField(problemFieldBinding.name, true /*resolve*/); |
| 469 | if (exactBinding != null) { |
| 470 | IVariableBinding variableBinding2 = (IVariableBinding) this.bindingTables.compilerBindingsToASTBindings.get(exactBinding); |
| 471 | if (variableBinding2 != null) { |
| 472 | return variableBinding2; |
| 473 | } |
| 474 | variableBinding2 = new VariableBinding(this, exactBinding); |
| 475 | this.bindingTables.compilerBindingsToASTBindings.put(exactBinding, variableBinding2); |
| 476 | return variableBinding2; |
| 477 | } |
| 478 | break; |
| 479 | } |
| 480 | } |
| 481 | } |
| 482 | } |
| 483 | return null; |
| 484 | } |
| 485 | return this.getVariableBinding(variableBinding); |
| 486 | } |
| 487 | |
| 488 | @Override |
| 489 | public WorkingCopyOwner getWorkingCopyOwner() { |
| 490 | return this.workingCopyOwner; |
| 491 | } |
| 492 | |
| 493 | @Override |
| 494 | synchronized IVariableBinding getVariableBinding(org.eclipse.jdt.internal.compiler.lookup.VariableBinding variableBinding) { |
| 495 | if (variableBinding != null) { |
| 496 | if (variableBinding.isValidBinding()) { |
| 497 | org.eclipse.jdt.internal.compiler.lookup.TypeBinding variableType = variableBinding.type; |
| 498 | if (variableType != null) { |
| 499 | if (!this.isRecoveringBindings && ((variableType.tagBits & TagBits.HasMissingType) != 0)) { |
| 500 | return null; |
| 501 | } |
| 502 | IVariableBinding binding = (IVariableBinding) this.bindingTables.compilerBindingsToASTBindings.get(variableBinding); |
| 503 | if (binding != null) { |
| 504 | return binding; |
| 505 | } |
| 506 | binding = new VariableBinding(this, variableBinding); |
| 507 | this.bindingTables.compilerBindingsToASTBindings.put(variableBinding, binding); |
| 508 | return binding; |
| 509 | } |
| 510 | } else { |
| 511 | /* |
| 512 | * http://dev.eclipse.org/bugs/show_bug.cgi?id=24449 |
| 513 | */ |
| 514 | if (variableBinding instanceof ProblemFieldBinding) { |
| 515 | ProblemFieldBinding problemFieldBinding = (ProblemFieldBinding) variableBinding; |
| 516 | switch(problemFieldBinding.problemId()) { |
| 517 | case ProblemReasons.NotVisible : |
| 518 | case ProblemReasons.NonStaticReferenceInStaticContext : |
| 519 | case ProblemReasons.NonStaticReferenceInConstructorInvocation : |
| 520 | ReferenceBinding declaringClass = problemFieldBinding.declaringClass; |
| 521 | FieldBinding exactBinding = declaringClass.getField(problemFieldBinding.name, true /*resolve*/); |
| 522 | if (exactBinding != null) { |
| 523 | IVariableBinding variableBinding2 = (IVariableBinding) this.bindingTables.compilerBindingsToASTBindings.get(exactBinding); |
| 524 | if (variableBinding2 != null) { |
| 525 | return variableBinding2; |
| 526 | } |
| 527 | variableBinding2 = new VariableBinding(this, exactBinding); |
| 528 | this.bindingTables.compilerBindingsToASTBindings.put(exactBinding, variableBinding2); |
| 529 | return variableBinding2; |
| 530 | } |
| 531 | break; |
| 532 | } |
| 533 | } |
| 534 | } |
| 535 | } |
| 536 | return null; |
| 537 | } |
| 538 | |
| 539 | static class AnnotationIdentityBinding { |
| 540 | org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding internalInstance; |
| 541 | AnnotationIdentityBinding(org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding internalInstance) { |
| 542 | this.internalInstance = internalInstance; |
| 543 | } |
| 544 | @Override |
| 545 | public boolean equals(Object o) { |
| 546 | return o instanceof AnnotationIdentityBinding && this.internalInstance == ((AnnotationIdentityBinding)o).internalInstance; |
| 547 | } |
| 548 | @Override |
| 549 | public int hashCode() { |
| 550 | return this.internalInstance.hashCode(); |
| 551 | } |
| 552 | } |
| 553 | |
| 554 | @Override |
| 555 | synchronized IAnnotationBinding getAnnotationInstance(org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding internalInstance) { |
| 556 | if (internalInstance == null) return null; |
| 557 | ReferenceBinding annotationType = internalInstance.getAnnotationType(); |
| 558 | if (!this.isRecoveringBindings) { |
| 559 | if (annotationType == null || ((annotationType.tagBits & TagBits.HasMissingType) != 0)) { |
| 560 | return null; |
| 561 | } |
| 562 | } |
| 563 | Object key = new AnnotationIdentityBinding(internalInstance); |
| 564 | IAnnotationBinding newDomInstance = new AnnotationBinding(internalInstance, this); |
| 565 | IAnnotationBinding domInstance = (IAnnotationBinding) ((ConcurrentHashMap)this.bindingTables.compilerAnnotationBindingsToASTBindings).putIfAbsent(key, newDomInstance); |
| 566 | return domInstance != null ? domInstance : newDomInstance; |
| 567 | } |
| 568 | |
| 569 | @Override |
| 570 | boolean isResolvedTypeInferredFromExpectedType(MethodInvocation methodInvocation) { |
| 571 | Object oldNode = this.newAstToOldAst.get(methodInvocation); |
| 572 | if (oldNode instanceof MessageSend) { |
| 573 | MessageSend messageSend = (MessageSend) oldNode; |
| 574 | org.eclipse.jdt.internal.compiler.lookup.MethodBinding methodBinding = messageSend.binding; |
| 575 | if (methodBinding instanceof ParameterizedGenericMethodBinding) { |
| 576 | ParameterizedGenericMethodBinding genericMethodBinding = (ParameterizedGenericMethodBinding) methodBinding; |
| 577 | return genericMethodBinding.inferredReturnType; |
| 578 | } |
| 579 | } |
| 580 | return false; |
| 581 | } |
| 582 | |
| 583 | @Override |
| 584 | boolean isResolvedTypeInferredFromExpectedType(SuperMethodInvocation superMethodInvocation) { |
| 585 | Object oldNode = this.newAstToOldAst.get(superMethodInvocation); |
| 586 | if (oldNode instanceof MessageSend) { |
| 587 | MessageSend messageSend = (MessageSend) oldNode; |
| 588 | org.eclipse.jdt.internal.compiler.lookup.MethodBinding methodBinding = messageSend.binding; |
| 589 | if (methodBinding instanceof ParameterizedGenericMethodBinding) { |
| 590 | ParameterizedGenericMethodBinding genericMethodBinding = (ParameterizedGenericMethodBinding) methodBinding; |
| 591 | return genericMethodBinding.inferredReturnType; |
| 592 | } |
| 593 | } |
| 594 | return false; |
| 595 | } |
| 596 | |
| 597 | @Override |
| 598 | boolean isResolvedTypeInferredFromExpectedType(ClassInstanceCreation classInstanceCreation) { |
| 599 | Object oldNode = this.newAstToOldAst.get(classInstanceCreation); |
| 600 | if (oldNode instanceof AllocationExpression) { |
| 601 | AllocationExpression allocationExpression = (AllocationExpression) oldNode; |
| 602 | return allocationExpression.inferredReturnType; |
| 603 | } |
| 604 | return false; |
| 605 | } |
| 606 | |
| 607 | @Override |
| 608 | LookupEnvironment lookupEnvironment() { |
| 609 | return this.scope.environment(); |
| 610 | } |
| 611 | |
| 612 | /** |
| 613 | * @see org.eclipse.jdt.core.dom.BindingResolver#recordScope(ASTNode, BlockScope) |
| 614 | */ |
| 615 | @Override |
| 616 | synchronized void recordScope(ASTNode astNode, BlockScope blockScope) { |
| 617 | this.astNodesToBlockScope.put(astNode, blockScope); |
| 618 | } |
| 619 | |
| 620 | @Override |
| 621 | boolean resolveBoxing(Expression expression) { |
| 622 | org.eclipse.jdt.internal.compiler.ast.ASTNode node = (org.eclipse.jdt.internal.compiler.ast.ASTNode) this.newAstToOldAst.get(expression); |
| 623 | if (node instanceof org.eclipse.jdt.internal.compiler.ast.Expression && |
| 624 | ((org.eclipse.jdt.internal.compiler.ast.Expression) node).isTrulyExpression()) { |
| 625 | org.eclipse.jdt.internal.compiler.ast.Expression compilerExpression = (org.eclipse.jdt.internal.compiler.ast.Expression) node; |
| 626 | return (compilerExpression.implicitConversion & TypeIds.BOXING) != 0; |
| 627 | } |
| 628 | return false; |
| 629 | } |
| 630 | |
| 631 | @Override |
| 632 | boolean resolveUnboxing(Expression expression) { |
| 633 | org.eclipse.jdt.internal.compiler.ast.ASTNode node = (org.eclipse.jdt.internal.compiler.ast.ASTNode) this.newAstToOldAst.get(expression); |
| 634 | if (node instanceof org.eclipse.jdt.internal.compiler.ast.Expression) { |
| 635 | org.eclipse.jdt.internal.compiler.ast.Expression compilerExpression = (org.eclipse.jdt.internal.compiler.ast.Expression) node; |
| 636 | return (compilerExpression.implicitConversion & TypeIds.UNBOXING) != 0; |
| 637 | } |
| 638 | return false; |
| 639 | } |
| 640 | |
| 641 | @Override |
| 642 | Object resolveConstantExpressionValue(Expression expression) { |
| 643 | org.eclipse.jdt.internal.compiler.ast.ASTNode node = (org.eclipse.jdt.internal.compiler.ast.ASTNode) this.newAstToOldAst.get(expression); |
| 644 | if(node instanceof org.eclipse.jdt.internal.compiler.ast.FieldDeclaration) { |
| 645 | node = ((org.eclipse.jdt.internal.compiler.ast.FieldDeclaration) node).initialization; |
| 646 | } |
| 647 | if (node instanceof org.eclipse.jdt.internal.compiler.ast.Expression && |
| 648 | ((org.eclipse.jdt.internal.compiler.ast.Expression) node).isTrulyExpression()) { |
| 649 | org.eclipse.jdt.internal.compiler.ast.Expression compilerExpression = (org.eclipse.jdt.internal.compiler.ast.Expression) node; |
| 650 | Constant constant = compilerExpression.constant; |
| 651 | if (constant != null && constant != Constant.NotAConstant) { |
| 652 | switch (constant.typeID()) { |
| 653 | case TypeIds.T_int : return Integer.valueOf(constant.intValue()); |
| 654 | case TypeIds.T_byte : return Byte.valueOf(constant.byteValue()); |
| 655 | case TypeIds.T_short : return Short.valueOf(constant.shortValue()); |
| 656 | case TypeIds.T_char : return Character.valueOf(constant.charValue()); |
| 657 | case TypeIds.T_float : return Float.valueOf(constant.floatValue()); |
| 658 | case TypeIds.T_double : return Double.valueOf(constant.doubleValue()); |
| 659 | case TypeIds.T_boolean : return constant.booleanValue() ? Boolean.TRUE : Boolean.FALSE; |
| 660 | case TypeIds.T_long : return Long.valueOf(constant.longValue()); |
| 661 | case TypeIds.T_JavaLangString : return constant.stringValue(); |
| 662 | } |
| 663 | return null; |
| 664 | } |
| 665 | } |
| 666 | return null; |
| 667 | } |
| 668 | |
| 669 | @Override |
| 670 | synchronized IMethodBinding resolveConstructor(ClassInstanceCreation expression) { |
| 671 | org.eclipse.jdt.internal.compiler.ast.ASTNode node = (org.eclipse.jdt.internal.compiler.ast.ASTNode) this.newAstToOldAst.get(expression); |
| 672 | if (node != null && (node.bits & org.eclipse.jdt.internal.compiler.ast.ASTNode.IsAnonymousType) != 0) { |
| 673 | org.eclipse.jdt.internal.compiler.ast.TypeDeclaration anonymousLocalTypeDeclaration = (org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) node; |
| 674 | return getMethodBinding(anonymousLocalTypeDeclaration.allocation.binding); |
| 675 | } else if (node instanceof AllocationExpression) { |
| 676 | return getMethodBinding(((AllocationExpression)node).binding); |
| 677 | } |
| 678 | return null; |
| 679 | } |
| 680 | |
| 681 | @Override |
| 682 | synchronized IMethodBinding resolveConstructor(ConstructorInvocation expression) { |
| 683 | org.eclipse.jdt.internal.compiler.ast.ASTNode node = (org.eclipse.jdt.internal.compiler.ast.ASTNode) this.newAstToOldAst.get(expression); |
| 684 | if (node instanceof ExplicitConstructorCall) { |
| 685 | ExplicitConstructorCall explicitConstructorCall = (ExplicitConstructorCall) node; |
| 686 | return getMethodBinding(explicitConstructorCall.binding); |
| 687 | } |
| 688 | return null; |
| 689 | } |
| 690 | |
| 691 | @Override |
| 692 | IMethodBinding resolveConstructor(EnumConstantDeclaration enumConstantDeclaration) { |
| 693 | org.eclipse.jdt.internal.compiler.ast.ASTNode node = (org.eclipse.jdt.internal.compiler.ast.ASTNode) this.newAstToOldAst.get(enumConstantDeclaration); |
| 694 | if (node instanceof org.eclipse.jdt.internal.compiler.ast.FieldDeclaration) { |
| 695 | org.eclipse.jdt.internal.compiler.ast.FieldDeclaration fieldDeclaration = (org.eclipse.jdt.internal.compiler.ast.FieldDeclaration) node; |
| 696 | if (fieldDeclaration.getKind() == AbstractVariableDeclaration.ENUM_CONSTANT && fieldDeclaration.initialization != null) { |
| 697 | AllocationExpression allocationExpression = (AllocationExpression) fieldDeclaration.initialization; |
| 698 | return getMethodBinding(allocationExpression.binding); |
| 699 | } |
| 700 | } |
| 701 | return null; |
| 702 | } |
| 703 | |
| 704 | @Override |
| 705 | synchronized IMethodBinding resolveConstructor(SuperConstructorInvocation expression) { |
| 706 | org.eclipse.jdt.internal.compiler.ast.ASTNode node = (org.eclipse.jdt.internal.compiler.ast.ASTNode) this.newAstToOldAst.get(expression); |
| 707 | if (node instanceof ExplicitConstructorCall) { |
| 708 | ExplicitConstructorCall explicitConstructorCall = (ExplicitConstructorCall) node; |
| 709 | return getMethodBinding(explicitConstructorCall.binding); |
| 710 | } |
| 711 | return null; |
| 712 | } |
| 713 | |
| 714 | @Override |
| 715 | synchronized ITypeBinding resolveExpressionType(Expression expression) { |
| 716 | try { |
| 717 | switch(expression.getNodeType()) { |
| 718 | case ASTNode.CLASS_INSTANCE_CREATION : |
| 719 | org.eclipse.jdt.internal.compiler.ast.ASTNode astNode = (org.eclipse.jdt.internal.compiler.ast.ASTNode) this.newAstToOldAst.get(expression); |
| 720 | if (astNode instanceof org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) { |
| 721 | // anonymous type case |
| 722 | org.eclipse.jdt.internal.compiler.ast.TypeDeclaration typeDeclaration = (org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) astNode; |
| 723 | ITypeBinding typeBinding = this.getTypeBinding(typeDeclaration.binding); |
| 724 | if (typeBinding != null) { |
| 725 | return typeBinding; |
| 726 | } |
| 727 | } else if (astNode instanceof AllocationExpression) { |
| 728 | // should be an AllocationExpression |
| 729 | AllocationExpression allocationExpression = (AllocationExpression) astNode; |
| 730 | return this.getTypeBinding(allocationExpression.resolvedType); |
| 731 | } |
| 732 | break; |
| 733 | case ASTNode.SIMPLE_NAME : |
| 734 | case ASTNode.QUALIFIED_NAME : |
| 735 | return resolveTypeBindingForName((Name) expression); |
| 736 | case ASTNode.ARRAY_INITIALIZER : |
| 737 | case ASTNode.ARRAY_CREATION : |
| 738 | case ASTNode.ASSIGNMENT : |
| 739 | case ASTNode.POSTFIX_EXPRESSION : |
| 740 | case ASTNode.PREFIX_EXPRESSION : |
| 741 | case ASTNode.CAST_EXPRESSION : |
| 742 | case ASTNode.TYPE_LITERAL : |
| 743 | case ASTNode.INFIX_EXPRESSION : |
| 744 | case ASTNode.INSTANCEOF_EXPRESSION : |
| 745 | case ASTNode.LAMBDA_EXPRESSION: |
| 746 | case ASTNode.CREATION_REFERENCE: |
| 747 | case ASTNode.EXPRESSION_METHOD_REFERENCE: |
| 748 | case ASTNode.TYPE_METHOD_REFERENCE: |
| 749 | case ASTNode.SUPER_METHOD_REFERENCE : |
| 750 | case ASTNode.FIELD_ACCESS : |
| 751 | case ASTNode.SUPER_FIELD_ACCESS : |
| 752 | case ASTNode.ARRAY_ACCESS : |
| 753 | case ASTNode.METHOD_INVOCATION : |
| 754 | case ASTNode.SUPER_METHOD_INVOCATION : |
| 755 | case ASTNode.CONDITIONAL_EXPRESSION : |
| 756 | case ASTNode.SWITCH_EXPRESSION : |
| 757 | case ASTNode.MARKER_ANNOTATION : |
| 758 | case ASTNode.NORMAL_ANNOTATION : |
| 759 | case ASTNode.SINGLE_MEMBER_ANNOTATION : |
| 760 | case ASTNode.GUARDED_PATTERN : |
| 761 | case ASTNode.TYPE_PATTERN : |
| 762 | org.eclipse.jdt.internal.compiler.ast.Expression compilerExpression = (org.eclipse.jdt.internal.compiler.ast.Expression) this.newAstToOldAst.get(expression); |
| 763 | if (compilerExpression != null) { |
| 764 | return this.getTypeBinding(compilerExpression.resolvedType); |
| 765 | } |
| 766 | break; |
| 767 | case ASTNode.TEXT_BLOCK : |
| 768 | case ASTNode.STRING_LITERAL : |
| 769 | if (this.scope != null) { |
| 770 | return this.getTypeBinding(this.scope.getJavaLangString()); |
| 771 | } |
| 772 | break; |
| 773 | case ASTNode.NULL_PATTERN : |
| 774 | return null; |
| 775 | case ASTNode.BOOLEAN_LITERAL : |
| 776 | case ASTNode.NULL_LITERAL : |
| 777 | case ASTNode.CHARACTER_LITERAL : |
| 778 | case ASTNode.NUMBER_LITERAL : |
| 779 | Literal literal = (Literal) this.newAstToOldAst.get(expression); |
| 780 | if (literal != null) { |
| 781 | return this.getTypeBinding(literal.literalType(null)); |
| 782 | } |
| 783 | break; |
| 784 | case ASTNode.THIS_EXPRESSION : |
| 785 | ThisReference thisReference = (ThisReference) this.newAstToOldAst.get(expression); |
| 786 | BlockScope blockScope = (BlockScope) this.astNodesToBlockScope.get(expression); |
| 787 | if (blockScope != null) { |
| 788 | return this.getTypeBinding(thisReference.resolveType(blockScope)); |
| 789 | } |
| 790 | break; |
| 791 | case ASTNode.PARENTHESIZED_EXPRESSION : |
| 792 | ParenthesizedExpression parenthesizedExpression = (ParenthesizedExpression) expression; |
| 793 | return resolveExpressionType(parenthesizedExpression.getExpression()); |
| 794 | case ASTNode.VARIABLE_DECLARATION_EXPRESSION : |
| 795 | VariableDeclarationExpression variableDeclarationExpression = (VariableDeclarationExpression) expression; |
| 796 | Type type = variableDeclarationExpression.getType(); |
| 797 | if (type != null) { |
| 798 | return type.resolveBinding(); |
| 799 | } |
| 800 | break; |
| 801 | } |
| 802 | } catch (AbortCompilation e) { |
| 803 | // handle missing types |
| 804 | } |
| 805 | return null; |
| 806 | } |
| 807 | |
| 808 | @Override |
| 809 | synchronized IVariableBinding resolveField(FieldAccess fieldAccess) { |
| 810 | Object oldNode = this.newAstToOldAst.get(fieldAccess); |
| 811 | if (oldNode instanceof FieldReference) { |
| 812 | FieldReference fieldReference = (FieldReference) oldNode; |
| 813 | return this.getVariableBinding(fieldReference.binding); |
| 814 | } |
| 815 | return null; |
| 816 | } |
| 817 | |
| 818 | @Override |
| 819 | synchronized IVariableBinding resolveField(SuperFieldAccess fieldAccess) { |
| 820 | Object oldNode = this.newAstToOldAst.get(fieldAccess); |
| 821 | if (oldNode instanceof FieldReference) { |
| 822 | FieldReference fieldReference = (FieldReference) oldNode; |
| 823 | return this.getVariableBinding(fieldReference.binding); |
| 824 | } |
| 825 | return null; |
| 826 | } |
| 827 | |
| 828 | @Override |
| 829 | synchronized IBinding resolveImport(ImportDeclaration importDeclaration) { |
| 830 | if (this.scope == null) return null; |
| 831 | try { |
| 832 | org.eclipse.jdt.internal.compiler.ast.ASTNode node = (org.eclipse.jdt.internal.compiler.ast.ASTNode) this.newAstToOldAst.get(importDeclaration); |
| 833 | if (node instanceof ImportReference) { |
| 834 | ImportReference importReference = (ImportReference) node; |
| 835 | final boolean isStatic = importReference.isStatic(); |
| 836 | if ((importReference.bits & org.eclipse.jdt.internal.compiler.ast.ASTNode.OnDemand) != 0) { |
| 837 | Binding binding = this.scope.getImport(CharOperation.subarray(importReference.tokens, 0, importReference.tokens.length), true, isStatic); |
| 838 | if (binding != null) { |
| 839 | if (isStatic) { |
| 840 | if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.TypeBinding) { |
| 841 | ITypeBinding typeBinding = this.getTypeBinding((org.eclipse.jdt.internal.compiler.lookup.TypeBinding) binding); |
| 842 | return typeBinding == null ? null : typeBinding; |
| 843 | } |
| 844 | } else { |
| 845 | if ((binding.kind() & Binding.PACKAGE) != 0) { |
| 846 | IPackageBinding packageBinding = getPackageBinding((org.eclipse.jdt.internal.compiler.lookup.PackageBinding) binding); |
| 847 | if (packageBinding == null) { |
| 848 | return null; |
| 849 | } |
| 850 | return packageBinding; |
| 851 | } else { |
| 852 | // if it is not a package, it has to be a type |
| 853 | ITypeBinding typeBinding = this.getTypeBinding((org.eclipse.jdt.internal.compiler.lookup.TypeBinding) binding); |
| 854 | if (typeBinding == null) { |
| 855 | return null; |
| 856 | } |
| 857 | return typeBinding; |
| 858 | } |
| 859 | } |
| 860 | } |
| 861 | } else { |
| 862 | Binding binding = this.scope.getImport(importReference.tokens, false, isStatic); |
| 863 | if (binding != null) { |
| 864 | if (isStatic) { |
| 865 | if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.TypeBinding) { |
| 866 | ITypeBinding typeBinding = this.getTypeBinding((org.eclipse.jdt.internal.compiler.lookup.TypeBinding) binding); |
| 867 | return typeBinding == null ? null : typeBinding; |
| 868 | } else if (binding instanceof FieldBinding) { |
| 869 | IVariableBinding variableBinding = this.getVariableBinding((FieldBinding) binding); |
| 870 | return variableBinding == null ? null : variableBinding; |
| 871 | } else if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.MethodBinding) { |
| 872 | // it is a type |
| 873 | return getMethodBinding((org.eclipse.jdt.internal.compiler.lookup.MethodBinding)binding); |
| 874 | } else if (binding instanceof RecordComponentBinding) { |
| 875 | IVariableBinding variableBinding = this.getVariableBinding((RecordComponentBinding) binding); |
| 876 | return variableBinding == null ? null : variableBinding; |
| 877 | } |
| 878 | } else { |
| 879 | if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.TypeBinding) { |
| 880 | ITypeBinding typeBinding = this.getTypeBinding((org.eclipse.jdt.internal.compiler.lookup.TypeBinding) binding); |
| 881 | return typeBinding == null ? null : typeBinding; |
| 882 | } |
| 883 | } |
| 884 | } |
| 885 | } |
| 886 | } |
| 887 | } catch(AbortCompilation e) { |
| 888 | // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=53357 |
| 889 | // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=63550 |
| 890 | // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=64299 |
| 891 | } |
| 892 | return null; |
| 893 | } |
| 894 | |
| 895 | @Override |
| 896 | IMethodBinding resolveMember(AnnotationTypeMemberDeclaration declaration) { |
| 897 | Object oldNode = this.newAstToOldAst.get(declaration); |
| 898 | if (oldNode instanceof AbstractMethodDeclaration) { |
| 899 | AbstractMethodDeclaration methodDeclaration = (AbstractMethodDeclaration) oldNode; |
| 900 | IMethodBinding methodBinding = getMethodBinding(methodDeclaration.binding); |
| 901 | if (methodBinding == null) { |
| 902 | return null; |
| 903 | } |
| 904 | this.bindingsToAstNodes.put(methodBinding, declaration); |
| 905 | String key = methodBinding.getKey(); |
| 906 | if (key != null) { |
| 907 | this.bindingTables.bindingKeysToBindings.put(key, methodBinding); |
| 908 | } |
| 909 | return methodBinding; |
| 910 | } |
| 911 | return null; |
| 912 | } |
| 913 | |
| 914 | private IVariableBinding[] getSyntheticOuterLocalVariables(org.eclipse.jdt.internal.compiler.ast.LambdaExpression lambdaExpression) { |
| 915 | IVariableBinding[] syntheticOuterLocals = new IVariableBinding[lambdaExpression.outerLocalVariables.length]; |
| 916 | int i = 0; |
| 917 | for (SyntheticArgumentBinding sab : lambdaExpression.outerLocalVariables) { |
| 918 | syntheticOuterLocals[i++] = getVariableBinding(sab); |
| 919 | } |
| 920 | return syntheticOuterLocals; |
| 921 | } |
| 922 | @Override |
| 923 | synchronized IMethodBinding resolveMethod(LambdaExpression lambda) { |
| 924 | Object oldNode = this.newAstToOldAst.get(lambda); |
| 925 | if (oldNode instanceof org.eclipse.jdt.internal.compiler.ast.LambdaExpression) { |
| 926 | org.eclipse.jdt.internal.compiler.ast.LambdaExpression lambdaExpression = (org.eclipse.jdt.internal.compiler.ast.LambdaExpression) oldNode; |
| 927 | IMethodBinding methodBinding = null; |
| 928 | if (lambdaExpression.descriptor != null) { |
| 929 | IBinding declaringMember = getDeclaringMember(lambdaExpression, lambdaExpression.enclosingScope); |
| 930 | if (declaringMember != null) |
| 931 | methodBinding = getMethodOrLambdaBinding(lambdaExpression.getMethodBinding(), lambdaExpression.descriptor, declaringMember); |
| 932 | } |
| 933 | if (methodBinding == null) { |
| 934 | return null; |
| 935 | } |
| 936 | if (methodBinding instanceof LambdaMethod) { |
| 937 | ((LambdaMethod) methodBinding).setSyntheticOuterLocals(getSyntheticOuterLocalVariables(lambdaExpression)); |
| 938 | } |
| 939 | this.bindingsToAstNodes.put(methodBinding, lambda); |
| 940 | String key = methodBinding.getKey(); |
| 941 | if (key != null) { |
| 942 | this.bindingTables.bindingKeysToBindings.put(key, methodBinding); |
| 943 | } |
| 944 | return methodBinding; |
| 945 | } |
| 946 | return null; |
| 947 | } |
| 948 | |
| 949 | private IBinding getDeclaringMember(org.eclipse.jdt.internal.compiler.ast.ASTNode node, Scope currentScope) { |
| 950 | MethodScope methodScope = currentScope != null ? currentScope.methodScope() : null; |
| 951 | if (methodScope != null) { |
| 952 | if (methodScope.isInsideInitializer()) { |
| 953 | org.eclipse.jdt.internal.compiler.ast.TypeDeclaration enclosingType = methodScope.referenceType(); |
| 954 | if (enclosingType.fields != null) { |
| 955 | for (int i = 0; i < enclosingType.fields.length; i++) { |
| 956 | FieldDeclaration field = enclosingType.fields[i]; |
| 957 | if (field.declarationSourceStart <= node.sourceStart && node.sourceEnd <= field.declarationSourceEnd) { |
| 958 | if (field instanceof org.eclipse.jdt.internal.compiler.ast.Initializer) |
| 959 | return getMethodBinding(((org.eclipse.jdt.internal.compiler.ast.Initializer) field).getMethodBinding()); |
| 960 | else |
| 961 | return getVariableBinding(field.binding); |
| 962 | } |
| 963 | } |
| 964 | } |
| 965 | } else { |
| 966 | if (methodScope.isLambdaScope()) { |
| 967 | org.eclipse.jdt.internal.compiler.ast.LambdaExpression lambdaExpression = (org.eclipse.jdt.internal.compiler.ast.LambdaExpression) methodScope.referenceContext; |
| 968 | IMethodBinding methodBinding = null; |
| 969 | if (lambdaExpression.descriptor != null) { |
| 970 | IBinding declaringMember = getDeclaringMember(lambdaExpression, lambdaExpression.enclosingScope); |
| 971 | if (declaringMember != null) |
| 972 | methodBinding = getMethodOrLambdaBinding(lambdaExpression.getMethodBinding(), lambdaExpression.descriptor, declaringMember); |
| 973 | } |
| 974 | if (methodBinding == null) { |
| 975 | return null; |
| 976 | } |
| 977 | String key = methodBinding.getKey(); |
| 978 | if (key != null) { |
| 979 | this.bindingTables.bindingKeysToBindings.put(key, methodBinding); |
| 980 | } |
| 981 | return methodBinding; |
| 982 | } else { |
| 983 | return getMethodBinding(methodScope.referenceMethodBinding()); |
| 984 | } |
| 985 | } |
| 986 | } |
| 987 | return null; |
| 988 | } |
| 989 | |
| 990 | @Override |
| 991 | synchronized IMethodBinding resolveMethod(MethodDeclaration method) { |
| 992 | Object oldNode = this.newAstToOldAst.get(method); |
| 993 | if (oldNode instanceof AbstractMethodDeclaration) { |
| 994 | AbstractMethodDeclaration methodDeclaration = (AbstractMethodDeclaration) oldNode; |
| 995 | IMethodBinding methodBinding = getMethodBinding(methodDeclaration.binding); |
| 996 | if (methodBinding == null) { |
| 997 | return null; |
| 998 | } |
| 999 | this.bindingsToAstNodes.put(methodBinding, method); |
| 1000 | String key = methodBinding.getKey(); |
| 1001 | if (key != null) { |
| 1002 | this.bindingTables.bindingKeysToBindings.put(key, methodBinding); |
| 1003 | } |
| 1004 | return methodBinding; |
| 1005 | } |
| 1006 | return null; |
| 1007 | } |
| 1008 | |
| 1009 | @Override |
| 1010 | synchronized IMethodBinding resolveMethod(MethodInvocation method) { |
| 1011 | Object oldNode = this.newAstToOldAst.get(method); |
| 1012 | if (oldNode instanceof MessageSend) { |
| 1013 | MessageSend messageSend = (MessageSend) oldNode; |
| 1014 | return getMethodBinding(messageSend.binding); |
| 1015 | } |
| 1016 | return null; |
| 1017 | } |
| 1018 | |
| 1019 | @Override |
| 1020 | synchronized IMethodBinding resolveMethod(MethodReference methodReference) { |
| 1021 | Object oldNode = this.newAstToOldAst.get(methodReference); |
| 1022 | if (oldNode instanceof org.eclipse.jdt.internal.compiler.ast.ReferenceExpression) { |
| 1023 | org.eclipse.jdt.internal.compiler.ast.ReferenceExpression referenceExpression = (org.eclipse.jdt.internal.compiler.ast.ReferenceExpression) oldNode; |
| 1024 | if (referenceExpression.receiverType != null && referenceExpression.receiverType.isArrayType()) |
| 1025 | return null; |
| 1026 | IMethodBinding methodBinding = getMethodBinding(referenceExpression.getMethodBinding()); |
| 1027 | if (methodBinding == null) { |
| 1028 | return null; |
| 1029 | } |
| 1030 | return methodBinding; |
| 1031 | } |
| 1032 | return null; |
| 1033 | } |
| 1034 | |
| 1035 | @Override |
| 1036 | synchronized IMethodBinding resolveMethod(SuperMethodInvocation method) { |
| 1037 | Object oldNode = this.newAstToOldAst.get(method); |
| 1038 | if (oldNode instanceof MessageSend) { |
| 1039 | MessageSend messageSend = (MessageSend) oldNode; |
| 1040 | return getMethodBinding(messageSend.binding); |
| 1041 | } |
| 1042 | return null; |
| 1043 | } |
| 1044 | |
| 1045 | synchronized ITypeBinding resolveTypeBindingForName(Name name) { |
| 1046 | org.eclipse.jdt.internal.compiler.ast.ASTNode node = (org.eclipse.jdt.internal.compiler.ast.ASTNode) this.newAstToOldAst.get(name); |
| 1047 | int index = name.index; |
| 1048 | if (node instanceof QualifiedNameReference) { |
| 1049 | QualifiedNameReference qualifiedNameReference = (QualifiedNameReference) node; |
| 1050 | final char[][] tokens = qualifiedNameReference.tokens; |
| 1051 | if (tokens.length == index) { |
| 1052 | return this.getTypeBinding(qualifiedNameReference.resolvedType); |
| 1053 | } |
| 1054 | int indexOfFirstFieldBinding = qualifiedNameReference.indexOfFirstFieldBinding; // one-based |
| 1055 | if (index < indexOfFirstFieldBinding) { |
| 1056 | // an extra lookup is required |
| 1057 | BlockScope internalScope = (BlockScope) this.astNodesToBlockScope.get(name); |
| 1058 | Binding binding = null; |
| 1059 | try { |
| 1060 | if (internalScope == null) { |
| 1061 | if (this.scope == null) return null; |
| 1062 | binding = this.scope.getTypeOrPackage(CharOperation.subarray(tokens, 0, index)); |
| 1063 | } else { |
| 1064 | binding = internalScope.getTypeOrPackage(CharOperation.subarray(tokens, 0, index)); |
| 1065 | } |
| 1066 | } catch (AbortCompilation e) { |
| 1067 | // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=53357 |
| 1068 | // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=63550 |
| 1069 | // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=64299 |
| 1070 | } |
| 1071 | if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.PackageBinding) { |
| 1072 | return null; |
| 1073 | } else if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.TypeBinding) { |
| 1074 | // it is a type |
| 1075 | return this.getTypeBinding((org.eclipse.jdt.internal.compiler.lookup.TypeBinding)binding); |
| 1076 | } |
| 1077 | } else if (index == indexOfFirstFieldBinding) { |
| 1078 | if (qualifiedNameReference.isTypeReference()) { |
| 1079 | return this.getTypeBinding(qualifiedNameReference.resolvedType); |
| 1080 | } else { |
| 1081 | // in this case we want to get the next field declaring's class |
| 1082 | if (qualifiedNameReference.otherBindings == null) { |
| 1083 | return null; |
| 1084 | } |
| 1085 | FieldBinding fieldBinding = qualifiedNameReference.otherBindings[0]; |
| 1086 | if (fieldBinding == null) return null; |
| 1087 | org.eclipse.jdt.internal.compiler.lookup.TypeBinding type = fieldBinding.declaringClass; |
| 1088 | if (type == null) { // array length scenario |
| 1089 | // use type from first binding (no capture needed for array type) |
| 1090 | switch (qualifiedNameReference.bits & org.eclipse.jdt.internal.compiler.ast.ASTNode.RestrictiveFlagMASK) { |
| 1091 | case Binding.FIELD: |
| 1092 | type = ((FieldBinding) qualifiedNameReference.binding).type; |
| 1093 | break; |
| 1094 | case Binding.LOCAL: |
| 1095 | type = ((LocalVariableBinding) qualifiedNameReference.binding).type; |
| 1096 | break; |
| 1097 | case Binding.RECORD_COMPONENT: |
| 1098 | type = ((RecordComponentBinding) qualifiedNameReference.binding).type; |
| 1099 | break; |
| 1100 | } |
| 1101 | } |
| 1102 | return this.getTypeBinding(type); |
| 1103 | } |
| 1104 | } else { |
| 1105 | /* This is the case for a name which is part of a qualified name that |
| 1106 | * cannot be resolved. See PR 13063. |
| 1107 | */ |
| 1108 | if (qualifiedNameReference.otherBindings == null) return null; |
| 1109 | final int otherBindingsLength = qualifiedNameReference.otherBindings.length; |
| 1110 | if (otherBindingsLength == (index - indexOfFirstFieldBinding)) { |
| 1111 | return this.getTypeBinding(qualifiedNameReference.resolvedType); |
| 1112 | } |
| 1113 | FieldBinding fieldBinding = qualifiedNameReference.otherBindings[index - indexOfFirstFieldBinding]; |
| 1114 | if (fieldBinding == null) return null; |
| 1115 | org.eclipse.jdt.internal.compiler.lookup.TypeBinding type = fieldBinding.declaringClass; |
| 1116 | if (type == null) { // array length scenario |
| 1117 | // use type from previous binding (no capture needed for array type) |
| 1118 | fieldBinding = qualifiedNameReference.otherBindings[index - indexOfFirstFieldBinding - 1]; |
| 1119 | if (fieldBinding == null) return null; |
| 1120 | type = fieldBinding.type; |
| 1121 | } |
| 1122 | return this.getTypeBinding(type); |
| 1123 | } |
| 1124 | } else if (node instanceof QualifiedTypeReference) { |
| 1125 | QualifiedTypeReference qualifiedTypeReference = (QualifiedTypeReference) node; |
| 1126 | if (qualifiedTypeReference.resolvedType == null) { |
| 1127 | return null; |
| 1128 | } |
| 1129 | if (index == qualifiedTypeReference.tokens.length) { |
| 1130 | if (!qualifiedTypeReference.resolvedType.isValidBinding() && qualifiedTypeReference instanceof JavadocQualifiedTypeReference) { |
| 1131 | JavadocQualifiedTypeReference typeRef = (JavadocQualifiedTypeReference) node; |
| 1132 | if (typeRef.packageBinding != null) { |
| 1133 | return null; |
| 1134 | } |
| 1135 | } |
| 1136 | return this.getTypeBinding(qualifiedTypeReference.resolvedType.leafComponentType()); |
| 1137 | } else { |
| 1138 | if (index >= 0) { |
| 1139 | BlockScope internalScope = (BlockScope) this.astNodesToBlockScope.get(name); |
| 1140 | Binding binding = null; |
| 1141 | try { |
| 1142 | if (internalScope == null) { |
| 1143 | if (this.scope == null) return null; |
| 1144 | binding = this.scope.getTypeOrPackage(CharOperation.subarray(qualifiedTypeReference.tokens, 0, index)); |
| 1145 | } else { |
| 1146 | binding = internalScope.getTypeOrPackage(CharOperation.subarray(qualifiedTypeReference.tokens, 0, index)); |
| 1147 | } |
| 1148 | } catch (AbortCompilation e) { |
| 1149 | // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=53357 |
| 1150 | } |
| 1151 | if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.PackageBinding) { |
| 1152 | return null; |
| 1153 | } else if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.TypeBinding) { |
| 1154 | // it is a type |
| 1155 | return this.getTypeBinding((org.eclipse.jdt.internal.compiler.lookup.TypeBinding)binding); |
| 1156 | } else { |
| 1157 | return null; |
| 1158 | } |
| 1159 | } |
| 1160 | } |
| 1161 | } else if (node instanceof ImportReference) { |
| 1162 | if ((node.bits & org.eclipse.jdt.internal.compiler.ast.ASTNode.inModule) != 0) |
| 1163 | return null; |
| 1164 | ImportReference importReference = (ImportReference) node; |
| 1165 | int importReferenceLength = importReference.tokens.length; |
| 1166 | if (index >= 0) { |
| 1167 | Binding binding = null; |
| 1168 | if (this.scope == null) return null; |
| 1169 | if (importReferenceLength == index) { |
| 1170 | try { |
| 1171 | binding = this.scope.getImport(CharOperation.subarray(importReference.tokens, 0, index), (importReference.bits & org.eclipse.jdt.internal.compiler.ast.ASTNode.OnDemand) != 0, importReference.isStatic()); |
| 1172 | } catch (AbortCompilation e) { |
| 1173 | // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=53357 |
| 1174 | } |
| 1175 | } else { |
| 1176 | try { |
| 1177 | binding = this.scope.getImport(CharOperation.subarray(importReference.tokens, 0, index), true, importReference.isStatic()); |
| 1178 | } catch (AbortCompilation e) { |
| 1179 | // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=53357 |
| 1180 | } |
| 1181 | } |
| 1182 | if (binding != null) { |
| 1183 | if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.TypeBinding) { |
| 1184 | // it is a type |
| 1185 | return this.getTypeBinding((org.eclipse.jdt.internal.compiler.lookup.TypeBinding)binding); |
| 1186 | } |
| 1187 | return null; |
| 1188 | } |
| 1189 | } |
| 1190 | } else if (node instanceof AbstractMethodDeclaration) { |
| 1191 | AbstractMethodDeclaration methodDeclaration = (AbstractMethodDeclaration) node; |
| 1192 | IMethodBinding method = getMethodBinding(methodDeclaration.binding); |
| 1193 | if (method == null) return null; |
| 1194 | return method.getReturnType(); |
| 1195 | } else if (node instanceof org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) { |
| 1196 | org.eclipse.jdt.internal.compiler.ast.TypeDeclaration typeDeclaration = (org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) node; |
| 1197 | ITypeBinding typeBinding = this.getTypeBinding(typeDeclaration.binding); |
| 1198 | if (typeBinding != null) { |
| 1199 | return typeBinding; |
| 1200 | } |
| 1201 | } if (node instanceof JavadocSingleNameReference) { |
| 1202 | JavadocSingleNameReference singleNameReference = (JavadocSingleNameReference) node; |
| 1203 | org.eclipse.jdt.internal.compiler.lookup.VariableBinding localVariable = (org.eclipse.jdt.internal.compiler.lookup.VariableBinding)singleNameReference.binding; |
| 1204 | if (localVariable != null) { |
| 1205 | return this.getTypeBinding(localVariable.type); |
| 1206 | } |
| 1207 | } if (node instanceof SingleNameReference) { |
| 1208 | SingleNameReference singleNameReference = (SingleNameReference) node; |
| 1209 | return this.getTypeBinding(singleNameReference.resolvedType); |
| 1210 | } else if (node instanceof QualifiedSuperReference) { |
| 1211 | QualifiedSuperReference qualifiedSuperReference = (QualifiedSuperReference) node; |
| 1212 | return this.getTypeBinding(qualifiedSuperReference.qualification.resolvedType); |
| 1213 | } else if (node instanceof Receiver) { |
| 1214 | org.eclipse.jdt.internal.compiler.lookup.TypeBinding receiver = ((Receiver) node).type.resolvedType; |
| 1215 | return this.getTypeBinding(receiver); |
| 1216 | } else if (node instanceof LocalDeclaration) { |
| 1217 | IVariableBinding variable = this.getVariableBinding(((LocalDeclaration)node).binding); |
| 1218 | if (variable == null) return null; |
| 1219 | return variable.getType(); |
| 1220 | } else if (node instanceof JavadocFieldReference) { |
| 1221 | JavadocFieldReference fieldRef = (JavadocFieldReference) node; |
| 1222 | if (fieldRef.methodBinding != null) { |
| 1223 | return getMethodBinding(fieldRef.methodBinding).getReturnType(); |
| 1224 | } |
| 1225 | return getTypeBinding(fieldRef.resolvedType); |
| 1226 | } else if (node instanceof FieldReference) { |
| 1227 | return getTypeBinding(((FieldReference) node).resolvedType); |
| 1228 | } else if (node instanceof SingleTypeReference) { |
| 1229 | SingleTypeReference singleTypeReference = (SingleTypeReference) node; |
| 1230 | org.eclipse.jdt.internal.compiler.lookup.TypeBinding binding = singleTypeReference.resolvedType; |
| 1231 | if (binding != null) { |
| 1232 | return this.getTypeBinding(binding.leafComponentType()); |
| 1233 | } |
| 1234 | } else if (node instanceof org.eclipse.jdt.internal.compiler.ast.FieldDeclaration) { |
| 1235 | org.eclipse.jdt.internal.compiler.ast.FieldDeclaration fieldDeclaration = (org.eclipse.jdt.internal.compiler.ast.FieldDeclaration) node; |
| 1236 | IVariableBinding field = this.getVariableBinding(fieldDeclaration.binding); |
| 1237 | if (field == null) return null; |
| 1238 | return field.getType(); |
| 1239 | } else if (node instanceof MessageSend) { |
| 1240 | MessageSend messageSend = (MessageSend) node; |
| 1241 | IMethodBinding method = getMethodBinding(messageSend.binding); |
| 1242 | if (method == null) return null; |
| 1243 | return method.getReturnType(); |
| 1244 | } else if (node instanceof AllocationExpression) { |
| 1245 | AllocationExpression allocation = (AllocationExpression) node; |
| 1246 | return getTypeBinding(allocation.resolvedType); |
| 1247 | } else if (node instanceof JavadocImplicitTypeReference) { |
| 1248 | JavadocImplicitTypeReference implicitRef = (JavadocImplicitTypeReference) node; |
| 1249 | return getTypeBinding(implicitRef.resolvedType); |
| 1250 | } else if (node instanceof org.eclipse.jdt.internal.compiler.ast.TypeParameter) { |
| 1251 | org.eclipse.jdt.internal.compiler.ast.TypeParameter typeParameter = (org.eclipse.jdt.internal.compiler.ast.TypeParameter) node; |
| 1252 | return this.getTypeBinding(typeParameter.binding); |
| 1253 | } else if (node instanceof org.eclipse.jdt.internal.compiler.ast.MemberValuePair) { |
| 1254 | org.eclipse.jdt.internal.compiler.ast.MemberValuePair memberValuePair = (org.eclipse.jdt.internal.compiler.ast.MemberValuePair) node; |
| 1255 | IMethodBinding method = getMethodBinding(memberValuePair.binding); |
| 1256 | if (method == null) return null; |
| 1257 | return method.getReturnType(); |
| 1258 | } else if (node instanceof org.eclipse.jdt.internal.compiler.ast.ReferenceExpression) { |
| 1259 | org.eclipse.jdt.internal.compiler.ast.ReferenceExpression referenceExpression = (org.eclipse.jdt.internal.compiler.ast.ReferenceExpression) node; |
| 1260 | IMethodBinding method = getMethodBinding(referenceExpression.getMethodBinding()); |
| 1261 | if (method == null) return null; |
| 1262 | return method.getReturnType(); |
| 1263 | } else if (node instanceof org.eclipse.jdt.internal.compiler.ast.RecordComponent) { |
| 1264 | org.eclipse.jdt.internal.compiler.ast.RecordComponent recordComponent = (org.eclipse.jdt.internal.compiler.ast.RecordComponent) node; |
| 1265 | org.eclipse.jdt.internal.compiler.lookup.TypeBinding recordComponentType = recordComponent.type.resolvedType; |
| 1266 | return this.getTypeBinding(recordComponentType); |
| 1267 | } |
| 1268 | return null; |
| 1269 | } |
| 1270 | |
| 1271 | @Override |
| 1272 | synchronized IBinding resolveName(Name name) { |
| 1273 | org.eclipse.jdt.internal.compiler.ast.ASTNode node = (org.eclipse.jdt.internal.compiler.ast.ASTNode) this.newAstToOldAst.get(name); |
| 1274 | int index = name.index; |
| 1275 | if (node instanceof QualifiedNameReference) { |
| 1276 | QualifiedNameReference qualifiedNameReference = (QualifiedNameReference) node; |
| 1277 | final char[][] tokens = qualifiedNameReference.tokens; |
| 1278 | int indexOfFirstFieldBinding = qualifiedNameReference.indexOfFirstFieldBinding; // one-based |
| 1279 | if (index < indexOfFirstFieldBinding) { |
| 1280 | // an extra lookup is required |
| 1281 | BlockScope internalScope = (BlockScope) this.astNodesToBlockScope.get(name); |
| 1282 | Binding binding = null; |
| 1283 | try { |
| 1284 | if (internalScope == null) { |
| 1285 | if (this.scope == null) return null; |
| 1286 | binding = this.scope.getTypeOrPackage(CharOperation.subarray(tokens, 0, index)); |
| 1287 | } else { |
| 1288 | binding = internalScope.getTypeOrPackage(CharOperation.subarray(tokens, 0, index)); |
| 1289 | } |
| 1290 | } catch (AbortCompilation e) { |
| 1291 | // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=53357 |
| 1292 | // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=63550 |
| 1293 | // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=64299 |
| 1294 | } |
| 1295 | if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.PackageBinding) { |
| 1296 | return getPackageBinding((org.eclipse.jdt.internal.compiler.lookup.PackageBinding)binding); |
| 1297 | } else if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.TypeBinding) { |
| 1298 | // it is a type |
| 1299 | return this.getTypeBinding((org.eclipse.jdt.internal.compiler.lookup.TypeBinding)binding); |
| 1300 | } |
| 1301 | } else if (index == indexOfFirstFieldBinding) { |
| 1302 | if (qualifiedNameReference.isTypeReference()) { |
| 1303 | return this.getTypeBinding(qualifiedNameReference.resolvedType); |
| 1304 | } else { |
| 1305 | Binding binding = qualifiedNameReference.binding; |
| 1306 | if (binding != null) { |
| 1307 | if (binding.isValidBinding()) { |
| 1308 | return this.getVariableBinding((org.eclipse.jdt.internal.compiler.lookup.VariableBinding) binding); |
| 1309 | } else if (binding instanceof ProblemFieldBinding) { |
| 1310 | ProblemFieldBinding problemFieldBinding = (ProblemFieldBinding) binding; |
| 1311 | switch(problemFieldBinding.problemId()) { |
| 1312 | case ProblemReasons.NotVisible : |
| 1313 | case ProblemReasons.NonStaticReferenceInStaticContext : |
| 1314 | ReferenceBinding declaringClass = problemFieldBinding.declaringClass; |
| 1315 | if (declaringClass != null) { |
| 1316 | FieldBinding exactBinding = declaringClass.getField(tokens[tokens.length - 1], true /*resolve*/); |
| 1317 | if (exactBinding != null) { |
| 1318 | if (exactBinding.type != null) { |
| 1319 | IVariableBinding variableBinding = (IVariableBinding) this.bindingTables.compilerBindingsToASTBindings.get(exactBinding); |
| 1320 | if (variableBinding != null) { |
| 1321 | return variableBinding; |
| 1322 | } |
| 1323 | variableBinding = new VariableBinding(this, exactBinding); |
| 1324 | this.bindingTables.compilerBindingsToASTBindings.put(exactBinding, variableBinding); |
| 1325 | return variableBinding; |
| 1326 | } |
| 1327 | } |
| 1328 | } |
| 1329 | break; |
| 1330 | } |
| 1331 | } |
| 1332 | } |
| 1333 | } |
| 1334 | } else { |
| 1335 | /* This is the case for a name which is part of a qualified name that |
| 1336 | * cannot be resolved. See PR 13063. |
| 1337 | */ |
| 1338 | if (qualifiedNameReference.otherBindings == null || (index - indexOfFirstFieldBinding - 1) < 0) { |
| 1339 | return null; |
| 1340 | } else { |
| 1341 | return this.getVariableBinding(qualifiedNameReference.otherBindings[index - indexOfFirstFieldBinding - 1]); |
| 1342 | } |
| 1343 | } |
| 1344 | } else if (node instanceof JavadocModuleReference) { |
| 1345 | JavadocModuleReference modRef = (JavadocModuleReference) node; |
| 1346 | if (modRef.typeReference == null) { |
| 1347 | ModuleReference moduleReference = modRef.moduleReference; |
| 1348 | IModuleBinding moduleBinding = getModuleBinding(moduleReference.binding); |
| 1349 | if (moduleBinding != null) { |
| 1350 | return moduleBinding; |
| 1351 | } |
| 1352 | } else { |
| 1353 | if (name instanceof ModuleQualifiedName) { |
| 1354 | return resolveName(((ModuleQualifiedName)name).getName()); |
| 1355 | } |
| 1356 | } |
| 1357 | } else if (node instanceof QualifiedTypeReference) { |
| 1358 | QualifiedTypeReference qualifiedTypeReference = (QualifiedTypeReference) node; |
| 1359 | if (qualifiedTypeReference.resolvedType == null) { |
| 1360 | return null; |
| 1361 | } |
| 1362 | if (index == qualifiedTypeReference.tokens.length) { |
| 1363 | if (!qualifiedTypeReference.resolvedType.isValidBinding() && qualifiedTypeReference instanceof JavadocQualifiedTypeReference) { |
| 1364 | JavadocQualifiedTypeReference typeRef = (JavadocQualifiedTypeReference) node; |
| 1365 | if (typeRef.packageBinding != null) { |
| 1366 | return getPackageBinding(typeRef.packageBinding); |
| 1367 | } |
| 1368 | } |
| 1369 | return this.getTypeBinding(qualifiedTypeReference.resolvedType.leafComponentType()); |
| 1370 | } else { |
| 1371 | if (index >= 0) { |
| 1372 | BlockScope internalScope = (BlockScope) this.astNodesToBlockScope.get(name); |
| 1373 | Binding binding = null; |
| 1374 | try { |
| 1375 | if (internalScope == null) { |
| 1376 | if (this.scope == null) return null; |
| 1377 | binding = this.scope.getTypeOrPackage(CharOperation.subarray(qualifiedTypeReference.tokens, 0, index)); |
| 1378 | } else { |
| 1379 | binding = internalScope.getTypeOrPackage(CharOperation.subarray(qualifiedTypeReference.tokens, 0, index)); |
| 1380 | } |
| 1381 | } catch (AbortCompilation e) { |
| 1382 | // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=53357 |
| 1383 | } |
| 1384 | if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.PackageBinding) { |
| 1385 | return getPackageBinding((org.eclipse.jdt.internal.compiler.lookup.PackageBinding)binding); |
| 1386 | } else if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.TypeBinding) { |
| 1387 | // it is a type |
| 1388 | return this.getTypeBinding((org.eclipse.jdt.internal.compiler.lookup.TypeBinding)binding); |
| 1389 | } else { |
| 1390 | return null; |
| 1391 | } |
| 1392 | } |
| 1393 | } |
| 1394 | } else if (node instanceof ImportReference) { |
| 1395 | ImportReference importReference = (ImportReference) node; |
| 1396 | int importReferenceLength = importReference.tokens.length; |
| 1397 | boolean inModule = (importReference.bits & org.eclipse.jdt.internal.compiler.ast.ASTNode.inModule) != 0; |
| 1398 | if (index >= 0) { |
| 1399 | Binding binding = null; |
| 1400 | if (this.scope == null) return null; |
| 1401 | if (importReferenceLength == index && !inModule) { |
| 1402 | try { |
| 1403 | binding = this.scope.getImport(CharOperation.subarray(importReference.tokens, 0, index), (importReference.bits & org.eclipse.jdt.internal.compiler.ast.ASTNode.OnDemand) != 0, importReference.isStatic()); |
| 1404 | } catch (AbortCompilation e) { |
| 1405 | // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=53357 |
| 1406 | } |
| 1407 | } else { |
| 1408 | try { |
| 1409 | binding = this.scope.getImport(inModule ? importReference.tokens : CharOperation.subarray(importReference.tokens, 0, index), true, importReference.isStatic()); |
| 1410 | } catch (AbortCompilation e) { |
| 1411 | // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=53357 |
| 1412 | } |
| 1413 | } |
| 1414 | if (binding != null) { |
| 1415 | if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.PackageBinding) { |
| 1416 | return getPackageBinding((org.eclipse.jdt.internal.compiler.lookup.PackageBinding)binding); |
| 1417 | } else if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.TypeBinding) { |
| 1418 | // it is a type |
| 1419 | return this.getTypeBinding((org.eclipse.jdt.internal.compiler.lookup.TypeBinding)binding); |
| 1420 | } else if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.FieldBinding) { |
| 1421 | // it is a type |
| 1422 | return this.getVariableBinding((org.eclipse.jdt.internal.compiler.lookup.FieldBinding)binding); |
| 1423 | } else if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.MethodBinding) { |
| 1424 | // it is a type |
| 1425 | return getMethodBinding((org.eclipse.jdt.internal.compiler.lookup.MethodBinding)binding); |
| 1426 | } else if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.RecordComponentBinding) { |
| 1427 | // it is a type |
| 1428 | return this.getVariableBinding((org.eclipse.jdt.internal.compiler.lookup.RecordComponentBinding)binding); |
| 1429 | } else { |
| 1430 | return null; |
| 1431 | } |
| 1432 | } |
| 1433 | } |
| 1434 | } else if (node instanceof CompilationUnitDeclaration) { |
| 1435 | CompilationUnitDeclaration compilationUnitDeclaration = (CompilationUnitDeclaration) node; |
| 1436 | org.eclipse.jdt.internal.compiler.ast.TypeDeclaration[] types = compilationUnitDeclaration.types; |
| 1437 | if (types == null || types.length == 0) { |
| 1438 | return null; |
| 1439 | } |
| 1440 | org.eclipse.jdt.internal.compiler.ast.TypeDeclaration type = types[0]; |
| 1441 | if (type != null) { |
| 1442 | ITypeBinding typeBinding = this.getTypeBinding(type.binding); |
| 1443 | if (typeBinding != null) { |
| 1444 | return typeBinding.getPackage(); |
| 1445 | } |
| 1446 | } |
| 1447 | } else if (node instanceof AbstractMethodDeclaration) { |
| 1448 | AbstractMethodDeclaration methodDeclaration = (AbstractMethodDeclaration) node; |
| 1449 | IMethodBinding methodBinding = getMethodBinding(methodDeclaration.binding); |
| 1450 | if (methodBinding != null) { |
| 1451 | return methodBinding; |
| 1452 | } |
| 1453 | } else if (node instanceof ModuleReference) { |
| 1454 | ModuleReference moduleReference = (ModuleReference) node; |
| 1455 | IModuleBinding moduleBinding = getModuleBinding(moduleReference.binding); |
| 1456 | if (moduleBinding != null) { |
| 1457 | return moduleBinding; |
| 1458 | } |
| 1459 | } else if (node instanceof org.eclipse.jdt.internal.compiler.ast.ModuleDeclaration) { |
| 1460 | org.eclipse.jdt.internal.compiler.ast.ModuleDeclaration moduleDeclaration = (org.eclipse.jdt.internal.compiler.ast.ModuleDeclaration) node; |
| 1461 | IModuleBinding moduleBinding = getModuleBinding(moduleDeclaration.binding); |
| 1462 | if (moduleBinding != null) { |
| 1463 | return moduleBinding; |
| 1464 | } |
| 1465 | } else if (node instanceof org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) { |
| 1466 | org.eclipse.jdt.internal.compiler.ast.TypeDeclaration typeDeclaration = (org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) node; |
| 1467 | ITypeBinding typeBinding = this.getTypeBinding(typeDeclaration.binding); |
| 1468 | if (typeBinding != null) { |
| 1469 | return typeBinding; |
| 1470 | } |
| 1471 | } if (node instanceof SingleNameReference) { |
| 1472 | SingleNameReference singleNameReference = (SingleNameReference) node; |
| 1473 | if (singleNameReference.isTypeReference()) { |
| 1474 | return this.getTypeBinding(singleNameReference.resolvedType); |
| 1475 | } else { |
| 1476 | // this is a variable or a field |
| 1477 | Binding binding = singleNameReference.binding; |
| 1478 | if (binding != null) { |
| 1479 | if (binding.isValidBinding()) { |
| 1480 | return this.getVariableBinding((org.eclipse.jdt.internal.compiler.lookup.VariableBinding) binding); |
| 1481 | } else { |
| 1482 | /* |
| 1483 | * http://dev.eclipse.org/bugs/show_bug.cgi?id=24449 |
| 1484 | */ |
| 1485 | if (binding instanceof ProblemFieldBinding) { |
| 1486 | ProblemFieldBinding problemFieldBinding = (ProblemFieldBinding) binding; |
| 1487 | switch(problemFieldBinding.problemId()) { |
| 1488 | case ProblemReasons.NotVisible : |
| 1489 | case ProblemReasons.NonStaticReferenceInStaticContext : |
| 1490 | case ProblemReasons.NonStaticReferenceInConstructorInvocation : |
| 1491 | ReferenceBinding declaringClass = problemFieldBinding.declaringClass; |
| 1492 | FieldBinding exactBinding = declaringClass.getField(problemFieldBinding.name, true /*resolve*/); |
| 1493 | if (exactBinding != null) { |
| 1494 | if (exactBinding.type != null) { |
| 1495 | IVariableBinding variableBinding2 = (IVariableBinding) this.bindingTables.compilerBindingsToASTBindings.get(exactBinding); |
| 1496 | if (variableBinding2 != null) { |
| 1497 | return variableBinding2; |
| 1498 | } |
| 1499 | variableBinding2 = new VariableBinding(this, exactBinding); |
| 1500 | this.bindingTables.compilerBindingsToASTBindings.put(exactBinding, variableBinding2); |
| 1501 | return variableBinding2; |
| 1502 | } |
| 1503 | } |
| 1504 | break; |
| 1505 | } |
| 1506 | } |
| 1507 | } |
| 1508 | } |
| 1509 | } |
| 1510 | } else if (node instanceof QualifiedSuperReference) { |
| 1511 | QualifiedSuperReference qualifiedSuperReference = (QualifiedSuperReference) node; |
| 1512 | return this.getTypeBinding(qualifiedSuperReference.qualification.resolvedType); |
| 1513 | } else if (node instanceof LocalDeclaration) { |
| 1514 | return name.getAST().apiLevel() >= AST.JLS10_INTERNAL && name instanceof SimpleName && ((SimpleName) name).isVar() ? |
| 1515 | resolveTypeBindingForName(name) : |
| 1516 | this.getVariableBinding(((LocalDeclaration)node).binding); |
| 1517 | } else if (node instanceof JavadocFieldReference) { |
| 1518 | JavadocFieldReference fieldRef = (JavadocFieldReference) node; |
| 1519 | if (fieldRef.methodBinding != null) { |
| 1520 | return getMethodBinding(fieldRef.methodBinding); |
| 1521 | } |
| 1522 | return getVariableBinding(fieldRef.binding); |
| 1523 | } else if (node instanceof FieldReference) { |
| 1524 | return getVariableBinding(((FieldReference) node).binding); |
| 1525 | } else if (node instanceof SingleTypeReference) { |
| 1526 | if (node instanceof JavadocSingleTypeReference) { |
| 1527 | JavadocSingleTypeReference typeRef = (JavadocSingleTypeReference) node; |
| 1528 | if (typeRef.packageBinding != null) { |
| 1529 | return getPackageBinding(typeRef.packageBinding); |
| 1530 | } |
| 1531 | } |
| 1532 | SingleTypeReference singleTypeReference = (SingleTypeReference) node; |
| 1533 | org.eclipse.jdt.internal.compiler.lookup.TypeBinding binding = singleTypeReference.resolvedType; |
| 1534 | if (binding == null) { |
| 1535 | return null; |
| 1536 | } |
| 1537 | return this.getTypeBinding(binding.leafComponentType()); |
| 1538 | } else if (node instanceof org.eclipse.jdt.internal.compiler.ast.FieldDeclaration) { |
| 1539 | org.eclipse.jdt.internal.compiler.ast.FieldDeclaration fieldDeclaration = (org.eclipse.jdt.internal.compiler.ast.FieldDeclaration) node; |
| 1540 | return this.getVariableBinding(fieldDeclaration.binding); |
| 1541 | } else if (node instanceof MessageSend) { |
| 1542 | MessageSend messageSend = (MessageSend) node; |
| 1543 | return getMethodBinding(messageSend.binding); |
| 1544 | } else if (node instanceof AllocationExpression) { |
| 1545 | AllocationExpression allocation = (AllocationExpression) node; |
| 1546 | return getMethodBinding(allocation.binding); |
| 1547 | } else if (node instanceof JavadocImplicitTypeReference) { |
| 1548 | JavadocImplicitTypeReference implicitRef = (JavadocImplicitTypeReference) node; |
| 1549 | return getTypeBinding(implicitRef.resolvedType); |
| 1550 | } else if (node instanceof org.eclipse.jdt.internal.compiler.ast.TypeParameter) { |
| 1551 | org.eclipse.jdt.internal.compiler.ast.TypeParameter typeParameter = (org.eclipse.jdt.internal.compiler.ast.TypeParameter) node; |
| 1552 | return this.getTypeBinding(typeParameter.binding); |
| 1553 | } else if (node instanceof org.eclipse.jdt.internal.compiler.ast.MemberValuePair) { |
| 1554 | org.eclipse.jdt.internal.compiler.ast.MemberValuePair memberValuePair = (org.eclipse.jdt.internal.compiler.ast.MemberValuePair) node; |
| 1555 | return getMethodBinding(memberValuePair.binding); |
| 1556 | } else if (node instanceof org.eclipse.jdt.internal.compiler.ast.ReferenceExpression) { |
| 1557 | org.eclipse.jdt.internal.compiler.ast.ReferenceExpression referenceExpression = (org.eclipse.jdt.internal.compiler.ast.ReferenceExpression) node; |
| 1558 | return getMethodBinding(referenceExpression.getMethodBinding()); |
| 1559 | } else if (node instanceof org.eclipse.jdt.internal.compiler.ast.RecordComponent) { |
| 1560 | org.eclipse.jdt.internal.compiler.ast.RecordComponent recordComponent = (org.eclipse.jdt.internal.compiler.ast.RecordComponent) node; |
| 1561 | return this.getVariableBinding(recordComponent.binding); |
| 1562 | } |
| 1563 | return null; |
| 1564 | } |
| 1565 | |
| 1566 | @Override |
| 1567 | synchronized IPackageBinding resolvePackage(PackageDeclaration pkg) { |
| 1568 | if (this.scope == null) return null; |
| 1569 | try { |
| 1570 | org.eclipse.jdt.internal.compiler.ast.ASTNode node = (org.eclipse.jdt.internal.compiler.ast.ASTNode) this.newAstToOldAst.get(pkg); |
| 1571 | if (node instanceof ImportReference) { |
| 1572 | ImportReference importReference = (ImportReference) node; |
| 1573 | Binding binding = this.scope.getOnlyPackage(CharOperation.subarray(importReference.tokens, 0, importReference.tokens.length)); |
| 1574 | if ((binding != null) && (binding.isValidBinding())) { |
| 1575 | if (binding instanceof ReferenceBinding) { |
| 1576 | // this only happens if a type name has the same name as its package |
| 1577 | ReferenceBinding referenceBinding = (ReferenceBinding) binding; |
| 1578 | binding = referenceBinding.fPackage; |
| 1579 | } |
| 1580 | if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.PackageBinding) { |
| 1581 | IPackageBinding packageBinding = getPackageBinding((org.eclipse.jdt.internal.compiler.lookup.PackageBinding) binding); |
| 1582 | if (packageBinding == null) { |
| 1583 | return null; |
| 1584 | } |
| 1585 | this.bindingsToAstNodes.put(packageBinding, pkg); |
| 1586 | String key = packageBinding.getKey(); |
| 1587 | if (key != null) { |
| 1588 | this.bindingTables.bindingKeysToBindings.put(key, packageBinding); |
| 1589 | } |
| 1590 | return packageBinding; |
| 1591 | } |
| 1592 | } |
| 1593 | } |
| 1594 | } catch (AbortCompilation e) { |
| 1595 | // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=53357 |
| 1596 | // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=63550 |
| 1597 | // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=64299 |
| 1598 | } |
| 1599 | return null; |
| 1600 | } |
| 1601 | |
| 1602 | @Override |
| 1603 | synchronized IBinding resolveReference(MemberRef ref) { |
| 1604 | org.eclipse.jdt.internal.compiler.ast.Expression expression = (org.eclipse.jdt.internal.compiler.ast.Expression) this.newAstToOldAst.get(ref); |
| 1605 | if (expression instanceof TypeReference) { |
| 1606 | return getTypeBinding(expression.resolvedType); |
| 1607 | } else if (expression instanceof JavadocFieldReference) { |
| 1608 | JavadocFieldReference fieldRef = (JavadocFieldReference) expression; |
| 1609 | if (fieldRef.methodBinding != null) { |
| 1610 | return getMethodBinding(fieldRef.methodBinding); |
| 1611 | } |
| 1612 | return getVariableBinding(fieldRef.binding); |
| 1613 | } |
| 1614 | return null; |
| 1615 | } |
| 1616 | |
| 1617 | @Override |
| 1618 | synchronized IMemberValuePairBinding resolveMemberValuePair(org.eclipse.jdt.core.dom.MemberValuePair memberValuePair) { |
| 1619 | MemberValuePair valuePair = (MemberValuePair) this.newAstToOldAst.get(memberValuePair); |
| 1620 | if (valuePair != null) { |
| 1621 | return getMemberValuePairBinding(valuePair.compilerElementPair); |
| 1622 | } |
| 1623 | return null; |
| 1624 | } |
| 1625 | |
| 1626 | /** |
| 1627 | * @see BindingResolver#resolveModule(ModuleDeclaration) |
| 1628 | * @since 3.14 |
| 1629 | */ |
| 1630 | @Override |
| 1631 | IModuleBinding resolveModule(ModuleDeclaration module) { |
| 1632 | Object oldNode = this.newAstToOldAst.get(module); |
| 1633 | if (oldNode instanceof org.eclipse.jdt.internal.compiler.ast.ModuleDeclaration) { |
| 1634 | org.eclipse.jdt.internal.compiler.ast.ModuleDeclaration moduleDeclaration = (org.eclipse.jdt.internal.compiler.ast.ModuleDeclaration) oldNode; |
| 1635 | IModuleBinding moduleBinding = getModuleBinding(moduleDeclaration.binding); |
| 1636 | if (moduleBinding == null) { |
| 1637 | return null; |
| 1638 | } |
| 1639 | this.bindingsToAstNodes.put(moduleBinding, module); |
| 1640 | String key = moduleBinding.getKey(); |
| 1641 | if (key != null) { |
| 1642 | this.bindingTables.bindingKeysToBindings.put(key, moduleBinding); |
| 1643 | } |
| 1644 | return moduleBinding; |
| 1645 | } |
| 1646 | |
| 1647 | return null; |
| 1648 | } |
| 1649 | |
| 1650 | @Override |
| 1651 | synchronized IBinding resolveReference(MethodRef ref) { |
| 1652 | org.eclipse.jdt.internal.compiler.ast.Expression expression = (org.eclipse.jdt.internal.compiler.ast.Expression) this.newAstToOldAst.get(ref); |
| 1653 | if (expression instanceof JavadocMessageSend) { |
| 1654 | return getMethodBinding(((JavadocMessageSend)expression).binding); |
| 1655 | } |
| 1656 | else if (expression instanceof JavadocAllocationExpression) { |
| 1657 | return getMethodBinding(((JavadocAllocationExpression)expression).binding); |
| 1658 | } |
| 1659 | return null; |
| 1660 | } |
| 1661 | |
| 1662 | @Override |
| 1663 | ITypeBinding resolveType(AnnotationTypeDeclaration type) { |
| 1664 | final Object node = this.newAstToOldAst.get(type); |
| 1665 | if (node instanceof org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) { |
| 1666 | org.eclipse.jdt.internal.compiler.ast.TypeDeclaration typeDeclaration = (org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) node; |
| 1667 | ITypeBinding typeBinding = this.getTypeBinding(typeDeclaration.binding); |
| 1668 | if (typeBinding == null) { |
| 1669 | return null; |
| 1670 | } |
| 1671 | this.bindingsToAstNodes.put(typeBinding, type); |
| 1672 | String key = typeBinding.getKey(); |
| 1673 | if (key != null) { |
| 1674 | this.bindingTables.bindingKeysToBindings.put(key, typeBinding); |
| 1675 | } |
| 1676 | return typeBinding; |
| 1677 | } |
| 1678 | return null; |
| 1679 | } |
| 1680 | |
| 1681 | @Override |
| 1682 | synchronized ITypeBinding resolveType(AnonymousClassDeclaration type) { |
| 1683 | org.eclipse.jdt.internal.compiler.ast.ASTNode node = (org.eclipse.jdt.internal.compiler.ast.ASTNode) this.newAstToOldAst.get(type); |
| 1684 | if (node != null && (node.bits & org.eclipse.jdt.internal.compiler.ast.ASTNode.IsAnonymousType) != 0) { |
| 1685 | org.eclipse.jdt.internal.compiler.ast.TypeDeclaration anonymousLocalTypeDeclaration = (org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) node; |
| 1686 | IBinding declaringMember = getDeclaringMember(anonymousLocalTypeDeclaration, anonymousLocalTypeDeclaration.scope); |
| 1687 | ITypeBinding typeBinding = internalGetTypeBinding(anonymousLocalTypeDeclaration.binding, declaringMember); |
| 1688 | if (typeBinding == null) { |
| 1689 | return null; |
| 1690 | } |
| 1691 | this.bindingsToAstNodes.put(typeBinding, type); |
| 1692 | String key = typeBinding.getKey(); |
| 1693 | if (key != null) { |
| 1694 | this.bindingTables.bindingKeysToBindings.put(key, typeBinding); |
| 1695 | } |
| 1696 | return typeBinding; |
| 1697 | } |
| 1698 | return null; |
| 1699 | } |
| 1700 | |
| 1701 | @Override |
| 1702 | ITypeBinding resolveType(EnumDeclaration type) { |
| 1703 | final Object node = this.newAstToOldAst.get(type); |
| 1704 | if (node instanceof org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) { |
| 1705 | org.eclipse.jdt.internal.compiler.ast.TypeDeclaration typeDeclaration = (org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) node; |
| 1706 | ITypeBinding typeBinding = this.getTypeBinding(typeDeclaration.binding); |
| 1707 | if (typeBinding == null) { |
| 1708 | return null; |
| 1709 | } |
| 1710 | this.bindingsToAstNodes.put(typeBinding, type); |
| 1711 | String key = typeBinding.getKey(); |
| 1712 | if (key != null) { |
| 1713 | this.bindingTables.bindingKeysToBindings.put(key, typeBinding); |
| 1714 | } |
| 1715 | return typeBinding; |
| 1716 | } |
| 1717 | return null; |
| 1718 | } |
| 1719 | |
| 1720 | @Override |
| 1721 | ITypeBinding resolveType(RecordDeclaration type) { |
| 1722 | final Object node = this.newAstToOldAst.get(type); |
| 1723 | if (node instanceof org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) { |
| 1724 | org.eclipse.jdt.internal.compiler.ast.TypeDeclaration typeDeclaration = (org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) node; |
| 1725 | ITypeBinding typeBinding = this.getTypeBinding(typeDeclaration.binding); |
| 1726 | if (typeBinding == null) { |
| 1727 | return null; |
| 1728 | } |
| 1729 | this.bindingsToAstNodes.put(typeBinding, type); |
| 1730 | String key = typeBinding.getKey(); |
| 1731 | if (key != null) { |
| 1732 | this.bindingTables.bindingKeysToBindings.put(key, typeBinding); |
| 1733 | } |
| 1734 | return typeBinding; |
| 1735 | } |
| 1736 | return null; |
| 1737 | } |
| 1738 | |
| 1739 | |
| 1740 | |
| 1741 | @Override |
| 1742 | synchronized ITypeBinding resolveType(Type type) { |
| 1743 | // retrieve the old ast node |
| 1744 | org.eclipse.jdt.internal.compiler.ast.ASTNode node = (org.eclipse.jdt.internal.compiler.ast.ASTNode) this.newAstToOldAst.get(type); |
| 1745 | org.eclipse.jdt.internal.compiler.lookup.TypeBinding binding = null; |
| 1746 | if (type.getAST().apiLevel() >= AST.JLS10_INTERNAL && type.isVar()) { |
| 1747 | return resolveTypeBindingForName(((SimpleType) type).getName()); |
| 1748 | } |
| 1749 | if (node != null) { |
| 1750 | if (node instanceof Receiver) { |
| 1751 | node = ((Receiver) node).type; |
| 1752 | } |
| 1753 | if (node instanceof ParameterizedQualifiedTypeReference) { |
| 1754 | ParameterizedQualifiedTypeReference typeReference = (ParameterizedQualifiedTypeReference) node; |
| 1755 | org.eclipse.jdt.internal.compiler.lookup.TypeBinding typeBinding = typeReference.resolvedType; |
| 1756 | // This unlikely case is possible when for some reason binding resolution has been stopped, like duplicate type declaration (bug 376440) |
| 1757 | if (typeBinding == null) return null; |
| 1758 | if (type.isArrayType()) { |
| 1759 | if (this.scope == null) { |
| 1760 | return null; |
| 1761 | } |
| 1762 | ArrayType arrayType = (ArrayType) type; |
| 1763 | ArrayBinding arrayBinding = (ArrayBinding) typeBinding; |
| 1764 | int dimensions = arrayType.getDimensions(); |
| 1765 | boolean isVarargs = typeReference.isVarargs(); |
| 1766 | if (dimensions == arrayBinding.dimensions) |
| 1767 | return getTypeBinding(arrayBinding); // reuse. |
| 1768 | return getTypeBinding(this.scope.createArrayType(arrayBinding.leafComponentType, dimensions, getTypeAnnotations(dimensions, arrayBinding, isVarargs))); |
| 1769 | } |
| 1770 | if (typeBinding.isArrayType()) { |
| 1771 | // 'typeBinding' can still be an array type because 'node' may be "larger" than 'type' (see comment of newAstToOldAst). |
| 1772 | typeBinding = ((ArrayBinding) typeBinding).leafComponentType; |
| 1773 | } |
| 1774 | int index; |
| 1775 | if (type.isQualifiedType()) { |
| 1776 | index = ((QualifiedType) type).index; |
| 1777 | } else if (type.isParameterizedType()) { |
| 1778 | index = ((ParameterizedType) type).index; |
| 1779 | } else { |
| 1780 | index = 1; |
| 1781 | } |
| 1782 | final int numberOfTypeArgumentsNotNull = getTypeCount(typeReference); |
| 1783 | if (index != numberOfTypeArgumentsNotNull) { |
| 1784 | int i = numberOfTypeArgumentsNotNull; |
| 1785 | while (i != index) { |
| 1786 | typeBinding = typeBinding.enclosingType(); |
| 1787 | i --; |
| 1788 | } |
| 1789 | binding = typeBinding; |
| 1790 | } else { |
| 1791 | binding = typeBinding; |
| 1792 | } |
| 1793 | } else if (node instanceof TypeReference) { |
| 1794 | if (type instanceof SimpleType && node instanceof QualifiedTypeReference) { |
| 1795 | return resolveTypeBindingForName(((SimpleType)type).getName()); |
| 1796 | } else if (type instanceof QualifiedType) { |
| 1797 | return resolveTypeBindingForName(((QualifiedType)type).getName()); |
| 1798 | } else if (type instanceof NameQualifiedType){ |
| 1799 | return resolveTypeBindingForName(((NameQualifiedType)type).getName()); |
| 1800 | } |
| 1801 | TypeReference typeReference = (TypeReference) node; |
| 1802 | binding = typeReference.resolvedType; |
| 1803 | } else if (node instanceof SingleNameReference && ((SingleNameReference)node).isTypeReference()) { |
| 1804 | binding = (((SingleNameReference)node).resolvedType); |
| 1805 | } else if (node instanceof QualifiedNameReference && ((QualifiedNameReference)node).isTypeReference()) { |
| 1806 | binding = (((QualifiedNameReference)node).resolvedType); |
| 1807 | } else if (node instanceof ArrayAllocationExpression) { |
| 1808 | binding = ((ArrayAllocationExpression) node).resolvedType; |
| 1809 | } |
| 1810 | if (binding != null) { |
| 1811 | if (type.isArrayType()) { |
| 1812 | ArrayType arrayType = (ArrayType) type; |
| 1813 | if (this.scope == null) { |
| 1814 | return null; |
| 1815 | } |
| 1816 | ArrayBinding arrayBinding = (ArrayBinding) binding; |
| 1817 | int dimensions = arrayType.getDimensions(); |
| 1818 | boolean isVarargs = node instanceof TypeReference && ((TypeReference) node).isVarargs(); |
| 1819 | if (dimensions == arrayBinding.dimensions) |
| 1820 | return getTypeBinding(arrayBinding); // reuse |
| 1821 | return getTypeBinding(this.scope.createArrayType(arrayBinding.leafComponentType, dimensions, getTypeAnnotations(dimensions, arrayBinding, isVarargs))); |
| 1822 | } else if (binding.isArrayType()) { |
| 1823 | // 'binding' can still be an array type because 'node' may be "larger" than 'type' (see comment of newAstToOldAst). |
| 1824 | ArrayBinding arrayBinding = (ArrayBinding) binding; |
| 1825 | return getTypeBinding(arrayBinding.leafComponentType); |
| 1826 | } |
| 1827 | return getTypeBinding(binding); |
| 1828 | } |
| 1829 | } else if (type.isPrimitiveType()) { |
| 1830 | /* Handle the void primitive type returned by getReturnType for a method declaration |
| 1831 | * that is a constructor declaration. It prevents null from being returned |
| 1832 | */ |
| 1833 | if (((PrimitiveType) type).getPrimitiveTypeCode() == PrimitiveType.VOID) { |
| 1834 | return this.getTypeBinding(org.eclipse.jdt.internal.compiler.lookup.TypeBinding.VOID); |
| 1835 | } |
| 1836 | } |
| 1837 | return null; |
| 1838 | } |
| 1839 | |
| 1840 | private org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding[] getTypeAnnotations(int dimensions, ArrayBinding arrayBinding, boolean isVarargs) { |
| 1841 | org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding [] oldies = arrayBinding.getTypeAnnotations(); |
| 1842 | org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding[] newbies = Binding.NO_ANNOTATIONS; |
| 1843 | // Skip past extended dimensions encoded ahead of base dimensions. Dimension for variable argument array comes after the base dimensions. |
| 1844 | int extendedDimensions = arrayBinding.dimensions - dimensions - (isVarargs ? 1 : 0); |
| 1845 | int i, length; |
| 1846 | for (i = 0, length = oldies == null ? 0 : oldies.length; i < length && extendedDimensions > 0 ; i++) { |
| 1847 | if (oldies[i] == null) |
| 1848 | extendedDimensions--; |
| 1849 | } |
| 1850 | int cells = 0; |
| 1851 | for (int j = i; j < length && dimensions > 0 ; j++) { |
| 1852 | if (oldies[j] == null) |
| 1853 | dimensions--; |
| 1854 | cells ++; |
| 1855 | } |
| 1856 | if (cells > 0) |
| 1857 | System.arraycopy(oldies, i, newbies = new org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding[cells], 0, cells); |
| 1858 | return newbies; |
| 1859 | } |
| 1860 | |
| 1861 | @Override |
| 1862 | synchronized ITypeBinding resolveType(TypeDeclaration type) { |
| 1863 | final Object node = this.newAstToOldAst.get(type); |
| 1864 | if (node instanceof org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) { |
| 1865 | org.eclipse.jdt.internal.compiler.ast.TypeDeclaration typeDeclaration = (org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) node; |
| 1866 | IBinding declaringMember = getDeclaringMember(typeDeclaration, typeDeclaration.scope); |
| 1867 | ITypeBinding typeBinding = internalGetTypeBinding(typeDeclaration.binding, declaringMember); |
| 1868 | if (typeBinding == null) { |
| 1869 | return null; |
| 1870 | } |
| 1871 | this.bindingsToAstNodes.put(typeBinding, type); |
| 1872 | String key = typeBinding.getKey(); |
| 1873 | if (key != null) { |
| 1874 | this.bindingTables.bindingKeysToBindings.put(key, typeBinding); |
| 1875 | } |
| 1876 | return typeBinding; |
| 1877 | } |
| 1878 | return null; |
| 1879 | } |
| 1880 | |
| 1881 | @Override |
| 1882 | synchronized ITypeBinding resolveTypeParameter(TypeParameter typeParameter) { |
| 1883 | final Object node = this.newAstToOldAst.get(typeParameter); |
| 1884 | if (node instanceof org.eclipse.jdt.internal.compiler.ast.TypeParameter) { |
| 1885 | org.eclipse.jdt.internal.compiler.ast.TypeParameter typeParameter2 = (org.eclipse.jdt.internal.compiler.ast.TypeParameter) node; |
| 1886 | ITypeBinding typeBinding = this.getTypeBinding(typeParameter2.binding); |
| 1887 | if (typeBinding == null) { |
| 1888 | return null; |
| 1889 | } |
| 1890 | this.bindingsToAstNodes.put(typeBinding, typeParameter); |
| 1891 | String key = typeBinding.getKey(); |
| 1892 | if (key != null) { |
| 1893 | this.bindingTables.bindingKeysToBindings.put(key, typeBinding); |
| 1894 | } |
| 1895 | return typeBinding; |
| 1896 | } |
| 1897 | return null; |
| 1898 | } |
| 1899 | |
| 1900 | @Override |
| 1901 | synchronized IVariableBinding resolveVariable(EnumConstantDeclaration enumConstant) { |
| 1902 | final Object node = this.newAstToOldAst.get(enumConstant); |
| 1903 | if (node instanceof org.eclipse.jdt.internal.compiler.ast.FieldDeclaration) { |
| 1904 | org.eclipse.jdt.internal.compiler.ast.FieldDeclaration fieldDeclaration = (org.eclipse.jdt.internal.compiler.ast.FieldDeclaration) node; |
| 1905 | IVariableBinding variableBinding = this.getVariableBinding(fieldDeclaration.binding); |
| 1906 | if (variableBinding == null) { |
| 1907 | return null; |
| 1908 | } |
| 1909 | this.bindingsToAstNodes.put(variableBinding, enumConstant); |
| 1910 | String key = variableBinding.getKey(); |
| 1911 | if (key != null) { |
| 1912 | this.bindingTables.bindingKeysToBindings.put(key, variableBinding); |
| 1913 | } |
| 1914 | return variableBinding; |
| 1915 | } |
| 1916 | return null; |
| 1917 | } |
| 1918 | |
| 1919 | @Override |
| 1920 | synchronized IVariableBinding resolveVariable(VariableDeclaration variable) { |
| 1921 | final Object node = this.newAstToOldAst.get(variable); |
| 1922 | if (node instanceof AbstractVariableDeclaration) { |
| 1923 | AbstractVariableDeclaration abstractVariableDeclaration = (AbstractVariableDeclaration) node; |
| 1924 | IVariableBinding variableBinding = null; |
| 1925 | if (abstractVariableDeclaration instanceof org.eclipse.jdt.internal.compiler.ast.FieldDeclaration) { |
| 1926 | org.eclipse.jdt.internal.compiler.ast.FieldDeclaration fieldDeclaration = (org.eclipse.jdt.internal.compiler.ast.FieldDeclaration) abstractVariableDeclaration; |
| 1927 | variableBinding = this.getVariableBinding(fieldDeclaration.binding, variable); |
| 1928 | } else if (abstractVariableDeclaration instanceof org.eclipse.jdt.internal.compiler.ast.RecordComponent) { |
| 1929 | org.eclipse.jdt.internal.compiler.ast.RecordComponent recordComponent = (org.eclipse.jdt.internal.compiler.ast.RecordComponent) abstractVariableDeclaration; |
| 1930 | variableBinding = this.getVariableBinding(recordComponent.binding, variable); |
| 1931 | } else { |
| 1932 | variableBinding = this.getVariableBinding(((LocalDeclaration) abstractVariableDeclaration).binding, variable); |
| 1933 | } |
| 1934 | if (variableBinding == null) { |
| 1935 | return null; |
| 1936 | } |
| 1937 | this.bindingsToAstNodes.put(variableBinding, variable); |
| 1938 | String key = variableBinding.getKey(); |
| 1939 | if (key != null) { |
| 1940 | this.bindingTables.bindingKeysToBindings.put(key, variableBinding); |
| 1941 | } |
| 1942 | return variableBinding; |
| 1943 | } |
| 1944 | return null; |
| 1945 | } |
| 1946 | |
| 1947 | @Override |
| 1948 | synchronized ITypeBinding resolveWellKnownType(String name) { |
| 1949 | if (this.scope == null) return null; |
| 1950 | ITypeBinding typeBinding = null; |
| 1951 | try { |
| 1952 | if (("boolean".equals(name))//$NON-NLS-1$ |
| 1953 | || ("char".equals(name))//$NON-NLS-1$ |
| 1954 | || ("byte".equals(name))//$NON-NLS-1$ |
| 1955 | || ("short".equals(name))//$NON-NLS-1$ |
| 1956 | || ("int".equals(name))//$NON-NLS-1$ |
| 1957 | || ("long".equals(name))//$NON-NLS-1$ |
| 1958 | || ("float".equals(name))//$NON-NLS-1$ |
| 1959 | || ("double".equals(name))//$NON-NLS-1$ |
| 1960 | || ("void".equals(name))) {//$NON-NLS-1$ |
| 1961 | typeBinding = this.getTypeBinding(Scope.getBaseType(name.toCharArray())); |
| 1962 | } else if ("java.lang.Object".equals(name)) {//$NON-NLS-1$ |
| 1963 | typeBinding = this.getTypeBinding(this.scope.getJavaLangObject()); |
| 1964 | } else if ("java.lang.String".equals(name)) {//$NON-NLS-1$ |
| 1965 | typeBinding = this.getTypeBinding(this.scope.getJavaLangString()); |
| 1966 | } else if ("java.lang.StringBuffer".equals(name)) {//$NON-NLS-1$ |
| 1967 | typeBinding = this.getTypeBinding(this.scope.getType(TypeConstants.JAVA_LANG_STRINGBUFFER, 3)); |
| 1968 | } else if ("java.lang.Throwable".equals(name)) {//$NON-NLS-1$ |
| 1969 | typeBinding = this.getTypeBinding(this.scope.getJavaLangThrowable()); |
| 1970 | } else if ("java.lang.Exception".equals(name)) {//$NON-NLS-1$ |
| 1971 | typeBinding = this.getTypeBinding(this.scope.getType(TypeConstants.JAVA_LANG_EXCEPTION, 3)); |
| 1972 | } else if ("java.lang.RuntimeException".equals(name)) {//$NON-NLS-1$ |
| 1973 | typeBinding = this.getTypeBinding(this.scope.getType(TypeConstants.JAVA_LANG_RUNTIMEEXCEPTION, 3)); |
| 1974 | } else if ("java.lang.Error".equals(name)) {//$NON-NLS-1$ |
| 1975 | typeBinding = this.getTypeBinding(this.scope.getType(TypeConstants.JAVA_LANG_ERROR, 3)); |
| 1976 | } else if ("java.lang.Class".equals(name)) {//$NON-NLS-1$ |
| 1977 | typeBinding = this.getTypeBinding(this.scope.getJavaLangClass()); |
| 1978 | } else if ("java.lang.Cloneable".equals(name)) {//$NON-NLS-1$ |
| 1979 | typeBinding = this.getTypeBinding(this.scope.getJavaLangCloneable()); |
| 1980 | } else if ("java.io.Serializable".equals(name)) {//$NON-NLS-1$ |
| 1981 | typeBinding = this.getTypeBinding(this.scope.getJavaIoSerializable()); |
| 1982 | } else if ("java.lang.Boolean".equals(name)) {//$NON-NLS-1$ |
| 1983 | typeBinding = this.getTypeBinding(this.scope.getType(TypeConstants.JAVA_LANG_BOOLEAN, 3)); |
| 1984 | } else if ("java.lang.Byte".equals(name)) {//$NON-NLS-1$ |
| 1985 | typeBinding = this.getTypeBinding(this.scope.getType(TypeConstants.JAVA_LANG_BYTE, 3)); |
| 1986 | } else if ("java.lang.Character".equals(name)) {//$NON-NLS-1$ |
| 1987 | typeBinding = this.getTypeBinding(this.scope.getType(TypeConstants.JAVA_LANG_CHARACTER, 3)); |
| 1988 | } else if ("java.lang.Double".equals(name)) {//$NON-NLS-1$ |
| 1989 | typeBinding = this.getTypeBinding(this.scope.getType(TypeConstants.JAVA_LANG_DOUBLE, 3)); |
| 1990 | } else if ("java.lang.Float".equals(name)) {//$NON-NLS-1$ |
| 1991 | typeBinding = this.getTypeBinding(this.scope.getType(TypeConstants.JAVA_LANG_FLOAT, 3)); |
| 1992 | } else if ("java.lang.Integer".equals(name)) {//$NON-NLS-1$ |
| 1993 | typeBinding = this.getTypeBinding(this.scope.getType(TypeConstants.JAVA_LANG_INTEGER, 3)); |
| 1994 | } else if ("java.lang.Long".equals(name)) {//$NON-NLS-1$ |
| 1995 | typeBinding = this.getTypeBinding(this.scope.getType(TypeConstants.JAVA_LANG_LONG, 3)); |
| 1996 | } else if ("java.lang.Short".equals(name)) {//$NON-NLS-1$ |
| 1997 | typeBinding = this.getTypeBinding(this.scope.getType(TypeConstants.JAVA_LANG_SHORT, 3)); |
| 1998 | } else if ("java.lang.Void".equals(name)) {//$NON-NLS-1$ |
| 1999 | typeBinding = this.getTypeBinding(this.scope.getType(TypeConstants.JAVA_LANG_VOID, 3)); |
| 2000 | } else if ("java.lang.AssertionError".equals(name)) { //$NON-NLS-1$ |
| 2001 | typeBinding = this.getTypeBinding(this.scope.getType(TypeConstants.JAVA_LANG_ASSERTIONERROR, 3)); |
| 2002 | } |
| 2003 | } catch (AbortCompilation e) { |
| 2004 | // ignore missing types |
| 2005 | } |
| 2006 | if (typeBinding != null && !typeBinding.isRecovered()) { |
| 2007 | return typeBinding; |
| 2008 | } |
| 2009 | return null; |
| 2010 | } |
| 2011 | |
| 2012 | @Override |
| 2013 | synchronized IAnnotationBinding resolveAnnotation(final Annotation domASTNode) { |
| 2014 | Object oldNode = this.newAstToOldAst.get(domASTNode); |
| 2015 | if (oldNode instanceof org.eclipse.jdt.internal.compiler.ast.Annotation) { |
| 2016 | org.eclipse.jdt.internal.compiler.ast.Annotation internalAstNode = |
| 2017 | (org.eclipse.jdt.internal.compiler.ast.Annotation) oldNode; |
| 2018 | |
| 2019 | IAnnotationBinding domAnnotation = getAnnotationInstance(internalAstNode.getCompilerAnnotation()); |
| 2020 | if (domAnnotation == null) |
| 2021 | return null; |
| 2022 | this.bindingsToAstNodes.put(domAnnotation, domASTNode); |
| 2023 | return domAnnotation; |
| 2024 | } |
| 2025 | return null; |
| 2026 | } |
| 2027 | |
| 2028 | @Override |
| 2029 | public CompilationUnitScope scope() { |
| 2030 | return this.scope; |
| 2031 | } |
| 2032 | |
| 2033 | @Override |
| 2034 | synchronized void store(ASTNode node, org.eclipse.jdt.internal.compiler.ast.ASTNode oldASTNode) { |
| 2035 | this.newAstToOldAst.put(node, oldASTNode); |
| 2036 | } |
| 2037 | |
| 2038 | @Override |
| 2039 | synchronized void updateKey(ASTNode node, ASTNode newNode) { |
| 2040 | Object astNode = this.newAstToOldAst.remove(node); |
| 2041 | if (astNode != null) { |
| 2042 | this.newAstToOldAst.put(newNode, astNode); |
| 2043 | } |
| 2044 | } |
| 2045 | |
| 2046 | @Override |
| 2047 | ITypeBinding resolveArrayType(ITypeBinding typeBinding, int dimensions) { |
| 2048 | if (typeBinding instanceof RecoveredTypeBinding) throw new IllegalArgumentException("Cannot be called on a recovered type binding"); //$NON-NLS-1$ |
| 2049 | ITypeBinding leafComponentType = typeBinding; |
| 2050 | int actualDimensions = dimensions; |
| 2051 | if (typeBinding.isArray()) { |
| 2052 | leafComponentType = typeBinding.getElementType(); |
| 2053 | actualDimensions += typeBinding.getDimensions(); |
| 2054 | } |
| 2055 | if (!(leafComponentType instanceof TypeBinding)) return null; |
| 2056 | org.eclipse.jdt.internal.compiler.lookup.TypeBinding leafTypeBinding = |
| 2057 | ((TypeBinding) leafComponentType).binding; |
| 2058 | if (leafTypeBinding instanceof VoidTypeBinding) { |
| 2059 | throw new IllegalArgumentException(); |
| 2060 | } |
| 2061 | if (typeBinding.isArray()) { |
| 2062 | return this.getTypeBinding(lookupEnvironment().createArrayType( |
| 2063 | leafTypeBinding, |
| 2064 | actualDimensions, |
| 2065 | insertAnnotations((((TypeBinding) typeBinding).binding).getTypeAnnotations(), dimensions))); |
| 2066 | } else { |
| 2067 | return this.getTypeBinding(lookupEnvironment().createArrayType( |
| 2068 | leafTypeBinding, |
| 2069 | actualDimensions)); |
| 2070 | } |
| 2071 | } |
| 2072 | |
| 2073 | private org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding[] insertAnnotations( |
| 2074 | org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding[] annots, int dimensions) { |
| 2075 | if (dimensions == 0 || annots == null || annots.length == 0) { |
| 2076 | return annots; |
| 2077 | } |
| 2078 | int index = 0; |
| 2079 | if (dimensions < 0) { |
| 2080 | for (int i = 0; i < annots.length; i++) { |
| 2081 | index++; |
| 2082 | if (annots[i] == null) { |
| 2083 | if(++dimensions == 0) break; |
| 2084 | } |
| 2085 | } |
| 2086 | if (dimensions < 0) dimensions = 0; // Just means there were no annotations |
| 2087 | } |
| 2088 | org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding[] newAnnots = |
| 2089 | new org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding[annots.length - index + dimensions]; |
| 2090 | |
| 2091 | System.arraycopy(annots, index, newAnnots, dimensions, annots.length - index); |
| 2092 | return newAnnots; |
| 2093 | } |
| 2094 | } |
| 2095 |
Members