1 11 package org.eclipse.jdt.internal.compiler.lookup; 12 13 import org.eclipse.jdt.core.compiler.CharOperation; 14 import org.eclipse.jdt.internal.compiler.util.HashtableOfPackage; 15 import org.eclipse.jdt.internal.compiler.util.HashtableOfType; 16 17 public class PackageBinding extends Binding implements TypeConstants { 18 public long tagBits = 0; 20 public char[][] compoundName; 21 PackageBinding parent; 22 public LookupEnvironment environment; 23 HashtableOfType knownTypes; 24 HashtableOfPackage knownPackages; 25 protected PackageBinding() { 26 } 28 public PackageBinding(char[][] compoundName, PackageBinding parent, LookupEnvironment environment) { 29 this.compoundName = compoundName; 30 this.parent = parent; 31 this.environment = environment; 32 this.knownTypes = null; this.knownPackages = new HashtableOfPackage(3); } 35 public PackageBinding(char[] topLevelPackageName, LookupEnvironment environment) { 36 this(new char[][] {topLevelPackageName}, null, environment); 37 } 38 40 41 public PackageBinding(LookupEnvironment environment) { 42 this(CharOperation.NO_CHAR_CHAR, null, environment); 43 } 44 private void addNotFoundPackage(char[] simpleName) { 45 knownPackages.put(simpleName, LookupEnvironment.TheNotFoundPackage); 46 } 47 private void addNotFoundType(char[] simpleName) { 48 if (knownTypes == null) 49 knownTypes = new HashtableOfType(25); 50 knownTypes.put(simpleName, LookupEnvironment.TheNotFoundType); 51 } 52 void addPackage(PackageBinding element) { 53 knownPackages.put(element.compoundName[element.compoundName.length - 1], element); 54 } 55 void addType(ReferenceBinding element) { 56 if (knownTypes == null) 57 knownTypes = new HashtableOfType(25); 58 knownTypes.put(element.compoundName[element.compoundName.length - 1], element); 59 } 60 63 64 public final int kind() { 65 return Binding.PACKAGE; 66 } 67 71 public char[] computeUniqueKey(boolean isLeaf) { 72 return CharOperation.concatWith(compoundName, '/'); 73 } 74 private PackageBinding findPackage(char[] name) { 75 if (!environment.isPackage(this.compoundName, name)) 76 return null; 77 78 char[][] subPkgCompoundName = CharOperation.arrayConcat(this.compoundName, name); 79 PackageBinding subPackageBinding = new PackageBinding(subPkgCompoundName, this, environment); 80 addPackage(subPackageBinding); 81 return subPackageBinding; 82 } 83 88 89 PackageBinding getPackage(char[] name) { 90 PackageBinding binding = getPackage0(name); 91 if (binding != null) { 92 if (binding == LookupEnvironment.TheNotFoundPackage) 93 return null; 94 else 95 return binding; 96 } 97 if ((binding = findPackage(name)) != null) 98 return binding; 99 100 addNotFoundPackage(name); 102 return null; 103 } 104 111 112 PackageBinding getPackage0(char[] name) { 113 return knownPackages.get(name); 114 } 115 122 123 ReferenceBinding getType(char[] name) { 124 ReferenceBinding typeBinding = getType0(name); 125 if (typeBinding == null) { 126 if ((typeBinding = environment.askForType(this, name)) == null) { 127 addNotFoundType(name); 129 return null; 130 } 131 } 132 133 if (typeBinding == LookupEnvironment.TheNotFoundType) 134 return null; 135 136 typeBinding = BinaryTypeBinding.resolveType(typeBinding, environment, false); if (typeBinding.isNestedType()) 138 return new ProblemReferenceBinding(name, typeBinding, ProblemReasons.InternalNameProvided); 139 return typeBinding; 140 } 141 148 149 ReferenceBinding getType0(char[] name) { 150 if (knownTypes == null) 151 return null; 152 return knownTypes.get(name); 153 } 154 163 164 public Binding getTypeOrPackage(char[] name) { 165 ReferenceBinding typeBinding = getType0(name); 166 if (typeBinding != null && typeBinding != LookupEnvironment.TheNotFoundType) { 167 typeBinding = BinaryTypeBinding.resolveType(typeBinding, environment, false); if (typeBinding.isNestedType()) 169 return new ProblemReferenceBinding(name, typeBinding, ProblemReasons.InternalNameProvided); 170 return typeBinding; 171 } 172 173 PackageBinding packageBinding = getPackage0(name); 174 if (packageBinding != null && packageBinding != LookupEnvironment.TheNotFoundPackage) 175 return packageBinding; 176 177 if (typeBinding == null) { if ((typeBinding = environment.askForType(this, name)) != null) { 179 if (typeBinding.isNestedType()) 180 return new ProblemReferenceBinding(name, typeBinding, ProblemReasons.InternalNameProvided); 181 return typeBinding; 182 } 183 184 addNotFoundType(name); 187 } 188 189 if (packageBinding == null) { if ((packageBinding = findPackage(name)) != null) 191 return packageBinding; 192 addNotFoundPackage(name); 193 } 194 195 return null; 196 } 197 public char[] readableName() { 198 return CharOperation.concatWith(compoundName, '.'); 199 } 200 public String toString() { 201 if (compoundName == CharOperation.NO_CHAR_CHAR) 202 return "The Default Package"; else 204 return "package " + ((compoundName != null) ? CharOperation.toString(compoundName) : "UNNAMED"); } 206 } 207 | Popular Tags |