[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] IASTTranslationUnit from eclipse editor?

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!?


2008/5/9 Leherbauer, Anton <Anton.Leherbauer@xxxxxxxxxxxxx>:
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.

Anton Leherbauer
Wind River CDT Team, Austria

From: cdt-dev-bounces@xxxxxxxxxxx [mailto:cdt-dev-bounces@xxxxxxxxxxx] On Behalf Of Jimmie Eriksson
Sent: Friday, May 09, 2008 1:35 PM
To: cdt-dev@xxxxxxxxxxx
Subject: [cdt-dev] IASTTranslationUnit from eclipse editor?

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?
        fileLocations = visitor.getLocations();
    } catch(IASTServiceProvider.UnsupportedDialectException e) {
    return fileLocations;


cdt-dev mailing list