diff options
Diffstat (limited to 'core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions')
3 files changed, 75 insertions, 54 deletions
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 6789418ce76..34461080628 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 @@ -11,6 +11,7 @@ package org.eclipse.cdt.internal.ui.search.actions; +import org.eclipse.cdt.core.dom.ast.IASTFileLocation; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IBinding; @@ -21,8 +22,10 @@ import org.eclipse.cdt.internal.ui.editor.CEditor; import org.eclipse.cdt.internal.ui.editor.CEditorMessages; import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.jface.text.ITextSelection; @@ -70,31 +73,42 @@ public class OpenDeclarationsAction extends SelectionParseAction { if (binding != null && !(binding instanceof IProblemBinding)) { final IASTName[] declNames = ast.getDeclarations(binding); if (declNames.length > 0) { - Display.getDefault().asyncExec(new Runnable() { - public void run() { - try { - open(declNames[0]); - } catch (CoreException e) { - CUIPlugin.getDefault().log(e); - } - }; - }); - } else if (binding instanceof PDOMBinding) { - PDOMBinding pdomBinding = (PDOMBinding)binding; - IASTName name = pdomBinding.getFirstDefinition(); - if (name == null) - name = pdomBinding.getFirstDeclaration(); - if (name != null) { - final IASTName dname = name; + IASTFileLocation fileloc = declNames[0].getFileLocation(); + if (fileloc != null) { + final IPath path = new Path(fileloc.getFileName()); + final int offset = fileloc.getNodeOffset(); + final int length = fileloc.getNodeLength(); Display.getDefault().asyncExec(new Runnable() { public void run() { try { - open(dname); + open(path, offset, length); } catch (CoreException e) { CUIPlugin.getDefault().log(e); } - } + }; }); + } + } else if (binding instanceof PDOMBinding) { + PDOMBinding pdomBinding = (PDOMBinding)binding; + IASTName name = pdomBinding.getFirstDefinition(); + if (name == null) + name = pdomBinding.getFirstDeclaration(); + if (name != null) { + IASTFileLocation fileloc = name.getFileLocation(); + if (fileloc != null) { + final IPath path = new Path(fileloc.getFileName()); + final int offset = fileloc.getNodeOffset(); + final int length = fileloc.getNodeLength(); + Display.getDefault().asyncExec(new Runnable() { + public void run() { + try { + open(path, offset, length); + } catch (CoreException e) { + CUIPlugin.getDefault().log(e); + } + } + }); + } } } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDefinitionAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDefinitionAction.java index 0f928c53a00..d533fc658f9 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDefinitionAction.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDefinitionAction.java @@ -10,6 +10,9 @@ *******************************************************************************/ package org.eclipse.cdt.internal.ui.search.actions; +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.dom.IPDOM; +import org.eclipse.cdt.core.dom.ast.IASTFileLocation; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IBinding; @@ -19,8 +22,10 @@ import org.eclipse.cdt.internal.ui.editor.CEditor; import org.eclipse.cdt.internal.ui.editor.CEditorMessages; import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.jface.text.ITextSelection; @@ -59,30 +64,43 @@ public class OpenDefinitionAction extends SelectionParseAction { IWorkingCopy workingCopy = CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(fEditor.getEditorInput()); if (workingCopy == null) return Status.CANCEL_STATUS; - - IASTTranslationUnit ast = workingCopy.getLanguage().getASTTranslationUnit(workingCopy, ILanguage.AST_SKIP_ALL_HEADERS | ILanguage.AST_USE_INDEX); - IASTName[] selectedNames = workingCopy.getLanguage().getSelectedNames(ast, selectionStart, selectionLength); - - if (selectedNames.length > 0 && selectedNames[0] != null) { // just right, only one name selected - IASTName searchName = selectedNames[0]; - - IBinding binding = searchName.resolveBinding(); - if (binding != null) { - final IASTName[] declNames = ast.getDefinitions(binding); - if (declNames.length > 0) { - Display.getDefault().asyncExec(new Runnable() { - public void run() { - try { - open(declNames[0]); - } catch (CoreException e) { - CUIPlugin.getDefault().log(e); - } - }; - }); + + IPDOM pdom = CCorePlugin.getPDOMManager().getPDOM(workingCopy.getCProject()); + try { + pdom.acquireReadLock(); + IASTTranslationUnit ast = workingCopy.getLanguage().getASTTranslationUnit(workingCopy, ILanguage.AST_SKIP_ALL_HEADERS | ILanguage.AST_USE_INDEX); + IASTName[] selectedNames = workingCopy.getLanguage().getSelectedNames(ast, selectionStart, selectionLength); + + if (selectedNames.length > 0 && selectedNames[0] != null) { // just right, only one name selected + IASTName searchName = selectedNames[0]; + + IBinding binding = searchName.resolveBinding(); + if (binding != null) { + final IASTName[] declNames = ast.getDefinitions(binding); + if (declNames.length > 0) { + IASTFileLocation fileloc = declNames[0].getFileLocation(); + if (fileloc != null) { + final IPath path = new Path(fileloc.getFileName()); + final int offset = fileloc.getNodeOffset(); + final int length = fileloc.getNodeLength(); + + Display.getDefault().asyncExec(new Runnable() { + public void run() { + try { + open(path, offset, length); + } catch (CoreException e) { + CUIPlugin.getDefault().log(e); + } + }; + }); + } + } } } + } catch (InterruptedException e) { + } finally { + pdom.releaseReadLock(); } - return Status.OK_STATUS; } catch (CoreException e) { return e.getStatus(); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/SelectionParseAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/SelectionParseAction.java index fd7fed1a295..13d7f6a10b2 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/SelectionParseAction.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/SelectionParseAction.java @@ -14,8 +14,6 @@ package org.eclipse.cdt.internal.ui.search.actions; import java.io.IOException; import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.dom.ast.IASTFileLocation; -import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.IWorkingCopy; import org.eclipse.cdt.core.parser.CodeReader; @@ -42,7 +40,6 @@ import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IStatusLineManager; import org.eclipse.jface.text.BadLocationException; @@ -521,22 +518,14 @@ public class SelectionParseAction extends Action { * * @param name */ - protected void open(IASTName name) throws CoreException { - IASTFileLocation fileloc = name.getFileLocation(); - if (fileloc == null) - // no source location - TODO spit out an error in the status bar - return; - int currentOffset = fileloc.getNodeOffset(); - int currentLength = fileloc.getNodeLength(); - - IPath path = new Path(fileloc.getFileName()); + protected void open(IPath path, int offset, int length) throws CoreException { IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(path); if (files.length > 0) { IEditorPart editor = IDE.openEditor(CUIPlugin.getActivePage(), files[0]); try { IMarker marker = files[0].createMarker(NewSearchUI.SEARCH_MARKER); - marker.setAttribute(IMarker.CHAR_START, currentOffset); - marker.setAttribute(IMarker.CHAR_END, currentOffset + currentLength); + marker.setAttribute(IMarker.CHAR_START, offset); + marker.setAttribute(IMarker.CHAR_END, offset + length); IDE.gotoMarker(editor, marker); marker.delete(); } catch (CoreException e) { @@ -548,7 +537,7 @@ public class SelectionParseAction extends Action { IEditorPart editor = CUIPlugin.getActivePage().openEditor(input, ExternalSearchEditor.EDITOR_ID); if (editor instanceof ITextEditor) { ITextEditor textEditor = (ITextEditor)editor; - textEditor.selectAndReveal(currentOffset, currentLength); + textEditor.selectAndReveal(offset, length); } } |