1 11 package org.eclipse.jdt.internal.core.search.matching; 12 13 import org.eclipse.jdt.core.compiler.CharOperation; 14 import org.eclipse.jdt.core.search.SearchPattern; 15 16 import org.eclipse.jdt.internal.core.util.Util; 17 18 public class FieldPattern extends VariablePattern { 19 20 protected char[] declaringQualification; 22 protected char[] declaringSimpleName; 23 24 protected char[] typeQualification; 26 protected char[] typeSimpleName; 27 28 protected static char[][] REF_CATEGORIES = { REF }; 29 protected static char[][] REF_AND_DECL_CATEGORIES = { REF, FIELD_DECL }; 30 protected static char[][] DECL_CATEGORIES = { FIELD_DECL }; 31 32 public static char[] createIndexKey(char[] fieldName) { 33 return fieldName; 34 } 35 36 public FieldPattern( 37 boolean findDeclarations, 38 boolean readAccess, 39 boolean writeAccess, 40 char[] name, 41 char[] declaringQualification, 42 char[] declaringSimpleName, 43 char[] typeQualification, 44 char[] typeSimpleName, 45 int matchRule) { 46 47 super(FIELD_PATTERN, findDeclarations, readAccess, writeAccess, name, matchRule); 48 49 this.declaringQualification = isCaseSensitive() ? declaringQualification : CharOperation.toLowerCase(declaringQualification); 50 this.declaringSimpleName = isCaseSensitive() ? declaringSimpleName : CharOperation.toLowerCase(declaringSimpleName); 51 this.typeQualification = isCaseSensitive() ? typeQualification : CharOperation.toLowerCase(typeQualification); 52 this.typeSimpleName = (isCaseSensitive() || isCamelCase()) ? typeSimpleName : CharOperation.toLowerCase(typeSimpleName); 53 54 ((InternalSearchPattern)this).mustResolve = mustResolve(); 55 } 56 59 public FieldPattern( 60 boolean findDeclarations, 61 boolean readAccess, 62 boolean writeAccess, 63 char[] name, 64 char[] declaringQualification, 65 char[] declaringSimpleName, 66 char[] typeQualification, 67 char[] typeSimpleName, 68 String typeSignature, 69 int matchRule) { 70 71 this(findDeclarations, readAccess, writeAccess, name, declaringQualification, declaringSimpleName, typeQualification, typeSimpleName, matchRule); 72 73 if (typeSignature != null) { 75 this.typeSignatures = Util.splitTypeLevelsSignature(typeSignature); 76 setTypeArguments(Util.getAllTypeArguments(this.typeSignatures)); 77 } 78 } 79 public void decodeIndexKey(char[] key) { 80 this.name = key; 81 } 82 public SearchPattern getBlankPattern() { 83 return new FieldPattern(false, false, false, null, null, null, null, null, R_EXACT_MATCH | R_CASE_SENSITIVE); 84 } 85 public char[] getIndexKey() { 86 return this.name; 87 } 88 public char[][] getIndexCategories() { 89 if (this.findReferences) 90 return this.findDeclarations || this.writeAccess ? REF_AND_DECL_CATEGORIES : REF_CATEGORIES; 91 if (this.findDeclarations) 92 return DECL_CATEGORIES; 93 return CharOperation.NO_CHAR_CHAR; 94 } 95 public boolean matchesDecodedKey(SearchPattern decodedPattern) { 96 return true; } 98 protected boolean mustResolve() { 99 if (this.declaringSimpleName != null || this.declaringQualification != null) return true; 100 if (this.typeSimpleName != null || this.typeQualification != null) return true; 101 102 return super.mustResolve(); 103 } 104 protected StringBuffer print(StringBuffer output) { 105 if (this.findDeclarations) { 106 output.append(this.findReferences 107 ? "FieldCombinedPattern: " : "FieldDeclarationPattern: "); } else { 110 output.append("FieldReferencePattern: "); } 112 if (declaringQualification != null) output.append(declaringQualification).append('.'); 113 if (declaringSimpleName != null) 114 output.append(declaringSimpleName).append('.'); 115 else if (declaringQualification != null) output.append("*."); if (name == null) { 117 output.append("*"); } else { 119 output.append(name); 120 } 121 if (typeQualification != null) 122 output.append(" --> ").append(typeQualification).append('.'); else if (typeSimpleName != null) output.append(" --> "); if (typeSimpleName != null) 125 output.append(typeSimpleName); 126 else if (typeQualification != null) output.append("*"); return super.print(output); 128 } 129 } 130 | Popular Tags |