1 11 package org.eclipse.jdt.core; 12 13 import org.eclipse.jdt.internal.core.util.KeyKind; 14 import org.eclipse.jdt.internal.core.util.KeyToSignature; 15 16 25 public final class BindingKey { 26 27 private String key; 28 29 34 public BindingKey(String key) { 35 this.key = key; 36 } 37 38 54 public static String createArrayTypeBindingKey(String typeKey, int arrayDimension) { 55 StringBuffer buffer = new StringBuffer (); 57 while (arrayDimension-- > 0) 58 buffer.append('['); 59 buffer.append(typeKey); 60 return buffer.toString(); 61 } 62 63 85 public static String createParameterizedTypeBindingKey(String genericTypeKey, String [] argumentTypeKeys) { 86 StringBuffer buffer = new StringBuffer (); 88 buffer.append(Signature.getTypeErasure(genericTypeKey)); 89 buffer.insert(buffer.length()-1, '<'); 90 for (int i = 0, length = argumentTypeKeys.length; i < length; i++) { 91 String argumentTypeKey = argumentTypeKeys[i]; 92 buffer.insert(buffer.length()-1, argumentTypeKey); 93 } 94 buffer.insert(buffer.length()-1, '>'); 95 return buffer.toString(); 96 } 97 98 117 public static String createTypeBindingKey(String typeName) { 118 return Signature.createTypeSignature(typeName.replace('.', '/'), true); 120 } 121 122 141 public static String createTypeVariableBindingKey(String typeVariableName, String declaringKey) { 142 StringBuffer buffer = new StringBuffer (); 144 buffer.append(declaringKey); 145 buffer.append(':'); 146 buffer.append('T'); 147 buffer.append(typeVariableName); 148 buffer.append(';'); 149 return buffer.toString(); 150 } 151 152 173 public static String createWilcardTypeBindingKey(String typeKey, char kind) { 174 switch (kind) { 176 case Signature.C_STAR: 177 return "*"; case Signature.C_SUPER: 179 return '-' + typeKey; 180 case Signature.C_EXTENDS: 181 return '+' + typeKey; 182 } 183 return null; 184 } 185 186 194 public String [] getThrownExceptions() { 195 KeyToSignature keyToSignature = new KeyToSignature(this.key, KeyToSignature.THROWN_EXCEPTIONS); 196 keyToSignature.parse(); 197 return keyToSignature.getThrownExceptions(); 198 } 199 200 207 public String [] getTypeArguments() { 208 KeyToSignature keyToSignature = new KeyToSignature(this.key, KeyToSignature.TYPE_ARGUMENTS); 209 keyToSignature.parse(); 210 return keyToSignature.getTypeArguments(); 211 } 212 213 218 public boolean isRawType() { 219 KeyKind kind = new KeyKind(this.key); 220 kind.parse(); 221 return (kind.flags & KeyKind.F_RAW_TYPE) != 0; 222 } 223 224 229 public boolean isParameterizedType() { 230 KeyKind kind = new KeyKind(this.key); 231 kind.parse(); 232 return (kind.flags & KeyKind.F_PARAMETERIZED_TYPE) != 0; 233 } 234 235 240 public boolean isParameterizedMethod() { 241 KeyKind kind = new KeyKind(this.key); 242 kind.parse(); 243 return (kind.flags & KeyKind.F_PARAMETERIZED_METHOD) != 0; 244 } 245 246 255 public String toSignature() { 256 KeyToSignature keyToSignature = new KeyToSignature(this.key, KeyToSignature.SIGNATURE); 257 keyToSignature.parse(); 258 return keyToSignature.signature.toString(); 259 } 260 261 264 public String toString() { 265 return this.key; 266 } 267 } 268 | Popular Tags |