[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[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;