From ad5bd36e658db1af158fd41965a5ff1f51305baa Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Fri, 14 Aug 2015 17:05:41 +0300 Subject: [PATCH] Added parameter "isStatement" for analyzeInContext and used it in UsePropertyAccessSyntaxIntention --- .../src/org/jetbrains/kotlin/analyzer/AnalyzerUtil.kt | 10 ++++++---- .../types/expressions/ExpressionTypingServices.java | 7 ++++--- .../intentions/UsePropertyAccessSyntaxIntention.kt | 4 ++-- .../JetChangeSignatureUsageProcessor.java | 3 ++- .../KotlinIntroduceVariableHandler.java | 2 +- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/analyzer/AnalyzerUtil.kt b/compiler/frontend/src/org/jetbrains/kotlin/analyzer/AnalyzerUtil.kt index b0ed6795ef7..506233982e5 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/analyzer/AnalyzerUtil.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/analyzer/AnalyzerUtil.kt @@ -35,10 +35,11 @@ public fun JetExpression.computeTypeInfoInContext( trace: BindingTrace = BindingTraceContext(), dataFlowInfo: DataFlowInfo = DataFlowInfo.EMPTY, expectedType: JetType = TypeUtils.NO_EXPECTED_TYPE, - module: ModuleDescriptor = scope.getModule() + module: ModuleDescriptor = scope.getModule(), + isStatement: Boolean = false ): JetTypeInfo { val expressionTypingServices = createContainerForMacros(getProject(), module).expressionTypingServices - return expressionTypingServices.getTypeInfo(scope, this, expectedType, dataFlowInfo, trace) + return expressionTypingServices.getTypeInfo(scope, this, expectedType, dataFlowInfo, trace, isStatement) } public fun JetExpression.analyzeInContext( @@ -46,9 +47,10 @@ public fun JetExpression.analyzeInContext( trace: BindingTrace = BindingTraceContext(), dataFlowInfo: DataFlowInfo = DataFlowInfo.EMPTY, expectedType: JetType = TypeUtils.NO_EXPECTED_TYPE, - module: ModuleDescriptor = scope.getModule() + module: ModuleDescriptor = scope.getModule(), + isStatement: Boolean = false ): BindingContext { - computeTypeInfoInContext(scope, trace, dataFlowInfo, expectedType, module) + computeTypeInfoInContext(scope, trace, dataFlowInfo, expectedType, module, isStatement) return trace.getBindingContext() } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingServices.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingServices.java index 6426ee5d2e2..eb02da14bb9 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingServices.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingServices.java @@ -86,12 +86,13 @@ public class ExpressionTypingServices { @NotNull JetExpression expression, @NotNull JetType expectedType, @NotNull DataFlowInfo dataFlowInfo, - @NotNull BindingTrace trace + @NotNull BindingTrace trace, + boolean isStatement ) { ExpressionTypingContext context = ExpressionTypingContext.newContext( trace, scope, dataFlowInfo, expectedType ); - return expressionTypingFacade.getTypeInfo(expression, context); + return expressionTypingFacade.getTypeInfo(expression, context, isStatement); } @NotNull @@ -107,7 +108,7 @@ public class ExpressionTypingServices { @NotNull DataFlowInfo dataFlowInfo, @NotNull BindingTrace trace ) { - return getTypeInfo(scope, expression, expectedType, dataFlowInfo, trace).getType(); + return getTypeInfo(scope, expression, expectedType, dataFlowInfo, trace, false).getType(); } ///////////////////////////////////////////////////////// diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/UsePropertyAccessSyntaxIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/UsePropertyAccessSyntaxIntention.kt index 55ebd415223..84cd625f00d 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/UsePropertyAccessSyntaxIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/UsePropertyAccessSyntaxIntention.kt @@ -98,8 +98,8 @@ class UsePropertyAccessSyntaxIntention : JetSelfTargetingOffsetIndependentIntent val callExpressionCopy = ((qualifiedExpressionCopy as? JetQualifiedExpression)?.selectorExpression ?: qualifiedExpressionCopy) as JetCallExpression val newExpression = applyTo(callExpressionCopy, property.name) val bindingTrace = DelegatingBindingTrace(bindingContext, "Temporary trace") - val newBindingContext = newExpression.analyzeInContext(resolutionScope, bindingTrace, dataFlowInfo, expectedType, moduleDescriptor) - if (newBindingContext.diagnostics.any { it.severity == Severity.ERROR && it.factory != Errors.ASSIGNMENT_IN_EXPRESSION_CONTEXT }) return null + val newBindingContext = newExpression.analyzeInContext(resolutionScope, bindingTrace, dataFlowInfo, expectedType, moduleDescriptor, isStatement = true) + if (newBindingContext.diagnostics.any { it.severity == Severity.ERROR }) return null } return property.name diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/JetChangeSignatureUsageProcessor.java b/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/JetChangeSignatureUsageProcessor.java index 24af0ba50bc..638b0e34542 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/JetChangeSignatureUsageProcessor.java +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/JetChangeSignatureUsageProcessor.java @@ -747,7 +747,8 @@ public class JetChangeSignatureUsageProcessor implements ChangeSignatureUsagePro new BindingTraceContext(), DataFlowInfo.EMPTY, TypeUtils.NO_EXPECTED_TYPE, - DescriptorUtils.getContainingModule(scope.getContainingDeclaration())); + DescriptorUtils.getContainingModule(scope.getContainingDeclaration()), + false); if (newContext.get(BindingContext.AMBIGUOUS_LABEL_TARGET, labelExpr) != null) { result.putValue( originalExpr, diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceVariable/KotlinIntroduceVariableHandler.java b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceVariable/KotlinIntroduceVariableHandler.java index 67a55c44071..d0d485e8edf 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceVariable/KotlinIntroduceVariableHandler.java +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceVariable/KotlinIntroduceVariableHandler.java @@ -137,7 +137,7 @@ public class KotlinIntroduceVariableHandler extends KotlinIntroduceHandlerBase { ObservableBindingTrace bindingTrace = new ObservableBindingTrace(new BindingTraceContext()); JetType typeNoExpectedType = AnalyzerPackage.computeTypeInfoInContext( - expression, scope, bindingTrace, dataFlowInfo, TypeUtils.NO_EXPECTED_TYPE, analysisResult.getModuleDescriptor() + expression, scope, bindingTrace, dataFlowInfo, TypeUtils.NO_EXPECTED_TYPE, analysisResult.getModuleDescriptor(), false ).getType(); if (expressionType != null && typeNoExpectedType != null && !JetTypeChecker.DEFAULT.equalTypes(expressionType, typeNoExpectedType)) {