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) { protected final IType[] getCompositeTypes(IType[] types) {
// Don't create a new array until it's really needed. // Don't create a new array until it's really needed.
IType[] result = types; IType[] result = types;
@ -71,13 +61,20 @@ public abstract class AbstractCompositeFactory implements ICompositesFactory {
return result; 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) { public final IIndexBinding[] getCompositeBindings(IIndexFragmentBinding[][] fragmentBindings) {
return getCompositeBindings(mergeBindingArrays(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) { public final IIndexFragmentBinding[] findEquivalentBindings(IBinding binding) {
CIndex cindex= (CIndex) index; CIndex cindex= (CIndex) index;
try { try {
@ -96,9 +93,13 @@ public abstract class AbstractCompositeFactory implements ICompositesFactory {
*/ */
protected IIndexFragmentBinding[] mergeBindingArrays(IIndexFragmentBinding[][] fragmentBindings) { protected IIndexFragmentBinding[] mergeBindingArrays(IIndexFragmentBinding[][] fragmentBindings) {
TreeSet<IIndexFragmentBinding> ts = new TreeSet<IIndexFragmentBinding>(fragmentComparator); TreeSet<IIndexFragmentBinding> ts = new TreeSet<IIndexFragmentBinding>(fragmentComparator);
for (IIndexFragmentBinding[] fragmentBinding : fragmentBindings) for (IIndexFragmentBinding[] array : fragmentBindings) {
for (IIndexFragmentBinding element : fragmentBinding) if (array != null) {
for (IIndexFragmentBinding element : array) {
ts.add(element); ts.add(element);
}
}
}
return ts.toArray(new IIndexFragmentBinding[ts.size()]); return ts.toArray(new IIndexFragmentBinding[ts.size()]);
} }
@ -113,20 +114,20 @@ public abstract class AbstractCompositeFactory implements ICompositesFactory {
* @return the representative binding as defined above * @return the representative binding as defined above
*/ */
protected IIndexFragmentBinding findOneBinding(IBinding binding, boolean allowDeclaration) { protected IIndexFragmentBinding findOneBinding(IBinding binding, boolean allowDeclaration) {
try{ try {
IIndexFragmentBinding[] ibs= findEquivalentBindings(binding); IIndexFragmentBinding[] ibs= findEquivalentBindings(binding);
IBinding def= null; IIndexFragmentBinding def= null;
IBinding dec= ibs.length>0 ? ibs[0] : null; IIndexFragmentBinding dec= ibs.length > 0 ? ibs[0] : null;
for (IIndexFragmentBinding ib : ibs) { for (IIndexFragmentBinding ib : ibs) {
if(ib.hasDefinition()) { if (ib.hasDefinition()) {
def= ib; def= ib;
} else if(allowDeclaration && ib.hasDeclaration()) { } else if (allowDeclaration && ib.hasDeclaration()) {
dec= ib; dec= ib;
} }
} }
return (IIndexFragmentBinding) (def == null ? dec : def); return def == null ? dec : def;
} catch(CoreException ce) { } catch (CoreException e) {
CCorePlugin.log(ce); CCorePlugin.log(e);
} }
throw new CompositingNotImplementedError(); throw new CompositingNotImplementedError();
} }
@ -141,7 +142,7 @@ public abstract class AbstractCompositeFactory implements ICompositesFactory {
public int compare(IIndexFragmentBinding f1, IIndexFragmentBinding f2) { public int compare(IIndexFragmentBinding f1, IIndexFragmentBinding f2) {
for (IIndexFragmentBindingComparator comparator : comparators) { for (IIndexFragmentBindingComparator comparator : comparators) {
int cmp= comparator.compare(f1, f2); int cmp= comparator.compare(f1, f2);
if(cmp!=Integer.MIN_VALUE) { if (cmp != Integer.MIN_VALUE) {
return cmp; return cmp;
} }
} }