[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [cdt-dev] IASTTranslationUnit from eclipse editor?
|
ok, I resolved it by installing cdt5 and added some more dependencies in the manifest.mf file..
< org.eclipse.cdt,
< org.eclipse.cdt.core
-> org.eclipse.cdt.core,
-> org.eclipse.cdt.source,
-> org.eclipse.cdt.ui,
-> org.eclipse.cdt.sdk
and I don't know exactly which of them are needed, maybe none!!
so, the final solution now looks like this... if anyone else ever had the same problem.
public FileLocation findReturnType(IProject project, FileLocation fileLocation, String functionName) {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceRoot root = workspace.getRoot();
IWorkbench wb = PlatformUI.getWorkbench();
IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
IWorkbenchPage page = win.getActivePage();
IEditorDescriptor desc = wb.getEditorRegistry().getDefaultEditor(fileLocation.getFilename());
if (desc == null)
return null;
IFile file = root.getFile(new Path(fileLocation.getFilename()));
ReturnTypeVisitor visitor = new ReturnTypeVisitor(fileLocation.getFilename(), functionName);
Vector<FileLocation> fileLocations = null;
try {
FileEditorInput fileEditorInput = new FileEditorInput(file);
ITextEditor editor = (ITextEditor)page.openEditor(fileEditorInput, desc.getId());
ICElement element = CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(editor.getEditorInput()); if (element instanceof ITranslationUnit) {
ITranslationUnit tu = ((ITranslationUnit)element); IASTTranslationUnit itu = tu.getAST();
itu.accept(visitor); fileLocations = visitor.getLocations();
} } catch (PartInitException e) {
} catch (CoreException e) {
}
return fileLocations.get(0);
}
/Jimmie
2008/5/12 Jimmie Eriksson <
eriksson.jimmie@xxxxxxxxx>:
I can't find any of those, are they in any package I don't have, am I outdated? isn't it cdt4.0.3?
shouldn' I be able to do this:
import org.eclipse.cdt.internal.ui.editor.ASTProvider; it only tells me "the import org.eclipse.cdt.internal.ui cannot be resolved" is it really ok to use the internal stuff? (I don't care as long as it's working... now it doesn't)
I can't find the "CElementHyperlinkDetecter" you refer to either as I do not know where to look. google and cdt-sites and docs gives nothing!?
/Jimmie
2008/5/9 Leherbauer, Anton <
Anton.Leherbauer@xxxxxxxxxxxxx>:
Hi,
the AST of the current active editor is
cached.
If you don't mind using an internal class, ASTProvider
gives you access to this cached AST.
See e.g. CElementHyperlinkDetecter for an example how to
use it.
HTH
Toni
--
Anton Leherbauer
Wind River CDT Team, Austria
Hi, (I'm new here and I'm working on my examwork which includes a
plugin for eclipse)
Is it possible to get a IASTTranslationUnit without
having to parse a c file oneself? I suspect the file already is parsed and
that the IASTTranslationUnit is there somewhere for me just to get? as the
colorhighlighting and the codecompletion is already there and working in
eclipse.
public FileLocation findReturnType(IProject project,
FileLocation fileLocation, String functionName) {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceRoot root = workspace.getRoot();
IWorkbench wb
= PlatformUI.getWorkbench();
IWorkbenchWindow win =
wb.getActiveWorkbenchWindow();
IWorkbenchPage page =
win.getActivePage();
IEditorDescriptor desc =
wb.getEditorRegistry().getDefaultEditor(fileLocation.getFilename());
if (desc == null)
return
null;
IFile file = root.getFile(new
Path(fileLocation.getFilename()));
ReturnTypeVisitor
visitor = new ReturnTypeVisitor(fileLocation.getFilename(),
functionName);
CDOM cDOM =
CDOM.getInstance();
Vector<FileLocation>
fileLocations = null;
try {
IASTTranslationUnit transUnit =
cDOM.getTranslationUnit(file);
// do I have
to do this or can I get it from the editor or elsewhere? some examplecode is
refereing to "workingCopy" which has similiar functionality.. or where should
one turn?
transUnit.accept(visitor);
fileLocations =
visitor.getLocations();
}
catch(IASTServiceProvider.UnsupportedDialectException e)
{
}
return
fileLocations;
...
...
/Jimmie
_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/cdt-dev