KickJava   Java API By Example, From Geeks To Geeks.

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


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.HashMap JavaDoc;
15 import java.util.Map JavaDoc;
16
17 import org.eclipse.jdt.core.IJavaElement;
18 import org.eclipse.jdt.core.IMember;
19 import org.eclipse.jdt.core.IType;
20
21 class CallSearchResultCollector {
22     private Map JavaDoc fCalledMembers;
23
24     public CallSearchResultCollector() {
25         this.fCalledMembers = createCalledMethodsData();
26     }
27
28     public Map JavaDoc getCallers() {
29         return fCalledMembers;
30     }
31
32     protected void addMember(IMember member, IMember calledMember, int start, int end) {
33         addMember(member, calledMember, start, end, CallLocation.UNKNOWN_LINE_NUMBER);
34     }
35
36     protected void addMember(IMember member, IMember calledMember, int start, int end, int lineNumber) {
37         if ((member != null) && (calledMember != null)) {
38             if (!isIgnored(calledMember)) {
39                 MethodCall methodCall = (MethodCall) fCalledMembers.get(calledMember.getHandleIdentifier());
40
41                 if (methodCall == null) {
42                     methodCall = new MethodCall(calledMember);
43                     fCalledMembers.put(calledMember.getHandleIdentifier(), methodCall);
44                 }
45
46                 methodCall.addCallLocation(new CallLocation(member, calledMember, start,
47                         end, lineNumber));
48             }
49         }
50     }
51
52     protected Map JavaDoc createCalledMethodsData() {
53         return new HashMap JavaDoc();
54     }
55
56     /**
57      * Method isIgnored.
58      * @param enclosingElement
59      * @return boolean
60      */

61     private boolean isIgnored(IMember enclosingElement) {
62         String JavaDoc fullyQualifiedName = getTypeOfElement(enclosingElement)
63                                         .getFullyQualifiedName();
64
65         return CallHierarchy.getDefault().isIgnored(fullyQualifiedName);
66     }
67
68     private IType getTypeOfElement(IMember element) {
69         if (element.getElementType() == IJavaElement.TYPE) {
70             return (IType) element;
71         }
72
73         return element.getDeclaringType();
74     }
75 }
76
Popular Tags