1 19 20 package org.openide.src; 21 22 26 public final class Identifier extends Object implements java.io.Serializable { 27 31 public static final int NOT_YET_RESOLVED = 0; 32 35 public static final int RESOLVED = 1; 36 40 public static final int UNRESOLVED = 2; 41 42 43 private String fullName; 44 45 49 private String sourceName; 50 51 54 private int namePos; 55 56 57 private transient Resolver resolver; 58 59 62 private int status; 63 64 static final long serialVersionUID =-2614114568575211024L; 65 66 70 private Identifier(Resolver resolver, String sourceName) { 71 this.fullName = null; 72 this.sourceName = sourceName; 73 this.resolver = resolver; 74 this.status = NOT_YET_RESOLVED; 75 } 76 77 Identifier(String fullName, String sourceName, int status) { 78 if (sourceName == null) 79 throw new IllegalArgumentException (); 80 this.sourceName = sourceName; 81 this.fullName = fullName; 82 this.status = status; 83 } 84 85 86 private void initNamePos() { 87 setFullName(); 88 namePos = fullName.lastIndexOf("."); if (namePos != -1) 90 namePos++; 91 if (fullName.startsWith(".") || fullName.endsWith(".")) throw new IllegalArgumentException (fullName); 93 } 94 95 96 private void setFullName() { 97 if (fullName == null) { 98 fullName = (resolver == null ? sourceName : resolver.resolve().intern()); 99 resolver = null; if (fullName == null) { fullName = sourceName; 102 } 103 } 104 } 105 106 107 private Object readResolve() { 108 if (fullName == null) { 109 return create(sourceName); 111 } else { 112 return create(fullName, sourceName); 113 } 114 } 115 116 121 public static Identifier create (String name) { 122 String n = name.intern(); 123 return new Identifier(null, n); 124 } 125 126 132 public static Identifier create(String fullName, String sourceName) { 133 Identifier ret = new Identifier(null, sourceName.intern()); 134 ret.fullName = fullName.intern(); 135 ret.initNamePos(); 136 return ret; 137 } 138 139 public static Identifier create(String full, String sourceName, 140 int status) { 141 Identifier id = Identifier.create(full, sourceName); 142 id.status = status; 143 return id; 144 } 145 146 151 public static Identifier create(Resolver resolver, String name) { 152 return new Identifier(resolver, name.intern()); 153 } 154 155 158 public String getName () { 159 int pos = sourceName.lastIndexOf("."); return (pos == -1) ? sourceName : sourceName.substring(pos + 1); 161 } 162 163 166 public String getSourceName () { 167 return sourceName; 168 } 169 170 173 public String getQualifier () { 174 if (fullName == null) { 175 initNamePos(); 176 } 177 return (namePos == -1) ? "" : fullName.substring(0, namePos - 1); } 179 180 183 public boolean isQualified () { 184 if (fullName == null) { 185 initNamePos(); 186 } 187 return (namePos != -1); 188 } 189 190 193 public String getFullName () { 194 if (fullName == null) { 195 initNamePos(); 196 } 197 return fullName; 198 } 199 200 209 public int getResolutionStatus() { 210 return this.status; 211 } 212 213 217 public String toString() { 218 return getSourceName(); 219 } 220 221 228 public boolean compareTo(Identifier id, boolean source) { 229 if (fullName == null) { 230 initNamePos(); 231 } 232 if (id.fullName == null) { 233 id.initNamePos(); 234 } 235 if (id.fullName == fullName) { 236 return source ? (id.sourceName == sourceName) : true; 237 } 238 return false; 239 } 240 241 248 public boolean equals(Object o) { 249 return (o instanceof Identifier) ? compareTo((Identifier) o, false) : false; 250 } 251 252 254 public int hashCode() { 255 if (fullName == null) { 256 initNamePos(); 257 } 258 return fullName.hashCode(); 259 } 260 261 262 public static interface Resolver { 263 264 267 String resolve(); 268 } 269 } 270 | Popular Tags |