]>
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.IImportDeclaration; | |
19 | import org.eclipse.jdt.core.IJavaElement; | |
20 | import org.eclipse.jdt.core.ILocalVariable; | |
21 | import org.eclipse.jdt.core.IMethod; | |
22 | import org.eclipse.jdt.core.IPackageDeclaration; | |
23 | import org.eclipse.jdt.core.IPackageFragment; | |
24 | import org.eclipse.jdt.core.IType; | |
25 | import org.eclipse.jdt.core.ITypeParameter; | |
26 | import org.eclipse.jdt.core.JavaModelException; | |
27 | import org.eclipse.jdt.core.search.IJavaSearchScope; | |
28 | ||
29 | import org.eclipse.jdt.ui.search.ElementQuerySpecification; | |
30 | import org.eclipse.jdt.ui.search.QuerySpecification; | |
31 | ||
32 | import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; | |
33 | import org.eclipse.jdt.internal.ui.JavaPluginImages; | |
34 | import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor; | |
35 | import org.eclipse.jdt.internal.ui.search.JavaSearchScopeFactory; | |
36 | import org.eclipse.jdt.internal.ui.search.SearchMessages; | |
37 | ||
38 | /** | |
39 | * Finds references to the selected element in the enclosing project | |
40 | * of the selected element. | |
41 | * The action is applicable to selections representing a Java element. | |
42 | * | |
43 | * <p> | |
44 | * This class may be instantiated; it is not intended to be subclassed. | |
45 | * </p> | |
46 | * | |
47 | * @since 3.0 | |
48 | * | |
49 | * @noextend This class is not intended to be subclassed by clients. | |
50 | */ | |
51 | public class FindReferencesInProjectAction extends FindReferencesAction { | |
52 | ||
53 | /** | |
54 | * Creates a new <code>FindReferencesInProjectAction</code>. The action | |
55 | * requires that the selection provided by the site's selection provider is of type | |
56 | * <code>IStructuredSelection</code>. | |
57 | * | |
58 | * @param site the site providing context information for this action | |
59 | */ | |
60 | public FindReferencesInProjectAction(IWorkbenchSite site) { | |
61 | super(site); | |
62 | } | |
63 | ||
64 | /** | |
65 | * Note: This constructor is for internal use only. Clients should not call this constructor. | |
66 | * @param editor the Java editor | |
67 | * | |
68 | * @noreference This constructor is not intended to be referenced by clients. | |
69 | */ | |
70 | public FindReferencesInProjectAction(JavaEditor editor) { | |
71 | super(editor); | |
72 | } | |
73 | ||
74 | @Override | |
75 | Class<?>[] getValidTypes() { | |
76 | return new Class[] { IField.class, IMethod.class, IType.class, ICompilationUnit.class, IPackageDeclaration.class, IImportDeclaration.class, IPackageFragment.class, ILocalVariable.class, ITypeParameter.class }; | |
77 | } | |
78 | ||
79 | @Override | |
80 | void init() { | |
81 | setText(SearchMessages.Search_FindReferencesInProjectAction_label); | |
82 | setToolTipText(SearchMessages.Search_FindReferencesInProjectAction_tooltip); | |
83 | setImageDescriptor(JavaPluginImages.DESC_OBJS_SEARCH_REF); | |
84 | PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.FIND_REFERENCES_IN_PROJECT_ACTION); | |
85 | } | |
86 | ||
87 | @Override | |
88 | QuerySpecification createQuery(IJavaElement element) throws JavaModelException { | |
89 | JavaSearchScopeFactory factory= JavaSearchScopeFactory.getInstance(); | |
90 | JavaEditor editor= getEditor(); | |
91 | ||
92 | IJavaSearchScope scope; | |
93 | String description; | |
94 | boolean isInsideJRE= factory.isInsideJRE(element); | |
95 | if (editor != null) { | |
96 | scope= factory.createJavaProjectSearchScope(editor.getEditorInput(), isInsideJRE); | |
97 | description= factory.getProjectScopeDescription(editor.getEditorInput(), isInsideJRE); | |
98 | } else { | |
99 | scope= factory.createJavaProjectSearchScope(element.getJavaProject(), isInsideJRE); | |
100 | description= factory.getProjectScopeDescription(element.getJavaProject(), isInsideJRE); | |
101 | } | |
102 | return new ElementQuerySpecification(element, getLimitTo(), scope, description); | |
103 | } | |
104 | ||
105 | } |