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.indexing;
011:
012: import org.eclipse.jdt.core.Signature;
013: import org.eclipse.jdt.core.compiler.CharOperation;
014: import org.eclipse.jdt.core.search.SearchDocument;
015: import org.eclipse.jdt.internal.compiler.lookup.TypeConstants;
016: import org.eclipse.jdt.internal.core.JavaModelManager;
017: import org.eclipse.jdt.internal.core.search.matching.*;
018:
019: public abstract class AbstractIndexer implements IIndexConstants {
020:
021: SearchDocument document;
022:
023: public AbstractIndexer(SearchDocument document) {
024: this .document = document;
025: }
026:
027: public void addAnnotationTypeDeclaration(int modifiers,
028: char[] packageName, char[] name,
029: char[][] enclosingTypeNames, boolean secondary) {
030: addTypeDeclaration(modifiers, packageName, name,
031: enclosingTypeNames, secondary);
032:
033: addIndexEntry(
034: SUPER_REF,
035: SuperTypeReferencePattern
036: .createIndexKey(
037: modifiers,
038: packageName,
039: name,
040: enclosingTypeNames,
041: null,
042: ANNOTATION_TYPE_SUFFIX,
043: CharOperation
044: .concatWith(
045: TypeConstants.JAVA_LANG_ANNOTATION_ANNOTATION,
046: '.'),
047: ANNOTATION_TYPE_SUFFIX));
048: }
049:
050: public void addClassDeclaration(int modifiers, char[] packageName,
051: char[] name, char[][] enclosingTypeNames,
052: char[] super class, char[][] super interfaces,
053: char[][] typeParameterSignatures, boolean secondary) {
054: addTypeDeclaration(modifiers, packageName, name,
055: enclosingTypeNames, secondary);
056:
057: if (super class != null) {
058: super class = erasure(super class);
059: addTypeReference(super class);
060: }
061: addIndexEntry(SUPER_REF, SuperTypeReferencePattern
062: .createIndexKey(modifiers, packageName, name,
063: enclosingTypeNames, typeParameterSignatures,
064: CLASS_SUFFIX, super class, CLASS_SUFFIX));
065: if (super interfaces != null) {
066: for (int i = 0, max = super interfaces.length; i < max; i++) {
067: char[] super interface = erasure(super interfaces[i]);
068: addTypeReference(super interface);
069: addIndexEntry(SUPER_REF, SuperTypeReferencePattern
070: .createIndexKey(modifiers, packageName, name,
071: enclosingTypeNames,
072: typeParameterSignatures, CLASS_SUFFIX,
073: super interface, INTERFACE_SUFFIX));
074: }
075: }
076: }
077:
078: private char[] erasure(char[] typeName) {
079: int genericStart = CharOperation.indexOf(
080: Signature.C_GENERIC_START, typeName);
081: if (genericStart > -1)
082: typeName = CharOperation
083: .subarray(typeName, 0, genericStart);
084: return typeName;
085: }
086:
087: public void addConstructorDeclaration(char[] typeName,
088: char[][] parameterTypes, char[][] exceptionTypes) {
089: int argCount = parameterTypes == null ? 0
090: : parameterTypes.length;
091: addIndexEntry(CONSTRUCTOR_DECL, ConstructorPattern
092: .createIndexKey(CharOperation
093: .lastSegment(typeName, '.'), argCount));
094:
095: if (parameterTypes != null) {
096: for (int i = 0; i < argCount; i++)
097: addTypeReference(parameterTypes[i]);
098: }
099: if (exceptionTypes != null)
100: for (int i = 0, max = exceptionTypes.length; i < max; i++)
101: addTypeReference(exceptionTypes[i]);
102: }
103:
104: public void addConstructorReference(char[] typeName, int argCount) {
105: char[] simpleTypeName = CharOperation
106: .lastSegment(typeName, '.');
107: addTypeReference(simpleTypeName);
108: addIndexEntry(CONSTRUCTOR_REF, ConstructorPattern
109: .createIndexKey(simpleTypeName, argCount));
110: char[] innermostTypeName = CharOperation.lastSegment(
111: simpleTypeName, '$');
112: if (innermostTypeName != simpleTypeName)
113: addIndexEntry(CONSTRUCTOR_REF, ConstructorPattern
114: .createIndexKey(innermostTypeName, argCount));
115: }
116:
117: public void addEnumDeclaration(int modifiers, char[] packageName,
118: char[] name, char[][] enclosingTypeNames,
119: char[] super class, char[][] super interfaces,
120: boolean secondary) {
121: addTypeDeclaration(modifiers, packageName, name,
122: enclosingTypeNames, secondary);
123:
124: addIndexEntry(SUPER_REF, SuperTypeReferencePattern
125: .createIndexKey(modifiers, packageName, name,
126: enclosingTypeNames, null, ENUM_SUFFIX,
127: super class, CLASS_SUFFIX));
128: if (super interfaces != null) {
129: for (int i = 0, max = super interfaces.length; i < max; i++) {
130: char[] super interface = erasure(super interfaces[i]);
131: addTypeReference(super interface);
132: addIndexEntry(SUPER_REF, SuperTypeReferencePattern
133: .createIndexKey(modifiers, packageName, name,
134: enclosingTypeNames, null, ENUM_SUFFIX,
135: super interface, INTERFACE_SUFFIX));
136: }
137: }
138: }
139:
140: public void addFieldDeclaration(char[] typeName, char[] fieldName) {
141: addIndexEntry(FIELD_DECL, FieldPattern
142: .createIndexKey(fieldName));
143: addTypeReference(typeName);
144: }
145:
146: public void addFieldReference(char[] fieldName) {
147: addNameReference(fieldName);
148: }
149:
150: protected void addIndexEntry(char[] category, char[] key) {
151: this .document.addIndexEntry(category, key);
152: }
153:
154: public void addInterfaceDeclaration(int modifiers,
155: char[] packageName, char[] name,
156: char[][] enclosingTypeNames, char[][] super interfaces,
157: char[][] typeParameterSignatures, boolean secondary) {
158: addTypeDeclaration(modifiers, packageName, name,
159: enclosingTypeNames, secondary);
160:
161: if (super interfaces != null) {
162: for (int i = 0, max = super interfaces.length; i < max; i++) {
163: char[] super interface = erasure(super interfaces[i]);
164: addTypeReference(super interface);
165: addIndexEntry(SUPER_REF, SuperTypeReferencePattern
166: .createIndexKey(modifiers, packageName, name,
167: enclosingTypeNames,
168: typeParameterSignatures,
169: INTERFACE_SUFFIX, super interface,
170: INTERFACE_SUFFIX));
171: }
172: }
173: }
174:
175: public void addMethodDeclaration(char[] methodName,
176: char[][] parameterTypes, char[] returnType,
177: char[][] exceptionTypes) {
178: int argCount = parameterTypes == null ? 0
179: : parameterTypes.length;
180: addIndexEntry(METHOD_DECL, MethodPattern.createIndexKey(
181: methodName, argCount));
182:
183: if (parameterTypes != null) {
184: for (int i = 0; i < argCount; i++)
185: addTypeReference(parameterTypes[i]);
186: }
187: if (exceptionTypes != null)
188: for (int i = 0, max = exceptionTypes.length; i < max; i++)
189: addTypeReference(exceptionTypes[i]);
190: if (returnType != null)
191: addTypeReference(returnType);
192: }
193:
194: public void addMethodReference(char[] methodName, int argCount) {
195: addIndexEntry(METHOD_REF, MethodPattern.createIndexKey(
196: methodName, argCount));
197: }
198:
199: public void addNameReference(char[] name) {
200: addIndexEntry(REF, name);
201: }
202:
203: protected void addTypeDeclaration(int modifiers,
204: char[] packageName, char[] name,
205: char[][] enclosingTypeNames, boolean secondary) {
206: char[] indexKey = TypeDeclarationPattern.createIndexKey(
207: modifiers, name, packageName, enclosingTypeNames,
208: secondary);
209: if (secondary)
210: JavaModelManager.getJavaModelManager().secondaryTypeAdding(
211: this .document.getPath(),
212: name == null ? CharOperation.NO_CHAR : name,
213: packageName == null ? CharOperation.NO_CHAR
214: : packageName);
215:
216: addIndexEntry(TYPE_DECL, indexKey);
217: }
218:
219: public void addTypeReference(char[] typeName) {
220: addNameReference(CharOperation.lastSegment(typeName, '.'));
221: }
222:
223: public abstract void indexDocument();
224: }
|