From 37107e83e198ab44144bb457d9e799b9dff08e71 Mon Sep 17 00:00:00 2001 From: Andrew Ferguson Date: Thu, 12 Jul 2007 09:58:54 +0000 Subject: [PATCH] 196279: apply fix for NPE on function elements --- .../cdt/core/browser/IndexTypeInfo.java | 30 +++++++++++-------- .../internal/ui/search/PDOMSearchElement.java | 5 ++-- .../internal/ui/search/PDOMSearchMatch.java | 5 ++-- .../internal/ui/search/PDOMSearchQuery.java | 2 +- 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/IndexTypeInfo.java b/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/IndexTypeInfo.java index eca02042eac..2185abf19e8 100644 --- a/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/IndexTypeInfo.java +++ b/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/core/browser/IndexTypeInfo.java @@ -39,6 +39,7 @@ import org.eclipse.core.filesystem.URIUtil; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.NullProgressMonitor; @@ -58,6 +59,8 @@ public class IndexTypeInfo implements ITypeInfo, IFunctionInfo { /** * Creates a typeinfo suitable for the binding. + * @param index a non-null index in which to locate references + * @param binding * @since 4.0.1 */ public static IndexTypeInfo create(IIndex index, IIndexBinding binding) { @@ -80,7 +83,7 @@ public class IndexTypeInfo implements ITypeInfo, IFunctionInfo { final IFunction function= (IFunction)binding; final String[] paramTypes= IndexModelUtil.extractParameterTypes(function); final String returnType= IndexModelUtil.extractReturnType(function); - return new IndexTypeInfo(fqn, elementType, paramTypes, returnType, null); + return new IndexTypeInfo(fqn, elementType, paramTypes, returnType, index); } } catch (DOMException e) { // index bindings don't throw DOMExceptions. @@ -90,31 +93,32 @@ public class IndexTypeInfo implements ITypeInfo, IFunctionInfo { return new IndexTypeInfo(fqn, elementType, index); } + private IndexTypeInfo(String[] fqn, int elementType, IIndex index, String[] params, String returnType, ITypeReference reference) { + Assert.isTrue(index != null); + this.fqn= fqn; + this.elementType= elementType; + this.index= index; + this.params= params; + this.returnType= returnType; + this.reference= reference; + } + /** * @deprecated, use {@link #create(IIndex, IBinding)}. */ public IndexTypeInfo(String[] fqn, int elementType, IIndex index) { - this.fqn = fqn; - this.elementType = elementType; - this.index = index; - this.params= null; - this.returnType= null; + this(fqn, elementType, index, null, null, null); } /** * @deprecated, use {@link #create(IIndex, IBinding)}. */ public IndexTypeInfo(String[] fqn, int elementType, String[] params, String returnType, IIndex index) { - this.fqn = fqn; - this.elementType = elementType; - this.params= params; - this.returnType= returnType; - this.index = index; + this(fqn, elementType, index, params, returnType, null); } public IndexTypeInfo(IndexTypeInfo rhs, ITypeReference ref) { - this(rhs.fqn, rhs.elementType, rhs.params, rhs.returnType, rhs.index); - this.reference= ref; + this(rhs.fqn, rhs.elementType, rhs.index, rhs.params, rhs.returnType, ref); } public void addDerivedReference(ITypeReference location) { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchElement.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchElement.java index 25938a15f27..51f0536610a 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchElement.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchElement.java @@ -17,6 +17,7 @@ import org.eclipse.core.runtime.Path; import org.eclipse.cdt.core.browser.ITypeInfo; import org.eclipse.cdt.core.browser.IndexTypeInfo; +import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IIndexName; @@ -30,8 +31,8 @@ public class PDOMSearchElement { private final ITypeInfo typeInfo; private final String filename; - public PDOMSearchElement(IIndexName name, IIndexBinding binding) throws CoreException { - this.typeInfo= IndexTypeInfo.create(null, binding); + public PDOMSearchElement(IIndex index, IIndexName name, IIndexBinding binding) throws CoreException { + this.typeInfo= IndexTypeInfo.create(index, binding); filename = new Path(name.getFileLocation().getFileName()).toOSString(); } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchMatch.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchMatch.java index bc90f99899c..557bcadf512 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchMatch.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchMatch.java @@ -15,6 +15,7 @@ package org.eclipse.cdt.internal.ui.search; import org.eclipse.core.runtime.CoreException; import org.eclipse.search.ui.text.Match; +import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IIndexName; @@ -24,8 +25,8 @@ import org.eclipse.cdt.core.index.IIndexName; */ public class PDOMSearchMatch extends Match { - public PDOMSearchMatch(IIndexBinding binding, IIndexName name, int offset, int length) throws CoreException { - super(new PDOMSearchElement(name, binding), offset, length); + public PDOMSearchMatch(IIndex index, IIndexBinding binding, IIndexName name, int offset, int length) throws CoreException { + super(new PDOMSearchElement(index, name, binding), offset, length); } public String getFileName() throws CoreException { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchQuery.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchQuery.java index 05f0f81121a..b58b349d0e9 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchQuery.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchQuery.java @@ -115,7 +115,7 @@ public abstract class PDOMSearchQuery implements ISearchQuery { if (!filterName(name)) { IASTFileLocation loc = name.getFileLocation(); IIndexBinding binding= index.findBinding(name); - result.addMatch(new PDOMSearchMatch(binding, name, loc.getNodeOffset(), loc.getNodeLength())); + result.addMatch(new PDOMSearchMatch(index, binding, name, loc.getNodeOffset(), loc.getNodeLength())); } } }