Renamed "containingDeclaration" parameters to "containingDeclarationOrModule" to make it more clear that we can pass ModuleDescriptor instead of precise containing declaration
This commit is contained in:
+11
-11
@@ -57,7 +57,7 @@ public class DataFlowValueFactory {
|
||||
@NotNull JetExpression expression,
|
||||
@NotNull JetType type,
|
||||
@NotNull BindingContext bindingContext,
|
||||
@NotNull DeclarationDescriptor containingDeclaration
|
||||
@NotNull DeclarationDescriptor containingDeclarationOrModule
|
||||
) {
|
||||
if (expression instanceof JetConstantExpression) {
|
||||
JetConstantExpression constantExpression = (JetConstantExpression) expression;
|
||||
@@ -67,7 +67,7 @@ public class DataFlowValueFactory {
|
||||
if (KotlinBuiltIns.getInstance().getNullableNothingType().equals(type)) {
|
||||
return DataFlowValue.NULL; // 'null' is the only inhabitant of 'Nothing?'
|
||||
}
|
||||
IdentifierInfo result = getIdForStableIdentifier(expression, bindingContext, containingDeclaration);
|
||||
IdentifierInfo result = getIdForStableIdentifier(expression, bindingContext, containingDeclarationOrModule);
|
||||
return new DataFlowValue(result == NO_IDENTIFIER_INFO ? expression : result.id, type, result.isStable, getImmanentNullability(type));
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ public class DataFlowValueFactory {
|
||||
public static DataFlowValue createDataFlowValue(
|
||||
@NotNull ReceiverValue receiverValue,
|
||||
@NotNull BindingContext bindingContext,
|
||||
@NotNull DeclarationDescriptor containingDeclaration
|
||||
@NotNull DeclarationDescriptor containingDeclarationOrModule
|
||||
) {
|
||||
if (receiverValue instanceof TransientReceiver || receiverValue instanceof ScriptReceiver) {
|
||||
// SCRIPT: smartcasts data flow
|
||||
@@ -105,7 +105,7 @@ public class DataFlowValueFactory {
|
||||
return createDataFlowValue(((ExpressionReceiver) receiverValue).getExpression(),
|
||||
receiverValue.getType(),
|
||||
bindingContext,
|
||||
containingDeclaration);
|
||||
containingDeclarationOrModule);
|
||||
}
|
||||
else if (receiverValue == ReceiverValue.NO_RECEIVER) {
|
||||
throw new IllegalArgumentException("No DataFlowValue exists for ReceiverValue.NO_RECEIVER");
|
||||
@@ -175,25 +175,25 @@ public class DataFlowValueFactory {
|
||||
private static IdentifierInfo getIdForStableIdentifier(
|
||||
@Nullable JetExpression expression,
|
||||
@NotNull BindingContext bindingContext,
|
||||
@NotNull DeclarationDescriptor containingDeclaration
|
||||
@NotNull DeclarationDescriptor containingDeclarationOrModule
|
||||
) {
|
||||
if (expression != null) {
|
||||
JetExpression deparenthesized = JetPsiUtil.deparenthesize(expression);
|
||||
if (expression != deparenthesized) {
|
||||
return getIdForStableIdentifier(deparenthesized, bindingContext, containingDeclaration);
|
||||
return getIdForStableIdentifier(deparenthesized, bindingContext, containingDeclarationOrModule);
|
||||
}
|
||||
}
|
||||
if (expression instanceof JetQualifiedExpression) {
|
||||
JetQualifiedExpression qualifiedExpression = (JetQualifiedExpression) expression;
|
||||
JetExpression receiverExpression = qualifiedExpression.getReceiverExpression();
|
||||
JetExpression selectorExpression = qualifiedExpression.getSelectorExpression();
|
||||
IdentifierInfo receiverId = getIdForStableIdentifier(receiverExpression, bindingContext, containingDeclaration);
|
||||
IdentifierInfo selectorId = getIdForStableIdentifier(selectorExpression, bindingContext, containingDeclaration);
|
||||
IdentifierInfo receiverId = getIdForStableIdentifier(receiverExpression, bindingContext, containingDeclarationOrModule);
|
||||
IdentifierInfo selectorId = getIdForStableIdentifier(selectorExpression, bindingContext, containingDeclarationOrModule);
|
||||
|
||||
return combineInfo(receiverId, selectorId);
|
||||
}
|
||||
if (expression instanceof JetSimpleNameExpression) {
|
||||
return getIdForSimpleNameExpression((JetSimpleNameExpression) expression, bindingContext, containingDeclaration);
|
||||
return getIdForSimpleNameExpression((JetSimpleNameExpression) expression, bindingContext, containingDeclarationOrModule);
|
||||
}
|
||||
else if (expression instanceof JetThisExpression) {
|
||||
JetThisExpression thisExpression = (JetThisExpression) expression;
|
||||
@@ -211,7 +211,7 @@ public class DataFlowValueFactory {
|
||||
private static IdentifierInfo getIdForSimpleNameExpression(
|
||||
@NotNull JetSimpleNameExpression simpleNameExpression,
|
||||
@NotNull BindingContext bindingContext,
|
||||
@NotNull DeclarationDescriptor containingDeclaration
|
||||
@NotNull DeclarationDescriptor containingDeclarationOrModule
|
||||
) {
|
||||
DeclarationDescriptor declarationDescriptor = bindingContext.get(REFERENCE_TARGET, simpleNameExpression);
|
||||
if (declarationDescriptor instanceof VariableDescriptor) {
|
||||
@@ -221,7 +221,7 @@ public class DataFlowValueFactory {
|
||||
// KT-4113
|
||||
// for now it fails for resolving 'invoke' convention, return it after 'invoke' algorithm changes
|
||||
// assert resolvedCall != null : "Cannot create right identifier info if the resolved call is not known yet for
|
||||
ModuleDescriptor usageModuleDescriptor = DescriptorUtils.getContainingModuleOrNull(containingDeclaration);
|
||||
ModuleDescriptor usageModuleDescriptor = DescriptorUtils.getContainingModuleOrNull(containingDeclarationOrModule);
|
||||
IdentifierInfo receiverInfo =
|
||||
resolvedCall != null ? getIdForImplicitReceiver(resolvedCall.getDispatchReceiver(), simpleNameExpression) : null;
|
||||
|
||||
|
||||
+6
-6
@@ -61,12 +61,12 @@ public class SmartCastUtils {
|
||||
public static List<JetType> getSmartCastVariants(
|
||||
@NotNull ReceiverValue receiverToCast,
|
||||
@NotNull BindingContext bindingContext,
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull DeclarationDescriptor containingDeclarationOrModule,
|
||||
@NotNull DataFlowInfo dataFlowInfo
|
||||
) {
|
||||
List<JetType> variants = Lists.newArrayList();
|
||||
variants.add(receiverToCast.getType());
|
||||
variants.addAll(getSmartCastVariantsExcludingReceiver(bindingContext, containingDeclaration, dataFlowInfo, receiverToCast));
|
||||
variants.addAll(getSmartCastVariantsExcludingReceiver(bindingContext, containingDeclarationOrModule, dataFlowInfo, receiverToCast));
|
||||
return variants;
|
||||
}
|
||||
|
||||
@@ -74,11 +74,11 @@ public class SmartCastUtils {
|
||||
public static List<JetType> getSmartCastVariantsWithLessSpecificExcluded(
|
||||
@NotNull ReceiverValue receiverToCast,
|
||||
@NotNull BindingContext bindingContext,
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull DeclarationDescriptor containingDeclarationOrModule,
|
||||
@NotNull DataFlowInfo dataFlowInfo
|
||||
) {
|
||||
final List<JetType> variants = getSmartCastVariants(receiverToCast, bindingContext,
|
||||
containingDeclaration, dataFlowInfo);
|
||||
containingDeclarationOrModule, dataFlowInfo);
|
||||
return KotlinPackage.filter(variants, new Function1<JetType, Boolean>() {
|
||||
@Override
|
||||
public Boolean invoke(final JetType type) {
|
||||
@@ -112,7 +112,7 @@ public class SmartCastUtils {
|
||||
@NotNull
|
||||
public static Collection<JetType> getSmartCastVariantsExcludingReceiver(
|
||||
@NotNull BindingContext bindingContext,
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull DeclarationDescriptor containingDeclarationOrModule,
|
||||
@NotNull DataFlowInfo dataFlowInfo,
|
||||
@NotNull ReceiverValue receiverToCast
|
||||
) {
|
||||
@@ -124,7 +124,7 @@ public class SmartCastUtils {
|
||||
}
|
||||
else if (receiverToCast instanceof ExpressionReceiver) {
|
||||
DataFlowValue dataFlowValue = DataFlowValueFactory.createDataFlowValue(
|
||||
receiverToCast, bindingContext, containingDeclaration);
|
||||
receiverToCast, bindingContext, containingDeclarationOrModule);
|
||||
return dataFlowInfo.getPossibleTypes(dataFlowValue);
|
||||
}
|
||||
return Collections.emptyList();
|
||||
|
||||
@@ -36,7 +36,7 @@ import org.jetbrains.kotlin.idea.util.makeNotNullable
|
||||
import org.jetbrains.kotlin.resolve.calls.context.ResolutionContext
|
||||
import org.jetbrains.kotlin.utils.singletonOrEmptyList
|
||||
|
||||
class SmartCastCalculator(val bindingContext: BindingContext, val containingDeclaration: DeclarationDescriptor) {
|
||||
class SmartCastCalculator(val bindingContext: BindingContext, val containingDeclarationOrModule: DeclarationDescriptor) {
|
||||
public fun calculate(position: JetExpression, receiver: JetExpression?): (VariableDescriptor) -> Collection<JetType> {
|
||||
val dataFlowInfo = bindingContext.getDataFlowInfo(position)
|
||||
val (variableToTypes, notNullVariables) = processDataFlowInfo(dataFlowInfo, receiver)
|
||||
@@ -66,7 +66,7 @@ class SmartCastCalculator(val bindingContext: BindingContext, val containingDecl
|
||||
val dataFlowValueToVariable: (DataFlowValue) -> VariableDescriptor?
|
||||
if (receiver != null) {
|
||||
val receiverType = bindingContext[BindingContext.EXPRESSION_TYPE, receiver] ?: return ProcessDataFlowInfoResult()
|
||||
val receiverId = DataFlowValueFactory.createDataFlowValue(receiver, receiverType, bindingContext, containingDeclaration).getId()
|
||||
val receiverId = DataFlowValueFactory.createDataFlowValue(receiver, receiverType, bindingContext, containingDeclarationOrModule).getId()
|
||||
dataFlowValueToVariable = { value ->
|
||||
val id = value.getId()
|
||||
if (id is Pair<*, *> && id.first == receiverId) id.second as? VariableDescriptor else null
|
||||
|
||||
Reference in New Issue
Block a user