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,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;
}
});

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,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;
}

View file

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

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) {
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;
}
});