KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > search > NewSearchResultCollector


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.ui.search;
12
13 import org.eclipse.core.runtime.CoreException;
14 import org.eclipse.jdt.core.IJavaElement;
15 import org.eclipse.jdt.core.search.FieldReferenceMatch;
16 import org.eclipse.jdt.core.search.LocalVariableReferenceMatch;
17 import org.eclipse.jdt.core.search.MethodReferenceMatch;
18 import org.eclipse.jdt.core.search.SearchMatch;
19 import org.eclipse.jdt.core.search.SearchParticipant;
20 import org.eclipse.jdt.core.search.SearchRequestor;
21
22 public class NewSearchResultCollector extends SearchRequestor {
23     private JavaSearchResult fSearch;
24     private boolean fIgnorePotentials;
25
26     public NewSearchResultCollector(JavaSearchResult search, boolean ignorePotentials) {
27         super();
28         fSearch= search;
29         fIgnorePotentials= ignorePotentials;
30     }
31     
32     public void acceptSearchMatch(SearchMatch match) throws CoreException {
33         IJavaElement enclosingElement= (IJavaElement) match.getElement();
34         if (enclosingElement != null) {
35             if (fIgnorePotentials && (match.getAccuracy() == SearchMatch.A_INACCURATE))
36                 return;
37             boolean isWriteAccess= false;
38             boolean isReadAccess= false;
39             if (match instanceof FieldReferenceMatch) {
40                 FieldReferenceMatch fieldRef= ((FieldReferenceMatch) match);
41                 isWriteAccess= fieldRef.isWriteAccess();
42                 isReadAccess= fieldRef.isReadAccess();
43             } else if (match instanceof LocalVariableReferenceMatch) {
44                 LocalVariableReferenceMatch localVarRef= ((LocalVariableReferenceMatch) match);
45                 isWriteAccess= localVarRef.isWriteAccess();
46                 isReadAccess= localVarRef.isReadAccess();
47             }
48             boolean isSuperInvocation= false;
49             if (match instanceof MethodReferenceMatch) {
50                 MethodReferenceMatch methodRef= (MethodReferenceMatch) match;
51                 isSuperInvocation= methodRef.isSuperInvocation();
52             }
53             fSearch.addMatch(new JavaElementMatch(enclosingElement, match.getRule(), match.getOffset(), match.getLength(), match.getAccuracy(), isReadAccess, isWriteAccess, match.isInsideDocComment(), isSuperInvocation));
54         }
55     }
56
57     public void beginReporting() {
58     }
59
60     public void endReporting() {
61     }
62
63     public void enterParticipant(SearchParticipant participant) {
64     }
65
66     public void exitParticipant(SearchParticipant participant) {
67     }
68
69 }
70
Popular Tags