KickJava   Java API By Example, From Geeks To Geeks.

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


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.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     /* Optimization: case where simpleName == null */
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; // always resolve (in case of a simple name reference being a potential match)
52
}
53     /*
54      * Instanciate a type reference pattern with additional information for generics search
55      */

56     public TypeReferencePattern(char[] qualification, char[] simpleName, String JavaDoc typeSignature, int matchRule) {
57         this(qualification, simpleName,matchRule);
58         if (typeSignature != null) {
59             // store type signatures and arguments
60
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     /*
68      * Instanciate a type reference pattern with additional information for generics search
69      */

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         // Optimization, eg. type reference is 'org.eclipse.jdt.core.*'
88
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         // Optimization, eg. type reference is 'org.eclipse.jdt.core.*'
99
// if package has at least 4 segments, don't look at the first 2 since they are mostly
100
// redundant (eg. in 'org.eclipse.jdt.core.*' 'org.eclipse' is used all the time)
101
return --this.currentSegment >= (this.segments.length >= 4 ? 2 : 0);
102     }
103
104     public boolean matchesDecodedKey(SearchPattern decodedPattern) {
105         return true; // index key is not encoded so query results all match
106
}
107
108     protected void resetQuery() {
109         /* walk the segments from end to start as it will find less potential references using 'lang' than 'java' */
110         if (this.segments != null)
111             this.currentSegment = this.segments.length - 1;
112     }
113     protected StringBuffer JavaDoc print(StringBuffer JavaDoc output) {
114         output.append("TypeReferencePattern: qualification<"); //$NON-NLS-1$
115
if (qualification != null)
116             output.append(qualification);
117         else
118             output.append("*"); //$NON-NLS-1$
119
output.append(">, type<"); //$NON-NLS-1$
120
if (simpleName != null)
121             output.append(simpleName);
122         else
123             output.append("*"); //$NON-NLS-1$
124
output.append(">"); //$NON-NLS-1$
125
return super.print(output);
126     }
127 }
128
Popular Tags