added -J option to preserve unmodified files in preexisting jarfile
[org.ibex.tool.git] / src / org / eclipse / jdt / internal / compiler / lookup / UnresolvedReferenceBinding.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-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) {
27         if (this.wrappers == null) {
28                 this.wrappers = new TypeBinding[] {wrapper};
29         } else {
30                 int length = this.wrappers.length;
31                 System.arraycopy(this.wrappers, 0, this.wrappers = new TypeBinding[length + 1], 0, length);
32                 this.wrappers[length] = wrapper;
33         }
34 }
35 public String debugName() {
36         return toString();
37 }
38 ReferenceBinding resolve(LookupEnvironment environment, boolean convertGenericToRawType) {
39     ReferenceBinding targetType = this.resolvedType;
40         if (targetType == null) {
41                 targetType = this.fPackage.getType0(this.compoundName[this.compoundName.length - 1]);
42                 if (targetType == this)
43                         targetType = environment.askForType(this.compoundName);
44                 if (targetType != null && targetType != this) { // could not resolve any better, error was already reported against it
45                         setResolvedType(targetType, environment);
46                 } else {
47                         environment.problemReporter.isClassPathCorrect(this.compoundName, null);
48                         return null; // will not get here since the above error aborts the compilation
49                 }
50         }
51         if (convertGenericToRawType) {
52                 boolean rawEnclosing = false;
53                 ReferenceBinding targetEnclosingType = targetType.enclosingType();
54                 if (targetEnclosingType != null && targetEnclosingType.isGenericType()) { // convert to raw type since wasn't parameterized
55                         rawEnclosing = true;
56                         targetEnclosingType = environment.createRawType(targetEnclosingType, targetEnclosingType.enclosingType());
57                 }
58                 if (targetType.isGenericType()) { // raw reference to generic ?
59                     return environment.createRawType(targetType, targetEnclosingType);
60                 } else if (rawEnclosing) {
61                         return environment.createParameterizedType(targetType, null, targetEnclosingType);
62                 }
63         }
64         return targetType;
65 }
66 void setResolvedType(ReferenceBinding targetType, LookupEnvironment environment) {
67         if (this.resolvedType == targetType) return; // already resolved
68
69         // targetType may be a source or binary type
70         this.resolvedType = targetType;
71         // must ensure to update any other type bindings that can contain the resolved type
72         // otherwise we could create 2 : 1 for this unresolved type & 1 for the resolved type
73         if (this.wrappers != null)
74                 for (int i = 0, l = this.wrappers.length; i < l; i++)
75                         this.wrappers[i].swapUnresolved(this, targetType, environment);
76         environment.updateCaches(this, targetType);
77 }
78 public String toString() {
79         return "Unresolved type " + ((compoundName != null) ? CharOperation.toString(compoundName) : "UNNAMED"); //$NON-NLS-1$ //$NON-NLS-2$
80 }
81 }