1 11 package org.eclipse.jdt.internal.core.search.indexing; 12 13 import org.eclipse.jdt.core.Signature; 14 import org.eclipse.jdt.core.compiler.CharOperation; 15 import org.eclipse.jdt.core.search.SearchDocument; 16 import org.eclipse.jdt.internal.compiler.lookup.TypeConstants; 17 import org.eclipse.jdt.internal.core.JavaModelManager; 18 import org.eclipse.jdt.internal.core.search.matching.*; 19 20 public abstract class AbstractIndexer implements IIndexConstants { 21 22 SearchDocument document; 23 24 public AbstractIndexer(SearchDocument document) { 25 this.document = document; 26 } 27 public void addAnnotationTypeDeclaration(int modifiers, char[] packageName, char[] name, char[][] enclosingTypeNames, boolean secondary) { 28 addTypeDeclaration(modifiers, packageName, name, enclosingTypeNames, secondary); 29 30 addIndexEntry( 31 SUPER_REF, 32 SuperTypeReferencePattern.createIndexKey( 33 modifiers, packageName, name, enclosingTypeNames, null, ANNOTATION_TYPE_SUFFIX, CharOperation.concatWith(TypeConstants.JAVA_LANG_ANNOTATION_ANNOTATION, '.'), ANNOTATION_TYPE_SUFFIX)); 34 } 35 public void addClassDeclaration( 36 int modifiers, 37 char[] packageName, 38 char[] name, 39 char[][] enclosingTypeNames, 40 char[] superclass, 41 char[][] superinterfaces, 42 char[][] typeParameterSignatures, 43 boolean secondary) { 44 addTypeDeclaration(modifiers, packageName, name, enclosingTypeNames, secondary); 45 46 if (superclass != null) { 47 superclass = erasure(superclass); 48 addTypeReference(superclass); 49 } 50 addIndexEntry( 51 SUPER_REF, 52 SuperTypeReferencePattern.createIndexKey( 53 modifiers, packageName, name, enclosingTypeNames, typeParameterSignatures, CLASS_SUFFIX, superclass, CLASS_SUFFIX)); 54 if (superinterfaces != null) { 55 for (int i = 0, max = superinterfaces.length; i < max; i++) { 56 char[] superinterface = erasure(superinterfaces[i]); 57 addTypeReference(superinterface); 58 addIndexEntry( 59 SUPER_REF, 60 SuperTypeReferencePattern.createIndexKey( 61 modifiers, packageName, name, enclosingTypeNames, typeParameterSignatures, CLASS_SUFFIX, superinterface, INTERFACE_SUFFIX)); 62 } 63 } 64 } 65 private char[] erasure(char[] typeName) { 66 int genericStart = CharOperation.indexOf(Signature.C_GENERIC_START, typeName); 67 if (genericStart > -1) 68 typeName = CharOperation.subarray(typeName, 0, genericStart); 69 return typeName; 70 } 71 public void addConstructorDeclaration(char[] typeName, char[][] parameterTypes, char[][] exceptionTypes) { 72 int argCount = parameterTypes == null ? 0 : parameterTypes.length; 73 addIndexEntry(CONSTRUCTOR_DECL, ConstructorPattern.createIndexKey(CharOperation.lastSegment(typeName,'.'), argCount)); 74 75 if (parameterTypes != null) { 76 for (int i = 0; i < argCount; i++) 77 addTypeReference(parameterTypes[i]); 78 } 79 if (exceptionTypes != null) 80 for (int i = 0, max = exceptionTypes.length; i < max; i++) 81 addTypeReference(exceptionTypes[i]); 82 } 83 public void addConstructorReference(char[] typeName, int argCount) { 84 char[] simpleTypeName = CharOperation.lastSegment(typeName,'.'); 85 addTypeReference(simpleTypeName); 86 addIndexEntry(CONSTRUCTOR_REF, ConstructorPattern.createIndexKey(simpleTypeName, argCount)); 87 char[] innermostTypeName = CharOperation.lastSegment(simpleTypeName,'$'); 88 if (innermostTypeName != simpleTypeName) 89 addIndexEntry(CONSTRUCTOR_REF, ConstructorPattern.createIndexKey(innermostTypeName, argCount)); 90 } 91 public void addEnumDeclaration(int modifiers, char[] packageName, char[] name, char[][] enclosingTypeNames, char[] superclass, char[][] superinterfaces, boolean secondary) { 92 addTypeDeclaration(modifiers, packageName, name, enclosingTypeNames, secondary); 93 94 addIndexEntry( 95 SUPER_REF, 96 SuperTypeReferencePattern.createIndexKey( 97 modifiers, packageName, name, enclosingTypeNames, null, ENUM_SUFFIX, superclass, CLASS_SUFFIX)); 98 if (superinterfaces != null) { 99 for (int i = 0, max = superinterfaces.length; i < max; i++) { 100 char[] superinterface = erasure(superinterfaces[i]); 101 addTypeReference(superinterface); 102 addIndexEntry( 103 SUPER_REF, 104 SuperTypeReferencePattern.createIndexKey( 105 modifiers, packageName, name, enclosingTypeNames, null, ENUM_SUFFIX, superinterface, INTERFACE_SUFFIX)); 106 } 107 } 108 } 109 public void addFieldDeclaration(char[] typeName, char[] fieldName) { 110 addIndexEntry(FIELD_DECL, FieldPattern.createIndexKey(fieldName)); 111 addTypeReference(typeName); 112 } 113 public void addFieldReference(char[] fieldName) { 114 addNameReference(fieldName); 115 } 116 protected void addIndexEntry(char[] category, char[] key) { 117 this.document.addIndexEntry(category, key); 118 } 119 public void addInterfaceDeclaration(int modifiers, char[] packageName, char[] name, char[][] enclosingTypeNames, char[][] superinterfaces, char[][] typeParameterSignatures, boolean secondary) { 120 addTypeDeclaration(modifiers, packageName, name, enclosingTypeNames, secondary); 121 122 if (superinterfaces != null) { 123 for (int i = 0, max = superinterfaces.length; i < max; i++) { 124 char[] superinterface = erasure(superinterfaces[i]); 125 addTypeReference(superinterface); 126 addIndexEntry( 127 SUPER_REF, 128 SuperTypeReferencePattern.createIndexKey( 129 modifiers, packageName, name, enclosingTypeNames, typeParameterSignatures, INTERFACE_SUFFIX, superinterface, INTERFACE_SUFFIX)); 130 } 131 } 132 } 133 public void addMethodDeclaration(char[] methodName, char[][] parameterTypes, char[] returnType, char[][] exceptionTypes) { 134 int argCount = parameterTypes == null ? 0 : parameterTypes.length; 135 addIndexEntry(METHOD_DECL, MethodPattern.createIndexKey(methodName, argCount)); 136 137 if (parameterTypes != null) { 138 for (int i = 0; i < argCount; i++) 139 addTypeReference(parameterTypes[i]); 140 } 141 if (exceptionTypes != null) 142 for (int i = 0, max = exceptionTypes.length; i < max; i++) 143 addTypeReference(exceptionTypes[i]); 144 if (returnType != null) 145 addTypeReference(returnType); 146 } 147 public void addMethodReference(char[] methodName, int argCount) { 148 addIndexEntry(METHOD_REF, MethodPattern.createIndexKey(methodName, argCount)); 149 } 150 public void addNameReference(char[] name) { 151 addIndexEntry(REF, name); 152 } 153 protected void addTypeDeclaration(int modifiers, char[] packageName, char[] name, char[][] enclosingTypeNames, boolean secondary) { 154 char[] indexKey = TypeDeclarationPattern.createIndexKey(modifiers, name, packageName, enclosingTypeNames, secondary); 155 if (secondary) 156 JavaModelManager.getJavaModelManager().secondaryTypeAdding( 157 this.document.getPath(), 158 name == null ? CharOperation.NO_CHAR : name, 159 packageName == null ? CharOperation.NO_CHAR : packageName); 160 161 addIndexEntry(TYPE_DECL, indexKey); 162 } 163 public void addTypeReference(char[] typeName) { 164 addNameReference(CharOperation.lastSegment(typeName, '.')); 165 } 166 public abstract void indexDocument(); 167 } 168 | Popular Tags |