001: /*******************************************************************************
002: * Copyright (c) 2000, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jdt.internal.core.search.matching;
011:
012: import org.eclipse.jdt.core.compiler.CharOperation;
013: import org.eclipse.jdt.core.search.SearchPattern;
014:
015: import org.eclipse.jdt.internal.core.util.Util;
016:
017: public class FieldPattern extends VariablePattern {
018:
019: // declaring type
020: protected char[] declaringQualification;
021: protected char[] declaringSimpleName;
022:
023: // type
024: protected char[] typeQualification;
025: protected char[] typeSimpleName;
026:
027: protected static char[][] REF_CATEGORIES = { REF };
028: protected static char[][] REF_AND_DECL_CATEGORIES = { REF,
029: FIELD_DECL };
030: protected static char[][] DECL_CATEGORIES = { FIELD_DECL };
031:
032: public static char[] createIndexKey(char[] fieldName) {
033: return fieldName;
034: }
035:
036: public FieldPattern(boolean findDeclarations, boolean readAccess,
037: boolean writeAccess, char[] name,
038: char[] declaringQualification, char[] declaringSimpleName,
039: char[] typeQualification, char[] typeSimpleName,
040: int matchRule) {
041:
042: super (FIELD_PATTERN, findDeclarations, readAccess, writeAccess,
043: name, matchRule);
044:
045: this .declaringQualification = this .isCaseSensitive ? declaringQualification
046: : CharOperation.toLowerCase(declaringQualification);
047: this .declaringSimpleName = this .isCaseSensitive ? declaringSimpleName
048: : CharOperation.toLowerCase(declaringSimpleName);
049: this .typeQualification = this .isCaseSensitive ? typeQualification
050: : CharOperation.toLowerCase(typeQualification);
051: this .typeSimpleName = (this .isCaseSensitive || this .isCamelCase) ? typeSimpleName
052: : CharOperation.toLowerCase(typeSimpleName);
053:
054: ((InternalSearchPattern) this ).mustResolve = mustResolve();
055: }
056:
057: /*
058: * Instantiate a field pattern with additional information for generic search
059: */
060: public FieldPattern(boolean findDeclarations, boolean readAccess,
061: boolean writeAccess, char[] name,
062: char[] declaringQualification, char[] declaringSimpleName,
063: char[] typeQualification, char[] typeSimpleName,
064: String typeSignature, int matchRule) {
065:
066: this (findDeclarations, readAccess, writeAccess, name,
067: declaringQualification, declaringSimpleName,
068: typeQualification, typeSimpleName, matchRule);
069:
070: // store type signatures and arguments
071: if (typeSignature != null) {
072: this .typeSignatures = Util
073: .splitTypeLevelsSignature(typeSignature);
074: setTypeArguments(Util
075: .getAllTypeArguments(this .typeSignatures));
076: }
077: }
078:
079: public void decodeIndexKey(char[] key) {
080: this .name = key;
081: }
082:
083: public SearchPattern getBlankPattern() {
084: return new FieldPattern(false, false, false, null, null, null,
085: null, null, R_EXACT_MATCH | R_CASE_SENSITIVE);
086: }
087:
088: public char[] getIndexKey() {
089: return this .name;
090: }
091:
092: public char[][] getIndexCategories() {
093: if (this .findReferences)
094: return this .findDeclarations || this .writeAccess ? REF_AND_DECL_CATEGORIES
095: : REF_CATEGORIES;
096: if (this .findDeclarations)
097: return DECL_CATEGORIES;
098: return CharOperation.NO_CHAR_CHAR;
099: }
100:
101: public boolean matchesDecodedKey(SearchPattern decodedPattern) {
102: return true; // index key is not encoded so query results all match
103: }
104:
105: protected boolean mustResolve() {
106: if (this .declaringSimpleName != null
107: || this .declaringQualification != null)
108: return true;
109: if (this .typeSimpleName != null
110: || this .typeQualification != null)
111: return true;
112:
113: return super .mustResolve();
114: }
115:
116: protected StringBuffer print(StringBuffer output) {
117: if (this .findDeclarations) {
118: output
119: .append(this .findReferences ? "FieldCombinedPattern: " //$NON-NLS-1$
120: : "FieldDeclarationPattern: "); //$NON-NLS-1$
121: } else {
122: output.append("FieldReferencePattern: "); //$NON-NLS-1$
123: }
124: if (declaringQualification != null)
125: output.append(declaringQualification).append('.');
126: if (declaringSimpleName != null)
127: output.append(declaringSimpleName).append('.');
128: else if (declaringQualification != null)
129: output.append("*."); //$NON-NLS-1$
130: if (name == null) {
131: output.append("*"); //$NON-NLS-1$
132: } else {
133: output.append(name);
134: }
135: if (typeQualification != null)
136: output
137: .append(" --> ").append(typeQualification).append('.'); //$NON-NLS-1$
138: else if (typeSimpleName != null)
139: output.append(" --> "); //$NON-NLS-1$
140: if (typeSimpleName != null)
141: output.append(typeSimpleName);
142: else if (typeQualification != null)
143: output.append("*"); //$NON-NLS-1$
144: return super.print(output);
145: }
146: }
|