From 363f066567cf6d6a1e206e245bf921b8c635b842 Mon Sep 17 00:00:00 2001 From: Doug Schaefer Date: Fri, 1 Apr 2005 20:12:41 +0000 Subject: [PATCH] Fixed an NPE when resolving prefix on a name that isn't properly hooked up in the AST. This usually occurs when a backtrack happens and the AST branch is cut off. --- .../eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNode.java | 5 ++--- .../ui/text/contentassist/DOMCompletionContributor.java | 3 +++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNode.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNode.java index 751128bb8ca..74d44d54a76 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNode.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNode.java @@ -30,10 +30,9 @@ public class CPPASTNode extends ASTNode implements IASTNode { public IASTTranslationUnit getTranslationUnit() { if( this instanceof IASTTranslationUnit ) return (IASTTranslationUnit) this; IASTNode node = getParent(); - while( ! (node instanceof IASTTranslationUnit )) - { + while(node != null && !(node instanceof IASTTranslationUnit)) node = node.getParent(); - } + return (IASTTranslationUnit) node; } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/DOMCompletionContributor.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/DOMCompletionContributor.java index 84283b6ff02..b290e075116 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/DOMCompletionContributor.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/DOMCompletionContributor.java @@ -52,6 +52,9 @@ public class DOMCompletionContributor implements ICompletionContributor { // Find all bindings List allBindings = new ArrayList(); for (int i = 0; i < names.length; ++i) { + if (names[i].getTranslationUnit() == null) + // The node isn't properly hooked up, must have backtracked out of this node + continue; IBinding[] bindings = names[i].resolvePrefix(); if (bindings != null) for (int j = 0; j < bindings.length; ++j) {