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.IASTCompoundStatement;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
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.IASTFileLocation;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
|
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
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$
|
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.setParent(result);
|
||||||
name.setPropertyInParent(IASTElaboratedTypeSpecifier.TYPE_NAME);
|
name.setPropertyInParent(IASTElaboratedTypeSpecifier.TYPE_NAME);
|
||||||
result.setKind(eck);
|
result.setKind(eck);
|
||||||
|
((ASTNode)result).setOffsetAndLength( t.getOffset(), calculateEndOffset(name) - t.getOffset() );
|
||||||
return result;
|
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.GNUCSourceParser;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.c.ICParserExtensionConfiguration;
|
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.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.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.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.IFile;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
|
@ -50,6 +55,8 @@ import org.eclipse.core.runtime.CoreException;
|
||||||
*/
|
*/
|
||||||
public class InternalASTServiceProvider implements IASTServiceProvider {
|
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$
|
private static final String[] dialects = { "C99", //$NON-NLS-1$
|
||||||
"C++98", //$NON-NLS-1$
|
"C++98", //$NON-NLS-1$
|
||||||
"GNUC", //$NON-NLS-1$
|
"GNUC", //$NON-NLS-1$
|
||||||
|
@ -110,9 +117,14 @@ public class InternalASTServiceProvider implements IASTServiceProvider {
|
||||||
if( configuration == null )
|
if( configuration == null )
|
||||||
{
|
{
|
||||||
ParserLanguage l = getLanguage(fileToParse);
|
ParserLanguage l = getLanguage(fileToParse);
|
||||||
scanner = ParserFactory.createScanner(reader, scanInfo, ParserMode.COMPLETE_PARSE,
|
IScannerExtensionConfiguration scannerExtensionConfiguration = null;
|
||||||
l, NULL_REQUESTOR,
|
if( l == ParserLanguage.CPP )
|
||||||
ParserUtil.getScannerLogService(), Collections.EMPTY_LIST);
|
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
|
//assume GCC
|
||||||
if( l == ParserLanguage.C )
|
if( l == ParserLanguage.C )
|
||||||
parser = new GNUCSourceParser( scanner, ParserMode.COMPLETE_PARSE, ParserUtil.getParserLogService(), new GCCParserExtensionConfiguration() );
|
parser = new GNUCSourceParser( scanner, ParserMode.COMPLETE_PARSE, ParserUtil.getParserLogService(), new GCCParserExtensionConfiguration() );
|
||||||
|
|
|
@ -10,36 +10,8 @@
|
||||||
**********************************************************************/
|
**********************************************************************/
|
||||||
package org.eclipse.cdt.ui.tests.DOMAST;
|
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.CDOM;
|
||||||
|
import org.eclipse.cdt.core.dom.IASTServiceProvider;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
|
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
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.c.ICASTDesignator;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter;
|
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;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction;
|
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;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction;
|
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.editor.CEditor;
|
||||||
|
import org.eclipse.cdt.internal.ui.util.EditorUtility;
|
||||||
import org.eclipse.core.resources.IFile;
|
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
|
* This sample class demonstrates how to plug-in a new workbench view. The view
|
||||||
* workbench view. The view shows data obtained from the
|
* shows data obtained from the model. The sample creates a dummy model on the
|
||||||
* model. The sample creates a dummy model on the fly,
|
* fly, but a real implementation would connect to the model available either in
|
||||||
* but a real implementation would connect to the model
|
* this or another plug-in (e.g. the workspace). The view is connected to the
|
||||||
* available either in this or another plug-in (e.g. the workspace).
|
* model using a content provider.
|
||||||
* The view is connected to the model using a content provider.
|
|
||||||
* <p>
|
* <p>
|
||||||
* The view uses a label provider to define how model
|
* The view uses a label provider to define how model objects should be
|
||||||
* objects should be presented in the view. Each
|
* presented in the view. Each view can present the same model objects using
|
||||||
* view can present the same model objects using
|
* different labels and icons, if needed. Alternatively, a single label provider
|
||||||
* different labels and icons, if needed. Alternatively,
|
* can be shared between views in order to ensure that objects of the same type
|
||||||
* a single label provider can be shared between views
|
* are presented in the same way everywhere.
|
||||||
* in order to ensure that objects of the same type are
|
|
||||||
* presented in the same way everywhere.
|
|
||||||
* <p>
|
* <p>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -102,7 +103,7 @@ public class DOMAST extends ViewPart {
|
||||||
private static final String POPUPMENU = "#PopupMenu"; //$NON-NLS-1$
|
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_DECLARATIONS = "Open Declarations"; //$NON-NLS-1$
|
||||||
private static final String OPEN_REFERENCES = "Open References"; //$NON-NLS-1$
|
private static final String OPEN_REFERENCES = "Open References"; //$NON-NLS-1$
|
||||||
private TreeViewer viewer;
|
TreeViewer viewer;
|
||||||
private DrillDownAdapter drillDownAdapter;
|
private DrillDownAdapter drillDownAdapter;
|
||||||
private Action action1;
|
private Action action1;
|
||||||
private Action action2;
|
private Action action2;
|
||||||
|
@ -113,13 +114,10 @@ public class DOMAST extends ViewPart {
|
||||||
ParserLanguage lang = null;
|
ParserLanguage lang = null;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The content provider class is responsible for
|
* The content provider class is responsible for providing objects to the
|
||||||
* providing objects to the view. It can wrap
|
* view. It can wrap existing objects in adapters or simply return objects
|
||||||
* existing objects in adapters or simply return
|
* as-is. These objects may be sensitive to the current input of the view, or
|
||||||
* objects as-is. These objects may be sensitive
|
* ignore it and always show the same content (like Task List, for example).
|
||||||
* 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,
|
public class ViewContentProvider implements IStructuredContentProvider,
|
||||||
|
@ -130,7 +128,8 @@ public class DOMAST extends ViewPart {
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public ViewContentProvider() {}
|
public ViewContentProvider() {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -141,27 +140,33 @@ public class DOMAST extends ViewPart {
|
||||||
|
|
||||||
public void inputChanged(Viewer v, Object oldInput, Object newInput) {
|
public void inputChanged(Viewer v, Object oldInput, Object newInput) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object[] getElements(Object parent) {
|
public Object[] getElements(Object parent) {
|
||||||
if (parent.equals(getViewSite())) {
|
if (parent.equals(getViewSite())) {
|
||||||
if (invisibleRoot==null) initialize();
|
if (invisibleRoot == null)
|
||||||
|
initialize();
|
||||||
return getChildren(invisibleRoot);
|
return getChildren(invisibleRoot);
|
||||||
}
|
}
|
||||||
return getChildren(parent);
|
return getChildren(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object getParent(Object child) {
|
public Object getParent(Object child) {
|
||||||
if (child instanceof TreeObject) {
|
if (child instanceof TreeObject) {
|
||||||
return ((TreeObject) child).getParent();
|
return ((TreeObject) child).getParent();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object[] getChildren(Object parent) {
|
public Object[] getChildren(Object parent) {
|
||||||
if (parent instanceof TreeParent) {
|
if (parent instanceof TreeParent) {
|
||||||
return ((TreeParent) parent).getChildren();
|
return ((TreeParent) parent).getChildren();
|
||||||
}
|
}
|
||||||
return new Object[0];
|
return new Object[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasChildren(Object parent) {
|
public boolean hasChildren(Object parent) {
|
||||||
if (parent instanceof TreeParent)
|
if (parent instanceof TreeParent)
|
||||||
return ((TreeParent) parent).hasChildren();
|
return ((TreeParent) parent).hasChildren();
|
||||||
|
@ -169,94 +174,29 @@ public class DOMAST extends ViewPart {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initialize() {
|
private void initialize() {
|
||||||
if ( aFile == null || lang == null) return;
|
if (aFile == null || lang == null)
|
||||||
|
return;
|
||||||
|
|
||||||
IPopulateDOMASTAction action = null;
|
IPopulateDOMASTAction action = null;
|
||||||
|
IASTTranslationUnit tu = 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;
|
|
||||||
try {
|
try {
|
||||||
// if( workingCopy == null )
|
tu = CDOM.getInstance().getDefaultASTService().getTranslationUnit(
|
||||||
reader = new CodeReader(aFile.getLocation().toOSString(), aFile.getCharset() );
|
aFile,
|
||||||
// else
|
CDOM.getInstance().getCodeReaderFactory(
|
||||||
// reader = new CodeReader(aFile.getLocation().toOSString(), workingCopy.getContents());
|
CDOM.PARSE_SAVED_RESOURCES));
|
||||||
} catch (IOException e) {
|
} catch (IASTServiceProvider.UnsupportedDialectException e) {
|
||||||
e.printStackTrace();
|
return;
|
||||||
} catch ( CoreException e ) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
if (lang == ParserLanguage.CPP) {
|
||||||
// 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();
|
|
||||||
|
|
||||||
action = new CPPPopulateASTViewAction(tu);
|
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
|
// display roots
|
||||||
invisibleRoot = new TreeParent(null); //$NON-NLS-1$
|
invisibleRoot = new TreeParent(null); //$NON-NLS-1$
|
||||||
invisibleRoot.addChild(action.getTree());
|
invisibleRoot.addChild(action.getTree());
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -265,6 +205,7 @@ public class DOMAST extends ViewPart {
|
||||||
public String getText(Object obj) {
|
public String getText(Object obj) {
|
||||||
return obj.toString();
|
return obj.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Image getImage(Object obj) {
|
public Image getImage(Object obj) {
|
||||||
String imageKey = DOMASTPluginImages.IMG_DEFAULT;
|
String imageKey = DOMASTPluginImages.IMG_DEFAULT;
|
||||||
|
|
||||||
|
@ -316,6 +257,7 @@ public class DOMAST extends ViewPart {
|
||||||
return DOMASTPluginImages.get(imageKey);
|
return DOMASTPluginImages.get(imageKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class NameSorter extends ViewerSorter {
|
class NameSorter extends ViewerSorter {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -324,13 +266,14 @@ public class DOMAST extends ViewPart {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is a callback that will allow us
|
* This is a callback that will allow us to create the viewer and initialize
|
||||||
* to create the viewer and initialize it.
|
* it.
|
||||||
*/
|
*/
|
||||||
public void createPartControl(Composite parent) {
|
public void createPartControl(Composite parent) {
|
||||||
|
|
||||||
if (part == null) {
|
if (part == null) {
|
||||||
IWorkbenchPage[] pages = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPages();
|
IWorkbenchPage[] pages = PlatformUI.getWorkbench()
|
||||||
|
.getActiveWorkbenchWindow().getPages();
|
||||||
|
|
||||||
if (pages.length == 0) {
|
if (pages.length == 0) {
|
||||||
// TODO determine how to hide view if no pages found and part==null
|
// TODO determine how to hide view if no pages found and part==null
|
||||||
|
@ -348,16 +291,20 @@ public class DOMAST extends ViewPart {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() != null &&
|
if (PlatformUI.getWorkbench().getActiveWorkbenchWindow()
|
||||||
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor() != null)
|
.getActivePage() != null
|
||||||
part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
|
&& PlatformUI.getWorkbench().getActiveWorkbenchWindow()
|
||||||
|
.getActivePage().getActiveEditor() != null)
|
||||||
|
part = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
|
||||||
|
.getActivePage().getActiveEditor();
|
||||||
}
|
}
|
||||||
|
|
||||||
viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
|
viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
|
||||||
drillDownAdapter = new DrillDownAdapter(viewer);
|
drillDownAdapter = new DrillDownAdapter(viewer);
|
||||||
|
|
||||||
if (part instanceof CEditor)
|
if (part instanceof CEditor)
|
||||||
viewer.setContentProvider( new ViewContentProvider(((CEditor)part).getInputFile()) );
|
viewer.setContentProvider(new ViewContentProvider(((CEditor) part)
|
||||||
|
.getInputFile()));
|
||||||
else
|
else
|
||||||
viewer.setContentProvider(new ViewContentProvider(file));
|
viewer.setContentProvider(new ViewContentProvider(file));
|
||||||
|
|
||||||
|
@ -381,12 +328,15 @@ public class DOMAST extends ViewPart {
|
||||||
DOMAST.this.fillContextMenu(manager);
|
DOMAST.this.fillContextMenu(manager);
|
||||||
IContributionItem[] items = manager.getItems();
|
IContributionItem[] items = manager.getItems();
|
||||||
for (int i = 0; i < items.length; i++) {
|
for (int i = 0; i < items.length; i++) {
|
||||||
if (items[i] instanceof ActionContributionItem &&
|
if (items[i] instanceof ActionContributionItem
|
||||||
(((ActionContributionItem)items[i]).getAction().getText().equals(OPEN_REFERENCES) ||
|
&& (((ActionContributionItem) items[i]).getAction()
|
||||||
((ActionContributionItem)items[i]).getAction().getText().equals(OPEN_DECLARATIONS) )) {
|
.getText().equals(OPEN_REFERENCES) || ((ActionContributionItem) items[i])
|
||||||
if (viewer.getSelection() instanceof StructuredSelection &&
|
.getAction().getText().equals(OPEN_DECLARATIONS))) {
|
||||||
((StructuredSelection)viewer.getSelection()).getFirstElement() instanceof TreeObject &&
|
if (viewer.getSelection() instanceof StructuredSelection
|
||||||
((TreeObject)((StructuredSelection)viewer.getSelection()).getFirstElement()).getNode() instanceof IASTName) {
|
&& ((StructuredSelection) viewer.getSelection())
|
||||||
|
.getFirstElement() instanceof TreeObject
|
||||||
|
&& ((TreeObject) ((StructuredSelection) viewer
|
||||||
|
.getSelection()).getFirstElement()).getNode() instanceof IASTName) {
|
||||||
items[i].setVisible(true);
|
items[i].setVisible(true);
|
||||||
} else {
|
} else {
|
||||||
items[i].setVisible(false);
|
items[i].setVisible(false);
|
||||||
|
@ -412,7 +362,7 @@ public class DOMAST extends ViewPart {
|
||||||
// manager.add(action2);
|
// manager.add(action2);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fillContextMenu(IMenuManager manager) {
|
void fillContextMenu(IMenuManager manager) {
|
||||||
manager.add(action1);
|
manager.add(action1);
|
||||||
manager.add(action2);
|
manager.add(action2);
|
||||||
manager.add(new Separator());
|
manager.add(new Separator());
|
||||||
|
@ -439,21 +389,23 @@ public class DOMAST extends ViewPart {
|
||||||
|
|
||||||
action1 = new Action() {
|
action1 = new Action() {
|
||||||
public void run() {
|
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.setText(OPEN_DECLARATIONS);
|
||||||
action1.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
|
action1.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages()
|
||||||
getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
|
.getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
|
||||||
|
|
||||||
action2 = new Action() {
|
action2 = new Action() {
|
||||||
public void run() {
|
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.setText(OPEN_REFERENCES);
|
||||||
action2.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
|
action2.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages()
|
||||||
getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
|
.getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
|
||||||
|
|
||||||
singleClickAction = new ASTHighlighterAction(part);
|
singleClickAction = new ASTHighlighterAction(part);
|
||||||
}
|
}
|
||||||
|
@ -469,22 +421,62 @@ public class DOMAST extends ViewPart {
|
||||||
this.aPart = part;
|
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() {
|
public void run() {
|
||||||
ISelection selection = viewer.getSelection();
|
ISelection selection = viewer.getSelection();
|
||||||
Object obj = ((IStructuredSelection) selection).getFirstElement();
|
Object obj = ((IStructuredSelection) selection).getFirstElement();
|
||||||
if (aPart instanceof CEditor && obj instanceof TreeObject) {
|
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)
|
// TODO need to create a new action with the following for annotations (get
|
||||||
|
// declarations/references)
|
||||||
// ISelection selection = viewer.getSelection();
|
// ISelection selection = viewer.getSelection();
|
||||||
// Object obj = ((IStructuredSelection)selection).getFirstElement();
|
// Object obj = ((IStructuredSelection)selection).getFirstElement();
|
||||||
//
|
//
|
||||||
// if (aPart instanceof CEditor) {
|
// if (aPart instanceof CEditor) {
|
||||||
// IAnnotationModel aModel = ((CEditor)aPart).getDocumentProvider().getAnnotationModel(aPart.getEditorInput());
|
// IAnnotationModel aModel =
|
||||||
// if ( aModel != null && obj instanceof TreeObject && !(((TreeObject)obj).getNode() instanceof IASTTranslationUnit) ) {
|
// ((CEditor)aPart).getDocumentProvider().getAnnotationModel(aPart.getEditorInput());
|
||||||
|
// if ( aModel != null && obj instanceof TreeObject &&
|
||||||
|
// !(((TreeObject)obj).getNode() instanceof IASTTranslationUnit) ) {
|
||||||
// Iterator itr = aModel.getAnnotationIterator();
|
// Iterator itr = aModel.getAnnotationIterator();
|
||||||
// while (itr.hasNext()) {
|
// while (itr.hasNext()) {
|
||||||
// aModel.removeAnnotation((Annotation)itr.next());
|
// aModel.removeAnnotation((Annotation)itr.next());
|
||||||
|
@ -492,13 +484,14 @@ public class DOMAST extends ViewPart {
|
||||||
//
|
//
|
||||||
// ASTViewAnnotation annotation = new ASTViewAnnotation();
|
// ASTViewAnnotation annotation = new ASTViewAnnotation();
|
||||||
// annotation.setType(CMarkerAnnotation.WARNING_ANNOTATION_TYPE);
|
// annotation.setType(CMarkerAnnotation.WARNING_ANNOTATION_TYPE);
|
||||||
// aModel.addAnnotation(annotation, new Position(((TreeObject)obj).getOffset(), ((TreeObject)obj).getLength()));
|
// aModel.addAnnotation(annotation, new
|
||||||
|
// Position(((TreeObject)obj).getOffset(), ((TreeObject)obj).getLength()));
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
// TODO implement annotation for things like open declarations/references
|
// TODO implement annotation for things like open declarations/references
|
||||||
// private class ASTViewAnnotation extends Annotation implements IAnnotationPresentation {
|
// private class ASTViewAnnotation extends Annotation implements
|
||||||
|
// IAnnotationPresentation {
|
||||||
//
|
//
|
||||||
// /* (non-Javadoc)
|
// /* (non-Javadoc)
|
||||||
// * @see org.eclipse.jface.text.source.IAnnotationPresentation#getLayer()
|
// * @see org.eclipse.jface.text.source.IAnnotationPresentation#getLayer()
|
||||||
|
@ -508,11 +501,14 @@ public class DOMAST extends ViewPart {
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// /* (non-Javadoc)
|
// /* (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)
|
// * @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) {
|
// public void paint(GC gc, Canvas canvas, Rectangle r) {
|
||||||
// // TODO implement this annotation image for
|
// // TODO implement this annotation image for
|
||||||
// ImageUtilities.drawImage(ASTViewPluginImages.get(ASTViewPluginImages.IMG_TO_DRAW), gc, canvas, r, SWT.CENTER, SWT.TOP);
|
// ImageUtilities.drawImage(ASTViewPluginImages.get(ASTViewPluginImages.IMG_TO_DRAW),
|
||||||
|
// gc, canvas, r, SWT.CENTER, SWT.TOP);
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
@ -524,10 +520,9 @@ public class DOMAST extends ViewPart {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showMessage(String message) {
|
private void showMessage(String message) {
|
||||||
MessageDialog.openInformation(
|
MessageDialog.openInformation(viewer.getControl().getShell(), VIEW_NAME,
|
||||||
viewer.getControl().getShell(),
|
|
||||||
VIEW_NAME,
|
|
||||||
message);
|
message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,8 +10,10 @@
|
||||||
**********************************************************************/
|
**********************************************************************/
|
||||||
package org.eclipse.cdt.ui.tests.DOMAST;
|
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.IASTName;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
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.cdt.internal.core.dom.parser.ASTNode;
|
||||||
import org.eclipse.core.runtime.IAdaptable;
|
import org.eclipse.core.runtime.IAdaptable;
|
||||||
|
|
||||||
|
@ -57,6 +59,7 @@ public class TreeObject implements IAdaptable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
if( node == null ) return ""; //$NON-NLS-1$ //TODO Devin is this the best way???
|
||||||
StringBuffer buffer = new StringBuffer();
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
|
||||||
Class[] classes = node.getClass().getInterfaces();
|
Class[] classes = node.getClass().getInterfaces();
|
||||||
|
@ -80,17 +83,25 @@ public class TreeObject implements IAdaptable {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getOffset() {
|
public String getFilename()
|
||||||
if (node instanceof ASTNode)
|
{
|
||||||
return ((ASTNode)node).getOffset();
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getLength() {
|
public int getLength() {
|
||||||
if (node instanceof ASTNode)
|
IASTNodeLocation [] location = node.getNodeLocations();
|
||||||
return ((ASTNode)node).getLength();
|
if( location.length == 1 )
|
||||||
|
return location[0].getNodeLength();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue