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.*; 17 import org.eclipse.jdt.core.search.*; 18 import org.eclipse.jdt.internal.compiler.env.AccessRuleSet; 19 import org.eclipse.jdt.internal.compiler.util.SuffixConstants; 20 import org.eclipse.jdt.internal.core.LocalVariable; 21 import org.eclipse.jdt.internal.core.index.Index; 22 import org.eclipse.jdt.internal.core.search.IndexQueryRequestor; 23 import org.eclipse.jdt.internal.core.search.JavaSearchScope; 24 import org.eclipse.jdt.internal.core.util.Util; 25 26 public class LocalVariablePattern extends VariablePattern { 27 28 LocalVariable localVariable; 29 30 public LocalVariablePattern(boolean findDeclarations, boolean readAccess, boolean writeAccess, LocalVariable localVariable, int matchRule) { 31 super(LOCAL_VAR_PATTERN, findDeclarations, readAccess, writeAccess, localVariable.getElementName().toCharArray(), matchRule); 32 this.localVariable = localVariable; 33 } 34 public void findIndexMatches(Index index, IndexQueryRequestor requestor, SearchParticipant participant, IJavaSearchScope scope, IProgressMonitor progressMonitor) { 35 IPackageFragmentRoot root = (IPackageFragmentRoot)this.localVariable.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); 36 String documentPath; 37 String relativePath; 38 if (root.isArchive()) { 39 IType type = (IType)this.localVariable.getAncestor(IJavaElement.TYPE); 40 relativePath = (type.getFullyQualifiedName('/')).replace('.', '/') + SuffixConstants.SUFFIX_STRING_class; 41 documentPath = root.getPath() + IJavaSearchScope.JAR_FILE_ENTRY_SEPARATOR + relativePath; 42 } else { 43 IPath path = this.localVariable.getPath(); 44 documentPath = path.toString(); 45 relativePath = Util.relativePath(path, 1); 46 } 47 48 if (scope instanceof JavaSearchScope) { 49 JavaSearchScope javaSearchScope = (JavaSearchScope) scope; 50 AccessRuleSet access = javaSearchScope.getAccessRuleSet(relativePath, index.containerPath); 53 if (access != JavaSearchScope.NOT_ENCLOSED) { if (!requestor.acceptIndexMatch(documentPath, this, participant, access)) 55 throw new OperationCanceledException(); 56 } 57 } else if (scope.encloses(documentPath)) { 58 if (!requestor.acceptIndexMatch(documentPath, this, participant, null)) 59 throw new OperationCanceledException(); 60 } 61 } 62 protected StringBuffer print(StringBuffer output) { 63 if (this.findDeclarations) { 64 output.append(this.findReferences 65 ? "LocalVarCombinedPattern: " : "LocalVarDeclarationPattern: "); } else { 68 output.append("LocalVarReferencePattern: "); } 70 output.append(this.localVariable.toStringWithAncestors()); 71 return super.print(output); 72 } 73 } 74 | Popular Tags |