mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-24 01:15:29 +02:00
Fix for 162161, NPE on search in workingset.
This commit is contained in:
parent
19ec4b5024
commit
29c91c21cb
4 changed files with 135 additions and 121 deletions
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2006 IBM Corporation and others.
|
||||
* Copyright (c) 2004, 2007 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
|
||||
|
@ -7,78 +7,34 @@
|
|||
*
|
||||
* Contributors:
|
||||
* IBM Corp. - Rational Software - initial implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.search.actions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.internal.ui.editor.CEditor;
|
||||
import org.eclipse.cdt.internal.ui.search.CSearchMessages;
|
||||
import org.eclipse.cdt.internal.ui.search.CSearchUtil;
|
||||
import org.eclipse.cdt.internal.ui.search.PDOMSearchQuery;
|
||||
import org.eclipse.core.runtime.IAdaptable;
|
||||
import org.eclipse.ui.IWorkbenchSite;
|
||||
import org.eclipse.ui.IWorkingSet;
|
||||
|
||||
public class FindDeclarationsInWorkingSetAction extends FindAction {
|
||||
import org.eclipse.cdt.internal.ui.editor.CEditor;
|
||||
import org.eclipse.cdt.internal.ui.search.CSearchMessages;
|
||||
import org.eclipse.cdt.internal.ui.search.PDOMSearchQuery;
|
||||
|
||||
private IWorkingSet[] fWorkingSet;
|
||||
private String scopeDescription = ""; //$NON-NLS-1$
|
||||
public class FindDeclarationsInWorkingSetAction extends FindInWorkingSetAction {
|
||||
|
||||
public FindDeclarationsInWorkingSetAction(IWorkbenchSite site, IWorkingSet[] wset) {
|
||||
this(site,
|
||||
CSearchMessages.getString("CSearch.FindDeclarationsInWorkingSetAction.label"), //$NON-NLS-1$
|
||||
CSearchMessages.getString("CSearch.FindDeclarationsInWorkingSetAction.tooltip")); //$NON-NLS-1$
|
||||
|
||||
if (wset != null)
|
||||
fWorkingSet = wset;
|
||||
public FindDeclarationsInWorkingSetAction(IWorkbenchSite site, IWorkingSet[] workingSets) {
|
||||
super(site,
|
||||
CSearchMessages.getString("CSearch.FindReferencesInWorkingSetAction.label"), //$NON-NLS-1$
|
||||
CSearchMessages.getString("CSearch.FindReferencesInWorkingSetAction.tooltip"), //$NON-NLS-1$
|
||||
workingSets);
|
||||
}
|
||||
|
||||
public FindDeclarationsInWorkingSetAction(CEditor editor, IWorkingSet[] wset) {
|
||||
this(editor,
|
||||
CSearchMessages.getString("CSearch.FindDeclarationsInWorkingSetAction.label"), //$NON-NLS-1$
|
||||
CSearchMessages.getString("CSearch.FindDeclarationsInWorkingSetAction.tooltip")); //$NON-NLS-1$
|
||||
|
||||
if (wset != null)
|
||||
fWorkingSet = wset;
|
||||
}
|
||||
|
||||
public FindDeclarationsInWorkingSetAction(CEditor editor, String label, String tooltip){
|
||||
super(editor);
|
||||
setText(label);
|
||||
setToolTipText(tooltip);
|
||||
}
|
||||
|
||||
public FindDeclarationsInWorkingSetAction(IWorkbenchSite site,String label, String tooltip){
|
||||
super(site);
|
||||
setText(label);
|
||||
setToolTipText(tooltip);
|
||||
}
|
||||
|
||||
protected String getScopeDescription() {
|
||||
return scopeDescription;
|
||||
}
|
||||
|
||||
protected ICElement[] getScope() {
|
||||
List resources = new ArrayList();
|
||||
|
||||
for (int i = 0; i < fWorkingSet.length; ++i) {
|
||||
IAdaptable[] elements = fWorkingSet[i].getElements();
|
||||
for (int j = 0; j < elements.length; ++j) {
|
||||
ICElement resource = (ICElement)elements[j].getAdapter(ICElement.class);
|
||||
if (resource != null)
|
||||
resources.add(resource);
|
||||
}
|
||||
}
|
||||
|
||||
scopeDescription = CSearchMessages.getFormattedString("WorkingSetScope", new String[] {CSearchUtil.toString(fWorkingSet)}); //$NON-NLS-1$
|
||||
return (ICElement[])resources.toArray(new ICElement[resources.size()]);
|
||||
public FindDeclarationsInWorkingSetAction(CEditor editor, IWorkingSet[] workingSets) {
|
||||
super(editor,
|
||||
CSearchMessages.getString("CSearch.FindReferencesInWorkingSetAction.label"), //$NON-NLS-1$
|
||||
CSearchMessages.getString("CSearch.FindReferencesInWorkingSetAction.tooltip"), //$NON-NLS-1$
|
||||
workingSets);
|
||||
}
|
||||
|
||||
protected int getLimitTo() {
|
||||
return PDOMSearchQuery.FIND_DECLARATIONS_DEFINITIONS;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,99 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 Wind River Systems, Inc. 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
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.search.actions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.core.runtime.IAdaptable;
|
||||
import org.eclipse.jface.window.Window;
|
||||
import org.eclipse.ui.IWorkbenchSite;
|
||||
import org.eclipse.ui.IWorkingSet;
|
||||
import org.eclipse.ui.IWorkingSetManager;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.ui.dialogs.IWorkingSetSelectionDialog;
|
||||
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.editor.CEditor;
|
||||
import org.eclipse.cdt.internal.ui.search.CSearchMessages;
|
||||
import org.eclipse.cdt.internal.ui.search.CSearchUtil;
|
||||
|
||||
public abstract class FindInWorkingSetAction extends FindAction {
|
||||
|
||||
private IWorkingSet[] fWorkingSets;
|
||||
private String scopeDescription = ""; //$NON-NLS-1$
|
||||
|
||||
public FindInWorkingSetAction(CEditor editor, String label, String tooltip, IWorkingSet[] workingSets) {
|
||||
super(editor);
|
||||
setText(label);
|
||||
setToolTipText(tooltip);
|
||||
fWorkingSets = workingSets;
|
||||
}
|
||||
|
||||
public FindInWorkingSetAction(IWorkbenchSite site, String label, String tooltip, IWorkingSet[] workingSets){
|
||||
super(site);
|
||||
setText(label);
|
||||
setToolTipText(tooltip);
|
||||
fWorkingSets= workingSets;
|
||||
}
|
||||
|
||||
final public void run() {
|
||||
IWorkingSet[] initial= fWorkingSets;
|
||||
if (fWorkingSets == null) {
|
||||
fWorkingSets= askForWorkingSets();
|
||||
}
|
||||
if (fWorkingSets != null) {
|
||||
scopeDescription = CSearchMessages.getFormattedString("WorkingSetScope", new String[] {CSearchUtil.toString(fWorkingSets)}); //$NON-NLS-1$
|
||||
super.run();
|
||||
}
|
||||
fWorkingSets= initial;
|
||||
}
|
||||
|
||||
final protected String getScopeDescription() {
|
||||
return scopeDescription;
|
||||
}
|
||||
|
||||
final protected ICElement[] getScope() {
|
||||
if (fWorkingSets == null) {
|
||||
return new ICElement[0];
|
||||
}
|
||||
List scope = new ArrayList();
|
||||
for (int i = 0; i < fWorkingSets.length; ++i) {
|
||||
IAdaptable[] elements = fWorkingSets[i].getElements();
|
||||
for (int j = 0; j < elements.length; ++j) {
|
||||
ICElement element = (ICElement)elements[j].getAdapter(ICElement.class);
|
||||
if (element != null)
|
||||
scope.add(element);
|
||||
}
|
||||
}
|
||||
|
||||
return (ICElement[])scope.toArray(new ICElement[scope.size()]);
|
||||
}
|
||||
|
||||
private IWorkingSet[] askForWorkingSets() {
|
||||
IWorkingSetManager wsm= PlatformUI.getWorkbench().getWorkingSetManager();
|
||||
IWorkingSetSelectionDialog dlg=
|
||||
wsm.createWorkingSetSelectionDialog(getSite().getShell(), true);
|
||||
IWorkingSet[] mru= wsm.getRecentWorkingSets();
|
||||
if (mru != null && mru.length > 0) {
|
||||
dlg.setSelection(new IWorkingSet[] {mru[0]});
|
||||
}
|
||||
if (dlg.open() == Window.OK) {
|
||||
mru= dlg.getSelection();
|
||||
if (mru != null && mru.length == 1) {
|
||||
wsm.addRecentWorkingSet(mru[0]);
|
||||
}
|
||||
return mru;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2006 IBM Corporation and others.
|
||||
* Copyright (c) 2004, 2007 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
|
||||
|
@ -7,79 +7,34 @@
|
|||
*
|
||||
* Contributors:
|
||||
* IBM Corp. - Rational Software - initial implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.search.actions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.internal.ui.editor.CEditor;
|
||||
import org.eclipse.cdt.internal.ui.search.CSearchMessages;
|
||||
import org.eclipse.cdt.internal.ui.search.CSearchUtil;
|
||||
import org.eclipse.cdt.internal.ui.search.PDOMSearchQuery;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.IAdaptable;
|
||||
import org.eclipse.ui.IWorkbenchSite;
|
||||
import org.eclipse.ui.IWorkingSet;
|
||||
|
||||
public class FindRefsInWorkingSetAction extends FindAction {
|
||||
|
||||
private IWorkingSet[] fWorkingSet;
|
||||
private String scopeDescription = ""; //$NON-NLS-1$
|
||||
import org.eclipse.cdt.internal.ui.editor.CEditor;
|
||||
import org.eclipse.cdt.internal.ui.search.CSearchMessages;
|
||||
import org.eclipse.cdt.internal.ui.search.PDOMSearchQuery;
|
||||
|
||||
public class FindRefsInWorkingSetAction extends FindInWorkingSetAction {
|
||||
|
||||
public FindRefsInWorkingSetAction(CEditor editor, IWorkingSet[] workingSets) {
|
||||
this(editor,
|
||||
CSearchMessages.getString("CSearch.FindReferencesInWorkingSetAction.label"), //$NON-NLS-1$
|
||||
CSearchMessages.getString("CSearch.FindReferencesInWorkingSetAction.tooltip")); //$NON-NLS-1$
|
||||
|
||||
if (workingSets != null)
|
||||
fWorkingSet = workingSets;
|
||||
super(editor,
|
||||
CSearchMessages.getString("CSearch.FindReferencesInWorkingSetAction.label"), //$NON-NLS-1$
|
||||
CSearchMessages.getString("CSearch.FindReferencesInWorkingSetAction.tooltip"), //$NON-NLS-1$
|
||||
workingSets);
|
||||
}
|
||||
|
||||
public FindRefsInWorkingSetAction(IWorkbenchSite site, IWorkingSet[] workingSets){
|
||||
this(site,
|
||||
CSearchMessages.getString("CSearch.FindReferencesInWorkingSetAction.label"), //$NON-NLS-1$
|
||||
CSearchMessages.getString("CSearch.FindReferencesInWorkingSetAction.tooltip")); //$NON-NLS-1$
|
||||
|
||||
if (workingSets != null)
|
||||
fWorkingSet= workingSets;
|
||||
super (site,
|
||||
CSearchMessages.getString("CSearch.FindReferencesInWorkingSetAction.label"), //$NON-NLS-1$
|
||||
CSearchMessages.getString("CSearch.FindReferencesInWorkingSetAction.tooltip"), //$NON-NLS-1$
|
||||
workingSets);
|
||||
}
|
||||
|
||||
public FindRefsInWorkingSetAction(CEditor editor, String label, String tooltip) {
|
||||
super(editor);
|
||||
setText(label);
|
||||
setToolTipText(tooltip);
|
||||
}
|
||||
|
||||
public FindRefsInWorkingSetAction(IWorkbenchSite site, String label, String tooltip) {
|
||||
super(site);
|
||||
setText(label);
|
||||
setToolTipText(tooltip); //$NON-NLS-1
|
||||
}
|
||||
|
||||
|
||||
protected int getLimitTo() {
|
||||
return PDOMSearchQuery.FIND_REFERENCES;
|
||||
}
|
||||
|
||||
protected String getScopeDescription() {
|
||||
return scopeDescription;
|
||||
}
|
||||
|
||||
protected ICElement[] getScope() {
|
||||
List scope = new ArrayList();
|
||||
|
||||
for (int i = 0; i < fWorkingSet.length; ++i) {
|
||||
IAdaptable[] elements = fWorkingSet[i].getElements();
|
||||
for (int j = 0; j < elements.length; ++j) {
|
||||
ICElement element = (ICElement)elements[j].getAdapter(IResource.class);
|
||||
if (element != null)
|
||||
scope.add(element);
|
||||
}
|
||||
}
|
||||
|
||||
scopeDescription = CSearchMessages.getFormattedString("WorkingSetScope", new String[] {CSearchUtil.toString(fWorkingSet)}); //$NON-NLS-1$
|
||||
return (ICElement[])scope.toArray(new ICElement[scope.size()]);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -69,6 +69,10 @@ public class SelectionParseAction extends Action {
|
|||
fSite=site;
|
||||
}
|
||||
|
||||
public IWorkbenchSite getSite() {
|
||||
return fSite;
|
||||
}
|
||||
|
||||
protected void operationNotAvailable(final String message) {
|
||||
// run the code to update the status line on the Display thread
|
||||
// this way any other thread can invoke operationNotAvailable(String)
|
||||
|
|
Loading…
Add table
Reference in a new issue