View | Details | Raw Unified | Return to bug 477340 | Differences between
and this patch

Collapse All | Expand All

(-)a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/search/JavaSearchQuery.java (-10 / +44 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
2
 * Copyright (c) 2000, 2016 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 Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 9-14 Link Here
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.ui.search;
11
package org.eclipse.jdt.internal.ui.search;
12
13
import java.util.ArrayList;
14
import java.util.Iterator;
12
15
13
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.core.runtime.CoreException;
14
import org.eclipse.core.runtime.IProgressMonitor;
17
import org.eclipse.core.runtime.IProgressMonitor;
Lines 116-131 Link Here
116
				totalTicks+= ticks[i];
119
				totalTicks+= ticks[i];
117
			}
120
			}
118
121
119
			SearchPattern pattern;
122
			SearchPattern pattern= null;
120
			String stringPattern;
123
			String stringPattern= null;
121
124
122
			if (fPatternData instanceof ElementQuerySpecification) {
125
			if (fPatternData instanceof ElementQuerySpecification) {
123
				IJavaElement element= ((ElementQuerySpecification) fPatternData).getElement();
126
				if (((ElementQuerySpecification) fPatternData).getElements().size() == 1){
124
				stringPattern= JavaElementLabels.getElementLabel(element, JavaElementLabels.ALL_DEFAULT);
127
					IJavaElement element= ((ElementQuerySpecification) fPatternData).getElement();
125
				if (!element.exists()) {
128
					stringPattern= JavaElementLabels.getElementLabel(element, JavaElementLabels.ALL_DEFAULT);
126
					return new Status(IStatus.ERROR, JavaPlugin.getPluginId(), 0, Messages.format(SearchMessages.JavaSearchQuery_error_element_does_not_exist, stringPattern), null);
129
					if (!element.exists()) {
130
						return new Status(IStatus.ERROR, JavaPlugin.getPluginId(), 0, Messages.format(SearchMessages.JavaSearchQuery_error_element_does_not_exist, stringPattern), null);
131
					}
132
					pattern= SearchPattern.createPattern(element, fPatternData.getLimitTo(), SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
133
				}else{
134
					ArrayList<IJavaElement> elementList = ((ElementQuerySpecification) fPatternData).getElements();
135
					for (Iterator iterator= elementList.iterator(); iterator.hasNext();) {
136
						IJavaElement element= (IJavaElement) iterator.next();
137
						stringPattern= JavaElementLabels.getElementLabel(element, JavaElementLabels.ALL_DEFAULT);
138
						if (!element.exists()) {
139
							return new Status(IStatus.ERROR, JavaPlugin.getPluginId(), 0, Messages.format(SearchMessages.JavaSearchQuery_error_element_does_not_exist, stringPattern), null);
140
						}
141
						SearchPattern elementPattern = SearchPattern.createPattern(element, fPatternData.getLimitTo(), SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
142
						if (pattern == null)
143
							pattern= elementPattern;
144
						else
145
							pattern= SearchPattern.createOrPattern(pattern, elementPattern);
146
					}
127
				}
147
				}
128
				pattern= SearchPattern.createPattern(element, fPatternData.getLimitTo(), SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
129
			} else {
148
			} else {
130
				PatternQuerySpecification patternSpec = (PatternQuerySpecification) fPatternData;
149
				PatternQuerySpecification patternSpec = (PatternQuerySpecification) fPatternData;
131
				stringPattern= patternSpec.getPattern();
150
				stringPattern= patternSpec.getPattern();
Lines 242-250 Link Here
242
261
243
	private String getSearchPatternDescription() {
262
	private String getSearchPatternDescription() {
244
		if (fPatternData instanceof ElementQuerySpecification) {
263
		if (fPatternData instanceof ElementQuerySpecification) {
245
			IJavaElement element= ((ElementQuerySpecification) fPatternData).getElement();
264
			if (((ElementQuerySpecification) fPatternData).getElements().size() == 1){
246
			return JavaElementLabels.getElementLabel(element, JavaElementLabels.ALL_DEFAULT
265
				IJavaElement element= ((ElementQuerySpecification) fPatternData).getElement();
266
				return JavaElementLabels.getElementLabel(element, JavaElementLabels.ALL_DEFAULT
247
					| JavaElementLabels.ALL_FULLY_QUALIFIED | JavaElementLabels.USE_RESOLVED | JavaElementLabels.P_COMPRESSED);
267
					| JavaElementLabels.ALL_FULLY_QUALIFIED | JavaElementLabels.USE_RESOLVED | JavaElementLabels.P_COMPRESSED);
268
			} else {
269
				ArrayList<IJavaElement> elements= ((ElementQuerySpecification) fPatternData).getElements();
270
				StringBuffer description = new StringBuffer();
271
				for (Iterator<IJavaElement> iterator= elements.iterator(); iterator.hasNext();) {
272
					IJavaElement element= iterator.next();
273
					if (description.length() != 0 && iterator.hasNext())
274
						description.append(", "); //$NON-NLS-1$
275
					else if (description.length() > 0)
276
						description.append(" and "); //$NON-NLS-1$
277
					description.append(JavaElementLabels.getElementLabel(element, JavaElementLabels.ALL_DEFAULT
278
						| JavaElementLabels.ALL_FULLY_QUALIFIED | JavaElementLabels.USE_RESOLVED | JavaElementLabels.P_COMPRESSED));
279
				}
280
				return description.toString();
281
			}
248
		}
282
		}
249
		return BasicElementLabels.getFilePattern(((PatternQuerySpecification) fPatternData).getPattern());
283
		return BasicElementLabels.getFilePattern(((PatternQuerySpecification) fPatternData).getPattern());
250
	}
284
	}
(-)a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/search/SearchMessages.java (-1 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2014 IBM Corporation and others.
2
 * Copyright (c) 2000, 2016 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 Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 268-273 Link Here
268
268
269
	public static String JavaSearchQuery_error_element_does_not_exist;
269
	public static String JavaSearchQuery_error_element_does_not_exist;
270
	public static String JavaSearchQuery_pluralReferencesWithMatchLocations;
270
	public static String JavaSearchQuery_pluralReferencesWithMatchLocations;
271
	public static String JavaSearchQuery_multi_selection_search_and;
271
	public static String MatchFilter_PotentialFilter_name;
272
	public static String MatchFilter_PotentialFilter_name;
272
	public static String MatchFilter_PotentialFilter_actionLabel;
273
	public static String MatchFilter_PotentialFilter_actionLabel;
273
	public static String MatchFilter_PotentialFilter_description;
274
	public static String MatchFilter_PotentialFilter_description;
(-)a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/search/SearchMessages.properties (-1 / +3 lines)
Lines 1-5 Link Here
1
###############################################################################
1
###############################################################################
2
# Copyright (c) 2000, 2011 IBM Corporation and others.
2
# Copyright (c) 2000, 2016 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 Eclipse Public License v1.0
4
# are made available under the terms of the Eclipse Public License v1.0
5
# which accompanies this distribution, and is available at
5
# which accompanies this distribution, and is available at
Lines 255-260 Link Here
255
JavaSearchQuery_error_participant_search=An error occurred during participant search. The participant has been disabled for the current session.
255
JavaSearchQuery_error_participant_search=An error occurred during participant search. The participant has been disabled for the current session.
256
JavaSearchQuery_pluralReferencesWithMatchLocations=''{0}'' in ''{3}'' - {1} references in {2}
256
JavaSearchQuery_pluralReferencesWithMatchLocations=''{0}'' in ''{3}'' - {1} references in {2}
257
257
258
JavaSearchQuery_multi_selection_search_and=and
259
258
SearchParticipant_error_noID=Missing id attribute on search participant extension {0}
260
SearchParticipant_error_noID=Missing id attribute on search participant extension {0}
259
SearchParticipant_error_noNature=Missing nature attribute on search participant {0}
261
SearchParticipant_error_noNature=Missing nature attribute on search participant {0}
260
SearchParticipant_error_noClass=Missing class attribute on search participant {0}
262
SearchParticipant_error_noClass=Missing class attribute on search participant {0}
(-)a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/typehierarchy/TypeHierarchyViewer.java (-2 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
2
 * Copyright (c) 2000, 2016 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 Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 41-47 Link Here
41
41
42
42
43
	public TypeHierarchyViewer(Composite parent, IContentProvider contentProvider, TypeHierarchyLifeCycle lifeCycle) {
43
	public TypeHierarchyViewer(Composite parent, IContentProvider contentProvider, TypeHierarchyLifeCycle lifeCycle) {
44
		super(new Tree(parent, SWT.SINGLE));
44
		super(new Tree(parent, SWT.MULTI));
45
45
46
		fLabelProvider= new HierarchyLabelProvider(lifeCycle);
46
		fLabelProvider= new HierarchyLabelProvider(lifeCycle);
47
47
(-)a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/FindAction.java (-11 / +116 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
2
 * Copyright (c) 2000, 2016 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 Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 11-16 Link Here
11
package org.eclipse.jdt.ui.actions;
11
package org.eclipse.jdt.ui.actions;
12
12
13
import java.lang.reflect.InvocationTargetException;
13
import java.lang.reflect.InvocationTargetException;
14
import java.util.ArrayList;
15
import java.util.Iterator;
14
16
15
import org.eclipse.core.runtime.IAdaptable;
17
import org.eclipse.core.runtime.IAdaptable;
16
import org.eclipse.core.runtime.IStatus;
18
import org.eclipse.core.runtime.IStatus;
Lines 98-104 Link Here
98
	 */
100
	 */
99
	abstract Class<?>[] getValidTypes();
101
	abstract Class<?>[] getValidTypes();
100
102
101
	private boolean canOperateOn(IStructuredSelection sel) {
103
	boolean canOperateOn(IStructuredSelection sel) {
102
		return sel != null && !sel.isEmpty() && canOperateOn(getJavaElement(sel, true));
104
		return sel != null && !sel.isEmpty() && canOperateOn(getJavaElement(sel, true));
103
	}
105
	}
104
106
Lines 139-144 Link Here
139
		}
141
		}
140
	}
142
	}
141
143
144
	IJavaElement getJavaElement(Object firstElement, boolean silent) {
145
		IJavaElement elem= null;
146
		if (firstElement instanceof IJavaElement)
147
			elem= (IJavaElement) firstElement;
148
		else if (firstElement instanceof IAdaptable)
149
			elem= ((IAdaptable) firstElement).getAdapter(IJavaElement.class);
150
		if (elem != null) {
151
			return getTypeIfPossible(elem, silent);
152
		}
153
154
		return null;
155
	}
156
	
142
	IJavaElement getJavaElement(IStructuredSelection selection, boolean silent) {
157
	IJavaElement getJavaElement(IStructuredSelection selection, boolean silent) {
143
		if (selection.size() == 1) {
158
		if (selection.size() == 1) {
144
			Object firstElement= selection.getFirstElement();
159
			Object firstElement= selection.getFirstElement();
Lines 153-158 Link Here
153
168
154
		}
169
		}
155
		return null;
170
		return null;
171
	}
172
	
173
	ArrayList<IJavaElement> getMultipleJavaElement(IStructuredSelection selection, boolean silent) {
174
		ArrayList<IJavaElement> javaElementList = new ArrayList<>();
175
		for (Iterator<?> iter= selection.iterator(); iter.hasNext();) {
176
			Object firstElement= iter.next();
177
			IJavaElement elem= null;
178
			if (firstElement instanceof IJavaElement)
179
				elem= (IJavaElement) firstElement;
180
			else if (firstElement instanceof IAdaptable)
181
				elem= ((IAdaptable) firstElement).getAdapter(IJavaElement.class);
182
			if (elem != null) {
183
				javaElementList.add(getTypeIfPossible(elem, silent));
184
			}
185
		}
186
		return javaElementList;
156
	}
187
	}
157
188
158
	private void showOperationUnavailableDialog() {
189
	private void showOperationUnavailableDialog() {
Lines 201-215 Link Here
201
	 */
232
	 */
202
	@Override
233
	@Override
203
	public void run(IStructuredSelection selection) {
234
	public void run(IStructuredSelection selection) {
204
		IJavaElement element= getJavaElement(selection, false);
235
		if (selection.size() == 1) {
205
		if (element == null || !element.exists()) {
236
			IJavaElement element= getJavaElement(selection, false);
206
			showOperationUnavailableDialog();
237
			if (element == null || !element.exists()) {
207
			return;
238
				showOperationUnavailableDialog();
239
				return;
240
			}
241
			else if (element == RETURN_WITHOUT_BEEP)
242
				return;
243
	
244
			run(element);
208
		}
245
		}
209
		else if (element == RETURN_WITHOUT_BEEP)
246
		else {
210
			return;
247
			ArrayList<IJavaElement> elementList = getMultipleJavaElement(selection, false);
211
248
			for (Iterator iterator= elementList.iterator(); iterator.hasNext();) {
212
		run(element);
249
				IJavaElement element= (IJavaElement) iterator.next();
250
				if (element == null || !element.exists()) {
251
					showOperationUnavailableDialog();
252
					return;
253
				}
254
				else if (!ActionUtil.isProcessable(getShell(), element))
255
					return;
256
				else if (element == RETURN_WITHOUT_BEEP)
257
					return;
258
			}
259
			run(elementList);
260
		}
213
	}
261
	}
214
262
215
	/*
263
	/*
Lines 275-282 Link Here
275
			// cancelled
323
			// cancelled
276
		}
324
		}
277
	}
325
	}
326
	
327
	/**
328
	 * Executes this action for the given java element List.
329
	 * @param element The java element in Lists to be found.
330
	 * @since 3.12
331
	 */
332
	public void run(ArrayList<IJavaElement> element) {
333
		// will return true except for debugging purposes.
334
		try {
335
			performNewSearch(element);
336
		} catch (JavaModelException ex) {
337
			ExceptionHandler.handle(ex, getShell(), SearchMessages.Search_Error_search_notsuccessful_title, SearchMessages.Search_Error_search_notsuccessful_message);
338
		} catch (InterruptedException e) {
339
			// cancelled
340
		}
341
	}
278
342
279
	private void performNewSearch(IJavaElement element) throws JavaModelException, InterruptedException {
343
	private void performNewSearch(IJavaElement element) throws JavaModelException, InterruptedException {
344
		JavaSearchQuery query= new JavaSearchQuery(createQuery(element));
345
		if (query.canRunInBackground()) {
346
			/*
347
			 * This indirection with Object as parameter is needed to prevent the loading
348
			 * of the Search plug-in: the VM verifies the method call and hence loads the
349
			 * types used in the method signature, eventually triggering the loading of
350
			 * a plug-in (in this case ISearchQuery results in Search plug-in being loaded).
351
			 */
352
			SearchUtil.runQueryInBackground(query);
353
		} else {
354
			IProgressService progressService= PlatformUI.getWorkbench().getProgressService();
355
			/*
356
			 * This indirection with Object as parameter is needed to prevent the loading
357
			 * of the Search plug-in: the VM verifies the method call and hence loads the
358
			 * types used in the method signature, eventually triggering the loading of
359
			 * a plug-in (in this case it would be ISearchQuery).
360
			 */
361
			IStatus status= SearchUtil.runQueryInForeground(progressService, query);
362
			if (status.matches(IStatus.ERROR | IStatus.INFO | IStatus.WARNING)) {
363
				ErrorDialog.openError(getShell(), SearchMessages.Search_Error_search_title, SearchMessages.Search_Error_search_message, status);
364
			}
365
		}
366
	}
367
	
368
	private void performNewSearch(ArrayList<IJavaElement> element) throws JavaModelException, InterruptedException {
280
		JavaSearchQuery query= new JavaSearchQuery(createQuery(element));
369
		JavaSearchQuery query= new JavaSearchQuery(createQuery(element));
281
		if (query.canRunInBackground()) {
370
		if (query.canRunInBackground()) {
282
			/*
371
			/*
Lines 316-322 Link Here
316
		String description= factory.getWorkspaceScopeDescription(true);
405
		String description= factory.getWorkspaceScopeDescription(true);
317
		return new ElementQuerySpecification(element, getLimitTo(), scope, description);
406
		return new ElementQuerySpecification(element, getLimitTo(), scope, description);
318
	}
407
	}
319
408
	
409
	/**
410
	 * Creates a query for the given element. Subclasses reimplement this method.
411
	 *
412
	 * @param elementList the elements to create a query for
413
	 *
414
	 * @return returns the query
415
	 * @throws JavaModelException thrown when accessing the element failed
416
	 * @throws InterruptedException thrown when the user interrupted the query selection
417
	 */
418
	QuerySpecification createQuery(ArrayList<IJavaElement> elementList) throws JavaModelException, InterruptedException {
419
		IJavaElement element = elementList.get(0);
420
		JavaSearchScopeFactory factory= JavaSearchScopeFactory.getInstance();
421
		IJavaSearchScope scope= factory.createWorkspaceScope(true);
422
		String description= factory.getWorkspaceScopeDescription(true);
423
		return new ElementQuerySpecification(element, getLimitTo(), scope, description);
424
	}
320
	abstract int getLimitTo();
425
	abstract int getLimitTo();
321
426
322
	IType getType(IJavaElement element) {
427
	IType getType(IJavaElement element) {
(-)a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/FindReadReferencesInProjectAction.java (-1 / +27 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
2
 * Copyright (c) 2000, 2016 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 Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 9-14 Link Here
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.ui.actions;
11
package org.eclipse.jdt.ui.actions;
12
13
import java.util.ArrayList;
12
14
13
import org.eclipse.ui.IWorkbenchSite;
15
import org.eclipse.ui.IWorkbenchSite;
14
import org.eclipse.ui.PlatformUI;
16
import org.eclipse.ui.PlatformUI;
Lines 87-90 Link Here
87
		return new ElementQuerySpecification(element, getLimitTo(), scope, description);
89
		return new ElementQuerySpecification(element, getLimitTo(), scope, description);
88
	}
90
	}
89
91
92
	@Override
93
	QuerySpecification createQuery(ArrayList<IJavaElement> elementList) throws JavaModelException, InterruptedException {
94
		JavaSearchScopeFactory factory= JavaSearchScopeFactory.getInstance();
95
		JavaEditor editor= getEditor();
96
97
		IJavaSearchScope scope;
98
		String description;
99
		boolean isInsideJRE= factory.isInsideJRE(elementList.get(0));
100
		if (editor != null) {
101
			scope= factory.createJavaProjectSearchScope(editor.getEditorInput(), isInsideJRE);
102
			description= factory.getProjectScopeDescription(editor.getEditorInput(), isInsideJRE);
103
		} else {
104
			String[] elementNames= new String[elementList.size()];
105
			int i= 0;
106
			for (IJavaElement element : elementList) {
107
				elementNames[i++]= element.getElementName();
108
			}
109
			scope= factory.createJavaProjectSearchScope(elementNames, isInsideJRE);
110
			description= factory.getProjectScopeDescription(elementList.get(0).getJavaProject(), isInsideJRE);
111
		}
112
		return new ElementQuerySpecification(elementList, getLimitTo(), scope, description);
113
	}
114
115
90
}
116
}
(-)a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/FindReferencesAction.java (-1 / +31 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
2
 * Copyright (c) 2000, 2016 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 Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 9-14 Link Here
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.ui.actions;
11
package org.eclipse.jdt.ui.actions;
12
13
import java.util.ArrayList;
14
import java.util.Iterator;
15
16
import org.eclipse.jface.viewers.IStructuredSelection;
12
17
13
import org.eclipse.ui.IWorkbenchSite;
18
import org.eclipse.ui.IWorkbenchSite;
14
import org.eclipse.ui.PlatformUI;
19
import org.eclipse.ui.PlatformUI;
Lines 99-108 Link Here
99
		String description= factory.getWorkspaceScopeDescription(isInsideJRE);
104
		String description= factory.getWorkspaceScopeDescription(isInsideJRE);
100
		return new ElementQuerySpecification(element, getLimitTo(), scope, description);
105
		return new ElementQuerySpecification(element, getLimitTo(), scope, description);
101
	}
106
	}
107
	
108
	@Override
109
	QuerySpecification createQuery(ArrayList<IJavaElement> element) throws JavaModelException, InterruptedException {
110
		JavaSearchScopeFactory factory= JavaSearchScopeFactory.getInstance();
111
		boolean isInsideJRE= factory.isInsideJRE(element.get(0));
112
113
		IJavaSearchScope scope= factory.createWorkspaceScope(isInsideJRE);
114
		String description= factory.getWorkspaceScopeDescription(isInsideJRE);
115
		return new ElementQuerySpecification(element, getLimitTo(), scope, description);
116
	}
102
117
103
	@Override
118
	@Override
104
	public void run(IJavaElement element) {
119
	public void run(IJavaElement element) {
105
		SearchUtil.warnIfBinaryConstant(element, getShell());
120
		SearchUtil.warnIfBinaryConstant(element, getShell());
106
		super.run(element);
121
		super.run(element);
107
	}
122
	}
123
	
124
	@Override
125
	boolean canOperateOn(IStructuredSelection sel) {
126
		if ( sel == null || sel.isEmpty() ){
127
			return false;
128
		}
129
		for (Iterator<?> iter= sel.iterator(); iter.hasNext();) {
130
			Object element= iter.next();
131
			if( !canOperateOn(getJavaElement(element, true))){
132
				return false;
133
			}
134
		}
135
		return true;
136
	}
137
	
108
}
138
}
(-)a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/FindReferencesInHierarchyAction.java (+17 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.ui.actions;
11
package org.eclipse.jdt.ui.actions;
12
12
13
import java.util.Iterator;
14
15
import org.eclipse.jface.viewers.IStructuredSelection;
16
13
import org.eclipse.ui.IWorkbenchSite;
17
import org.eclipse.ui.IWorkbenchSite;
14
import org.eclipse.ui.PlatformUI;
18
import org.eclipse.ui.PlatformUI;
15
19
Lines 93-96 Link Here
93
		return new ElementQuerySpecification(element, getLimitTo(), scope, description);
97
		return new ElementQuerySpecification(element, getLimitTo(), scope, description);
94
	}
98
	}
95
99
100
	@Override
101
	boolean canOperateOn(IStructuredSelection sel) {
102
		if ( sel == null || sel.isEmpty() || sel.size() > 1){
103
			return false;
104
		}
105
		for (Iterator<?> iter= sel.iterator(); iter.hasNext();) {
106
			Object element= iter.next();
107
			if( !canOperateOn(getJavaElement(element, true))){
108
				return false;
109
			}
110
		}
111
		return true;
112
	}
96
}
113
}
(-)a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/FindReferencesInProjectAction.java (-1 / +26 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
2
 * Copyright (c) 2000, 2016 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 Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 9-14 Link Here
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.ui.actions;
11
package org.eclipse.jdt.ui.actions;
12
13
import java.util.ArrayList;
12
14
13
import org.eclipse.ui.IWorkbenchSite;
15
import org.eclipse.ui.IWorkbenchSite;
14
import org.eclipse.ui.PlatformUI;
16
import org.eclipse.ui.PlatformUI;
Lines 102-105 Link Here
102
		return new ElementQuerySpecification(element, getLimitTo(), scope, description);
104
		return new ElementQuerySpecification(element, getLimitTo(), scope, description);
103
	}
105
	}
104
106
107
	@Override
108
	QuerySpecification createQuery(ArrayList<IJavaElement> elementList) throws JavaModelException, InterruptedException {
109
		JavaSearchScopeFactory factory= JavaSearchScopeFactory.getInstance();
110
		JavaEditor editor= getEditor();
111
112
		IJavaSearchScope scope;
113
		String description;
114
		boolean isInsideJRE= factory.isInsideJRE(elementList.get(0));
115
		if (editor != null) {
116
			scope= factory.createJavaProjectSearchScope(editor.getEditorInput(), isInsideJRE);
117
			description= factory.getProjectScopeDescription(editor.getEditorInput(), isInsideJRE);
118
		} else {
119
			String[] elementNames= new String[elementList.size()];
120
			int i= 0;
121
			for (IJavaElement element : elementList) {
122
				elementNames[i++]= element.getElementName();
123
			}
124
			scope= factory.createJavaProjectSearchScope(elementNames, isInsideJRE);
125
			description= factory.getProjectScopeDescription(elementList.get(0).getJavaProject(), isInsideJRE);
126
		}
127
		return new ElementQuerySpecification(elementList, getLimitTo(), scope, description);
128
	}
129
105
}
130
}
(-)a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/FindReferencesInWorkingSetAction.java (-1 / +19 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
2
 * Copyright (c) 2000, 2016 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 Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 9-14 Link Here
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.ui.actions;
11
package org.eclipse.jdt.ui.actions;
12
13
import java.util.ArrayList;
12
14
13
import org.eclipse.ui.IWorkbenchSite;
15
import org.eclipse.ui.IWorkbenchSite;
14
import org.eclipse.ui.IWorkingSet;
16
import org.eclipse.ui.IWorkingSet;
Lines 115-118 Link Here
115
		String description= factory.getWorkingSetScopeDescription(workingSets, JavaSearchScopeFactory.NO_PROJ);
117
		String description= factory.getWorkingSetScopeDescription(workingSets, JavaSearchScopeFactory.NO_PROJ);
116
		return new ElementQuerySpecification(element, getLimitTo(), scope, description);
118
		return new ElementQuerySpecification(element, getLimitTo(), scope, description);
117
	}
119
	}
120
121
	@Override
122
	QuerySpecification createQuery(ArrayList<IJavaElement> element) throws JavaModelException, InterruptedException {
123
		JavaSearchScopeFactory factory= JavaSearchScopeFactory.getInstance();
124
125
		IWorkingSet[] workingSets= fWorkingSets;
126
		if (fWorkingSets == null) {
127
			workingSets= factory.queryWorkingSets();
128
			if (workingSets == null)
129
				return super.createQuery(element); // in workspace
130
		}
131
		SearchUtil.updateLRUWorkingSets(workingSets);
132
		IJavaSearchScope scope= factory.createJavaSearchScope(workingSets, JavaSearchScopeFactory.NO_PROJ);
133
		String description= factory.getWorkingSetScopeDescription(workingSets, JavaSearchScopeFactory.NO_PROJ);
134
		return new ElementQuerySpecification(element, getLimitTo(), scope, description);
135
	}
118
}
136
}
(-)a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/search/ElementQuerySpecification.java (-4 / +29 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.ui.search;
11
package org.eclipse.jdt.ui.search;
12
12
13
import java.util.ArrayList;
14
13
import org.eclipse.jdt.core.IJavaElement;
15
import org.eclipse.jdt.core.IJavaElement;
14
import org.eclipse.jdt.core.search.IJavaSearchScope;
16
import org.eclipse.jdt.core.search.IJavaSearchScope;
15
17
Lines 30-36 Link Here
30
 * @noextend This class is not intended to be subclassed by clients.
32
 * @noextend This class is not intended to be subclassed by clients.
31
 */
33
 */
32
public class ElementQuerySpecification extends QuerySpecification {
34
public class ElementQuerySpecification extends QuerySpecification {
33
	private IJavaElement fElement;
35
	private ArrayList<IJavaElement> fElements;
34
36
35
	/**
37
	/**
36
	 * A constructor.
38
	 * A constructor.
Lines 41-54 Link Here
41
	 */
43
	 */
42
	public ElementQuerySpecification(IJavaElement javaElement, int limitTo, IJavaSearchScope scope, String scopeDescription) {
44
	public ElementQuerySpecification(IJavaElement javaElement, int limitTo, IJavaSearchScope scope, String scopeDescription) {
43
		super(limitTo, scope, scopeDescription);
45
		super(limitTo, scope, scopeDescription);
44
		fElement= javaElement;
46
		fElements = new ArrayList<>(1);
47
		fElements.add(javaElement);
48
	}
49
	
50
	/**
51
	 * A constructor.
52
	 * @param javaElements The java elements the query should search for
53
	 * @param limitTo		  The kind of occurrence the query should search for
54
	 * @param scope		  The scope to search in
55
	 * @param scopeDescription A human readable description of the search scope
56
	 * @since 3.12
57
	 */
58
	public ElementQuerySpecification(ArrayList<IJavaElement> javaElements, int limitTo, IJavaSearchScope scope, String scopeDescription) {
59
		super(limitTo, scope, scopeDescription);
60
		fElements= javaElements;
45
	}
61
	}
46
62
47
	/**
63
	/**
48
	 * Returns the element to search for.
64
	 * Returns the element to search for.
49
	 * @return The element to search for.
65
	 * @return The element to search for. If multiple elements are selected, returns the first element from the selected list.
50
	 */
66
	 */
51
	public IJavaElement getElement() {
67
	public IJavaElement getElement() {
52
		return fElement;
68
		return fElements.get(0);
69
	}
70
	
71
	/**
72
	 * Returns the element to search for.
73
	 * @return The list of elements to search for
74
	 * @since 3.12
75
	 */
76
	public ArrayList<IJavaElement> getElements() {
77
		return fElements;
53
	}
78
	}
54
}
79
}

Return to bug 477340