diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/search/JavaSearchQuery.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/search/JavaSearchQuery.java index e433971..077fcd3 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/search/JavaSearchQuery.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/search/JavaSearchQuery.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2010 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -9,6 +9,9 @@ * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.jdt.internal.ui.search; + +import java.util.ArrayList; +import java.util.Iterator; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; @@ -116,16 +119,32 @@ totalTicks+= ticks[i]; } - SearchPattern pattern; - String stringPattern; + SearchPattern pattern= null; + String stringPattern= null; if (fPatternData instanceof ElementQuerySpecification) { - IJavaElement element= ((ElementQuerySpecification) fPatternData).getElement(); - stringPattern= JavaElementLabels.getElementLabel(element, JavaElementLabels.ALL_DEFAULT); - if (!element.exists()) { - return new Status(IStatus.ERROR, JavaPlugin.getPluginId(), 0, Messages.format(SearchMessages.JavaSearchQuery_error_element_does_not_exist, stringPattern), null); + if (((ElementQuerySpecification) fPatternData).getElements().size() == 1){ + IJavaElement element= ((ElementQuerySpecification) fPatternData).getElement(); + stringPattern= JavaElementLabels.getElementLabel(element, JavaElementLabels.ALL_DEFAULT); + if (!element.exists()) { + return new Status(IStatus.ERROR, JavaPlugin.getPluginId(), 0, Messages.format(SearchMessages.JavaSearchQuery_error_element_does_not_exist, stringPattern), null); + } + pattern= SearchPattern.createPattern(element, fPatternData.getLimitTo(), SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE); + }else{ + ArrayList elementList = ((ElementQuerySpecification) fPatternData).getElements(); + for (Iterator iterator= elementList.iterator(); iterator.hasNext();) { + IJavaElement element= (IJavaElement) iterator.next(); + stringPattern= JavaElementLabels.getElementLabel(element, JavaElementLabels.ALL_DEFAULT); + if (!element.exists()) { + return new Status(IStatus.ERROR, JavaPlugin.getPluginId(), 0, Messages.format(SearchMessages.JavaSearchQuery_error_element_does_not_exist, stringPattern), null); + } + SearchPattern elementPattern = SearchPattern.createPattern(element, fPatternData.getLimitTo(), SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE); + if (pattern == null) + pattern= elementPattern; + else + pattern= SearchPattern.createOrPattern(pattern, elementPattern); + } } - pattern= SearchPattern.createPattern(element, fPatternData.getLimitTo(), SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE); } else { PatternQuerySpecification patternSpec = (PatternQuerySpecification) fPatternData; stringPattern= patternSpec.getPattern(); @@ -242,9 +261,24 @@ private String getSearchPatternDescription() { if (fPatternData instanceof ElementQuerySpecification) { - IJavaElement element= ((ElementQuerySpecification) fPatternData).getElement(); - return JavaElementLabels.getElementLabel(element, JavaElementLabels.ALL_DEFAULT + if (((ElementQuerySpecification) fPatternData).getElements().size() == 1){ + IJavaElement element= ((ElementQuerySpecification) fPatternData).getElement(); + return JavaElementLabels.getElementLabel(element, JavaElementLabels.ALL_DEFAULT | JavaElementLabels.ALL_FULLY_QUALIFIED | JavaElementLabels.USE_RESOLVED | JavaElementLabels.P_COMPRESSED); + } else { + ArrayList elements= ((ElementQuerySpecification) fPatternData).getElements(); + StringBuffer description = new StringBuffer(); + for (Iterator iterator= elements.iterator(); iterator.hasNext();) { + IJavaElement element= iterator.next(); + if (description.length() != 0 && iterator.hasNext()) + description.append(", "); //$NON-NLS-1$ + else if (description.length() > 0) + description.append(" and "); //$NON-NLS-1$ + description.append(JavaElementLabels.getElementLabel(element, JavaElementLabels.ALL_DEFAULT + | JavaElementLabels.ALL_FULLY_QUALIFIED | JavaElementLabels.USE_RESOLVED | JavaElementLabels.P_COMPRESSED)); + } + return description.toString(); + } } return BasicElementLabels.getFilePattern(((PatternQuerySpecification) fPatternData).getPattern()); } diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/search/SearchMessages.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/search/SearchMessages.java index f28f357..d55b1bf 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/search/SearchMessages.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/search/SearchMessages.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2014 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -268,6 +268,7 @@ public static String JavaSearchQuery_error_element_does_not_exist; public static String JavaSearchQuery_pluralReferencesWithMatchLocations; + public static String JavaSearchQuery_multi_selection_search_and; public static String MatchFilter_PotentialFilter_name; public static String MatchFilter_PotentialFilter_actionLabel; public static String MatchFilter_PotentialFilter_description; diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/search/SearchMessages.properties b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/search/SearchMessages.properties index 4c4ad13..9d5f86d 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/search/SearchMessages.properties +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/search/SearchMessages.properties @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2000, 2011 IBM Corporation and others. +# Copyright (c) 2000, 2016 IBM Corporation and others. # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Public License v1.0 # which accompanies this distribution, and is available at @@ -255,6 +255,8 @@ JavaSearchQuery_error_participant_search=An error occurred during participant search. The participant has been disabled for the current session. JavaSearchQuery_pluralReferencesWithMatchLocations=''{0}'' in ''{3}'' - {1} references in {2} +JavaSearchQuery_multi_selection_search_and=and + SearchParticipant_error_noID=Missing id attribute on search participant extension {0} SearchParticipant_error_noNature=Missing nature attribute on search participant {0} SearchParticipant_error_noClass=Missing class attribute on search participant {0} diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/typehierarchy/TypeHierarchyViewer.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/typehierarchy/TypeHierarchyViewer.java index 7cb81ef..ad2e939 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/typehierarchy/TypeHierarchyViewer.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/typehierarchy/TypeHierarchyViewer.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2011 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -41,7 +41,7 @@ public TypeHierarchyViewer(Composite parent, IContentProvider contentProvider, TypeHierarchyLifeCycle lifeCycle) { - super(new Tree(parent, SWT.SINGLE)); + super(new Tree(parent, SWT.MULTI)); fLabelProvider= new HierarchyLabelProvider(lifeCycle); diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/FindAction.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/FindAction.java index a9e2f15..730d5fe 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/FindAction.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/FindAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2011 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -11,6 +11,8 @@ package org.eclipse.jdt.ui.actions; import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.Iterator; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IStatus; @@ -98,7 +100,7 @@ */ abstract Class[] getValidTypes(); - private boolean canOperateOn(IStructuredSelection sel) { + boolean canOperateOn(IStructuredSelection sel) { return sel != null && !sel.isEmpty() && canOperateOn(getJavaElement(sel, true)); } @@ -139,6 +141,19 @@ } } + IJavaElement getJavaElement(Object firstElement, boolean silent) { + IJavaElement elem= null; + if (firstElement instanceof IJavaElement) + elem= (IJavaElement) firstElement; + else if (firstElement instanceof IAdaptable) + elem= ((IAdaptable) firstElement).getAdapter(IJavaElement.class); + if (elem != null) { + return getTypeIfPossible(elem, silent); + } + + return null; + } + IJavaElement getJavaElement(IStructuredSelection selection, boolean silent) { if (selection.size() == 1) { Object firstElement= selection.getFirstElement(); @@ -153,6 +168,22 @@ } return null; + } + + ArrayList getMultipleJavaElement(IStructuredSelection selection, boolean silent) { + ArrayList javaElementList = new ArrayList<>(); + for (Iterator iter= selection.iterator(); iter.hasNext();) { + Object firstElement= iter.next(); + IJavaElement elem= null; + if (firstElement instanceof IJavaElement) + elem= (IJavaElement) firstElement; + else if (firstElement instanceof IAdaptable) + elem= ((IAdaptable) firstElement).getAdapter(IJavaElement.class); + if (elem != null) { + javaElementList.add(getTypeIfPossible(elem, silent)); + } + } + return javaElementList; } private void showOperationUnavailableDialog() { @@ -201,15 +232,32 @@ */ @Override public void run(IStructuredSelection selection) { - IJavaElement element= getJavaElement(selection, false); - if (element == null || !element.exists()) { - showOperationUnavailableDialog(); - return; + if (selection.size() == 1) { + IJavaElement element= getJavaElement(selection, false); + if (element == null || !element.exists()) { + showOperationUnavailableDialog(); + return; + } + else if (element == RETURN_WITHOUT_BEEP) + return; + + run(element); } - else if (element == RETURN_WITHOUT_BEEP) - return; - - run(element); + else { + ArrayList elementList = getMultipleJavaElement(selection, false); + for (Iterator iterator= elementList.iterator(); iterator.hasNext();) { + IJavaElement element= (IJavaElement) iterator.next(); + if (element == null || !element.exists()) { + showOperationUnavailableDialog(); + return; + } + else if (!ActionUtil.isProcessable(getShell(), element)) + return; + else if (element == RETURN_WITHOUT_BEEP) + return; + } + run(elementList); + } } /* @@ -275,8 +323,49 @@ // cancelled } } + + /** + * Executes this action for the given java element List. + * @param element The java element in Lists to be found. + * @since 3.12 + */ + public void run(ArrayList element) { + // will return true except for debugging purposes. + try { + performNewSearch(element); + } catch (JavaModelException ex) { + ExceptionHandler.handle(ex, getShell(), SearchMessages.Search_Error_search_notsuccessful_title, SearchMessages.Search_Error_search_notsuccessful_message); + } catch (InterruptedException e) { + // cancelled + } + } private void performNewSearch(IJavaElement element) throws JavaModelException, InterruptedException { + JavaSearchQuery query= new JavaSearchQuery(createQuery(element)); + if (query.canRunInBackground()) { + /* + * This indirection with Object as parameter is needed to prevent the loading + * of the Search plug-in: the VM verifies the method call and hence loads the + * types used in the method signature, eventually triggering the loading of + * a plug-in (in this case ISearchQuery results in Search plug-in being loaded). + */ + SearchUtil.runQueryInBackground(query); + } else { + IProgressService progressService= PlatformUI.getWorkbench().getProgressService(); + /* + * This indirection with Object as parameter is needed to prevent the loading + * of the Search plug-in: the VM verifies the method call and hence loads the + * types used in the method signature, eventually triggering the loading of + * a plug-in (in this case it would be ISearchQuery). + */ + IStatus status= SearchUtil.runQueryInForeground(progressService, query); + if (status.matches(IStatus.ERROR | IStatus.INFO | IStatus.WARNING)) { + ErrorDialog.openError(getShell(), SearchMessages.Search_Error_search_title, SearchMessages.Search_Error_search_message, status); + } + } + } + + private void performNewSearch(ArrayList element) throws JavaModelException, InterruptedException { JavaSearchQuery query= new JavaSearchQuery(createQuery(element)); if (query.canRunInBackground()) { /* @@ -316,7 +405,23 @@ String description= factory.getWorkspaceScopeDescription(true); return new ElementQuerySpecification(element, getLimitTo(), scope, description); } - + + /** + * Creates a query for the given element. Subclasses reimplement this method. + * + * @param elementList the elements to create a query for + * + * @return returns the query + * @throws JavaModelException thrown when accessing the element failed + * @throws InterruptedException thrown when the user interrupted the query selection + */ + QuerySpecification createQuery(ArrayList elementList) throws JavaModelException, InterruptedException { + IJavaElement element = elementList.get(0); + JavaSearchScopeFactory factory= JavaSearchScopeFactory.getInstance(); + IJavaSearchScope scope= factory.createWorkspaceScope(true); + String description= factory.getWorkspaceScopeDescription(true); + return new ElementQuerySpecification(element, getLimitTo(), scope, description); + } abstract int getLimitTo(); IType getType(IJavaElement element) { diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/FindReadReferencesInProjectAction.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/FindReadReferencesInProjectAction.java index 6d21f7b..d551867 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/FindReadReferencesInProjectAction.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/FindReadReferencesInProjectAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2011 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -9,6 +9,8 @@ * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.jdt.ui.actions; + +import java.util.ArrayList; import org.eclipse.ui.IWorkbenchSite; import org.eclipse.ui.PlatformUI; @@ -87,4 +89,28 @@ return new ElementQuerySpecification(element, getLimitTo(), scope, description); } + @Override + QuerySpecification createQuery(ArrayList elementList) throws JavaModelException, InterruptedException { + JavaSearchScopeFactory factory= JavaSearchScopeFactory.getInstance(); + JavaEditor editor= getEditor(); + + IJavaSearchScope scope; + String description; + boolean isInsideJRE= factory.isInsideJRE(elementList.get(0)); + if (editor != null) { + scope= factory.createJavaProjectSearchScope(editor.getEditorInput(), isInsideJRE); + description= factory.getProjectScopeDescription(editor.getEditorInput(), isInsideJRE); + } else { + String[] elementNames= new String[elementList.size()]; + int i= 0; + for (IJavaElement element : elementList) { + elementNames[i++]= element.getElementName(); + } + scope= factory.createJavaProjectSearchScope(elementNames, isInsideJRE); + description= factory.getProjectScopeDescription(elementList.get(0).getJavaProject(), isInsideJRE); + } + return new ElementQuerySpecification(elementList, getLimitTo(), scope, description); + } + + } diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/FindReferencesAction.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/FindReferencesAction.java index a134df7..9b4af34 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/FindReferencesAction.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/FindReferencesAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2011 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -9,6 +9,11 @@ * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.jdt.ui.actions; + +import java.util.ArrayList; +import java.util.Iterator; + +import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.ui.IWorkbenchSite; import org.eclipse.ui.PlatformUI; @@ -99,10 +104,35 @@ String description= factory.getWorkspaceScopeDescription(isInsideJRE); return new ElementQuerySpecification(element, getLimitTo(), scope, description); } + + @Override + QuerySpecification createQuery(ArrayList element) throws JavaModelException, InterruptedException { + JavaSearchScopeFactory factory= JavaSearchScopeFactory.getInstance(); + boolean isInsideJRE= factory.isInsideJRE(element.get(0)); + + IJavaSearchScope scope= factory.createWorkspaceScope(isInsideJRE); + String description= factory.getWorkspaceScopeDescription(isInsideJRE); + return new ElementQuerySpecification(element, getLimitTo(), scope, description); + } @Override public void run(IJavaElement element) { SearchUtil.warnIfBinaryConstant(element, getShell()); super.run(element); } + + @Override + boolean canOperateOn(IStructuredSelection sel) { + if ( sel == null || sel.isEmpty() ){ + return false; + } + for (Iterator iter= sel.iterator(); iter.hasNext();) { + Object element= iter.next(); + if( !canOperateOn(getJavaElement(element, true))){ + return false; + } + } + return true; + } + } diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/FindReferencesInHierarchyAction.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/FindReferencesInHierarchyAction.java index 942df16..49bbe92 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/FindReferencesInHierarchyAction.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/FindReferencesInHierarchyAction.java @@ -10,6 +10,10 @@ *******************************************************************************/ package org.eclipse.jdt.ui.actions; +import java.util.Iterator; + +import org.eclipse.jface.viewers.IStructuredSelection; + import org.eclipse.ui.IWorkbenchSite; import org.eclipse.ui.PlatformUI; @@ -93,4 +97,17 @@ return new ElementQuerySpecification(element, getLimitTo(), scope, description); } + @Override + boolean canOperateOn(IStructuredSelection sel) { + if ( sel == null || sel.isEmpty() || sel.size() > 1){ + return false; + } + for (Iterator iter= sel.iterator(); iter.hasNext();) { + Object element= iter.next(); + if( !canOperateOn(getJavaElement(element, true))){ + return false; + } + } + return true; + } } diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/FindReferencesInProjectAction.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/FindReferencesInProjectAction.java index f4a2e69..4de0fb0 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/FindReferencesInProjectAction.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/FindReferencesInProjectAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2011 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -9,6 +9,8 @@ * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.jdt.ui.actions; + +import java.util.ArrayList; import org.eclipse.ui.IWorkbenchSite; import org.eclipse.ui.PlatformUI; @@ -102,4 +104,27 @@ return new ElementQuerySpecification(element, getLimitTo(), scope, description); } + @Override + QuerySpecification createQuery(ArrayList elementList) throws JavaModelException, InterruptedException { + JavaSearchScopeFactory factory= JavaSearchScopeFactory.getInstance(); + JavaEditor editor= getEditor(); + + IJavaSearchScope scope; + String description; + boolean isInsideJRE= factory.isInsideJRE(elementList.get(0)); + if (editor != null) { + scope= factory.createJavaProjectSearchScope(editor.getEditorInput(), isInsideJRE); + description= factory.getProjectScopeDescription(editor.getEditorInput(), isInsideJRE); + } else { + String[] elementNames= new String[elementList.size()]; + int i= 0; + for (IJavaElement element : elementList) { + elementNames[i++]= element.getElementName(); + } + scope= factory.createJavaProjectSearchScope(elementNames, isInsideJRE); + description= factory.getProjectScopeDescription(elementList.get(0).getJavaProject(), isInsideJRE); + } + return new ElementQuerySpecification(elementList, getLimitTo(), scope, description); + } + } diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/FindReferencesInWorkingSetAction.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/FindReferencesInWorkingSetAction.java index 5c53979..5d7947e 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/FindReferencesInWorkingSetAction.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/FindReferencesInWorkingSetAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2011 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -9,6 +9,8 @@ * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.jdt.ui.actions; + +import java.util.ArrayList; import org.eclipse.ui.IWorkbenchSite; import org.eclipse.ui.IWorkingSet; @@ -115,4 +117,20 @@ String description= factory.getWorkingSetScopeDescription(workingSets, JavaSearchScopeFactory.NO_PROJ); return new ElementQuerySpecification(element, getLimitTo(), scope, description); } + + @Override + QuerySpecification createQuery(ArrayList element) throws JavaModelException, InterruptedException { + JavaSearchScopeFactory factory= JavaSearchScopeFactory.getInstance(); + + IWorkingSet[] workingSets= fWorkingSets; + if (fWorkingSets == null) { + workingSets= factory.queryWorkingSets(); + if (workingSets == null) + return super.createQuery(element); // in workspace + } + SearchUtil.updateLRUWorkingSets(workingSets); + IJavaSearchScope scope= factory.createJavaSearchScope(workingSets, JavaSearchScopeFactory.NO_PROJ); + String description= factory.getWorkingSetScopeDescription(workingSets, JavaSearchScopeFactory.NO_PROJ); + return new ElementQuerySpecification(element, getLimitTo(), scope, description); + } } diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/search/ElementQuerySpecification.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/search/ElementQuerySpecification.java index 5202d5b..6bea3c4 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/search/ElementQuerySpecification.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/search/ElementQuerySpecification.java @@ -10,6 +10,8 @@ *******************************************************************************/ package org.eclipse.jdt.ui.search; +import java.util.ArrayList; + import org.eclipse.jdt.core.IJavaElement; import org.eclipse.jdt.core.search.IJavaSearchScope; @@ -30,7 +32,7 @@ * @noextend This class is not intended to be subclassed by clients. */ public class ElementQuerySpecification extends QuerySpecification { - private IJavaElement fElement; + private ArrayList fElements; /** * A constructor. @@ -41,14 +43,37 @@ */ public ElementQuerySpecification(IJavaElement javaElement, int limitTo, IJavaSearchScope scope, String scopeDescription) { super(limitTo, scope, scopeDescription); - fElement= javaElement; + fElements = new ArrayList<>(1); + fElements.add(javaElement); + } + + /** + * A constructor. + * @param javaElements The java elements the query should search for + * @param limitTo The kind of occurrence the query should search for + * @param scope The scope to search in + * @param scopeDescription A human readable description of the search scope + * @since 3.12 + */ + public ElementQuerySpecification(ArrayList javaElements, int limitTo, IJavaSearchScope scope, String scopeDescription) { + super(limitTo, scope, scopeDescription); + fElements= javaElements; } /** * Returns the element to search for. - * @return The element to search for. + * @return The element to search for. If multiple elements are selected, returns the first element from the selected list. */ public IJavaElement getElement() { - return fElement; + return fElements.get(0); + } + + /** + * Returns the element to search for. + * @return The list of elements to search for + * @since 3.12 + */ + public ArrayList getElements() { + return fElements; } }