From 28526afbdeb1c0d0b235591f1aeaf2717a18205d Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Mon, 30 Apr 2012 15:07:15 +0400 Subject: [PATCH] interface ResolvedCallWithTrace added --- .../calls/OverloadResolutionResultsImpl.java | 18 ++++++------ .../calls/OverloadResolutionResultsUtil.java | 6 ++-- .../calls/OverloadingConflictResolver.java | 14 +++++----- .../lang/resolve/calls/ResolvedCallImpl.java | 28 +++++++++---------- ...itizer.java => ResolvedCallWithTrace.java} | 16 ++++------- .../lang/resolve/calls/TracingStrategy.java | 17 +++++------ 6 files changed, 48 insertions(+), 51 deletions(-) rename compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/{MemberPrioritizer.java => ResolvedCallWithTrace.java} (64%) diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/OverloadResolutionResultsImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/OverloadResolutionResultsImpl.java index 5e90d79d572..6487e96c36c 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/OverloadResolutionResultsImpl.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/OverloadResolutionResultsImpl.java @@ -27,42 +27,42 @@ import java.util.Collections; */ /*package*/ class OverloadResolutionResultsImpl implements OverloadResolutionResults { - public static OverloadResolutionResultsImpl success(@NotNull ResolvedCallImpl descriptor) { + public static OverloadResolutionResultsImpl success(@NotNull ResolvedCallWithTrace descriptor) { return new OverloadResolutionResultsImpl(Code.SUCCESS, Collections.singleton(descriptor)); } public static OverloadResolutionResultsImpl nameNotFound() { - return new OverloadResolutionResultsImpl(Code.NAME_NOT_FOUND, Collections.>emptyList()); + return new OverloadResolutionResultsImpl(Code.NAME_NOT_FOUND, Collections.>emptyList()); } - public static OverloadResolutionResultsImpl singleFailedCandidate(ResolvedCallImpl candidate) { + public static OverloadResolutionResultsImpl singleFailedCandidate(ResolvedCallWithTrace candidate) { return new OverloadResolutionResultsImpl(Code.SINGLE_CANDIDATE_ARGUMENT_MISMATCH, Collections.singleton(candidate)); } - public static OverloadResolutionResultsImpl manyFailedCandidates(Collection> failedCandidates) { + public static OverloadResolutionResultsImpl manyFailedCandidates(Collection> failedCandidates) { return new OverloadResolutionResultsImpl(Code.MANY_FAILED_CANDIDATES, failedCandidates); } - public static OverloadResolutionResultsImpl ambiguity(Collection> descriptors) { + public static OverloadResolutionResultsImpl ambiguity(Collection> descriptors) { return new OverloadResolutionResultsImpl(Code.AMBIGUITY, descriptors); } - private final Collection> results; + private final Collection> results; private final Code resultCode; - private OverloadResolutionResultsImpl(@NotNull Code resultCode, @NotNull Collection> results) { + private OverloadResolutionResultsImpl(@NotNull Code resultCode, @NotNull Collection> results) { this.results = results; this.resultCode = resultCode; } @Override @NotNull - public Collection> getResultingCalls() { + public Collection> getResultingCalls() { return results; } @Override @NotNull - public ResolvedCallImpl getResultingCall() { + public ResolvedCallWithTrace getResultingCall() { assert isSingleResult(); return results.iterator().next(); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/OverloadResolutionResultsUtil.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/OverloadResolutionResultsUtil.java index 44e46111f33..07d259f9f5c 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/OverloadResolutionResultsUtil.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/OverloadResolutionResultsUtil.java @@ -30,9 +30,9 @@ import java.util.Collection; public class OverloadResolutionResultsUtil { @NotNull public static OverloadResolutionResults ambiguity(OverloadResolutionResults results1, OverloadResolutionResults results2) { - Collection> resultingCalls = Lists.newArrayList(); - resultingCalls.addAll((Collection>) results1.getResultingCalls()); - resultingCalls.addAll((Collection>) results2.getResultingCalls()); + Collection> resultingCalls = Lists.newArrayList(); + resultingCalls.addAll((Collection>) results1.getResultingCalls()); + resultingCalls.addAll((Collection>) results2.getResultingCalls()); return OverloadResolutionResultsImpl.ambiguity(resultingCalls); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/OverloadingConflictResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/OverloadingConflictResolver.java index 1edce3205fa..360e117c08c 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/OverloadingConflictResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/OverloadingConflictResolver.java @@ -39,23 +39,23 @@ import java.util.Set; public class OverloadingConflictResolver { @Nullable - public ResolvedCallImpl findMaximallySpecific(Set> candidates, boolean discriminateGenericDescriptors) { + public ResolvedCallWithTrace findMaximallySpecific(Set> candidates, boolean discriminateGenericDescriptors) { // Different autocasts may lead to the same candidate descriptor wrapped into different ResolvedCallImpl objects - Set> maximallySpecific = new THashSet>(new TObjectHashingStrategy>() { + Set> maximallySpecific = new THashSet>(new TObjectHashingStrategy>() { @Override - public boolean equals(ResolvedCallImpl o1, ResolvedCallImpl o2) { + public boolean equals(ResolvedCallWithTrace o1, ResolvedCallWithTrace o2) { return o1 == null ? o2 == null : o1.getResultingDescriptor().equals(o2.getResultingDescriptor()); } @Override - public int computeHashCode(ResolvedCallImpl object) { + public int computeHashCode(ResolvedCallWithTrace object) { return object == null ? 0 : object.getResultingDescriptor().hashCode(); } }); meLoop: - for (ResolvedCallImpl candidateCall : candidates) { + for (ResolvedCallWithTrace candidateCall : candidates) { D me = candidateCall.getResultingDescriptor(); - for (ResolvedCallImpl otherCall : candidates) { + for (ResolvedCallWithTrace otherCall : candidates) { D other = otherCall.getResultingDescriptor(); if (other == me) continue; if (!moreSpecific(me, other, discriminateGenericDescriptors) || moreSpecific(other, me, discriminateGenericDescriptors)) { @@ -65,7 +65,7 @@ public class OverloadingConflictResolver { maximallySpecific.add(candidateCall); } if (maximallySpecific.size() == 1) { - ResolvedCallImpl result = maximallySpecific.iterator().next(); + ResolvedCallWithTrace result = maximallySpecific.iterator().next(); result.getTrace().commit(); return result; } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/ResolvedCallImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/ResolvedCallImpl.java index 2bf2516e751..e6399ea151d 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/ResolvedCallImpl.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/ResolvedCallImpl.java @@ -16,7 +16,6 @@ package org.jetbrains.jet.lang.resolve.calls; -import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.intellij.util.Function; import org.jetbrains.annotations.NotNull; @@ -28,7 +27,6 @@ import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor; import org.jetbrains.jet.lang.types.JetType; import java.util.ArrayList; -import java.util.Collection; import java.util.List; import java.util.Map; @@ -37,25 +35,30 @@ import static org.jetbrains.jet.lang.resolve.calls.ResolutionStatus.UNKNOWN_STAT /** * @author abreslav */ -public class ResolvedCallImpl implements ResolvedCall { +public class ResolvedCallImpl implements ResolvedCallWithTrace { - public static final Function, CallableDescriptor> MAP_TO_CANDIDATE = new Function, CallableDescriptor>() { + public static final Function, CallableDescriptor> MAP_TO_CANDIDATE = new Function, CallableDescriptor>() { @Override - public CallableDescriptor fun(ResolvedCallImpl resolvedCall) { + public CallableDescriptor fun(ResolvedCallWithTrace resolvedCall) { return resolvedCall.getCandidateDescriptor(); } }; - public static final Function, CallableDescriptor> MAP_TO_RESULT = new Function, CallableDescriptor>() { + public static final Function, CallableDescriptor> MAP_TO_RESULT = new Function, CallableDescriptor>() { @Override - public CallableDescriptor fun(ResolvedCallImpl resolvedCall) { + public CallableDescriptor fun(ResolvedCallWithTrace resolvedCall) { return resolvedCall.getResultingDescriptor(); } }; @NotNull - public static ResolvedCallImpl create(@NotNull ResolutionCandidate candidate) { - return new ResolvedCallImpl(candidate.getDescriptor(), candidate.getThisObject(), candidate.getReceiverArgument()); + public static ResolvedCallImpl create(@NotNull ResolutionCandidate candidate, @NotNull TemporaryBindingTrace trace) { + return create(candidate.getDescriptor(), candidate.getThisObject(), candidate.getReceiverArgument(), trace); + } + + @NotNull + public static ResolvedCallImpl create(@NotNull D descriptor, @NotNull ReceiverDescriptor thisObject, @NotNull ReceiverDescriptor receiverArgument, @NotNull TemporaryBindingTrace trace) { + return new ResolvedCallImpl(descriptor, thisObject, receiverArgument, trace); } private final D candidateDescriptor; @@ -70,10 +73,11 @@ public class ResolvedCallImpl implements ResolvedC private TemporaryBindingTrace trace; private ResolutionStatus status = UNKNOWN_STATUS; - private ResolvedCallImpl(@NotNull D candidateDescriptor, @NotNull ReceiverDescriptor thisObject, @NotNull ReceiverDescriptor receiverArgument) { + private ResolvedCallImpl(@NotNull D candidateDescriptor, @NotNull ReceiverDescriptor thisObject, @NotNull ReceiverDescriptor receiverArgument, @NotNull TemporaryBindingTrace trace) { this.candidateDescriptor = candidateDescriptor; this.thisObject = thisObject; this.receiverArgument = receiverArgument; + this.trace = trace; } @NotNull @@ -90,10 +94,6 @@ public class ResolvedCallImpl implements ResolvedC return trace; } - public void setTrace(@NotNull TemporaryBindingTrace trace) { - this.trace = trace; - } - @Override @NotNull public D getCandidateDescriptor() { diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/MemberPrioritizer.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/ResolvedCallWithTrace.java similarity index 64% rename from compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/MemberPrioritizer.java rename to compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/ResolvedCallWithTrace.java index 14dace99c4d..ae3d5798dbd 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/MemberPrioritizer.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/ResolvedCallWithTrace.java @@ -18,21 +18,17 @@ package org.jetbrains.jet.lang.resolve.calls; import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.lang.descriptors.CallableDescriptor; -import org.jetbrains.jet.lang.resolve.scopes.JetScope; -import org.jetbrains.jet.lang.types.JetType; - -import java.util.Collection; +import org.jetbrains.jet.lang.resolve.TemporaryBindingTrace; /** * @author svtk */ -public interface MemberPrioritizer { - @NotNull - Collection getNonExtensionsByName(JetScope scope, String name); +public interface ResolvedCallWithTrace extends ResolvedCall { @NotNull - Collection getMembersByName(@NotNull JetType receiver, String name); + ResolutionStatus getStatus(); - @NotNull - Collection getExtensionsByName(JetScope scope, String name); + boolean isDirty(); + + TemporaryBindingTrace getTrace(); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/TracingStrategy.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/TracingStrategy.java index a1551908809..9207e24747b 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/TracingStrategy.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/TracingStrategy.java @@ -34,14 +34,15 @@ import java.util.List; */ /*package*/ interface TracingStrategy { TracingStrategy EMPTY = new TracingStrategy() { + @Override - public void bindReference(@NotNull BindingTrace trace, @NotNull ResolvedCallImpl resolvedCall) {} + public void bindResolvedCall(@NotNull BindingTrace trace, @NotNull ResolvedCallWithTrace resolvedCall) {} @Override public void unresolvedReference(@NotNull BindingTrace trace) {} @Override - public void recordAmbiguity(BindingTrace trace, Collection> candidates) {} + public void recordAmbiguity(BindingTrace trace, Collection> candidates) {} @Override public void missingReceiver(@NotNull BindingTrace trace, @NotNull ReceiverDescriptor expectedReceiver) {} @@ -59,10 +60,10 @@ import java.util.List; public void wrongNumberOfTypeArguments(@NotNull BindingTrace trace, int expectedTypeArgumentCount) {} @Override - public void ambiguity(@NotNull BindingTrace trace, @NotNull Collection> descriptors) {} + public void ambiguity(@NotNull BindingTrace trace, @NotNull Collection> descriptors) {} @Override - public void noneApplicable(@NotNull BindingTrace trace, @NotNull Collection> descriptors) {} + public void noneApplicable(@NotNull BindingTrace trace, @NotNull Collection> descriptors) {} @Override public void instantiationOfAbstractClass(@NotNull BindingTrace trace) {} @@ -83,11 +84,11 @@ import java.util.List; public void invisibleMember(@NotNull BindingTrace trace, @NotNull DeclarationDescriptor descriptor) {} }; - void bindReference(@NotNull BindingTrace trace, @NotNull ResolvedCallImpl resolvedCall); + void bindResolvedCall(@NotNull BindingTrace trace, @NotNull ResolvedCallWithTrace resolvedCall); void unresolvedReference(@NotNull BindingTrace trace); - void recordAmbiguity(BindingTrace trace, Collection> candidates); + void recordAmbiguity(BindingTrace trace, Collection> candidates); void missingReceiver(@NotNull BindingTrace trace, @NotNull ReceiverDescriptor expectedReceiver); @@ -99,9 +100,9 @@ import java.util.List; void wrongNumberOfTypeArguments(@NotNull BindingTrace trace, int expectedTypeArgumentCount); - void ambiguity(@NotNull BindingTrace trace, @NotNull Collection> descriptors); + void ambiguity(@NotNull BindingTrace trace, @NotNull Collection> descriptors); - void noneApplicable(@NotNull BindingTrace trace, @NotNull Collection> descriptors); + void noneApplicable(@NotNull BindingTrace trace, @NotNull Collection> descriptors); void instantiationOfAbstractClass(@NotNull BindingTrace trace);