]> git.uio.no Git - ifi-stolz-refaktor.git/blame - case-study/jdt-after/ui/org/eclipse/jdt/ui/actions/FindReferencesInProjectAction.java
Some talks, mostly identical.
[ifi-stolz-refaktor.git] / case-study / jdt-after / ui / org / eclipse / jdt / ui / actions / FindReferencesInProjectAction.java
CommitLineData
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 *******************************************************************************/
11package org.eclipse.jdt.ui.actions;
12
13import org.eclipse.ui.IWorkbenchSite;
14import org.eclipse.ui.PlatformUI;
15
16import org.eclipse.jdt.core.ICompilationUnit;
17import org.eclipse.jdt.core.IField;
18import org.eclipse.jdt.core.IImportDeclaration;
19import org.eclipse.jdt.core.IJavaElement;
20import org.eclipse.jdt.core.ILocalVariable;
21import org.eclipse.jdt.core.IMethod;
22import org.eclipse.jdt.core.IPackageDeclaration;
23import org.eclipse.jdt.core.IPackageFragment;
24import org.eclipse.jdt.core.IType;
25import org.eclipse.jdt.core.ITypeParameter;
26import org.eclipse.jdt.core.JavaModelException;
27import org.eclipse.jdt.core.search.IJavaSearchScope;
28
29import org.eclipse.jdt.ui.search.ElementQuerySpecification;
30import org.eclipse.jdt.ui.search.QuerySpecification;
31
32import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
33import org.eclipse.jdt.internal.ui.JavaPluginImages;
34import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor;
35import org.eclipse.jdt.internal.ui.search.JavaSearchScopeFactory;
36import 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 */
51public 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}