mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 17:05:26 +02:00
196279: apply fix for NPE on function elements
This commit is contained in:
parent
3368b94eb8
commit
37107e83e1
4 changed files with 24 additions and 18 deletions
|
@ -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) {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue