KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.*;
15 import org.eclipse.jdt.internal.core.search.indexing.IIndexConstants;
16
17 public class QualifiedTypeDeclarationPattern extends TypeDeclarationPattern implements IIndexConstants {
18
19 public char[] qualification;
20 PackageDeclarationPattern packagePattern;
21 public int packageIndex = -1;
22
23 public QualifiedTypeDeclarationPattern(char[] qualification, char[] simpleName, char typeSuffix, int matchRule) {
24     this(matchRule);
25
26     this.qualification = isCaseSensitive() ? qualification : CharOperation.toLowerCase(qualification);
27     this.simpleName = (isCaseSensitive() || isCamelCase()) ? simpleName : CharOperation.toLowerCase(simpleName);
28     this.typeSuffix = typeSuffix;
29
30     ((InternalSearchPattern)this).mustResolve = this.qualification != null || typeSuffix != TYPE_SUFFIX;
31 }
32 public QualifiedTypeDeclarationPattern(char[] qualification, int qualificationMatchRule, char[] simpleName, char typeSuffix, int matchRule) {
33     this(qualification, simpleName, typeSuffix, matchRule);
34     this.packagePattern = new PackageDeclarationPattern(qualification, qualificationMatchRule);
35 }
36 QualifiedTypeDeclarationPattern(int matchRule) {
37     super(matchRule);
38 }
39 public void decodeIndexKey(char[] key) {
40     int slash = CharOperation.indexOf(SEPARATOR, key, 0);
41     this.simpleName = CharOperation.subarray(key, 0, slash);
42
43     int start = ++slash;
44     if (key[start] == SEPARATOR) {
45         this.pkg = CharOperation.NO_CHAR;
46     } else {
47         slash = CharOperation.indexOf(SEPARATOR, key, start);
48         this.pkg = internedPackageNames.add(CharOperation.subarray(key, start, slash));
49     }
50     this.qualification = this.pkg;
51
52     // Continue key read by the end to decode modifiers
53
int last = key.length-1;
54     this.secondary = key[last] == 'S';
55     if (this.secondary) {
56         last -= 2;
57     }
58     this.modifiers = key[last-1] + (key[last]<<16);
59     decodeModifiers();
60
61     // Retrieve enclosing type names
62
start = slash + 1;
63     last -= 2; // position of ending slash
64
if (start == last) {
65         this.enclosingTypeNames = CharOperation.NO_CHAR_CHAR;
66     } else {
67         int length = this.qualification.length;
68         int size = last - start;
69         System.arraycopy(this.qualification, 0, this.qualification = new char[length+1+size], 0, length);
70         this.qualification[length] = '.';
71         if (last == (start+1) && key[start] == ZERO_CHAR) {
72             this.enclosingTypeNames = ONE_ZERO_CHAR;
73             this.qualification[length+1] = ZERO_CHAR;
74         } else {
75             this.enclosingTypeNames = CharOperation.splitOn('.', key, start, last);
76             System.arraycopy(key, start, this.qualification, length+1, size);
77         }
78     }
79 }
80 public SearchPattern getBlankPattern() {
81     return new QualifiedTypeDeclarationPattern(R_EXACT_MATCH | R_CASE_SENSITIVE);
82 }
83 public boolean matchesDecodedKey(SearchPattern decodedPattern) {
84     QualifiedTypeDeclarationPattern pattern = (QualifiedTypeDeclarationPattern) decodedPattern;
85     
86     // check type suffix
87
if (this.typeSuffix != pattern.typeSuffix && typeSuffix != TYPE_SUFFIX) {
88         if (!matchDifferentTypeSuffixes(this.typeSuffix, pattern.typeSuffix)) {
89             return false;
90         }
91     }
92
93     // check name
94
return matchesName(this.simpleName, pattern.simpleName) &&
95         (this.qualification == null || this.packagePattern == null || this.packagePattern.matchesName(this.qualification, pattern.qualification));
96 }
97 protected StringBuffer JavaDoc print(StringBuffer JavaDoc output) {
98     switch (this.typeSuffix){
99         case CLASS_SUFFIX :
100             output.append("ClassDeclarationPattern: qualification<"); //$NON-NLS-1$
101
break;
102         case CLASS_AND_INTERFACE_SUFFIX:
103             output.append("ClassAndInterfaceDeclarationPattern: qualification<"); //$NON-NLS-1$
104
break;
105         case CLASS_AND_ENUM_SUFFIX :
106             output.append("ClassAndEnumDeclarationPattern: qualification<"); //$NON-NLS-1$
107
break;
108         case INTERFACE_SUFFIX :
109             output.append("InterfaceDeclarationPattern: qualification<"); //$NON-NLS-1$
110
break;
111         case INTERFACE_AND_ANNOTATION_SUFFIX:
112             output.append("InterfaceAndAnnotationDeclarationPattern: qualification<"); //$NON-NLS-1$
113
break;
114         case ENUM_SUFFIX :
115             output.append("EnumDeclarationPattern: qualification<"); //$NON-NLS-1$
116
break;
117         case ANNOTATION_TYPE_SUFFIX :
118             output.append("AnnotationTypeDeclarationPattern: qualification<"); //$NON-NLS-1$
119
break;
120         default :
121             output.append("TypeDeclarationPattern: qualification<"); //$NON-NLS-1$
122
break;
123     }
124     if (this.qualification != null)
125         output.append(this.qualification);
126     else
127         output.append("*"); //$NON-NLS-1$
128
output.append(">, type<"); //$NON-NLS-1$
129
if (simpleName != null)
130         output.append(simpleName);
131     else
132         output.append("*"); //$NON-NLS-1$
133
output.append("> "); //$NON-NLS-1$
134
return super.print(output);
135 }
136 }
137
Popular Tags