1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-01 06:05:24 +02:00

PDOM - start of new search actions off of the Index View.

This commit is contained in:
Doug Schaefer 2006-02-10 04:11:00 +00:00
parent b65a91b8b5
commit 711acc8651
16 changed files with 887 additions and 100 deletions

View file

@ -1232,6 +1232,10 @@
searchResultClass="org.eclipse.cdt.internal.ui.search.CSearchResult"
id="org.eclipse.cdt.ui.CSearchResultPage">
</viewPage>
<viewPage
class="org.eclipse.cdt.internal.ui.search.PDOMSearchViewPage"
id="org.eclipse.cdt.ui.pdomSearchViewPage"
searchResultClass="org.eclipse.cdt.internal.ui.search.PDOMSearchResult"/>
</extension>
<extension
point="org.eclipse.ui.propertyPages">

View file

@ -322,3 +322,5 @@ Editorutility.closedproject.description = The project {0} containing that declar
# ------- Index View Text -----------
IndexView.rebuildIndex.name = Rebuild Index
IndexView.openDefinition.name = Open Definition
IndexView.findReferences.name = Find References
IndexView.findDeclarations.name = Find Declarations

View file

@ -17,10 +17,13 @@ import org.eclipse.jface.action.IMenuManager;
public class ExternalSearchEditor extends CEditor {
public static final String EDITOR_ID = "org.eclipse.cdt.ui.editor.ExternalSearchEditor";
public ExternalSearchEditor(){
super();
setDocumentProvider(CUIPlugin.getDefault().getExternalSearchDocumentProvider());
}
public void editorContextMenuAboutToShow(IMenuManager menu) {
super.editorContextMenuAboutToShow(menu);
IContributionItem[] contrItem = menu.getItems();

View file

@ -0,0 +1,54 @@
/*******************************************************************************
* Copyright (c) 2006 QNX Software Systems 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:
* QNX - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.ui.indexview;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.internal.ui.search.PDOMSearchQuery;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.search.ui.NewSearchUI;
/**
* @author Doug Schaefer
*
*/
public class FindDeclarationsAction extends IndexAction {
public FindDeclarationsAction(TreeViewer viewer) {
super(viewer, CUIPlugin.getResourceString("IndexView.findDeclarations.name"));
}
private PDOMBinding getBinding() {
ISelection selection = viewer.getSelection();
if (!(selection instanceof IStructuredSelection))
return null;
Object[] objs = ((IStructuredSelection)selection).toArray();
return (objs.length == 1 && objs[0] instanceof PDOMBinding)
? (PDOMBinding)objs[0] : null;
}
public void run() {
PDOMSearchQuery query = new PDOMSearchQuery(getBinding(),
PDOMSearchQuery.FIND_DECLARATIONS | PDOMSearchQuery.FIND_DEFINITIONS);
NewSearchUI.activateSearchResultView();
NewSearchUI.runQueryInBackground(query);
}
public boolean valid() {
return getBinding() != null;
}
}

View file

@ -0,0 +1,53 @@
/*******************************************************************************
* Copyright (c) 2006 QNX Software Systems 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:
* QNX - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.ui.indexview;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.internal.ui.search.PDOMSearchQuery;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.search.ui.NewSearchUI;
/**
* @author Doug Schaefer
*
*/
public class FindReferencesAction extends IndexAction {
public FindReferencesAction(TreeViewer viewer) {
super(viewer, CUIPlugin.getResourceString("IndexView.findReferences.name"));
}
private PDOMBinding getBinding() {
ISelection selection = viewer.getSelection();
if (!(selection instanceof IStructuredSelection))
return null;
Object[] objs = ((IStructuredSelection)selection).toArray();
return (objs.length == 1 && objs[0] instanceof PDOMBinding)
? (PDOMBinding)objs[0] : null;
}
public void run() {
PDOMSearchQuery query = new PDOMSearchQuery(getBinding(), PDOMSearchQuery.FIND_REFERENCES);
NewSearchUI.activateSearchResultView();
NewSearchUI.runQueryInBackground(query);
}
public boolean valid() {
return getBinding() != null;
}
}

View file

@ -0,0 +1,49 @@
/*******************************************************************************
* Copyright (c) 2006 QNX Software Systems 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:
* QNX - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.ui.indexview;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.TreeViewer;
/**
* @author Doug Schaefer
*
* Root class for Index View Actions. Add an check to make sure the
* action is valid with the current context.
*/
public abstract class IndexAction extends Action {
protected TreeViewer viewer;
protected IndexAction(TreeViewer viewer) {
super();
this.viewer = viewer;
}
protected IndexAction(TreeViewer viewer, String text) {
super(text);
this.viewer = viewer;
}
protected IndexAction(TreeViewer viewer, String text, ImageDescriptor image) {
super(text, image);
this.viewer = viewer;
}
protected IndexAction(TreeViewer viewer, String text, int style) {
super(text, style);
this.viewer = viewer;
}
public abstract boolean valid();
}

View file

@ -13,7 +13,6 @@ package org.eclipse.cdt.internal.ui.indexview;
import org.eclipse.cdt.core.dom.IPDOM;
import org.eclipse.cdt.core.dom.PDOM;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.ICompositeType;
import org.eclipse.cdt.core.dom.ast.IFunction;
@ -24,25 +23,17 @@ import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICModel;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.resources.FileStorage;
import org.eclipse.cdt.internal.core.pdom.PDOMDatabase;
import org.eclipse.cdt.internal.core.pdom.PDOMUpdator;
import org.eclipse.cdt.internal.core.pdom.db.IBTreeVisitor;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMMember;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMMemberOwner;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
import org.eclipse.cdt.internal.core.pdom.dom.cpp.PDOMCPPNamespace;
import org.eclipse.cdt.internal.ui.util.EditorUtility;
import org.eclipse.cdt.internal.ui.viewsupport.CElementImageProvider;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
@ -51,8 +42,6 @@ import org.eclipse.jface.action.Separator;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.ILazyTreeContentProvider;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TreeViewer;
@ -62,13 +51,11 @@ import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.ide.IDE;
import org.eclipse.ui.part.ViewPart;
import org.eclipse.ui.texteditor.ITextEditor;
/**
* @author Doug Schaefer
@ -80,6 +67,8 @@ public class IndexView extends ViewPart implements PDOMDatabase.IListener {
// private DrillDownAdapter drillDownAdapter;
private IndexAction rebuildAction;
private IndexAction openDefinitionAction;
private IndexAction findDeclarationsAction;
private IndexAction findReferencesAction;
private static class Counter implements IBTreeVisitor {
int count;
@ -394,92 +383,11 @@ public class IndexView extends ViewPart implements PDOMDatabase.IListener {
getSite().registerContextMenu(menuMgr, viewer);
}
private abstract static class IndexAction extends Action {
public abstract boolean valid();
}
private void makeActions() {
rebuildAction = new IndexAction() {
public void run() {
ISelection selection = viewer.getSelection();
if (!(selection instanceof IStructuredSelection))
return;
Object[] objs = ((IStructuredSelection)selection).toArray();
for (int i = 0; i < objs.length; ++i) {
if (!(objs[i] instanceof ICProject))
continue;
ICProject cproject = (ICProject)objs[i];
try {
PDOM.deletePDOM(cproject.getProject());
PDOMUpdator job = new PDOMUpdator(cproject, null);
job.schedule();
} catch (CoreException e) {
CUIPlugin.getDefault().log(e);
}
}
}
public boolean valid() {
ISelection selection = viewer.getSelection();
if (!(selection instanceof IStructuredSelection))
return false;
Object[] objs = ((IStructuredSelection)selection).toArray();
for (int i = 0; i < objs.length; ++i)
if (objs[i] instanceof ICProject)
return true;
return false;
}
};
rebuildAction.setText(CUIPlugin.getResourceString("IndexView.rebuildIndex.name")); //$NON-NLS-1$
openDefinitionAction = new IndexAction() {
public void run() {
ISelection selection = viewer.getSelection();
if (!(selection instanceof IStructuredSelection))
return;
Object[] objs = ((IStructuredSelection)selection).toArray();
for (int i = 0; i < objs.length; ++i) {
if (!(objs[i] instanceof PDOMBinding))
continue;
try {
PDOMBinding binding = (PDOMBinding)objs[i];
PDOMName name = binding.getFirstDefinition();
if (name == null)
name = binding.getFirstDeclaration();
if (name == null)
continue;
IASTFileLocation location = name.getFileLocation();
IPath path = new Path(location.getFileName());
Object input = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path);
if (input == null)
input = new FileStorage(path);
IEditorPart editor = EditorUtility.openInEditor(input);
if (editor != null && editor instanceof ITextEditor) {
((ITextEditor)editor).selectAndReveal(location.getNodeOffset(), location.getNodeLength());
return;
}
} catch (CoreException e) {
CUIPlugin.getDefault().log(e);
}
}
}
public boolean valid() {
ISelection selection = viewer.getSelection();
if (!(selection instanceof IStructuredSelection))
return false;
Object[] objs = ((IStructuredSelection)selection).toArray();
for (int i = 0; i < objs.length; ++i)
if (objs[i] instanceof PDOMBinding)
return true;
return false;
}
};
openDefinitionAction.setText(CUIPlugin.getResourceString("IndexView.openDefinition.name"));//$NON-NLS-1$
rebuildAction = new RebuildIndexAction(viewer);
openDefinitionAction = new OpenDefinitionAction(viewer);
findDeclarationsAction = new FindDeclarationsAction(viewer);
findReferencesAction = new FindReferencesAction(viewer);
}
private void hookContextMenu() {
@ -498,8 +406,12 @@ public class IndexView extends ViewPart implements PDOMDatabase.IListener {
private void fillContextMenu(IMenuManager manager) {
if (rebuildAction.valid())
manager.add(rebuildAction);
if (rebuildAction.valid())
if (openDefinitionAction.valid())
manager.add(openDefinitionAction);
if (findDeclarationsAction.valid())
manager.add(findDeclarationsAction);
if (findReferencesAction.valid())
manager.add(findReferencesAction);
//manager.add(new Separator());
//drillDownAdapter.addNavigationActions(manager);
manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));

View file

@ -0,0 +1,86 @@
/*******************************************************************************
* Copyright (c) 2006 QNX Software Systems 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:
* QNX - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.ui.indexview;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.resources.FileStorage;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
import org.eclipse.cdt.internal.ui.util.EditorUtility;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.texteditor.ITextEditor;
/**
* @author Doug Schaefer
*
*/
public class OpenDefinitionAction extends IndexAction {
public OpenDefinitionAction(TreeViewer viewer) {
super(viewer, CUIPlugin.getResourceString("IndexView.openDefinition.name"));//$NON-NLS-1$
}
public void run() {
ISelection selection = viewer.getSelection();
if (!(selection instanceof IStructuredSelection))
return;
Object[] objs = ((IStructuredSelection)selection).toArray();
for (int i = 0; i < objs.length; ++i) {
if (!(objs[i] instanceof PDOMBinding))
continue;
try {
PDOMBinding binding = (PDOMBinding)objs[i];
PDOMName name = binding.getFirstDefinition();
if (name == null)
name = binding.getFirstDeclaration();
if (name == null)
continue;
IASTFileLocation location = name.getFileLocation();
IPath path = new Path(location.getFileName());
Object input = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path);
if (input == null)
input = new FileStorage(path);
IEditorPart editor = EditorUtility.openInEditor(input);
if (editor != null && editor instanceof ITextEditor) {
((ITextEditor)editor).selectAndReveal(location.getNodeOffset(), location.getNodeLength());
return;
}
} catch (CoreException e) {
CUIPlugin.getDefault().log(e);
}
}
}
public boolean valid() {
ISelection selection = viewer.getSelection();
if (!(selection instanceof IStructuredSelection))
return false;
Object[] objs = ((IStructuredSelection)selection).toArray();
for (int i = 0; i < objs.length; ++i)
if (objs[i] instanceof PDOMBinding)
return true;
return false;
}
}

View file

@ -0,0 +1,66 @@
/*******************************************************************************
* Copyright (c) 2006 QNX Software Systems 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:
* QNX - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.ui.indexview;
import org.eclipse.cdt.core.dom.PDOM;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.internal.core.pdom.PDOMUpdator;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TreeViewer;
/**
* @author Doug Schaefer
*
*/
public class RebuildIndexAction extends IndexAction {
public RebuildIndexAction(TreeViewer viewer) {
super(viewer, CUIPlugin.getResourceString("IndexView.rebuildIndex.name")); //$NON-NLS-1$
}
public void run() {
ISelection selection = viewer.getSelection();
if (!(selection instanceof IStructuredSelection))
return;
Object[] objs = ((IStructuredSelection)selection).toArray();
for (int i = 0; i < objs.length; ++i) {
if (!(objs[i] instanceof ICProject))
continue;
ICProject cproject = (ICProject)objs[i];
try {
PDOM.deletePDOM(cproject.getProject());
PDOMUpdator job = new PDOMUpdator(cproject, null);
job.schedule();
} catch (CoreException e) {
CUIPlugin.getDefault().log(e);
}
}
}
public boolean valid() {
ISelection selection = viewer.getSelection();
if (!(selection instanceof IStructuredSelection))
return false;
Object[] objs = ((IStructuredSelection)selection).toArray();
for (int i = 0; i < objs.length; ++i)
if (objs[i] instanceof ICProject)
return true;
return false;
}
}

View file

@ -140,4 +140,8 @@ CSearchPage.warning.indexersomeprojects=Index not enabled on some projects
# Add To Index Action
ActionDefinition.addToIndex.name= Add To Index
ActionDefinition.addToIndex.description= Add file to index
ActionDefinition.addToIndex.description= Add file to index
PDOMSearch.query.refs.label = Find references to
PDOMSearch.query.defs.label = Find definitions of
PDOMSearch.query.decls.label = Find declarations of

View file

@ -0,0 +1,65 @@
/*******************************************************************************
* Copyright (c) 2006 QNX Software Systems 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:
* QNX - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.ui.search;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
import org.eclipse.cdt.internal.ui.CPluginImages;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
/**
* @author Doug Schaefer
*
*/
public class PDOMSearchLabelProvider extends LabelProvider {
public Image getImage(Object element) {
ImageDescriptor imageDescriptor = null;
if (element instanceof IProject) {
imageDescriptor = CPluginImages.DESC_OBJS_SEARCHHIERPROJECT;
} else if (element instanceof IFolder) {
imageDescriptor = CPluginImages.DESC_OBJS_SEARCHHIERFODLER;
} else if (element instanceof IFile) {
imageDescriptor = CPluginImages.DESC_OBJS_TUNIT;
} else if (element instanceof PDOMName) {
imageDescriptor = CPluginImages.DESC_OBJS_VARIABLE;
} else if (element instanceof String) {
// external path, likely a header file
imageDescriptor = CPluginImages.DESC_OBJS_TUNIT_HEADER;
}
if (imageDescriptor != null) {
return CUIPlugin.getImageDescriptorRegistry().get( imageDescriptor );
} else
return super.getImage(element);
}
public String getText(Object element) {
if (element instanceof IResource) {
return ((IResource)element).getName();
} else if (element instanceof PDOMName) {
PDOMName name = (PDOMName)element;
return new String(name.toCharArray())
+ " (" + name.getFileName() + ")";
} else {
return super.getText(element);
}
}
}

View file

@ -0,0 +1,30 @@
/*******************************************************************************
* Copyright (c) 2006 QNX Software Systems 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:
* QNX - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.ui.search;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
import org.eclipse.search.ui.text.Match;
/**
* @author Doug Schaefer
*
*/
public class PDOMSearchMatch extends Match {
public PDOMSearchMatch(PDOMName name, int offset, int length) {
super(name, offset, length);
}
public String getFileName() {
return ((PDOMName)getElement()).getFileName();
}
}

View file

@ -0,0 +1,103 @@
/*******************************************************************************
* Copyright (c) 2006 QNX Software Systems 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:
* QNX - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.ui.search;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Status;
import org.eclipse.search.ui.ISearchQuery;
import org.eclipse.search.ui.ISearchResult;
/**
* @author Doug Schaefer
*
* This is the search query to be used for searching the PDOM.
*/
public class PDOMSearchQuery implements ISearchQuery {
public static final int FIND_DECLARATIONS = 1;
public static final int FIND_DEFINITIONS = 2;
public static final int FIND_REFERENCES = 4;
private PDOMSearchResult result = new PDOMSearchResult(this);
private PDOMBinding binding;
private int flags;
public PDOMSearchQuery(PDOMBinding binding, int flags) {
this.binding = binding;
this.flags = flags;
}
public IStatus run(IProgressMonitor monitor) throws OperationCanceledException {
try {
if ((flags & FIND_DECLARATIONS) != 0) {
PDOMName name = binding.getFirstDeclaration();
while (name != null) {
IASTFileLocation loc = name.getFileLocation();
result.addMatch(new PDOMSearchMatch(name, loc.getNodeOffset(), loc.getNodeLength()));
name = name.getNextInBinding();
}
}
if ((flags & (FIND_DECLARATIONS)) != 0) {
// for decls we do defs too
PDOMName name = binding.getFirstDefinition();
while (name != null) {
IASTFileLocation loc = name.getFileLocation();
result.addMatch(new PDOMSearchMatch(name, loc.getNodeOffset(), loc.getNodeLength()));
name = name.getNextInBinding();
}
}
if ((flags & FIND_REFERENCES) != 0) {
PDOMName name = binding.getFirstReference();
while (name != null) {
IASTFileLocation loc = name.getFileLocation();
result.addMatch(new PDOMSearchMatch(name, loc.getNodeOffset(), loc.getNodeLength()));
name = name.getNextInBinding();
}
}
return Status.OK_STATUS;
} catch (CoreException e) {
return new Status(IStatus.ERROR, CUIPlugin.PLUGIN_ID, 0, e.getLocalizedMessage(), e);
}
}
public String getLabel() {
String type = null;
if ((flags & FIND_REFERENCES) != 0)
type = CSearchMessages.getString("PDOMSearch.query.refs.label"); //$NON-NLS-1$
else if ((flags & FIND_DECLARATIONS) != 0)
type = CSearchMessages.getString("PDOMSearch.query.decls.label"); //$NON-NLS-1$
else
type = CSearchMessages.getString("PDOMSearch.query.defs.label"); //$NON-NLS-1$
return type + " " + binding.getName();
}
public boolean canRerun() {
return true;
}
public boolean canRunInBackground() {
return true;
}
public ISearchResult getSearchResult() {
return result;
}
}

View file

@ -0,0 +1,136 @@
/*******************************************************************************
* Copyright (c) 2006 QNX Software Systems 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:
* QNX - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.ui.search;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
import org.eclipse.cdt.internal.ui.util.ExternalEditorInput;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.search.ui.ISearchQuery;
import org.eclipse.search.ui.text.AbstractTextSearchResult;
import org.eclipse.search.ui.text.IEditorMatchAdapter;
import org.eclipse.search.ui.text.IFileMatchAdapter;
import org.eclipse.search.ui.text.Match;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.part.FileEditorInput;
/**
* @author Doug Schaefer
*
*/
public class PDOMSearchResult extends AbstractTextSearchResult implements IEditorMatchAdapter, IFileMatchAdapter {
private PDOMSearchQuery query;
public PDOMSearchResult(PDOMSearchQuery query) {
super();
this.query = query;
}
public IEditorMatchAdapter getEditorMatchAdapter() {
return this;
}
public IFileMatchAdapter getFileMatchAdapter() {
return this;
}
private String getFileName(IEditorPart editor) {
IEditorInput input = editor.getEditorInput();
if (input instanceof FileEditorInput) {
FileEditorInput fileInput = (FileEditorInput)input;
return fileInput.getFile().getLocation().toOSString();
} else if (input instanceof ExternalEditorInput) {
ExternalEditorInput extInput = (ExternalEditorInput)input;
return extInput.getStorage().getFullPath().toOSString();
} else {
return null;
}
}
public boolean isShownInEditor(Match match, IEditorPart editor) {
String filename = getFileName(editor);
if (filename != null && match instanceof PDOMSearchMatch) {
return filename.equals(((PDOMSearchMatch)match).getFileName());
} else
return false;
}
private Match[] computeContainedMatches(AbstractTextSearchResult result, String filename) {
List list = new ArrayList();
Object[] elements = result.getElements();
for (int i = 0; i < elements.length; ++i) {
Match[] matches = result.getMatches(elements[i]);
for (int j = 0; j < matches.length; ++j) {
if (matches[j] instanceof PDOMSearchMatch) {
String mfilename = ((PDOMSearchMatch)matches[j]).getFileName();
if (filename.equals(mfilename))
list.add(matches[j]);
}
}
}
return (Match[])list.toArray(new Match[list.size()]);
}
public Match[] computeContainedMatches(AbstractTextSearchResult result, IEditorPart editor) {
String filename = getFileName(editor);
if (filename != null) {
return computeContainedMatches(result, filename);
} else {
return new Match[0];
}
}
public Match[] computeContainedMatches(AbstractTextSearchResult result, IFile file) {
String filename = file.getLocation().toOSString();
return computeContainedMatches(result, filename);
}
public IFile getFile(Object element) {
if (element instanceof PDOMName) {
PDOMName name = (PDOMName)element;
IASTFileLocation loc = name.getFileLocation();
IPath path = new Path(loc.getFileName());
IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(path);
if (files.length > 0)
return files[0];
else
return null;
} else
return null;
}
public String getLabel() {
return query.getLabel();
}
public String getTooltip() {
return null;
}
public ImageDescriptor getImageDescriptor() {
return null;
}
public ISearchQuery getQuery() {
return query;
}
}

View file

@ -0,0 +1,122 @@
/*******************************************************************************
* Copyright (c) 2006 QNX Software Systems 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:
* QNX - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.ui.search;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.widgets.Display;
/**
* @author Doug Schaefer
*
*/
public class PDOMSearchTreeContentProvider implements ITreeContentProvider {
private TreeViewer viewer;
private PDOMSearchResult result;
private HashMap tree;
public Object[] getChildren(Object parentElement) {
Set children = (Set)tree.get(parentElement);
if (children == null)
return new Object[0];
return children.toArray();
}
public Object getParent(Object element) {
return null;
}
public boolean hasChildren(Object element) {
return tree.get(element) != null;
}
public Object[] getElements(Object inputElement) {
return getChildren(result);
}
public void dispose() {
}
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
this.viewer = (TreeViewer)viewer;
result = (PDOMSearchResult)newInput;
tree = new HashMap();
}
private void insertChild(Object parent, Object child) {
Set children = (Set)tree.get(parent);
if (children == null) {
children = new HashSet();
tree.put(parent, children);
}
children.add(child);
}
private void insertName(PDOMName name) {
IASTFileLocation loc = name.getFileLocation();
IPath path = new Path(loc.getFileName());
IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(path);
if (files.length > 0) {
for (int j = 0; j < files.length; ++j) {
insertChild(files[j], name);
insertResource(files[j]);
}
} else {
String pathName = path.toOSString();
insertChild(pathName, name);
insertChild(result, pathName);
}
}
private void insertResource(IResource resource) {
if (resource instanceof IProject) {
insertChild(result, resource);
} else {
IContainer parent = resource.getParent();
insertChild(parent, resource);
insertResource(parent);
}
}
public void elementsChanged(Object[] elements) {
if (elements == null || elements.length == 0)
return;
for (int i = 0; i < elements.length; ++i) {
PDOMName name = (PDOMName)elements[i];
insertName(name);
}
Display.getDefault().asyncExec(new Runnable() {
public void run() {
viewer.refresh();
};
});
}
public void clear() {
}
}

View file

@ -0,0 +1,98 @@
/*******************************************************************************
* Copyright (c) 2006 QNX Software Systems 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:
* QNX - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.ui.search;
import org.eclipse.cdt.core.resources.FileStorage;
import org.eclipse.cdt.internal.ui.editor.ExternalSearchEditor;
import org.eclipse.cdt.internal.ui.util.ExternalEditorInput;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.search.ui.NewSearchUI;
import org.eclipse.search.ui.text.AbstractTextSearchViewPage;
import org.eclipse.search.ui.text.Match;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.ide.IDE;
import org.eclipse.ui.texteditor.ITextEditor;
/**
* @author Doug Schaefer
*
*/
public class PDOMSearchViewPage extends AbstractTextSearchViewPage {
private PDOMSearchTreeContentProvider contentProvider;
public PDOMSearchViewPage(int supportedLayouts) {
super(supportedLayouts);
}
public PDOMSearchViewPage() {
super();
}
protected void elementsChanged(Object[] objects) {
if (contentProvider != null)
contentProvider.elementsChanged(objects);
}
protected void clear() {
if (contentProvider != null)
contentProvider.clear();
}
protected void configureTreeViewer(TreeViewer viewer) {
contentProvider = new PDOMSearchTreeContentProvider();
viewer.setContentProvider(contentProvider);
viewer.setLabelProvider(new PDOMSearchLabelProvider());
}
protected void configureTableViewer(TableViewer viewer) {
}
protected void showMatch(Match match, int currentOffset, int currentLength, boolean activate) throws PartInitException {
if (!(match instanceof PDOMSearchMatch))
return;
IPath path = new Path(((PDOMSearchMatch)match).getFileName());
IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(path);
if (files.length > 0) {
IEditorPart editor = IDE.openEditor(CUIPlugin.getActivePage(), files[0]);
try {
IMarker marker = files[0].createMarker(NewSearchUI.SEARCH_MARKER);
marker.setAttribute(IMarker.CHAR_START, currentOffset);
marker.setAttribute(IMarker.CHAR_END, currentOffset + currentLength);
IDE.gotoMarker(editor, marker);
marker.delete();
} catch (CoreException e) {
CUIPlugin.getDefault().log(e);
}
} else {
// external file
IEditorInput input = new ExternalEditorInput(new FileStorage(path));
IEditorPart editor = CUIPlugin.getActivePage().openEditor(input, ExternalSearchEditor.EDITOR_ID);
if (editor instanceof ITextEditor) {
ITextEditor textEditor = (ITextEditor)editor;
textEditor.selectAndReveal(currentOffset, currentLength);
}
}
}
}