From 3340b94bd82e5ea72c1959314c04e796e652904a Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Thu, 13 Jun 2013 20:35:34 +0400 Subject: [PATCH] refactoring extracted methods --- .../results/ResolutionResultsHandler.java | 156 +++++++++--------- 1 file changed, 82 insertions(+), 74 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/results/ResolutionResultsHandler.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/results/ResolutionResultsHandler.java index 6a539962ed8..a427b80640e 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/results/ResolutionResultsHandler.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/results/ResolutionResultsHandler.java @@ -57,85 +57,13 @@ public class ResolutionResultsHandler { failedCandidates.add(candidateCall); } } - return computeResultAndReportErrors(trace, tracing, successfulCandidates, failedCandidates, incompleteCandidates); - } - - @NotNull - private OverloadResolutionResultsImpl computeResultAndReportErrors( - @NotNull BindingTrace trace, - @NotNull TracingStrategy tracing, - @NotNull Set> successfulCandidates, - @NotNull Set> failedCandidates, - @NotNull Set> incompleteCandidates - ) { // TODO : maybe it's better to filter overrides out first, and only then look for the maximally specific if (!successfulCandidates.isEmpty() || !incompleteCandidates.isEmpty()) { - Set> successfulAndIncomplete = Sets.newLinkedHashSet(); - successfulAndIncomplete.addAll(successfulCandidates); - successfulAndIncomplete.addAll(incompleteCandidates); - OverloadResolutionResultsImpl results = chooseAndReportMaximallySpecific(successfulAndIncomplete, true); - if (results.isSingleResult()) { - ResolvedCallWithTrace resultingCall = results.getResultingCall(); - resultingCall.getTrace().moveAllMyDataTo(trace); - if (resultingCall.getStatus() == INCOMPLETE_TYPE_INFERENCE) { - return OverloadResolutionResultsImpl.incompleteTypeInference(resultingCall); - } - } - if (results.isAmbiguity()) { - tracing.recordAmbiguity(trace, results.getResultingCalls()); - if (allIncomplete(results.getResultingCalls())) { - tracing.cannotCompleteResolve(trace, results.getResultingCalls()); - return OverloadResolutionResultsImpl.incompleteTypeInference(results.getResultingCalls()); - } - // This check is needed for the following case: - // x.foo(unresolved) -- if there are multiple foo's, we'd report an ambiguity, and it does not make sense here - if (allClean(results.getResultingCalls())) { - tracing.ambiguity(trace, results.getResultingCalls()); - } - } - return results; + return computeSuccessfulResult(trace, tracing, successfulCandidates, incompleteCandidates); } else if (!failedCandidates.isEmpty()) { - if (failedCandidates.size() != 1) { - // 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" - // Used to be: weak errors. Generalized for future extensions - for (EnumSet severityLevel : SEVERITY_LEVELS) { - Set> thisLevel = Sets.newLinkedHashSet(); - for (ResolvedCallWithTrace candidate : failedCandidates) { - if (severityLevel.contains(candidate.getStatus())) { - thisLevel.add(candidate); - } - } - if (!thisLevel.isEmpty()) { - OverloadResolutionResultsImpl results = chooseAndReportMaximallySpecific(thisLevel, false); - if (results.isSingleResult()) { - results.getResultingCall().getTrace().moveAllMyDataTo(trace); - return OverloadResolutionResultsImpl.singleFailedCandidate(results.getResultingCall()); - } - - tracing.noneApplicable(trace, results.getResultingCalls()); - tracing.recordAmbiguity(trace, results.getResultingCalls()); - return OverloadResolutionResultsImpl.manyFailedCandidates(results.getResultingCalls()); - } - } - - assert false : "Should not be reachable, cause every status must belong to some level"; - - Set> noOverrides = OverridingUtil.filterOverrides(failedCandidates, MAP_TO_CANDIDATE); - if (noOverrides.size() != 1) { - tracing.noneApplicable(trace, noOverrides); - tracing.recordAmbiguity(trace, noOverrides); - return OverloadResolutionResultsImpl.manyFailedCandidates(noOverrides); - } - - failedCandidates = noOverrides; - } - - ResolvedCallWithTrace failed = failedCandidates.iterator().next(); - failed.getTrace().moveAllMyDataTo(trace); - return OverloadResolutionResultsImpl.singleFailedCandidate(failed); + return computeFailedResult(trace, tracing, failedCandidates); } else { tracing.unresolvedReference(trace); @@ -143,6 +71,86 @@ public class ResolutionResultsHandler { } } + @NotNull + private OverloadResolutionResultsImpl computeSuccessfulResult( + BindingTrace trace, + TracingStrategy tracing, + Set> successfulCandidates, + Set> incompleteCandidates + ) { + Set> successfulAndIncomplete = Sets.newLinkedHashSet(); + successfulAndIncomplete.addAll(successfulCandidates); + successfulAndIncomplete.addAll(incompleteCandidates); + OverloadResolutionResultsImpl results = chooseAndReportMaximallySpecific(successfulAndIncomplete, true); + if (results.isSingleResult()) { + ResolvedCallWithTrace resultingCall = results.getResultingCall(); + resultingCall.getTrace().moveAllMyDataTo(trace); + if (resultingCall.getStatus() == INCOMPLETE_TYPE_INFERENCE) { + return OverloadResolutionResultsImpl.incompleteTypeInference(resultingCall); + } + } + if (results.isAmbiguity()) { + tracing.recordAmbiguity(trace, results.getResultingCalls()); + if (allIncomplete(results.getResultingCalls())) { + tracing.cannotCompleteResolve(trace, results.getResultingCalls()); + return OverloadResolutionResultsImpl.incompleteTypeInference(results.getResultingCalls()); + } + // This check is needed for the following case: + // x.foo(unresolved) -- if there are multiple foo's, we'd report an ambiguity, and it does not make sense here + if (allClean(results.getResultingCalls())) { + tracing.ambiguity(trace, results.getResultingCalls()); + } + } + return results; + } + + @NotNull + private OverloadResolutionResultsImpl computeFailedResult( + BindingTrace trace, + TracingStrategy tracing, + Set> failedCandidates + ) { + if (failedCandidates.size() != 1) { + // 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" + // Used to be: weak errors. Generalized for future extensions + for (EnumSet severityLevel : SEVERITY_LEVELS) { + Set> thisLevel = Sets.newLinkedHashSet(); + for (ResolvedCallWithTrace candidate : failedCandidates) { + if (severityLevel.contains(candidate.getStatus())) { + thisLevel.add(candidate); + } + } + if (!thisLevel.isEmpty()) { + OverloadResolutionResultsImpl results = chooseAndReportMaximallySpecific(thisLevel, false); + if (results.isSingleResult()) { + results.getResultingCall().getTrace().moveAllMyDataTo(trace); + return OverloadResolutionResultsImpl.singleFailedCandidate(results.getResultingCall()); + } + + tracing.noneApplicable(trace, results.getResultingCalls()); + tracing.recordAmbiguity(trace, results.getResultingCalls()); + return OverloadResolutionResultsImpl.manyFailedCandidates(results.getResultingCalls()); + } + } + + assert false : "Should not be reachable, cause every status must belong to some level"; + + Set> noOverrides = OverridingUtil.filterOverrides(failedCandidates, MAP_TO_CANDIDATE); + if (noOverrides.size() != 1) { + tracing.noneApplicable(trace, noOverrides); + tracing.recordAmbiguity(trace, noOverrides); + return OverloadResolutionResultsImpl.manyFailedCandidates(noOverrides); + } + + failedCandidates = noOverrides; + } + + ResolvedCallWithTrace failed = failedCandidates.iterator().next(); + failed.getTrace().moveAllMyDataTo(trace); + return OverloadResolutionResultsImpl.singleFailedCandidate(failed); + } + private static boolean allClean(@NotNull Collection> results) { for (ResolvedCallWithTrace result : results) { if (result.isDirty()) return false;