Added parameter "isStatement" for analyzeInContext and used it in UsePropertyAccessSyntaxIntention

This commit is contained in:
Valentin Kipyatkov
2015-08-14 17:05:41 +03:00
parent 16e1138374
commit ad5bd36e65
5 changed files with 15 additions and 11 deletions
@@ -35,10 +35,11 @@ public fun JetExpression.computeTypeInfoInContext(
trace: BindingTrace = BindingTraceContext(), trace: BindingTrace = BindingTraceContext(),
dataFlowInfo: DataFlowInfo = DataFlowInfo.EMPTY, dataFlowInfo: DataFlowInfo = DataFlowInfo.EMPTY,
expectedType: JetType = TypeUtils.NO_EXPECTED_TYPE, expectedType: JetType = TypeUtils.NO_EXPECTED_TYPE,
module: ModuleDescriptor = scope.getModule() module: ModuleDescriptor = scope.getModule(),
isStatement: Boolean = false
): JetTypeInfo { ): JetTypeInfo {
val expressionTypingServices = createContainerForMacros(getProject(), module).expressionTypingServices 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( public fun JetExpression.analyzeInContext(
@@ -46,9 +47,10 @@ public fun JetExpression.analyzeInContext(
trace: BindingTrace = BindingTraceContext(), trace: BindingTrace = BindingTraceContext(),
dataFlowInfo: DataFlowInfo = DataFlowInfo.EMPTY, dataFlowInfo: DataFlowInfo = DataFlowInfo.EMPTY,
expectedType: JetType = TypeUtils.NO_EXPECTED_TYPE, expectedType: JetType = TypeUtils.NO_EXPECTED_TYPE,
module: ModuleDescriptor = scope.getModule() module: ModuleDescriptor = scope.getModule(),
isStatement: Boolean = false
): BindingContext { ): BindingContext {
computeTypeInfoInContext(scope, trace, dataFlowInfo, expectedType, module) computeTypeInfoInContext(scope, trace, dataFlowInfo, expectedType, module, isStatement)
return trace.getBindingContext() return trace.getBindingContext()
} }
@@ -86,12 +86,13 @@ public class ExpressionTypingServices {
@NotNull JetExpression expression, @NotNull JetExpression expression,
@NotNull JetType expectedType, @NotNull JetType expectedType,
@NotNull DataFlowInfo dataFlowInfo, @NotNull DataFlowInfo dataFlowInfo,
@NotNull BindingTrace trace @NotNull BindingTrace trace,
boolean isStatement
) { ) {
ExpressionTypingContext context = ExpressionTypingContext.newContext( ExpressionTypingContext context = ExpressionTypingContext.newContext(
trace, scope, dataFlowInfo, expectedType trace, scope, dataFlowInfo, expectedType
); );
return expressionTypingFacade.getTypeInfo(expression, context); return expressionTypingFacade.getTypeInfo(expression, context, isStatement);
} }
@NotNull @NotNull
@@ -107,7 +108,7 @@ public class ExpressionTypingServices {
@NotNull DataFlowInfo dataFlowInfo, @NotNull DataFlowInfo dataFlowInfo,
@NotNull BindingTrace trace @NotNull BindingTrace trace
) { ) {
return getTypeInfo(scope, expression, expectedType, dataFlowInfo, trace).getType(); return getTypeInfo(scope, expression, expectedType, dataFlowInfo, trace, false).getType();
} }
///////////////////////////////////////////////////////// /////////////////////////////////////////////////////////
@@ -98,8 +98,8 @@ class UsePropertyAccessSyntaxIntention : JetSelfTargetingOffsetIndependentIntent
val callExpressionCopy = ((qualifiedExpressionCopy as? JetQualifiedExpression)?.selectorExpression ?: qualifiedExpressionCopy) as JetCallExpression val callExpressionCopy = ((qualifiedExpressionCopy as? JetQualifiedExpression)?.selectorExpression ?: qualifiedExpressionCopy) as JetCallExpression
val newExpression = applyTo(callExpressionCopy, property.name) val newExpression = applyTo(callExpressionCopy, property.name)
val bindingTrace = DelegatingBindingTrace(bindingContext, "Temporary trace") val bindingTrace = DelegatingBindingTrace(bindingContext, "Temporary trace")
val newBindingContext = newExpression.analyzeInContext(resolutionScope, bindingTrace, dataFlowInfo, expectedType, moduleDescriptor) val newBindingContext = newExpression.analyzeInContext(resolutionScope, bindingTrace, dataFlowInfo, expectedType, moduleDescriptor, isStatement = true)
if (newBindingContext.diagnostics.any { it.severity == Severity.ERROR && it.factory != Errors.ASSIGNMENT_IN_EXPRESSION_CONTEXT }) return null if (newBindingContext.diagnostics.any { it.severity == Severity.ERROR }) return null
} }
return property.name return property.name
@@ -747,7 +747,8 @@ public class JetChangeSignatureUsageProcessor implements ChangeSignatureUsagePro
new BindingTraceContext(), new BindingTraceContext(),
DataFlowInfo.EMPTY, DataFlowInfo.EMPTY,
TypeUtils.NO_EXPECTED_TYPE, TypeUtils.NO_EXPECTED_TYPE,
DescriptorUtils.getContainingModule(scope.getContainingDeclaration())); DescriptorUtils.getContainingModule(scope.getContainingDeclaration()),
false);
if (newContext.get(BindingContext.AMBIGUOUS_LABEL_TARGET, labelExpr) != null) { if (newContext.get(BindingContext.AMBIGUOUS_LABEL_TARGET, labelExpr) != null) {
result.putValue( result.putValue(
originalExpr, originalExpr,
@@ -137,7 +137,7 @@ public class KotlinIntroduceVariableHandler extends KotlinIntroduceHandlerBase {
ObservableBindingTrace bindingTrace = new ObservableBindingTrace(new BindingTraceContext()); ObservableBindingTrace bindingTrace = new ObservableBindingTrace(new BindingTraceContext());
JetType typeNoExpectedType = AnalyzerPackage.computeTypeInfoInContext( 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(); ).getType();
if (expressionType != null && typeNoExpectedType != null && !JetTypeChecker.DEFAULT.equalTypes(expressionType, if (expressionType != null && typeNoExpectedType != null && !JetTypeChecker.DEFAULT.equalTypes(expressionType,
typeNoExpectedType)) { typeNoExpectedType)) {