1 /*******************************************************************************
2 * Copyright (c) 2000, 2011 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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package org.eclipse.jdt.internal.ui.search;
13 import org.eclipse.core.runtime.CoreException;
15 import org.eclipse.search.ui.text.AbstractTextSearchResult;
17 import org.eclipse.jdt.core.IJavaElement;
18 import org.eclipse.jdt.core.search.FieldDeclarationMatch;
19 import org.eclipse.jdt.core.search.FieldReferenceMatch;
20 import org.eclipse.jdt.core.search.LocalVariableDeclarationMatch;
21 import org.eclipse.jdt.core.search.LocalVariableReferenceMatch;
22 import org.eclipse.jdt.core.search.MethodReferenceMatch;
23 import org.eclipse.jdt.core.search.SearchMatch;
24 import org.eclipse.jdt.core.search.SearchParticipant;
25 import org.eclipse.jdt.core.search.SearchRequestor;
27 public class NewSearchResultCollector extends SearchRequestor {
28 private AbstractTextSearchResult fSearch;
29 private boolean fIgnorePotentials;
31 public NewSearchResultCollector(AbstractTextSearchResult search, boolean ignorePotentials) {
34 fIgnorePotentials= ignorePotentials;
38 public void acceptSearchMatch(SearchMatch match) throws CoreException {
39 IJavaElement enclosingElement= (IJavaElement) match.getElement();
40 if (enclosingElement != null) {
41 if (fIgnorePotentials && (match.getAccuracy() == SearchMatch.A_INACCURATE))
43 boolean isWriteAccess= false;
44 boolean isReadAccess= false;
45 if (match instanceof FieldReferenceMatch) {
46 FieldReferenceMatch fieldRef= ((FieldReferenceMatch) match);
47 isWriteAccess= fieldRef.isWriteAccess();
48 isReadAccess= fieldRef.isReadAccess();
49 } else if (match instanceof FieldDeclarationMatch) {
51 } else if (match instanceof LocalVariableReferenceMatch) {
52 LocalVariableReferenceMatch localVarRef= ((LocalVariableReferenceMatch) match);
53 isWriteAccess= localVarRef.isWriteAccess();
54 isReadAccess= localVarRef.isReadAccess();
55 } else if (match instanceof LocalVariableDeclarationMatch) {
58 boolean isSuperInvocation= false;
59 if (match instanceof MethodReferenceMatch) {
60 MethodReferenceMatch methodRef= (MethodReferenceMatch) match;
61 isSuperInvocation= methodRef.isSuperInvocation();
63 fSearch.addMatch(new JavaElementMatch(enclosingElement, match.getRule(), match.getOffset(), match.getLength(), match.getAccuracy(), isReadAccess, isWriteAccess, match.isInsideDocComment(), isSuperInvocation));
68 public void beginReporting() {
72 public void endReporting() {
76 public void enterParticipant(SearchParticipant participant) {
80 public void exitParticipant(SearchParticipant participant) {