From 33f119a65a324a5ab59e2a8bab134defe4a636ed Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Tue, 7 Apr 2015 15:07:15 +0300 Subject: [PATCH] Renamed "containingDeclaration" parameters to "containingDeclarationOrModule" to make it more clear that we can pass ModuleDescriptor instead of precise containing declaration --- .../smartcasts/DataFlowValueFactory.java | 22 +++++++++---------- .../calls/smartcasts/SmartCastUtils.java | 12 +++++----- .../kotlin/idea/core/SmartCastCalculator.kt | 4 ++-- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DataFlowValueFactory.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DataFlowValueFactory.java index f00522254b6..ef1ea010499 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DataFlowValueFactory.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DataFlowValueFactory.java @@ -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; diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/SmartCastUtils.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/SmartCastUtils.java index 927893a6d5c..e3f633b44a7 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/SmartCastUtils.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/SmartCastUtils.java @@ -61,12 +61,12 @@ public class SmartCastUtils { public static List getSmartCastVariants( @NotNull ReceiverValue receiverToCast, @NotNull BindingContext bindingContext, - @NotNull DeclarationDescriptor containingDeclaration, + @NotNull DeclarationDescriptor containingDeclarationOrModule, @NotNull DataFlowInfo dataFlowInfo ) { List 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 getSmartCastVariantsWithLessSpecificExcluded( @NotNull ReceiverValue receiverToCast, @NotNull BindingContext bindingContext, - @NotNull DeclarationDescriptor containingDeclaration, + @NotNull DeclarationDescriptor containingDeclarationOrModule, @NotNull DataFlowInfo dataFlowInfo ) { final List variants = getSmartCastVariants(receiverToCast, bindingContext, - containingDeclaration, dataFlowInfo); + containingDeclarationOrModule, dataFlowInfo); return KotlinPackage.filter(variants, new Function1() { @Override public Boolean invoke(final JetType type) { @@ -112,7 +112,7 @@ public class SmartCastUtils { @NotNull public static Collection 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(); diff --git a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/SmartCastCalculator.kt b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/SmartCastCalculator.kt index e3c22764869..e7d34fbfd3f 100644 --- a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/SmartCastCalculator.kt +++ b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/SmartCastCalculator.kt @@ -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 { 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