refactoring: removed AutoCastService

used getAutoCastVariantsIncludingReceiver util method instead
This commit is contained in:
Svetlana Isakova
2013-12-03 14:43:45 +04:00
parent ab1d27dd6b
commit 81e6eb8253
5 changed files with 27 additions and 121 deletions
@@ -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<ReceiverValue> getVariantsForReceiver(@NotNull ReceiverValue receiverValue) {
return Collections.singletonList(receiverValue);
}
};
@NotNull
List<ReceiverValue> getVariantsForReceiver(@NotNull ReceiverValue receiverValue);
@NotNull
DataFlowInfo getDataFlowInfo();
boolean isNotNull(@NotNull ReceiverValue receiver);
}
@@ -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<ReceiverValue> getVariantsForReceiver(@NotNull ReceiverValue receiverValue) {
List<ReceiverValue> 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<ReceiverValue> autoCastVariants = AutoCastUtils.getAutoCastVariants(bindingContext, dataFlowInfo, receiver);
for (ReceiverValue autoCastVariant : autoCastVariants) {
if (!autoCastVariant.getType().isNullable()) return true;
}
return false;
}
}
@@ -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<ReceiverValue> getAutoCastVariantsIncludingReceiver(
@NotNull ReceiverValue receiverToCast,
@NotNull ResolutionContext context
) {
return getAutoCastVariantsIncludingReceiver(receiverToCast, context.trace.getBindingContext(), context.dataFlowInfo);
}
public static List<ReceiverValue> getAutoCastVariantsIncludingReceiver(
@NotNull ReceiverValue receiverToCast,
@NotNull BindingContext bindingContext,
@NotNull DataFlowInfo dataFlowInfo
) {
List<ReceiverValue> 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
*/
@@ -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<ReceiverValue> variantsForExplicitReceiver = c.autoCastService.getVariantsForReceiver(receiver);
List<ReceiverValue> variantsForExplicitReceiver = AutoCastUtils.getAutoCastVariantsIncludingReceiver(receiver, c.context);
//members
for (CallableDescriptorCollector<? extends D> callableDescriptorCollector : c.callableDescriptorCollectors) {
@@ -169,7 +169,7 @@ public class TaskPrioritizer {
) {
Collection<? extends D> memberExtensions = callableDescriptorCollector.getNonMembersByName(
implicitReceiver.getType().getMemberScope(), c.name, c.context.trace);
List<ReceiverValue> variantsForImplicitReceiver = c.autoCastService.getVariantsForReceiver(implicitReceiver);
List<ReceiverValue> 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<D, F> c
) {
List<ReceiverValue> variantsForExplicitReceiver = c.autoCastService.getVariantsForReceiver(explicitReceiver);
List<ReceiverValue> variantsForExplicitReceiver = AutoCastUtils.getAutoCastVariantsIncludingReceiver(explicitReceiver, c.context);
for (CallableDescriptorCollector<? extends D> 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<CallableDescriptorCollector<? extends D>> 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());
}
}
}
@@ -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<ReceiverValue> variantsForExplicitReceiver = autoCastService.getVariantsForReceiver(receiverValue);
List<ReceiverValue> variantsForExplicitReceiver = AutoCastUtils.getAutoCastVariantsIncludingReceiver(
receiverValue, context, info);
for (ReceiverValue descriptor : variantsForExplicitReceiver) {
descriptors.addAll(includeExternalCallableExtensions(