1 11 package org.eclipse.jdt.internal.core.search.matching; 12 13 import org.eclipse.core.runtime.IPath; 14 import org.eclipse.core.runtime.IProgressMonitor; 15 import org.eclipse.core.runtime.OperationCanceledException; 16 import org.eclipse.jdt.core.IJavaElement; 17 import org.eclipse.jdt.core.IMember; 18 import org.eclipse.jdt.core.IMethod; 19 import org.eclipse.jdt.core.IPackageFragmentRoot; 20 import org.eclipse.jdt.core.IType; 21 import org.eclipse.jdt.core.ITypeParameter; 22 import org.eclipse.jdt.core.Signature; 23 import org.eclipse.jdt.core.search.IJavaSearchScope; 24 import org.eclipse.jdt.core.search.SearchParticipant; 25 import org.eclipse.jdt.internal.compiler.env.AccessRuleSet; 26 import org.eclipse.jdt.internal.compiler.util.SuffixConstants; 27 import org.eclipse.jdt.internal.core.index.Index; 28 import org.eclipse.jdt.internal.core.search.IndexQueryRequestor; 29 import org.eclipse.jdt.internal.core.search.JavaSearchScope; 30 import org.eclipse.jdt.internal.core.util.Util; 31 32 37 public class TypeParameterPattern extends JavaSearchPattern { 38 39 protected boolean findDeclarations; 40 protected boolean findReferences; 41 protected char[] name; 42 protected ITypeParameter typeParameter; 43 protected char[] declaringMemberName; 44 protected char[] methodDeclaringClassName; 45 protected char[][] methodArgumentTypes; 46 47 53 public TypeParameterPattern(boolean findDeclarations, boolean findReferences, ITypeParameter typeParameter, int matchRule) { 54 super(TYPE_PARAM_PATTERN, matchRule); 55 56 this.findDeclarations = findDeclarations; this.findReferences = findReferences; this.typeParameter = typeParameter; 59 this.name = typeParameter.getElementName().toCharArray(); IMember member = typeParameter.getDeclaringMember(); 61 this.declaringMemberName = member.getElementName().toCharArray(); 63 if (member instanceof IMethod) { 65 IMethod method = (IMethod) member; 66 this.methodDeclaringClassName = method.getParent().getElementName().toCharArray(); 67 String [] parameters = method.getParameterTypes(); 68 int length = parameters.length; 69 this.methodArgumentTypes = new char[length][]; 70 for (int i=0; i<length; i++) { 71 this.methodArgumentTypes[i] = Signature.toCharArray(parameters[i].toCharArray()); 72 } 73 } 74 } 75 76 79 public void findIndexMatches(Index index, IndexQueryRequestor requestor, SearchParticipant participant, IJavaSearchScope scope, IProgressMonitor progressMonitor) { 80 IPackageFragmentRoot root = (IPackageFragmentRoot) this.typeParameter.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); 81 String documentPath; 82 String relativePath; 83 if (root.isArchive()) { 84 IType type = (IType) this.typeParameter.getAncestor(IJavaElement.TYPE); 85 relativePath = (type.getFullyQualifiedName('/')).replace('.', '/') + SuffixConstants.SUFFIX_STRING_class; 86 documentPath = root.getPath() + IJavaSearchScope.JAR_FILE_ENTRY_SEPARATOR + relativePath; 87 } else { 88 IPath path = this.typeParameter.getPath(); 89 documentPath = path.toString(); 90 relativePath = Util.relativePath(path, 1); 91 } 92 93 if (scope instanceof JavaSearchScope) { 94 JavaSearchScope javaSearchScope = (JavaSearchScope) scope; 95 AccessRuleSet access = javaSearchScope.getAccessRuleSet(relativePath, index.containerPath); 98 if (access != JavaSearchScope.NOT_ENCLOSED) { if (!requestor.acceptIndexMatch(documentPath, this, participant, access)) 100 throw new OperationCanceledException(); 101 } 102 } else if (scope.encloses(documentPath)) { 103 if (!requestor.acceptIndexMatch(documentPath, this, participant, null)) 104 throw new OperationCanceledException(); 105 } 106 } 107 108 protected StringBuffer print(StringBuffer output) { 109 if (this.findDeclarations) { 110 output.append(this.findReferences 111 ? "TypeParamCombinedPattern: " : "TypeParamDeclarationPattern: "); } else { 114 output.append("TypeParamReferencePattern: "); } 116 output.append(typeParameter.toString()); 117 return super.print(output); 118 } 119 120 } 121 | Popular Tags |