]> git.uio.no Git - ifi-stolz-refaktor.git/blob - case-study/jdt-before/ui/org/eclipse/jdt/internal/ui/search/NewSearchResultCollector.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-before / ui / org / eclipse / jdt / internal / ui / search / NewSearchResultCollector.java
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
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
15 import org.eclipse.search.ui.text.AbstractTextSearchResult;
16
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;
26
27 public class NewSearchResultCollector extends SearchRequestor {
28         private AbstractTextSearchResult fSearch;
29         private boolean fIgnorePotentials;
30
31         public NewSearchResultCollector(AbstractTextSearchResult search, boolean ignorePotentials) {
32                 super();
33                 fSearch= search;
34                 fIgnorePotentials= ignorePotentials;
35         }
36
37         @Override
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))
42                                 return;
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) {
50                                 isWriteAccess= true;
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) {
56                                 isWriteAccess= true;
57                         }
58                         boolean isSuperInvocation= false;
59                         if (match instanceof MethodReferenceMatch) {
60                                 MethodReferenceMatch methodRef= (MethodReferenceMatch) match;
61                                 isSuperInvocation= methodRef.isSuperInvocation();
62                         }
63                         fSearch.addMatch(new JavaElementMatch(enclosingElement, match.getRule(), match.getOffset(), match.getLength(), match.getAccuracy(), isReadAccess, isWriteAccess, match.isInsideDocComment(), isSuperInvocation));
64                 }
65         }
66
67         @Override
68         public void beginReporting() {
69         }
70
71         @Override
72         public void endReporting() {
73         }
74
75         @Override
76         public void enterParticipant(SearchParticipant participant) {
77         }
78
79         @Override
80         public void exitParticipant(SearchParticipant participant) {
81         }
82
83 }