diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/autocasts/AutoCastService.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/autocasts/AutoCastService.java deleted file mode 100644 index 9231e67ed63..00000000000 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/autocasts/AutoCastService.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2010-2013 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.jet.lang.resolve.calls.autocasts; - -import org.jetbrains.annotations.NotNull; -import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue; - -import java.util.Collections; -import java.util.List; - -public interface AutoCastService { - AutoCastService NO_AUTO_CASTS = new AutoCastService() { - @NotNull - @Override - public DataFlowInfo getDataFlowInfo() { - return DataFlowInfo.EMPTY; - } - - @Override - public boolean isNotNull(@NotNull ReceiverValue receiver) { - return !receiver.getType().isNullable(); - } - - @NotNull - @Override - public List getVariantsForReceiver(@NotNull ReceiverValue receiverValue) { - return Collections.singletonList(receiverValue); - } - }; - - @NotNull - List getVariantsForReceiver(@NotNull ReceiverValue receiverValue); - - @NotNull - DataFlowInfo getDataFlowInfo(); - - boolean isNotNull(@NotNull ReceiverValue receiver); -} diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/autocasts/AutoCastServiceImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/autocasts/AutoCastServiceImpl.java deleted file mode 100644 index 73ed966dea3..00000000000 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/autocasts/AutoCastServiceImpl.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2010-2013 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.jet.lang.resolve.calls.autocasts; - -import com.google.common.collect.Lists; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.jet.lang.resolve.BindingContext; -import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue; - -import java.util.List; - -public class AutoCastServiceImpl implements AutoCastService { - private final DataFlowInfo dataFlowInfo; - private final BindingContext bindingContext; - - public AutoCastServiceImpl(DataFlowInfo dataFlowInfo, BindingContext bindingContext) { - this.dataFlowInfo = dataFlowInfo; - this.bindingContext = bindingContext; - } - - @NotNull - @Override - public List getVariantsForReceiver(@NotNull ReceiverValue receiverValue) { - List variants = Lists.newArrayList(); - variants.add(receiverValue); - variants.addAll(AutoCastUtils.getAutoCastVariants(bindingContext, dataFlowInfo, receiverValue)); - return variants; - } - - @NotNull - @Override - public DataFlowInfo getDataFlowInfo() { - return dataFlowInfo; - } - - @Override - public boolean isNotNull(@NotNull ReceiverValue receiver) { - if (!receiver.getType().isNullable()) return true; - - List autoCastVariants = AutoCastUtils.getAutoCastVariants(bindingContext, dataFlowInfo, receiver); - for (ReceiverValue autoCastVariant : autoCastVariants) { - if (!autoCastVariant.getType().isNullable()) return true; - } - return false; - } -} diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/autocasts/AutoCastUtils.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/autocasts/AutoCastUtils.java index 70e99509583..69d2098cf16 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/autocasts/AutoCastUtils.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/autocasts/AutoCastUtils.java @@ -16,9 +16,11 @@ package org.jetbrains.jet.lang.resolve.calls.autocasts; +import com.google.common.collect.Lists; import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.BindingTrace; +import org.jetbrains.jet.lang.resolve.calls.context.ResolutionContext; import org.jetbrains.jet.lang.resolve.scopes.receivers.ExpressionReceiver; import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue; import org.jetbrains.jet.lang.resolve.scopes.receivers.ThisReceiver; @@ -37,6 +39,24 @@ public class AutoCastUtils { private AutoCastUtils() {} + public static List getAutoCastVariantsIncludingReceiver( + @NotNull ReceiverValue receiverToCast, + @NotNull ResolutionContext context + ) { + return getAutoCastVariantsIncludingReceiver(receiverToCast, context.trace.getBindingContext(), context.dataFlowInfo); + } + + public static List getAutoCastVariantsIncludingReceiver( + @NotNull ReceiverValue receiverToCast, + @NotNull BindingContext bindingContext, + @NotNull DataFlowInfo dataFlowInfo + ) { + List variants = Lists.newArrayList(); + variants.add(receiverToCast); + variants.addAll(getAutoCastVariants(bindingContext, dataFlowInfo, receiverToCast)); + return variants; + } + /** * @return variants @param receiverToCast may be cast to according to @param dataFlowInfo, @param receiverToCast itself is NOT included */ diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/tasks/TaskPrioritizer.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/tasks/TaskPrioritizer.java index 1ae1e1d185e..5217ae65b74 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/tasks/TaskPrioritizer.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/tasks/TaskPrioritizer.java @@ -26,7 +26,7 @@ import org.jetbrains.jet.lang.psi.JetExpression; import org.jetbrains.jet.lang.psi.JetReferenceExpression; import org.jetbrains.jet.lang.psi.JetSuperExpression; import org.jetbrains.jet.lang.resolve.DescriptorUtils; -import org.jetbrains.jet.lang.resolve.calls.autocasts.AutoCastServiceImpl; +import org.jetbrains.jet.lang.resolve.calls.autocasts.AutoCastUtils; import org.jetbrains.jet.lang.resolve.calls.context.BasicCallResolutionContext; import org.jetbrains.jet.lang.resolve.name.Name; import org.jetbrains.jet.lang.resolve.scopes.JetScope; @@ -134,7 +134,7 @@ public class TaskPrioritizer { boolean resolveInvoke ) { - List variantsForExplicitReceiver = c.autoCastService.getVariantsForReceiver(receiver); + List variantsForExplicitReceiver = AutoCastUtils.getAutoCastVariantsIncludingReceiver(receiver, c.context); //members for (CallableDescriptorCollector callableDescriptorCollector : c.callableDescriptorCollectors) { @@ -169,7 +169,7 @@ public class TaskPrioritizer { ) { Collection memberExtensions = callableDescriptorCollector.getNonMembersByName( implicitReceiver.getType().getMemberScope(), c.name, c.context.trace); - List variantsForImplicitReceiver = c.autoCastService.getVariantsForReceiver(implicitReceiver); + List variantsForImplicitReceiver = AutoCastUtils.getAutoCastVariantsIncludingReceiver(implicitReceiver, c.context); c.result.addCandidates(convertWithReceivers(memberExtensions, variantsForImplicitReceiver, variantsForExplicitReceiver, resolveInvoke)); } @@ -249,7 +249,7 @@ public class TaskPrioritizer { @NotNull ReceiverValue explicitReceiver, @NotNull TaskPrioritizerContext c ) { - List variantsForExplicitReceiver = c.autoCastService.getVariantsForReceiver(explicitReceiver); + List variantsForExplicitReceiver = AutoCastUtils.getAutoCastVariantsIncludingReceiver(explicitReceiver, c.context); for (CallableDescriptorCollector callableDescriptorCollector : c.callableDescriptorCollectors) { addMemberExtensionCandidates(variableReceiver, variantsForExplicitReceiver, callableDescriptorCollector, c, /*resolveInvoke=*/true); @@ -395,7 +395,6 @@ public class TaskPrioritizer { @NotNull public final BasicCallResolutionContext context; @NotNull public final JetScope scope; @NotNull public final List> callableDescriptorCollectors; - @NotNull AutoCastServiceImpl autoCastService; private TaskPrioritizerContext( @NotNull Name name, @@ -409,7 +408,6 @@ public class TaskPrioritizer { this.context = context; this.scope = scope; this.callableDescriptorCollectors = callableDescriptorCollectors; - autoCastService = new AutoCastServiceImpl(context.dataFlowInfo, context.trace.getBindingContext()); } } } diff --git a/idea/src/org/jetbrains/jet/plugin/codeInsight/TipsManager.java b/idea/src/org/jetbrains/jet/plugin/codeInsight/TipsManager.java index a652b2ddaf5..8235f34999e 100644 --- a/idea/src/org/jetbrains/jet/plugin/codeInsight/TipsManager.java +++ b/idea/src/org/jetbrains/jet/plugin/codeInsight/TipsManager.java @@ -31,7 +31,7 @@ import org.jetbrains.jet.lang.psi.JetImportDirective; import org.jetbrains.jet.lang.psi.JetNamespaceHeader; import org.jetbrains.jet.lang.psi.JetSimpleNameExpression; import org.jetbrains.jet.lang.resolve.BindingContext; -import org.jetbrains.jet.lang.resolve.calls.autocasts.AutoCastServiceImpl; +import org.jetbrains.jet.lang.resolve.calls.autocasts.AutoCastUtils; import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo; import org.jetbrains.jet.lang.resolve.scopes.JetScope; import org.jetbrains.jet.lang.resolve.scopes.JetScopeUtils; @@ -69,8 +69,8 @@ public final class TipsManager { info = DataFlowInfo.EMPTY; } - AutoCastServiceImpl autoCastService = new AutoCastServiceImpl(info, context); - List variantsForExplicitReceiver = autoCastService.getVariantsForReceiver(receiverValue); + List variantsForExplicitReceiver = AutoCastUtils.getAutoCastVariantsIncludingReceiver( + receiverValue, context, info); for (ReceiverValue descriptor : variantsForExplicitReceiver) { descriptors.addAll(includeExternalCallableExtensions(