mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 02:06:01 +02:00
Handle potential null pointers in ASTRunnable.runOnAST()
This commit is contained in:
parent
9cedcf1a8e
commit
94bee24a59
5 changed files with 39 additions and 27 deletions
|
@ -89,6 +89,7 @@ public class CElementHyperlinkDetector implements IHyperlinkDetector {
|
||||||
try {
|
try {
|
||||||
IStatus status= ASTProvider.getASTProvider().runOnAST(workingCopy, ASTProvider.WAIT_YES, null, new ASTRunnable() {
|
IStatus status= ASTProvider.getASTProvider().runOnAST(workingCopy, ASTProvider.WAIT_YES, null, new ASTRunnable() {
|
||||||
public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) {
|
public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) {
|
||||||
|
if (ast != null) {
|
||||||
IASTName[] selectedNames=
|
IASTName[] selectedNames=
|
||||||
lang.getSelectedNames(ast, selection.getOffset(), selection.getLength());
|
lang.getSelectedNames(ast, selection.getOffset(), selection.getLength());
|
||||||
|
|
||||||
|
@ -102,6 +103,7 @@ public class CElementHyperlinkDetector implements IHyperlinkDetector {
|
||||||
|
|
||||||
if(linkRegion != null)
|
if(linkRegion != null)
|
||||||
result[0]= new CElementHyperlink(linkRegion, openAction);
|
result[0]= new CElementHyperlink(linkRegion, openAction);
|
||||||
|
}
|
||||||
return Status.OK_STATUS;
|
return Status.OK_STATUS;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Anton Leherbauer (Wind River Systems) - initial API and implementation
|
* Anton Leherbauer (Wind River Systems) - initial API and implementation
|
||||||
|
* Markus Schorn (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.cdt.internal.ui.editor;
|
package org.eclipse.cdt.internal.ui.editor;
|
||||||
|
@ -104,12 +105,14 @@ public class ToggleSourceAndHeaderAction extends TextEditorAction {
|
||||||
shouldVisitDeclarators= true;
|
shouldVisitDeclarators= true;
|
||||||
}
|
}
|
||||||
public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) {
|
public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) {
|
||||||
|
if (ast != null) {
|
||||||
fIndex= ast.getIndex();
|
fIndex= ast.getIndex();
|
||||||
fFilePath= Path.fromOSString(ast.getFilePath());
|
fFilePath= Path.fromOSString(ast.getFilePath());
|
||||||
fMap= new HashMap();
|
fMap= new HashMap();
|
||||||
if (fIndex != null) {
|
if (fIndex != null) {
|
||||||
ast.accept(this);
|
ast.accept(this);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return Status.OK_STATUS;
|
return Status.OK_STATUS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,7 @@ public class PDOMSearchTextSelectionQuery extends PDOMSearchQuery {
|
||||||
protected IStatus runWithIndex(final IIndex index, IProgressMonitor monitor) {
|
protected IStatus runWithIndex(final IIndex index, IProgressMonitor monitor) {
|
||||||
return ASTProvider.getASTProvider().runOnAST(tu, ASTProvider.WAIT_YES, monitor, new ASTRunnable() {
|
return ASTProvider.getASTProvider().runOnAST(tu, ASTProvider.WAIT_YES, monitor, new ASTRunnable() {
|
||||||
public IStatus runOnAST(ILanguage language, IASTTranslationUnit ast) throws CoreException {
|
public IStatus runOnAST(ILanguage language, IASTTranslationUnit ast) throws CoreException {
|
||||||
|
if (ast != null) {
|
||||||
IASTName[] names = language.getSelectedNames(ast, selection.getOffset(), selection.getLength());
|
IASTName[] names = language.getSelectedNames(ast, selection.getOffset(), selection.getLength());
|
||||||
if (names != null) {
|
if (names != null) {
|
||||||
for (int i = 0; i < names.length; ++i) {
|
for (int i = 0; i < names.length; ++i) {
|
||||||
|
@ -56,6 +57,7 @@ public class PDOMSearchTextSelectionQuery extends PDOMSearchQuery {
|
||||||
createMatches(index, binding);
|
createMatches(index, binding);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return Status.OK_STATUS;
|
return Status.OK_STATUS;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -114,6 +114,9 @@ public class OpenDeclarationsAction extends SelectionParseAction {
|
||||||
}
|
}
|
||||||
|
|
||||||
public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) throws CoreException {
|
public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) throws CoreException {
|
||||||
|
if (ast == null) {
|
||||||
|
return Status.OK_STATUS;
|
||||||
|
}
|
||||||
int selectionStart = selNode.getOffset();
|
int selectionStart = selNode.getOffset();
|
||||||
int selectionLength = selNode.getLength();
|
int selectionLength = selNode.getLength();
|
||||||
|
|
||||||
|
|
|
@ -339,9 +339,11 @@ public class IndexUI {
|
||||||
final IASTName[] result= {null};
|
final IASTName[] result= {null};
|
||||||
ASTProvider.getASTProvider().runOnAST(workingCopy, ASTProvider.WAIT_YES, null, new ASTRunnable() {
|
ASTProvider.getASTProvider().runOnAST(workingCopy, ASTProvider.WAIT_YES, null, new ASTRunnable() {
|
||||||
public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) {
|
public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) {
|
||||||
|
if (ast != null) {
|
||||||
FindNameForSelectionVisitor finder= new FindNameForSelectionVisitor(ast.getFilePath(), selectionStart, selectionLength);
|
FindNameForSelectionVisitor finder= new FindNameForSelectionVisitor(ast.getFilePath(), selectionStart, selectionLength);
|
||||||
ast.accept(finder);
|
ast.accept(finder);
|
||||||
result[0]= finder.getSelectedName();
|
result[0]= finder.getSelectedName();
|
||||||
|
}
|
||||||
return Status.OK_STATUS;
|
return Status.OK_STATUS;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue