KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > corext > callhierarchy > MethodReferencesSearchRequestor


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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  * Jesper Kamstrup Linnet (eclipse@kamstrup-linnet.dk) - initial API and implementation
10  * (report 36180: Callers/Callees view)
11  *******************************************************************************/

12 package org.eclipse.jdt.internal.corext.callhierarchy;
13
14 import java.util.Map JavaDoc;
15
16 import org.eclipse.jdt.core.IJavaElement;
17 import org.eclipse.jdt.core.IMember;
18 import org.eclipse.jdt.core.search.SearchMatch;
19 import org.eclipse.jdt.core.search.SearchRequestor;
20
21 class MethodReferencesSearchRequestor extends SearchRequestor {
22     private CallSearchResultCollector fSearchResults;
23     private boolean fRequireExactMatch = true;
24
25     MethodReferencesSearchRequestor() {
26         fSearchResults = new CallSearchResultCollector();
27     }
28
29     public Map JavaDoc getCallers() {
30         return fSearchResults.getCallers();
31     }
32
33     /* (non-Javadoc)
34      * @see org.eclipse.jdt.core.search.SearchRequestor#acceptSearchMatch(org.eclipse.jdt.core.search.SearchMatch)
35      */

36     public void acceptSearchMatch(SearchMatch match) {
37         if (fRequireExactMatch && (match.getAccuracy() != SearchMatch.A_ACCURATE)) {
38             return;
39         }
40         
41         if (match.isInsideDocComment()) {
42             return;
43         }
44
45         if (match.getElement() != null && match.getElement() instanceof IMember) {
46             IMember member= (IMember) match.getElement();
47             switch (member.getElementType()) {
48                 case IJavaElement.METHOD:
49                 case IJavaElement.TYPE:
50                 case IJavaElement.FIELD:
51                 case IJavaElement.INITIALIZER:
52                     fSearchResults.addMember(member, member, match.getOffset(), match.getOffset()+match.getLength());
53                     break;
54             }
55         }
56     }
57 }
58
Popular Tags