From fe09a6ed3d39cce85c174bbaac7b412538b44730 Mon Sep 17 00:00:00 2001 From: Doug Schaefer Date: Tue, 17 Apr 2007 03:04:46 +0000 Subject: [PATCH] Open Declaration works on include statements. --- .../actions/OpenDeclarationsAction.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsAction.java index add33e23c12..fb176dcb7d6 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsAction.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsAction.java @@ -28,6 +28,8 @@ import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.IName; import org.eclipse.cdt.core.dom.ast.IASTFileLocation; import org.eclipse.cdt.core.dom.ast.IASTName; +import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement; +import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IProblemBinding; @@ -118,6 +120,33 @@ public class OpenDeclarationsAction extends SelectionParseAction { } } } + } else { + // Check if we're in an include statement + IASTPreprocessorStatement[] preprocs = ast.getAllPreprocessorStatements(); + for (int i = 0; i < preprocs.length; ++i) { + if (!(preprocs[i] instanceof IASTPreprocessorIncludeStatement)) + continue; + IASTFileLocation loc = preprocs[i].getFileLocation(); + if (loc.getFileName().equals(ast.getFilePath()) + && loc.getNodeOffset() < selectionStart + && loc.getNodeOffset() + loc.getNodeLength() > selectionStart) { + // Got it + String name = ((IASTPreprocessorIncludeStatement)preprocs[i]).getPath(); + if (name != null) { + final IPath path = new Path(name); + runInUIThread(new Runnable() { + public void run() { + try { + open(path, 0, 0); + } catch (CoreException e) { + CUIPlugin.getDefault().log(e); + } + } + }); + } + break; + } + } } } finally { index.releaseReadLock();