refactoring

extracted methods
This commit is contained in:
Svetlana Isakova
2013-06-13 20:35:34 +04:00
parent 342e9ebe7a
commit 3340b94bd8
@@ -57,20 +57,27 @@ public class ResolutionResultsHandler {
failedCandidates.add(candidateCall); failedCandidates.add(candidateCall);
} }
} }
return computeResultAndReportErrors(trace, tracing, successfulCandidates, failedCandidates, incompleteCandidates);
}
@NotNull
private <D extends CallableDescriptor> OverloadResolutionResultsImpl<D> computeResultAndReportErrors(
@NotNull BindingTrace trace,
@NotNull TracingStrategy tracing,
@NotNull Set<ResolvedCallWithTrace<D>> successfulCandidates,
@NotNull Set<ResolvedCallWithTrace<D>> failedCandidates,
@NotNull Set<ResolvedCallWithTrace<D>> incompleteCandidates
) {
// TODO : maybe it's better to filter overrides out first, and only then look for the maximally specific // TODO : maybe it's better to filter overrides out first, and only then look for the maximally specific
if (!successfulCandidates.isEmpty() || !incompleteCandidates.isEmpty()) { if (!successfulCandidates.isEmpty() || !incompleteCandidates.isEmpty()) {
return computeSuccessfulResult(trace, tracing, successfulCandidates, incompleteCandidates);
}
else if (!failedCandidates.isEmpty()) {
return computeFailedResult(trace, tracing, failedCandidates);
}
else {
tracing.unresolvedReference(trace);
return OverloadResolutionResultsImpl.nameNotFound();
}
}
@NotNull
private <D extends CallableDescriptor> OverloadResolutionResultsImpl<D> computeSuccessfulResult(
BindingTrace trace,
TracingStrategy tracing,
Set<ResolvedCallWithTrace<D>> successfulCandidates,
Set<ResolvedCallWithTrace<D>> incompleteCandidates
) {
Set<ResolvedCallWithTrace<D>> successfulAndIncomplete = Sets.newLinkedHashSet(); Set<ResolvedCallWithTrace<D>> successfulAndIncomplete = Sets.newLinkedHashSet();
successfulAndIncomplete.addAll(successfulCandidates); successfulAndIncomplete.addAll(successfulCandidates);
successfulAndIncomplete.addAll(incompleteCandidates); successfulAndIncomplete.addAll(incompleteCandidates);
@@ -96,7 +103,13 @@ public class ResolutionResultsHandler {
} }
return results; return results;
} }
else if (!failedCandidates.isEmpty()) {
@NotNull
private <D extends CallableDescriptor> OverloadResolutionResultsImpl<D> computeFailedResult(
BindingTrace trace,
TracingStrategy tracing,
Set<ResolvedCallWithTrace<D>> failedCandidates
) {
if (failedCandidates.size() != 1) { if (failedCandidates.size() != 1) {
// This is needed when there are several overloads some of which are OK but for nullability of the receiver, // This is needed when there are several overloads some of which are OK but for nullability of the receiver,
// and some are not OK at all. In this case we'd like to say "unsafe call" rather than "none applicable" // and some are not OK at all. In this case we'd like to say "unsafe call" rather than "none applicable"
@@ -137,11 +150,6 @@ public class ResolutionResultsHandler {
failed.getTrace().moveAllMyDataTo(trace); failed.getTrace().moveAllMyDataTo(trace);
return OverloadResolutionResultsImpl.singleFailedCandidate(failed); return OverloadResolutionResultsImpl.singleFailedCandidate(failed);
} }
else {
tracing.unresolvedReference(trace);
return OverloadResolutionResultsImpl.nameNotFound();
}
}
private static <D extends CallableDescriptor> boolean allClean(@NotNull Collection<ResolvedCallWithTrace<D>> results) { private static <D extends CallableDescriptor> boolean allClean(@NotNull Collection<ResolvedCallWithTrace<D>> results) {
for (ResolvedCallWithTrace<D> result : results) { for (ResolvedCallWithTrace<D> result : results) {