Refactoring of JetTypeInfo / BindingContext. Loop data flow analysis corrected.

Now BindingContext includes expression type info instead of jump out possible, data flow info and expression type.
getType() was added into BindingContext, getType() and recordType() were added into BindingTrace.
JetTypeInfo now includes also jump possible flag and jump point data flow info.
Old TypeInfoWithJumpInfo deleted.
TypeInfoFactory introduced to create JetTypeInfo instances.
A pack of extra tests for break / continue in loops added.
This commit is contained in:
Mikhail Glukhikh
2015-04-20 16:12:49 +03:00
parent 14b92404cd
commit 27625b04e1
113 changed files with 908 additions and 550 deletions
@@ -96,7 +96,7 @@ public class ReferenceVariantsHelper(
val expressionType = if (useRuntimeReceiverType)
getQualifierRuntimeType(receiverExpression)
else
context[BindingContext.EXPRESSION_TYPE, receiverExpression]
context.getType(receiverExpression)
if (expressionType != null && !expressionType.isError()) {
val receiverValue = ExpressionReceiver(receiverExpression, expressionType)
val dataFlowInfo = context.getDataFlowInfo(expression)
@@ -164,7 +164,7 @@ public class ReferenceVariantsHelper(
val receiverData = getExplicitReceiverData(expression)
if (receiverData != null) {
val receiverExpression = receiverData.first
val expressionType = context[BindingContext.EXPRESSION_TYPE, receiverExpression] ?: return ReceiversData.Empty
val expressionType = context.getType(receiverExpression) ?: return ReceiversData.Empty
return ReceiversData(listOf(ExpressionReceiver(receiverExpression, expressionType)), receiverData.second)
}
else {
@@ -174,7 +174,7 @@ public class ReferenceVariantsHelper(
}
private fun getQualifierRuntimeType(receiver: JetExpression): JetType? {
val type = context[BindingContext.EXPRESSION_TYPE, receiver]
val type = context.getType(receiver)
if (type != null && TypeUtils.canHaveSubtypes(JetTypeChecker.DEFAULT, type)) {
val evaluator = receiver.getContainingFile().getCopyableUserData(JetCodeFragment.RUNTIME_TYPE_EVALUATOR)
return evaluator?.invoke(receiver)
@@ -127,7 +127,7 @@ public class OperatorToFunctionIntention : JetSelfTargetingIntention<JetExpressi
val context = element.analyze()
val functionCandidate = element.getResolvedCall(context)
val functionName = functionCandidate?.getCandidateDescriptor()?.getName().toString()
val elemType = context[BindingContext.EXPRESSION_TYPE, left]
val elemType = context.getType(left)
val transformation = when (op) {
JetTokens.PLUS -> "$leftText.plus($rightText)"
@@ -139,7 +139,7 @@ class ExpectedInfos(
val callOperationNode: ASTNode?
if (parent is JetQualifiedExpression && callElement == parent.getSelectorExpression()) {
val receiverExpression = parent.getReceiverExpression()
val expressionType = bindingContext[BindingContext.EXPRESSION_TYPE, receiverExpression]
val expressionType = bindingContext.getType(receiverExpression)
val qualifier = bindingContext[BindingContext.QUALIFIER, receiverExpression]
if (expressionType != null) {
receiver = ExpressionReceiver(receiverExpression, expressionType)
@@ -231,7 +231,7 @@ class ExpectedInfos(
|| operationToken == JetTokens.EQEQEQ || operationToken == JetTokens.EXCLEQEQEQ) {
val otherOperand = if (expressionWithType == binaryExpression.getRight()) binaryExpression.getLeft() else binaryExpression.getRight()
if (otherOperand != null) {
val expressionType = bindingContext[BindingContext.EXPRESSION_TYPE, otherOperand] ?: return null
val expressionType = bindingContext.getType(otherOperand) ?: return null
return listOf(ExpectedInfo(expressionType, expectedNameFromExpression(otherOperand), null))
}
}
@@ -248,7 +248,7 @@ class ExpectedInfos(
ifExpression.getElse() -> {
val ifExpectedInfo = calculate(ifExpression)
val thenType = bindingContext[BindingContext.EXPRESSION_TYPE, ifExpression.getThen()]
val thenType = bindingContext.getType(ifExpression.getThen())
if (thenType != null)
ifExpectedInfo?.filter { it.type.isSubtypeOf(thenType) }
else
@@ -265,7 +265,7 @@ class ExpectedInfos(
val operationToken = binaryExpression.getOperationToken()
if (operationToken == JetTokens.ELVIS && expressionWithType == binaryExpression.getRight()) {
val leftExpression = binaryExpression.getLeft() ?: return null
val leftType = bindingContext[BindingContext.EXPRESSION_TYPE, leftExpression]
val leftType = bindingContext.getType(leftExpression)
val leftTypeNotNullable = leftType?.makeNotNullable()
val expectedInfos = calculate(binaryExpression)
if (expectedInfos != null) {
@@ -294,7 +294,7 @@ class ExpectedInfos(
val whenExpression = entry.getParent() as JetWhenExpression
val subject = whenExpression.getSubjectExpression()
if (subject != null) {
val subjectType = bindingContext[BindingContext.EXPRESSION_TYPE, subject] ?: return null
val subjectType = bindingContext.getType(subject) ?: return null
return listOf(ExpectedInfo(subjectType, null, null))
}
else {
@@ -298,7 +298,7 @@ class SmartCompletion(
}
}
val subjectType = bindingContext[BindingContext.EXPRESSION_TYPE, subject] ?: return setOf()
val subjectType = bindingContext.getType(subject) ?: return setOf()
val classDescriptor = TypeUtils.getClassDescriptor(subjectType)
if (classDescriptor != null && DescriptorUtils.isEnumClass(classDescriptor)) {
val conditions = whenExpression.getEntries()
@@ -410,7 +410,7 @@ class SmartCompletion(
val operationToken = binaryExpression.getOperationToken()
if (operationToken != JetTokens.IN_KEYWORD && operationToken != JetTokens.NOT_IN || expressionWithType != binaryExpression.getRight()) return null
val leftOperandType = bindingContext.get(BindingContext.EXPRESSION_TYPE, binaryExpression.getLeft()) ?: return null
val leftOperandType = bindingContext.getType(binaryExpression.getLeft()) ?: return null
val scope = bindingContext.get(BindingContext.RESOLUTION_SCOPE, expressionWithType)
val detector = TypesWithContainsDetector(scope, leftOperandType, project, moduleDescriptor)
@@ -122,7 +122,7 @@ public class KotlinIndicesHelper(
if (receiverPair != null) {
val (receiverExpression, callType) = receiverPair
val expressionType = bindingContext[BindingContext.EXPRESSION_TYPE, receiverExpression]
val expressionType = bindingContext.getType(receiverExpression)
if (expressionType == null || expressionType.isError()) return emptyList()
val receiverValue = ExpressionReceiver(receiverExpression, expressionType)
@@ -65,7 +65,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 receiverType = bindingContext.getType(receiver) ?: return ProcessDataFlowInfoResult()
val receiverId = DataFlowValueFactory.createDataFlowValue(receiver, receiverType, bindingContext, containingDeclarationOrModule).getId()
dataFlowValueToVariable = { value ->
val id = value.getId()
@@ -35,7 +35,7 @@ fun DeclarationDescriptorWithVisibility.isVisible(
if (bindingContext == null || element == null) return false
val receiver = element.getReceiverExpression()
val type = receiver?.let { bindingContext.get(BindingContext.EXPRESSION_TYPE, it) }
val type = receiver?.let { bindingContext.getType(it) }
val explicitReceiver = type?.let { ExpressionReceiver(receiver, it) }
if (explicitReceiver != null) {
@@ -69,7 +69,7 @@ public class JetNameSuggester {
ArrayList<String> result = new ArrayList<String>();
BindingContext bindingContext = ResolvePackage.analyze(expression, BodyResolveMode.FULL);
JetType jetType = bindingContext.get(BindingContext.EXPRESSION_TYPE, expression);
JetType jetType = bindingContext.getType(expression);
if (jetType != null) {
addNamesForType(result, jetType, validator);
}
@@ -50,7 +50,7 @@ public class ShowExpressionTypeAction extends AnAction {
else {
int offset = editor.getCaretModel().getOffset();
expression = PsiTreeUtil.getParentOfType(psiFile.findElementAt(offset), JetExpression.class);
while (expression != null && bindingContext.get(BindingContext.EXPRESSION_TYPE, expression) == null) {
while (expression != null && bindingContext.getType(expression) == null) {
expression = PsiTreeUtil.getParentOfType(expression, JetExpression.class);
}
if (expression != null) {
@@ -59,7 +59,7 @@ public class ShowExpressionTypeAction extends AnAction {
}
}
if (expression != null) {
JetType type = bindingContext.get(BindingContext.EXPRESSION_TYPE, expression);
JetType type = bindingContext.getType(expression);
if (type != null) {
HintManager.getInstance().showInformationHint(editor, "<html>" + DescriptorRenderer.HTML.renderType(type) + "</html>");
}
@@ -135,7 +135,7 @@ public class CheckPartialBodyResolveAction : AnAction() {
builder.append(" resolves to ${target?.presentation()}")
}
val type = bindingContext[BindingContext.EXPRESSION_TYPE, expression]
val type = bindingContext.getType(expression)
if (type != null) {
builder.append(" has type ${type.presentation()}")
}
@@ -77,7 +77,7 @@ public class FindImplicitNothingAction : AnAction() {
try {
val bindingContext = resolutionFacade.analyze(expression)
val type = bindingContext[BindingContext.EXPRESSION_TYPE, expression] ?: return
val type = bindingContext.getType(expression) ?: return
if (KotlinBuiltIns.isNothing(type) && !expression.hasExplicitNothing(bindingContext)) { //TODO: what about nullable Nothing?
found.add(expression)
}
@@ -44,7 +44,7 @@ public abstract class KotlinExpressionSurrounder implements Surrounder {
if (expression instanceof JetCallExpression && expression.getParent() instanceof JetQualifiedExpression) {
return false;
}
JetType type = ResolvePackage.analyze(expression, BodyResolveMode.PARTIAL).get(BindingContext.EXPRESSION_TYPE, expression);
JetType type = ResolvePackage.analyze(expression, BodyResolveMode.PARTIAL).getType(expression);
if (type == null || type.equals(KotlinBuiltIns.getInstance().getUnitType())) {
return false;
}
@@ -42,7 +42,7 @@ public class KotlinNotSurrounder extends KotlinExpressionSurrounder {
@Override
public boolean isApplicable(@NotNull JetExpression expression) {
JetType type = ResolvePackage.analyze(expression, BodyResolveMode.PARTIAL).get(BindingContext.EXPRESSION_TYPE, expression);
JetType type = ResolvePackage.analyze(expression, BodyResolveMode.PARTIAL).getType(expression);
return KotlinBuiltIns.getInstance().getBooleanType().equals(type);
}
@@ -52,7 +52,7 @@ public class KotlinRuntimeTypeCastSurrounder: KotlinExpressionSurrounder() {
if (file !is JetCodeFragment) return false
val context = file.analyzeFully()
val type = context[BindingContext.EXPRESSION_TYPE, expression]
val type = context.getType(expression)
if (type == null) return false
return TypeUtils.canHaveSubtypes(JetTypeChecker.DEFAULT, type)
@@ -70,7 +70,7 @@ public class KotlinWhenSurrounder extends KotlinExpressionSurrounder {
}
private String getCodeTemplate(JetExpression expression) {
JetType type = ResolvePackage.analyze(expression, BodyResolveMode.PARTIAL).get(BindingContext.EXPRESSION_TYPE, expression);
JetType type = ResolvePackage.analyze(expression, BodyResolveMode.PARTIAL).getType(expression);
if (type != null) {
ClassifierDescriptor descriptor = type.getConstructor().getDeclarationDescriptor();
if (descriptor instanceof ClassDescriptor && ((ClassDescriptor) descriptor).getKind() == ClassKind.ENUM_CLASS) {
@@ -76,5 +76,5 @@ public class ConvertToConcatenatedStringIntention : JetSelfTargetingOffsetIndepe
private fun String.quote(quote: String) = quote + this + quote
private fun JetExpression.isStringExpression() = KotlinBuiltIns.isString(BindingContextUtils.getRecordedTypeInfo(this, analyze())?.getType())
private fun JetExpression.isStringExpression() = KotlinBuiltIns.isString(BindingContextUtils.getRecordedTypeInfo(this, analyze())?.type)
}
@@ -94,7 +94,7 @@ public class ConvertToExpressionBodyIntention : JetSelfTargetingOffsetIndependen
val declaredType = (descriptor as? CallableDescriptor)?.getReturnType() ?: return false
val scope = scopeExpression.analyze()[BindingContext.RESOLUTION_SCOPE, scopeExpression] ?: return false
val expressionType = expression.analyzeInContext(scope)[BindingContext.EXPRESSION_TYPE, expression] ?: return false
val expressionType = expression.analyzeInContext(scope).getType(expression) ?: return false
return expressionType.isSubtypeOf(declaredType)
}
@@ -39,7 +39,7 @@ public class ConvertToStringTemplateIntention : JetSelfTargetingOffsetIndependen
override fun isApplicableTo(element: JetBinaryExpression): Boolean {
if (element.getOperationToken() != JetTokens.PLUS) return false
val elementType = BindingContextUtils.getRecordedTypeInfo(element, element.analyze())?.getType()
val elementType = BindingContextUtils.getRecordedTypeInfo(element, element.analyze())?.type
if (!KotlinBuiltIns.isString(elementType)) return false
val left = element.getLeft() ?: return false
@@ -80,7 +80,7 @@ public class ConvertToStringTemplateIntention : JetSelfTargetingOffsetIndependen
val context = expression.analyze()
val constant = ConstantExpressionEvaluator.evaluate(expression, DelegatingBindingTrace(context, "Trace for evaluating constant"), null)
if (constant is IntegerValueTypeConstant) {
val elementType = BindingContextUtils.getRecordedTypeInfo(expression, context)?.getType()!!
val elementType = BindingContextUtils.getRecordedTypeInfo(expression, context)?.type!!
constant.getValue(elementType).toString()
}
else {
@@ -83,7 +83,7 @@ public open class ReplaceWithInfixFunctionCallIntention : JetSelfTargetingIntent
val valueArguments = element.getValueArgumentList()?.getArguments() ?: listOf<JetValueArgument>()
val functionLiteralArguments = element.getFunctionLiteralArguments()
val bindingContext = parent.analyze()
val receiverType = bindingContext[BindingContext.EXPRESSION_TYPE, receiver]
val receiverType = bindingContext.getType(receiver)
if (receiverType == null) {
if (bindingContext[BindingContext.QUALIFIER, receiver] != null) {
intentionFailed(editor, "package.call")
@@ -47,7 +47,7 @@ fun specifyTypeExplicitly(declaration: JetNamedFunction, typeReference: JetTypeR
fun expressionType(expression: JetExpression): JetType? {
val bindingContext = expression.analyze()
return bindingContext.get(BindingContext.EXPRESSION_TYPE, expression)
return bindingContext.getType(expression)
}
fun functionReturnType(function: JetNamedFunction): JetType? {
@@ -45,9 +45,7 @@ public class DeclarationUtils {
private static JetType getPropertyTypeIfNeeded(@NotNull JetProperty property) {
if (property.getTypeReference() != null) return null;
JetType type = ResolvePackage.analyze(property, BodyResolveMode.FULL).get(
BindingContext.EXPRESSION_TYPE, property.getInitializer()
);
JetType type = ResolvePackage.analyze(property, BodyResolveMode.FULL).getType(property.getInitializer());
return type == null || type.isError() ? null : type;
}
@@ -330,7 +330,7 @@ public class JetFunctionParameterInfoHandler implements ParameterInfoHandlerWith
private static boolean isArgumentTypeValid(BindingContext bindingContext, JetValueArgument argument, ValueParameterDescriptor param) {
if (argument.getArgumentExpression() != null) {
JetType paramType = getActualParameterType(param);
JetType exprType = bindingContext.get(BindingContext.EXPRESSION_TYPE, argument.getArgumentExpression());
JetType exprType = bindingContext.getType(argument.getArgumentExpression());
return exprType == null || JetTypeChecker.DEFAULT.isSubtypeOf(exprType, paramType);
}
@@ -138,7 +138,7 @@ public class AddFunctionParametersFix extends ChangeFunctionSignatureFix {
if (i < parameters.size()) {
validator.validateName(parameters.get(i).getName().asString());
JetType argumentType = expression != null ? bindingContext.get(BindingContext.EXPRESSION_TYPE, expression) : null;
JetType argumentType = expression != null ? bindingContext.getType(expression) : null;
JetType parameterType = parameters.get(i).getType();
if (argumentType != null && !JetTypeChecker.DEFAULT.isSubtypeOf(argumentType, parameterType)) {
@@ -74,7 +74,7 @@ public class AddNameToArgumentFix extends JetIntentionAction<JetValueArgument> {
if (resolvedCall == null) return Collections.emptyList();
CallableDescriptor callableDescriptor = resolvedCall.getResultingDescriptor();
JetType type = context.get(BindingContext.EXPRESSION_TYPE, argument.getArgumentExpression());
JetType type = context.getType(argument.getArgumentExpression());
Set<String> usedParameters = QuickFixUtil.getUsedParameters(callElement, null, callableDescriptor);
List<String> names = Lists.newArrayList();
for (ValueParameterDescriptor parameter: callableDescriptor.getValueParameters()) {
@@ -65,7 +65,7 @@ public class CastExpressionFix extends JetIntentionAction<JetExpression> {
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
if (!super.isAvailable(project, editor, file)) return false;
BindingContext context = ResolvePackage.analyzeFully((JetFile) file);
JetType expressionType = context.get(BindingContext.EXPRESSION_TYPE, element);
JetType expressionType = context.getType(element);
return expressionType != null && JetTypeChecker.DEFAULT.isSubtypeOf(type, expressionType);
}
@@ -58,7 +58,7 @@ public class ChangeFunctionLiteralReturnTypeFix extends JetIntentionAction<JetFu
functionLiteralReturnTypeRef = functionLiteralExpression.getFunctionLiteral().getTypeReference();
BindingContext context = ResolvePackage.analyzeFully(functionLiteralExpression.getContainingJetFile());
JetType functionLiteralType = context.get(BindingContext.EXPRESSION_TYPE, functionLiteralExpression);
JetType functionLiteralType = context.getType(functionLiteralExpression);
assert functionLiteralType != null : "Type of function literal not available in binding context";
ClassDescriptor functionClass = KotlinBuiltIns.getInstance().getFunction(functionLiteralType.getArguments().size() - 1);
@@ -118,7 +118,7 @@ public abstract class ChangeFunctionSignatureFix extends JetIntentionAction<PsiE
) {
String name = getNewArgumentName(argument, validator);
JetExpression expression = argument.getArgumentExpression();
JetType type = expression != null ? bindingContext.get(BindingContext.EXPRESSION_TYPE, expression) : null;
JetType type = expression != null ? bindingContext.getType(expression) : null;
type = type != null ? type : KotlinBuiltIns.getInstance().getNullableAnyType();
JetParameterInfo parameterInfo = new JetParameterInfo(-1, name, type, null, "", JetValVar.None, null);
parameterInfo.setCurrentTypeText(IdeDescriptorRenderers.SOURCE_CODE.renderType(type));
@@ -135,7 +135,7 @@ public abstract class ChangeFunctionSignatureFix extends JetIntentionAction<PsiE
assert i < arguments .size(); // number of parameters must not be greater than the number of arguments (it's called only for TOO_MANY_ARGUMENTS error)
JetExpression argumentExpression = arguments.get(i).getArgumentExpression();
JetType argumentType =
argumentExpression != null ? bindingContext.get(BindingContext.EXPRESSION_TYPE, argumentExpression) : null;
argumentExpression != null ? bindingContext.getType(argumentExpression) : null;
JetType parameterType = parameters.get(i).getType();
if (argumentType == null || !JetTypeChecker.DEFAULT.isSubtypeOf(argumentType, parameterType)) {
@@ -127,7 +127,7 @@ private class LambdaToFunctionExpression(
init {
val bindingContext = functionLiteralExpression.analyze()
val functionLiteralType = bindingContext.get(BindingContext.EXPRESSION_TYPE, functionLiteralExpression)
val functionLiteralType = bindingContext.getType(functionLiteralExpression)
assert(functionLiteralType != null && KotlinBuiltIns.isFunctionOrExtensionFunctionType(functionLiteralType)) {
"Broken function type for expression: ${functionLiteralExpression.getText()}, at: ${DiagnosticUtils.atLocation(functionLiteralExpression)}"
}
@@ -80,7 +80,7 @@ public class QuickFixFactoryForTypeMismatchError extends JetIntentionActionsFact
DiagnosticWithParameters2<JetConstantExpression, String, JetType> diagnosticWithParameters =
Errors.CONSTANT_EXPECTED_TYPE_MISMATCH.cast(diagnostic);
expectedType = diagnosticWithParameters.getB();
expressionType = context.get(BindingContext.EXPRESSION_TYPE, expression);
expressionType = context.getType(expression);
if (expressionType == null) {
LOG.error("No type inferred: " + expression.getText());
return Collections.emptyList();
@@ -155,7 +155,7 @@ public class QuickFixFactoryForTypeMismatchError extends JetIntentionActionsFact
JetParameter correspondingParameter = QuickFixUtil.getParameterDeclarationForValueArgument(resolvedCall, valueArgument);
JetType valueArgumentType = diagnostic.getFactory() == Errors.NULL_FOR_NONNULL_TYPE
? expressionType
: context.get(BindingContext.EXPRESSION_TYPE, valueArgument.getArgumentExpression());
: context.getType(valueArgument.getArgumentExpression());
if (correspondingParameter != null && valueArgumentType != null) {
JetCallableDeclaration callable = PsiTreeUtil.getParentOfType(correspondingParameter, JetCallableDeclaration.class, true);
JetScope scope = callable != null ? JetScopeUtils.getResolutionScope(callable, context) : null;
@@ -55,7 +55,7 @@ private fun DeclarationDescriptor.render(
private fun JetType.render(typeParameterNameMap: Map<TypeParameterDescriptor, String>, fq: Boolean): String {
val arguments = getArguments().map { it.getType().render(typeParameterNameMap, fq) }
val typeString = getConstructor().getDeclarationDescriptor()!!.render(typeParameterNameMap, fq)
val typeArgumentString = if (arguments.notEmpty) arguments.joinToString(", ", "<", ">") else ""
val typeArgumentString = if (arguments.isNotEmpty()) arguments.joinToString(", ", "<", ">") else ""
val nullifier = if (isMarkedNullable()) "?" else ""
return "$typeString$typeArgumentString$nullifier"
}
@@ -73,10 +73,10 @@ private fun getTypeParameterNamesNotInScope(typeParameters: Collection<TypeParam
fun JetType.getTypeParameters(): Set<TypeParameterDescriptor> {
val typeParameters = LinkedHashSet<TypeParameterDescriptor>()
val arguments = getArguments()
if (arguments.empty) {
if (arguments.isEmpty()) {
val descriptor = getConstructor().getDeclarationDescriptor()
if (descriptor is TypeParameterDescriptor) {
typeParameters.add(descriptor as TypeParameterDescriptor)
typeParameters.add(descriptor)
}
}
else {
@@ -100,9 +100,9 @@ fun JetExpression.guessTypes(
&& getNonStrictParentOfType<JetAnnotationEntry>() == null) return array(builtIns.getUnitType())
// if we know the actual type of the expression
val theType1 = context[BindingContext.EXPRESSION_TYPE, this]
val theType1 = context.getType(this)
if (theType1 != null) {
val dataFlowInfo = context[BindingContext.EXPRESSION_DATA_FLOW_INFO, this]
val dataFlowInfo = context[BindingContext.EXPRESSION_TYPE_INFO, this]?.dataFlowInfo
val possibleTypes = dataFlowInfo?.getPossibleTypes(DataFlowValueFactory.createDataFlowValue(this, theType1, context, module))
return if (possibleTypes != null && possibleTypes.isNotEmpty()) possibleTypes.copyToArray() else array(theType1)
}
@@ -117,12 +117,12 @@ fun JetExpression.guessTypes(
return when {
this is JetTypeConstraint -> {
// expression itself is a type assertion
val constraint = (this as JetTypeConstraint)
val constraint = this
array(context[BindingContext.TYPE, constraint.getBoundTypeReference()]!!)
}
parent is JetTypeConstraint -> {
// expression is on the left side of a type assertion
val constraint = (parent as JetTypeConstraint)
val constraint = parent
array(context[BindingContext.TYPE, constraint.getBoundTypeReference()]!!)
}
this is JetMultiDeclarationEntry -> {
@@ -162,7 +162,7 @@ fun JetExpression.guessTypes(
variable.guessType(context)
}
}
parent is JetPropertyDelegate && module != null -> {
parent is JetPropertyDelegate -> {
val property = context[BindingContext.DECLARATION_TO_DESCRIPTOR, parent.getParent() as JetProperty] as PropertyDescriptor
val delegateClassName = if (property.isVar()) "ReadWriteProperty" else "ReadOnlyProperty"
val delegateClass = module.resolveTopLevelClass(FqName("kotlin.properties.$delegateClassName"))
@@ -180,7 +180,7 @@ fun JetExpression.guessTypes(
}
private fun JetNamedDeclaration.guessType(context: BindingContext): Array<JetType> {
val expectedTypes = SearchUtils.findAllReferences(this, getUseScope())!!.stream().map { ref ->
val expectedTypes = SearchUtils.findAllReferences(this, getUseScope())!!.sequence().map { ref ->
if (ref is JetSimpleNameReference) {
context[BindingContext.EXPECTED_EXPRESSION_TYPE, ref.expression]
}
@@ -140,7 +140,7 @@ object CreateCallableFromCallActionFactory : JetIntentionActionsFactory() {
return when {
!receiver.exists() -> TypeInfo.Empty
receiver is Qualifier -> {
val qualifierType = context[BindingContext.EXPRESSION_TYPE, receiver.expression]
val qualifierType = context.getType(receiver.expression)
if (qualifierType != null) return TypeInfo(qualifierType, Variance.IN_VARIANCE)
val classifier = receiver.classifier as? JavaClassDescriptor ?: return null
@@ -427,7 +427,7 @@ public class JetRefactoringUtil {
if (addExpression) {
JetExpression expression = (JetExpression)element;
BindingContext bindingContext = ResolvePackage.analyze(expression, BodyResolveMode.FULL);
JetType expressionType = bindingContext.get(BindingContext.EXPRESSION_TYPE, expression);
JetType expressionType = bindingContext.getType(expression);
if (expressionType == null || !KotlinBuiltIns.isUnit(expressionType)) {
expressions.add(expression);
}
@@ -322,7 +322,7 @@ public class JetChangeSignatureUsageProcessor implements ChangeSignatureUsagePro
FunctionDescriptor functionDescriptor = context.get(BindingContext.FUNCTION, functionLiteral);
assert functionDescriptor != null : "No descriptor for " + functionLiteral.getText();
JetType samCallType = context.get(BindingContext.EXPRESSION_TYPE, callExpression);
JetType samCallType = context.getType(callExpression);
if (samCallType == null) continue;
result.add(new DeferredSAMUsage(functionLiteral, functionDescriptor, samCallType));
@@ -85,8 +85,8 @@ import org.jetbrains.kotlin.utils.DFS.VisitedWithSet
import java.util.*
import kotlin.properties.Delegates
private val DEFAULT_RETURN_TYPE = KotlinBuiltIns.getInstance().getUnitType()!!
private val DEFAULT_PARAMETER_TYPE = KotlinBuiltIns.getInstance().getNullableAnyType()!!
private val DEFAULT_RETURN_TYPE = KotlinBuiltIns.getInstance().getUnitType()
private val DEFAULT_PARAMETER_TYPE = KotlinBuiltIns.getInstance().getNullableAnyType()
private fun DeclarationDescriptor.renderForMessage(): String =
IdeDescriptorRenderers.SOURCE_CODE_SHORT_NAMES_IN_TYPES.render(this)
@@ -158,7 +158,7 @@ private fun List<Instruction>.getResultTypeAndExpressions(
if (expression == null) return null
if (options.inferUnitTypeForUnusedValues && expression.isUsedAsStatement(bindingContext)) return null
return bindingContext[BindingContext.EXPRESSION_TYPE, expression]
return bindingContext.getType(expression)
}
val resultTypes = map(::instructionToType).filterNotNull()
@@ -668,11 +668,11 @@ private fun ExtractionData.inferParametersInfo(
originalDescriptor.getReturnType() ?: DEFAULT_RETURN_TYPE)
}
parameterExpression != null -> bindingContext[BindingContext.SMARTCAST, parameterExpression]
?: bindingContext[BindingContext.EXPRESSION_TYPE, parameterExpression]
?: bindingContext.getType(parameterExpression)
?: if (receiverToExtract.exists()) receiverToExtract.getType() else null
receiverToExtract is ThisReceiver -> {
val calleeExpression = resolvedCall!!.getCall().getCalleeExpression()
bindingContext[BindingContext.EXPRESSION_DATA_FLOW_INFO, calleeExpression]?.let { dataFlowInfo ->
bindingContext[BindingContext.EXPRESSION_TYPE_INFO, calleeExpression]?.dataFlowInfo?.let { dataFlowInfo ->
val possibleTypes = dataFlowInfo.getPossibleTypes(DataFlowValueFactory.createDataFlowValue(receiverToExtract))
if (possibleTypes.isNotEmpty()) CommonSupertypes.commonSupertype(possibleTypes) else null
} ?: receiverToExtract.getType()
@@ -147,7 +147,7 @@ public open class KotlinIntroduceParameterHandler: KotlinIntroduceHandlerBase()
fun invoke(project: Project, editor: Editor, expression: JetExpression, targetParent: JetNamedDeclaration) {
val context = expression.analyze()
val expressionType = context[BindingContext.EXPRESSION_TYPE, expression]
val expressionType = context.getType(expression)
if (expressionType.isUnit() || expressionType.isNothing()) {
val message = JetRefactoringBundle.message(
"cannot.introduce.parameter.of.0.type",
@@ -127,7 +127,7 @@ public class KotlinIntroduceVariableHandler extends KotlinIntroduceHandlerBase {
AnalysisResult analysisResult = ResolvePackage.analyzeAndGetResult(expression);
final BindingContext bindingContext = analysisResult.getBindingContext();
final JetType expressionType = bindingContext.get(BindingContext.EXPRESSION_TYPE, expression); //can be null or error type
final JetType expressionType = bindingContext.getType(expression); //can be null or error type
JetScope scope = bindingContext.get(BindingContext.RESOLUTION_SCOPE, expression);
if (scope != null) {
DataFlowInfo dataFlowInfo = BindingContextUtilPackage.getDataFlowInfo(bindingContext, expression);
@@ -728,7 +728,7 @@ public class JetPsiUnifier(
}
private fun PsiElement.checkType(parameter: UnifierParameter): Boolean {
val targetElementType = (this as? JetExpression)?.let { it.bindingContext[BindingContext.EXPRESSION_TYPE, it] }
val targetElementType = (this as? JetExpression)?.let { it.bindingContext.getType(it) }
return targetElementType != null && JetTypeChecker.DEFAULT.isSubtypeOf(targetElementType, parameter.expectedType)
}
@@ -157,7 +157,7 @@ public abstract class AbstractPartialBodyResolveTest : JetLightCodeInsightFixtur
else {
expression
}
val type = bindingContext[BindingContext.EXPRESSION_TYPE, expressionWithType]
val type = bindingContext.getType(expressionWithType)
return ResolveData(target, type, processedStatements)
}