]>
Commit | Line | Data |
---|---|---|
1b2798f6 EK |
1 | /******************************************************************************* |
2 | * Copyright (c) 2000, 2011 IBM Corporation and others. | |
3 | * All rights reserved. This program and the accompanying materials | |
4 | * are made available under the terms of the Eclipse Public License v1.0 | |
5 | * which accompanies this distribution, and is available at | |
6 | * http://www.eclipse.org/legal/epl-v10.html | |
7 | * | |
8 | * Contributors: | |
9 | * IBM Corporation - initial API and implementation | |
10 | *******************************************************************************/ | |
11 | package org.eclipse.jdt.ui.actions; | |
12 | ||
13 | import org.eclipse.ui.IWorkbenchSite; | |
14 | import org.eclipse.ui.PlatformUI; | |
15 | ||
16 | import org.eclipse.jdt.core.ICompilationUnit; | |
17 | import org.eclipse.jdt.core.IField; | |
18 | import org.eclipse.jdt.core.IJavaElement; | |
19 | import org.eclipse.jdt.core.ILocalVariable; | |
20 | import org.eclipse.jdt.core.IMethod; | |
21 | import org.eclipse.jdt.core.IType; | |
22 | import org.eclipse.jdt.core.ITypeParameter; | |
23 | import org.eclipse.jdt.core.JavaModelException; | |
24 | import org.eclipse.jdt.core.search.IJavaSearchScope; | |
25 | import org.eclipse.jdt.core.search.SearchEngine; | |
26 | ||
27 | import org.eclipse.jdt.ui.search.ElementQuerySpecification; | |
28 | import org.eclipse.jdt.ui.search.QuerySpecification; | |
29 | ||
30 | import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; | |
31 | import org.eclipse.jdt.internal.ui.JavaPluginImages; | |
32 | import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor; | |
33 | import org.eclipse.jdt.internal.ui.search.JavaSearchScopeFactory; | |
34 | import org.eclipse.jdt.internal.ui.search.SearchMessages; | |
35 | ||
36 | /** | |
37 | * Finds references of the selected element in its hierarchy. | |
38 | * The action is applicable to selections representing a Java element. | |
39 | * | |
40 | * <p> | |
41 | * This class may be instantiated; it is not intended to be subclassed. | |
42 | * </p> | |
43 | * | |
44 | * @since 2.0 | |
45 | * | |
46 | * @noextend This class is not intended to be subclassed by clients. | |
47 | */ | |
48 | public class FindReferencesInHierarchyAction extends FindReferencesAction { | |
49 | ||
50 | /** | |
51 | * Creates a new <code>FindReferencesInHierarchyAction</code>. The action | |
52 | * requires that the selection provided by the site's selection provider is of type | |
53 | * <code>org.eclipse.jface.viewers.IStructuredSelection</code>. | |
54 | * | |
55 | * @param site the site providing context information for this action | |
56 | */ | |
57 | public FindReferencesInHierarchyAction(IWorkbenchSite site) { | |
58 | super(site); | |
59 | } | |
60 | ||
61 | /** | |
62 | * Note: This constructor is for internal use only. Clients should not call this constructor. | |
63 | * @param editor the Java editor | |
64 | * | |
65 | * @noreference This constructor is not intended to be referenced by clients. | |
66 | */ | |
67 | public FindReferencesInHierarchyAction(JavaEditor editor) { | |
68 | super(editor); | |
69 | } | |
70 | ||
71 | @Override | |
72 | Class<?>[] getValidTypes() { | |
73 | return new Class[] { ICompilationUnit.class, IType.class, IMethod.class, IField.class, ILocalVariable.class, ITypeParameter.class }; | |
74 | } | |
75 | ||
76 | @Override | |
77 | void init() { | |
78 | setText(SearchMessages.Search_FindHierarchyReferencesAction_label); | |
79 | setToolTipText(SearchMessages.Search_FindHierarchyReferencesAction_tooltip); | |
80 | setImageDescriptor(JavaPluginImages.DESC_OBJS_SEARCH_REF); | |
81 | PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.FIND_REFERENCES_IN_HIERARCHY_ACTION); | |
82 | } | |
83 | ||
84 | @Override | |
85 | QuerySpecification createQuery(IJavaElement element) throws JavaModelException, InterruptedException { | |
86 | IType type= getType(element); | |
87 | if (type == null) { | |
88 | return super.createQuery(element); | |
89 | } | |
90 | JavaSearchScopeFactory factory= JavaSearchScopeFactory.getInstance(); | |
91 | IJavaSearchScope scope= SearchEngine.createHierarchyScope(type); | |
92 | String description= factory.getHierarchyScopeDescription(type); | |
93 | return new ElementQuerySpecification(element, getLimitTo(), scope, description); | |
94 | } | |
95 | ||
96 | } |