diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CElementHyperlinkDetector.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CElementHyperlinkDetector.java index 8cb89d255b1..5d967d3bbb3 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CElementHyperlinkDetector.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CElementHyperlinkDetector.java @@ -89,19 +89,21 @@ public class CElementHyperlinkDetector implements IHyperlinkDetector { try { IStatus status= ASTProvider.getASTProvider().runOnAST(workingCopy, ASTProvider.WAIT_YES, null, new ASTRunnable() { public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) { - IASTName[] selectedNames= - lang.getSelectedNames(ast, selection.getOffset(), selection.getLength()); + if (ast != null) { + IASTName[] selectedNames= + lang.getSelectedNames(ast, selection.getOffset(), selection.getLength()); - IRegion linkRegion; - if(selectedNames.length > 0 && selectedNames[0] != null) { // found a name - linkRegion = new Region(selection.getOffset(), selection.getLength()); - } - else { // check if we are in an include statement - linkRegion = matchIncludeStatement(ast, selection); - } + IRegion linkRegion; + if(selectedNames.length > 0 && selectedNames[0] != null) { // found a name + linkRegion = new Region(selection.getOffset(), selection.getLength()); + } + else { // check if we are in an include statement + linkRegion = matchIncludeStatement(ast, selection); + } - if(linkRegion != null) - result[0]= new CElementHyperlink(linkRegion, openAction); + if(linkRegion != null) + result[0]= new CElementHyperlink(linkRegion, openAction); + } return Status.OK_STATUS; } }); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/ToggleSourceAndHeaderAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/ToggleSourceAndHeaderAction.java index 0b0d0eb4bcc..be517f4ea53 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/ToggleSourceAndHeaderAction.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/ToggleSourceAndHeaderAction.java @@ -7,6 +7,7 @@ * * Contributors: * Anton Leherbauer (Wind River Systems) - initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.ui.editor; @@ -104,11 +105,13 @@ public class ToggleSourceAndHeaderAction extends TextEditorAction { shouldVisitDeclarators= true; } public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) { - fIndex= ast.getIndex(); - fFilePath= Path.fromOSString(ast.getFilePath()); - fMap= new HashMap(); - if (fIndex != null) { - ast.accept(this); + if (ast != null) { + fIndex= ast.getIndex(); + fFilePath= Path.fromOSString(ast.getFilePath()); + fMap= new HashMap(); + if (fIndex != null) { + ast.accept(this); + } } return Status.OK_STATUS; } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchTextSelectionQuery.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchTextSelectionQuery.java index c375c34a209..72baaecb48f 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchTextSelectionQuery.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchTextSelectionQuery.java @@ -6,8 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * QNX - Initial API and implementation - * Markus Schorn (Wind River Systems) + * QNX - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.ui.search; @@ -48,12 +48,14 @@ public class PDOMSearchTextSelectionQuery extends PDOMSearchQuery { protected IStatus runWithIndex(final IIndex index, IProgressMonitor monitor) { return ASTProvider.getASTProvider().runOnAST(tu, ASTProvider.WAIT_YES, monitor, new ASTRunnable() { public IStatus runOnAST(ILanguage language, IASTTranslationUnit ast) throws CoreException { - IASTName[] names = language.getSelectedNames(ast, selection.getOffset(), selection.getLength()); - if (names != null) { - for (int i = 0; i < names.length; ++i) { - IBinding binding = names[i].resolveBinding(); - if (binding != null) - createMatches(index, binding); + if (ast != null) { + IASTName[] names = language.getSelectedNames(ast, selection.getOffset(), selection.getLength()); + if (names != null) { + for (int i = 0; i < names.length; ++i) { + IBinding binding = names[i].resolveBinding(); + if (binding != null) + createMatches(index, binding); + } } } return Status.OK_STATUS; 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 b18f191f9fd..18665de3981 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 @@ -114,6 +114,9 @@ public class OpenDeclarationsAction extends SelectionParseAction { } public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) throws CoreException { + if (ast == null) { + return Status.OK_STATUS; + } int selectionStart = selNode.getOffset(); int selectionLength = selNode.getLength(); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/IndexUI.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/IndexUI.java index 3aa0817419d..e4451ee0ed2 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/IndexUI.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/IndexUI.java @@ -339,9 +339,11 @@ public class IndexUI { final IASTName[] result= {null}; ASTProvider.getASTProvider().runOnAST(workingCopy, ASTProvider.WAIT_YES, null, new ASTRunnable() { public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) { - FindNameForSelectionVisitor finder= new FindNameForSelectionVisitor(ast.getFilePath(), selectionStart, selectionLength); - ast.accept(finder); - result[0]= finder.getSelectedName(); + if (ast != null) { + FindNameForSelectionVisitor finder= new FindNameForSelectionVisitor(ast.getFilePath(), selectionStart, selectionLength); + ast.accept(finder); + result[0]= finder.getSelectedName(); + } return Status.OK_STATUS; } });