mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 17:56:01 +02:00
Patch from Mike for Bug 174486
This commit is contained in:
parent
b4340ada20
commit
ac5bca2e7b
3 changed files with 83 additions and 128 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2005, 2006 IBM Corporation and others.
|
* Copyright (c) 2005, 2007 IBM Corporation and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -11,15 +11,14 @@
|
||||||
package org.eclipse.cdt.ui.tests.DOMAST;
|
package org.eclipse.cdt.ui.tests.DOMAST;
|
||||||
|
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.IProject;
|
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
import org.eclipse.core.resources.ResourcesPlugin;
|
import org.eclipse.core.resources.ResourcesPlugin;
|
||||||
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IPath;
|
import org.eclipse.core.runtime.IPath;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
import org.eclipse.core.runtime.IStatus;
|
import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.core.runtime.Path;
|
import org.eclipse.core.runtime.Path;
|
||||||
import org.eclipse.core.runtime.Status;
|
import org.eclipse.core.runtime.Status;
|
||||||
import org.eclipse.core.runtime.content.IContentType;
|
|
||||||
import org.eclipse.core.runtime.jobs.ISchedulingRule;
|
import org.eclipse.core.runtime.jobs.ISchedulingRule;
|
||||||
import org.eclipse.core.runtime.jobs.Job;
|
import org.eclipse.core.runtime.jobs.Job;
|
||||||
import org.eclipse.jface.action.Action;
|
import org.eclipse.jface.action.Action;
|
||||||
|
@ -63,9 +62,6 @@ import org.eclipse.ui.part.ViewPart;
|
||||||
import org.eclipse.ui.texteditor.AbstractTextEditor;
|
import org.eclipse.ui.texteditor.AbstractTextEditor;
|
||||||
import org.eclipse.ui.views.properties.PropertySheet;
|
import org.eclipse.ui.views.properties.PropertySheet;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
|
||||||
import org.eclipse.cdt.core.dom.CDOM;
|
|
||||||
import org.eclipse.cdt.core.dom.IASTServiceProvider;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTSignatureUtil;
|
import org.eclipse.cdt.core.dom.ast.ASTSignatureUtil;
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
|
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
|
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
|
||||||
|
@ -96,17 +92,16 @@ import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||||
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.core.model.CModelException;
|
import org.eclipse.cdt.core.model.CModelException;
|
||||||
import org.eclipse.cdt.core.model.CoreModel;
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
import org.eclipse.cdt.core.model.ICProject;
|
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
|
||||||
import org.eclipse.cdt.core.parser.ParserUtil;
|
import org.eclipse.cdt.core.parser.ParserUtil;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTEnumerator;
|
import org.eclipse.cdt.core.parser.ast.IASTEnumerator;
|
||||||
import org.eclipse.cdt.core.resources.FileStorage;
|
import org.eclipse.cdt.core.resources.FileStorage;
|
||||||
import org.eclipse.cdt.ui.actions.CustomFiltersActionGroup;
|
import org.eclipse.cdt.ui.actions.CustomFiltersActionGroup;
|
||||||
import org.eclipse.cdt.ui.testplugin.CTestPlugin;
|
import org.eclipse.cdt.ui.testplugin.CTestPlugin;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.core.model.CProject;
|
import org.eclipse.cdt.internal.core.dom.parser.c.CASTTranslationUnit;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTranslationUnit;
|
||||||
|
|
||||||
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.cdt.internal.ui.util.EditorUtility;
|
||||||
|
@ -157,9 +152,9 @@ public class DOMAST extends ViewPart {
|
||||||
private Action collapseAllAction;
|
private Action collapseAllAction;
|
||||||
private Action clearAction;
|
private Action clearAction;
|
||||||
private Action searchNamesAction;
|
private Action searchNamesAction;
|
||||||
protected IFile file = null;
|
|
||||||
|
protected ITranslationUnit tu = null;
|
||||||
private IEditorPart part = null;
|
private IEditorPart part = null;
|
||||||
protected ParserLanguage lang = null;
|
|
||||||
|
|
||||||
private CustomFiltersActionGroup customFiltersActionGroup;
|
private CustomFiltersActionGroup customFiltersActionGroup;
|
||||||
|
|
||||||
|
@ -183,12 +178,12 @@ public class DOMAST extends ViewPart {
|
||||||
public ViewContentProvider() {
|
public ViewContentProvider() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ViewContentProvider(IFile file) {
|
public ViewContentProvider(ITranslationUnit tu) {
|
||||||
this(file, null);
|
this(tu, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ViewContentProvider(IFile file, Object[] expanded) {
|
public ViewContentProvider(ITranslationUnit tu, Object[] expanded) {
|
||||||
initializeASTViewJob = new StartInitializingASTView(new InitializeView(POPULATING_AST_VIEW, this, viewer, file), expanded);
|
initializeASTViewJob = new StartInitializingASTView(new InitializeView(POPULATING_AST_VIEW, this, viewer, tu), expanded);
|
||||||
initializeASTViewJob.schedule();
|
initializeASTViewJob.schedule();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -218,10 +213,6 @@ public class DOMAST extends ViewPart {
|
||||||
return tu;
|
return tu;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ParserLanguage getTULanguage() {
|
|
||||||
return lang;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -326,18 +317,18 @@ public class DOMAST extends ViewPart {
|
||||||
DOMASTNodeParent root = null;
|
DOMASTNodeParent root = null;
|
||||||
ViewContentProvider provider = null;
|
ViewContentProvider provider = null;
|
||||||
TreeViewer view = null;
|
TreeViewer view = null;
|
||||||
IFile aFile = null;
|
ITranslationUnit tu = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param name
|
* @param name
|
||||||
*/
|
*/
|
||||||
public InitializeView(String name, ViewContentProvider provider, TreeViewer view, IFile file) {
|
public InitializeView(String name, ViewContentProvider provider, TreeViewer view, ITranslationUnit tu) {
|
||||||
super(name);
|
super(name);
|
||||||
this.name = name;
|
this.name = name;
|
||||||
setUser(true);
|
setUser(true);
|
||||||
this.provider = provider;
|
this.provider = provider;
|
||||||
this.view = view;
|
this.view = view;
|
||||||
this.aFile = file;
|
this.tu = tu;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DOMASTNodeParent getInvisibleRoot() {
|
public DOMASTNodeParent getInvisibleRoot() {
|
||||||
|
@ -358,35 +349,35 @@ public class DOMAST extends ViewPart {
|
||||||
long start=0;
|
long start=0;
|
||||||
long overallStart=System.currentTimeMillis();
|
long overallStart=System.currentTimeMillis();
|
||||||
|
|
||||||
if (aFile == null || lang == null || monitor == null)
|
if (tu == null || monitor == null)
|
||||||
return Status.CANCEL_STATUS;
|
return Status.CANCEL_STATUS;
|
||||||
|
|
||||||
if (monitor.isCanceled()) return Status.CANCEL_STATUS;
|
if (monitor.isCanceled()) return Status.CANCEL_STATUS;
|
||||||
monitor.beginTask(name, 100);
|
monitor.beginTask(name, 100);
|
||||||
start=System.currentTimeMillis();
|
start=System.currentTimeMillis();
|
||||||
|
|
||||||
IPopulateDOMASTAction action = null;
|
IPopulateDOMASTAction action = null;
|
||||||
IASTTranslationUnit aTu = null;
|
IASTTranslationUnit aTu;
|
||||||
try {
|
|
||||||
monitor.subTask(PARSING_TRANSLATION_UNIT);
|
try {
|
||||||
start=System.currentTimeMillis();
|
monitor.subTask(PARSING_TRANSLATION_UNIT);
|
||||||
aTu = CDOM.getInstance().getASTService().getTranslationUnit(
|
start=System.currentTimeMillis();
|
||||||
aFile,
|
aTu = tu.getAST();
|
||||||
CDOM.getInstance().getCodeReaderFactory(
|
monitor.worked(30);
|
||||||
CDOM.PARSE_SAVED_RESOURCES));
|
System.out.println(DOM_AST_VIEW_DONE + PARSING_TRANSLATION_UNIT + COLON_SPACE + (System.currentTimeMillis()- start) );
|
||||||
monitor.worked(30);
|
} catch (CoreException e) {
|
||||||
System.out.println(DOM_AST_VIEW_DONE + PARSING_TRANSLATION_UNIT + COLON_SPACE + (System.currentTimeMillis()- start) );
|
return Status.CANCEL_STATUS;
|
||||||
} catch (IASTServiceProvider.UnsupportedDialectException e) {
|
}
|
||||||
return Status.CANCEL_STATUS;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (monitor.isCanceled()) return Status.CANCEL_STATUS;
|
if (monitor.isCanceled()) return Status.CANCEL_STATUS;
|
||||||
|
|
||||||
monitor.subTask(GENERATING_INITIAL_TREE);
|
monitor.subTask(GENERATING_INITIAL_TREE);
|
||||||
start=System.currentTimeMillis();
|
start=System.currentTimeMillis();
|
||||||
if (lang == ParserLanguage.CPP) {
|
if (aTu instanceof CPPASTTranslationUnit ) {
|
||||||
action = new CPPPopulateASTViewAction(aTu, monitor);
|
action = new CPPPopulateASTViewAction(aTu, monitor);
|
||||||
aTu.accept( (CPPASTVisitor) action);
|
aTu.accept( (CPPASTVisitor) action);
|
||||||
} else {
|
}
|
||||||
|
else if (aTu instanceof CASTTranslationUnit){
|
||||||
action = new CPopulateASTViewAction(aTu, monitor);
|
action = new CPopulateASTViewAction(aTu, monitor);
|
||||||
aTu.accept( (CASTVisitor) action);
|
aTu.accept( (CASTVisitor) action);
|
||||||
}
|
}
|
||||||
|
@ -652,10 +643,16 @@ public class DOMAST extends ViewPart {
|
||||||
drillDownAdapter = new DrillDownAdapter(viewer);
|
drillDownAdapter = new DrillDownAdapter(viewer);
|
||||||
|
|
||||||
if (part instanceof CEditor) {
|
if (part instanceof CEditor) {
|
||||||
viewer.setContentProvider(new ViewContentProvider(((CEditor) part).getInputFile()));
|
ICElement inputElement = ((CEditor)part).getInputCElement();
|
||||||
setFile(((CEditor) part).getInputFile());
|
if(inputElement instanceof ITranslationUnit) {
|
||||||
|
viewer.setContentProvider(new ViewContentProvider((ITranslationUnit)inputElement));
|
||||||
|
setTranslationUnit((ITranslationUnit)inputElement);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
viewer.setContentProvider(new ViewContentProvider(null));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
viewer.setContentProvider(new ViewContentProvider(null)); // don't attempt to create a view based on old file info
|
viewer.setContentProvider(new ViewContentProvider(null)); // don't attempt to create a view based on old file info
|
||||||
}
|
}
|
||||||
|
|
||||||
viewer.setLabelProvider(new ViewLabelProvider());
|
viewer.setLabelProvider(new ViewLabelProvider());
|
||||||
|
@ -826,7 +823,7 @@ public class DOMAST extends ViewPart {
|
||||||
Object[] expanded = viewer.getExpandedElements();
|
Object[] expanded = viewer.getExpandedElements();
|
||||||
|
|
||||||
// set the new content provider
|
// set the new content provider
|
||||||
setContentProvider(new ViewContentProvider(file, expanded));
|
setContentProvider(new ViewContentProvider(tu, expanded));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
refreshAction.setText(REFRESH_DOM_AST);
|
refreshAction.setText(REFRESH_DOM_AST);
|
||||||
|
@ -867,7 +864,7 @@ public class DOMAST extends ViewPart {
|
||||||
showMessage(DOM_AST_HAS_NO_CONTENT);
|
showMessage(DOM_AST_HAS_NO_CONTENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
FindIASTNameDialog dialog = new FindIASTNameDialog(getSite().getShell(), new FindIASTNameTarget(viewer, lang));
|
FindIASTNameDialog dialog = new FindIASTNameDialog(getSite().getShell(), new FindIASTNameTarget(viewer));
|
||||||
dialog.open();
|
dialog.open();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -942,7 +939,6 @@ public class DOMAST extends ViewPart {
|
||||||
getSite().getPage().getActiveEditor() instanceof CEditor) {
|
getSite().getPage().getActiveEditor() instanceof CEditor) {
|
||||||
editor = getSite().getPage().getActiveEditor();
|
editor = getSite().getPage().getActiveEditor();
|
||||||
part = editor;
|
part = editor;
|
||||||
lang = getLanguageFromFile(((CEditor)editor).getInputFile());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return editor;
|
return editor;
|
||||||
|
@ -999,15 +995,14 @@ public class DOMAST extends ViewPart {
|
||||||
} else {
|
} else {
|
||||||
IPath path = new Path( filename );
|
IPath path = new Path( filename );
|
||||||
|
|
||||||
ICProject cproject = new CProject(null, file.getProject());
|
if (tu != null) {
|
||||||
ITranslationUnit unit = CoreModel.getDefault().createTranslationUnitFrom(cproject, path);
|
|
||||||
if (unit != null)
|
|
||||||
try {
|
try {
|
||||||
aPart = EditorUtility.openInEditor(unit);
|
aPart = EditorUtility.openInEditor(tu);
|
||||||
} catch (PartInitException e) {
|
} catch (PartInitException e) {
|
||||||
return;
|
return;
|
||||||
} catch (CModelException e) {
|
} catch (CModelException e) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1060,12 +1055,9 @@ public class DOMAST extends ViewPart {
|
||||||
((ASTHighlighterAction) singleClickAction).setPart(part);
|
((ASTHighlighterAction) singleClickAction).setPart(part);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLang(ParserLanguage lang) {
|
|
||||||
this.lang = lang;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFile(IFile file) {
|
public void setTranslationUnit(ITranslationUnit tu) {
|
||||||
this.file = file;
|
this.tu = tu;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class RunAfterViewOpenJob extends Job {
|
private class RunAfterViewOpenJob extends Job {
|
||||||
|
@ -1135,24 +1127,16 @@ public class DOMAST extends ViewPart {
|
||||||
|
|
||||||
if (tempView != null) {
|
if (tempView != null) {
|
||||||
if (tempView instanceof DOMAST) {
|
if (tempView instanceof DOMAST) {
|
||||||
IFile aFile = ((CEditor)editor).getInputFile();
|
ICElement input = ((CEditor)editor).getInputCElement();
|
||||||
|
|
||||||
// check if the file is a valid "compilation unit" (based on file extension)
|
if(!(input instanceof ITranslationUnit)) {
|
||||||
if (aFile == null) {
|
|
||||||
MessageDialog.openInformation(shell, DOMAST.VIEW_NAME, NOT_VALID_COMPILATION_UNIT);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
String ext = aFile.getFileExtension().toUpperCase();
|
|
||||||
if (!(ext.equals(EXTENSION_C) || ext.equals(EXTENSION_CC) || ext.equals(EXTENSION_CPP) || ext.equals(EXTENSION_CXX))) {
|
|
||||||
MessageDialog.openInformation(shell, DOMAST.VIEW_NAME, NOT_VALID_COMPILATION_UNIT);
|
MessageDialog.openInformation(shell, DOMAST.VIEW_NAME, NOT_VALID_COMPILATION_UNIT);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
((DOMAST)tempView).setFile(aFile);
|
((DOMAST)tempView).setTranslationUnit((ITranslationUnit)input);
|
||||||
((DOMAST)tempView).setPart(editor);
|
((DOMAST)tempView).setPart(editor);
|
||||||
((DOMAST)tempView).setLang(getLanguageFromFile(aFile));
|
((DOMAST)tempView).setContentProvider(((DOMAST)tempView).new ViewContentProvider((ITranslationUnit)input));
|
||||||
((DOMAST)tempView).setContentProvider(((DOMAST)tempView).new ViewContentProvider(((CEditor)editor).getInputFile()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1163,23 +1147,4 @@ public class DOMAST extends ViewPart {
|
||||||
return tempView;
|
return tempView;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ParserLanguage getLanguageFromFile(IFile file) {
|
|
||||||
if (file == null) { // assume CPP
|
|
||||||
return ParserLanguage.CPP;
|
|
||||||
}
|
|
||||||
|
|
||||||
IProject project = file.getProject();
|
|
||||||
String lid = null;
|
|
||||||
IContentType type = CCorePlugin.getContentType(project, file.getFullPath().lastSegment());
|
|
||||||
if (type != null) {
|
|
||||||
lid = type.getId();
|
|
||||||
}
|
|
||||||
if ( lid != null
|
|
||||||
&& ( lid.equals(CCorePlugin.CONTENT_TYPE_CXXSOURCE) || lid.equals(CCorePlugin.CONTENT_TYPE_CXXHEADER)) ) {
|
|
||||||
return ParserLanguage.CPP;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ParserLanguage.C;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2005 IBM Corporation and others.
|
* Copyright (c) 2005, 2007 IBM Corporation and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -15,14 +15,6 @@ import java.util.List;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.c.CASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
|
||||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
|
||||||
import org.eclipse.jface.text.IFindReplaceTarget;
|
import org.eclipse.jface.text.IFindReplaceTarget;
|
||||||
import org.eclipse.jface.text.IFindReplaceTargetExtension3;
|
import org.eclipse.jface.text.IFindReplaceTargetExtension3;
|
||||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||||
|
@ -30,6 +22,17 @@ import org.eclipse.jface.viewers.TreeViewer;
|
||||||
import org.eclipse.swt.graphics.Point;
|
import org.eclipse.swt.graphics.Point;
|
||||||
import org.eclipse.swt.widgets.TreeItem;
|
import org.eclipse.swt.widgets.TreeItem;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.c.CASTVisitor;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.c.CASTTranslationUnit;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTranslationUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author dsteffle
|
* @author dsteffle
|
||||||
*/
|
*/
|
||||||
|
@ -37,7 +40,6 @@ public class FindIASTNameTarget implements IFindReplaceTarget, IFindReplaceTarge
|
||||||
|
|
||||||
IASTTranslationUnit tu = null;
|
IASTTranslationUnit tu = null;
|
||||||
DOMASTNodeParent tuTreeParent = null;
|
DOMASTNodeParent tuTreeParent = null;
|
||||||
ParserLanguage lang = null;
|
|
||||||
TreeViewer viewer = null;
|
TreeViewer viewer = null;
|
||||||
DOMASTNodeLeaf startingNode = null;
|
DOMASTNodeLeaf startingNode = null;
|
||||||
IASTName[] matchingNames = null;
|
IASTName[] matchingNames = null;
|
||||||
|
@ -252,14 +254,13 @@ public class FindIASTNameTarget implements IFindReplaceTarget, IFindReplaceTarge
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public FindIASTNameTarget(TreeViewer viewer, ParserLanguage lang) {
|
public FindIASTNameTarget(TreeViewer viewer) {
|
||||||
if (viewer.getContentProvider() instanceof DOMAST.ViewContentProvider) {
|
if (viewer.getContentProvider() instanceof DOMAST.ViewContentProvider) {
|
||||||
tu = ((DOMAST.ViewContentProvider)viewer.getContentProvider()).getTU();
|
tu = ((DOMAST.ViewContentProvider)viewer.getContentProvider()).getTU();
|
||||||
tuTreeParent = ((DOMAST.ViewContentProvider)viewer.getContentProvider()).getTUTreeParent();
|
tuTreeParent = ((DOMAST.ViewContentProvider)viewer.getContentProvider()).getTUTreeParent();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.viewer = viewer;
|
this.viewer = viewer;
|
||||||
this.lang = lang;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
@ -274,11 +275,11 @@ public class FindIASTNameTarget implements IFindReplaceTarget, IFindReplaceTarge
|
||||||
boolean searchForward, boolean caseSensitive, boolean wholeWord, boolean regExSearch) {
|
boolean searchForward, boolean caseSensitive, boolean wholeWord, boolean regExSearch) {
|
||||||
|
|
||||||
if (matchingNames == null && tu != null) {
|
if (matchingNames == null && tu != null) {
|
||||||
if (lang == ParserLanguage.CPP) {
|
if (tu instanceof CPPASTTranslationUnit) {
|
||||||
CPPNameCollector col = new CPPNameCollector(findString, caseSensitive, wholeWord, regExSearch);
|
CPPNameCollector col = new CPPNameCollector(findString, caseSensitive, wholeWord, regExSearch);
|
||||||
tu.accept(col);
|
tu.accept(col);
|
||||||
matchingNames = col.getNameArray(tu.getAllPreprocessorStatements());
|
matchingNames = col.getNameArray(tu.getAllPreprocessorStatements());
|
||||||
} else {
|
} else if(tu instanceof CASTTranslationUnit) {
|
||||||
CNameCollector col = new CNameCollector(findString, caseSensitive, wholeWord, regExSearch);
|
CNameCollector col = new CNameCollector(findString, caseSensitive, wholeWord, regExSearch);
|
||||||
tu.accept(col);
|
tu.accept(col);
|
||||||
matchingNames = col.getNameArray(tu.getAllPreprocessorStatements());
|
matchingNames = col.getNameArray(tu.getAllPreprocessorStatements());
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2005 IBM Corporation and others.
|
* Copyright (c) 2005, 2007 IBM Corporation and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -10,15 +10,6 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.ui.tests.DOMAST;
|
package org.eclipse.cdt.ui.tests.DOMAST;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.model.CModelException;
|
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
|
||||||
import org.eclipse.cdt.core.model.ISourceReference;
|
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
|
||||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
|
||||||
import org.eclipse.cdt.internal.core.model.TranslationUnit;
|
|
||||||
import org.eclipse.cdt.internal.ui.util.EditorUtility;
|
|
||||||
import org.eclipse.cdt.ui.tests.DOMAST.DOMAST;
|
|
||||||
import org.eclipse.core.resources.IFile;
|
|
||||||
import org.eclipse.jface.action.IAction;
|
import org.eclipse.jface.action.IAction;
|
||||||
import org.eclipse.jface.viewers.ISelection;
|
import org.eclipse.jface.viewers.ISelection;
|
||||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||||
|
@ -30,6 +21,13 @@ import org.eclipse.ui.IViewPart;
|
||||||
import org.eclipse.ui.IWorkbenchPart;
|
import org.eclipse.ui.IWorkbenchPart;
|
||||||
import org.eclipse.ui.PartInitException;
|
import org.eclipse.ui.PartInitException;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.model.CModelException;
|
||||||
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
|
import org.eclipse.cdt.core.model.ISourceReference;
|
||||||
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.internal.ui.util.EditorUtility;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author dsteffle
|
* @author dsteffle
|
||||||
*/
|
*/
|
||||||
|
@ -37,7 +35,6 @@ public class OpenDOMViewAction implements IViewActionDelegate, IEditorActionDele
|
||||||
|
|
||||||
IViewPart viewPart = null;
|
IViewPart viewPart = null;
|
||||||
ISelection selection = null;
|
ISelection selection = null;
|
||||||
IFile file = null;
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.ui.IViewActionDelegate#init(org.eclipse.ui.IViewPart)
|
* @see org.eclipse.ui.IViewActionDelegate#init(org.eclipse.ui.IViewPart)
|
||||||
|
@ -80,12 +77,9 @@ public class OpenDOMViewAction implements IViewActionDelegate, IEditorActionDele
|
||||||
|
|
||||||
if (tempView != null) {
|
if (tempView != null) {
|
||||||
if (tempView instanceof DOMAST) {
|
if (tempView instanceof DOMAST) {
|
||||||
((DOMAST)tempView).setFile(file);
|
((DOMAST)tempView).setTranslationUnit(tu);
|
||||||
((DOMAST)tempView).setPart(part);
|
((DOMAST)tempView).setPart(part);
|
||||||
if (tu != null) {
|
((DOMAST)tempView).setContentProvider(((DOMAST)tempView).new ViewContentProvider(tu));
|
||||||
((DOMAST)tempView).setLang(tu.isCXXLanguage() ? ParserLanguage.CPP : ParserLanguage.C);
|
|
||||||
}
|
|
||||||
((DOMAST)tempView).setContentProvider(((DOMAST)tempView).new ViewContentProvider(file));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,11 +90,6 @@ public class OpenDOMViewAction implements IViewActionDelegate, IEditorActionDele
|
||||||
* @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
|
* @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
|
||||||
*/
|
*/
|
||||||
public void selectionChanged(IAction action, ISelection selection) {
|
public void selectionChanged(IAction action, ISelection selection) {
|
||||||
if (selection instanceof IStructuredSelection &&
|
|
||||||
((IStructuredSelection)selection).getFirstElement() instanceof TranslationUnit &&
|
|
||||||
((TranslationUnit)((IStructuredSelection)selection).getFirstElement()).getResource() instanceof IFile) {
|
|
||||||
this.file = (IFile)((TranslationUnit)((IStructuredSelection)selection).getFirstElement()).getResource();
|
|
||||||
}
|
|
||||||
this.selection = selection;
|
this.selection = selection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue