KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > core > search > matching > FieldPattern


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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 // declaring type
21
protected char[] declaringQualification;
22 protected char[] declaringSimpleName;
23
24 // type
25
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 /*
57  * Instanciate a field pattern with additional information for generics search
58  */

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 JavaDoc typeSignature,
69     int matchRule) {
70
71     this(findDeclarations, readAccess, writeAccess, name, declaringQualification, declaringSimpleName, typeQualification, typeSimpleName, matchRule);
72
73     // store type signatures and arguments
74
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; // index key is not encoded so query results all match
97
}
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 JavaDoc print(StringBuffer JavaDoc output) {
105     if (this.findDeclarations) {
106         output.append(this.findReferences
107             ? "FieldCombinedPattern: " //$NON-NLS-1$
108
: "FieldDeclarationPattern: "); //$NON-NLS-1$
109
} else {
110         output.append("FieldReferencePattern: "); //$NON-NLS-1$
111
}
112     if (declaringQualification != null) output.append(declaringQualification).append('.');
113     if (declaringSimpleName != null)
114         output.append(declaringSimpleName).append('.');
115     else if (declaringQualification != null) output.append("*."); //$NON-NLS-1$
116
if (name == null) {
117         output.append("*"); //$NON-NLS-1$
118
} else {
119         output.append(name);
120     }
121     if (typeQualification != null)
122         output.append(" --> ").append(typeQualification).append('.'); //$NON-NLS-1$
123
else if (typeSimpleName != null) output.append(" --> "); //$NON-NLS-1$
124
if (typeSimpleName != null)
125         output.append(typeSimpleName);
126     else if (typeQualification != null) output.append("*"); //$NON-NLS-1$
127
return super.print(output);
128 }
129 }
130
Popular Tags