1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +02:00

Fixed NPE in AbstractCompositeFactory.java

This commit is contained in:
Sergey Prigogin 2011-06-24 18:58:58 -07:00
parent b5b6ad368e
commit 7170b3a515

View file

@ -43,16 +43,6 @@ public abstract class AbstractCompositeFactory implements ICompositesFactory {
);
}
/*
* @see org.eclipse.cdt.internal.core.index.composite.ICompositesFactory#getCompositeBindings(org.eclipse.cdt.core.index.IIndex, org.eclipse.cdt.internal.core.index.IIndexFragmentBinding[])
*/
public final IIndexBinding[] getCompositeBindings(IIndexFragmentBinding[] bindings) {
IIndexBinding[] result = new IIndexBinding[bindings.length];
for(int i=0; i<result.length; i++)
result[i] = getCompositeBinding(bindings[i]);
return result;
}
protected final IType[] getCompositeTypes(IType[] types) {
// Don't create a new array until it's really needed.
IType[] result = types;
@ -71,13 +61,20 @@ public abstract class AbstractCompositeFactory implements ICompositesFactory {
return result;
}
/*
* @see org.eclipse.cdt.internal.core.index.composite.cpp.ICompositesFactory#getComposites(org.eclipse.cdt.core.index.IIndex, org.eclipse.cdt.internal.core.index.IIndexFragmentBinding[][])
/**
* @see ICompositesFactory#getCompositeBindings(IIndexFragmentBinding[][])
*/
public final IIndexBinding[] getCompositeBindings(IIndexFragmentBinding[][] fragmentBindings) {
return getCompositeBindings(mergeBindingArrays(fragmentBindings));
}
private final IIndexBinding[] getCompositeBindings(IIndexFragmentBinding[] bindings) {
IIndexBinding[] result = new IIndexBinding[bindings.length];
for (int i = 0; i < result.length; i++)
result[i] = getCompositeBinding(bindings[i]);
return result;
}
public final IIndexFragmentBinding[] findEquivalentBindings(IBinding binding) {
CIndex cindex= (CIndex) index;
try {
@ -96,9 +93,13 @@ public abstract class AbstractCompositeFactory implements ICompositesFactory {
*/
protected IIndexFragmentBinding[] mergeBindingArrays(IIndexFragmentBinding[][] fragmentBindings) {
TreeSet<IIndexFragmentBinding> ts = new TreeSet<IIndexFragmentBinding>(fragmentComparator);
for (IIndexFragmentBinding[] fragmentBinding : fragmentBindings)
for (IIndexFragmentBinding element : fragmentBinding)
for (IIndexFragmentBinding[] array : fragmentBindings) {
if (array != null) {
for (IIndexFragmentBinding element : array) {
ts.add(element);
}
}
}
return ts.toArray(new IIndexFragmentBinding[ts.size()]);
}
@ -115,8 +116,8 @@ public abstract class AbstractCompositeFactory implements ICompositesFactory {
protected IIndexFragmentBinding findOneBinding(IBinding binding, boolean allowDeclaration) {
try {
IIndexFragmentBinding[] ibs= findEquivalentBindings(binding);
IBinding def= null;
IBinding dec= ibs.length>0 ? ibs[0] : null;
IIndexFragmentBinding def= null;
IIndexFragmentBinding dec= ibs.length > 0 ? ibs[0] : null;
for (IIndexFragmentBinding ib : ibs) {
if (ib.hasDefinition()) {
def= ib;
@ -124,9 +125,9 @@ public abstract class AbstractCompositeFactory implements ICompositesFactory {
dec= ib;
}
}
return (IIndexFragmentBinding) (def == null ? dec : def);
} catch(CoreException ce) {
CCorePlugin.log(ce);
return def == null ? dec : def;
} catch (CoreException e) {
CCorePlugin.log(e);
}
throw new CompositingNotImplementedError();
}