01: /*******************************************************************************
02: * Copyright (c) 2000, 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.jdt.internal.compiler.lookup;
11:
12: import org.eclipse.jdt.core.compiler.CharOperation;
13:
14: public class UnresolvedReferenceBinding extends ReferenceBinding {
15:
16: ReferenceBinding resolvedType;
17: TypeBinding[] wrappers;
18:
19: UnresolvedReferenceBinding(char[][] compoundName,
20: 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:
27: void addWrapper(TypeBinding wrapper, LookupEnvironment environment) {
28: if (this .resolvedType != null) {
29: // the type reference B<B<T>.M> means a signature of <T:Ljava/lang/Object;>LB<LB<TT;>.M;>;
30: // when the ParameterizedType for Unresolved B is created with args B<T>.M, the Unresolved B is resolved before the wrapper is added
31: wrapper
32: .swapUnresolved(this , this .resolvedType,
33: environment);
34: return;
35: }
36: if (this .wrappers == null) {
37: this .wrappers = new TypeBinding[] { wrapper };
38: } else {
39: int length = this .wrappers.length;
40: System.arraycopy(this .wrappers, 0,
41: this .wrappers = new TypeBinding[length + 1], 0,
42: length);
43: this .wrappers[length] = wrapper;
44: }
45: }
46:
47: public String debugName() {
48: return toString();
49: }
50:
51: ReferenceBinding resolve(LookupEnvironment environment,
52: boolean convertGenericToRawType) {
53: ReferenceBinding targetType = this .resolvedType;
54: if (targetType == null) {
55: targetType = this .fPackage
56: .getType0(this .compoundName[this .compoundName.length - 1]);
57: if (targetType == this )
58: targetType = environment.askForType(this .compoundName);
59: if (targetType == null || targetType == this ) { // could not resolve any better, error was already reported against it
60: // create a proxy for the missing BinaryType
61: targetType = environment.cacheMissingBinaryType(
62: this .compoundName, null);
63: }
64: setResolvedType(targetType, environment);
65: }
66: if (convertGenericToRawType) {
67: targetType = (ReferenceBinding) environment
68: .convertUnresolvedBinaryToRawType(targetType);
69: }
70: return targetType;
71: }
72:
73: void setResolvedType(ReferenceBinding targetType,
74: LookupEnvironment environment) {
75: if (this .resolvedType == targetType)
76: return; // already resolved
77:
78: // targetType may be a source or binary type
79: this .resolvedType = targetType;
80: // must ensure to update any other type bindings that can contain the resolved type
81: // otherwise we could create 2 : 1 for this unresolved type & 1 for the resolved type
82: if (this .wrappers != null)
83: for (int i = 0, l = this .wrappers.length; i < l; i++)
84: this .wrappers[i].swapUnresolved(this , targetType,
85: environment);
86: environment.updateCaches(this , targetType);
87: }
88:
89: public String toString() {
90: return "Unresolved type " + ((compoundName != null) ? CharOperation.toString(compoundName) : "UNNAMED"); //$NON-NLS-1$ //$NON-NLS-2$
91: }
92: }
|