| 1 11 package org.eclipse.jdt.internal.core.search.matching; 12 13 import java.io.IOException ; 14 15 import org.eclipse.jdt.core.compiler.*; 16 import org.eclipse.jdt.core.search.*; 17 import org.eclipse.jdt.internal.core.index.*; 18 19 public class SuperTypeReferencePattern extends JavaSearchPattern { 20 21 public char[] superQualification; 22 public char[] superSimpleName; 23 public char superClassOrInterface; 24 25 public char typeSuffix; 29 public char[] pkgName; 30 public char[] simpleName; 31 public char[] enclosingTypeName; 32 public char classOrInterface; 33 public int modifiers; 34 public char[][] typeParameterSignatures; 35 36 protected int superRefKind; 37 public static final int ALL_SUPER_TYPES = 0; 38 public static final int ONLY_SUPER_INTERFACES = 1; public static final int ONLY_SUPER_CLASSES = 2; 41 protected static char[][] CATEGORIES = { SUPER_REF }; 42 43 public static char[] createIndexKey( 44 int modifiers, 45 char[] packageName, 46 char[] typeName, 47 char[][] enclosingTypeNames, 48 char[][] typeParameterSignatures, 49 char classOrInterface, 50 char[] superTypeName, 51 char superClassOrInterface) { 52 53 if (superTypeName == null) 54 superTypeName = OBJECT; 55 char[] superSimpleName = CharOperation.lastSegment(superTypeName, '.'); 56 char[] superQualification = null; 57 if (superSimpleName != superTypeName) { 58 int length = superTypeName.length - superSimpleName.length - 1; 59 superQualification = new char[length]; 60 System.arraycopy(superTypeName, 0, superQualification, 0, length); 61 } 62 63 char[] superTypeSourceName = CharOperation.lastSegment(superSimpleName, '$'); 66 if (superTypeSourceName != superSimpleName) { 67 int start = superQualification == null ? 0 : superQualification.length + 1; 68 int prefixLength = superSimpleName.length - superTypeSourceName.length; 69 char[] mangledQualification = new char[start + prefixLength]; 70 if (superQualification != null) { 71 System.arraycopy(superQualification, 0, mangledQualification, 0, start-1); 72 mangledQualification[start-1] = '.'; 73 } 74 System.arraycopy(superSimpleName, 0, mangledQualification, start, prefixLength); 75 superQualification = mangledQualification; 76 superSimpleName = superTypeSourceName; 77 } 78 79 char[] simpleName = CharOperation.lastSegment(typeName, '.'); 80 char[] enclosingTypeName = CharOperation.concatWith(enclosingTypeNames, '$'); 81 if (superQualification != null && CharOperation.equals(superQualification, packageName)) 82 packageName = ONE_ZERO; 84 char[] typeParameters = CharOperation.NO_CHAR; 85 int typeParametersLength = 0; 86 if (typeParameterSignatures != null) { 87 StringBuffer buffer = new StringBuffer (); 88 for (int i = 0, length = typeParameterSignatures.length; i < length; i++) { 89 char[] typeParameter = typeParameterSignatures[i]; 90 buffer.append(typeParameter); 91 typeParametersLength += typeParameter.length; 92 if (i != length-1) { 93 buffer.append(','); 94 typeParametersLength++; 95 } 96 } 97 typeParameters = new char[typeParametersLength]; 98 buffer.getChars(0, typeParametersLength, typeParameters, 0); 99 } 100 101 int superLength = superSimpleName == null ? 0 : superSimpleName.length; 103 int superQLength = superQualification == null ? 0 : superQualification.length; 104 int simpleLength = simpleName == null ? 0 : simpleName.length; 105 int enclosingLength = enclosingTypeName == null ? 0 : enclosingTypeName.length; 106 int packageLength = packageName == null ? 0 : packageName.length; 107 char[] result = new char[superLength + superQLength + simpleLength + enclosingLength + typeParametersLength + packageLength + 9]; 108 int pos = 0; 109 if (superLength > 0) { 110 System.arraycopy(superSimpleName, 0, result, pos, superLength); 111 pos += superLength; 112 } 113 result[pos++] = SEPARATOR; 114 if (superQLength > 0) { 115 System.arraycopy(superQualification, 0, result, pos, superQLength); 116 pos += superQLength; 117 } 118 result[pos++] = SEPARATOR; 119 if (simpleLength > 0) { 120 System.arraycopy(simpleName, 0, result, pos, simpleLength); 121 pos += simpleLength; 122 } 123 result[pos++] = SEPARATOR; 124 if (enclosingLength > 0) { 125 System.arraycopy(enclosingTypeName, 0, result, pos, enclosingLength); 126 pos += enclosingLength; 127 } 128 result[pos++] = SEPARATOR; 129 if (typeParametersLength > 0) { 130 System.arraycopy(typeParameters, 0, result, pos, typeParametersLength); 131 pos += typeParametersLength; 132 } 133 result[pos++] = SEPARATOR; 134 if (packageLength > 0) { 135 System.arraycopy(packageName, 0, result, pos, packageLength); 136 pos += packageLength; 137 } 138 result[pos++] = SEPARATOR; 139 result[pos++] = superClassOrInterface; 140 result[pos++] = classOrInterface; 141 result[pos] = (char) modifiers; 142 return result; 143 } 144 145 public SuperTypeReferencePattern( 146 char[] superQualification, 147 char[] superSimpleName, 148 int superRefKind, 149 int matchRule) { 150 151 this(matchRule); 152 153 this.superQualification = isCaseSensitive() ? superQualification : CharOperation.toLowerCase(superQualification); 154 this.superSimpleName = (isCaseSensitive() || isCamelCase()) ? superSimpleName : CharOperation.toLowerCase(superSimpleName); 155 ((InternalSearchPattern)this).mustResolve = superQualification != null; 156 this.superRefKind = superRefKind; 157 } 158 public SuperTypeReferencePattern( 159 char[] superQualification, 160 char[] superSimpleName, 161 int superRefKind, 162 char typeSuffix, 163 int matchRule) { 164 165 this(superQualification, superSimpleName, superRefKind, matchRule); 166 this.typeSuffix = typeSuffix; 167 ((InternalSearchPattern)this).mustResolve = superQualification != null || typeSuffix != TYPE_SUFFIX; 168 } 169 SuperTypeReferencePattern(int matchRule) { 170 super(SUPER_REF_PATTERN, matchRule); 171 } 172 175 public void decodeIndexKey(char[] key) { 176 int slash = CharOperation.indexOf(SEPARATOR, key, 0); 177 this.superSimpleName = CharOperation.subarray(key, 0, slash); 178 179 int start = slash + 1; 181 slash = CharOperation.indexOf(SEPARATOR, key, start); 182 this.superQualification = slash == start ? null : CharOperation.subarray(key, start, slash); 183 184 slash = CharOperation.indexOf(SEPARATOR, key, start = slash + 1); 185 this.simpleName = CharOperation.subarray(key, start, slash); 186 187 start = ++slash; 188 if (key[start] == SEPARATOR) { 189 this.enclosingTypeName = null; 190 } else { 191 slash = CharOperation.indexOf(SEPARATOR, key, start); 192 if (slash == (start+1) && key[start] == ZERO_CHAR) { 193 this.enclosingTypeName = ONE_ZERO; 194 } else { 195 char[] names = CharOperation.subarray(key, start, slash); 196 this.enclosingTypeName = names; 197 } 198 } 199 200 start = ++slash; 201 if (key[start] == SEPARATOR) { 202 this.typeParameterSignatures = null; 203 } else { 204 slash = CharOperation.indexOf(SEPARATOR, key, start); 205 this.typeParameterSignatures = CharOperation.splitOn(',', key, start, slash); 206 } 207 208 start = ++slash; 209 if (key[start] == SEPARATOR) { 210 this.pkgName = null; 211 } else { 212 slash = CharOperation.indexOf(SEPARATOR, key, start); 213 if (slash == (start+1) && key[start] == ZERO_CHAR) { 214 this.pkgName = this.superQualification; 215 } else { 216 char[] names = CharOperation.subarray(key, start, slash); 217 this.pkgName = names; 218 } 219 } 220 221 this.superClassOrInterface = key[slash + 1]; 222 this.classOrInterface = key[slash + 2]; 223 this.modifiers = key[slash + 3]; } 225 public SearchPattern getBlankPattern() { 226 return new SuperTypeReferencePattern(R_EXACT_MATCH | R_CASE_SENSITIVE); 227 } 228 public char[][] getIndexCategories() { 229 return CATEGORIES; 230 } 231 public boolean matchesDecodedKey(SearchPattern decodedPattern) { 232 SuperTypeReferencePattern pattern = (SuperTypeReferencePattern) decodedPattern; 233 if (this.superRefKind == ONLY_SUPER_CLASSES && pattern.enclosingTypeName != ONE_ZERO) 234 if (pattern.superClassOrInterface == INTERFACE_SUFFIX 236 || pattern.superClassOrInterface == ANNOTATION_TYPE_SUFFIX) 237 return false; 238 239 if (pattern.superQualification != null) 240 if (!matchesName(this.superQualification, pattern.superQualification)) return false; 241 242 return matchesName(this.superSimpleName, pattern.superSimpleName); 243 } 244 EntryResult[] queryIn(Index index) throws IOException { 245 char[] key = this.superSimpleName; int matchRule = getMatchRule(); 247 248 switch(getMatchMode()) { 250 case R_EXACT_MATCH : 251 if (this.isCamelCase) break; 252 matchRule &= ~R_EXACT_MATCH; 254 matchRule |= R_PREFIX_MATCH; 255 if (this.superSimpleName != null) 256 key = CharOperation.append(this.superSimpleName, SEPARATOR); 257 break; 258 case R_PREFIX_MATCH : 259 break; 261 case R_PATTERN_MATCH : 262 break; 264 case R_REGEXP_MATCH : 265 break; 267 } 268 269 return index.query(getIndexCategories(), key, matchRule); } 271 protected StringBuffer print(StringBuffer output) { 272 switch (this.superRefKind) { 273 case ALL_SUPER_TYPES: 274 output.append("SuperTypeReferencePattern: <"); break; 276 case ONLY_SUPER_INTERFACES: 277 output.append("SuperInterfaceReferencePattern: <"); break; 279 case ONLY_SUPER_CLASSES: 280 output.append("SuperClassReferencePattern: <"); break; 282 } 283 if (superSimpleName != null) 284 output.append(superSimpleName); 285 else 286 output.append("*"); output.append(">"); return super.print(output); 289 } 290 } 291 | Popular Tags |