KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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.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 JavaDoc documentPath;
37     String JavaDoc 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/*remove project segment*/);
46     }
47
48     if (scope instanceof JavaSearchScope) {
49         JavaSearchScope javaSearchScope = (JavaSearchScope) scope;
50         // Get document path access restriction from java search scope
51
// Note that requestor has to verify if needed whether the document violates the access restriction or not
52
AccessRuleSet access = javaSearchScope.getAccessRuleSet(relativePath, index.containerPath);
53         if (access != JavaSearchScope.NOT_ENCLOSED) { // scope encloses the path
54
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 JavaDoc print(StringBuffer JavaDoc output) {
63     if (this.findDeclarations) {
64         output.append(this.findReferences
65             ? "LocalVarCombinedPattern: " //$NON-NLS-1$
66
: "LocalVarDeclarationPattern: "); //$NON-NLS-1$
67
} else {
68         output.append("LocalVarReferencePattern: "); //$NON-NLS-1$
69
}
70     output.append(this.localVariable.toStringWithAncestors());
71     return super.print(output);
72 }
73 }
74
Popular Tags