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(),
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()
}
@@ -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();
}
/////////////////////////////////////////////////////////
@@ -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
@@ -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,
@@ -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)) {