mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-31 12:55:40 +02:00
Patch for Devin Steffler.
Further updates to DOM AST View.
This commit is contained in:
parent
027b23c9e3
commit
d35174e94d
5 changed files with 209 additions and 14 deletions
|
@ -18,6 +18,7 @@
|
||||||
<import plugin="org.eclipse.swt"/>
|
<import plugin="org.eclipse.swt"/>
|
||||||
<import plugin="org.eclipse.ui"/>
|
<import plugin="org.eclipse.ui"/>
|
||||||
<import plugin="org.eclipse.ui.editors"/>
|
<import plugin="org.eclipse.ui.editors"/>
|
||||||
|
<import plugin="org.eclipse.ui.ide"/>
|
||||||
<import plugin="org.eclipse.ui.views"/>
|
<import plugin="org.eclipse.ui.views"/>
|
||||||
<import plugin="org.eclipse.ui.workbench.texteditor"/>
|
<import plugin="org.eclipse.ui.workbench.texteditor"/>
|
||||||
<import plugin="org.junit"/>
|
<import plugin="org.junit"/>
|
||||||
|
@ -25,6 +26,10 @@
|
||||||
<import plugin="org.eclipse.cdt.core.tests"/>
|
<import plugin="org.eclipse.cdt.core.tests"/>
|
||||||
<import plugin="org.eclipse.help"/>
|
<import plugin="org.eclipse.help"/>
|
||||||
<import plugin="org.eclipse.core.runtime"/>
|
<import plugin="org.eclipse.core.runtime"/>
|
||||||
|
<import plugin="org.eclipse.search"/>
|
||||||
|
<import plugin="org.eclipse.compare"/>
|
||||||
|
<import plugin="org.eclipse.ui.console"/>
|
||||||
|
<import plugin="org.eclipse.core.expressions"/>
|
||||||
</requires>
|
</requires>
|
||||||
|
|
||||||
<extension
|
<extension
|
||||||
|
|
|
@ -18,6 +18,7 @@ import org.eclipse.core.runtime.Plugin;
|
||||||
|
|
||||||
public class CTestPlugin extends Plugin {
|
public class CTestPlugin extends Plugin {
|
||||||
|
|
||||||
|
public static String PLUGIN_ID = "org.eclipse.cdt.ui.tests"; //$NON-NLS-1$
|
||||||
private static CTestPlugin fgDefault;
|
private static CTestPlugin fgDefault;
|
||||||
|
|
||||||
public CTestPlugin() {
|
public CTestPlugin() {
|
||||||
|
@ -48,5 +49,9 @@ public class CTestPlugin extends Plugin {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getPluginId() {
|
||||||
|
return PLUGIN_ID;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -67,6 +67,7 @@ import org.eclipse.jface.viewers.StructuredSelection;
|
||||||
import org.eclipse.jface.viewers.TreeViewer;
|
import org.eclipse.jface.viewers.TreeViewer;
|
||||||
import org.eclipse.jface.viewers.Viewer;
|
import org.eclipse.jface.viewers.Viewer;
|
||||||
import org.eclipse.jface.viewers.ViewerSorter;
|
import org.eclipse.jface.viewers.ViewerSorter;
|
||||||
|
import org.eclipse.search.ui.NewSearchUI;
|
||||||
import org.eclipse.swt.SWT;
|
import org.eclipse.swt.SWT;
|
||||||
import org.eclipse.swt.graphics.Image;
|
import org.eclipse.swt.graphics.Image;
|
||||||
import org.eclipse.swt.widgets.Composite;
|
import org.eclipse.swt.widgets.Composite;
|
||||||
|
@ -418,22 +419,12 @@ private static final String REFRESH_DOM_AST = "Refresh DOM AST"; //$NON-NLS-1
|
||||||
collapseAllAction.setToolTipText(COLLAPSE_ALL);
|
collapseAllAction.setToolTipText(COLLAPSE_ALL);
|
||||||
collapseAllAction.setImageDescriptor(DOMASTPluginImages.DESC_COLLAPSE_ALL);
|
collapseAllAction.setImageDescriptor(DOMASTPluginImages.DESC_COLLAPSE_ALL);
|
||||||
|
|
||||||
openDeclarationsAction = new Action() {
|
openDeclarationsAction = new DisplayDeclarationsAction();
|
||||||
public void run() {
|
|
||||||
showMessage("Action 1 executed"); // TODO open declarations action //$NON-NLS-1$
|
|
||||||
// ... use annotations
|
|
||||||
}
|
|
||||||
};
|
|
||||||
openDeclarationsAction.setText(OPEN_DECLARATIONS);
|
openDeclarationsAction.setText(OPEN_DECLARATIONS);
|
||||||
openDeclarationsAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages()
|
openDeclarationsAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages()
|
||||||
.getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
|
.getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
|
||||||
|
|
||||||
openReferencesAction = new Action() {
|
openReferencesAction = new DisplayReferencesAction();
|
||||||
public void run() {
|
|
||||||
showMessage("Action 2 executed"); // TODO open references action ... //$NON-NLS-1$
|
|
||||||
// use annotations
|
|
||||||
}
|
|
||||||
};
|
|
||||||
openReferencesAction.setText(OPEN_REFERENCES);
|
openReferencesAction.setText(OPEN_REFERENCES);
|
||||||
openReferencesAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages()
|
openReferencesAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages()
|
||||||
.getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
|
.getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
|
||||||
|
@ -504,6 +495,48 @@ private static final String REFRESH_DOM_AST = "Refresh DOM AST"; //$NON-NLS-1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class DisplayDeclarationsAction extends DisplaySearchResultAction {
|
||||||
|
public void run() {
|
||||||
|
ISelection selection = viewer.getSelection();
|
||||||
|
if (selection instanceof IStructuredSelection &&
|
||||||
|
((IStructuredSelection)selection).getFirstElement() instanceof TreeObject &&
|
||||||
|
((TreeObject)((IStructuredSelection)selection).getFirstElement()).getNode() instanceof IASTName) {
|
||||||
|
|
||||||
|
if (lang == ParserLanguage.CPP) {
|
||||||
|
// TODO Devin when implemented in CPPVisitor
|
||||||
|
} else {
|
||||||
|
IASTName[] names = CVisitor.getDeclarations( ((TreeObject)((IStructuredSelection)selection).getFirstElement()).getNode().getTranslationUnit(), ((IASTName)((TreeObject)((IStructuredSelection)selection).getFirstElement()).getNode()).resolveBinding() );
|
||||||
|
displayNames(names, OPEN_DECLARATIONS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class DisplayReferencesAction extends DisplaySearchResultAction {
|
||||||
|
public void run() {
|
||||||
|
ISelection selection = viewer.getSelection();
|
||||||
|
if (selection instanceof IStructuredSelection &&
|
||||||
|
((IStructuredSelection)selection).getFirstElement() instanceof TreeObject &&
|
||||||
|
((TreeObject)((IStructuredSelection)selection).getFirstElement()).getNode() instanceof IASTName) {
|
||||||
|
|
||||||
|
if (lang == ParserLanguage.CPP) {
|
||||||
|
// TODO Devin when implemented in CPPVisitor
|
||||||
|
} else {
|
||||||
|
IASTName[] names = CVisitor.getReferences( ((TreeObject)((IStructuredSelection)selection).getFirstElement()).getNode().getTranslationUnit(), ((IASTName)((TreeObject)((IStructuredSelection)selection).getFirstElement()).getNode()).resolveBinding() );
|
||||||
|
displayNames(names, OPEN_REFERENCES);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class DisplaySearchResultAction extends Action {
|
||||||
|
protected void displayNames(IASTName[] names, String queryLabel) {
|
||||||
|
DOMQuery job = new DOMQuery(names, queryLabel);
|
||||||
|
NewSearchUI.activateSearchResultView();
|
||||||
|
NewSearchUI.runQuery(job);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO need to create a new action with the following for annotations (get
|
// TODO need to create a new action with the following for annotations (get
|
||||||
// declarations/references)
|
// declarations/references)
|
||||||
// ISelection selection = viewer.getSelection();
|
// ISelection selection = viewer.getSelection();
|
||||||
|
@ -552,7 +585,6 @@ private static final String REFRESH_DOM_AST = "Refresh DOM AST"; //$NON-NLS-1
|
||||||
private void hookSingleClickAction() {
|
private void hookSingleClickAction() {
|
||||||
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
|
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
|
||||||
public void selectionChanged(SelectionChangedEvent event) {
|
public void selectionChanged(SelectionChangedEvent event) {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
singleClickAction.run();
|
singleClickAction.run();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -0,0 +1,153 @@
|
||||||
|
/**********************************************************************
|
||||||
|
* Copyright (c) 2005 IBM Canada and others.
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Common Public License v0.5
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/cpl-v05.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* IBM Rational Software - Initial API and implementation
|
||||||
|
**********************************************************************/
|
||||||
|
package org.eclipse.cdt.ui.tests.DOMAST;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
|
||||||
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
|
import org.eclipse.cdt.core.search.BasicSearchMatch;
|
||||||
|
import org.eclipse.cdt.core.search.IMatch;
|
||||||
|
import org.eclipse.cdt.ui.testplugin.CTestPlugin;
|
||||||
|
import org.eclipse.cdt.internal.ui.search.CSearchQuery;
|
||||||
|
import org.eclipse.cdt.internal.ui.search.CSearchResult;
|
||||||
|
import org.eclipse.cdt.internal.ui.search.NewSearchResultCollector;
|
||||||
|
import org.eclipse.core.resources.IFile;
|
||||||
|
import org.eclipse.core.resources.IResource;
|
||||||
|
import org.eclipse.core.resources.ResourcesPlugin;
|
||||||
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
import org.eclipse.core.runtime.IPath;
|
||||||
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
|
import org.eclipse.core.runtime.IStatus;
|
||||||
|
import org.eclipse.core.runtime.OperationCanceledException;
|
||||||
|
import org.eclipse.core.runtime.Path;
|
||||||
|
import org.eclipse.core.runtime.Status;
|
||||||
|
import org.eclipse.core.runtime.SubProgressMonitor;
|
||||||
|
import org.eclipse.search.ui.ISearchQuery;
|
||||||
|
import org.eclipse.search.ui.ISearchResult;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author dsteffle
|
||||||
|
*/
|
||||||
|
public class DOMQuery extends CSearchQuery implements ISearchQuery {
|
||||||
|
|
||||||
|
private static final String BLANK_STRING = ""; //$NON-NLS-1$
|
||||||
|
private CSearchResult _result;
|
||||||
|
private IASTName[] names = null;
|
||||||
|
private String queryLabel = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public DOMQuery(IASTName[] names, String queryLabel) {
|
||||||
|
super(CTestPlugin.getWorkspace(), null, null, BLANK_STRING, null); //$NON-NLS-1$
|
||||||
|
this.names = names;
|
||||||
|
this.queryLabel = queryLabel;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.search.ui.ISearchQuery#run(org.eclipse.core.runtime.IProgressMonitor)
|
||||||
|
*/
|
||||||
|
public IStatus run(IProgressMonitor monitor)
|
||||||
|
throws OperationCanceledException {
|
||||||
|
|
||||||
|
final CSearchResult textResult= (CSearchResult) getSearchResult();
|
||||||
|
|
||||||
|
IProgressMonitor mainSearchPM= new SubProgressMonitor(monitor, 1000);
|
||||||
|
NewSearchResultCollector collector = new NewSearchResultCollector(textResult, mainSearchPM);
|
||||||
|
|
||||||
|
collector.aboutToStart();
|
||||||
|
|
||||||
|
for (int i=0; i<names.length; i++) {
|
||||||
|
try {
|
||||||
|
String fileName = null;
|
||||||
|
IFile file = null;
|
||||||
|
IPath path = null;
|
||||||
|
int start = 0;
|
||||||
|
int end = 0;
|
||||||
|
if ( names[i] != null ) {
|
||||||
|
IASTNodeLocation [] location = names[i].getNodeLocations();
|
||||||
|
if( location.length > 0 && location[0] instanceof IASTFileLocation )
|
||||||
|
fileName = ((IASTFileLocation)location[0]).getFileName(); // TODO Devin this is in two places now, put into one, and fix up the location[0] for things like macros
|
||||||
|
else
|
||||||
|
fileName = BLANK_STRING;
|
||||||
|
|
||||||
|
path = new Path(fileName);
|
||||||
|
file = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path);
|
||||||
|
start = names[i].getNodeLocations()[0].getNodeOffset();
|
||||||
|
end = names[i].getNodeLocations()[0].getNodeOffset() + names[i].getNodeLocations()[0].getNodeLength();
|
||||||
|
|
||||||
|
collector.acceptMatch( createMatch(file, start, end, names[i], path ) );
|
||||||
|
}
|
||||||
|
} catch (CoreException ce) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
mainSearchPM.done();
|
||||||
|
collector.done();
|
||||||
|
|
||||||
|
return new Status(IStatus.OK, CTestPlugin.getPluginId(), 0, BLANK_STRING, null); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
|
||||||
|
public IMatch createMatch( Object fileResource, int start, int end, IASTName name, IPath referringElement ) {
|
||||||
|
BasicSearchMatch result = new BasicSearchMatch();
|
||||||
|
if( fileResource instanceof IResource )
|
||||||
|
result.resource = (IResource) fileResource;
|
||||||
|
else if( fileResource instanceof IPath )
|
||||||
|
result.path = (IPath) fileResource;
|
||||||
|
|
||||||
|
result.startOffset = start;
|
||||||
|
result.endOffset = end;
|
||||||
|
result.parentName = BLANK_STRING; //$NON-NLS-1$
|
||||||
|
result.referringElement = referringElement;
|
||||||
|
|
||||||
|
result.name = name.toString();
|
||||||
|
|
||||||
|
result.type = ICElement.C_FIELD; // TODO Devin static for now, want something like BasicSearchResultCollector#setElementInfo
|
||||||
|
result.visibility = ICElement.CPP_PUBLIC; // TODO Devin static for now, want something like BasicSearchResultCollector#setElementInfo
|
||||||
|
result.returnType = BLANK_STRING;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.search.ui.ISearchQuery#getLabel()
|
||||||
|
*/
|
||||||
|
public String getLabel() {
|
||||||
|
return queryLabel;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.search.ui.ISearchQuery#canRerun()
|
||||||
|
*/
|
||||||
|
public boolean canRerun() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.search.ui.ISearchQuery#canRunInBackground()
|
||||||
|
*/
|
||||||
|
public boolean canRunInBackground() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.search.ui.ISearchQuery#getSearchResult()
|
||||||
|
*/
|
||||||
|
public ISearchResult getSearchResult() {
|
||||||
|
if (_result == null)
|
||||||
|
_result= new CSearchResult(this);
|
||||||
|
return _result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -65,7 +65,7 @@ public class TreeObject implements IAdaptable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
if( node == null ) return BLANK_FILENAME; //$NON-NLS-1$ //TODO Devin is this the best way???
|
if( node == null ) return BLANK_FILENAME; //$NON-NLS-1$
|
||||||
StringBuffer buffer = new StringBuffer();
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
|
||||||
Class[] classes = node.getClass().getInterfaces();
|
Class[] classes = node.getClass().getInterfaces();
|
||||||
|
|
Loading…
Add table
Reference in a new issue