KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > compiler > lookup > UnresolvedReferenceBinding


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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 package org.eclipse.jdt.internal.compiler.lookup;
12
13 import org.eclipse.jdt.core.compiler.CharOperation;
14
15 public class UnresolvedReferenceBinding extends ReferenceBinding {
16
17 ReferenceBinding resolvedType;
18 TypeBinding[] wrappers;
19
20 UnresolvedReferenceBinding(char[][] compoundName, PackageBinding packageBinding) {
21     this.compoundName = compoundName;
22     this.sourceName = compoundName[compoundName.length - 1]; // reasonable guess
23
this.fPackage = packageBinding;
24     this.wrappers = null;
25 }
26 void addWrapper(TypeBinding wrapper, LookupEnvironment environment) {
27     if (this.resolvedType != null) {
28         // the type reference B<B<T>.M> means a signature of <T:Ljava/lang/Object;>LB<LB<TT;>.M;>;
29
// when the ParameterizedType for Unresolved B is created with args B<T>.M, the Unresolved B is resolved before the wrapper is added
30
wrapper.swapUnresolved(this, this.resolvedType, environment);
31         return;
32     }
33     if (this.wrappers == null) {
34         this.wrappers = new TypeBinding[] {wrapper};
35     } else {
36         int length = this.wrappers.length;
37         System.arraycopy(this.wrappers, 0, this.wrappers = new TypeBinding[length + 1], 0, length);
38         this.wrappers[length] = wrapper;
39     }
40 }
41 public String JavaDoc debugName() {
42     return toString();
43 }
44 ReferenceBinding resolve(LookupEnvironment environment, boolean convertGenericToRawType) {
45     ReferenceBinding targetType = this.resolvedType;
46     if (targetType == null) {
47         targetType = this.fPackage.getType0(this.compoundName[this.compoundName.length - 1]);
48         if (targetType == this)
49             targetType = environment.askForType(this.compoundName);
50         if (targetType == null || targetType == this) { // could not resolve any better, error was already reported against it
51
// create a proxy for the missing BinaryType
52
targetType = environment.cacheMissingBinaryType(this.compoundName, null);
53         }
54         setResolvedType(targetType, environment);
55     }
56     if (convertGenericToRawType) {
57         targetType = (ReferenceBinding) environment.convertUnresolvedBinaryToRawType(targetType);
58     }
59     return targetType;
60 }
61 void setResolvedType(ReferenceBinding targetType, LookupEnvironment environment) {
62     if (this.resolvedType == targetType) return; // already resolved
63

64     // targetType may be a source or binary type
65
this.resolvedType = targetType;
66     // must ensure to update any other type bindings that can contain the resolved type
67
// otherwise we could create 2 : 1 for this unresolved type & 1 for the resolved type
68
if (this.wrappers != null)
69         for (int i = 0, l = this.wrappers.length; i < l; i++)
70             this.wrappers[i].swapUnresolved(this, targetType, environment);
71     environment.updateCaches(this, targetType);
72 }
73 public String JavaDoc toString() {
74     return "Unresolved type " + ((compoundName != null) ? CharOperation.toString(compoundName) : "UNNAMED"); //$NON-NLS-1$ //$NON-NLS-2$
75
}
76 }
77
Popular Tags