View | Details | Raw Unified | Return to bug 36520
Collapse All | Expand All

(-)core (+240 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2003 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-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.ArrayList;
15
import java.util.Arrays;
16
import java.util.Collection;
17
import java.util.List;
18
import java.util.StringTokenizer;
19
20
import org.eclipse.core.runtime.NullProgressMonitor;
21
import org.eclipse.jdt.core.IJavaElement;
22
import org.eclipse.jdt.core.IMethod;
23
import org.eclipse.jdt.core.search.IJavaSearchScope;
24
import org.eclipse.jdt.core.search.SearchEngine;
25
import org.eclipse.jdt.internal.ui.JavaPlugin;
26
import org.eclipse.jdt.internal.ui.callhierarchy.ICallHierarchyPreferencesConstants;
27
import org.eclipse.jdt.internal.ui.util.StringMatcher;
28
import org.eclipse.jface.preference.IPreferenceStore;
29
30
public class CallHierarchy {
31
    private static final String PREF_USE_FILTERS = "PREF_USE_FILTERS";
32
    private static final String PREF_FILTERS_LIST = "PREF_FILTERS_LIST";
33
34
    private static final String DEFAULT_IGNORE_FILTERS = "java.*,javax.*";
35
    private static CallHierarchy fgInstance;
36
    private IJavaSearchScope fSearchScope;
37
    private StringMatcher[] fFilters;
38
39
    public static CallHierarchy getDefault() {
40
        if (fgInstance == null) {
41
            fgInstance = new CallHierarchy();
42
        }
43
44
        return fgInstance;
45
    }
46
47
    /**
48
     * @return
49
     */
50
    public boolean isSearchForCalleesUsingImplementorsEnabled() {
51
        IPreferenceStore settings = JavaPlugin.getDefault().getPreferenceStore();
52
53
        return settings.getBoolean(ICallHierarchyPreferencesConstants.PREF_USE_IMPLEMENTORS_FOR_CALLEE_SEARCH);
54
    }
55
56
    /**
57
     * @return
58
     */
59
    public boolean isSearchForCallersUsingImplementorsEnabled() {
60
        IPreferenceStore settings = JavaPlugin.getDefault().getPreferenceStore();
61
62
        return settings.getBoolean(ICallHierarchyPreferencesConstants.PREF_USE_IMPLEMENTORS_FOR_CALLER_SEARCH);
63
    }
64
65
    /**
66
     * @param method
67
     *
68
     * @return
69
     */
70
    public Collection getImplementingMethods(IMethod method) {
71
        if (isSearchForCalleesUsingImplementorsEnabled()) {
72
            IJavaElement[] result = Implementors.getInstance().searchForImplementors(new IJavaElement[] {
73
                        method
74
                    }, new NullProgressMonitor());
75
76
            if ((result != null) && (result.length > 0)) {
77
                return Arrays.asList(result);
78
            }
79
        }
80
81
        return new ArrayList(0);
82
    }
83
84
    /**
85
     * @param method
86
     *
87
     * @return
88
     */
89
    public Collection getInterfaceMethods(IMethod method) {
90
        if (isSearchForCallersUsingImplementorsEnabled()) {
91
            IJavaElement[] result = Implementors.getInstance().searchForInterfaces(new IJavaElement[] {
92
                        method
93
                    }, new NullProgressMonitor());
94
95
            if ((result != null) && (result.length > 0)) {
96
                return Arrays.asList(result);
97
            }
98
        }
99
100
        return new ArrayList(0);
101
    }
102
103
    public MethodWrapper getCallerRoot(IMethod method) {
104
        return new CallerMethodWrapper(null, new MethodCall(method));
105
    }
106
107
    public MethodWrapper getCalleeRoot(IMethod method) {
108
        return new CalleeMethodWrapper(null, new MethodCall(method));
109
    }
110
111
    public static CallLocation getCallLocation(Object element) {
112
        CallLocation callLocation = null;
113
114
        if (element instanceof MethodWrapper) {
115
            MethodWrapper methodWrapper = (MethodWrapper) element;
116
            MethodCall methodCall = methodWrapper.getMethodCall();
117
118
            if (methodCall != null) {
119
                callLocation = methodCall.getFirstCallLocation();
120
            }
121
        } else if (element instanceof CallLocation) {
122
            callLocation = (CallLocation) element;
123
        }
124
125
        return callLocation;
126
    }
127
128
    public IJavaSearchScope getSearchScope() {
129
        if (fSearchScope != null) {
130
            return fSearchScope;
131
        }
132
133
        Utility.logDebug("No search scope was set");
134
135
        return SearchEngine.createWorkspaceScope();
136
    }
137
138
    public void setSearchScope(IJavaSearchScope searchScope) {
139
        this.fSearchScope = searchScope;
140
    }
141
142
    /**
143
     * Checks whether the fully qualified name is ignored by the set filters.
144
     *
145
     * @param fullyQualifiedName
146
     *
147
     * @return True if the fully qualified name is ignored.
148
     */
149
    public boolean isIgnored(String fullyQualifiedName) {
150
        if ((getIgnoreFilters() != null) && (getIgnoreFilters().length > 0)) {
151
            for (int i = 0; i < getIgnoreFilters().length; i++) {
152
                String fullyQualifiedName1 = fullyQualifiedName;
153
154
                if (getIgnoreFilters()[i].match(fullyQualifiedName1)) {
155
                    return true;
156
                }
157
            }
158
        }
159
160
        return false;
161
    }
162
163
    /**
164
     * @return
165
     */
166
    public boolean isFilterEnabled() {
167
        IPreferenceStore settings = JavaPlugin.getDefault().getPreferenceStore();
168
        return settings.getBoolean(PREF_USE_FILTERS);
169
    }
170
171
    /**
172
     * @param b
173
     */
174
    public void setFilterEnabled(boolean filterEnabled) {
175
        IPreferenceStore settings = JavaPlugin.getDefault().getPreferenceStore();
176
        settings.setValue(PREF_USE_FILTERS, filterEnabled);
177
    }
178
    
179
    /**
180
     * Returns the current filters as a string.
181
     *
182
     * @return
183
     */
184
    public String getFilters() {
185
        IPreferenceStore settings = JavaPlugin.getDefault().getPreferenceStore();
186
187
        return settings.getString(PREF_FILTERS_LIST);
188
    }
189
190
    public void setFilters(String filters) {
191
        fFilters = null;
192
193
        IPreferenceStore settings = JavaPlugin.getDefault().getPreferenceStore();
194
        settings.setValue(PREF_FILTERS_LIST, filters);
195
    }
196
197
    /**
198
     * Returns filters for packages which should not be included in the search results.
199
     *
200
     * @return StringMatcher[]
201
     */
202
    private StringMatcher[] getIgnoreFilters() {
203
        if (fFilters == null) {
204
            String filterString = null;
205
206
            if (isFilterEnabled()) {
207
                filterString = getFilters();
208
209
                if (filterString == null) {
210
                    filterString = DEFAULT_IGNORE_FILTERS;
211
                }
212
            }
213
214
            if (filterString != null) {
215
                fFilters = parseList(filterString);
216
            } else {
217
                fFilters = null;
218
            }
219
        }
220
221
        return fFilters;
222
    }
223
224
    /**
225
     * Parses the comma separated string into an array of StringMatcher objects
226
     *
227
     * @return list
228
     */
229
    private static StringMatcher[] parseList(String listString) {
230
        List list = new ArrayList(10);
231
        StringTokenizer tokenizer = new StringTokenizer(listString, ","); //$NON-NLS-1$
232
233
        while (tokenizer.hasMoreTokens()) {
234
            String textFilter = tokenizer.nextToken();
235
            list.add(new StringMatcher(textFilter, false, false));
236
        }
237
238
        return (StringMatcher[]) list.toArray(new StringMatcher[list.size()]);
239
    }
240
}
(-)core (+100 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2003 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-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 org.eclipse.core.runtime.IAdaptable;
15
import org.eclipse.jdt.core.IBuffer;
16
import org.eclipse.jdt.core.ICompilationUnit;
17
import org.eclipse.jdt.core.IJavaElement;
18
import org.eclipse.jdt.core.IMember;
19
import org.eclipse.jdt.core.JavaModelException;
20
21
/**
22
 * @author jl
23
 */
24
public class CallLocation implements IAdaptable {
25
    private IMember fCalledMember;
26
    private IMember fMember;
27
    private String fCallText;
28
    private int fEnd;
29
    private int fStart;
30
31
    /**
32
     * @param method
33
     * @param cu
34
     * @param start
35
     * @param end
36
     */
37
    public CallLocation(IMember member, IMember calledMember, int start, int end) {
38
        this.fMember = member;
39
        this.fCalledMember = calledMember;
40
        this.fStart = start;
41
        this.fEnd = end;
42
43
        fCallText = initializeCallText();
44
    }
45
46
    /**
47
     * @return IMethod
48
     */
49
    public IMember getCalledMember() {
50
        return fCalledMember;
51
    }
52
53
    /**
54
     *
55
     */
56
    public int getEnd() {
57
        return fEnd;
58
    }
59
60
    public IMember getMember() {
61
        return fMember;
62
    }
63
64
    /**
65
     *
66
     */
67
    public int getStart() {
68
        return fStart;
69
    }
70
71
    public String toString() {
72
        return fCallText;
73
    }
74
75
    private String initializeCallText() {
76
        try {
77
            ICompilationUnit compilationUnit = fMember.getCompilationUnit();
78
79
            if ((fMember != null) && (compilationUnit != null)) {
80
                IBuffer buffer = compilationUnit.getBuffer();
81
82
                return buffer.getText(fStart, (fEnd - fStart));
83
            } else {
84
                return fMember.getOpenable().getBuffer().getText(fStart, (fEnd - fStart));
85
            }
86
        } catch (JavaModelException e) {
87
            Utility.logError("CallLocation::toString: Error creating text", e);
88
89
            return "- error -";
90
        }
91
    }
92
93
    public Object getAdapter(Class adapter) {
94
        if (IJavaElement.class.isAssignableFrom(adapter)) {
95
            return getMember();
96
        }
97
98
        return null;
99
    }
100
}
(-)core (+73 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2003 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-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;
15
import java.util.Map;
16
import org.eclipse.jdt.core.IJavaElement;
17
import org.eclipse.jdt.core.IMember;
18
import org.eclipse.jdt.core.IType;
19
20
/**
21
 * @author jl
22
 */
23
class CallSearchResultCollector {
24
    private Map fCalledMembers;
25
26
    public CallSearchResultCollector() {
27
        this.fCalledMembers = createCalledMethodsData();
28
    }
29
30
    public Map getCallers() {
31
        return fCalledMembers;
32
    }
33
34
    protected void addMember(IMember member, IMember calledMember, int start, int end) {
35
        if ((member != null) && (calledMember != null)) {
36
            if (!isIgnored(calledMember)) {
37
                MethodCall methodCall = (MethodCall) fCalledMembers.get(calledMember.getHandleIdentifier());
38
39
                if (methodCall == null) {
40
                    methodCall = new MethodCall(calledMember);
41
                    fCalledMembers.put(calledMember.getHandleIdentifier(), methodCall);
42
                }
43
44
                methodCall.addCallLocation(new CallLocation(member, calledMember, start,
45
                        end));
46
            }
47
        }
48
    }
49
50
    protected Map createCalledMethodsData() {
51
        return new HashMap();
52
    }
53
54
    /**
55
     * Method isIgnored.
56
     * @param enclosingElement
57
     * @return boolean
58
     */
59
    private boolean isIgnored(IMember enclosingElement) {
60
        String fullyQualifiedName = getTypeOfElement(enclosingElement)
61
                                        .getFullyQualifiedName();
62
63
        return CallHierarchy.getDefault().isIgnored(fullyQualifiedName);
64
    }
65
66
    private IType getTypeOfElement(IMember element) {
67
        if (element.getElementType() == IJavaElement.TYPE) {
68
            return (IType) element;
69
        }
70
71
        return element.getDeclaringType();
72
    }
73
}
(-)core (+246 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2003 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-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.Collection;
15
import java.util.Map;
16
17
import org.eclipse.core.runtime.IProgressMonitor;
18
import org.eclipse.core.runtime.SubProgressMonitor;
19
import org.eclipse.jdt.core.IMethod;
20
import org.eclipse.jdt.core.ISourceRange;
21
import org.eclipse.jdt.core.IType;
22
import org.eclipse.jdt.core.JavaModelException;
23
import org.eclipse.jdt.core.dom.ASTNode;
24
import org.eclipse.jdt.core.dom.ASTVisitor;
25
import org.eclipse.jdt.core.dom.ClassInstanceCreation;
26
import org.eclipse.jdt.core.dom.ConstructorInvocation;
27
import org.eclipse.jdt.core.dom.IMethodBinding;
28
import org.eclipse.jdt.core.dom.ITypeBinding;
29
import org.eclipse.jdt.core.dom.MethodDeclaration;
30
import org.eclipse.jdt.core.dom.MethodInvocation;
31
import org.eclipse.jdt.core.dom.SuperConstructorInvocation;
32
import org.eclipse.jdt.core.dom.SuperMethodInvocation;
33
import org.eclipse.jdt.core.search.IJavaSearchScope;
34
import org.eclipse.jdt.internal.corext.dom.Binding2JavaModel;
35
36
/**
37
 * @author jl
38
 */
39
class CalleeAnalyzerVisitor extends ASTVisitor {
40
    private CallSearchResultCollector fSearchResults;
41
    private IMethod fMethod;
42
    private IProgressMonitor fProgressMonitor;
43
    private int fMethodEndPosition;
44
    private int fMethodStartPosition;
45
46
    CalleeAnalyzerVisitor(IMethod method, IProgressMonitor progressMonitor) {
47
        fSearchResults = new CallSearchResultCollector();
48
        this.fMethod = method;
49
        this.fProgressMonitor = progressMonitor;
50
51
        try {
52
            ISourceRange sourceRange = method.getSourceRange();
53
            this.fMethodStartPosition = sourceRange.getOffset();
54
            this.fMethodEndPosition = fMethodStartPosition + sourceRange.getLength();
55
        } catch (JavaModelException jme) {
56
            Utility.logError("Error getting start and end of method: " +
57
                fMethod.getElementName(), jme);
58
        }
59
    }
60
61
    /**
62
     * Method getCallees.
63
     *
64
     * @return CallerElement
65
     */
66
    public Map getCallees() {
67
        return fSearchResults.getCallers();
68
    }
69
70
    /* (non-Javadoc)
71
     * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.ClassInstanceCreation)
72
     */
73
    public boolean visit(ClassInstanceCreation node) {
74
        if (!isNodeWithinMethod(node)) {
75
            return false;
76
        }
77
78
        addMethodCall(node.resolveConstructorBinding(), node);
79
80
        return true;
81
    }
82
83
    /**
84
     * Find all constructor invocations (<code>this(...)</code>) from the called method.
85
     * Since we only traverse into the AST on the wanted method declaration, this method
86
     * should not hit on more constructor invocations than those in the wanted method.
87
     *
88
     * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.ConstructorInvocation)
89
     */
90
    public boolean visit(ConstructorInvocation node) {
91
        if (!isNodeWithinMethod(node)) {
92
            return false;
93
        }
94
95
        addMethodCall(node.resolveConstructorBinding(), node);
96
97
        return true;
98
    }
99
100
    /**
101
     * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.MethodDeclaration)
102
     */
103
    public boolean visit(MethodDeclaration node) {
104
        return isNodeWithinMethod(node);
105
    }
106
107
    /**
108
     * Find all method invocations from the called method. Since we only traverse into
109
     * the AST on the wanted method declaration, this method should not hit on more
110
     * method invocations than those in the wanted method.
111
     *
112
     * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.MethodInvocation)
113
     */
114
    public boolean visit(MethodInvocation node) {
115
        if (!isNodeWithinMethod(node)) {
116
            return false;
117
        }
118
119
        addMethodCall(node.resolveMethodBinding(), node);
120
121
        return true;
122
    }
123
124
    /**
125
     * Find invocations of the supertype's constructor from the called method
126
     * (=constructor). Since we only traverse into the AST on the wanted method
127
     * declaration, this method should not hit on more method invocations than those in
128
     * the wanted method.
129
     *
130
     * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.SuperConstructorInvocation)
131
     */
132
    public boolean visit(SuperConstructorInvocation node) {
133
        if (!isNodeWithinMethod(node)) {
134
            return false;
135
        }
136
137
        addMethodCall(node.resolveConstructorBinding(), node);
138
139
        return true;
140
    }
141
142
    /**
143
     * Find all method invocations from the called method. Since we only traverse into
144
     * the AST on the wanted method declaration, this method should not hit on more
145
     * method invocations than those in the wanted method.
146
     *
147
     * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.MethodInvocation)
148
     */
149
    public boolean visit(SuperMethodInvocation node) {
150
        if (!isNodeWithinMethod(node)) {
151
            return false;
152
        }
153
154
        addMethodCall(node.resolveMethodBinding(), node);
155
156
        return true;
157
    }
158
159
    /**
160
     * Adds the specified method binding to the search results.
161
     *
162
     * @param calledMethodBinding
163
     * @param node
164
     */
165
    protected void addMethodCall(IMethodBinding calledMethodBinding, ASTNode node) {
166
        try {
167
            if (calledMethodBinding != null) {
168
                fProgressMonitor.worked(1);
169
170
                ITypeBinding calledTypeBinding = calledMethodBinding.getDeclaringClass();
171
                IType calledType = null;
172
173
                if (!calledTypeBinding.isAnonymous()) {
174
                    calledType = Binding2JavaModel.find(calledTypeBinding,
175
                            fMethod.getJavaProject());
176
                } else {
177
                    calledType = Binding2JavaModel.find(calledTypeBinding.getInterfaces()[0],
178
                            fMethod.getJavaProject());
179
                }
180
181
                IMethod calledMethod = Binding2JavaModel.findIncludingSupertypes(calledMethodBinding,
182
                        calledType,
183
                        new SubProgressMonitor(fProgressMonitor, 100,
184
                            SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
185
186
                if ((calledMethod != null) && calledType.isInterface()) {
187
                    calledMethod = findImplementingMethods(calledMethod);
188
                }
189
190
                if (!isIgnoredBySearchScope(calledMethod)) {
191
                    fSearchResults.addMember(fMethod, calledMethod,
192
                        node.getStartPosition(),
193
                        node.getStartPosition() + node.getLength());
194
                }
195
            }
196
        } catch (JavaModelException jme) {
197
            Utility.logError("Error adding callee search result", jme);
198
        }
199
    }
200
201
    /**
202
     * @param enclosingElement
203
     *
204
     * @return
205
     */
206
    private boolean isIgnoredBySearchScope(IMethod enclosingElement) {
207
        if (enclosingElement != null) {
208
            return !getSearchScope().encloses(enclosingElement);
209
        } else {
210
            return false;
211
        }
212
    }
213
214
    private IJavaSearchScope getSearchScope() {
215
        return CallHierarchy.getDefault().getSearchScope();
216
    }
217
218
    private boolean isNodeWithinMethod(ASTNode node) {
219
        int nodeStartPosition = node.getStartPosition();
220
        int nodeEndPosition = nodeStartPosition + node.getLength();
221
222
        if (nodeStartPosition < fMethodStartPosition) {
223
            return false;
224
        }
225
226
        if (nodeEndPosition > fMethodEndPosition) {
227
            return false;
228
        }
229
230
        return true;
231
    }
232
233
    /**
234
     * @param calledMethod
235
     */
236
    private IMethod findImplementingMethods(IMethod calledMethod) {
237
        Collection implementingMethods = CallHierarchy.getDefault()
238
                                                        .getImplementingMethods(calledMethod);
239
240
        if ((implementingMethods.size() == 0) || (implementingMethods.size() > 1)) {
241
            return calledMethod;
242
        } else {
243
            return (IMethod) implementingMethods.iterator().next();
244
        }
245
    }
246
}
(-)core (+108 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2003 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-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.Arrays;
15
import java.util.Comparator;
16
import java.util.HashMap;
17
import java.util.Map;
18
19
import org.eclipse.core.runtime.IProgressMonitor;
20
import org.eclipse.jdt.core.ICompilationUnit;
21
import org.eclipse.jdt.core.IJavaElement;
22
import org.eclipse.jdt.core.IMethod;
23
import org.eclipse.jdt.core.dom.AST;
24
import org.eclipse.jdt.core.dom.CompilationUnit;
25
26
/**
27
 * @author jl
28
 */
29
class CalleeMethodWrapper extends MethodWrapper {
30
    private Comparator fMethodWrapperComparator = new MethodWrapperComparator();
31
32
    private class MethodWrapperComparator implements Comparator {
33
        /* (non-Javadoc)
34
         * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
35
         */
36
        public int compare(Object o1, Object o2) {
37
            MethodWrapper m1 = (MethodWrapper) o1;
38
            MethodWrapper m2 = (MethodWrapper) o2;
39
40
            CallLocation callLocation1 = m1.getMethodCall().getFirstCallLocation();
41
            CallLocation callLocation2 = m2.getMethodCall().getFirstCallLocation();
42
43
            if ((callLocation1 != null) && (callLocation2 != null)) {
44
                if (callLocation1.getStart() == callLocation2.getStart()) {
45
                    return callLocation1.getEnd() - callLocation2.getEnd();
46
                }
47
48
                return callLocation1.getStart() - callLocation2.getStart();
49
            }
50
51
            return 0;
52
        }
53
    }
54
55
    /**
56
     * Constructor for CalleeMethodWrapper.
57
     * @param parent
58
     * @param method
59
     */
60
    public CalleeMethodWrapper(MethodWrapper parent, MethodCall methodCall) {
61
        super(parent, methodCall);
62
    }
63
64
    /* Returns the calls sorted after the call location
65
     * @see dk.kamstruplinnet.callers.search.MethodWrapper#getCalls()
66
     */
67
    public MethodWrapper[] getCalls() {
68
        MethodWrapper[] result = super.getCalls();
69
        Arrays.sort(result, fMethodWrapperComparator);
70
71
        return result;
72
    }
73
74
    /* (non-Javadoc)
75
     * @see dk.kamstruplinnet.callers.search.MethodWrapper#getTaskName()
76
     */
77
    protected String getTaskName() {
78
        return null;
79
    }
80
81
    /**
82
     * @see dk.kamstruplinnet.callers.CallerMethodWrapper#createMethodWrapper(org.eclipse.jdt.core.IMethod)
83
     */
84
    protected MethodWrapper createMethodWrapper(MethodCall methodCall) {
85
        return new CalleeMethodWrapper(this, methodCall);
86
    }
87
88
    /**
89
     * Find callees called from the current method.
90
     * @see dk.kamstruplinnet.callers.MethodWrapper#findChildren()
91
     */
92
    protected Map findChildren(IProgressMonitor progressMonitor) {
93
        if (getMember().getElementType() == IJavaElement.METHOD) {
94
            CalleeAnalyzerVisitor visitor = new CalleeAnalyzerVisitor((IMethod) getMember(),
95
                    progressMonitor);
96
            ICompilationUnit icu = getMember().getCompilationUnit();
97
        
98
            if (icu != null) {
99
                CompilationUnit cu = AST.parseCompilationUnit(icu, true);
100
                cu.accept(visitor);
101
            }
102
        
103
            return visitor.getCallees();
104
        } else {
105
            return new HashMap();
106
        }
107
    }
108
}
(-)core (+93 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2003 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-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.ArrayList;
15
import java.util.Collection;
16
import java.util.HashMap;
17
import java.util.Iterator;
18
import java.util.Map;
19
20
import org.eclipse.core.resources.ResourcesPlugin;
21
import org.eclipse.core.runtime.IProgressMonitor;
22
import org.eclipse.core.runtime.SubProgressMonitor;
23
import org.eclipse.jdt.core.IJavaElement;
24
import org.eclipse.jdt.core.IMember;
25
import org.eclipse.jdt.core.IMethod;
26
import org.eclipse.jdt.core.JavaModelException;
27
import org.eclipse.jdt.core.search.IJavaSearchConstants;
28
import org.eclipse.jdt.core.search.IJavaSearchScope;
29
import org.eclipse.jdt.core.search.SearchEngine;
30
31
/**
32
 * @author jl
33
 */
34
class CallerMethodWrapper extends MethodWrapper {
35
    public CallerMethodWrapper(MethodWrapper parent, MethodCall methodCall) {
36
        super(parent, methodCall);
37
    }
38
39
    protected IJavaSearchScope getSearchScope() {
40
        return CallHierarchy.getDefault().getSearchScope();
41
    }
42
43
    protected String getTaskName() {
44
        return "Finding callers...";
45
    }
46
47
    /**
48
     * @see dk.kamstruplinnet.callers.CallerMethodWrapper#createMethodWrapper(org.eclipse.jdt.core.IMethod)
49
     */
50
    protected MethodWrapper createMethodWrapper(MethodCall methodCall) {
51
        return new CallerMethodWrapper(this, methodCall);
52
    }
53
54
    /**
55
     * @see dk.kamstruplinnet.callers.MethodWrapper#findChildren()
56
     * @return The result of the search for children
57
     */
58
    protected Map findChildren(IProgressMonitor progressMonitor) {
59
        try {
60
            MethodReferencesSearchCollector searchCollector = new MethodReferencesSearchCollector();
61
            SearchEngine searchEngine = new SearchEngine();
62
63
            for (Iterator iter = getMembers().iterator();
64
                        iter.hasNext() && !progressMonitor.isCanceled();) {
65
                IMember member = (IMember) iter.next();
66
                searchCollector.setProgressMonitor(new SubProgressMonitor(
67
                        progressMonitor, 10, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
68
                searchEngine.search(ResourcesPlugin.getWorkspace(), member,
69
                    IJavaSearchConstants.REFERENCES, getSearchScope(), searchCollector);
70
            }
71
72
            return searchCollector.getCallers();
73
        } catch (JavaModelException e) {
74
            Utility.logError("Error finding callers", e);
75
76
            return new HashMap(0);
77
        }
78
    }
79
80
    /**
81
     * Returns a collection of IMember instances representing what to search for 
82
     */
83
    private Collection getMembers() {
84
        Collection result = new ArrayList();
85
86
        result.add(getMember());
87
        if (getMember().getElementType() == IJavaElement.METHOD) {
88
            result.addAll(CallHierarchy.getDefault().getInterfaceMethods((IMethod) getMember()));
89
        }
90
91
        return result;
92
    }
93
}
(-)core (+73 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2003 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-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.ArrayList;
15
import java.util.Collection;
16
import java.util.List;
17
18
import org.eclipse.jdt.core.IMember;
19
20
/**
21
 * @author jl
22
 */
23
public class MethodCall {
24
    private IMember fMember;
25
    private List fCallLocations;
26
27
    /**
28
     * @param enclosingElement
29
     */
30
    public MethodCall(IMember enclosingElement) {
31
        this.fMember = enclosingElement;
32
    }
33
34
    /**
35
     *
36
     */
37
    public Collection getCallLocations() {
38
        return fCallLocations;
39
    }
40
41
    public CallLocation getFirstCallLocation() {
42
        if ((fCallLocations != null) && !fCallLocations.isEmpty()) {
43
            return (CallLocation) fCallLocations.get(0);
44
        } else {
45
            return null;
46
        }
47
    }
48
49
    /**
50
     * @return Object
51
     */
52
    public Object getKey() {
53
        return getMember().getHandleIdentifier();
54
    }
55
56
    /**
57
     *
58
     */
59
    public IMember getMember() {
60
        return fMember;
61
    }
62
63
    /**
64
     * @param location
65
     */
66
    public void addCallLocation(CallLocation location) {
67
        if (fCallLocations == null) {
68
            fCallLocations = new ArrayList();
69
        }
70
71
        fCallLocations.add(location);
72
    }
73
}
(-)core (+84 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2003 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-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;
15
16
import org.eclipse.core.resources.IResource;
17
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.runtime.IProgressMonitor;
19
import org.eclipse.core.runtime.SubProgressMonitor;
20
import org.eclipse.jdt.core.IJavaElement;
21
import org.eclipse.jdt.core.IMember;
22
import org.eclipse.jdt.core.search.IJavaSearchResultCollector;
23
24
/**
25
 * @author jl
26
 */
27
class MethodReferencesSearchCollector implements IJavaSearchResultCollector {
28
    private CallSearchResultCollector fSearchResults;
29
    private IProgressMonitor fProgressMonitor;
30
    private boolean fRequireExactMatch = true;
31
32
    MethodReferencesSearchCollector() {
33
        fSearchResults = new CallSearchResultCollector();
34
    }
35
36
    public Map getCallers() {
37
        return fSearchResults.getCallers();
38
    }
39
40
    /**
41
     * @see org.eclipse.jdt.core.search.IJavaSearchResultCollector#getProgressMonitor()
42
     */
43
    public IProgressMonitor getProgressMonitor() {
44
        return fProgressMonitor;
45
    }
46
47
    /**
48
     * @see org.eclipse.jdt.core.search.IJavaSearchResultCollector#aboutToStart()
49
     */
50
    public void aboutToStart() {}
51
52
    /**
53
     * @see org.eclipse.jdt.core.search.IJavaSearchResultCollector#accept(org.eclipse.core.resources.IResource, int, int, org.eclipse.jdt.core.IJavaElement, int)
54
     */
55
    public void accept(IResource resource, int start, int end,
56
        IJavaElement enclosingElement, int accuracy) throws CoreException {
57
        if (fRequireExactMatch && (accuracy != IJavaSearchResultCollector.EXACT_MATCH)) {
58
            return;
59
        }
60
61
        if (enclosingElement != null && enclosingElement instanceof IMember) {
62
            IMember member= (IMember) enclosingElement;
63
            switch (enclosingElement.getElementType()) {
64
                case IJavaElement.METHOD:
65
                case IJavaElement.TYPE:
66
                case IJavaElement.FIELD:
67
                    fSearchResults.addMember(member, member, start, end);
68
                    break;
69
            }
70
        }
71
    }
72
73
    /**
74
     * @see org.eclipse.jdt.core.search.IJavaSearchResultCollector#done()
75
     */
76
    public void done() {}
77
78
    /**
79
     * @param monitor
80
     */
81
    void setProgressMonitor(SubProgressMonitor monitor) {
82
        this.fProgressMonitor = monitor;
83
    }
84
}
(-)core (+331 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2003 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-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;
15
import java.util.Iterator;
16
import java.util.Map;
17
import org.eclipse.core.runtime.IAdaptable;
18
import org.eclipse.core.runtime.IProgressMonitor;
19
import org.eclipse.core.runtime.NullProgressMonitor;
20
import org.eclipse.jdt.core.IJavaElement;
21
import org.eclipse.jdt.core.IMember;
22
import org.eclipse.jdt.core.IMethod;
23
24
/**
25
 * This class represents the general parts of a method call (either to or from a
26
 * method).
27
 *
28
 * @author jl
29
 */
30
public abstract class MethodWrapper implements IAdaptable {
31
    private Map fElements = null;
32
33
    /*
34
     * A cache of previously found methods. This cache should be searched
35
     * before adding a "new" method object reference to the list of elements.
36
     * This way previously found methods won't be searched again.
37
     */
38
    private Map fMethodCache;
39
    private MethodCall fMethodCall;
40
    private MethodWrapper fParent;
41
    private int fLevel;
42
43
    /**
44
     * Constructor CallerElement.
45
     */
46
    public MethodWrapper(MethodWrapper parent, MethodCall methodCall) {
47
        super();
48
49
        if (methodCall == null) {
50
            throw new IllegalArgumentException("Parameter method cannot be null");
51
        }
52
53
        if (parent == null) {
54
            setMethodCache(new HashMap());
55
            fLevel = 1;
56
        } else {
57
            setMethodCache(parent.getMethodCache());
58
            fLevel = parent.getLevel() + 1;
59
        }
60
61
        this.fMethodCall = methodCall;
62
        this.fParent = parent;
63
    }
64
65
    public Object getAdapter(Class adapter) {
66
        if (adapter == IMethod.class) {
67
            if (getMember().getElementType() == IJavaElement.METHOD) {
68
                return getMember();
69
            } else {
70
                return null;
71
            }
72
        } else {
73
            if (IJavaElement.class.isAssignableFrom(adapter)) {
74
                return getMember();
75
            }
76
        }
77
78
        return null;
79
    }
80
81
    /**
82
     * Method getCallerElements.
83
     * @return The child caller elements of this element
84
     */
85
    public MethodWrapper[] getCalls() {
86
        if (fElements == null) {
87
            doFindChildren();
88
        }
89
90
        MethodWrapper[] result = new MethodWrapper[fElements.size()];
91
        int i = 0;
92
93
        for (Iterator iter = fElements.keySet().iterator(); iter.hasNext();) {
94
            MethodCall methodCall = getMethodCallFromMap(fElements, iter.next());
95
            result[i++] = createMethodWrapper(methodCall);
96
        }
97
98
        return result;
99
    }
100
101
    /**
102
     * @return int
103
     */
104
    public int getLevel() {
105
        return fLevel;
106
    }
107
108
    /**
109
     * Method getMethod.
110
     * @return Object
111
     */
112
    public IMember getMember() {
113
        return getMethodCall().getMember();
114
    }
115
116
    /**
117
     * @return MethodCall
118
     */
119
    public MethodCall getMethodCall() {
120
        return fMethodCall;
121
    }
122
123
    /**
124
     * Method getName.
125
     */
126
    public String getName() {
127
        if (getMethodCall() != null) {
128
            return getMethodCall().getMember().getElementName();
129
        } else {
130
            return "";
131
        }
132
    }
133
134
    /**
135
     * Method getParent.
136
     * @return
137
     */
138
    public MethodWrapper getParent() {
139
        return fParent;
140
    }
141
142
    public boolean equals(Object oth) {
143
        if (this == oth) {
144
            return true;
145
        }
146
147
        if (oth == null) {
148
            return false;
149
        }
150
151
        if (oth.getClass() != getClass()) {
152
            return false;
153
        }
154
155
        MethodWrapper other = (MethodWrapper) oth;
156
157
        if (this.fParent == null) {
158
            if (other.fParent != null) {
159
                return false;
160
            }
161
        } else {
162
            if (!this.fParent.equals(other.fParent)) {
163
                return false;
164
            }
165
        }
166
167
        if (this.getMethodCall() == null) {
168
            if (other.getMethodCall() != null) {
169
                return false;
170
            }
171
        } else {
172
            if (!this.getMethodCall().equals(other.getMethodCall())) {
173
                return false;
174
            }
175
        }
176
177
        return true;
178
    }
179
180
    public int hashCode() {
181
        final int PRIME = 1000003;
182
        int result = 0;
183
184
        if (fParent != null) {
185
            result = (PRIME * result) + fParent.hashCode();
186
        }
187
188
        if (getMethodCall() != null) {
189
            result = (PRIME * result) + getMethodCall().getMember().hashCode();
190
        }
191
192
        return result;
193
    }
194
195
    /**
196
     * @see java.lang.Object#toString()
197
     */
198
    public String toString() {
199
        String result;
200
201
        result = "CallerElement[name=" + getName() + ", children=";
202
203
        if (fElements == null) {
204
            result += "unknown]";
205
        } else {
206
            result += (fElements.size() + "]");
207
        }
208
209
        return result;
210
    }
211
212
    private void setMethodCache(Map methodCache) {
213
        fMethodCache = methodCache;
214
    }
215
216
    protected abstract String getTaskName();
217
218
    private void addCallToCache(MethodCall methodCall) {
219
        Map cachedCalls = lookupMethod(this.getMethodCall());
220
        cachedCalls.put(methodCall.getKey(), methodCall);
221
    }
222
223
    /**
224
     * Method createMethodWrapper.
225
     * @param method
226
     * @return MethodWrapper
227
     */
228
    protected abstract MethodWrapper createMethodWrapper(MethodCall methodCall);
229
230
    private void doFindChildren() {
231
        Map existingResults = lookupMethod(getMethodCall());
232
233
        if (existingResults != null) {
234
            fElements = new HashMap();
235
            fElements.putAll(existingResults);
236
        } else {
237
            initCalls();
238
239
            try {
240
                IProgressMonitor progressMonitor = getProgressMonitor();
241
242
                if (progressMonitor != null) {
243
                    progressMonitor.beginTask(getTaskName(), IProgressMonitor.UNKNOWN);
244
                }
245
246
                try {
247
                    performSearch(progressMonitor);
248
                } finally {
249
                    if (progressMonitor != null) {
250
                        progressMonitor.done();
251
                    }
252
                }
253
254
                //                ModalContext.run(getRunnableWithProgress(), true, getProgressMonitor(),
255
                //                    Display.getCurrent());
256
            } catch (Exception e) {
257
                Utility.logError("Error searching in modal context", e);
258
            }
259
        }
260
    }
261
262
    /**
263
     * Determines if the method represents a recursion call (i.e. whether the
264
     * method call is already in the cache.)
265
     *
266
     * @return True if the call is part of a recursion
267
     */
268
    public boolean isRecursive() {
269
        MethodWrapper current = getParent();
270
271
        while (current != null) {
272
            if (getMember().getHandleIdentifier().equals(current.getMember()
273
                                                                        .getHandleIdentifier())) {
274
                return true;
275
            }
276
277
            current = current.getParent();
278
        }
279
280
        return false;
281
    }
282
283
    /**
284
     * This method finds the children of the current IMethod (either callers or
285
     * callees, depending on the concrete subclass.
286
     * @return The result of the search for children
287
     */
288
    protected abstract Map findChildren(IProgressMonitor progressMonitor);
289
290
    private Map getMethodCache() {
291
        return fMethodCache;
292
    }
293
294
    private void initCalls() {
295
        this.fElements = new HashMap();
296
297
        initCacheForMethod();
298
    }
299
300
    /**
301
     * Looks up a previously created search result in the "global" cache.
302
     * @param method
303
     * @return List List of previously found search results
304
     */
305
    private Map lookupMethod(MethodCall methodCall) {
306
        return (Map) getMethodCache().get(methodCall.getKey());
307
    }
308
309
    private void performSearch(IProgressMonitor progressMonitor) {
310
        fElements = findChildren(progressMonitor);
311
312
        for (Iterator iter = fElements.keySet().iterator(); iter.hasNext();) {
313
            MethodCall methodCall = getMethodCallFromMap(fElements, iter.next());
314
            addCallToCache(methodCall);
315
        }
316
    }
317
318
    private MethodCall getMethodCallFromMap(Map elements, Object key) {
319
        return (MethodCall) elements.get(key);
320
    }
321
322
    private IProgressMonitor getProgressMonitor() {
323
        // TODO: Figure out what to do with progress monitors
324
        return new NullProgressMonitor();
325
    }
326
327
    private void initCacheForMethod() {
328
        Map cachedCalls = new HashMap();
329
        getMethodCache().put(this.getMethodCall().getKey(), cachedCalls);
330
    }
331
}
(-)ui/org/eclipse/jdt/internal/ui/callhierarchy/AbstractGotoActionDelegate.java (-154 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2003 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-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.ui.callhierarchy;
13
14
import org.eclipse.core.runtime.IProgressMonitor;
15
import org.eclipse.core.runtime.NullProgressMonitor;
16
17
import org.eclipse.swt.widgets.Shell;
18
19
import org.eclipse.jface.action.IAction;
20
import org.eclipse.jface.action.IStatusLineManager;
21
import org.eclipse.jface.viewers.ISelection;
22
23
import org.eclipse.ui.IEditorActionDelegate;
24
import org.eclipse.ui.IEditorPart;
25
import org.eclipse.ui.PartInitException;
26
27
import org.eclipse.jdt.core.IJavaElement;
28
import org.eclipse.jdt.core.JavaModelException;
29
30
import org.eclipse.jdt.internal.ui.JavaPlugin;
31
import org.eclipse.jdt.internal.ui.actions.OpenActionUtil;
32
import org.eclipse.jdt.internal.ui.actions.SelectionConverter;
33
import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor;
34
35
/**
36
 * @see IEditorActionDelegate
37
 */
38
public abstract class AbstractGotoActionDelegate implements IEditorActionDelegate {
39
    private IEditorPart fEditor;
40
41
    public AbstractGotoActionDelegate() {}
42
43
    /**
44
     * @see IEditorActionDelegate#setActiveEditor
45
     */
46
    public void setActiveEditor(IAction action, IEditorPart targetEditor) {
47
        this.fEditor = targetEditor;
48
    }
49
50
    /**
51
     * @see IEditorActionDelegate#run
52
     */
53
    public void run(IAction action) {
54
        clearErrorMessage();
55
56
        if (fEditor instanceof JavaEditor) {
57
            try {
58
                IJavaElement element = SelectionConverter.codeResolve((JavaEditor) fEditor,
59
                        getShell(), "Title - TODO", "Message - TODO");
60
61
                if (element != null) {
62
                    IJavaElement[] members = internalSearchForMembers(element,
63
                            getProgressMonitor());
64
65
                    if (members != null) {
66
                        if (members.length == 0) {
67
                            IJavaElement foundElement = OpenActionUtil.selectJavaElement(members,
68
                                    getShell(), getSelectMethodTitle(),
69
                                    getSelectMethodMessage());
70
71
                            if (foundElement != null) {
72
                                OpenActionUtil.open(foundElement, true);
73
                            }
74
                        } else {
75
                            showInfoMessage(getNoResultsMessage());
76
                        }
77
                    }
78
                }
79
            } catch (JavaModelException e) {
80
                Utility.logError("Error finding/jumping to method", e);
81
            } catch (PartInitException e) {
82
                Utility.logError("Error finding/jumping to method", e);
83
            }
84
        }
85
    }
86
87
    private Shell getShell() {
88
        return JavaPlugin.getActiveWorkbenchWindow().getShell();
89
    }
90
91
    /**
92
     * @see IEditorActionDelegate#selectionChanged
93
     */
94
    public void selectionChanged(IAction action, ISelection selection) {}
95
96
    protected abstract String getEmptySelectionMessage();
97
98
    protected abstract String getNoResultsMessage();
99
100
    protected abstract String getSelectMethodMessage();
101
102
    protected abstract String getSelectMethodTitle();
103
104
    protected abstract String getTaskName();
105
106
    protected IJavaElement[] internalSearchForMembers(IJavaElement element,
107
        IProgressMonitor progressMonitor) {
108
        if (progressMonitor == null) {
109
            progressMonitor = new NullProgressMonitor();
110
        }
111
112
        progressMonitor.beginTask(getTaskName(), IProgressMonitor.UNKNOWN);
113
114
        IJavaElement[] result = null;
115
116
        try {
117
            result = searchForMembers(element, progressMonitor);
118
        } finally {
119
            progressMonitor.done();
120
        }
121
122
        return result;
123
    }
124
125
    protected abstract IJavaElement[] searchForMembers(IJavaElement element,
126
        IProgressMonitor progressMonitor);
127
128
    private IProgressMonitor getProgressMonitor() {
129
        return new NullProgressMonitor();
130
131
        //        return getStatusLineManager().getProgressMonitor();
132
    }
133
134
    private IStatusLineManager getStatusLineManager() {
135
        IStatusLineManager statusLineManager = fEditor.getEditorSite().getActionBars()
136
                                                      .getStatusLineManager();
137
        statusLineManager.setCancelEnabled(true);
138
139
        return statusLineManager;
140
    }
141
142
    private void clearErrorMessage() {
143
        showErrorMessage(null);
144
    }
145
146
    private void showErrorMessage(String msg) {
147
        getStatusLineManager().setErrorMessage(msg);
148
    }
149
150
    private void showInfoMessage(String msg) {
151
        getStatusLineManager().setMessage(msg);
152
        clearErrorMessage();
153
    }
154
}
(-)ui/org/eclipse/jdt/internal/ui/callhierarchy/CallHierarchy.java (-346 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2003 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-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.ui.callhierarchy;
13
14
import java.util.ArrayList;
15
import java.util.Arrays;
16
import java.util.Collection;
17
import java.util.List;
18
import java.util.StringTokenizer;
19
20
import org.eclipse.core.runtime.IProgressMonitor;
21
import org.eclipse.core.runtime.IStatus;
22
import org.eclipse.core.runtime.NullProgressMonitor;
23
import org.eclipse.core.runtime.Status;
24
25
import org.eclipse.swt.widgets.Shell;
26
27
import org.eclipse.jface.action.IStatusLineManager;
28
import org.eclipse.jface.dialogs.ErrorDialog;
29
import org.eclipse.jface.dialogs.MessageDialog;
30
import org.eclipse.jface.preference.IPreferenceStore;
31
import org.eclipse.jface.util.IPropertyChangeListener;
32
import org.eclipse.jface.util.OpenStrategy;
33
import org.eclipse.jface.util.PropertyChangeEvent;
34
35
import org.eclipse.ui.IEditorPart;
36
import org.eclipse.ui.PartInitException;
37
import org.eclipse.ui.PlatformUI;
38
import org.eclipse.ui.texteditor.ITextEditor;
39
40
import org.eclipse.jdt.core.IJavaElement;
41
import org.eclipse.jdt.core.IMethod;
42
import org.eclipse.jdt.core.JavaModelException;
43
import org.eclipse.jdt.core.search.IJavaSearchScope;
44
import org.eclipse.jdt.core.search.SearchEngine;
45
46
import org.eclipse.jdt.ui.JavaUI;
47
48
import org.eclipse.jdt.internal.ui.IJavaStatusConstants;
49
import org.eclipse.jdt.internal.ui.JavaPlugin;
50
import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility;
51
52
import org.eclipse.jdt.internal.corext.callhierarchy.Implementors;
53
54
public class CallHierarchy implements IPropertyChangeListener {
55
    private static CallHierarchy fInstance;
56
    private IJavaSearchScope fSearchScope;
57
    private int fMaxCallDepth = -1;
58
59
    private CallHierarchy() {
60
        JavaPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(this);
61
    }
62
63
    public static CallHierarchy getDefault() {
64
        if (fInstance == null) {
65
            fInstance = new CallHierarchy();
66
        }
67
68
        return fInstance;
69
    }
70
71
    /**
72
     * Parses the comma separated string into an array of strings
73
     *
74
     * @return list
75
     */
76
    public static String[] parseList(String listString) {
77
        List list = new ArrayList(10);
78
        StringTokenizer tokenizer = new StringTokenizer(listString, ","); //$NON-NLS-1$
79
80
        while (tokenizer.hasMoreTokens()) {
81
            String token = tokenizer.nextToken();
82
            list.add(token);
83
        }
84
85
        return (String[]) list.toArray(new String[list.size()]);
86
    }
87
88
    /**
89
     * Returns filters for packages which should not be included in the search
90
     * results.
91
     * @return String[]
92
     */
93
    public String[] getIgnoreFilters() {
94
        IPreferenceStore settings = JavaPlugin.getDefault().getPreferenceStore();
95
96
        if (settings.getBoolean(ICallHierarchyPreferencesConstants.PREF_USE_FILTERS)) {
97
            String[] strings = CallHierarchy.parseList(settings.getString(
98
                        ICallHierarchyPreferencesConstants.PREF_ACTIVE_FILTERS_LIST));
99
100
            return strings;
101
        } else {
102
            return null;
103
        }
104
    }
105
106
    /**
107
     * Returns the maximum tree level allowed
108
     * @return int
109
     */
110
    public int getMaxCallDepth() {
111
        if (fMaxCallDepth == -1) {
112
            IPreferenceStore settings = JavaPlugin.getDefault().getPreferenceStore();
113
114
            fMaxCallDepth = settings.getInt(ICallHierarchyPreferencesConstants.PREF_MAX_CALL_DEPTH);
115
        }
116
117
        return fMaxCallDepth;
118
    }
119
120
    /**
121
     * @return
122
     */
123
    public IProgressMonitor getProgressMonitor() {
124
        //        IProgressMonitor progressMonitor = getStatusLineManager().getProgressMonitor();
125
        return new NullProgressMonitor();
126
    }
127
128
    /**
129
     * @return
130
     */
131
    public boolean isSearchForCalleesUsingImplementorsEnabled() {
132
        IPreferenceStore settings = JavaPlugin.getDefault().getPreferenceStore();
133
134
        return settings.getBoolean(ICallHierarchyPreferencesConstants.PREF_USE_IMPLEMENTORS_FOR_CALLEE_SEARCH);
135
    }
136
137
    /**
138
     * @return
139
     */
140
    public boolean isSearchForCallersUsingImplementorsEnabled() {
141
        IPreferenceStore settings = JavaPlugin.getDefault().getPreferenceStore();
142
143
        return settings.getBoolean(ICallHierarchyPreferencesConstants.PREF_USE_IMPLEMENTORS_FOR_CALLER_SEARCH);
144
    }
145
146
    public void setSearchScope(IJavaSearchScope searchScope) {
147
        this.fSearchScope = searchScope;
148
    }
149
150
    public IJavaSearchScope getSearchScope() {
151
        if (fSearchScope != null) {
152
            return fSearchScope;
153
        }
154
155
        Utility.logDebug("No search scope was set");
156
157
        return SearchEngine.createWorkspaceScope();
158
    }
159
160
    public void initializeDefaultBasePreferences(IPreferenceStore store) {
161
        store.setDefault(ICallHierarchyPreferencesConstants.PREF_MAX_CALL_DEPTH, 10);
162
        store.setDefault(ICallHierarchyPreferencesConstants.PREF_USE_IMPLEMENTORS_FOR_CALLER_SEARCH,
163
            false);
164
        store.setDefault(ICallHierarchyPreferencesConstants.PREF_USE_IMPLEMENTORS_FOR_CALLEE_SEARCH,
165
            false);
166
    }
167
168
    public void initializeDefaultFilterPreferences(IPreferenceStore store) {
169
        store.setDefault(ICallHierarchyPreferencesConstants.PREF_ACTIVE_FILTERS_LIST,
170
            "javax.*,java.*");
171
        store.setDefault(ICallHierarchyPreferencesConstants.PREF_INACTIVE_FILTERS_LIST,
172
            "com.ibm.*,com.sun.*,org.omg.*,sun.*,sunw.*"); //$NON-NLS-1$
173
        store.setDefault(ICallHierarchyPreferencesConstants.PREF_USE_FILTERS, true);
174
    }
175
176
    public void initializeDefaultPreferences(IPreferenceStore store) {
177
        initializeDefaultBasePreferences(store);
178
        initializeDefaultFilterPreferences(store);
179
    }
180
181
    /**
182
     * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(PropertyChangeEvent)
183
     */
184
    public void propertyChange(PropertyChangeEvent event) {
185
        if (event.getProperty().equals(ICallHierarchyPreferencesConstants.PREF_MAX_CALL_DEPTH)) {
186
            fMaxCallDepth = ((Integer) event.getNewValue()).intValue();
187
        }
188
    }
189
190
    /**
191
     * This method removes this class as a property change listener on the plugin's preference
192
     * store.
193
     *
194
     * TODO: Does this class ever receive shutdown messages?
195
     */
196
    public void shutdown() {
197
        JavaPlugin.getDefault().getPreferenceStore().removePropertyChangeListener(this);
198
    }
199
200
    private IStatusLineManager getStatusLineManager() {
201
        IStatusLineManager statusLineManager = PlatformUI.getWorkbench()
202
                                                         .getActiveWorkbenchWindow()
203
                                                         .getActivePage()
204
                                                         .findView(CallHierarchyViewPart.CALLERS_VIEW_ID)
205
                                                         .getViewSite().getActionBars()
206
                                                         .getStatusLineManager();
207
        statusLineManager.setCancelEnabled(true);
208
209
        return statusLineManager;
210
    }
211
212
    /**
213
     * @param method
214
     * @return
215
     */
216
    public Collection getInterfaceMethods(IMethod method) {
217
        if (isSearchForCallersUsingImplementorsEnabled()) {
218
            IJavaElement[] result = Implementors.getInstance().searchForInterfaces(new IJavaElement[] {
219
                        method
220
                    }, new NullProgressMonitor());
221
    
222
            if ((result != null) && (result.length > 0)) {
223
                return Arrays.asList(result);
224
            }
225
        }
226
    
227
        return new ArrayList(0);
228
    }
229
230
    /**
231
     * @param method
232
     * @return
233
     */
234
    public Collection getImplementingMethods(IMethod method) {
235
        if (isSearchForCalleesUsingImplementorsEnabled()) {
236
            IJavaElement[] result = Implementors.getInstance().searchForImplementors(new IJavaElement[] {
237
                        method
238
                    }, new NullProgressMonitor());
239
    
240
            if ((result != null) && (result.length > 0)) {
241
                return Arrays.asList(result);
242
            }
243
        }
244
    
245
        return new ArrayList(0);
246
    }
247
248
    public MethodWrapper getCallerRoot(IMethod method) {
249
        return new CallerMethodWrapper(null, new MethodCall(method));
250
    }
251
252
    public MethodWrapper getCalleeRoot(IMethod method) {
253
        return new CalleeMethodWrapper(null, new MethodCall(method));
254
    }
255
256
    public static void jumpToMember(IJavaElement element) {
257
        if (element != null) {
258
            try {
259
                IEditorPart methodEditor = EditorUtility.openInEditor(element, true);
260
                JavaUI.revealInEditor(methodEditor, (IJavaElement) element);
261
            } catch (JavaModelException e) {
262
                Utility.logError("Error getting underlying resource", e);
263
            } catch (PartInitException e) {
264
                Utility.logError("Error opening editor", e);
265
            }
266
        }
267
    }
268
269
    static CallLocation getCallLocation(Object element) {
270
        CallLocation callLocation = null;
271
272
        if (element instanceof MethodWrapper) {
273
            MethodWrapper methodWrapper = (MethodWrapper) element;
274
            MethodCall methodCall = methodWrapper.getMethodCall();
275
276
            if (methodCall != null) {
277
                callLocation = methodCall.getFirstCallLocation();
278
            }
279
        } else if (element instanceof CallLocation) {
280
            callLocation = (CallLocation) element;
281
        }
282
283
        return callLocation;
284
    }
285
286
    public static void openInEditor(Object element, Shell shell, String title) {
287
        CallLocation callLocation= null;
288
        if (element instanceof CallLocation) {
289
            callLocation= (CallLocation) element;
290
        } else if (element instanceof CallLocation) {
291
            callLocation= getCallLocation(element);
292
        }
293
294
        if (callLocation == null) {
295
            return;
296
        }
297
298
        try {
299
            boolean activateOnOpen = OpenStrategy.activateOnOpen();
300
301
            IEditorPart methodEditor = EditorUtility.openInEditor(callLocation.getMember(),
302
                    activateOnOpen);
303
304
            if (methodEditor instanceof ITextEditor) {
305
                ITextEditor editor = (ITextEditor) methodEditor;
306
                editor.selectAndReveal(callLocation.getStart(),
307
                    (callLocation.getEnd() - callLocation.getStart()));
308
            }
309
        } catch (JavaModelException e) {
310
            JavaPlugin.log(new Status(IStatus.ERROR, JavaPlugin.getPluginId(),
311
                    IJavaStatusConstants.INTERNAL_ERROR,
312
                    CallHierarchyMessages.getString(
313
                        "CallHierarchy.open_in_editor.error.message"), e)); //$NON-NLS-1$
314
315
            ErrorDialog.openError(shell, title,
316
                CallHierarchyMessages.getString(
317
                    "CallHierarchy.open_in_editor.error.messageProblems"), //$NON-NLS-1$
318
                e.getStatus());
319
        } catch (PartInitException x) {
320
            String name = callLocation.getCalledMember().getElementName();
321
            MessageDialog.openError(shell,
322
                CallHierarchyMessages.getString(
323
                    "CallHierarchy.open_in_editor.error.messageProblems"), //$NON-NLS-1$
324
                CallHierarchyMessages.getFormattedString(
325
                    "CallHierarchy.open_in_editor.error.messageArgs", //$NON-NLS-1$
326
                    new String[] { name, x.getMessage() }));
327
        }
328
    }
329
330
    /**
331
     * @param elem
332
     * @return
333
     */
334
    public static IEditorPart isOpenInEditor(Object elem) {
335
        IJavaElement javaElement= null;
336
        if (elem instanceof MethodWrapper) {
337
            javaElement= ((MethodWrapper) elem).getMember();
338
        } else if (elem instanceof CallLocation) {
339
            javaElement= ((CallLocation) elem).getCalledMember();
340
        }
341
        if (javaElement != null) {
342
            return EditorUtility.isOpenInEditor(javaElement);
343
        }
344
        return null;
345
    }
346
}
(-)ui/org/eclipse/jdt/internal/ui/callhierarchy/CallHierarchyContentProvider.java (-3 / +3 lines)
Lines 11-22 Link Here
11
 ******************************************************************************/
11
 ******************************************************************************/
12
package org.eclipse.jdt.internal.ui.callhierarchy;
12
package org.eclipse.jdt.internal.ui.callhierarchy;
13
13
14
import org.eclipse.jdt.core.IJavaElement;
15
import org.eclipse.jdt.internal.corext.callhierarchy.MethodWrapper;
14
import org.eclipse.jface.viewers.ITreeContentProvider;
16
import org.eclipse.jface.viewers.ITreeContentProvider;
15
import org.eclipse.jface.viewers.TreeViewer;
17
import org.eclipse.jface.viewers.TreeViewer;
16
import org.eclipse.jface.viewers.Viewer;
18
import org.eclipse.jface.viewers.Viewer;
17
19
18
import org.eclipse.jdt.core.IJavaElement;
19
20
class CallHierarchyContentProvider implements ITreeContentProvider {
20
class CallHierarchyContentProvider implements ITreeContentProvider {
21
    private final static Object[] EMPTY_ARRAY = new Object[0];
21
    private final static Object[] EMPTY_ARRAY = new Object[0];
22
    private TreeViewer fViewer;
22
    private TreeViewer fViewer;
Lines 59-65 Link Here
59
    }
59
    }
60
60
61
    private boolean isMaxCallDepthExceeded(MethodWrapper methodWrapper) {
61
    private boolean isMaxCallDepthExceeded(MethodWrapper methodWrapper) {
62
        return methodWrapper.getLevel() > CallHierarchy.getDefault().getMaxCallDepth();
62
        return methodWrapper.getLevel() > CallHierarchyUI.getDefault().getMaxCallDepth();
63
    }
63
    }
64
64
65
    /**
65
    /**
(-)ui/org/eclipse/jdt/internal/ui/callhierarchy/CallHierarchyFiltersActionGroup.java (+94 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2003 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-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.ui.callhierarchy;
13
14
import org.eclipse.jdt.internal.ui.JavaPluginImages;
15
import org.eclipse.jface.action.Action;
16
import org.eclipse.jface.action.IMenuManager;
17
import org.eclipse.jface.action.IToolBarManager;
18
import org.eclipse.jface.action.Separator;
19
import org.eclipse.jface.util.Assert;
20
import org.eclipse.jface.viewers.StructuredViewer;
21
import org.eclipse.ui.IActionBars;
22
import org.eclipse.ui.IViewPart;
23
import org.eclipse.ui.actions.ActionGroup;
24
25
/**
26
 * Action group to add the filter action to a view part's toolbar
27
 * menu.
28
 * <p>
29
 * This class may be instantiated; it is not intended to be subclassed.
30
 * </p>
31
 * 
32
 * @since 2.0
33
 */
34
public class CallHierarchyFiltersActionGroup extends ActionGroup {
35
36
    class ShowFilterDialogAction extends Action {
37
        ShowFilterDialogAction() {
38
            setText(CallHierarchyMessages.getString("ShowFilterDialogAction.text")); //$NON-NLS-1$
39
            setImageDescriptor(JavaPluginImages.DESC_CLCL_FILTER);
40
        }
41
        
42
        public void run() {
43
            openDialog();
44
        }
45
    }
46
47
    private IViewPart fPart;
48
    private StructuredViewer fViewer;
49
50
    /**
51
     * Creates a new <code>CustomFiltersActionGroup</code>.
52
     * 
53
     * @param part      the view part that owns this action group
54
     * @param viewer    the viewer to be filtered
55
     */
56
    public CallHierarchyFiltersActionGroup(IViewPart part, StructuredViewer viewer) {
57
        Assert.isNotNull(part);
58
        Assert.isNotNull(viewer);
59
        fPart= part;
60
        fViewer= viewer;
61
    }
62
63
    /* (non-Javadoc)
64
     * Method declared on ActionGroup.
65
     */
66
    public void fillActionBars(IActionBars actionBars) {
67
        fillToolBar(actionBars.getToolBarManager());
68
        fillViewMenu(actionBars.getMenuManager());
69
    }
70
71
    private void fillToolBar(IToolBarManager toolBar) {
72
    }
73
74
    private void fillViewMenu(IMenuManager viewMenu) {
75
        viewMenu.add(new Separator("filters")); //$NON-NLS-1$
76
        viewMenu.add(new ShowFilterDialogAction());
77
    }
78
79
    /* (non-Javadoc)
80
     * Method declared on ActionGroup.
81
     */
82
    public void dispose() {
83
        super.dispose();
84
    }
85
    
86
    // ---------- dialog related code ----------
87
88
    private void openDialog() {
89
        FiltersDialog dialog= new FiltersDialog(
90
            fPart.getViewSite().getShell());
91
        
92
        dialog.open();
93
    }
94
}
(-)ui/org/eclipse/jdt/internal/ui/callhierarchy/CallHierarchyLabelProvider.java (-4 / +3 lines)
Lines 13-23 Link Here
13
13
14
import java.util.Collection;
14
import java.util.Collection;
15
15
16
import org.eclipse.swt.graphics.Image;
16
import org.eclipse.jdt.internal.corext.callhierarchy.MethodWrapper;
17
18
import org.eclipse.jface.viewers.LabelProvider;
19
20
import org.eclipse.jdt.ui.JavaElementLabelProvider;
17
import org.eclipse.jdt.ui.JavaElementLabelProvider;
18
import org.eclipse.jface.viewers.LabelProvider;
19
import org.eclipse.swt.graphics.Image;
21
20
22
class CallHierarchyLabelProvider extends LabelProvider {
21
class CallHierarchyLabelProvider extends LabelProvider {
23
    private JavaElementLabelProvider fJavaElementLabelProvider = new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_BASICS);
22
    private JavaElementLabelProvider fJavaElementLabelProvider = new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_BASICS);
(-)ui/org/eclipse/jdt/internal/ui/callhierarchy/CallHierarchyMessages.properties (-19 / +7 lines)
Lines 10-33 Link Here
10
# 			(report 36180: Callers/Callees view)
10
# 			(report 36180: Callers/Callees view)
11
###############################################################################
11
###############################################################################
12
12
13
CallHierarchyPreferenceFilterPage.description=Filters
14
CallHierarchyPreferenceFilterPage.use.package.filters=Use package filters
15
CallHierarchyPreferenceFilterPage.defined.package.filters=Defined package filters
16
CallHierarchyPreferenceFilterPage.add.filter=Add filter
17
CallHierarchyPreferenceFilterPage.add.filter.tooltip=Add filter (tooltip)
18
CallHierarchyPreferenceFilterPage.add.package=Add package
19
CallHierarchyPreferenceFilterPage.add.package.tooltip=Add package (tooltip)
20
CallHierarchyPreferenceFilterPage.remove.filter=Remove filter
21
CallHierarchyPreferenceFilterPage.remove.filter.tooltip=Remove filter (tooltip)
22
CallHierarchyPreferenceFilterPage.enable.all=Enable all
23
CallHierarchyPreferenceFilterPage.enable.all.tooltip=Enable all (tooltip)
24
CallHierarchyPreferenceFilterPage.disable.all=Disable all
25
CallHierarchyPreferenceFilterPage.disable.all.tooltip=Disable all (tooltip)
26
CallHierarchyPreferenceFilterPage.invalid.input=Invalid input
27
CallHierarchyPreferenceFilterPage.addpackagedialog.title=addpackagedialog.title
28
CallHierarchyPreferenceFilterPage.addpackagedialog.error.message=addpackagedialog.error.message
29
CallHierarchyPreferenceFilterPage.addpackagedialog.message=addpackagedialog.message
30
CallHierarchyPreferenceFilterPage.label.defaultpackage=label.defaultpackage
31
CallHierarchyViewPart.empty=No method has been selected.
13
CallHierarchyViewPart.empty=No method has been selected.
32
ToggleCallModeAction.callers.tooltip=Show the Caller Hierarchy
14
ToggleCallModeAction.callers.tooltip=Show the Caller Hierarchy
33
ToggleCallModeAction.callers.label=Caller Hierarchy
15
ToggleCallModeAction.callers.label=Caller Hierarchy
Lines 39-42 Link Here
39
ToggleJavaLabelFormatAction.long.label=Long format
21
ToggleJavaLabelFormatAction.long.label=Long format
40
ToggleOrientationAction.vertical.label=Vertical View Orientation
22
ToggleOrientationAction.vertical.label=Vertical View Orientation
41
ToggleOrientationAction.horizontal.label=Horizontal View Orientation
23
ToggleOrientationAction.horizontal.label=Horizontal View Orientation
42
ToggleOrientationAction.single.label=Hierarchy View Only
24
ToggleOrientationAction.single.label=Hierarchy View Only
25
ShowFilterDialogAction.text= &Filters...
26
FiltersDialog.filter= Filter Calls
27
FiltersDialog.filterOnNames= Filter on path names:
28
FiltersDialog.maxCallDepth= Max call depth:
29
FiltersDialog.titleMaxCallDepthInvalid= Error
30
FiltersDialog.messageMaxCallDepthInvalid= The max call depth must be in range [1..99]
(-)ui/org/eclipse/jdt/internal/ui/callhierarchy/CallHierarchyPreferenceBasePage.java (-15 / +2 lines)
Lines 11-26 Link Here
11
 ******************************************************************************/
11
 ******************************************************************************/
12
package org.eclipse.jdt.internal.ui.callhierarchy;
12
package org.eclipse.jdt.internal.ui.callhierarchy;
13
13
14
import org.eclipse.jdt.internal.ui.JavaPlugin;
14
import org.eclipse.jface.preference.BooleanFieldEditor;
15
import org.eclipse.jface.preference.BooleanFieldEditor;
15
import org.eclipse.jface.preference.FieldEditorPreferencePage;
16
import org.eclipse.jface.preference.FieldEditorPreferencePage;
16
import org.eclipse.jface.preference.IPreferenceStore;
17
import org.eclipse.jface.preference.IPreferenceStore;
17
import org.eclipse.jface.preference.IntegerFieldEditor;
18
19
import org.eclipse.ui.IWorkbench;
18
import org.eclipse.ui.IWorkbench;
20
import org.eclipse.ui.IWorkbenchPreferencePage;
19
import org.eclipse.ui.IWorkbenchPreferencePage;
21
20
22
import org.eclipse.jdt.internal.ui.JavaPlugin;
23
24
/**
21
/**
25
 * @see PreferencePage
22
 * @see PreferencePage
26
 */
23
 */
Lines 43-60 Link Here
43
     * Set the default preferences for this page.
40
     * Set the default preferences for this page.
44
     */
41
     */
45
    public static void initDefaults(IPreferenceStore store) {
42
    public static void initDefaults(IPreferenceStore store) {
46
        CallHierarchy.getDefault().initializeDefaultBasePreferences(store);
43
        CallHierarchyUI.getDefault().initializeDefaultBasePreferences(store);
47
    }
44
    }
48
45
49
    /* (non-Javadoc)
46
    /* (non-Javadoc)
50
     * @see org.eclipse.jface.preference.FieldEditorPreferencePage#createFieldEditors()
47
     * @see org.eclipse.jface.preference.FieldEditorPreferencePage#createFieldEditors()
51
     */
48
     */
52
    protected void createFieldEditors() {
49
    protected void createFieldEditors() {
53
        IntegerFieldEditor maxCallDepth = new IntegerFieldEditor(ICallHierarchyPreferencesConstants.PREF_MAX_CALL_DEPTH,
54
                "&Max call depth", getFieldEditorParent());
55
        maxCallDepth.setValidRange(1, 99);
56
        addField(maxCallDepth);
57
58
        BooleanFieldEditor useImplementorsForCallerSearch = new BooleanFieldEditor(ICallHierarchyPreferencesConstants.PREF_USE_IMPLEMENTORS_FOR_CALLER_SEARCH,
50
        BooleanFieldEditor useImplementorsForCallerSearch = new BooleanFieldEditor(ICallHierarchyPreferencesConstants.PREF_USE_IMPLEMENTORS_FOR_CALLER_SEARCH,
59
                "Search for &callers using the Implementors plugin",
51
                "Search for &callers using the Implementors plugin",
60
                getFieldEditorParent());
52
                getFieldEditorParent());
Lines 64-73 Link Here
64
                "Sea&rch for callees using the Implementors plugin",
56
                "Sea&rch for callees using the Implementors plugin",
65
                getFieldEditorParent());
57
                getFieldEditorParent());
66
        addField(useImplementorsForCalleeSearch);
58
        addField(useImplementorsForCalleeSearch);
67
68
        // This should be reenabled when the openInEditor(Object, boolean) method is made API.
69
        //        BooleanFieldEditor activateEditorOnSelect = new BooleanFieldEditor(ICallersConstants.PREF_ACTIVATE_EDITOR_ON_SELECT,
70
        //                "&Activate editor on select", getFieldEditorParent());
71
        //        addField(activateEditorOnSelect);
72
    }
59
    }
73
}
60
}
(-)ui/org/eclipse/jdt/internal/ui/callhierarchy/CallHierarchyUI.java (+168 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2003 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-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.ui.callhierarchy;
13
14
import org.eclipse.core.runtime.IStatus;
15
import org.eclipse.core.runtime.Status;
16
import org.eclipse.jdt.core.IJavaElement;
17
import org.eclipse.jdt.core.JavaModelException;
18
import org.eclipse.jdt.internal.corext.callhierarchy.CallHierarchy;
19
import org.eclipse.jdt.internal.corext.callhierarchy.CallLocation;
20
import org.eclipse.jdt.internal.corext.callhierarchy.MethodWrapper;
21
import org.eclipse.jdt.internal.ui.IJavaStatusConstants;
22
import org.eclipse.jdt.internal.ui.JavaPlugin;
23
import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility;
24
import org.eclipse.jdt.ui.JavaUI;
25
import org.eclipse.jface.action.IStatusLineManager;
26
import org.eclipse.jface.dialogs.ErrorDialog;
27
import org.eclipse.jface.dialogs.MessageDialog;
28
import org.eclipse.jface.preference.IPreferenceStore;
29
import org.eclipse.jface.util.OpenStrategy;
30
import org.eclipse.swt.widgets.Shell;
31
import org.eclipse.ui.IEditorPart;
32
import org.eclipse.ui.PartInitException;
33
import org.eclipse.ui.PlatformUI;
34
import org.eclipse.ui.texteditor.ITextEditor;
35
36
/**
37
 * @author jl
38
 */
39
class CallHierarchyUI {
40
    private static final int DEFAULT_MAX_CALL_DEPTH= 10;    
41
    private static final String PREF_MAX_CALL_DEPTH = "PREF_MAX_CALL_DEPTH";
42
43
    private static CallHierarchyUI fgInstance;
44
45
    private CallHierarchyUI() { }
46
47
    public static CallHierarchyUI getDefault() {
48
        if (fgInstance == null) {
49
            fgInstance = new CallHierarchyUI();
50
        }
51
52
        return fgInstance;
53
    }
54
55
    /**
56
     * Returns the maximum tree level allowed
57
     * @return int
58
     */
59
    public int getMaxCallDepth() {
60
        int maxCallDepth;
61
        
62
        IPreferenceStore settings = JavaPlugin.getDefault().getPreferenceStore();
63
        maxCallDepth = settings.getInt(PREF_MAX_CALL_DEPTH);
64
        if (maxCallDepth < 1 || maxCallDepth > 99) {
65
            maxCallDepth= DEFAULT_MAX_CALL_DEPTH;
66
        }
67
68
        return maxCallDepth;
69
    }
70
71
    public void setMaxCallDepth(int maxCallDepth) {
72
        IPreferenceStore settings = JavaPlugin.getDefault().getPreferenceStore();
73
        settings.setValue(PREF_MAX_CALL_DEPTH, maxCallDepth);
74
    }
75
    
76
    public void initializeDefaultBasePreferences(IPreferenceStore store) {
77
        store.setDefault(ICallHierarchyPreferencesConstants.PREF_USE_IMPLEMENTORS_FOR_CALLER_SEARCH,
78
            false);
79
        store.setDefault(ICallHierarchyPreferencesConstants.PREF_USE_IMPLEMENTORS_FOR_CALLEE_SEARCH,
80
            false);
81
    }
82
83
    private IStatusLineManager getStatusLineManager() {
84
        IStatusLineManager statusLineManager = PlatformUI.getWorkbench()
85
                                                         .getActiveWorkbenchWindow()
86
                                                         .getActivePage()
87
                                                         .findView(CallHierarchyViewPart.CALLERS_VIEW_ID)
88
                                                         .getViewSite().getActionBars()
89
                                                         .getStatusLineManager();
90
        statusLineManager.setCancelEnabled(true);
91
92
        return statusLineManager;
93
    }
94
95
    public static void jumpToMember(IJavaElement element) {
96
        if (element != null) {
97
            try {
98
                IEditorPart methodEditor = EditorUtility.openInEditor(element, true);
99
                JavaUI.revealInEditor(methodEditor, (IJavaElement) element);
100
            } catch (JavaModelException e) {
101
                Utility.logError("Error getting underlying resource", e);
102
            } catch (PartInitException e) {
103
                Utility.logError("Error opening editor", e);
104
            }
105
        }
106
    }
107
108
    public static void openInEditor(Object element, Shell shell, String title) {
109
        CallLocation callLocation= null;
110
        if (element instanceof CallLocation) {
111
            callLocation= (CallLocation) element;
112
        } else if (element instanceof CallLocation) {
113
            callLocation= CallHierarchy.getCallLocation(element);
114
        }
115
116
        if (callLocation == null) {
117
            return;
118
        }
119
120
        try {
121
            boolean activateOnOpen = OpenStrategy.activateOnOpen();
122
123
            IEditorPart methodEditor = EditorUtility.openInEditor(callLocation.getMember(),
124
                    activateOnOpen);
125
126
            if (methodEditor instanceof ITextEditor) {
127
                ITextEditor editor = (ITextEditor) methodEditor;
128
                editor.selectAndReveal(callLocation.getStart(),
129
                    (callLocation.getEnd() - callLocation.getStart()));
130
            }
131
        } catch (JavaModelException e) {
132
            JavaPlugin.log(new Status(IStatus.ERROR, JavaPlugin.getPluginId(),
133
                    IJavaStatusConstants.INTERNAL_ERROR,
134
                    CallHierarchyMessages.getString(
135
                        "CallHierarchyUI.open_in_editor.error.message"), e)); //$NON-NLS-1$
136
137
            ErrorDialog.openError(shell, title,
138
                CallHierarchyMessages.getString(
139
                    "CallHierarchyUI.open_in_editor.error.messageProblems"), //$NON-NLS-1$
140
                e.getStatus());
141
        } catch (PartInitException x) {
142
            String name = callLocation.getCalledMember().getElementName();
143
            MessageDialog.openError(shell,
144
                CallHierarchyMessages.getString(
145
                    "CallHierarchyUI.open_in_editor.error.messageProblems"), //$NON-NLS-1$
146
                CallHierarchyMessages.getFormattedString(
147
                    "CallHierarchyUI.open_in_editor.error.messageArgs", //$NON-NLS-1$
148
                    new String[] { name, x.getMessage() }));
149
        }
150
    }
151
152
    /**
153
     * @param elem
154
     * @return
155
     */
156
    public static IEditorPart isOpenInEditor(Object elem) {
157
        IJavaElement javaElement= null;
158
        if (elem instanceof MethodWrapper) {
159
            javaElement= ((MethodWrapper) elem).getMember();
160
        } else if (elem instanceof CallLocation) {
161
            javaElement= ((CallLocation) elem).getCalledMember();
162
        }
163
        if (javaElement != null) {
164
            return EditorUtility.isOpenInEditor(javaElement);
165
        }
166
        return null;
167
    }
168
}
(-)ui/org/eclipse/jdt/internal/ui/callhierarchy/CallHierarchyViewPart.java (-90 / +94 lines)
Lines 1-28 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2003 IBM Corporation and others.
2
 * Copyright (c) 2000, 2003 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Common Public License v1.0
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *   Jesper Kamstrup Linnet (eclipse@kamstrup-linnet.dk) - initial API and implementation 
9
 *   Jesper Kamstrup Linnet (eclipse@kamstrup-linnet.dk) - initial API and implementation
10
 * 			(report 36180: Callers/Callees view)
10
 *             (report 36180: Callers/Callees view)
11
 ******************************************************************************/
11
 ******************************************************************************/
12
package org.eclipse.jdt.internal.ui.callhierarchy;
12
package org.eclipse.jdt.internal.ui.callhierarchy;
13
13
14
import java.util.ArrayList;
14
import java.util.ArrayList;
15
import java.util.List;
15
import java.util.List;
16
16
17
import org.eclipse.swt.SWT;
17
import org.eclipse.jdt.core.IJavaElement;
18
import org.eclipse.swt.custom.SashForm;
18
import org.eclipse.jdt.core.IMember;
19
import org.eclipse.swt.events.KeyAdapter;
19
import org.eclipse.jdt.core.IMethod;
20
import org.eclipse.swt.events.KeyEvent;
20
import org.eclipse.jdt.core.JavaModelException;
21
import org.eclipse.swt.events.KeyListener;
21
import org.eclipse.jdt.core.search.IJavaSearchScope;
22
import org.eclipse.swt.widgets.Composite;
22
import org.eclipse.jdt.internal.corext.callhierarchy.CallHierarchy;
23
import org.eclipse.swt.widgets.Label;
23
import org.eclipse.jdt.internal.corext.callhierarchy.CallLocation;
24
import org.eclipse.swt.widgets.Menu;
24
import org.eclipse.jdt.internal.corext.callhierarchy.MethodWrapper;
25
25
import org.eclipse.jdt.internal.ui.JavaPlugin;
26
import org.eclipse.jdt.internal.ui.actions.CompositeActionGroup;
27
import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility;
28
import org.eclipse.jdt.internal.ui.viewsupport.StatusBarUpdater;
29
import org.eclipse.jdt.ui.IContextMenuConstants;
30
import org.eclipse.jdt.ui.JavaElementLabelProvider;
31
import org.eclipse.jdt.ui.actions.OpenViewActionGroup;
32
import org.eclipse.jdt.ui.actions.RefactorActionGroup;
26
import org.eclipse.jface.action.IMenuListener;
33
import org.eclipse.jface.action.IMenuListener;
27
import org.eclipse.jface.action.IMenuManager;
34
import org.eclipse.jface.action.IMenuManager;
28
import org.eclipse.jface.action.IStatusLineManager;
35
import org.eclipse.jface.action.IStatusLineManager;
Lines 41-47 Link Here
41
import org.eclipse.jface.viewers.OpenEvent;
48
import org.eclipse.jface.viewers.OpenEvent;
42
import org.eclipse.jface.viewers.SelectionChangedEvent;
49
import org.eclipse.jface.viewers.SelectionChangedEvent;
43
import org.eclipse.jface.viewers.Viewer;
50
import org.eclipse.jface.viewers.Viewer;
44
51
import org.eclipse.swt.SWT;
52
import org.eclipse.swt.custom.SashForm;
53
import org.eclipse.swt.events.KeyAdapter;
54
import org.eclipse.swt.events.KeyEvent;
55
import org.eclipse.swt.events.KeyListener;
56
import org.eclipse.swt.widgets.Composite;
57
import org.eclipse.swt.widgets.Label;
58
import org.eclipse.swt.widgets.Menu;
45
import org.eclipse.ui.IActionBars;
59
import org.eclipse.ui.IActionBars;
46
import org.eclipse.ui.IEditorPart;
60
import org.eclipse.ui.IEditorPart;
47
import org.eclipse.ui.IMemento;
61
import org.eclipse.ui.IMemento;
Lines 55-77 Link Here
55
import org.eclipse.ui.part.ViewPart;
69
import org.eclipse.ui.part.ViewPart;
56
import org.eclipse.ui.texteditor.ITextEditor;
70
import org.eclipse.ui.texteditor.ITextEditor;
57
71
58
import org.eclipse.jdt.core.IJavaElement;
59
import org.eclipse.jdt.core.IMember;
60
import org.eclipse.jdt.core.IMethod;
61
import org.eclipse.jdt.core.JavaModelException;
62
import org.eclipse.jdt.core.search.IJavaSearchScope;
63
64
import org.eclipse.jdt.ui.IContextMenuConstants;
65
import org.eclipse.jdt.ui.JavaElementLabelProvider;
66
import org.eclipse.jdt.ui.actions.CustomFiltersActionGroup;
67
import org.eclipse.jdt.ui.actions.OpenViewActionGroup;
68
import org.eclipse.jdt.ui.actions.RefactorActionGroup;
69
70
import org.eclipse.jdt.internal.ui.JavaPlugin;
71
import org.eclipse.jdt.internal.ui.actions.CompositeActionGroup;
72
import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility;
73
import org.eclipse.jdt.internal.ui.viewsupport.StatusBarUpdater;
74
75
/**
72
/**
76
 * This is the main view for the callers plugin. It builds a tree of callers/callees
73
 * This is the main view for the callers plugin. It builds a tree of callers/callees
77
 * and allows the user to double click an entry to go to the selected method.
74
 * and allows the user to double click an entry to go to the selected method.
Lines 109-129 Link Here
109
    private int fCurrentOrientation;
106
    private int fCurrentOrientation;
110
    private int fCurrentCallMode;
107
    private int fCurrentCallMode;
111
    private int fCurrentJavaLabelFormat;
108
    private int fCurrentJavaLabelFormat;
112
    private CalleeMethodWrapper fCalleeRoot;
109
    private MethodWrapper fCalleeRoot;
113
    private CallerMethodWrapper fCallerRoot;
110
    private MethodWrapper fCallerRoot;
114
    private IMemento fMemento;
111
    private IMemento fMemento;
115
    private IMethod fShownMethod;
112
    private IMethod fShownMethod;
116
    private SelectionProviderMediator fSelectionProviderMediator;
113
    private SelectionProviderMediator fSelectionProviderMediator;
117
    private List fMethodHistory;
114
    private List fMethodHistory;
118
    private ListViewer fLocationViewer;
115
    private ListViewer fLocationViewer;
119
    private Menu fListContextMenu;
116
    private Menu fLocationContextMenu;
120
    private Menu fTreeContextMenu;
117
    private Menu fTreeContextMenu;
121
    private SashForm fHierarchyLocationSplitter;
118
    private SashForm fHierarchyLocationSplitter;
122
    private SearchScopeActionGroup fSearchScopeActions;
119
    private SearchScopeActionGroup fSearchScopeActions;
123
    private ToggleOrientationAction[] fToggleOrientationActions;
120
    private ToggleOrientationAction[] fToggleOrientationActions;
124
    private ToggleCallModeAction[] fToggleCallModeActions;
121
    private ToggleCallModeAction[] fToggleCallModeActions;
125
    private ToggleJavaLabelFormatAction[] fToggleJavaLabelFormatActions;
122
    private ToggleJavaLabelFormatAction[] fToggleJavaLabelFormatActions;
126
    private CustomFiltersActionGroup fCustomFiltersActionGroup;
123
    private CallHierarchyFiltersActionGroup fFiltersActionGroup;
127
    private HistoryDropDownAction fHistoryDropDownAction;
124
    private HistoryDropDownAction fHistoryDropDownAction;
128
    private RefreshAction fRefreshAction;
125
    private RefreshAction fRefreshAction;
129
    private OpenDeclarationAction fOpenDeclarationAction;
126
    private OpenDeclarationAction fOpenDeclarationAction;
Lines 175-181 Link Here
175
     */
172
     */
176
    public void setMethod(IMethod method) {
173
    public void setMethod(IMethod method) {
177
        if (method == null) {
174
        if (method == null) {
178
            fPagebook.showPage(fNoHierarchyShownLabel);
175
            showPage(PAGE_EMPTY);
179
176
180
            return;
177
            return;
181
        }
178
        }
Lines 285-294 Link Here
285
282
286
        showPage(PAGE_EMPTY);
283
        showPage(PAGE_EMPTY);
287
284
288
        fSelectionProviderMediator= new SelectionProviderMediator(new Viewer[] { fCallHierarchyViewer, fLocationViewer });
285
        fSelectionProviderMediator = new SelectionProviderMediator(new Viewer[] {
286
                    fCallHierarchyViewer, fLocationViewer
287
                });
289
288
290
        IStatusLineManager slManager= getViewSite().getActionBars().getStatusLineManager();
289
        IStatusLineManager slManager = getViewSite().getActionBars().getStatusLineManager();
291
        fSelectionProviderMediator.addSelectionChangedListener(new StatusBarUpdater(slManager));
290
        fSelectionProviderMediator.addSelectionChangedListener(new StatusBarUpdater(
291
                slManager));
292
        getSite().setSelectionProvider(fSelectionProviderMediator);
292
        getSite().setSelectionProvider(fSelectionProviderMediator);
293
293
294
        makeActions();
294
        makeActions();
Lines 321-326 Link Here
321
     * @param b
321
     * @param b
322
     */
322
     */
323
    private void enableActions(boolean enabled) {
323
    private void enableActions(boolean enabled) {
324
        fLocationContextMenu.setEnabled(enabled);
325
324
        // TODO: Is it possible to disable the actions on the toolbar and on the view menu? 
326
        // TODO: Is it possible to disable the actions on the toolbar and on the view menu? 
325
    }
327
    }
326
328
Lines 442-448 Link Here
442
     */
444
     */
443
    public void dispose() {
445
    public void dispose() {
444
        disposeMenu(fTreeContextMenu);
446
        disposeMenu(fTreeContextMenu);
445
        disposeMenu(fListContextMenu);
447
        disposeMenu(fLocationContextMenu);
446
448
447
        super.dispose();
449
        super.dispose();
448
    }
450
    }
Lines 483-495 Link Here
483
            Object structuredSelection = ((IStructuredSelection) selection).getFirstElement();
485
            Object structuredSelection = ((IStructuredSelection) selection).getFirstElement();
484
486
485
            if (structuredSelection instanceof IMember) {
487
            if (structuredSelection instanceof IMember) {
486
                CallHierarchy.jumpToMember((IMember) structuredSelection);
488
                CallHierarchyUI.jumpToMember((IMember) structuredSelection);
487
            } else if (structuredSelection instanceof MethodWrapper) {
489
            } else if (structuredSelection instanceof MethodWrapper) {
488
                MethodWrapper methodWrapper = (MethodWrapper) structuredSelection;
490
                MethodWrapper methodWrapper = (MethodWrapper) structuredSelection;
489
491
490
                CallHierarchy.jumpToMember(methodWrapper.getMember());
492
                CallHierarchyUI.jumpToMember(methodWrapper.getMember());
491
            } else if (structuredSelection instanceof CallLocation) {
493
            } else if (structuredSelection instanceof CallLocation) {
492
                CallHierarchy.jumpToMember(((CallLocation) structuredSelection).getCalledMember());
494
                CallHierarchyUI.jumpToMember(((CallLocation) structuredSelection).getCalledMember());
493
            }
495
            }
494
        }
496
        }
495
    }
497
    }
Lines 506-512 Link Here
506
                if (firstCall != null) {
508
                if (firstCall != null) {
507
                    jumpToLocation(firstCall);
509
                    jumpToLocation(firstCall);
508
                } else {
510
                } else {
509
                    CallHierarchy.jumpToMember(methodWrapper.getMember());
511
                    CallHierarchyUI.jumpToMember(methodWrapper.getMember());
510
                }
512
                }
511
            } else if (structuredSelection instanceof CallLocation) {
513
            } else if (structuredSelection instanceof CallLocation) {
512
                jumpToLocation((CallLocation) structuredSelection);
514
                jumpToLocation((CallLocation) structuredSelection);
Lines 557-564 Link Here
557
    /**
559
    /**
558
     * @param selection
560
     * @param selection
559
     */
561
     */
560
    private void locationSelectionChanged(ISelection selection) {
562
    private void locationSelectionChanged(ISelection selection) {}
561
    }
562
563
563
    /**
564
    /**
564
     * @param selection
565
     * @param selection
Lines 569-576 Link Here
569
570
570
            if (selectedElement instanceof MethodWrapper) {
571
            if (selectedElement instanceof MethodWrapper) {
571
                MethodWrapper methodWrapper = (MethodWrapper) selectedElement;
572
                MethodWrapper methodWrapper = (MethodWrapper) selectedElement;
572
                
573
573
                revealElementInEditor(methodWrapper, fCallHierarchyViewer);                
574
                revealElementInEditor(methodWrapper, fCallHierarchyViewer);
574
                updateLocationsView(methodWrapper);
575
                updateLocationsView(methodWrapper);
575
            } else {
576
            } else {
576
                updateLocationsView(null);
577
                updateLocationsView(null);
Lines 581-601 Link Here
581
    private void revealElementInEditor(Object elem, Viewer originViewer) {
582
    private void revealElementInEditor(Object elem, Viewer originViewer) {
582
        // only allow revealing when the type hierarchy is the active pagae
583
        // only allow revealing when the type hierarchy is the active pagae
583
        // no revealing after selection events due to model changes
584
        // no revealing after selection events due to model changes
584
        
585
        if (getSite().getPage().getActivePart() != this) {
585
        if (getSite().getPage().getActivePart() != this) {
586
            return;
586
            return;
587
        }
587
        }
588
        
588
589
        if (fSelectionProviderMediator.getViewerInFocus() != originViewer) {
589
        if (fSelectionProviderMediator.getViewerInFocus() != originViewer) {
590
            return;
590
            return;
591
        }
591
        }
592
        
592
593
        if (elem instanceof MethodWrapper) {
593
        if (elem instanceof MethodWrapper) {
594
            CallLocation callLocation= CallHierarchy.getCallLocation(elem);
594
            CallLocation callLocation = CallHierarchy.getCallLocation(elem);
595
595
            if (callLocation != null) {
596
            if (callLocation != null) {
596
                IEditorPart editorPart= CallHierarchy.isOpenInEditor(callLocation);
597
                IEditorPart editorPart = CallHierarchyUI.isOpenInEditor(callLocation);
598
597
                if (editorPart != null) {
599
                if (editorPart != null) {
598
                    getSite().getPage().bringToTop(editorPart);
600
                    getSite().getPage().bringToTop(editorPart);
601
599
                    if (editorPart instanceof ITextEditor) {
602
                    if (editorPart instanceof ITextEditor) {
600
                        ITextEditor editor = (ITextEditor) editorPart;
603
                        ITextEditor editor = (ITextEditor) editorPart;
601
                        editor.selectAndReveal(callLocation.getStart(),
604
                        editor.selectAndReveal(callLocation.getStart(),
Lines 603-619 Link Here
603
                    }
606
                    }
604
                }
607
                }
605
            } else {
608
            } else {
606
                IEditorPart editorPart= CallHierarchy.isOpenInEditor(elem);
609
                IEditorPart editorPart = CallHierarchyUI.isOpenInEditor(elem);
607
                getSite().getPage().bringToTop(editorPart);
610
                getSite().getPage().bringToTop(editorPart);
608
                EditorUtility.revealInEditor(editorPart, ((MethodWrapper) elem).getMember());
611
                EditorUtility.revealInEditor(editorPart,
612
                    ((MethodWrapper) elem).getMember());
609
            }
613
            }
610
        } else if (elem instanceof IJavaElement) {
614
        } else if (elem instanceof IJavaElement) {
611
            IEditorPart editorPart= EditorUtility.isOpenInEditor(elem);
615
            IEditorPart editorPart = EditorUtility.isOpenInEditor(elem);
616
612
            if (editorPart != null) {
617
            if (editorPart != null) {
613
    //            getSite().getPage().removePartListener(fPartListener);
618
                //            getSite().getPage().removePartListener(fPartListener);
614
                getSite().getPage().bringToTop(editorPart);
619
                getSite().getPage().bringToTop(editorPart);
615
                EditorUtility.revealInEditor(editorPart, (IJavaElement) elem);
620
                EditorUtility.revealInEditor(editorPart, (IJavaElement) elem);
616
    //            getSite().getPage().addPartListener(fPartListener);
621
622
                //            getSite().getPage().addPartListener(fPartListener);
617
            }
623
            }
618
        }
624
        }
619
    }
625
    }
Lines 637-657 Link Here
637
643
638
    protected void handleKeyEvent(KeyEvent event) {
644
    protected void handleKeyEvent(KeyEvent event) {
639
        if (event.stateMask == 0) {
645
        if (event.stateMask == 0) {
640
//            if (event.keyCode == SWT.F3) {
646
            //            if (event.keyCode == SWT.F3) {
641
//                if ((fOpenDeclarationAction != null) &&
647
            //                if ((fOpenDeclarationAction != null) &&
642
//                            fOpenDeclarationAction.isEnabled()) {
648
            //                            fOpenDeclarationAction.isEnabled()) {
643
//                    fOpenDeclarationAction.run();
649
            //                    fOpenDeclarationAction.run();
644
650
            //                    return;
645
//                    return;
651
            //                }
646
//                }
652
            //            } else 
647
//            } else 
653
            if (event.keyCode == SWT.F5) {
648
                if (event.keyCode == SWT.F5) {
654
                if ((fRefreshAction != null) && fRefreshAction.isEnabled()) {
649
                    if ((fRefreshAction != null) && fRefreshAction.isEnabled()) {
655
                    fRefreshAction.run();
650
                        fRefreshAction.run();
656
651
    
657
                    return;
652
                        return;
653
                    }
654
                }
658
                }
659
            }
655
        }
660
        }
656
    }
661
    }
657
662
Lines 659-683 Link Here
659
        return getViewSite().getActionBars();
664
        return getViewSite().getActionBars();
660
    }
665
    }
661
666
662
    private void setCalleeRoot(CalleeMethodWrapper calleeRoot) {
667
    private void setCalleeRoot(MethodWrapper calleeRoot) {
663
        this.fCalleeRoot = calleeRoot;
668
        this.fCalleeRoot = calleeRoot;
664
    }
669
    }
665
670
666
    private MethodWrapper getCalleeRoot() {
671
    private MethodWrapper getCalleeRoot() {
667
        if (fCalleeRoot == null) {
672
        if (fCalleeRoot == null) {
668
            fCalleeRoot = (CalleeMethodWrapper) CallHierarchy.getDefault().getCalleeRoot(fShownMethod);
673
            fCalleeRoot = (MethodWrapper) CallHierarchy.getDefault().getCalleeRoot(fShownMethod);
669
        }
674
        }
670
675
671
        return fCalleeRoot;
676
        return fCalleeRoot;
672
    }
677
    }
673
678
674
    private void setCallerRoot(CallerMethodWrapper callerRoot) {
679
    private void setCallerRoot(MethodWrapper callerRoot) {
675
        this.fCallerRoot = callerRoot;
680
        this.fCallerRoot = callerRoot;
676
    }
681
    }
677
682
678
    private MethodWrapper getCallerRoot() {
683
    private MethodWrapper getCallerRoot() {
679
        if (fCallerRoot == null) {
684
        if (fCallerRoot == null) {
680
            fCallerRoot = (CallerMethodWrapper) CallHierarchy.getDefault().getCallerRoot(fShownMethod);
685
            fCallerRoot = (MethodWrapper) CallHierarchy.getDefault().getCallerRoot(fShownMethod);
681
        }
686
        }
682
687
683
        return fCallerRoot;
688
        return fCallerRoot;
Lines 705-720 Link Here
705
        fLocationViewer.setLabelProvider(new LocationLabelProvider());
710
        fLocationViewer.setLabelProvider(new LocationLabelProvider());
706
        fLocationViewer.setInput(new ArrayList());
711
        fLocationViewer.setInput(new ArrayList());
707
        fLocationViewer.getControl().addKeyListener(createKeyListener());
712
        fLocationViewer.getControl().addKeyListener(createKeyListener());
708
        
713
709
        fOpenLocationAction= new OpenLocationAction(getSite());
714
        fOpenLocationAction = new OpenLocationAction(getSite());
710
        fLocationViewer.addOpenListener(new IOpenListener() {
715
        fLocationViewer.addOpenListener(new IOpenListener() {
711
            public void open(OpenEvent event) {
716
                public void open(OpenEvent event) {
712
                fOpenLocationAction.run();
717
                    fOpenLocationAction.run();
713
            }
718
                }
714
        });
719
            });
715
        
716
//        fListViewer.addDoubleClickListener(this);
717
720
721
        //        fListViewer.addDoubleClickListener(this);
718
        MenuManager menuMgr = new MenuManager(); //$NON-NLS-1$
722
        MenuManager menuMgr = new MenuManager(); //$NON-NLS-1$
719
        menuMgr.setRemoveAllWhenShown(true);
723
        menuMgr.setRemoveAllWhenShown(true);
720
        menuMgr.addMenuListener(new IMenuListener() {
724
        menuMgr.addMenuListener(new IMenuListener() {
Lines 726-733 Link Here
726
                }
730
                }
727
            });
731
            });
728
732
729
        fListContextMenu = menuMgr.createContextMenu(fLocationViewer.getControl());
733
        fLocationContextMenu = menuMgr.createContextMenu(fLocationViewer.getControl());
730
        fLocationViewer.getControl().setMenu(fListContextMenu);
734
        fLocationViewer.getControl().setMenu(fLocationContextMenu);
731
735
732
        // Register viewer with site. This must be done before making the actions.
736
        // Register viewer with site. This must be done before making the actions.
733
        getSite().registerContextMenu(menuMgr, fLocationViewer);
737
        getSite().registerContextMenu(menuMgr, fLocationViewer);
Lines 829-835 Link Here
829
        fOpenDeclarationAction = new OpenDeclarationAction(this.getSite());
833
        fOpenDeclarationAction = new OpenDeclarationAction(this.getSite());
830
        fFocusOnSelectionAction = new FocusOnSelectionAction(this);
834
        fFocusOnSelectionAction = new FocusOnSelectionAction(this);
831
        fSearchScopeActions = new SearchScopeActionGroup(this);
835
        fSearchScopeActions = new SearchScopeActionGroup(this);
832
        fCustomFiltersActionGroup = new CustomFiltersActionGroup(this,
836
        fFiltersActionGroup = new CallHierarchyFiltersActionGroup(this,
833
                fCallHierarchyViewer);
837
                fCallHierarchyViewer);
834
        fHistoryDropDownAction = new HistoryDropDownAction(this);
838
        fHistoryDropDownAction = new HistoryDropDownAction(this);
835
        fHistoryDropDownAction.setEnabled(false);
839
        fHistoryDropDownAction.setEnabled(false);
Lines 850-856 Link Here
850
854
851
        fActionGroups = new CompositeActionGroup(new ActionGroup[] {
855
        fActionGroups = new CompositeActionGroup(new ActionGroup[] {
852
                    new OpenViewActionGroup(this), new RefactorActionGroup(this),
856
                    new OpenViewActionGroup(this), new RefactorActionGroup(this),
853
                    fSearchScopeActions, fCustomFiltersActionGroup
857
                    fSearchScopeActions, fFiltersActionGroup
854
                });
858
                });
855
    }
859
    }
856
860
Lines 904-911 Link Here
904
    }
908
    }
905
909
906
    static CallHierarchyViewPart findAndShowCallersView(IWorkbenchPartSite site) {
910
    static CallHierarchyViewPart findAndShowCallersView(IWorkbenchPartSite site) {
907
        IWorkbenchPage workbenchPage= site.getPage();
911
        IWorkbenchPage workbenchPage = site.getPage();
908
        CallHierarchyViewPart callersView= null;
912
        CallHierarchyViewPart callersView = null;
909
913
910
        try {
914
        try {
911
            callersView = (CallHierarchyViewPart) workbenchPage.showView(CallHierarchyViewPart.CALLERS_VIEW_ID);
915
            callersView = (CallHierarchyViewPart) workbenchPage.showView(CallHierarchyViewPart.CALLERS_VIEW_ID);
(-)ui/org/eclipse/jdt/internal/ui/callhierarchy/CallHierarchyViewer.java (-7 / +6 lines)
Lines 11-16 Link Here
11
 ******************************************************************************/
11
 ******************************************************************************/
12
package org.eclipse.jdt.internal.ui.callhierarchy;
12
package org.eclipse.jdt.internal.ui.callhierarchy;
13
13
14
import org.eclipse.jdt.internal.corext.callhierarchy.MethodWrapper;
15
import org.eclipse.jface.action.IMenuListener;
16
import org.eclipse.jface.action.MenuManager;
17
import org.eclipse.jface.viewers.IOpenListener;
18
import org.eclipse.jface.viewers.OpenEvent;
19
import org.eclipse.jface.viewers.TreeViewer;
14
import org.eclipse.swt.SWT;
20
import org.eclipse.swt.SWT;
15
import org.eclipse.swt.events.KeyListener;
21
import org.eclipse.swt.events.KeyListener;
16
import org.eclipse.swt.layout.GridData;
22
import org.eclipse.swt.layout.GridData;
Lines 18-30 Link Here
18
import org.eclipse.swt.widgets.Menu;
24
import org.eclipse.swt.widgets.Menu;
19
import org.eclipse.swt.widgets.Tree;
25
import org.eclipse.swt.widgets.Tree;
20
import org.eclipse.swt.widgets.TreeItem;
26
import org.eclipse.swt.widgets.TreeItem;
21
22
import org.eclipse.jface.action.IMenuListener;
23
import org.eclipse.jface.action.MenuManager;
24
import org.eclipse.jface.viewers.IOpenListener;
25
import org.eclipse.jface.viewers.OpenEvent;
26
import org.eclipse.jface.viewers.TreeViewer;
27
28
import org.eclipse.ui.IWorkbenchPartSite;
27
import org.eclipse.ui.IWorkbenchPartSite;
29
28
30
class CallHierarchyViewer extends TreeViewer {
29
class CallHierarchyViewer extends TreeViewer {
(-)ui/org/eclipse/jdt/internal/ui/callhierarchy/CallLocation.java (-97 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2003 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-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.ui.callhierarchy;
13
14
import org.eclipse.core.runtime.IAdaptable;
15
16
import org.eclipse.jdt.core.IBuffer;
17
import org.eclipse.jdt.core.ICompilationUnit;
18
import org.eclipse.jdt.core.IJavaElement;
19
import org.eclipse.jdt.core.IMember;
20
import org.eclipse.jdt.core.JavaModelException;
21
22
class CallLocation implements IAdaptable {
23
    private IMember fCalledMember;
24
    private IMember fMember;
25
    private String fCallText;
26
    private int fEnd;
27
    private int fStart;
28
29
    /**
30
     * @param method
31
     * @param cu
32
     * @param start
33
     * @param end
34
     */
35
    public CallLocation(IMember member, IMember calledMember, int start, int end) {
36
        this.fMember = member;
37
        this.fCalledMember = calledMember;
38
        this.fStart = start;
39
        this.fEnd = end;
40
41
        fCallText = initializeCallText();
42
    }
43
44
    /**
45
     * @return IMethod
46
     */
47
    public IMember getCalledMember() {
48
        return fCalledMember;
49
    }
50
51
    /**
52
     *
53
     */
54
    public int getEnd() {
55
        return fEnd;
56
    }
57
58
    public IMember getMember() {
59
        return fMember;
60
    }
61
62
    /**
63
     *
64
     */
65
    public int getStart() {
66
        return fStart;
67
    }
68
69
    public String toString() {
70
        return fCallText;
71
    }
72
73
    private String initializeCallText() {
74
        try {
75
            ICompilationUnit compilationUnit = fMember.getCompilationUnit();
76
77
            if ((fMember != null) && (compilationUnit != null)) {
78
                IBuffer buffer = compilationUnit.getBuffer();
79
80
                return buffer.getText(fStart, (fEnd - fStart));
81
            } else {
82
                return fMember.getOpenable().getBuffer().getText(fStart, (fEnd - fStart));
83
            }
84
        } catch (JavaModelException e) {
85
            Utility.logError("CallLocation::toString: Error creating text", e);
86
87
            return "- error -";
88
        }
89
    }
90
    
91
    public Object getAdapter(Class adapter) {
92
        if (IJavaElement.class.isAssignableFrom(adapter)) {
93
            return getMember();
94
        }
95
        return null;
96
    }
97
}
(-)ui/org/eclipse/jdt/internal/ui/callhierarchy/CallSearchResultCollector.java (-107 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2003 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-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.ui.callhierarchy;
13
14
import java.util.HashMap;
15
import java.util.Map;
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 fCalledMembers;
23
    private String[] fPackageNames = null;
24
25
    public CallSearchResultCollector() {
26
        this.fCalledMembers = createCalledMethodsData();
27
28
        initializePackageFilters();
29
    }
30
31
    public Map getCallers() {
32
        return fCalledMembers;
33
    }
34
35
    protected void addMember(IMember member, IMember calledMember, int start, int end) {
36
        if ((member != null) && (calledMember != null)) {
37
            if (!isIgnored(calledMember)) {
38
                MethodCall methodCall = (MethodCall) fCalledMembers.get(calledMember.getHandleIdentifier());
39
40
                if (methodCall == null) {
41
                    methodCall = new MethodCall(calledMember);
42
                    fCalledMembers.put(calledMember.getHandleIdentifier(), methodCall);
43
                }
44
45
                methodCall.addCallLocation(new CallLocation(member, calledMember, start,
46
                        end));
47
            }
48
        }
49
    }
50
51
    protected Map createCalledMethodsData() {
52
        return new HashMap();
53
    }
54
55
    /**
56
     * Method isIgnored.
57
     * @param enclosingElement
58
     * @return boolean
59
     */
60
    private boolean isIgnored(IMember enclosingElement) {
61
        if ((fPackageNames != null) && (fPackageNames.length > 0)) {
62
            String fullyQualifiedName = getTypeOfElement(enclosingElement)
63
                                         .getFullyQualifiedName();
64
65
            for (int i = 0; i < fPackageNames.length; i++) {
66
                if (matchPackage(fullyQualifiedName, fPackageNames[i])) {
67
                    return true;
68
                }
69
            }
70
        }
71
72
        return false;
73
    }
74
75
    private IType getTypeOfElement(IMember element) {
76
        if (element.getElementType() == IJavaElement.TYPE) {
77
            return (IType) element;
78
        }
79
        return element.getDeclaringType();
80
    }
81
82
    /**
83
     * Method getPackageNames.
84
     * @param strings
85
     * @return String[]
86
     */
87
    private String[] getPackageNames(String[] filters) {
88
        if (filters != null) {
89
            for (int i = 0; i < filters.length; i++) {
90
                if (filters[i].endsWith(".*")) {
91
                    filters[i] = filters[i].substring(0, filters[i].length() - 2);
92
                }
93
            }
94
        }
95
96
        return filters;
97
    }
98
99
    private void initializePackageFilters() {
100
        String[] filters = CallHierarchy.getDefault().getIgnoreFilters();
101
        fPackageNames = getPackageNames(filters);
102
    }
103
104
    private boolean matchPackage(String fullyQualifiedName, String filter) {
105
        return fullyQualifiedName.startsWith(filter);
106
    }
107
}
(-)ui/org/eclipse/jdt/internal/ui/callhierarchy/CalleeAnalyzerVisitor.java (-236 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2003 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-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.ui.callhierarchy;
13
14
import java.util.Collection;
15
import java.util.Map;
16
17
import org.eclipse.core.runtime.IProgressMonitor;
18
import org.eclipse.core.runtime.SubProgressMonitor;
19
20
import org.eclipse.jdt.core.IMethod;
21
import org.eclipse.jdt.core.ISourceRange;
22
import org.eclipse.jdt.core.IType;
23
import org.eclipse.jdt.core.JavaModelException;
24
import org.eclipse.jdt.core.dom.ASTNode;
25
import org.eclipse.jdt.core.dom.ASTVisitor;
26
import org.eclipse.jdt.core.dom.ClassInstanceCreation;
27
import org.eclipse.jdt.core.dom.ConstructorInvocation;
28
import org.eclipse.jdt.core.dom.IMethodBinding;
29
import org.eclipse.jdt.core.dom.ITypeBinding;
30
import org.eclipse.jdt.core.dom.MethodDeclaration;
31
import org.eclipse.jdt.core.dom.MethodInvocation;
32
import org.eclipse.jdt.core.dom.SuperConstructorInvocation;
33
import org.eclipse.jdt.core.dom.SuperMethodInvocation;
34
35
import org.eclipse.jdt.internal.corext.dom.Binding2JavaModel;
36
37
class CalleeAnalyzerVisitor extends ASTVisitor {
38
    private CallSearchResultCollector fSearchResults;
39
    private IMethod fMethod;
40
    private IProgressMonitor fProgressMonitor;
41
    private int fMethodEndPosition;
42
    private int fMethodStartPosition;
43
44
    CalleeAnalyzerVisitor(IMethod method, IProgressMonitor progressMonitor) {
45
        fSearchResults = new CallSearchResultCollector();
46
        this.fMethod = method;
47
        this.fProgressMonitor = progressMonitor;
48
49
        try {
50
            ISourceRange sourceRange = method.getSourceRange();
51
            this.fMethodStartPosition = sourceRange.getOffset();
52
            this.fMethodEndPosition = fMethodStartPosition + sourceRange.getLength();
53
        } catch (JavaModelException jme) {
54
            Utility.logError("Error getting start and end of method: " +
55
                fMethod.getElementName(), jme);
56
        }
57
    }
58
59
    /**
60
     * Method getCallees.
61
     * @return CallerElement
62
     */
63
    public Map getCallees() {
64
        return fSearchResults.getCallers();
65
    }
66
67
    /* (non-Javadoc)
68
     * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.ClassInstanceCreation)
69
     */
70
    public boolean visit(ClassInstanceCreation node) {
71
        if (!isNodeWithinMethod(node)) {
72
            return false;
73
        }
74
75
        addMethodCall(node.resolveConstructorBinding(), node);
76
77
        return true;
78
    }
79
80
    /**
81
     * Find all constructor invocations (<code>this(...)</code>) from the called method. Since we only traverse into the
82
     * AST on the wanted method declaration, this method should not hit on more constructor
83
     * invocations than those in the wanted method.
84
     *
85
     * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.ConstructorInvocation)
86
     */
87
    public boolean visit(ConstructorInvocation node) {
88
        if (!isNodeWithinMethod(node)) {
89
            return false;
90
        }
91
92
        addMethodCall(node.resolveConstructorBinding(), node);
93
94
        return true;
95
    }
96
97
    /**
98
     * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.MethodDeclaration)
99
     */
100
    public boolean visit(MethodDeclaration node) {
101
        return isNodeWithinMethod(node);
102
    }
103
104
    /**
105
     * Find all method invocations from the called method. Since we only traverse into the
106
     * AST on the wanted method declaration, this method should not hit on more method
107
     * invocations than those in the wanted method.
108
     *
109
     * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.MethodInvocation)
110
     */
111
    public boolean visit(MethodInvocation node) {
112
        if (!isNodeWithinMethod(node)) {
113
            return false;
114
        }
115
116
        addMethodCall(node.resolveMethodBinding(), node);
117
118
        return true;
119
    }
120
121
    /**
122
     * Find invocations of the supertype's constructor from the called method (=constructor).
123
     * Since we only traverse into the AST on the wanted method declaration, this method should
124
     * not hit on more method invocations than those in the wanted method.
125
     *
126
     * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.SuperConstructorInvocation)
127
     */
128
    public boolean visit(SuperConstructorInvocation node) {
129
        if (!isNodeWithinMethod(node)) {
130
            return false;
131
        }
132
133
        addMethodCall(node.resolveConstructorBinding(), node);
134
135
        return true;
136
    }
137
138
    /**
139
     * Find all method invocations from the called method. Since we only traverse into the
140
     * AST on the wanted method declaration, this method should not hit on more method
141
     * invocations than those in the wanted method.
142
     *
143
     * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.MethodInvocation)
144
     */
145
    public boolean visit(SuperMethodInvocation node) {
146
        if (!isNodeWithinMethod(node)) {
147
            return false;
148
        }
149
150
        addMethodCall(node.resolveMethodBinding(), node);
151
152
        return true;
153
    }
154
155
    /**
156
     * Adds the specified method binding to the search results.
157
     * @param calledMethodBinding
158
     * @param node
159
     */
160
    protected void addMethodCall(IMethodBinding calledMethodBinding, ASTNode node) {
161
        try {
162
            if (calledMethodBinding != null) {
163
                fProgressMonitor.worked(1);
164
165
                ITypeBinding calledTypeBinding = calledMethodBinding.getDeclaringClass();
166
                IType calledType = null;
167
168
                if (!calledTypeBinding.isAnonymous()) {
169
                    calledType = Binding2JavaModel.find(calledTypeBinding,
170
                            fMethod.getJavaProject());
171
                } else {
172
                    calledType = Binding2JavaModel.find(calledTypeBinding.getInterfaces()[0],
173
                            fMethod.getJavaProject());
174
                }
175
176
                IMethod calledMethod = Binding2JavaModel.findIncludingSupertypes(calledMethodBinding,
177
                        calledType,
178
                        new SubProgressMonitor(fProgressMonitor, 100,
179
                            SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
180
181
                if ((calledMethod != null) && calledType.isInterface()) {
182
                    calledMethod = findImplementingMethods(calledMethod);
183
                }
184
185
                if (!isIgnoredBySearchScope(calledMethod)) {
186
                    fSearchResults.addMember(fMethod, calledMethod,
187
                        node.getStartPosition(),
188
                        node.getStartPosition() + node.getLength());
189
                }
190
            }
191
        } catch (JavaModelException jme) {
192
            Utility.logError("Error adding callee search result", jme);
193
        }
194
    }
195
196
    /**
197
     * @param enclosingElement
198
     * @return
199
     */
200
    private boolean isIgnoredBySearchScope(IMethod enclosingElement) {
201
        if (enclosingElement != null) {
202
            return !CallHierarchy.getDefault().getSearchScope().encloses(enclosingElement);
203
        } else {
204
            return false;
205
        }
206
    }
207
208
    private boolean isNodeWithinMethod(ASTNode node) {
209
        int nodeStartPosition = node.getStartPosition();
210
        int nodeEndPosition = nodeStartPosition + node.getLength();
211
212
        if (nodeStartPosition < fMethodStartPosition) {
213
            return false;
214
        }
215
216
        if (nodeEndPosition > fMethodEndPosition) {
217
            return false;
218
        }
219
220
        return true;
221
    }
222
223
    /**
224
     * @param calledMethod
225
     */
226
    private IMethod findImplementingMethods(IMethod calledMethod) {
227
        Collection implementingMethods = CallHierarchy.getDefault()
228
                                                      .getImplementingMethods(calledMethod);
229
230
        if ((implementingMethods.size() == 0) || (implementingMethods.size() > 1)) {
231
            return calledMethod;
232
        } else {
233
            return (IMethod) implementingMethods.iterator().next();
234
        }
235
    }
236
}
(-)ui/org/eclipse/jdt/internal/ui/callhierarchy/CalleeMethodWrapper.java (-106 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2003 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-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.ui.callhierarchy;
13
14
import java.util.Arrays;
15
import java.util.Comparator;
16
import java.util.HashMap;
17
import java.util.Map;
18
19
import org.eclipse.core.runtime.IProgressMonitor;
20
21
import org.eclipse.jdt.core.ICompilationUnit;
22
import org.eclipse.jdt.core.IJavaElement;
23
import org.eclipse.jdt.core.IMethod;
24
import org.eclipse.jdt.core.dom.AST;
25
import org.eclipse.jdt.core.dom.CompilationUnit;
26
27
class CalleeMethodWrapper extends MethodWrapper {
28
    private Comparator fMethodWrapperComparator = new MethodWrapperComparator();
29
30
    private class MethodWrapperComparator implements Comparator {
31
        /* (non-Javadoc)
32
         * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
33
         */
34
        public int compare(Object o1, Object o2) {
35
            MethodWrapper m1 = (MethodWrapper) o1;
36
            MethodWrapper m2 = (MethodWrapper) o2;
37
38
            CallLocation callLocation1 = m1.getMethodCall().getFirstCallLocation();
39
            CallLocation callLocation2 = m2.getMethodCall().getFirstCallLocation();
40
41
            if ((callLocation1 != null) && (callLocation2 != null)) {
42
                if (callLocation1.getStart() == callLocation2.getStart()) {
43
                    return callLocation1.getEnd() - callLocation2.getEnd();
44
                }
45
46
                return callLocation1.getStart() - callLocation2.getStart();
47
            }
48
49
            return 0;
50
        }
51
    }
52
53
    /**
54
     * Constructor for CalleeMethodWrapper.
55
     * @param parent
56
     * @param method
57
     */
58
    public CalleeMethodWrapper(MethodWrapper parent, MethodCall methodCall) {
59
        super(parent, methodCall);
60
    }
61
62
	/* Returns the calls sorted after the call location
63
	 * @see org.eclipse.jdt.internal.ui.callhierarchy.MethodWrapper#getCalls()
64
     */
65
    public MethodWrapper[] getCalls() {
66
        MethodWrapper[] result = super.getCalls();
67
        Arrays.sort(result, fMethodWrapperComparator);
68
69
        return result;
70
    }
71
72
	/* (non-Javadoc)
73
	 * @see org.eclipse.jdt.internal.ui.callhierarchy.MethodWrapper#getTaskName()
74
     */
75
    protected String getTaskName() {
76
        return null;
77
    }
78
79
	/**
80
	 * @see org.eclipse.jdt.internal.ui.callhierarchy.MethodWrapper#createMethodWrapper(org.eclipse.jdt.internal.ui.callhierarchy.MethodCall)
81
     */
82
    protected MethodWrapper createMethodWrapper(MethodCall methodCall) {
83
        return new CalleeMethodWrapper(this, methodCall);
84
    }
85
86
	/**
87
     * Find callees called from the current method.
88
	 * @see org.eclipse.jdt.internal.ui.callhierarchy.MethodWrapper#findChildren(org.eclipse.core.runtime.IProgressMonitor)
89
     */
90
    protected Map findChildren(IProgressMonitor progressMonitor) {
91
        if (getMember().getElementType() == IJavaElement.METHOD) {
92
            CalleeAnalyzerVisitor visitor = new CalleeAnalyzerVisitor((IMethod) getMember(),
93
                    progressMonitor);
94
            ICompilationUnit icu = getMember().getCompilationUnit();
95
        
96
            if (icu != null) {
97
                CompilationUnit cu = AST.parseCompilationUnit(icu, true);
98
                cu.accept(visitor);
99
            }
100
        
101
            return visitor.getCallees();
102
        } else {
103
            return new HashMap();
104
        }
105
    }
106
}
(-)ui/org/eclipse/jdt/internal/ui/callhierarchy/CallerMethodWrapper.java (-91 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2003 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-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.ui.callhierarchy;
13
14
import java.util.ArrayList;
15
import java.util.Collection;
16
import java.util.HashMap;
17
import java.util.Iterator;
18
import java.util.Map;
19
20
import org.eclipse.core.resources.ResourcesPlugin;
21
import org.eclipse.core.runtime.IProgressMonitor;
22
import org.eclipse.core.runtime.SubProgressMonitor;
23
24
import org.eclipse.jdt.core.IJavaElement;
25
import org.eclipse.jdt.core.IMember;
26
import org.eclipse.jdt.core.IMethod;
27
import org.eclipse.jdt.core.JavaModelException;
28
import org.eclipse.jdt.core.search.IJavaSearchConstants;
29
import org.eclipse.jdt.core.search.IJavaSearchScope;
30
import org.eclipse.jdt.core.search.SearchEngine;
31
32
class CallerMethodWrapper extends MethodWrapper {
33
    public CallerMethodWrapper(MethodWrapper parent, MethodCall methodCall) {
34
        super(parent, methodCall);
35
    }
36
37
    protected IJavaSearchScope getSearchScope() {
38
        return CallHierarchy.getDefault().getSearchScope();
39
    }
40
41
    protected String getTaskName() {
42
        return "Finding callers...";
43
    }
44
45
	/**
46
	 * @see org.eclipse.jdt.internal.ui.callhierarchy.MethodWrapper#createMethodWrapper(org.eclipse.jdt.internal.ui.callhierarchy.MethodCall)
47
     */
48
    protected MethodWrapper createMethodWrapper(MethodCall methodCall) {
49
        return new CallerMethodWrapper(this, methodCall);
50
    }
51
52
	/**
53
	 * @see org.eclipse.jdt.internal.ui.callhierarchy.MethodWrapper#findChildren(org.eclipse.core.runtime.IProgressMonitor)
54
     * @return The result of the search for children
55
     */
56
    protected Map findChildren(IProgressMonitor progressMonitor) {
57
        try {
58
            MethodReferencesSearchCollector searchCollector = new MethodReferencesSearchCollector();
59
            SearchEngine searchEngine = new SearchEngine();
60
61
            for (Iterator iter = getMembers().iterator();
62
                        iter.hasNext() && !progressMonitor.isCanceled();) {
63
                IMember member = (IMember) iter.next();
64
                searchCollector.setProgressMonitor(new SubProgressMonitor(
65
                        progressMonitor, 10, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
66
                searchEngine.search(ResourcesPlugin.getWorkspace(), member,
67
                    IJavaSearchConstants.REFERENCES, getSearchScope(), searchCollector);
68
            }
69
70
            return searchCollector.getCallers();
71
        } catch (JavaModelException e) {
72
            Utility.logError("Error finding callers", e);
73
74
            return new HashMap(0);
75
        }
76
    }
77
78
    /**
79
     * Returns a collection of IMember instances representing what to search for 
80
     */
81
    private Collection getMembers() {
82
        Collection result = new ArrayList();
83
84
        result.add(getMember());
85
        if (getMember().getElementType() == IJavaElement.METHOD) {
86
            result.addAll(CallHierarchy.getDefault().getInterfaceMethods((IMethod) getMember()));
87
        }
88
89
        return result;
90
    }
91
}
(-)ui/org/eclipse/jdt/internal/ui/callhierarchy/FiltersDialog.java (+204 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2003 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-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.ui.callhierarchy;
13
14
import org.eclipse.jdt.internal.corext.callhierarchy.CallHierarchy;
15
import org.eclipse.jface.dialogs.Dialog;
16
import org.eclipse.swt.SWT;
17
import org.eclipse.swt.events.SelectionAdapter;
18
import org.eclipse.swt.events.SelectionEvent;
19
import org.eclipse.swt.events.SelectionListener;
20
import org.eclipse.swt.graphics.Font;
21
import org.eclipse.swt.layout.GridData;
22
import org.eclipse.swt.layout.GridLayout;
23
import org.eclipse.swt.widgets.Button;
24
import org.eclipse.swt.widgets.Composite;
25
import org.eclipse.swt.widgets.Control;
26
import org.eclipse.swt.widgets.Label;
27
import org.eclipse.swt.widgets.MessageBox;
28
import org.eclipse.swt.widgets.Shell;
29
import org.eclipse.swt.widgets.Text;
30
31
/**
32
 * @author jl
33
 */
34
public class FiltersDialog extends Dialog {
35
    private Button fFilterOnNames;
36
    private Text fNames;
37
    private Text fMaxCallDepth;
38
39
    private SelectionListener selectionListener = new SelectionAdapter() {
40
        public void widgetSelected(SelectionEvent e) {
41
            FiltersDialog.this.widgetSelected(e);
42
        }
43
    };
44
45
    /**
46
     * @param parentShell
47
     */
48
    protected FiltersDialog(Shell parentShell) {
49
        super(parentShell);
50
    }
51
52
    /* (non-Javadoc)
53
     * Method declared on Dialog.
54
     */
55
    protected Control createDialogArea(Composite parent) {
56
        Composite superComposite = (Composite) super.createDialogArea(parent);
57
58
        Font font = parent.getFont();
59
        Composite composite = new Composite(superComposite, SWT.NONE);
60
        composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
61
        composite.setFont(font);
62
63
        GridLayout layout = new GridLayout();
64
        layout.numColumns = 2;
65
        composite.setLayout(layout);
66
67
        createNamesArea(composite);
68
        createMaxCallDepthArea(composite);
69
    
70
        updateUIFromFilter();
71
        
72
        return composite;
73
    }
74
75
    /* (non-Javadoc)
76
     * Method declared on Window.
77
     */
78
    protected void configureShell(Shell newShell) {
79
        super.configureShell(newShell);
80
        newShell.setText(CallHierarchyMessages.getString("FiltersDialog.filter")); //$NON-NLS-1$
81
//      TODO: WorkbenchHelp.setHelp(newShell, ITaskListHelpContextIds.FILTERS_DIALOG);
82
    }
83
    
84
    void createMaxCallDepthArea(Composite parent) {
85
        new Label(parent, SWT.NONE).setText(CallHierarchyMessages.getString("FiltersDialog.maxCallDepth"));
86
        
87
        fMaxCallDepth = new Text(parent, SWT.SINGLE | SWT.BORDER);
88
        fMaxCallDepth.setTextLimit(6);
89
90
        GridData gridData = new GridData();
91
        gridData.widthHint = convertWidthInCharsToPixels(10);
92
        fMaxCallDepth.setLayoutData(gridData);
93
        fMaxCallDepth.setFont(parent.getFont());
94
    }
95
96
    void createNamesArea(Composite parent) {
97
        fFilterOnNames = createCheckbox(parent,
98
                CallHierarchyMessages.getString("FiltersDialog.filterOnNames"),
99
                false); //$NON-NLS-1$
100
        fFilterOnNames.setLayoutData(new GridData());
101
        fNames= new Text(parent, SWT.SINGLE | SWT.BORDER);
102
103
        GridData gridData = new GridData();
104
        gridData.widthHint = convertWidthInCharsToPixels(30);
105
        fNames.setLayoutData(gridData);
106
        fNames.setFont(parent.getFont());
107
    }
108
109
    /**
110
     * Creates a check box button with the given parent and text.
111
     *
112
     * @param parent the parent composite
113
     * @param text the text for the check box
114
     * @param grabRow <code>true</code>to grab the remaining horizontal space,
115
     *        <code>false</code> otherwise
116
     *
117
     * @return the check box button
118
     */
119
    Button createCheckbox(Composite parent, String text, boolean grabRow) {
120
        Button button = new Button(parent, SWT.CHECK);
121
122
        if (grabRow) {
123
            GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
124
            button.setLayoutData(gridData);
125
        }
126
127
        button.setText(text);
128
        button.addSelectionListener(selectionListener);
129
        button.setFont(parent.getFont());
130
131
        return button;
132
    }
133
134
    /**
135
     * Updates the enabled state of the widgetry.
136
     */
137
    void updateEnabledState() {
138
        fNames.setEnabled(fFilterOnNames.getSelection());
139
    }
140
    
141
    /**
142
     * Updates the given filter from the UI state.
143
     *
144
     * @param filter the filter to update
145
     */
146
    void updateFilterFromUI() {
147
        int maxCallDepth = Integer.parseInt(this.fMaxCallDepth.getText());
148
149
        CallHierarchyUI.getDefault().setMaxCallDepth(maxCallDepth);
150
        CallHierarchy.getDefault().setFilters(fNames.getText());
151
        CallHierarchy.getDefault().setFilterEnabled(fFilterOnNames.getSelection());
152
    }
153
    
154
    /**
155
     * Updates the UI state from the given filter.
156
     *
157
     * @param filter the filter to use
158
     */
159
    void updateUIFromFilter() {
160
      fMaxCallDepth.setText(""+CallHierarchyUI.getDefault().getMaxCallDepth()); //$NON-NLS-1$
161
      fNames.setText(CallHierarchy.getDefault().getFilters());
162
      fFilterOnNames.setSelection(CallHierarchy.getDefault().isFilterEnabled());
163
      updateEnabledState();
164
    }
165
    
166
    /**
167
     * Handles selection on a check box or combo box.
168
     */
169
    void widgetSelected(SelectionEvent e) {
170
        updateEnabledState();
171
    }
172
    
173
    /**
174
     * Updates the filter from the UI state.
175
     * Must be done here rather than by extending open()
176
     * because after super.open() is called, the widgetry is disposed.
177
     */
178
    protected void okPressed() {
179
        try {
180
            int maxCallDepth = Integer.parseInt(this.fMaxCallDepth.getText());
181
    
182
            if (maxCallDepth < 1 || maxCallDepth > 99) {
183
                throw new NumberFormatException();
184
            }           
185
            
186
            updateFilterFromUI();
187
            super.okPressed();
188
        }
189
        catch (NumberFormatException eNumberFormat) {
190
            MessageBox messageBox = new MessageBox(getShell(), 
191
                    SWT.OK | SWT.APPLICATION_MODAL | SWT.ICON_ERROR);
192
            messageBox.setText(CallHierarchyMessages.getString(
193
                    "FiltersDialog.titleMaxCallDepthInvalid")); //$NON-NLS-1$
194
            messageBox.setMessage(CallHierarchyMessages.getString(
195
                    "FiltersDialog.messageMaxCallDepthInvalid")); //$NON-NLS-1$
196
            messageBox.open();
197
    
198
            if (fMaxCallDepth.forceFocus()) {
199
                fMaxCallDepth.setSelection(0, fMaxCallDepth.getCharCount());
200
                fMaxCallDepth.showSelection();
201
            }
202
        }
203
    }
204
}
(-)ui/org/eclipse/jdt/internal/ui/callhierarchy/FocusOnSelectionAction.java (-7 / +7 lines)
Lines 12-25 Link Here
12
package org.eclipse.jdt.internal.ui.callhierarchy;
12
package org.eclipse.jdt.internal.ui.callhierarchy;
13
13
14
import org.eclipse.core.runtime.IAdaptable;
14
import org.eclipse.core.runtime.IAdaptable;
15
16
import org.eclipse.jface.action.Action;
17
import org.eclipse.jface.viewers.ISelection;
18
import org.eclipse.jface.viewers.ISelectionProvider;
19
20
import org.eclipse.jdt.core.IJavaElement;
15
import org.eclipse.jdt.core.IJavaElement;
21
import org.eclipse.jdt.core.IMember;
16
import org.eclipse.jdt.core.IMember;
22
import org.eclipse.jdt.core.IMethod;
17
import org.eclipse.jdt.core.IMethod;
18
import org.eclipse.jdt.internal.corext.callhierarchy.MethodWrapper;
19
import org.eclipse.jdt.internal.ui.util.SelectionUtil;
20
import org.eclipse.jface.action.Action;
21
import org.eclipse.jface.viewers.ISelection;
22
import org.eclipse.jface.viewers.ISelectionProvider;
23
23
24
class FocusOnSelectionAction extends Action {
24
class FocusOnSelectionAction extends Action {
25
    private CallHierarchyViewPart fPart;
25
    private CallHierarchyViewPart fPart;
Lines 32-38 Link Here
32
    }
32
    }
33
33
34
    public boolean canActionBeAdded() {
34
    public boolean canActionBeAdded() {
35
        Object element = Utility.getSingleElement(getSelection());
35
        Object element = SelectionUtil.getSingleElement(getSelection());
36
36
37
        IMethod method = null;
37
        IMethod method = null;
38
        
38
        
Lines 55-61 Link Here
55
     * @see Action#run
55
     * @see Action#run
56
     */
56
     */
57
    public void run() {
57
    public void run() {
58
        Object element = Utility.getSingleElement(getSelection());
58
        Object element = SelectionUtil.getSingleElement(getSelection());
59
59
60
        if (element instanceof MethodWrapper) {
60
        if (element instanceof MethodWrapper) {
61
            IMember member= ((MethodWrapper) element).getMember();
61
            IMember member= ((MethodWrapper) element).getMember();
(-)ui/org/eclipse/jdt/internal/ui/callhierarchy/ICallHierarchyPreferencesConstants.java (-4 lines)
Lines 12-21 Link Here
12
package org.eclipse.jdt.internal.ui.callhierarchy;
12
package org.eclipse.jdt.internal.ui.callhierarchy;
13
13
14
public interface ICallHierarchyPreferencesConstants {
14
public interface ICallHierarchyPreferencesConstants {
15
    public static final String PREF_USE_FILTERS = "PREF_USE_FILTERS";
16
    public static final String PREF_INACTIVE_FILTERS_LIST = "PREF_INACTIVE_FILTERS_LIST";
17
    public static final String PREF_ACTIVE_FILTERS_LIST = "PREF_ACTIVE_FILTERS_LIST";
18
    public static final String PREF_MAX_CALL_DEPTH = "PREF_MAX_CALL_DEPTH";
19
    public static final String PREF_USE_IMPLEMENTORS_FOR_CALLER_SEARCH = "PREF_USE_IMPLEMENTORS_FOR_CALLER_SEARCH";
15
    public static final String PREF_USE_IMPLEMENTORS_FOR_CALLER_SEARCH = "PREF_USE_IMPLEMENTORS_FOR_CALLER_SEARCH";
20
    public static final String PREF_USE_IMPLEMENTORS_FOR_CALLEE_SEARCH = "PREF_USE_IMPLEMENTORS_FOR_CALLEE_SEARCH";
16
    public static final String PREF_USE_IMPLEMENTORS_FOR_CALLEE_SEARCH = "PREF_USE_IMPLEMENTORS_FOR_CALLEE_SEARCH";
21
}
17
}
(-)ui/org/eclipse/jdt/internal/ui/callhierarchy/LocationLabelProvider.java (+1 lines)
Lines 11-16 Link Here
11
 ******************************************************************************/
11
 ******************************************************************************/
12
package org.eclipse.jdt.internal.ui.callhierarchy;
12
package org.eclipse.jdt.internal.ui.callhierarchy;
13
13
14
import org.eclipse.jdt.internal.corext.callhierarchy.CallLocation;
14
import org.eclipse.jface.viewers.LabelProvider;
15
import org.eclipse.jface.viewers.LabelProvider;
15
16
16
class LocationLabelProvider extends LabelProvider {
17
class LocationLabelProvider extends LabelProvider {
(-)ui/org/eclipse/jdt/internal/ui/callhierarchy/MethodCall.java (-70 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2003 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-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.ui.callhierarchy;
13
14
import java.util.ArrayList;
15
import java.util.Collection;
16
import java.util.List;
17
18
import org.eclipse.jdt.core.IMember;
19
20
class MethodCall {
21
    private IMember fMember;
22
    private List fCallLocations;
23
24
    /**
25
     * @param enclosingElement
26
     */
27
    public MethodCall(IMember enclosingElement) {
28
        this.fMember = enclosingElement;
29
    }
30
31
    /**
32
     *
33
     */
34
    public Collection getCallLocations() {
35
        return fCallLocations;
36
    }
37
38
    public CallLocation getFirstCallLocation() {
39
        if ((fCallLocations != null) && !fCallLocations.isEmpty()) {
40
            return (CallLocation) fCallLocations.get(0);
41
        } else {
42
            return null;
43
        }
44
    }
45
46
    /**
47
     * @return Object
48
     */
49
    public Object getKey() {
50
        return getMember().getHandleIdentifier();
51
    }
52
53
    /**
54
     *
55
     */
56
    public IMember getMember() {
57
        return fMember;
58
    }
59
60
    /**
61
     * @param location
62
     */
63
    public void addCallLocation(CallLocation location) {
64
        if (fCallLocations == null) {
65
            fCallLocations = new ArrayList();
66
        }
67
68
        fCallLocations.add(location);
69
    }
70
}
(-)ui/org/eclipse/jdt/internal/ui/callhierarchy/MethodReferencesSearchCollector.java (-82 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2003 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-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.ui.callhierarchy;
13
14
import java.util.Map;
15
16
import org.eclipse.core.resources.IResource;
17
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.runtime.IProgressMonitor;
19
import org.eclipse.core.runtime.SubProgressMonitor;
20
21
import org.eclipse.jdt.core.IJavaElement;
22
import org.eclipse.jdt.core.IMember;
23
import org.eclipse.jdt.core.search.IJavaSearchResultCollector;
24
25
class MethodReferencesSearchCollector implements IJavaSearchResultCollector {
26
    private CallSearchResultCollector fSearchResults;
27
    private IProgressMonitor fProgressMonitor;
28
    private boolean fRequireExactMatch = true;
29
30
    MethodReferencesSearchCollector() {
31
        fSearchResults = new CallSearchResultCollector();
32
    }
33
34
    public Map getCallers() {
35
        return fSearchResults.getCallers();
36
    }
37
38
    /**
39
     * @see org.eclipse.jdt.core.search.IJavaSearchResultCollector#getProgressMonitor()
40
     */
41
    public IProgressMonitor getProgressMonitor() {
42
        return fProgressMonitor;
43
    }
44
45
    /**
46
     * @see org.eclipse.jdt.core.search.IJavaSearchResultCollector#aboutToStart()
47
     */
48
    public void aboutToStart() {}
49
50
    /**
51
     * @see org.eclipse.jdt.core.search.IJavaSearchResultCollector#accept(org.eclipse.core.resources.IResource, int, int, org.eclipse.jdt.core.IJavaElement, int)
52
     */
53
    public void accept(IResource resource, int start, int end,
54
        IJavaElement enclosingElement, int accuracy) throws CoreException {
55
        if (fRequireExactMatch && (accuracy != IJavaSearchResultCollector.EXACT_MATCH)) {
56
            return;
57
        }
58
59
        if (enclosingElement != null && enclosingElement instanceof IMember) {
60
            IMember member= (IMember) enclosingElement;
61
            switch (enclosingElement.getElementType()) {
62
                case IJavaElement.METHOD:
63
                case IJavaElement.TYPE:
64
                case IJavaElement.FIELD:
65
                    fSearchResults.addMember(member, member, start, end);
66
                    break;
67
            }
68
        }
69
    }
70
71
    /**
72
     * @see org.eclipse.jdt.core.search.IJavaSearchResultCollector#done()
73
     */
74
    public void done() {}
75
76
    /**
77
     * @param monitor
78
     */
79
    void setProgressMonitor(SubProgressMonitor monitor) {
80
        this.fProgressMonitor = monitor;
81
    }
82
}
(-)ui/org/eclipse/jdt/internal/ui/callhierarchy/MethodWrapper.java (-326 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2003 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-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.ui.callhierarchy;
13
14
import java.util.HashMap;
15
import java.util.Iterator;
16
import java.util.Map;
17
18
import org.eclipse.core.runtime.IAdaptable;
19
import org.eclipse.core.runtime.IProgressMonitor;
20
21
import org.eclipse.jdt.core.IJavaElement;
22
import org.eclipse.jdt.core.IMember;
23
import org.eclipse.jdt.core.IMethod;
24
25
/**
26
 * This class represents the general parts of a method call (either to or from a
27
 * method).
28
 *
29
 */
30
public abstract class MethodWrapper implements IAdaptable {
31
    private Map fElements = null;
32
33
    /*
34
     * A cache of previously found methods. This cache should be searched
35
     * before adding a "new" method object reference to the list of elements.
36
     * This way previously found methods won't be searched again.
37
     */
38
    private Map fMethodCache;
39
    private MethodCall fMethodCall;
40
    private MethodWrapper fParent;
41
    private int fLevel;
42
43
    /**
44
     * Constructor CallerElement.
45
     */
46
    public MethodWrapper(MethodWrapper parent, MethodCall methodCall) {
47
        super();
48
49
        if (methodCall == null) {
50
            throw new IllegalArgumentException("Parameter method cannot be null");
51
        }
52
53
        if (parent == null) {
54
            setMethodCache(new HashMap());
55
            fLevel = 1;
56
        } else {
57
            setMethodCache(parent.getMethodCache());
58
            fLevel = parent.getLevel() + 1;
59
        }
60
61
        this.fMethodCall = methodCall;
62
        this.fParent = parent;
63
    }
64
65
    public Object getAdapter(Class adapter) {
66
        if (adapter == IMethod.class) {
67
            if (getMember().getElementType() == IJavaElement.METHOD) {
68
                return getMember();
69
            } else {
70
                return null;
71
            }
72
        } else {
73
            if (IJavaElement.class.isAssignableFrom(adapter)) {
74
                return getMember();
75
            }
76
        }
77
78
        return null;
79
    }
80
81
    /**
82
     * Method getCallerElements.
83
     * @return The child caller elements of this element
84
     */
85
    public MethodWrapper[] getCalls() {
86
        if (fElements == null) {
87
            doFindChildren();
88
        }
89
90
        MethodWrapper[] result = new MethodWrapper[fElements.size()];
91
        int i = 0;
92
93
        for (Iterator iter = fElements.keySet().iterator(); iter.hasNext();) {
94
            MethodCall methodCall = getMethodCallFromMap(fElements, iter.next());
95
            result[i++] = createMethodWrapper(methodCall);
96
        }
97
98
        return result;
99
    }
100
101
    /**
102
     * @return int
103
     */
104
    public int getLevel() {
105
        return fLevel;
106
    }
107
108
    /**
109
     * Method getMethod.
110
     * @return Object
111
     */
112
    public IMember getMember() {
113
        return getMethodCall().getMember();
114
    }
115
116
    /**
117
     * @return MethodCall
118
     */
119
    public MethodCall getMethodCall() {
120
        return fMethodCall;
121
    }
122
123
    /**
124
     * Method getName.
125
     */
126
    public String getName() {
127
        if (getMethodCall() != null) {
128
            return getMethodCall().getMember().getElementName();
129
        } else {
130
            return "";
131
        }
132
    }
133
134
    /**
135
     * Method getParent.
136
     * @return
137
     */
138
    public MethodWrapper getParent() {
139
        return fParent;
140
    }
141
142
    public boolean equals(Object oth) {
143
        if (this == oth) {
144
            return true;
145
        }
146
147
        if (oth == null) {
148
            return false;
149
        }
150
151
        if (oth.getClass() != getClass()) {
152
            return false;
153
        }
154
155
        MethodWrapper other = (MethodWrapper) oth;
156
157
        if (this.fParent == null) {
158
            if (other.fParent != null) {
159
                return false;
160
            }
161
        } else {
162
            if (!this.fParent.equals(other.fParent)) {
163
                return false;
164
            }
165
        }
166
167
        if (this.getMethodCall() == null) {
168
            if (other.getMethodCall() != null) {
169
                return false;
170
            }
171
        } else {
172
            if (!this.getMethodCall().equals(other.getMethodCall())) {
173
                return false;
174
            }
175
        }
176
177
        return true;
178
    }
179
180
    public int hashCode() {
181
        final int PRIME = 1000003;
182
        int result = 0;
183
184
        if (fParent != null) {
185
            result = (PRIME * result) + fParent.hashCode();
186
        }
187
188
        if (getMethodCall() != null) {
189
            result = (PRIME * result) + getMethodCall().getMember().hashCode();
190
        }
191
192
        return result;
193
    }
194
195
    /**
196
     * @see java.lang.Object#toString()
197
     */
198
    public String toString() {
199
        String result;
200
201
        result = "CallerElement[name=" + getName() + ", children=";
202
203
        if (fElements == null) {
204
            result += "unknown]";
205
        } else {
206
            result += (fElements.size() + "]");
207
        }
208
209
        return result;
210
    }
211
212
    private void setMethodCache(Map methodCache) {
213
        fMethodCache = methodCache;
214
    }
215
216
    protected abstract String getTaskName();
217
218
    private void addCallToCache(MethodCall methodCall) {
219
        Map cachedCalls = lookupMethod(this.getMethodCall());
220
        cachedCalls.put(methodCall.getKey(), methodCall);
221
    }
222
223
    /**
224
     * Method createMethodWrapper.
225
     * @param method
226
     * @return MethodWrapper
227
     */
228
    protected abstract MethodWrapper createMethodWrapper(MethodCall methodCall);
229
230
    private void doFindChildren() {
231
        Map existingResults = lookupMethod(getMethodCall());
232
233
        if (existingResults != null) {
234
            fElements = new HashMap();
235
            fElements.putAll(existingResults);
236
        } else {
237
            initCalls();
238
239
            IProgressMonitor progressMonitor = getProgressMonitor();
240
241
            if (progressMonitor != null) {
242
                progressMonitor.beginTask(getTaskName(), IProgressMonitor.UNKNOWN);
243
            }
244
245
            try {
246
                performSearch(progressMonitor);
247
            } finally {
248
                if (progressMonitor != null) {
249
                    progressMonitor.done();
250
                }
251
            }
252
253
            //                ModalContext.run(getRunnableWithProgress(), true, getProgressMonitor(),
254
            //                    Display.getCurrent());
255
        }
256
    }
257
258
    /**
259
     * Determines if the method represents a recursion call (i.e. whether the
260
     * method call is already in the cache.)
261
     *
262
     * @return True if the call is part of a recursion
263
     */
264
    public boolean isRecursive() {
265
        MethodWrapper current = getParent();
266
267
        while (current != null) {
268
            if (getMember().getHandleIdentifier().equals(current.getMember()
269
                                                                        .getHandleIdentifier())) {
270
                return true;
271
            }
272
273
            current = current.getParent();
274
        }
275
276
        return false;
277
    }
278
279
    /**
280
     * This method finds the children of the current IMethod (either callers or
281
     * callees, depending on the concrete subclass.
282
     * @return The result of the search for children
283
     */
284
    protected abstract Map findChildren(IProgressMonitor progressMonitor);
285
286
    private Map getMethodCache() {
287
        return fMethodCache;
288
    }
289
290
    private void initCalls() {
291
        this.fElements = new HashMap();
292
293
        initCacheForMethod();
294
    }
295
296
    /**
297
     * Looks up a previously created search result in the "global" cache.
298
     * @param method
299
     * @return List List of previously found search results
300
     */
301
    private Map lookupMethod(MethodCall methodCall) {
302
        return (Map) getMethodCache().get(methodCall.getKey());
303
    }
304
305
    private void performSearch(IProgressMonitor progressMonitor) {
306
        fElements = findChildren(progressMonitor);
307
308
        for (Iterator iter = fElements.keySet().iterator(); iter.hasNext();) {
309
            MethodCall methodCall = getMethodCallFromMap(fElements, iter.next());
310
            addCallToCache(methodCall);
311
        }
312
    }
313
314
    private MethodCall getMethodCallFromMap(Map elements, Object key) {
315
        return (MethodCall) elements.get(key);
316
    }
317
318
    private IProgressMonitor getProgressMonitor() {
319
        return CallHierarchy.getDefault().getProgressMonitor();
320
    }
321
322
    private void initCacheForMethod() {
323
        Map cachedCalls = new HashMap();
324
        getMethodCache().put(this.getMethodCall().getKey(), cachedCalls);
325
    }
326
}
(-)ui/org/eclipse/jdt/internal/ui/callhierarchy/OpenDeclarationAction.java (-8 / +6 lines)
Lines 16-40 Link Here
16
import java.util.List;
16
import java.util.List;
17
17
18
import org.eclipse.core.runtime.IAdaptable;
18
import org.eclipse.core.runtime.IAdaptable;
19
19
import org.eclipse.jdt.core.IMethod;
20
import org.eclipse.jdt.core.JavaModelException;
21
import org.eclipse.jdt.internal.corext.callhierarchy.MethodWrapper;
22
import org.eclipse.jdt.internal.ui.util.SelectionUtil;
23
import org.eclipse.jdt.ui.actions.OpenAction;
20
import org.eclipse.jface.viewers.ISelection;
24
import org.eclipse.jface.viewers.ISelection;
21
import org.eclipse.jface.viewers.IStructuredSelection;
25
import org.eclipse.jface.viewers.IStructuredSelection;
22
import org.eclipse.jface.viewers.StructuredSelection;
26
import org.eclipse.jface.viewers.StructuredSelection;
23
24
import org.eclipse.ui.IWorkbenchSite;
27
import org.eclipse.ui.IWorkbenchSite;
25
28
26
import org.eclipse.jdt.core.IMethod;
27
import org.eclipse.jdt.core.JavaModelException;
28
29
import org.eclipse.jdt.ui.actions.OpenAction;
30
31
class OpenDeclarationAction extends OpenAction {
29
class OpenDeclarationAction extends OpenAction {
32
    public OpenDeclarationAction(IWorkbenchSite site) {
30
    public OpenDeclarationAction(IWorkbenchSite site) {
33
        super(site);
31
        super(site);
34
    }
32
    }
35
33
36
    public boolean canActionBeAdded() {
34
    public boolean canActionBeAdded() {
37
        Object element = Utility.getSingleElement(getSelection());
35
        Object element = SelectionUtil.getSingleElement(getSelection());
38
36
39
        IMethod method = null;
37
        IMethod method = null;
40
        
38
        
(-)ui/org/eclipse/jdt/internal/ui/callhierarchy/OpenLocationAction.java (-4 / +4 lines)
Lines 13-24 Link Here
13
13
14
import java.util.Iterator;
14
import java.util.Iterator;
15
15
16
import org.eclipse.jdt.internal.corext.callhierarchy.CallLocation;
17
import org.eclipse.jdt.internal.corext.callhierarchy.MethodWrapper;
18
import org.eclipse.jdt.ui.actions.SelectionDispatchAction;
16
import org.eclipse.jface.viewers.IStructuredSelection;
19
import org.eclipse.jface.viewers.IStructuredSelection;
17
18
import org.eclipse.ui.IWorkbenchSite;
20
import org.eclipse.ui.IWorkbenchSite;
19
21
20
import org.eclipse.jdt.ui.actions.SelectionDispatchAction;
21
22
class OpenLocationAction extends SelectionDispatchAction {
22
class OpenLocationAction extends SelectionDispatchAction {
23
    public OpenLocationAction(IWorkbenchSite site) {
23
    public OpenLocationAction(IWorkbenchSite site) {
24
        super(site);
24
        super(site);
Lines 56-62 Link Here
56
    }
56
    }
57
57
58
    private void run(Object element) {
58
    private void run(Object element) {
59
        CallHierarchy.openInEditor(element, getShell(), getDialogTitle());
59
        CallHierarchyUI.openInEditor(element, getShell(), getDialogTitle());
60
    }
60
    }
61
61
62
    private String getDialogTitle() {
62
    private String getDialogTitle() {
(-)ui/org/eclipse/jdt/internal/ui/callhierarchy/Utility.java (-22 lines)
Lines 20-47 Link Here
20
import org.eclipse.jdt.internal.ui.JavaPlugin;
20
import org.eclipse.jdt.internal.ui.JavaPlugin;
21
21
22
class Utility {
22
class Utility {
23
    /**
24
     * Returns the selected element if the selection
25
     * consists of a single element only.
26
     *
27
     * @param selection the selection
28
     * @return the selected first element or null
29
     *
30
     */
31
    public static Object getSingleElement(ISelection s) {
32
        if (!(s instanceof IStructuredSelection)) {
33
            return null;
34
        }
35
36
        IStructuredSelection selection = (IStructuredSelection) s;
37
38
        if (selection.size() != 1) {
39
            return null;
40
        }
41
42
        return selection.getFirstElement();
43
    }
44
45
    static void logDebug(String message) {
23
    static void logDebug(String message) {
46
        if (JavaPlugin.getDefault().isDebugging()) {
24
        if (JavaPlugin.getDefault().isDebugging()) {
47
            JavaPlugin.getDefault().getLog().log(new Status(IStatus.INFO,
25
            JavaPlugin.getDefault().getLog().log(new Status(IStatus.INFO,

Return to bug 36520