1 11 package org.eclipse.jdt.internal.core.search.matching; 12 13 import org.eclipse.jdt.core.IType; 14 import org.eclipse.jdt.core.compiler.CharOperation; 15 import org.eclipse.jdt.core.search.SearchPattern; 16 import org.eclipse.jdt.internal.core.util.Util; 17 18 public class TypeReferencePattern extends AndPattern { 19 20 protected char[] qualification; 21 protected char[] simpleName; 22 23 protected char[] currentCategory; 24 25 26 public int segmentsSize; 27 protected char[][] segments; 28 protected int currentSegment; 29 30 protected static char[][] CATEGORIES = { REF }; 31 32 public TypeReferencePattern(char[] qualification, char[] simpleName, int matchRule) { 33 this(matchRule); 34 35 this.qualification = isCaseSensitive() ? qualification : CharOperation.toLowerCase(qualification); 36 this.simpleName = (isCaseSensitive() || isCamelCase()) ? simpleName : CharOperation.toLowerCase(simpleName); 37 38 if (simpleName == null) 39 this.segments = this.qualification == null ? ONE_STAR_CHAR : CharOperation.splitOn('.', this.qualification); 40 else 41 this.segments = null; 42 43 if (this.segments == null) 44 if (this.qualification == null) 45 this.segmentsSize = 0; 46 else 47 this.segmentsSize = CharOperation.occurencesOf('.', this.qualification) + 1; 48 else 49 this.segmentsSize = this.segments.length; 50 51 ((InternalSearchPattern)this).mustResolve = true; } 53 56 public TypeReferencePattern(char[] qualification, char[] simpleName, String typeSignature, int matchRule) { 57 this(qualification, simpleName,matchRule); 58 if (typeSignature != null) { 59 this.typeSignatures = Util.splitTypeLevelsSignature(typeSignature); 61 setTypeArguments(Util.getAllTypeArguments(this.typeSignatures)); 62 if (hasTypeArguments()) { 63 this.segmentsSize = getTypeArguments().length + CharOperation.occurencesOf('/', this.typeSignatures[0]) - 1; 64 } 65 } 66 } 67 70 public TypeReferencePattern(char[] qualification, char[] simpleName, IType type, int matchRule) { 71 this(qualification, simpleName,matchRule); 72 storeTypeSignaturesAndArguments(type); 73 } 74 TypeReferencePattern(int matchRule) { 75 super(TYPE_REF_PATTERN, matchRule); 76 } 77 public void decodeIndexKey(char[] key) { 78 this.simpleName = key; 79 } 80 public SearchPattern getBlankPattern() { 81 return new TypeReferencePattern(R_EXACT_MATCH | R_CASE_SENSITIVE); 82 } 83 public char[] getIndexKey() { 84 if (this.simpleName != null) 85 return this.simpleName; 86 87 if (this.currentSegment >= 0) 89 return this.segments[this.currentSegment]; 90 return null; 91 } 92 public char[][] getIndexCategories() { 93 return CATEGORIES; 94 } 95 protected boolean hasNextQuery() { 96 if (this.segments == null) return false; 97 98 return --this.currentSegment >= (this.segments.length >= 4 ? 2 : 0); 102 } 103 104 public boolean matchesDecodedKey(SearchPattern decodedPattern) { 105 return true; } 107 108 protected void resetQuery() { 109 110 if (this.segments != null) 111 this.currentSegment = this.segments.length - 1; 112 } 113 protected StringBuffer print(StringBuffer output) { 114 output.append("TypeReferencePattern: qualification<"); if (qualification != null) 116 output.append(qualification); 117 else 118 output.append("*"); output.append(">, type<"); if (simpleName != null) 121 output.append(simpleName); 122 else 123 output.append("*"); output.append(">"); return super.print(output); 126 } 127 } 128 | Popular Tags |