mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Further DOM/AST fixes (w/viewer).
This commit is contained in:
parent
d7b97a7f42
commit
b811a0479b
5 changed files with 547 additions and 514 deletions
|
@ -13,6 +13,7 @@ package org.eclipse.cdt.core.parser.tests.ast2;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
||||
|
@ -166,4 +167,17 @@ public class DOMLocationTests extends AST2BaseTest {
|
|||
assertSoleLocation( expression, code.indexOf( "return ") + "return ".length(), 1 ); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
|
||||
|
||||
public void testElaboratedTypeSpecifier() throws ParserException {
|
||||
String code = "/* blah */ struct A anA; /* blah */"; //$NON-NLS-1$
|
||||
for (ParserLanguage p = ParserLanguage.C; p != null; p = (p == ParserLanguage.C) ? ParserLanguage.CPP
|
||||
: null) {
|
||||
IASTTranslationUnit tu = parse(code, p);
|
||||
IASTSimpleDeclaration declaration = (IASTSimpleDeclaration) tu.getDeclarations()[0];
|
||||
IASTElaboratedTypeSpecifier elabType = (IASTElaboratedTypeSpecifier) declaration.getDeclSpecifier();
|
||||
assertSoleLocation( elabType, code.indexOf( "struct"), "struct A".length() ); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1672,6 +1672,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
name.setParent(result);
|
||||
name.setPropertyInParent(IASTElaboratedTypeSpecifier.TYPE_NAME);
|
||||
result.setKind(eck);
|
||||
((ASTNode)result).setOffsetAndLength( t.getOffset(), calculateEndOffset(name) - t.getOffset() );
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -37,9 +37,14 @@ import org.eclipse.cdt.internal.core.dom.parser.c.GCCParserExtensionConfiguratio
|
|||
import org.eclipse.cdt.internal.core.dom.parser.c.GNUCSourceParser;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.c.ICParserExtensionConfiguration;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ANSICPPParserExtensionConfiguration;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.GPPParserExtensionConfiguration;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.GNUCPPSourceParser;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.GPPParserExtensionConfiguration;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPParserExtensionConfiguration;
|
||||
import org.eclipse.cdt.internal.core.parser.InternalParserUtil;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.DOMScanner;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.GCCScannerExtensionConfiguration;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.GPPScannerExtensionConfiguration;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.IScannerExtensionConfiguration;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
|
@ -50,6 +55,8 @@ import org.eclipse.core.runtime.CoreException;
|
|||
*/
|
||||
public class InternalASTServiceProvider implements IASTServiceProvider {
|
||||
|
||||
protected static final GCCScannerExtensionConfiguration C_GNU_SCANNER_EXTENSION = new GCCScannerExtensionConfiguration();
|
||||
protected static final GPPScannerExtensionConfiguration CPP_GNU_SCANNER_EXTENSION = new GPPScannerExtensionConfiguration();
|
||||
private static final String[] dialects = { "C99", //$NON-NLS-1$
|
||||
"C++98", //$NON-NLS-1$
|
||||
"GNUC", //$NON-NLS-1$
|
||||
|
@ -110,9 +117,14 @@ public class InternalASTServiceProvider implements IASTServiceProvider {
|
|||
if( configuration == null )
|
||||
{
|
||||
ParserLanguage l = getLanguage(fileToParse);
|
||||
scanner = ParserFactory.createScanner(reader, scanInfo, ParserMode.COMPLETE_PARSE,
|
||||
l, NULL_REQUESTOR,
|
||||
ParserUtil.getScannerLogService(), Collections.EMPTY_LIST);
|
||||
IScannerExtensionConfiguration scannerExtensionConfiguration = null;
|
||||
if( l == ParserLanguage.CPP )
|
||||
scannerExtensionConfiguration = CPP_GNU_SCANNER_EXTENSION;
|
||||
else
|
||||
scannerExtensionConfiguration = C_GNU_SCANNER_EXTENSION;
|
||||
|
||||
scanner = new DOMScanner(reader, scanInfo, ParserMode.COMPLETE_PARSE,
|
||||
l, ParserFactory.createDefaultLogService(), scannerExtensionConfiguration, fileCreator );
|
||||
//assume GCC
|
||||
if( l == ParserLanguage.C )
|
||||
parser = new GNUCSourceParser( scanner, ParserMode.COMPLETE_PARSE, ParserUtil.getParserLogService(), new GCCParserExtensionConfiguration() );
|
||||
|
|
|
@ -10,36 +10,8 @@
|
|||
**********************************************************************/
|
||||
package org.eclipse.cdt.ui.tests.DOMAST;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.ui.tests.DOMAST.DOMASTPluginImages;
|
||||
import org.eclipse.cdt.ui.tests.DOMAST.CPPPopulateASTViewAction;
|
||||
import org.eclipse.cdt.ui.tests.DOMAST.CPopulateASTViewAction;
|
||||
import org.eclipse.cdt.ui.tests.DOMAST.IPopulateDOMASTAction;
|
||||
import org.eclipse.cdt.ui.tests.DOMAST.TreeObject;
|
||||
import org.eclipse.cdt.ui.tests.DOMAST.TreeParent;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.ui.part.*;
|
||||
import org.eclipse.jface.viewers.*;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
import org.eclipse.jface.action.*;
|
||||
import org.eclipse.jface.dialogs.MessageDialog;
|
||||
import org.eclipse.ui.*;
|
||||
import org.eclipse.swt.widgets.Menu;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.NullLogService;
|
||||
import org.eclipse.cdt.core.parser.NullSourceElementRequestor;
|
||||
import org.eclipse.cdt.core.parser.ParserFactory;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.IScanner;
|
||||
import org.eclipse.cdt.core.parser.ParserMode;
|
||||
import org.eclipse.cdt.core.parser.ScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTEnumerator;
|
||||
import org.eclipse.cdt.core.dom.CDOM;
|
||||
import org.eclipse.cdt.core.dom.IASTServiceProvider;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||
|
@ -59,40 +31,69 @@ import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
|||
import org.eclipse.cdt.core.dom.ast.c.ICASTDesignator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser;
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.ParserUtil;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTEnumerator;
|
||||
import org.eclipse.cdt.core.resources.FileStorage;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.c.GCCParserExtensionConfiguration;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.c.GNUCSourceParser;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.GNUCPPSourceParser;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.GPPParserExtensionConfiguration;
|
||||
import org.eclipse.cdt.internal.core.parser.InternalParserUtil;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.DOMScanner;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.GCCScannerExtensionConfiguration;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.GPPScannerExtensionConfiguration;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.IScannerExtensionConfiguration;
|
||||
import org.eclipse.cdt.internal.ui.editor.CEditor;
|
||||
import org.eclipse.cdt.internal.ui.util.EditorUtility;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
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.action.Action;
|
||||
import org.eclipse.jface.action.ActionContributionItem;
|
||||
import org.eclipse.jface.action.IContributionItem;
|
||||
import org.eclipse.jface.action.IMenuListener;
|
||||
import org.eclipse.jface.action.IMenuManager;
|
||||
import org.eclipse.jface.action.IToolBarManager;
|
||||
import org.eclipse.jface.action.MenuManager;
|
||||
import org.eclipse.jface.action.Separator;
|
||||
import org.eclipse.jface.dialogs.MessageDialog;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.viewers.ISelectionChangedListener;
|
||||
import org.eclipse.jface.viewers.IStructuredContentProvider;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.jface.viewers.ITreeContentProvider;
|
||||
import org.eclipse.jface.viewers.LabelProvider;
|
||||
import org.eclipse.jface.viewers.SelectionChangedEvent;
|
||||
import org.eclipse.jface.viewers.StructuredSelection;
|
||||
import org.eclipse.jface.viewers.TreeViewer;
|
||||
import org.eclipse.jface.viewers.Viewer;
|
||||
import org.eclipse.jface.viewers.ViewerSorter;
|
||||
import org.eclipse.swt.SWT;
|
||||
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.IEditorReference;
|
||||
import org.eclipse.ui.ISharedImages;
|
||||
import org.eclipse.ui.IWorkbenchActionConstants;
|
||||
import org.eclipse.ui.IWorkbenchPage;
|
||||
import org.eclipse.ui.PartInitException;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.ui.part.DrillDownAdapter;
|
||||
import org.eclipse.ui.part.ViewPart;
|
||||
|
||||
/**
|
||||
* This sample class demonstrates how to plug-in a new
|
||||
* workbench view. The view shows data obtained from the
|
||||
* model. The sample creates a dummy model on the fly,
|
||||
* but a real implementation would connect to the model
|
||||
* available either in this or another plug-in (e.g. the workspace).
|
||||
* The view is connected to the model using a content provider.
|
||||
* This sample class demonstrates how to plug-in a new workbench view. The view
|
||||
* shows data obtained from the model. The sample creates a dummy model on the
|
||||
* fly, but a real implementation would connect to the model available either in
|
||||
* this or another plug-in (e.g. the workspace). The view is connected to the
|
||||
* model using a content provider.
|
||||
* <p>
|
||||
* The view uses a label provider to define how model
|
||||
* objects should be presented in the view. Each
|
||||
* view can present the same model objects using
|
||||
* different labels and icons, if needed. Alternatively,
|
||||
* a single label provider can be shared between views
|
||||
* in order to ensure that objects of the same type are
|
||||
* presented in the same way everywhere.
|
||||
* The view uses a label provider to define how model objects should be
|
||||
* presented in the view. Each view can present the same model objects using
|
||||
* different labels and icons, if needed. Alternatively, a single label provider
|
||||
* can be shared between views in order to ensure that objects of the same type
|
||||
* are presented in the same way everywhere.
|
||||
* <p>
|
||||
*/
|
||||
|
||||
|
@ -102,7 +103,7 @@ public class DOMAST extends ViewPart {
|
|||
private static final String POPUPMENU = "#PopupMenu"; //$NON-NLS-1$
|
||||
private static final String OPEN_DECLARATIONS = "Open Declarations"; //$NON-NLS-1$
|
||||
private static final String OPEN_REFERENCES = "Open References"; //$NON-NLS-1$
|
||||
private TreeViewer viewer;
|
||||
TreeViewer viewer;
|
||||
private DrillDownAdapter drillDownAdapter;
|
||||
private Action action1;
|
||||
private Action action2;
|
||||
|
@ -113,13 +114,10 @@ public class DOMAST extends ViewPart {
|
|||
ParserLanguage lang = null;
|
||||
|
||||
/*
|
||||
* The content provider class is responsible for
|
||||
* providing objects to the view. It can wrap
|
||||
* existing objects in adapters or simply return
|
||||
* objects as-is. These objects may be sensitive
|
||||
* to the current input of the view, or ignore
|
||||
* it and always show the same content
|
||||
* (like Task List, for example).
|
||||
* The content provider class is responsible for providing objects to the
|
||||
* view. It can wrap existing objects in adapters or simply return objects
|
||||
* as-is. These objects may be sensitive to the current input of the view, or
|
||||
* ignore it and always show the same content (like Task List, for example).
|
||||
*/
|
||||
|
||||
public class ViewContentProvider implements IStructuredContentProvider,
|
||||
|
@ -130,7 +128,8 @@ public class DOMAST extends ViewPart {
|
|||
/**
|
||||
*
|
||||
*/
|
||||
public ViewContentProvider() {}
|
||||
public ViewContentProvider() {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -141,122 +140,63 @@ public class DOMAST extends ViewPart {
|
|||
|
||||
public void inputChanged(Viewer v, Object oldInput, Object newInput) {
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
}
|
||||
|
||||
public Object[] getElements(Object parent) {
|
||||
if (parent.equals(getViewSite())) {
|
||||
if (invisibleRoot==null) initialize();
|
||||
if (invisibleRoot == null)
|
||||
initialize();
|
||||
return getChildren(invisibleRoot);
|
||||
}
|
||||
return getChildren(parent);
|
||||
}
|
||||
|
||||
public Object getParent(Object child) {
|
||||
if (child instanceof TreeObject) {
|
||||
return ((TreeObject)child).getParent();
|
||||
return ((TreeObject) child).getParent();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public Object [] getChildren(Object parent) {
|
||||
|
||||
public Object[] getChildren(Object parent) {
|
||||
if (parent instanceof TreeParent) {
|
||||
return ((TreeParent)parent).getChildren();
|
||||
return ((TreeParent) parent).getChildren();
|
||||
}
|
||||
return new Object[0];
|
||||
}
|
||||
|
||||
public boolean hasChildren(Object parent) {
|
||||
if (parent instanceof TreeParent)
|
||||
return ((TreeParent)parent).hasChildren();
|
||||
return ((TreeParent) parent).hasChildren();
|
||||
return false;
|
||||
}
|
||||
|
||||
private void initialize() {
|
||||
if ( aFile == null || lang == null) return;
|
||||
if (aFile == null || lang == null)
|
||||
return;
|
||||
|
||||
IPopulateDOMASTAction action = null;
|
||||
|
||||
// TODO could use something like below to work with working copy... i.e. refresh button
|
||||
// IProject currentProject = aFile.getProject();
|
||||
// IWorkingCopy workingCopy = null;
|
||||
// if( editor.isDirty() ){
|
||||
// IWorkingCopy [] workingCopies = CUIPlugin.getSharedWorkingCopies();
|
||||
// if( workingCopies != null ){
|
||||
// for( int i = 0; i < workingCopies.length; i++ ){
|
||||
// if( workingCopies[i].getUnderlyingResource().equals( file ) ){
|
||||
// workingCopy = workingCopies[i];
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
CodeReader reader = null;
|
||||
IASTTranslationUnit tu = null;
|
||||
try {
|
||||
// if( workingCopy == null )
|
||||
reader = new CodeReader(aFile.getLocation().toOSString(), aFile.getCharset() );
|
||||
// else
|
||||
// reader = new CodeReader(aFile.getLocation().toOSString(), workingCopy.getContents());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch ( CoreException e ) {
|
||||
e.printStackTrace();
|
||||
tu = CDOM.getInstance().getDefaultASTService().getTranslationUnit(
|
||||
aFile,
|
||||
CDOM.getInstance().getCodeReaderFactory(
|
||||
CDOM.PARSE_SAVED_RESOURCES));
|
||||
} catch (IASTServiceProvider.UnsupportedDialectException e) {
|
||||
return;
|
||||
}
|
||||
|
||||
// get IFile
|
||||
// IWorkspace workspace= ResourcesPlugin.getWorkspace();
|
||||
// workspace.setDescription(desc);
|
||||
// getWorkbench().getActiveWorkbenchWindow();
|
||||
|
||||
// parse IFile
|
||||
ParserMode mode = ParserMode.COMPLETE_PARSE;
|
||||
Map definitions = new Hashtable();
|
||||
|
||||
String [] includePaths = new String[0];
|
||||
IScannerInfo scannerInfo = new ScannerInfo( definitions, includePaths );
|
||||
IScannerExtensionConfiguration configuration = null;
|
||||
if( lang == ParserLanguage.CPP )
|
||||
configuration = new GPPScannerExtensionConfiguration();
|
||||
else
|
||||
configuration = new GCCScannerExtensionConfiguration();
|
||||
|
||||
IScanner scanner = new DOMScanner( reader, scannerInfo, mode, lang, ParserFactory.createDefaultLogService(), configuration, CDOM.getInstance().getCodeReaderFactory( CDOM.PARSE_SAVED_RESOURCES) );
|
||||
|
||||
// reader,
|
||||
// scannerInfo,
|
||||
// mode,
|
||||
// lang,
|
||||
// new NullSourceElementRequestor(),
|
||||
// null,
|
||||
// null );
|
||||
AbstractGNUSourceCodeParser parser = null;
|
||||
if ( lang == ParserLanguage.C ) {
|
||||
parser = new GNUCSourceParser(
|
||||
scanner,
|
||||
mode,
|
||||
new NullLogService(),
|
||||
new GCCParserExtensionConfiguration()
|
||||
);
|
||||
|
||||
IASTTranslationUnit tu = parser.parse();
|
||||
|
||||
action = new CPopulateASTViewAction(tu);
|
||||
CVisitor.visitTranslationUnit(tu, (CBaseVisitorAction)action);
|
||||
} else if ( lang == ParserLanguage.CPP ){
|
||||
parser = new GNUCPPSourceParser(
|
||||
scanner,
|
||||
mode,
|
||||
new NullLogService(),
|
||||
new GPPParserExtensionConfiguration()
|
||||
);
|
||||
|
||||
IASTTranslationUnit tu = parser.parse();
|
||||
|
||||
if (lang == ParserLanguage.CPP) {
|
||||
action = new CPPPopulateASTViewAction(tu);
|
||||
CPPVisitor.visitTranslationUnit(tu, (CPPBaseVisitorAction)action);
|
||||
CPPVisitor.visitTranslationUnit(tu, (CPPBaseVisitorAction) action);
|
||||
} else {
|
||||
action = new CPopulateASTViewAction(tu);
|
||||
CVisitor.visitTranslationUnit(tu, (CBaseVisitorAction) action);
|
||||
}
|
||||
|
||||
// display roots
|
||||
invisibleRoot = new TreeParent(null); //$NON-NLS-1$
|
||||
invisibleRoot.addChild(action.getTree());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -265,57 +205,59 @@ public class DOMAST extends ViewPart {
|
|||
public String getText(Object obj) {
|
||||
return obj.toString();
|
||||
}
|
||||
|
||||
public Image getImage(Object obj) {
|
||||
String imageKey = DOMASTPluginImages.IMG_DEFAULT;
|
||||
|
||||
IASTNode node = null;
|
||||
if (obj instanceof TreeObject) {
|
||||
node = ((TreeObject)obj).getNode();
|
||||
node = ((TreeObject) obj).getNode();
|
||||
}
|
||||
|
||||
if ( node instanceof IASTArrayModifier ) {
|
||||
if (node instanceof IASTArrayModifier) {
|
||||
imageKey = DOMASTPluginImages.IMG_IASTArrayModifier;
|
||||
} else if ( node instanceof IASTDeclaration ) {
|
||||
} else if (node instanceof IASTDeclaration) {
|
||||
imageKey = DOMASTPluginImages.IMG_IASTDeclaration;
|
||||
} else if ( node instanceof IASTDeclarator ) {
|
||||
} else if (node instanceof IASTDeclarator) {
|
||||
imageKey = DOMASTPluginImages.IMG_IASTDeclarator;
|
||||
} else if ( node instanceof IASTDeclSpecifier ) {
|
||||
} else if (node instanceof IASTDeclSpecifier) {
|
||||
imageKey = DOMASTPluginImages.IMG_IASTDeclSpecifier;
|
||||
} else if ( node instanceof IASTEnumerator ) {
|
||||
} else if (node instanceof IASTEnumerator) {
|
||||
imageKey = DOMASTPluginImages.IMG_IASTEnumerator;
|
||||
} else if ( node instanceof IASTExpression ) {
|
||||
} else if (node instanceof IASTExpression) {
|
||||
imageKey = DOMASTPluginImages.IMG_IASTExpression;
|
||||
} else if ( node instanceof IASTInitializer ) {
|
||||
} else if (node instanceof IASTInitializer) {
|
||||
imageKey = DOMASTPluginImages.IMG_IASTInitializer;
|
||||
} else if ( node instanceof IASTName ) {
|
||||
} else if (node instanceof IASTName) {
|
||||
imageKey = DOMASTPluginImages.IMG_IASTName;
|
||||
} else if ( node instanceof IASTParameterDeclaration ) {
|
||||
} else if (node instanceof IASTParameterDeclaration) {
|
||||
imageKey = DOMASTPluginImages.IMG_IASTParameterDeclaration;
|
||||
} else if ( node instanceof IASTPointerOperator ) {
|
||||
} else if (node instanceof IASTPointerOperator) {
|
||||
imageKey = DOMASTPluginImages.IMG_IASTPointerOperator;
|
||||
} else if ( node instanceof IASTPreprocessorStatement ) {
|
||||
} else if (node instanceof IASTPreprocessorStatement) {
|
||||
imageKey = DOMASTPluginImages.IMG_IASTPreprocessorStatement;
|
||||
} else if ( node instanceof IASTProblem ) {
|
||||
} else if (node instanceof IASTProblem) {
|
||||
imageKey = DOMASTPluginImages.IMG_IASTProblem;
|
||||
} else if ( node instanceof IASTSimpleDeclaration ) {
|
||||
} else if (node instanceof IASTSimpleDeclaration) {
|
||||
imageKey = DOMASTPluginImages.IMG_IASTSimpleDeclaration;
|
||||
} else if ( node instanceof IASTStatement ) {
|
||||
} else if (node instanceof IASTStatement) {
|
||||
imageKey = DOMASTPluginImages.IMG_IASTStatement;
|
||||
} else if ( node instanceof IASTTranslationUnit ) {
|
||||
} else if (node instanceof IASTTranslationUnit) {
|
||||
imageKey = DOMASTPluginImages.IMG_IASTTranslationUnit;
|
||||
} else if ( node instanceof IASTTypeId ) {
|
||||
} else if (node instanceof IASTTypeId) {
|
||||
imageKey = DOMASTPluginImages.IMG_IASTTypeId;
|
||||
} else if ( node instanceof ICASTDesignator ) {
|
||||
} else if (node instanceof ICASTDesignator) {
|
||||
imageKey = DOMASTPluginImages.IMG_ICASTDesignator;
|
||||
} else if ( node instanceof ICPPASTConstructorChainInitializer ) {
|
||||
} else if (node instanceof ICPPASTConstructorChainInitializer) {
|
||||
imageKey = DOMASTPluginImages.IMG_ICPPASTConstructorChainInitializer;
|
||||
} else if ( node instanceof ICPPASTTemplateParameter ) {
|
||||
} else if (node instanceof ICPPASTTemplateParameter) {
|
||||
imageKey = DOMASTPluginImages.IMG_ICPPASTTemplateParameter;
|
||||
}
|
||||
|
||||
return DOMASTPluginImages.get(imageKey);
|
||||
}
|
||||
}
|
||||
|
||||
class NameSorter extends ViewerSorter {
|
||||
}
|
||||
|
||||
|
@ -324,21 +266,22 @@ public class DOMAST extends ViewPart {
|
|||
}
|
||||
|
||||
/**
|
||||
* This is a callback that will allow us
|
||||
* to create the viewer and initialize it.
|
||||
* This is a callback that will allow us to create the viewer and initialize
|
||||
* it.
|
||||
*/
|
||||
public void createPartControl(Composite parent) {
|
||||
|
||||
if (part == null) {
|
||||
IWorkbenchPage[] pages = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPages();
|
||||
IWorkbenchPage[] pages = PlatformUI.getWorkbench()
|
||||
.getActiveWorkbenchWindow().getPages();
|
||||
|
||||
if (pages.length == 0) {
|
||||
// TODO determine how to hide view if no pages found and part==null
|
||||
}
|
||||
|
||||
outerLoop: for(int i=0; i<pages.length; i++) {
|
||||
outerLoop: for (int i = 0; i < pages.length; i++) {
|
||||
IEditorReference[] editorRefs = pages[i].getEditorReferences();
|
||||
for (int j=0; j<editorRefs.length; j++) {
|
||||
for (int j = 0; j < editorRefs.length; j++) {
|
||||
part = editorRefs[j].getEditor(false);
|
||||
if (part instanceof CEditor) {
|
||||
// TODO set the language properly if implement the above TODO
|
||||
|
@ -348,16 +291,20 @@ public class DOMAST extends ViewPart {
|
|||
}
|
||||
}
|
||||
|
||||
if (PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() != null &&
|
||||
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor() != null)
|
||||
part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
|
||||
if (PlatformUI.getWorkbench().getActiveWorkbenchWindow()
|
||||
.getActivePage() != null
|
||||
&& PlatformUI.getWorkbench().getActiveWorkbenchWindow()
|
||||
.getActivePage().getActiveEditor() != null)
|
||||
part = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
|
||||
.getActivePage().getActiveEditor();
|
||||
}
|
||||
|
||||
viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
|
||||
drillDownAdapter = new DrillDownAdapter(viewer);
|
||||
|
||||
if (part instanceof CEditor)
|
||||
viewer.setContentProvider( new ViewContentProvider(((CEditor)part).getInputFile()) );
|
||||
viewer.setContentProvider(new ViewContentProvider(((CEditor) part)
|
||||
.getInputFile()));
|
||||
else
|
||||
viewer.setContentProvider(new ViewContentProvider(file));
|
||||
|
||||
|
@ -380,13 +327,16 @@ public class DOMAST extends ViewPart {
|
|||
public void menuAboutToShow(IMenuManager manager) {
|
||||
DOMAST.this.fillContextMenu(manager);
|
||||
IContributionItem[] items = manager.getItems();
|
||||
for (int i=0; i<items.length; i++) {
|
||||
if (items[i] instanceof ActionContributionItem &&
|
||||
(((ActionContributionItem)items[i]).getAction().getText().equals(OPEN_REFERENCES) ||
|
||||
((ActionContributionItem)items[i]).getAction().getText().equals(OPEN_DECLARATIONS) )) {
|
||||
if (viewer.getSelection() instanceof StructuredSelection &&
|
||||
((StructuredSelection)viewer.getSelection()).getFirstElement() instanceof TreeObject &&
|
||||
((TreeObject)((StructuredSelection)viewer.getSelection()).getFirstElement()).getNode() instanceof IASTName) {
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
if (items[i] instanceof ActionContributionItem
|
||||
&& (((ActionContributionItem) items[i]).getAction()
|
||||
.getText().equals(OPEN_REFERENCES) || ((ActionContributionItem) items[i])
|
||||
.getAction().getText().equals(OPEN_DECLARATIONS))) {
|
||||
if (viewer.getSelection() instanceof StructuredSelection
|
||||
&& ((StructuredSelection) viewer.getSelection())
|
||||
.getFirstElement() instanceof TreeObject
|
||||
&& ((TreeObject) ((StructuredSelection) viewer
|
||||
.getSelection()).getFirstElement()).getNode() instanceof IASTName) {
|
||||
items[i].setVisible(true);
|
||||
} else {
|
||||
items[i].setVisible(false);
|
||||
|
@ -407,12 +357,12 @@ public class DOMAST extends ViewPart {
|
|||
}
|
||||
|
||||
private void fillLocalPullDown(IMenuManager manager) {
|
||||
// manager.add(action1); // TODO determine the groups/filters to use
|
||||
// manager.add(new Separator());
|
||||
// manager.add(action2);
|
||||
// manager.add(action1); // TODO determine the groups/filters to use
|
||||
// manager.add(new Separator());
|
||||
// manager.add(action2);
|
||||
}
|
||||
|
||||
private void fillContextMenu(IMenuManager manager) {
|
||||
void fillContextMenu(IMenuManager manager) {
|
||||
manager.add(action1);
|
||||
manager.add(action2);
|
||||
manager.add(new Separator());
|
||||
|
@ -439,21 +389,23 @@ public class DOMAST extends ViewPart {
|
|||
|
||||
action1 = new Action() {
|
||||
public void run() {
|
||||
showMessage("Action 1 executed"); // TODO open declarations action ... use annotations
|
||||
showMessage("Action 1 executed"); // TODO open declarations action
|
||||
// ... use annotations
|
||||
}
|
||||
};
|
||||
action1.setText(OPEN_DECLARATIONS);
|
||||
action1.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
|
||||
getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
|
||||
action1.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages()
|
||||
.getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
|
||||
|
||||
action2 = new Action() {
|
||||
public void run() {
|
||||
showMessage("Action 2 executed"); // TODO open references action ... use annotations
|
||||
showMessage("Action 2 executed"); // TODO open references action ...
|
||||
// use annotations
|
||||
}
|
||||
};
|
||||
action2.setText(OPEN_REFERENCES);
|
||||
action2.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
|
||||
getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
|
||||
action2.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages()
|
||||
.getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
|
||||
|
||||
singleClickAction = new ASTHighlighterAction(part);
|
||||
}
|
||||
|
@ -469,52 +421,96 @@ public class DOMAST extends ViewPart {
|
|||
this.aPart = part;
|
||||
}
|
||||
|
||||
protected boolean open(String filename) throws PartInitException,
|
||||
CModelException {
|
||||
IPath path = new Path(filename);
|
||||
IFile f = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(
|
||||
path);
|
||||
if (f != null) {
|
||||
EditorUtility.openInEditor(f);
|
||||
return true;
|
||||
}
|
||||
|
||||
FileStorage storage = new FileStorage(null, path);
|
||||
EditorUtility.openInEditor(storage);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
ISelection selection = viewer.getSelection();
|
||||
Object obj = ((IStructuredSelection)selection).getFirstElement();
|
||||
Object obj = ((IStructuredSelection) selection).getFirstElement();
|
||||
if (aPart instanceof CEditor && obj instanceof TreeObject) {
|
||||
((CEditor)aPart).selectAndReveal(((TreeObject)obj).getOffset(), ((TreeObject)obj).getLength());
|
||||
String filename = ((TreeObject) obj).getFilename();
|
||||
IResource r = ParserUtil.getResourceForFilename(filename);
|
||||
if (r != null) {
|
||||
try {
|
||||
aPart = EditorUtility.openInEditor(r);
|
||||
} catch (PartInitException pie) {
|
||||
return;
|
||||
} catch (CModelException e) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
IPath path = new Path( filename );
|
||||
FileStorage storage = new FileStorage(null, path);
|
||||
try {
|
||||
aPart = EditorUtility.openInEditor(storage);
|
||||
} catch (PartInitException e) {
|
||||
return;
|
||||
} catch (CModelException e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
((CEditor) aPart).selectAndReveal(((TreeObject) obj).getOffset(),
|
||||
((TreeObject) obj).getLength());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO need to create a new action with the following for annotations (get declarations/references)
|
||||
// ISelection selection = viewer.getSelection();
|
||||
// Object obj = ((IStructuredSelection)selection).getFirstElement();
|
||||
//
|
||||
// if (aPart instanceof CEditor) {
|
||||
// IAnnotationModel aModel = ((CEditor)aPart).getDocumentProvider().getAnnotationModel(aPart.getEditorInput());
|
||||
// if ( aModel != null && obj instanceof TreeObject && !(((TreeObject)obj).getNode() instanceof IASTTranslationUnit) ) {
|
||||
// Iterator itr = aModel.getAnnotationIterator();
|
||||
// while (itr.hasNext()) {
|
||||
// aModel.removeAnnotation((Annotation)itr.next());
|
||||
// }
|
||||
//
|
||||
// ASTViewAnnotation annotation = new ASTViewAnnotation();
|
||||
// annotation.setType(CMarkerAnnotation.WARNING_ANNOTATION_TYPE);
|
||||
// aModel.addAnnotation(annotation, new Position(((TreeObject)obj).getOffset(), ((TreeObject)obj).getLength()));
|
||||
// }
|
||||
// }
|
||||
|
||||
// TODO need to create a new action with the following for annotations (get
|
||||
// declarations/references)
|
||||
// ISelection selection = viewer.getSelection();
|
||||
// Object obj = ((IStructuredSelection)selection).getFirstElement();
|
||||
//
|
||||
// if (aPart instanceof CEditor) {
|
||||
// IAnnotationModel aModel =
|
||||
// ((CEditor)aPart).getDocumentProvider().getAnnotationModel(aPart.getEditorInput());
|
||||
// if ( aModel != null && obj instanceof TreeObject &&
|
||||
// !(((TreeObject)obj).getNode() instanceof IASTTranslationUnit) ) {
|
||||
// Iterator itr = aModel.getAnnotationIterator();
|
||||
// while (itr.hasNext()) {
|
||||
// aModel.removeAnnotation((Annotation)itr.next());
|
||||
// }
|
||||
//
|
||||
// ASTViewAnnotation annotation = new ASTViewAnnotation();
|
||||
// annotation.setType(CMarkerAnnotation.WARNING_ANNOTATION_TYPE);
|
||||
// aModel.addAnnotation(annotation, new
|
||||
// Position(((TreeObject)obj).getOffset(), ((TreeObject)obj).getLength()));
|
||||
// }
|
||||
// }
|
||||
|
||||
// TODO implement annotation for things like open declarations/references
|
||||
// private class ASTViewAnnotation extends Annotation implements IAnnotationPresentation {
|
||||
//
|
||||
// /* (non-Javadoc)
|
||||
// * @see org.eclipse.jface.text.source.IAnnotationPresentation#getLayer()
|
||||
// */
|
||||
// public int getLayer() {
|
||||
// return IAnnotationAccessExtension.DEFAULT_LAYER;
|
||||
// }
|
||||
//
|
||||
// /* (non-Javadoc)
|
||||
// * @see org.eclipse.jface.text.source.IAnnotationPresentation#paint(org.eclipse.swt.graphics.GC, org.eclipse.swt.widgets.Canvas, org.eclipse.swt.graphics.Rectangle)
|
||||
// */
|
||||
// public void paint(GC gc, Canvas canvas, Rectangle r) {
|
||||
// // TODO implement this annotation image for
|
||||
// ImageUtilities.drawImage(ASTViewPluginImages.get(ASTViewPluginImages.IMG_TO_DRAW), gc, canvas, r, SWT.CENTER, SWT.TOP);
|
||||
// }
|
||||
// }
|
||||
// private class ASTViewAnnotation extends Annotation implements
|
||||
// IAnnotationPresentation {
|
||||
//
|
||||
// /* (non-Javadoc)
|
||||
// * @see org.eclipse.jface.text.source.IAnnotationPresentation#getLayer()
|
||||
// */
|
||||
// public int getLayer() {
|
||||
// return IAnnotationAccessExtension.DEFAULT_LAYER;
|
||||
// }
|
||||
//
|
||||
// /* (non-Javadoc)
|
||||
// * @see
|
||||
// org.eclipse.jface.text.source.IAnnotationPresentation#paint(org.eclipse.swt.graphics.GC,
|
||||
// org.eclipse.swt.widgets.Canvas, org.eclipse.swt.graphics.Rectangle)
|
||||
// */
|
||||
// public void paint(GC gc, Canvas canvas, Rectangle r) {
|
||||
// // TODO implement this annotation image for
|
||||
// ImageUtilities.drawImage(ASTViewPluginImages.get(ASTViewPluginImages.IMG_TO_DRAW),
|
||||
// gc, canvas, r, SWT.CENTER, SWT.TOP);
|
||||
// }
|
||||
// }
|
||||
|
||||
private void hookSingleClickAction() {
|
||||
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
|
||||
|
@ -524,10 +520,9 @@ public class DOMAST extends ViewPart {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void showMessage(String message) {
|
||||
MessageDialog.openInformation(
|
||||
viewer.getControl().getShell(),
|
||||
VIEW_NAME,
|
||||
MessageDialog.openInformation(viewer.getControl().getShell(), VIEW_NAME,
|
||||
message);
|
||||
}
|
||||
|
||||
|
@ -547,7 +542,7 @@ public class DOMAST extends ViewPart {
|
|||
this.part = part;
|
||||
|
||||
if (singleClickAction instanceof ASTHighlighterAction)
|
||||
((ASTHighlighterAction)singleClickAction).setPart(part);
|
||||
((ASTHighlighterAction) singleClickAction).setPart(part);
|
||||
}
|
||||
|
||||
public void setLang(ParserLanguage lang) {
|
||||
|
|
|
@ -10,8 +10,10 @@
|
|||
**********************************************************************/
|
||||
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.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||
import org.eclipse.core.runtime.IAdaptable;
|
||||
|
||||
|
@ -57,6 +59,7 @@ public class TreeObject implements IAdaptable {
|
|||
}
|
||||
|
||||
public String toString() {
|
||||
if( node == null ) return ""; //$NON-NLS-1$ //TODO Devin is this the best way???
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
|
||||
Class[] classes = node.getClass().getInterfaces();
|
||||
|
@ -80,17 +83,25 @@ public class TreeObject implements IAdaptable {
|
|||
return null;
|
||||
}
|
||||
|
||||
public int getOffset() {
|
||||
if (node instanceof ASTNode)
|
||||
return ((ASTNode)node).getOffset();
|
||||
public String getFilename()
|
||||
{
|
||||
IASTNodeLocation [] location = node.getNodeLocations();
|
||||
if( location[0] instanceof IASTFileLocation )
|
||||
return ((IASTFileLocation)location[0]).getFileName();
|
||||
return ""; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public int getOffset() {
|
||||
IASTNodeLocation [] location = node.getNodeLocations();
|
||||
if( location.length == 1 )
|
||||
return location[0].getNodeOffset();
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int getLength() {
|
||||
if (node instanceof ASTNode)
|
||||
return ((ASTNode)node).getLength();
|
||||
|
||||
IASTNodeLocation [] location = node.getNodeLocations();
|
||||
if( location.length == 1 )
|
||||
return location[0].getNodeLength();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue