refactoring

extracted method 'isMaximallySpecific'
This commit is contained in:
Svetlana Isakova
2013-07-16 19:55:44 +04:00
parent f5a11960cd
commit 3f782523a7
@@ -20,10 +20,7 @@ import gnu.trove.THashSet;
import gnu.trove.TObjectHashingStrategy; import gnu.trove.TObjectHashingStrategy;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.CallableDescriptor; import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.descriptors.ReceiverParameterDescriptor;
import org.jetbrains.jet.lang.descriptors.ScriptDescriptor;
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
import org.jetbrains.jet.lang.resolve.DescriptorUtils; import org.jetbrains.jet.lang.resolve.DescriptorUtils;
import org.jetbrains.jet.lang.resolve.OverridingUtil; import org.jetbrains.jet.lang.resolve.OverridingUtil;
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCallWithTrace; import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCallWithTrace;
@@ -58,21 +55,30 @@ public class OverloadingConflictResolver {
return object == null ? 0 : object.getResultingDescriptor().hashCode(); return object == null ? 0 : object.getResultingDescriptor().hashCode();
} }
}); });
meLoop:
for (ResolvedCallWithTrace<D> candidateCall : candidates) { for (ResolvedCallWithTrace<D> candidateCall : candidates) {
D me = candidateCall.getResultingDescriptor(); if (isMaximallySpecific(candidateCall, candidates, discriminateGenericDescriptors)) {
for (ResolvedCallWithTrace<D> otherCall : candidates) { maximallySpecific.add(candidateCall);
D other = otherCall.getResultingDescriptor();
if (other == me) continue;
if (!moreSpecific(me, other, discriminateGenericDescriptors) || moreSpecific(other, me, discriminateGenericDescriptors)) {
continue meLoop;
}
} }
maximallySpecific.add(candidateCall);
} }
return maximallySpecific.size() == 1 ? maximallySpecific.iterator().next() : null; return maximallySpecific.size() == 1 ? maximallySpecific.iterator().next() : null;
} }
private <D extends CallableDescriptor> boolean isMaximallySpecific(
@NotNull ResolvedCallWithTrace<D> candidateCall,
@NotNull Set<ResolvedCallWithTrace<D>> candidates,
boolean discriminateGenericDescriptors
) {
D me = candidateCall.getResultingDescriptor();
for (ResolvedCallWithTrace<D> otherCall : candidates) {
D other = otherCall.getResultingDescriptor();
if (other == me) continue;
if (!moreSpecific(me, other, discriminateGenericDescriptors) || moreSpecific(other, me, discriminateGenericDescriptors)) {
return false;
}
}
return true;
}
/** /**
* Let < mean "more specific" * Let < mean "more specific"
* Subtype < supertype * Subtype < supertype