KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > core > dom > DefaultBindingResolver


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.jdt.core.dom;
13
14 import java.util.HashMap JavaDoc;
15 import java.util.Map JavaDoc;
16
17 import org.eclipse.jdt.core.WorkingCopyOwner;
18 import org.eclipse.jdt.core.compiler.CharOperation;
19 import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
20 import org.eclipse.jdt.internal.compiler.ast.AbstractVariableDeclaration;
21 import org.eclipse.jdt.internal.compiler.ast.AllocationExpression;
22 import org.eclipse.jdt.internal.compiler.ast.ArrayAllocationExpression;
23 import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
24 import org.eclipse.jdt.internal.compiler.ast.ExplicitConstructorCall;
25 import org.eclipse.jdt.internal.compiler.ast.FieldReference;
26 import org.eclipse.jdt.internal.compiler.ast.JavadocImplicitTypeReference;
27 import org.eclipse.jdt.internal.compiler.ast.ImportReference;
28 import org.eclipse.jdt.internal.compiler.ast.JavadocAllocationExpression;
29 import org.eclipse.jdt.internal.compiler.ast.JavadocFieldReference;
30 import org.eclipse.jdt.internal.compiler.ast.JavadocMessageSend;
31 import org.eclipse.jdt.internal.compiler.ast.JavadocQualifiedTypeReference;
32 import org.eclipse.jdt.internal.compiler.ast.JavadocSingleTypeReference;
33 import org.eclipse.jdt.internal.compiler.ast.Literal;
34 import org.eclipse.jdt.internal.compiler.ast.LocalDeclaration;
35 import org.eclipse.jdt.internal.compiler.ast.MessageSend;
36 import org.eclipse.jdt.internal.compiler.ast.ParameterizedQualifiedTypeReference;
37 import org.eclipse.jdt.internal.compiler.ast.QualifiedNameReference;
38 import org.eclipse.jdt.internal.compiler.ast.QualifiedSuperReference;
39 import org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference;
40 import org.eclipse.jdt.internal.compiler.ast.SingleNameReference;
41 import org.eclipse.jdt.internal.compiler.ast.SingleTypeReference;
42 import org.eclipse.jdt.internal.compiler.ast.ThisReference;
43 import org.eclipse.jdt.internal.compiler.ast.TypeReference;
44 import org.eclipse.jdt.internal.compiler.impl.Constant;
45 import org.eclipse.jdt.internal.compiler.lookup.ArrayBinding;
46 import org.eclipse.jdt.internal.compiler.lookup.BaseTypes;
47 import org.eclipse.jdt.internal.compiler.lookup.Binding;
48 import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
49 import org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope;
50 import org.eclipse.jdt.internal.compiler.lookup.FieldBinding;
51 import org.eclipse.jdt.internal.compiler.lookup.LocalVariableBinding;
52 import org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment;
53 import org.eclipse.jdt.internal.compiler.lookup.ProblemFieldBinding;
54 import org.eclipse.jdt.internal.compiler.lookup.ProblemReasons;
55 import org.eclipse.jdt.internal.compiler.lookup.ProblemReferenceBinding;
56 import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
57 import org.eclipse.jdt.internal.compiler.lookup.Scope;
58 import org.eclipse.jdt.internal.compiler.lookup.TypeConstants;
59 import org.eclipse.jdt.internal.compiler.lookup.TypeIds;
60 import org.eclipse.jdt.internal.compiler.problem.AbortCompilation;
61
62 /**
63  * Internal class for resolving bindings using old ASTs.
64  * <p>
65  * IMPORTANT: The methods on this class are synchronized. This is required
66  * because there may be multiple clients in separate threads concurrently
67  * reading an AST and asking for bindings for its nodes. These requests all
68  * end up invoking instance methods on this class. There are various internal
69  * tables and caches which are built and maintained in the course of looking
70  * up bindings. To ensure that they remain coherent in the presence of multiple
71  * threads, the methods are synchronized on the DefaultBindingResolver instance.
72  * </p>
73  */

74 class DefaultBindingResolver extends BindingResolver {
75     
76     /*
77      * Holds on binding tables that can be shared by several ASTs.
78      */

79     static class BindingTables {
80     
81         /**
82          * This map is used to get a binding from its binding key.
83          */

84         Map JavaDoc bindingKeysToBindings;
85         /**
86          * This map is used to keep the correspondance between new bindings and the
87          * compiler bindings. This is an identity map. We should only create one object
88          * for one binding.
89          */

90         Map JavaDoc compilerBindingsToASTBindings;
91         
92         BindingTables() {
93             this.compilerBindingsToASTBindings = new HashMap JavaDoc();
94             this.bindingKeysToBindings = new HashMap JavaDoc();
95         }
96     
97     }
98     /**
99      * This map is used to retrieve the corresponding block scope for a ast node
100      */

101     Map JavaDoc astNodesToBlockScope;
102     
103     /**
104      * This map is used to get an ast node from its binding (new binding)
105      */

106     Map JavaDoc bindingsToAstNodes;
107     
108     /*
109      * The shared binding tables accros ASTs.
110      */

111     BindingTables bindingTables;
112     
113     /**
114      * This map is used to retrieve an old ast node using the new ast node. This is not an
115      * identity map.
116      */

117     Map JavaDoc newAstToOldAst;
118     
119     /**
120      * Compilation unit scope
121      */

122     private CompilationUnitScope scope;
123     
124     /**
125      * The working copy owner that defines the context in which this resolver is creating the bindings.
126      */

127     WorkingCopyOwner workingCopyOwner;
128     
129     /**
130      * Constructor for DefaultBindingResolver.
131      */

132     DefaultBindingResolver(CompilationUnitScope scope, WorkingCopyOwner workingCopyOwner, BindingTables bindingTables) {
133         this.newAstToOldAst = new HashMap JavaDoc();
134         this.astNodesToBlockScope = new HashMap JavaDoc();
135         this.bindingsToAstNodes = new HashMap JavaDoc();
136         this.bindingTables = bindingTables;
137         this.scope = scope;
138         this.workingCopyOwner = workingCopyOwner;
139     }
140
141     DefaultBindingResolver(LookupEnvironment lookupEnvironment, WorkingCopyOwner workingCopyOwner, BindingTables bindingTables) {
142         this.newAstToOldAst = new HashMap JavaDoc();
143         this.astNodesToBlockScope = new HashMap JavaDoc();
144         this.bindingsToAstNodes = new HashMap JavaDoc();
145         this.bindingTables = bindingTables;
146         this.scope = new CompilationUnitScope(new CompilationUnitDeclaration(null, null, -1), lookupEnvironment);
147         this.workingCopyOwner = workingCopyOwner;
148     }
149
150     /*
151      * Method declared on BindingResolver.
152      */

153     synchronized ASTNode findDeclaringNode(IBinding binding) {
154         if (binding == null) {
155             return null;
156         }
157         if (binding instanceof IMethodBinding) {
158             IMethodBinding methodBinding = (IMethodBinding) binding;
159             return (ASTNode) this.bindingsToAstNodes.get(methodBinding.getMethodDeclaration());
160         } else if (binding instanceof ITypeBinding) {
161             ITypeBinding typeBinding = (ITypeBinding) binding;
162             return (ASTNode) this.bindingsToAstNodes.get(typeBinding.getTypeDeclaration());
163         } else if (binding instanceof IVariableBinding) {
164             IVariableBinding variableBinding = (IVariableBinding) binding;
165             return (ASTNode) this.bindingsToAstNodes.get(variableBinding.getVariableDeclaration());
166         }
167         return (ASTNode) this.bindingsToAstNodes.get(binding);
168     }
169     
170     synchronized ASTNode findDeclaringNode(String JavaDoc bindingKey) {
171         if (bindingKey == null) {
172             return null;
173         }
174         Object JavaDoc binding = this.bindingTables.bindingKeysToBindings.get(bindingKey);
175         if (binding == null)
176             return null;
177         return (ASTNode) this.bindingsToAstNodes.get(binding);
178     }
179     
180     IBinding getBinding(org.eclipse.jdt.internal.compiler.lookup.Binding binding) {
181         switch (binding.kind()) {
182             case Binding.PACKAGE:
183                 return getPackageBinding((org.eclipse.jdt.internal.compiler.lookup.PackageBinding) binding);
184             case Binding.TYPE:
185             case Binding.BASE_TYPE:
186             case Binding.GENERIC_TYPE:
187             case Binding.PARAMETERIZED_TYPE:
188             case Binding.RAW_TYPE:
189                 return getTypeBinding((org.eclipse.jdt.internal.compiler.lookup.TypeBinding) binding);
190             case Binding.ARRAY_TYPE:
191             case Binding.TYPE_PARAMETER:
192                 return new TypeBinding(this, (org.eclipse.jdt.internal.compiler.lookup.TypeBinding) binding);
193             case Binding.METHOD:
194                 return getMethodBinding((org.eclipse.jdt.internal.compiler.lookup.MethodBinding) binding);
195             case Binding.FIELD:
196             case Binding.LOCAL:
197                 return getVariableBinding((org.eclipse.jdt.internal.compiler.lookup.VariableBinding) binding);
198         }
199         return null;
200     }
201
202     synchronized org.eclipse.jdt.internal.compiler.ast.ASTNode getCorrespondingNode(ASTNode currentNode) {
203         return (org.eclipse.jdt.internal.compiler.ast.ASTNode) this.newAstToOldAst.get(currentNode);
204     }
205     
206     /*
207      * Method declared on BindingResolver.
208      */

209     synchronized IMethodBinding getMethodBinding(org.eclipse.jdt.internal.compiler.lookup.MethodBinding methodBinding) {
210         if (methodBinding != null) {
211             if (methodBinding.isValidBinding()) {
212                 IMethodBinding binding = (IMethodBinding) this.bindingTables.compilerBindingsToASTBindings.get(methodBinding);
213                 if (binding != null) {
214                     return binding;
215                 }
216                 binding = new MethodBinding(this, methodBinding);
217                 this.bindingTables.compilerBindingsToASTBindings.put(methodBinding, binding);
218                 return binding;
219             } else {
220                 /*
221                  * http://dev.eclipse.org/bugs/show_bug.cgi?id=23597
222                  */

223                 switch(methodBinding.problemId()) {
224                     case ProblemReasons.NotVisible :
225                     case ProblemReasons.NonStaticReferenceInStaticContext :
226                     case ProblemReasons.NonStaticReferenceInConstructorInvocation :
227                         ReferenceBinding declaringClass = methodBinding.declaringClass;
228                         if (declaringClass != null) {
229                             org.eclipse.jdt.internal.compiler.lookup.MethodBinding exactBinding = declaringClass.getExactMethod(methodBinding.selector, methodBinding.parameters, null);
230                             if (exactBinding != null) {
231                                 IMethodBinding binding = (IMethodBinding) this.bindingTables.compilerBindingsToASTBindings.get(exactBinding);
232                                 if (binding != null) {
233                                     return binding;
234                                 }
235                                 binding = new MethodBinding(this, exactBinding);
236                                 this.bindingTables.compilerBindingsToASTBindings.put(exactBinding, binding);
237                                 return binding;
238                             }
239                         }
240                         break;
241                 }
242             }
243         }
244         return null;
245     }
246     /*
247      * Method declared on BindingResolver.
248      */

249     synchronized IPackageBinding getPackageBinding(org.eclipse.jdt.internal.compiler.lookup.PackageBinding packageBinding) {
250         if (packageBinding == null || !packageBinding.isValidBinding()) {
251             return null;
252         }
253         IPackageBinding binding = (IPackageBinding) this.bindingTables.compilerBindingsToASTBindings.get(packageBinding);
254         if (binding != null) {
255             return binding;
256         }
257         binding = new PackageBinding(packageBinding);
258         this.bindingTables.compilerBindingsToASTBindings.put(packageBinding, binding);
259         return binding;
260     }
261     private int getTypeArguments(ParameterizedQualifiedTypeReference typeReference) {
262         TypeReference[][] typeArguments = typeReference.typeArguments;
263         int value = 0;
264         for (int i = 0, max = typeArguments.length; i < max; i++) {
265             if ((typeArguments[i] != null) || (value != 0)) {
266                 value++;
267             }
268         }
269         return value;
270     }
271         
272     /*
273      * Method declared on BindingResolver.
274      */

275     synchronized ITypeBinding getTypeBinding(org.eclipse.jdt.internal.compiler.lookup.TypeBinding referenceBinding) {
276         if (referenceBinding == null) {
277             return null;
278         } else if (!referenceBinding.isValidBinding()) {
279             switch(referenceBinding.problemId()) {
280                 case ProblemReasons.NotVisible :
281                 case ProblemReasons.NonStaticReferenceInStaticContext :
282                     if (referenceBinding instanceof ProblemReferenceBinding) {
283                         ProblemReferenceBinding problemReferenceBinding = (ProblemReferenceBinding) referenceBinding;
284                         Binding binding2 = problemReferenceBinding.original;
285                         if (binding2 != null && binding2 instanceof org.eclipse.jdt.internal.compiler.lookup.TypeBinding) {
286                             TypeBinding binding = (TypeBinding) this.bindingTables.compilerBindingsToASTBindings.get(binding2);
287                             if (binding != null) {
288                                 return binding;
289                             }
290                             binding = new TypeBinding(this, (org.eclipse.jdt.internal.compiler.lookup.TypeBinding) binding2);
291                             this.bindingTables.compilerBindingsToASTBindings.put(binding2, binding);
292                             return binding;
293                         }
294                     }
295             }
296             return null;
297         } else {
298             TypeBinding binding = (TypeBinding) this.bindingTables.compilerBindingsToASTBindings.get(referenceBinding);
299             if (binding != null) {
300                 return binding;
301             }
302             binding = new TypeBinding(this, referenceBinding);
303             this.bindingTables.compilerBindingsToASTBindings.put(referenceBinding, binding);
304             return binding;
305         }
306     }
307     /*
308      * Method declared on BindingResolver.
309      */

310     synchronized IVariableBinding getVariableBinding(org.eclipse.jdt.internal.compiler.lookup.VariableBinding variableBinding) {
311         if (variableBinding != null) {
312             if (variableBinding.isValidBinding()) {
313                 IVariableBinding binding = (IVariableBinding) this.bindingTables.compilerBindingsToASTBindings.get(variableBinding);
314                 if (binding != null) {
315                     return binding;
316                 }
317                 binding = new VariableBinding(this, variableBinding);
318                 this.bindingTables.compilerBindingsToASTBindings.put(variableBinding, binding);
319                 return binding;
320             } else {
321                 /*
322                  * http://dev.eclipse.org/bugs/show_bug.cgi?id=24449
323                  */

324                 if (variableBinding instanceof ProblemFieldBinding) {
325                     ProblemFieldBinding problemFieldBinding = (ProblemFieldBinding) variableBinding;
326                     switch(problemFieldBinding.problemId()) {
327                         case ProblemReasons.NotVisible :
328                         case ProblemReasons.NonStaticReferenceInStaticContext :
329                         case ProblemReasons.NonStaticReferenceInConstructorInvocation :
330                             ReferenceBinding declaringClass = problemFieldBinding.declaringClass;
331                             FieldBinding exactBinding = declaringClass.getField(problemFieldBinding.name, true /*resolve*/);
332                             if (exactBinding != null) {
333                                 IVariableBinding variableBinding2 = (IVariableBinding) this.bindingTables.compilerBindingsToASTBindings.get(exactBinding);
334                                 if (variableBinding2 != null) {
335                                     return variableBinding2;
336                                 }
337                                 variableBinding2 = new VariableBinding(this, exactBinding);
338                                 this.bindingTables.compilerBindingsToASTBindings.put(exactBinding, variableBinding2);
339                                 return variableBinding2;
340                             }
341                             break;
342                     }
343                 }
344             }
345         }
346         return null;
347     }
348     
349     /*
350      * Method declared on BindingResolver.
351      */

352     LookupEnvironment lookupEnvironment() {
353         return this.scope.environment();
354     }
355     
356     /**
357      * @see org.eclipse.jdt.core.dom.BindingResolver#recordScope(ASTNode, BlockScope)
358      */

359     synchronized void recordScope(ASTNode astNode, BlockScope blockScope) {
360         this.astNodesToBlockScope.put(astNode, blockScope);
361     }
362     
363     /*
364      * @see BindingResolver#resolveBoxing(Expression)
365      */

366     boolean resolveBoxing(Expression expression) {
367         org.eclipse.jdt.internal.compiler.ast.ASTNode node = (org.eclipse.jdt.internal.compiler.ast.ASTNode) this.newAstToOldAst.get(expression);
368         if (node != null && (node instanceof org.eclipse.jdt.internal.compiler.ast.Expression)) {
369             org.eclipse.jdt.internal.compiler.ast.Expression compilerExpression = (org.eclipse.jdt.internal.compiler.ast.Expression) node;
370             return (compilerExpression.implicitConversion & TypeIds.BOXING) != 0;
371         }
372         return false;
373     }
374     
375     /*
376      * @see BindingResolver#resolveUnboxing(Expression)
377      */

378     boolean resolveUnboxing(Expression expression) {
379         org.eclipse.jdt.internal.compiler.ast.ASTNode node = (org.eclipse.jdt.internal.compiler.ast.ASTNode) this.newAstToOldAst.get(expression);
380         if (node != null && (node instanceof org.eclipse.jdt.internal.compiler.ast.Expression)) {
381             org.eclipse.jdt.internal.compiler.ast.Expression compilerExpression = (org.eclipse.jdt.internal.compiler.ast.Expression) node;
382             return (compilerExpression.implicitConversion & TypeIds.UNBOXING) != 0;
383         }
384         return false;
385     }
386     
387     /*
388      * @see BindingResolver#resolveConstantExpressionValue(Expression)
389      */

390     Object JavaDoc resolveConstantExpressionValue(Expression expression) {
391         org.eclipse.jdt.internal.compiler.ast.ASTNode node = (org.eclipse.jdt.internal.compiler.ast.ASTNode) this.newAstToOldAst.get(expression);
392         if (node != null && (node instanceof org.eclipse.jdt.internal.compiler.ast.Expression)) {
393             org.eclipse.jdt.internal.compiler.ast.Expression compilerExpression = (org.eclipse.jdt.internal.compiler.ast.Expression) node;
394             Constant constant = compilerExpression.constant;
395             if (constant != null && constant != Constant.NotAConstant) {
396                 switch (constant.typeID()) {
397                     case TypeIds.T_int : return new Integer JavaDoc(constant.intValue());
398                     case TypeIds.T_byte : return new Byte JavaDoc(constant.byteValue());
399                     case TypeIds.T_short : return new Short JavaDoc(constant.shortValue());
400                     case TypeIds.T_char : return new Character JavaDoc(constant.charValue());
401                     case TypeIds.T_float : return new Float JavaDoc(constant.floatValue());
402                     case TypeIds.T_double : return new Double JavaDoc(constant.doubleValue());
403                     case TypeIds.T_boolean : return constant.booleanValue() ? Boolean.TRUE : Boolean.FALSE;
404                     case TypeIds.T_long : return new Long JavaDoc(constant.longValue());
405                     case TypeIds.T_JavaLangString : return constant.stringValue();
406                 }
407                 return null;
408             }
409         }
410         return null;
411     }
412     
413     /*
414      * @see BindingResolver#resolveConstructor(ClassInstanceCreation)
415      */

416     synchronized IMethodBinding resolveConstructor(ClassInstanceCreation expression) {
417         org.eclipse.jdt.internal.compiler.ast.ASTNode node = (org.eclipse.jdt.internal.compiler.ast.ASTNode) this.newAstToOldAst.get(expression);
418         if (node != null && (node.bits & org.eclipse.jdt.internal.compiler.ast.ASTNode.IsAnonymousTypeMASK) != 0) {
419             org.eclipse.jdt.internal.compiler.ast.TypeDeclaration anonymousLocalTypeDeclaration = (org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) node;
420             return this.getMethodBinding(anonymousLocalTypeDeclaration.allocation.binding);
421         } else if (node instanceof AllocationExpression) {
422             return this.getMethodBinding(((AllocationExpression)node).binding);
423         }
424         return null;
425     }
426
427     /*
428      * @see BindingResolver#resolveConstructor(ConstructorInvocation)
429      */

430     synchronized IMethodBinding resolveConstructor(ConstructorInvocation expression) {
431         org.eclipse.jdt.internal.compiler.ast.ASTNode node = (org.eclipse.jdt.internal.compiler.ast.ASTNode) this.newAstToOldAst.get(expression);
432         if (node instanceof ExplicitConstructorCall) {
433             ExplicitConstructorCall explicitConstructorCall = (ExplicitConstructorCall) node;
434             return this.getMethodBinding(explicitConstructorCall.binding);
435         }
436         return null;
437     }
438
439     /* (non-Javadoc)
440      * @see org.eclipse.jdt.core.dom.BindingResolver#resolveConstructor(org.eclipse.jdt.core.dom.EnumConstantDeclaration)
441      */

442     IMethodBinding resolveConstructor(EnumConstantDeclaration enumConstantDeclaration) {
443         org.eclipse.jdt.internal.compiler.ast.ASTNode node = (org.eclipse.jdt.internal.compiler.ast.ASTNode) this.newAstToOldAst.get(enumConstantDeclaration);
444         if (node instanceof org.eclipse.jdt.internal.compiler.ast.FieldDeclaration) {
445             org.eclipse.jdt.internal.compiler.ast.FieldDeclaration fieldDeclaration = (org.eclipse.jdt.internal.compiler.ast.FieldDeclaration) node;
446             if (fieldDeclaration.getKind() == AbstractVariableDeclaration.ENUM_CONSTANT && fieldDeclaration.initialization != null) {
447                 AllocationExpression allocationExpression = (AllocationExpression) fieldDeclaration.initialization;
448                 return this.getMethodBinding(allocationExpression.binding);
449             }
450         }
451         return null;
452     }
453
454     /*
455      * @see BindingResolver#resolveConstructor(SuperConstructorInvocation)
456      */

457     synchronized IMethodBinding resolveConstructor(SuperConstructorInvocation expression) {
458         org.eclipse.jdt.internal.compiler.ast.ASTNode node = (org.eclipse.jdt.internal.compiler.ast.ASTNode) this.newAstToOldAst.get(expression);
459         if (node instanceof ExplicitConstructorCall) {
460             ExplicitConstructorCall explicitConstructorCall = (ExplicitConstructorCall) node;
461             return this.getMethodBinding(explicitConstructorCall.binding);
462         }
463         return null;
464     }
465     /*
466      * Method declared on BindingResolver.
467      */

468     synchronized ITypeBinding resolveExpressionType(Expression expression) {
469         switch(expression.getNodeType()) {
470             case ASTNode.CLASS_INSTANCE_CREATION :
471                 org.eclipse.jdt.internal.compiler.ast.ASTNode astNode = (org.eclipse.jdt.internal.compiler.ast.ASTNode) this.newAstToOldAst.get(expression);
472                 if (astNode instanceof org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) {
473                     // anonymous type case
474
org.eclipse.jdt.internal.compiler.ast.TypeDeclaration typeDeclaration = (org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) astNode;
475                     if (typeDeclaration != null) {
476                         ITypeBinding typeBinding = this.getTypeBinding(typeDeclaration.binding);
477                         if (typeBinding == null) {
478                             return null;
479                         }
480                         return typeBinding;
481                     }
482                 } else {
483                     // should be an AllocationExpression
484
AllocationExpression allocationExpression = (AllocationExpression) astNode;
485                     return this.getTypeBinding(allocationExpression.resolvedType);
486                 }
487                 return null;
488             case ASTNode.SIMPLE_NAME :
489             case ASTNode.QUALIFIED_NAME :
490                 return this.resolveTypeBindingForName((Name) expression);
491             case ASTNode.ARRAY_INITIALIZER :
492             case ASTNode.ARRAY_CREATION :
493             case ASTNode.ASSIGNMENT :
494             case ASTNode.POSTFIX_EXPRESSION :
495             case ASTNode.PREFIX_EXPRESSION :
496             case ASTNode.CAST_EXPRESSION :
497             case ASTNode.TYPE_LITERAL :
498             case ASTNode.INFIX_EXPRESSION :
499             case ASTNode.INSTANCEOF_EXPRESSION :
500             case ASTNode.FIELD_ACCESS :
501             case ASTNode.SUPER_FIELD_ACCESS :
502             case ASTNode.ARRAY_ACCESS :
503             case ASTNode.METHOD_INVOCATION :
504             case ASTNode.SUPER_METHOD_INVOCATION :
505             case ASTNode.CONDITIONAL_EXPRESSION :
506             case ASTNode.MARKER_ANNOTATION :
507             case ASTNode.NORMAL_ANNOTATION :
508             case ASTNode.SINGLE_MEMBER_ANNOTATION :
509                 org.eclipse.jdt.internal.compiler.ast.Expression compilerExpression = (org.eclipse.jdt.internal.compiler.ast.Expression) this.newAstToOldAst.get(expression);
510                 if (compilerExpression == null) {
511                     return null;
512                 }
513                 return this.getTypeBinding(compilerExpression.resolvedType);
514             case ASTNode.STRING_LITERAL :
515                 return this.getTypeBinding(this.scope.getJavaLangString());
516             case ASTNode.BOOLEAN_LITERAL :
517             case ASTNode.NULL_LITERAL :
518             case ASTNode.CHARACTER_LITERAL :
519             case ASTNode.NUMBER_LITERAL :
520                 Literal literal = (Literal) this.newAstToOldAst.get(expression);
521                 return this.getTypeBinding(literal.literalType(null));
522             case ASTNode.THIS_EXPRESSION :
523                 ThisReference thisReference = (ThisReference) this.newAstToOldAst.get(expression);
524                 BlockScope blockScope = (BlockScope) this.astNodesToBlockScope.get(expression);
525                 if (blockScope == null) {
526                     return null;
527                 }
528                 return this.getTypeBinding(thisReference.resolveType(blockScope));
529             case ASTNode.PARENTHESIZED_EXPRESSION :
530                 ParenthesizedExpression parenthesizedExpression = (ParenthesizedExpression) expression;
531                 return this.resolveExpressionType(parenthesizedExpression.getExpression());
532             case ASTNode.VARIABLE_DECLARATION_EXPRESSION :
533                 VariableDeclarationExpression variableDeclarationExpression = (VariableDeclarationExpression) expression;
534                 Type type = variableDeclarationExpression.getType();
535                 if (type != null) {
536                     return type.resolveBinding();
537                 }
538                 return null;
539             default:
540                 return null;
541         }
542     }
543
544     /*
545      * @see BindingResolver#resolveField(FieldAccess)
546      */

547     synchronized IVariableBinding resolveField(FieldAccess fieldAccess) {
548         Object JavaDoc oldNode = this.newAstToOldAst.get(fieldAccess);
549         if (oldNode instanceof FieldReference) {
550             FieldReference fieldReference = (FieldReference) oldNode;
551             if (fieldReference != null) {
552                 return this.getVariableBinding(fieldReference.binding);
553             }
554         }
555         return null;
556     }
557
558     /*
559      * @see BindingResolver#resolveField(SuperFieldAccess)
560      */

561     synchronized IVariableBinding resolveField(SuperFieldAccess fieldAccess) {
562         Object JavaDoc oldNode = this.newAstToOldAst.get(fieldAccess);
563         if (oldNode instanceof FieldReference) {
564             FieldReference fieldReference = (FieldReference) oldNode;
565             if (fieldReference != null) {
566                 return this.getVariableBinding(fieldReference.binding);
567             }
568         }
569         return null;
570     }
571
572     /*
573      * @see BindingResolver#resolveImport(ImportDeclaration)
574      */

575     synchronized IBinding resolveImport(ImportDeclaration importDeclaration) {
576         try {
577             org.eclipse.jdt.internal.compiler.ast.ASTNode node = (org.eclipse.jdt.internal.compiler.ast.ASTNode) this.newAstToOldAst.get(importDeclaration);
578             if (node instanceof ImportReference) {
579                 ImportReference importReference = (ImportReference) node;
580                 final boolean isStatic = importReference.isStatic();
581                 if (importReference.onDemand) {
582                     Binding binding = this.scope.getImport(CharOperation.subarray(importReference.tokens, 0, importReference.tokens.length), true, isStatic);
583                     if (binding != null) {
584                         if (isStatic) {
585                             if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.TypeBinding) {
586                                 ITypeBinding typeBinding = this.getTypeBinding((org.eclipse.jdt.internal.compiler.lookup.TypeBinding) binding);
587                                 return typeBinding == null ? null : typeBinding;
588                             }
589                         } else {
590                             if ((binding.kind() & Binding.PACKAGE) != 0) {
591                                 IPackageBinding packageBinding = this.getPackageBinding((org.eclipse.jdt.internal.compiler.lookup.PackageBinding) binding);
592                                 if (packageBinding == null) {
593                                     return null;
594                                 }
595                                 return packageBinding;
596                             } else {
597                                 // if it is not a package, it has to be a type
598
ITypeBinding typeBinding = this.getTypeBinding((org.eclipse.jdt.internal.compiler.lookup.TypeBinding) binding);
599                                 if (typeBinding == null) {
600                                     return null;
601                                 }
602                                 return typeBinding;
603                             }
604                         }
605                     }
606                 } else {
607                     Binding binding = this.scope.getImport(importReference.tokens, false, isStatic);
608                     if (binding != null) {
609                         if (isStatic) {
610                             if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.TypeBinding) {
611                                 ITypeBinding typeBinding = this.getTypeBinding((org.eclipse.jdt.internal.compiler.lookup.TypeBinding) binding);
612                                 return typeBinding == null ? null : typeBinding;
613                             } else if (binding instanceof FieldBinding) {
614                                 IVariableBinding variableBinding = this.getVariableBinding((FieldBinding) binding);
615                                 return variableBinding == null ? null : variableBinding;
616                             } else if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.MethodBinding) {
617                                 // it is a type
618
return this.getMethodBinding((org.eclipse.jdt.internal.compiler.lookup.MethodBinding)binding);
619                             }
620                         } else {
621                             if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.TypeBinding) {
622                                 ITypeBinding typeBinding = this.getTypeBinding((org.eclipse.jdt.internal.compiler.lookup.TypeBinding) binding);
623                                 return typeBinding == null ? null : typeBinding;
624                             }
625                         }
626                     }
627                 }
628             }
629         } catch(RuntimeException JavaDoc e) {
630             // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=53357
631
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=63550
632
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=64299
633
}
634         return null;
635     }
636     
637     /* (non-Javadoc)
638      * @see org.eclipse.jdt.core.dom.BindingResolver#resolveMember(org.eclipse.jdt.core.dom.AnnotationTypeMemberDeclaration)
639      */

640     IMethodBinding resolveMember(AnnotationTypeMemberDeclaration declaration) {
641         Object JavaDoc oldNode = this.newAstToOldAst.get(declaration);
642         if (oldNode instanceof AbstractMethodDeclaration) {
643             AbstractMethodDeclaration methodDeclaration = (AbstractMethodDeclaration) oldNode;
644             if (methodDeclaration != null) {
645                 IMethodBinding methodBinding = this.getMethodBinding(methodDeclaration.binding);
646                 if (methodBinding == null) {
647                     return null;
648                 }
649                 this.bindingsToAstNodes.put(methodBinding, declaration);
650                 String JavaDoc key = methodBinding.getKey();
651                 if (key != null) {
652                     this.bindingTables.bindingKeysToBindings.put(key, methodBinding);
653                 }
654                 return methodBinding;
655             }
656         }
657         return null;
658     }
659     
660     /*
661      * Method declared on BindingResolver.
662      */

663     synchronized IMethodBinding resolveMethod(MethodDeclaration method) {
664         Object JavaDoc oldNode = this.newAstToOldAst.get(method);
665         if (oldNode instanceof AbstractMethodDeclaration) {
666             AbstractMethodDeclaration methodDeclaration = (AbstractMethodDeclaration) oldNode;
667             if (methodDeclaration != null) {
668                 IMethodBinding methodBinding = this.getMethodBinding(methodDeclaration.binding);
669                 if (methodBinding == null) {
670                     return null;
671                 }
672                 this.bindingsToAstNodes.put(methodBinding, method);
673                 String JavaDoc key = methodBinding.getKey();
674                 if (key != null) {
675                     this.bindingTables.bindingKeysToBindings.put(key, methodBinding);
676                 }
677                 return methodBinding;
678             }
679         }
680         return null;
681     }
682     /*
683      * Method declared on BindingResolver.
684      */

685     synchronized IMethodBinding resolveMethod(MethodInvocation method) {
686         Object JavaDoc oldNode = this.newAstToOldAst.get(method);
687         if (oldNode instanceof MessageSend) {
688             MessageSend messageSend = (MessageSend) oldNode;
689             if (messageSend != null) {
690                 return this.getMethodBinding(messageSend.binding);
691             }
692         }
693         return null;
694     }
695     /*
696      * Method declared on BindingResolver.
697      */

698     synchronized IMethodBinding resolveMethod(SuperMethodInvocation method) {
699         Object JavaDoc oldNode = this.newAstToOldAst.get(method);
700         if (oldNode instanceof MessageSend) {
701             MessageSend messageSend = (MessageSend) oldNode;
702             if (messageSend != null) {
703                 return this.getMethodBinding(messageSend.binding);
704             }
705         }
706         return null;
707     }
708     
709     synchronized ITypeBinding resolveTypeBindingForName(Name name) {
710         org.eclipse.jdt.internal.compiler.ast.ASTNode node = (org.eclipse.jdt.internal.compiler.ast.ASTNode) this.newAstToOldAst.get(name);
711         int index = name.index;
712         if (node instanceof QualifiedNameReference) {
713             QualifiedNameReference qualifiedNameReference = (QualifiedNameReference) node;
714             final char[][] tokens = qualifiedNameReference.tokens;
715             if (tokens.length == index) {
716                 return this.getTypeBinding(qualifiedNameReference.resolvedType);
717             }
718             int indexOfFirstFieldBinding = qualifiedNameReference.indexOfFirstFieldBinding; // one-based
719
if (index < indexOfFirstFieldBinding) {
720                 // an extra lookup is required
721
BlockScope internalScope = (BlockScope) this.astNodesToBlockScope.get(name);
722                 Binding binding = null;
723                 try {
724                     if (internalScope == null) {
725                         binding = this.scope.getTypeOrPackage(CharOperation.subarray(tokens, 0, index));
726                     } else {
727                         binding = internalScope.getTypeOrPackage(CharOperation.subarray(tokens, 0, index));
728                     }
729                 } catch (RuntimeException JavaDoc e) {
730                     // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=53357
731
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=63550
732
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=64299
733
}
734                 if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.PackageBinding) {
735                     return null;
736                 } else if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.TypeBinding) {
737                     // it is a type
738
return this.getTypeBinding((org.eclipse.jdt.internal.compiler.lookup.TypeBinding)binding);
739                 }
740             } else if (index == indexOfFirstFieldBinding) {
741                 if (qualifiedNameReference.isTypeReference()) {
742                     return this.getTypeBinding(qualifiedNameReference.resolvedType);
743                 } else {
744                     // in this case we want to get the next field declaring's class
745
if (qualifiedNameReference.otherBindings == null) {
746                         return null;
747                     }
748                     FieldBinding fieldBinding = qualifiedNameReference.otherBindings[0];
749                     if (fieldBinding == null) return null;
750                     org.eclipse.jdt.internal.compiler.lookup.TypeBinding type = fieldBinding.declaringClass;
751                     if (type == null) { // array length scenario
752
// use type from first binding (no capture needed for array type)
753
switch (qualifiedNameReference.bits & org.eclipse.jdt.internal.compiler.ast.ASTNode.RestrictiveFlagMASK) {
754                             case Binding.FIELD:
755                                 type = ((FieldBinding) qualifiedNameReference.binding).type;
756                                 break;
757                             case Binding.LOCAL:
758                                 type = ((LocalVariableBinding) qualifiedNameReference.binding).type;
759                                 break;
760                         }
761                     }
762                     return this.getTypeBinding(type);
763                 }
764             } else {
765                 /* This is the case for a name which is part of a qualified name that
766                  * cannot be resolved. See PR 13063.
767                  */

768                 if (qualifiedNameReference.otherBindings == null) return null;
769                 final int otherBindingsLength = qualifiedNameReference.otherBindings.length;
770                 if (otherBindingsLength == (index - indexOfFirstFieldBinding)) {
771                     return this.getTypeBinding(qualifiedNameReference.resolvedType);
772                 }
773                 FieldBinding fieldBinding = qualifiedNameReference.otherBindings[index - indexOfFirstFieldBinding];
774                 if (fieldBinding == null) return null;
775                 org.eclipse.jdt.internal.compiler.lookup.TypeBinding type = fieldBinding.declaringClass;
776                 if (type == null) { // array length scenario
777
// use type from previous binding (no capture needed for array type)
778
fieldBinding = qualifiedNameReference.otherBindings[index - indexOfFirstFieldBinding - 1];
779                     if (fieldBinding == null) return null;
780                     type = fieldBinding.type;
781                 }
782                 return this.getTypeBinding(type);
783             }
784         } else if (node instanceof QualifiedTypeReference) {
785             QualifiedTypeReference qualifiedTypeReference = (QualifiedTypeReference) node;
786             if (qualifiedTypeReference.resolvedType == null) {
787                 return null;
788             }
789             if (index == qualifiedTypeReference.tokens.length) {
790                 if (!qualifiedTypeReference.resolvedType.isValidBinding() && qualifiedTypeReference instanceof JavadocQualifiedTypeReference) {
791                     JavadocQualifiedTypeReference typeRef = (JavadocQualifiedTypeReference) node;
792                     if (typeRef.packageBinding != null) {
793                         return null;
794                     }
795                 }
796                 return this.getTypeBinding(qualifiedTypeReference.resolvedType.leafComponentType());
797             } else {
798                 if (index >= 0) {
799                     BlockScope internalScope = (BlockScope) this.astNodesToBlockScope.get(name);
800                     Binding binding = null;
801                     try {
802                         if (internalScope == null) {
803                             binding = this.scope.getTypeOrPackage(CharOperation.subarray(qualifiedTypeReference.tokens, 0, index));
804                         } else {
805                             binding = internalScope.getTypeOrPackage(CharOperation.subarray(qualifiedTypeReference.tokens, 0, index));
806                         }
807                     } catch (RuntimeException JavaDoc e) {
808                         // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=53357
809
}
810                     if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.PackageBinding) {
811                         return null;
812                     } else if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.TypeBinding) {
813                         // it is a type
814
return this.getTypeBinding((org.eclipse.jdt.internal.compiler.lookup.TypeBinding)binding);
815                     } else {
816                         return null;
817                     }
818                 }
819             }
820         } else if (node instanceof ImportReference) {
821             ImportReference importReference = (ImportReference) node;
822             int importReferenceLength = importReference.tokens.length;
823             if (index >= 0) {
824                 Binding binding = null;
825                 if (importReferenceLength == index) {
826                     try {
827                         binding = this.scope.getImport(CharOperation.subarray(importReference.tokens, 0, index), importReference.onDemand, importReference.isStatic());
828                     } catch (RuntimeException JavaDoc e) {
829                         // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=53357
830
}
831                 } else {
832                     try {
833                         binding = this.scope.getImport(CharOperation.subarray(importReference.tokens, 0, index), true, importReference.isStatic());
834                     } catch (RuntimeException JavaDoc e) {
835                         // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=53357
836
}
837                 }
838                 if (binding != null) {
839                     if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.TypeBinding) {
840                         // it is a type
841
return this.getTypeBinding((org.eclipse.jdt.internal.compiler.lookup.TypeBinding)binding);
842                     }
843                     return null;
844                 }
845             }
846         } else if (node instanceof AbstractMethodDeclaration) {
847             AbstractMethodDeclaration methodDeclaration = (AbstractMethodDeclaration) node;
848             if (methodDeclaration != null) {
849                 IMethodBinding method = this.getMethodBinding(methodDeclaration.binding);
850                 if (method == null) return null;
851                 return method.getReturnType();
852             }
853         } else if (node instanceof org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) {
854             org.eclipse.jdt.internal.compiler.ast.TypeDeclaration typeDeclaration = (org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) node;
855             ITypeBinding typeBinding = this.getTypeBinding(typeDeclaration.binding);
856             if (typeBinding != null) {
857                 return typeBinding;
858             }
859         } if (node instanceof SingleNameReference) {
860             SingleNameReference singleNameReference = (SingleNameReference) node;
861             return this.getTypeBinding(singleNameReference.resolvedType);
862         } else if (node instanceof QualifiedSuperReference) {
863             QualifiedSuperReference qualifiedSuperReference = (QualifiedSuperReference) node;
864             return this.getTypeBinding(qualifiedSuperReference.qualification.resolvedType);
865         } else if (node instanceof LocalDeclaration) {
866             IVariableBinding variable = this.getVariableBinding(((LocalDeclaration)node).binding);
867             if (variable == null) return null;
868             return variable.getType();
869         } else if (node instanceof JavadocFieldReference) {
870             JavadocFieldReference fieldRef = (JavadocFieldReference) node;
871             if (fieldRef.methodBinding != null) {
872                 return getMethodBinding(fieldRef.methodBinding).getReturnType();
873             }
874             return getTypeBinding(fieldRef.resolvedType);
875         } else if (node instanceof FieldReference) {
876             return getTypeBinding(((FieldReference) node).resolvedType);
877         } else if (node instanceof SingleTypeReference) {
878             SingleTypeReference singleTypeReference = (SingleTypeReference) node;
879             org.eclipse.jdt.internal.compiler.lookup.TypeBinding binding = singleTypeReference.resolvedType;
880             if (binding != null) {
881                 return this.getTypeBinding(binding.leafComponentType());
882             }
883         } else if (node instanceof org.eclipse.jdt.internal.compiler.ast.FieldDeclaration) {
884             org.eclipse.jdt.internal.compiler.ast.FieldDeclaration fieldDeclaration = (org.eclipse.jdt.internal.compiler.ast.FieldDeclaration) node;
885             IVariableBinding field = this.getVariableBinding(fieldDeclaration.binding);
886             if (field == null) return null;
887             return field.getType();
888         } else if (node instanceof MessageSend) {
889             MessageSend messageSend = (MessageSend) node;
890             IMethodBinding method = getMethodBinding(messageSend.binding);
891             if (method == null) return null;
892             return method.getReturnType();
893         } else if (node instanceof AllocationExpression) {
894             AllocationExpression allocation = (AllocationExpression) node;
895             return getTypeBinding(allocation.resolvedType);
896         } else if (node instanceof JavadocImplicitTypeReference) {
897             JavadocImplicitTypeReference implicitRef = (JavadocImplicitTypeReference) node;
898             return getTypeBinding(implicitRef.resolvedType);
899         } else if (node instanceof org.eclipse.jdt.internal.compiler.ast.TypeParameter) {
900             org.eclipse.jdt.internal.compiler.ast.TypeParameter typeParameter = (org.eclipse.jdt.internal.compiler.ast.TypeParameter) node;
901             return this.getTypeBinding(typeParameter.binding);
902         } else if (node instanceof org.eclipse.jdt.internal.compiler.ast.MemberValuePair) {
903             org.eclipse.jdt.internal.compiler.ast.MemberValuePair memberValuePair = (org.eclipse.jdt.internal.compiler.ast.MemberValuePair) node;
904             IMethodBinding method = getMethodBinding(memberValuePair.binding);
905             if (method == null) return null;
906             return method.getReturnType();
907         }
908         return null;
909     }
910     
911     /*
912      * Method declared on BindingResolver.
913      */

914     synchronized IBinding resolveName(Name name) {
915         org.eclipse.jdt.internal.compiler.ast.ASTNode node = (org.eclipse.jdt.internal.compiler.ast.ASTNode) this.newAstToOldAst.get(name);
916         int index = name.index;
917         if (node instanceof QualifiedNameReference) {
918             QualifiedNameReference qualifiedNameReference = (QualifiedNameReference) node;
919             final char[][] tokens = qualifiedNameReference.tokens;
920             int indexOfFirstFieldBinding = qualifiedNameReference.indexOfFirstFieldBinding; // one-based
921
if (index < indexOfFirstFieldBinding) {
922                 // an extra lookup is required
923
BlockScope internalScope = (BlockScope) this.astNodesToBlockScope.get(name);
924                 Binding binding = null;
925                 try {
926                     if (internalScope == null) {
927                         binding = this.scope.getTypeOrPackage(CharOperation.subarray(tokens, 0, index));
928                     } else {
929                         binding = internalScope.getTypeOrPackage(CharOperation.subarray(tokens, 0, index));
930                     }
931                 } catch (RuntimeException JavaDoc e) {
932                     // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=53357
933
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=63550
934
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=64299
935
}
936                 if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.PackageBinding) {
937                     return this.getPackageBinding((org.eclipse.jdt.internal.compiler.lookup.PackageBinding)binding);
938                 } else if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.TypeBinding) {
939                     // it is a type
940
return this.getTypeBinding((org.eclipse.jdt.internal.compiler.lookup.TypeBinding)binding);
941                 }
942             } else if (index == indexOfFirstFieldBinding) {
943                 if (qualifiedNameReference.isTypeReference()) {
944                     return this.getTypeBinding(qualifiedNameReference.resolvedType);
945                 } else {
946                     Binding binding = qualifiedNameReference.binding;
947                     if (binding != null) {
948                         if (binding.isValidBinding()) {
949                             return this.getVariableBinding((org.eclipse.jdt.internal.compiler.lookup.VariableBinding) binding);
950                         } else if (binding instanceof ProblemFieldBinding) {
951                             ProblemFieldBinding problemFieldBinding = (ProblemFieldBinding) binding;
952                             switch(problemFieldBinding.problemId()) {
953                                 case ProblemReasons.NotVisible :
954                                 case ProblemReasons.NonStaticReferenceInStaticContext :
955                                     ReferenceBinding declaringClass = problemFieldBinding.declaringClass;
956                                     if (declaringClass != null) {
957                                         FieldBinding exactBinding = declaringClass.getField(tokens[tokens.length - 1], true /*resolve*/);
958                                         if (exactBinding != null) {
959                                             IVariableBinding variableBinding = (IVariableBinding) this.bindingTables.compilerBindingsToASTBindings.get(exactBinding);
960                                             if (variableBinding != null) {
961                                                 return variableBinding;
962                                             }
963                                             variableBinding = new VariableBinding(this, exactBinding);
964                                             this.bindingTables.compilerBindingsToASTBindings.put(exactBinding, variableBinding);
965                                             return variableBinding;
966                                         }
967                                     }
968                                     break;
969                             }
970                         }
971                     }
972                 }
973             } else {
974                 /* This is the case for a name which is part of a qualified name that
975                  * cannot be resolved. See PR 13063.
976                  */

977                 if (qualifiedNameReference.otherBindings == null || (index - indexOfFirstFieldBinding - 1) < 0) {
978                     return null;
979                 } else {
980                     return this.getVariableBinding(qualifiedNameReference.otherBindings[index - indexOfFirstFieldBinding - 1]);
981                 }
982             }
983         } else if (node instanceof QualifiedTypeReference) {
984             QualifiedTypeReference qualifiedTypeReference = (QualifiedTypeReference) node;
985             if (qualifiedTypeReference.resolvedType == null) {
986                 return null;
987             }
988             if (index == qualifiedTypeReference.tokens.length) {
989                 if (!qualifiedTypeReference.resolvedType.isValidBinding() && qualifiedTypeReference instanceof JavadocQualifiedTypeReference) {
990                     JavadocQualifiedTypeReference typeRef = (JavadocQualifiedTypeReference) node;
991                     if (typeRef.packageBinding != null) {
992                         return getPackageBinding(typeRef.packageBinding);
993                     }
994                 }
995                 return this.getTypeBinding(qualifiedTypeReference.resolvedType.leafComponentType());
996             } else {
997                 if (index >= 0) {
998                     BlockScope internalScope = (BlockScope) this.astNodesToBlockScope.get(name);
999                     Binding binding = null;
1000                    try {
1001                        if (internalScope == null) {
1002                            binding = this.scope.getTypeOrPackage(CharOperation.subarray(qualifiedTypeReference.tokens, 0, index));
1003                        } else {
1004                            binding = internalScope.getTypeOrPackage(CharOperation.subarray(qualifiedTypeReference.tokens, 0, index));
1005                        }
1006                    } catch (RuntimeException JavaDoc e) {
1007                        // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=53357
1008
}
1009                    if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.PackageBinding) {
1010                        return this.getPackageBinding((org.eclipse.jdt.internal.compiler.lookup.PackageBinding)binding);
1011                    } else if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.TypeBinding) {
1012                        // it is a type
1013
return this.getTypeBinding((org.eclipse.jdt.internal.compiler.lookup.TypeBinding)binding);
1014                    } else {
1015                        return null;
1016                    }
1017                }
1018            }
1019        } else if (node instanceof ImportReference) {
1020            ImportReference importReference = (ImportReference) node;
1021            int importReferenceLength = importReference.tokens.length;
1022            if (index >= 0) {
1023                Binding binding = null;
1024                if (importReferenceLength == index) {
1025                    try {
1026                        binding = this.scope.getImport(CharOperation.subarray(importReference.tokens, 0, index), importReference.onDemand, importReference.isStatic());
1027                    } catch (RuntimeException JavaDoc e) {
1028                        // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=53357
1029
}
1030                } else {
1031                    try {
1032                        binding = this.scope.getImport(CharOperation.subarray(importReference.tokens, 0, index), true, importReference.isStatic());
1033                    } catch (RuntimeException JavaDoc e) {
1034                        // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=53357
1035
}
1036                }
1037                if (binding != null) {
1038                    if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.PackageBinding) {
1039                        return this.getPackageBinding((org.eclipse.jdt.internal.compiler.lookup.PackageBinding)binding);
1040                    } else if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.TypeBinding) {
1041                        // it is a type
1042
return this.getTypeBinding((org.eclipse.jdt.internal.compiler.lookup.TypeBinding)binding);
1043                    } else if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.FieldBinding) {
1044                        // it is a type
1045
return this.getVariableBinding((org.eclipse.jdt.internal.compiler.lookup.FieldBinding)binding);
1046                    } else if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.MethodBinding) {
1047                        // it is a type
1048
return this.getMethodBinding((org.eclipse.jdt.internal.compiler.lookup.MethodBinding)binding);
1049                    } else {
1050                        return null;
1051                    }
1052                }
1053            }
1054        } else if (node instanceof CompilationUnitDeclaration) {
1055            CompilationUnitDeclaration compilationUnitDeclaration = (CompilationUnitDeclaration) node;
1056            org.eclipse.jdt.internal.compiler.ast.TypeDeclaration[] types = compilationUnitDeclaration.types;
1057            if (types == null || types.length == 0) {
1058                return null;
1059            }
1060            org.eclipse.jdt.internal.compiler.ast.TypeDeclaration type = types[0];
1061            if (type != null) {
1062                ITypeBinding typeBinding = this.getTypeBinding(type.binding);
1063                if (typeBinding != null) {
1064                    return typeBinding.getPackage();
1065                }
1066            }
1067        } else if (node instanceof AbstractMethodDeclaration) {
1068            AbstractMethodDeclaration methodDeclaration = (AbstractMethodDeclaration) node;
1069            if (methodDeclaration != null) {
1070                IMethodBinding methodBinding = this.getMethodBinding(methodDeclaration.binding);
1071                if (methodBinding != null) {
1072                    return methodBinding;
1073                }
1074            }
1075        } else if (node instanceof org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) {
1076            org.eclipse.jdt.internal.compiler.ast.TypeDeclaration typeDeclaration = (org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) node;
1077            ITypeBinding typeBinding = this.getTypeBinding(typeDeclaration.binding);
1078            if (typeBinding != null) {
1079                return typeBinding;
1080            }
1081        } if (node instanceof SingleNameReference) {
1082            SingleNameReference singleNameReference = (SingleNameReference) node;
1083            if (singleNameReference.isTypeReference()) {
1084                return this.getTypeBinding(singleNameReference.resolvedType);
1085            } else {
1086                // this is a variable or a field
1087
Binding binding = singleNameReference.binding;
1088                if (binding != null) {
1089                    if (binding.isValidBinding()) {
1090                        return this.getVariableBinding((org.eclipse.jdt.internal.compiler.lookup.VariableBinding) binding);
1091                    } else {
1092                        /*
1093                         * http://dev.eclipse.org/bugs/show_bug.cgi?id=24449
1094                         */

1095                        if (binding instanceof ProblemFieldBinding) {
1096                            ProblemFieldBinding problemFieldBinding = (ProblemFieldBinding) binding;
1097                            switch(problemFieldBinding.problemId()) {
1098                                case ProblemReasons.NotVisible :
1099                                case ProblemReasons.NonStaticReferenceInStaticContext :
1100                                case ProblemReasons.NonStaticReferenceInConstructorInvocation :
1101                                    ReferenceBinding declaringClass = problemFieldBinding.declaringClass;
1102                                    FieldBinding exactBinding = declaringClass.getField(problemFieldBinding.name, true /*resolve*/);
1103                                    if (exactBinding != null) {
1104                                        IVariableBinding variableBinding2 = (IVariableBinding) this.bindingTables.compilerBindingsToASTBindings.get(exactBinding);
1105                                        if (variableBinding2 != null) {
1106                                            return variableBinding2;
1107                                        }
1108                                        variableBinding2 = new VariableBinding(this, exactBinding);
1109                                        this.bindingTables.compilerBindingsToASTBindings.put(exactBinding, variableBinding2);
1110                                        return variableBinding2;
1111                                    }
1112                                    break;
1113                            }
1114                        }
1115                    }
1116                }
1117            }
1118        } else if (node instanceof QualifiedSuperReference) {
1119            QualifiedSuperReference qualifiedSuperReference = (QualifiedSuperReference) node;
1120            return this.getTypeBinding(qualifiedSuperReference.qualification.resolvedType);
1121        } else if (node instanceof LocalDeclaration) {
1122            return this.getVariableBinding(((LocalDeclaration)node).binding);
1123        } else if (node instanceof JavadocFieldReference) {
1124            JavadocFieldReference fieldRef = (JavadocFieldReference) node;
1125            if (fieldRef.methodBinding != null) {
1126                return getMethodBinding(fieldRef.methodBinding);
1127            }
1128            return getVariableBinding(fieldRef.binding);
1129        } else if (node instanceof FieldReference) {
1130            return getVariableBinding(((FieldReference) node).binding);
1131        } else if (node instanceof SingleTypeReference) {
1132            SingleTypeReference singleTypeReference = (SingleTypeReference) node;
1133            org.eclipse.jdt.internal.compiler.lookup.TypeBinding binding = singleTypeReference.resolvedType;
1134            if (binding != null) {
1135                if (!binding.isValidBinding() && node instanceof JavadocSingleTypeReference) {
1136                    JavadocSingleTypeReference typeRef = (JavadocSingleTypeReference) node;
1137                    if (typeRef.packageBinding != null) {
1138                        return getPackageBinding(typeRef.packageBinding);
1139                    }
1140                }
1141                return this.getTypeBinding(binding.leafComponentType());
1142            }
1143        } else if (node instanceof org.eclipse.jdt.internal.compiler.ast.FieldDeclaration) {
1144            org.eclipse.jdt.internal.compiler.ast.FieldDeclaration fieldDeclaration = (org.eclipse.jdt.internal.compiler.ast.FieldDeclaration) node;
1145            return this.getVariableBinding(fieldDeclaration.binding);
1146        } else if (node instanceof MessageSend) {
1147            MessageSend messageSend = (MessageSend) node;
1148            return getMethodBinding(messageSend.binding);
1149        } else if (node instanceof AllocationExpression) {
1150            AllocationExpression allocation = (AllocationExpression) node;
1151            return getMethodBinding(allocation.binding);
1152        } else if (node instanceof JavadocImplicitTypeReference) {
1153            JavadocImplicitTypeReference implicitRef = (JavadocImplicitTypeReference) node;
1154            return getTypeBinding(implicitRef.resolvedType);
1155        } else if (node instanceof org.eclipse.jdt.internal.compiler.ast.TypeParameter) {
1156            org.eclipse.jdt.internal.compiler.ast.TypeParameter typeParameter = (org.eclipse.jdt.internal.compiler.ast.TypeParameter) node;
1157            return this.getTypeBinding(typeParameter.binding);
1158        } else if (node instanceof org.eclipse.jdt.internal.compiler.ast.MemberValuePair) {
1159            org.eclipse.jdt.internal.compiler.ast.MemberValuePair memberValuePair = (org.eclipse.jdt.internal.compiler.ast.MemberValuePair) node;
1160            return getMethodBinding(memberValuePair.binding);
1161        }
1162        return null;
1163    }
1164
1165    /*
1166     * @see BindingResolver#resolvePackage(PackageDeclaration)
1167     */

1168    synchronized IPackageBinding resolvePackage(PackageDeclaration pkg) {
1169        try {
1170            org.eclipse.jdt.internal.compiler.ast.ASTNode node = (org.eclipse.jdt.internal.compiler.ast.ASTNode) this.newAstToOldAst.get(pkg);
1171            if (node instanceof ImportReference) {
1172                ImportReference importReference = (ImportReference) node;
1173                Binding binding = this.scope.getTypeOrPackage(CharOperation.subarray(importReference.tokens, 0, importReference.tokens.length));
1174                if ((binding != null) && (binding.isValidBinding())) {
1175                    IPackageBinding packageBinding = this.getPackageBinding((org.eclipse.jdt.internal.compiler.lookup.PackageBinding) binding);
1176                    if (packageBinding == null) {
1177                        return null;
1178                    }
1179                    this.bindingsToAstNodes.put(packageBinding, pkg);
1180                    String JavaDoc key = packageBinding.getKey();
1181                    if (key != null) {
1182                        this.bindingTables.bindingKeysToBindings.put(key, packageBinding);
1183                    }
1184                    return packageBinding;
1185                }
1186            }
1187        } catch (RuntimeException JavaDoc e) {
1188            // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=53357
1189
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=63550
1190
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=64299
1191
}
1192        return null;
1193    }
1194    
1195    /* (non-Javadoc)
1196     * @see BindingResolver#resolveReference(MemberRef)
1197     * @since 3.0
1198     */

1199    synchronized IBinding resolveReference(MemberRef ref) {
1200        org.eclipse.jdt.internal.compiler.ast.Expression expression = (org.eclipse.jdt.internal.compiler.ast.Expression) this.newAstToOldAst.get(ref);
1201        if (expression instanceof TypeReference) {
1202            return getTypeBinding(expression.resolvedType);
1203        }
1204        else if (expression instanceof JavadocFieldReference) {
1205            JavadocFieldReference fieldRef = (JavadocFieldReference) expression;
1206            if (fieldRef.methodBinding != null) {
1207                return getMethodBinding(fieldRef.methodBinding);
1208            }
1209            return getVariableBinding(fieldRef.binding);
1210        }
1211        return null;
1212    }
1213
1214    /* (non-Javadoc)
1215     * @see BindingResolver#resolveReference(MethodRef)
1216     * @since 3.0
1217     */

1218    synchronized IBinding resolveReference(MethodRef ref) {
1219        org.eclipse.jdt.internal.compiler.ast.Expression expression = (org.eclipse.jdt.internal.compiler.ast.Expression) this.newAstToOldAst.get(ref);
1220        if (expression instanceof JavadocMessageSend) {
1221            return this.getMethodBinding(((JavadocMessageSend)expression).binding);
1222        }
1223        else if (expression instanceof JavadocAllocationExpression) {
1224            return this.getMethodBinding(((JavadocAllocationExpression)expression).binding);
1225        }
1226        return null;
1227    }
1228    
1229    /* (non-Javadoc)
1230     * @see org.eclipse.jdt.core.dom.BindingResolver#resolveType(org.eclipse.jdt.core.dom.AnnotationTypeDeclaration)
1231     */

1232    ITypeBinding resolveType(AnnotationTypeDeclaration type) {
1233        final Object JavaDoc node = this.newAstToOldAst.get(type);
1234        if (node instanceof org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) {
1235            org.eclipse.jdt.internal.compiler.ast.TypeDeclaration typeDeclaration = (org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) node;
1236            if (typeDeclaration != null) {
1237                ITypeBinding typeBinding = this.getTypeBinding(typeDeclaration.binding);
1238                if (typeBinding == null) {
1239                    return null;
1240                }
1241                this.bindingsToAstNodes.put(typeBinding, type);
1242                String JavaDoc key = typeBinding.getKey();
1243                if (key != null) {
1244                    this.bindingTables.bindingKeysToBindings.put(key, typeBinding);
1245                }
1246                return typeBinding;
1247            }
1248        }
1249        return null;
1250    }
1251    /*
1252     * @see BindingResolver#resolveType(AnonymousClassDeclaration)
1253     */

1254    synchronized ITypeBinding resolveType(AnonymousClassDeclaration type) {
1255        org.eclipse.jdt.internal.compiler.ast.ASTNode node = (org.eclipse.jdt.internal.compiler.ast.ASTNode) this.newAstToOldAst.get(type);
1256        if (node != null && (node.bits & org.eclipse.jdt.internal.compiler.ast.ASTNode.IsAnonymousTypeMASK) != 0) {
1257            org.eclipse.jdt.internal.compiler.ast.TypeDeclaration anonymousLocalTypeDeclaration = (org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) node;
1258            if (anonymousLocalTypeDeclaration != null) {
1259                ITypeBinding typeBinding = this.getTypeBinding(anonymousLocalTypeDeclaration.binding);
1260                if (typeBinding == null) {
1261                    return null;
1262                }
1263                this.bindingsToAstNodes.put(typeBinding, type);
1264                String JavaDoc key = typeBinding.getKey();
1265                if (key != null) {
1266                    this.bindingTables.bindingKeysToBindings.put(key, typeBinding);
1267                }
1268                return typeBinding;
1269            }
1270        }
1271        return null;
1272    }
1273
1274    /* (non-Javadoc)
1275     * @see org.eclipse.jdt.core.dom.BindingResolver#resolveType(org.eclipse.jdt.core.dom.EnumDeclaration)
1276     */

1277    ITypeBinding resolveType(EnumDeclaration type) {
1278        final Object JavaDoc node = this.newAstToOldAst.get(type);
1279        if (node instanceof org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) {
1280            org.eclipse.jdt.internal.compiler.ast.TypeDeclaration typeDeclaration = (org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) node;
1281            if (typeDeclaration != null) {
1282                ITypeBinding typeBinding = this.getTypeBinding(typeDeclaration.binding);
1283                if (typeBinding == null) {
1284                    return null;
1285                }
1286                this.bindingsToAstNodes.put(typeBinding, type);
1287                String JavaDoc key = typeBinding.getKey();
1288                if (key != null) {
1289                    this.bindingTables.bindingKeysToBindings.put(key, typeBinding);
1290                }
1291                return typeBinding;
1292            }
1293        }
1294        return null;
1295    }
1296
1297    /*
1298     * Method declared on BindingResolver.
1299     */

1300    synchronized ITypeBinding resolveType(Type type) {
1301        // retrieve the old ast node
1302
org.eclipse.jdt.internal.compiler.ast.ASTNode node = (org.eclipse.jdt.internal.compiler.ast.ASTNode) this.newAstToOldAst.get(type);
1303        org.eclipse.jdt.internal.compiler.lookup.TypeBinding binding = null;
1304        if (node != null) {
1305            if (node instanceof ParameterizedQualifiedTypeReference) {
1306                ParameterizedQualifiedTypeReference typeReference = (ParameterizedQualifiedTypeReference) node;
1307                org.eclipse.jdt.internal.compiler.lookup.TypeBinding typeBinding = typeReference.resolvedType;
1308                int index;
1309                if (type.isQualifiedType()) {
1310                    index = ((QualifiedType) type).index;
1311                } else if (type.isParameterizedType()) {
1312                    index = ((ParameterizedType) type).index;
1313                } else {
1314                    index = 1;
1315                }
1316                final int numberOfTypeArgumentsNotNull = getTypeArguments(typeReference);
1317                if (index != numberOfTypeArgumentsNotNull) {
1318                    int i = numberOfTypeArgumentsNotNull;
1319                    while (i != index) {
1320                        typeBinding = typeBinding.enclosingType();
1321                        i --;
1322                    }
1323                    binding = typeBinding;
1324                } else {
1325                    binding = typeBinding;
1326                }
1327            } else if (node instanceof TypeReference) {
1328                TypeReference typeReference = (TypeReference) node;
1329                binding = typeReference.resolvedType;
1330            } else if (node instanceof SingleNameReference && ((SingleNameReference)node).isTypeReference()) {
1331                binding = (((SingleNameReference)node).resolvedType);
1332            } else if (node instanceof QualifiedNameReference && ((QualifiedNameReference)node).isTypeReference()) {
1333                binding = (((QualifiedNameReference)node).resolvedType);
1334            } else if (node instanceof ArrayAllocationExpression) {
1335                binding = ((ArrayAllocationExpression) node).resolvedType;
1336            }
1337            if (binding != null) {
1338                if (type.isArrayType()) {
1339                    ArrayType arrayType = (ArrayType) type;
1340                    if (binding.isArrayType()) {
1341                        ArrayBinding arrayBinding = (ArrayBinding) binding;
1342                        return getTypeBinding(this.scope.createArrayType(arrayBinding.leafComponentType, arrayType.getDimensions()));
1343                    } else {
1344                        return getTypeBinding(this.scope.createArrayType(binding, arrayType.getDimensions()));
1345                    }
1346                } else {
1347                    if (binding.isArrayType()) {
1348                        ArrayBinding arrayBinding = (ArrayBinding) binding;
1349                        return getTypeBinding(arrayBinding.leafComponentType);
1350                    } else {
1351                        return getTypeBinding(binding);
1352                    }
1353                }
1354            }
1355        } else if (type.isPrimitiveType()) {
1356            /* Handle the void primitive type returned by getReturnType for a method declaration
1357             * that is a constructor declaration. It prevents null from being returned
1358             */

1359            if (((PrimitiveType) type).getPrimitiveTypeCode() == PrimitiveType.VOID) {
1360                return this.getTypeBinding(BaseTypes.VoidBinding);
1361            }
1362        }
1363        return null;
1364    }
1365
1366    /*
1367     * Method declared on BindingResolver.
1368     */

1369    synchronized ITypeBinding resolveType(TypeDeclaration type) {
1370        final Object JavaDoc node = this.newAstToOldAst.get(type);
1371        if (node instanceof org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) {
1372            org.eclipse.jdt.internal.compiler.ast.TypeDeclaration typeDeclaration = (org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) node;
1373            if (typeDeclaration != null) {
1374                ITypeBinding typeBinding = this.getTypeBinding(typeDeclaration.binding);
1375                if (typeBinding == null) {
1376                    return null;
1377                }
1378                this.bindingsToAstNodes.put(typeBinding, type);
1379                String JavaDoc key = typeBinding.getKey();
1380                if (key != null) {
1381                    this.bindingTables.bindingKeysToBindings.put(key, typeBinding);
1382                }
1383                return typeBinding;
1384            }
1385        }
1386        return null;
1387    }
1388    
1389    synchronized ITypeBinding resolveTypeParameter(TypeParameter typeParameter) {
1390        final Object JavaDoc node = this.newAstToOldAst.get(typeParameter);
1391        if (node instanceof org.eclipse.jdt.internal.compiler.ast.TypeParameter) {
1392            org.eclipse.jdt.internal.compiler.ast.TypeParameter typeParameter2 = (org.eclipse.jdt.internal.compiler.ast.TypeParameter) node;
1393            if (typeParameter2 != null) {
1394                ITypeBinding typeBinding = this.getTypeBinding(typeParameter2.binding);
1395                if (typeBinding == null) {
1396                    return null;
1397                }
1398                this.bindingsToAstNodes.put(typeBinding, typeParameter);
1399                String JavaDoc key = typeBinding.getKey();
1400                if (key != null) {
1401                    this.bindingTables.bindingKeysToBindings.put(key, typeBinding);
1402                }
1403                return typeBinding;
1404            }
1405        }
1406        return null;
1407    }
1408    
1409    /* (non-Javadoc)
1410     * @see org.eclipse.jdt.core.dom.BindingResolver#resolveVariable(org.eclipse.jdt.core.dom.EnumConstantDeclaration)
1411     */

1412    synchronized IVariableBinding resolveVariable(EnumConstantDeclaration enumConstant) {
1413        final Object JavaDoc node = this.newAstToOldAst.get(enumConstant);
1414        if (node instanceof org.eclipse.jdt.internal.compiler.ast.FieldDeclaration) {
1415            org.eclipse.jdt.internal.compiler.ast.FieldDeclaration fieldDeclaration = (org.eclipse.jdt.internal.compiler.ast.FieldDeclaration) node;
1416            IVariableBinding variableBinding = this.getVariableBinding(fieldDeclaration.binding);
1417            if (variableBinding == null) {
1418                return null;
1419            }
1420            this.bindingsToAstNodes.put(variableBinding, enumConstant);
1421            String JavaDoc key = variableBinding.getKey();
1422            if (key != null) {
1423                this.bindingTables.bindingKeysToBindings.put(key, variableBinding);
1424            }
1425            return variableBinding;
1426        }
1427        return null;
1428    }
1429    /*
1430     * Method declared on BindingResolver.
1431     */

1432    synchronized IVariableBinding resolveVariable(VariableDeclaration variable) {
1433        final Object JavaDoc node = this.newAstToOldAst.get(variable);
1434        if (node instanceof AbstractVariableDeclaration) {
1435            AbstractVariableDeclaration abstractVariableDeclaration = (AbstractVariableDeclaration) node;
1436            if (abstractVariableDeclaration instanceof org.eclipse.jdt.internal.compiler.ast.FieldDeclaration) {
1437                org.eclipse.jdt.internal.compiler.ast.FieldDeclaration fieldDeclaration = (org.eclipse.jdt.internal.compiler.ast.FieldDeclaration) abstractVariableDeclaration;
1438                IVariableBinding variableBinding = this.getVariableBinding(fieldDeclaration.binding);
1439                if (variableBinding == null) {
1440                    return null;
1441                }
1442                this.bindingsToAstNodes.put(variableBinding, variable);
1443                String JavaDoc key = variableBinding.getKey();
1444                if (key != null) {
1445                    this.bindingTables.bindingKeysToBindings.put(key, variableBinding);
1446                }
1447                return variableBinding;
1448            }
1449            IVariableBinding variableBinding = this.getVariableBinding(((LocalDeclaration) abstractVariableDeclaration).binding);
1450            if (variableBinding == null) {
1451                return null;
1452            }
1453            this.bindingsToAstNodes.put(variableBinding, variable);
1454            String JavaDoc key = variableBinding.getKey();
1455            if (key != null) {
1456                this.bindingTables.bindingKeysToBindings.put(key, variableBinding);
1457            }
1458            return variableBinding;
1459        }
1460        return null;
1461    }
1462    
1463    /*
1464     * Method declared on BindingResolver.
1465     */

1466    synchronized ITypeBinding resolveWellKnownType(String JavaDoc name) {
1467        try {
1468            if (("boolean".equals(name))//$NON-NLS-1$
1469
|| ("char".equals(name))//$NON-NLS-1$
1470
|| ("byte".equals(name))//$NON-NLS-1$
1471
|| ("short".equals(name))//$NON-NLS-1$
1472
|| ("int".equals(name))//$NON-NLS-1$
1473
|| ("long".equals(name))//$NON-NLS-1$
1474
|| ("float".equals(name))//$NON-NLS-1$
1475
|| ("double".equals(name))//$NON-NLS-1$
1476
|| ("void".equals(name))) {//$NON-NLS-1$
1477
return this.getTypeBinding(Scope.getBaseType(name.toCharArray()));
1478            } else if ("java.lang.Object".equals(name)) {//$NON-NLS-1$
1479
return this.getTypeBinding(this.scope.getJavaLangObject());
1480            } else if ("java.lang.String".equals(name)) {//$NON-NLS-1$
1481
return this.getTypeBinding(this.scope.getJavaLangString());
1482            } else if ("java.lang.StringBuffer".equals(name)) {//$NON-NLS-1$
1483
return this.getTypeBinding(this.scope.getType(TypeConstants.JAVA_LANG_STRINGBUFFER, 3));
1484            } else if ("java.lang.Throwable".equals(name)) {//$NON-NLS-1$
1485
return this.getTypeBinding(this.scope.getJavaLangThrowable());
1486            } else if ("java.lang.Exception".equals(name)) {//$NON-NLS-1$
1487
return this.getTypeBinding(this.scope.getType(TypeConstants.JAVA_LANG_EXCEPTION, 3));
1488            } else if ("java.lang.RuntimeException".equals(name)) {//$NON-NLS-1$
1489
return this.getTypeBinding(this.scope.getType(TypeConstants.JAVA_LANG_RUNTIMEEXCEPTION, 3));
1490            } else if ("java.lang.Error".equals(name)) {//$NON-NLS-1$
1491
return this.getTypeBinding(this.scope.getType(TypeConstants.JAVA_LANG_ERROR, 3));
1492            } else if ("java.lang.Class".equals(name)) {//$NON-NLS-1$
1493
return this.getTypeBinding(this.scope.getJavaLangClass());
1494            } else if ("java.lang.Cloneable".equals(name)) {//$NON-NLS-1$
1495
return this.getTypeBinding(this.scope.getJavaLangCloneable());
1496            } else if ("java.io.Serializable".equals(name)) {//$NON-NLS-1$
1497
return this.getTypeBinding(this.scope.getJavaIoSerializable());
1498            } else if ("java.lang.Boolean".equals(name)) {//$NON-NLS-1$
1499
return this.getTypeBinding(this.scope.getType(TypeConstants.JAVA_LANG_BOOLEAN, 3));
1500            } else if ("java.lang.Byte".equals(name)) {//$NON-NLS-1$
1501
return this.getTypeBinding(this.scope.getType(TypeConstants.JAVA_LANG_BYTE, 3));
1502            } else if ("java.lang.Character".equals(name)) {//$NON-NLS-1$
1503
return this.getTypeBinding(this.scope.getType(TypeConstants.JAVA_LANG_CHARACTER, 3));
1504            } else if ("java.lang.Double".equals(name)) {//$NON-NLS-1$
1505
return this.getTypeBinding(this.scope.getType(TypeConstants.JAVA_LANG_DOUBLE, 3));
1506            } else if ("java.lang.Float".equals(name)) {//$NON-NLS-1$
1507
return this.getTypeBinding(this.scope.getType(TypeConstants.JAVA_LANG_FLOAT, 3));
1508            } else if ("java.lang.Integer".equals(name)) {//$NON-NLS-1$
1509
return this.getTypeBinding(this.scope.getType(TypeConstants.JAVA_LANG_INTEGER, 3));
1510            } else if ("java.lang.Long".equals(name)) {//$NON-NLS-1$
1511
return this.getTypeBinding(this.scope.getType(TypeConstants.JAVA_LANG_LONG, 3));
1512            } else if ("java.lang.Short".equals(name)) {//$NON-NLS-1$
1513
return this.getTypeBinding(this.scope.getType(TypeConstants.JAVA_LANG_SHORT, 3));
1514            } else if ("java.lang.Void".equals(name)) {//$NON-NLS-1$
1515
return this.getTypeBinding(this.scope.getType(TypeConstants.JAVA_LANG_VOID, 3));
1516            }
1517        } catch (AbortCompilation e) {
1518            // ignore missing types
1519
}
1520        return null;
1521    }
1522    
1523    /*
1524     * Method declared on BindingResolver.
1525     */

1526    public CompilationUnitScope scope() {
1527        return this.scope;
1528    }
1529        
1530    /*
1531     * Method declared on BindingResolver.
1532     */

1533    synchronized void store(ASTNode node, org.eclipse.jdt.internal.compiler.ast.ASTNode oldASTNode) {
1534        this.newAstToOldAst.put(node, oldASTNode);
1535    }
1536    
1537    /*
1538     * Method declared on BindingResolver.
1539     */

1540    synchronized void updateKey(ASTNode node, ASTNode newNode) {
1541        Object JavaDoc astNode = this.newAstToOldAst.remove(node);
1542        if (astNode != null) {
1543            this.newAstToOldAst.put(newNode, astNode);
1544        }
1545    }
1546}
1547
Popular Tags