1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +02:00

Handle potential null pointers in ASTRunnable.runOnAST()

This commit is contained in:
Markus Schorn 2007-07-27 09:28:16 +00:00
parent 9cedcf1a8e
commit 94bee24a59
5 changed files with 39 additions and 27 deletions

View file

@ -89,6 +89,7 @@ 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) {
if (ast != null) {
IASTName[] selectedNames=
lang.getSelectedNames(ast, selection.getOffset(), selection.getLength());
@ -102,6 +103,7 @@ public class CElementHyperlinkDetector implements IHyperlinkDetector {
if(linkRegion != null)
result[0]= new CElementHyperlink(linkRegion, openAction);
}
return Status.OK_STATUS;
}
});

View file

@ -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,12 +105,14 @@ public class ToggleSourceAndHeaderAction extends TextEditorAction {
shouldVisitDeclarators= true;
}
public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) {
if (ast != null) {
fIndex= ast.getIndex();
fFilePath= Path.fromOSString(ast.getFilePath());
fMap= new HashMap();
if (fIndex != null) {
ast.accept(this);
}
}
return Status.OK_STATUS;
}

View file

@ -48,6 +48,7 @@ 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 {
if (ast != null) {
IASTName[] names = language.getSelectedNames(ast, selection.getOffset(), selection.getLength());
if (names != null) {
for (int i = 0; i < names.length; ++i) {
@ -56,6 +57,7 @@ public class PDOMSearchTextSelectionQuery extends PDOMSearchQuery {
createMatches(index, binding);
}
}
}
return Status.OK_STATUS;
}
});

View file

@ -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();

View file

@ -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) {
if (ast != null) {
FindNameForSelectionVisitor finder= new FindNameForSelectionVisitor(ast.getFilePath(), selectionStart, selectionLength);
ast.accept(finder);
result[0]= finder.getSelectedName();
}
return Status.OK_STATUS;
}
});