Convert ExpressionReceiver to kotlin.
This commit is contained in:
+1
-1
@@ -180,7 +180,7 @@ public class JavaNullabilityWarningsChecker : AdditionalTypeChecker {
|
||||
actualMayBeNull ->
|
||||
val reportOn =
|
||||
if (receiverArgument is ExpressionReceiver)
|
||||
receiverArgument.getExpression()
|
||||
receiverArgument.expression
|
||||
else
|
||||
c.call.getCalleeExpression() ?: c.call.getCallElement()
|
||||
|
||||
|
||||
@@ -145,7 +145,7 @@ public class DelegatedPropertyResolver {
|
||||
|
||||
KtPsiFactory psiFactory = KtPsiFactory(delegateExpression);
|
||||
List<KtExpression> arguments = Collections.singletonList(createExpressionForProperty(psiFactory));
|
||||
ExpressionReceiver receiver = ExpressionReceiver.create(delegateExpression, delegateType, trace.getBindingContext());
|
||||
ExpressionReceiver receiver = ExpressionReceiver.Companion.create(delegateExpression, delegateType, trace.getBindingContext());
|
||||
|
||||
Pair<Call, OverloadResolutionResults<FunctionDescriptor>> resolutionResult =
|
||||
fakeCallResolver.makeAndResolveFakeCallInContext(receiver, context, arguments, PROPERTY_DELEGATED_FUNCTION_NAME, delegateExpression);
|
||||
@@ -261,7 +261,7 @@ public class DelegatedPropertyResolver {
|
||||
}
|
||||
|
||||
Name functionName = isGet ? GETTER_NAME : SETTER_NAME;
|
||||
ExpressionReceiver receiver = ExpressionReceiver.create(delegateExpression, delegateType, trace.getBindingContext());
|
||||
ExpressionReceiver receiver = ExpressionReceiver.Companion.create(delegateExpression, delegateType, trace.getBindingContext());
|
||||
|
||||
Pair<Call, OverloadResolutionResults<FunctionDescriptor>> resolutionResult =
|
||||
fakeCallResolver.makeAndResolveFakeCallInContext(receiver, context, arguments, functionName, delegateExpression);
|
||||
|
||||
+1
-1
@@ -349,7 +349,7 @@ public class CallExpressionResolver {
|
||||
QualifierReceiver qualifierReceiver = (QualifierReceiver) context.trace.get(BindingContext.QUALIFIER, element.getReceiver());
|
||||
|
||||
ReceiverValue receiver = qualifierReceiver == null ?
|
||||
ExpressionReceiver.create(element.getReceiver(), receiverType, context.trace.getBindingContext()) :
|
||||
ExpressionReceiver.Companion.create(element.getReceiver(), receiverType, context.trace.getBindingContext()) :
|
||||
qualifierReceiver;
|
||||
|
||||
boolean lastStage = element.getQualified() == expression;
|
||||
|
||||
@@ -315,7 +315,7 @@ public class CallResolver {
|
||||
}
|
||||
KotlinType calleeType = expressionTypingServices.safeGetType(
|
||||
context.scope, calleeExpression, expectedType, context.dataFlowInfo, context.trace);
|
||||
ExpressionReceiver expressionReceiver = ExpressionReceiver.create(calleeExpression, calleeType, context.trace.getBindingContext());
|
||||
ExpressionReceiver expressionReceiver = ExpressionReceiver.Companion.create(calleeExpression, calleeType, context.trace.getBindingContext());
|
||||
|
||||
Call call = new CallTransformer.CallForImplicitInvoke(context.call.getExplicitReceiver(), expressionReceiver, context.call);
|
||||
TracingStrategyForInvoke tracingForInvoke = new TracingStrategyForInvoke(calleeExpression, call, calleeType);
|
||||
|
||||
@@ -133,7 +133,7 @@ public fun isInvokeCallOnVariable(call: Call): Boolean {
|
||||
if (call.getCallType() !== Call.CallType.INVOKE) return false
|
||||
val dispatchReceiver = call.getDispatchReceiver()
|
||||
//calleeExpressionAsDispatchReceiver for invoke is always ExpressionReceiver, see CallForImplicitInvoke
|
||||
val expression = (dispatchReceiver as ExpressionReceiver).getExpression()
|
||||
val expression = (dispatchReceiver as ExpressionReceiver).expression
|
||||
return expression is KtSimpleNameExpression
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ public fun isInvokeCallOnExpressionWithBothReceivers(call: Call): Boolean {
|
||||
}
|
||||
|
||||
public fun getSuperCallExpression(call: Call): KtSuperExpression? {
|
||||
return (call.getExplicitReceiver() as? ExpressionReceiver)?.getExpression() as? KtSuperExpression
|
||||
return (call.getExplicitReceiver() as? ExpressionReceiver)?.expression as? KtSuperExpression
|
||||
}
|
||||
|
||||
public fun getEffectiveExpectedType(parameterDescriptor: ValueParameterDescriptor, argument: ValueArgument): KotlinType {
|
||||
|
||||
@@ -235,7 +235,7 @@ public class CallTransformer<D extends CallableDescriptor, F extends D> {
|
||||
KtExpression calleeExpression = task.call.getCalleeExpression();
|
||||
if (calleeExpression == null) return Collections.emptyList();
|
||||
|
||||
ExpressionReceiver variableReceiver = ExpressionReceiver.create(
|
||||
ExpressionReceiver variableReceiver = ExpressionReceiver.Companion.create(
|
||||
calleeExpression, variableResolvedCall.getResultingDescriptor().getType(), context.trace.getBindingContext());
|
||||
Call functionCall = new CallForImplicitInvoke(context.explicitExtensionReceiverForInvoke, variableReceiver, task.call);
|
||||
|
||||
|
||||
@@ -285,7 +285,7 @@ public class CandidateResolver(
|
||||
|
||||
private fun getReceiverSuper(receiver: ReceiverValue): KtSuperExpression? {
|
||||
if (receiver is ExpressionReceiver) {
|
||||
val expression = receiver.getExpression()
|
||||
val expression = receiver.expression
|
||||
if (expression is KtSuperExpression) {
|
||||
return expression
|
||||
}
|
||||
|
||||
+1
-1
@@ -99,7 +99,7 @@ class GenericCandidateResolver(
|
||||
else
|
||||
receiverArgument.getType()
|
||||
if (receiverArgument is ExpressionReceiver) {
|
||||
receiverType = updateResultTypeForSmartCasts(receiverType, receiverArgument.getExpression(), context)
|
||||
receiverType = updateResultTypeForSmartCasts(receiverType, receiverArgument.expression, context)
|
||||
}
|
||||
constraintSystem.addSubtypeConstraint(receiverType, receiverParameter.getType(), RECEIVER_POSITION.position())
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ private fun ResolvedCall<*>.hasThisOrNoDispatchReceiver(
|
||||
dispatchReceiverDescriptor = dispatchReceiverValue.getDeclarationDescriptor()
|
||||
}
|
||||
else if (dispatchReceiverValue is ExpressionReceiver && considerExplicitReceivers) {
|
||||
val expression = KtPsiUtil.deparenthesize(dispatchReceiverValue.getExpression())
|
||||
val expression = KtPsiUtil.deparenthesize(dispatchReceiverValue.expression)
|
||||
if (expression is KtThisExpression) {
|
||||
// this.foo() -- explicit receiver
|
||||
dispatchReceiverDescriptor = context.get(BindingContext.REFERENCE_TARGET, expression.getInstanceReference())
|
||||
|
||||
-50
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.resolve.scopes.receivers;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.psi.KtExpression;
|
||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
|
||||
public class ExpressionReceiver extends AbstractReceiverValue implements ReceiverValue {
|
||||
|
||||
public static ExpressionReceiver create(
|
||||
@NotNull KtExpression expression,
|
||||
@NotNull KotlinType type,
|
||||
@NotNull BindingContext bindingContext
|
||||
) {
|
||||
return new ExpressionReceiver(expression, type);
|
||||
}
|
||||
|
||||
private final KtExpression expression;
|
||||
|
||||
public ExpressionReceiver(@NotNull KtExpression expression, @NotNull KotlinType type) {
|
||||
super(type);
|
||||
this.expression = expression;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public KtExpression getExpression() {
|
||||
return expression;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getType() + " {" + expression + ": " + expression.getText() + "}";
|
||||
}
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.resolve.scopes.receivers
|
||||
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
|
||||
class ExpressionReceiver(val expression: KtExpression, type: KotlinType) : AbstractReceiverValue(type), ReceiverValue {
|
||||
|
||||
override fun toString() = "$type {$expression: ${expression.text}}"
|
||||
|
||||
companion object {
|
||||
|
||||
fun create(
|
||||
expression: KtExpression,
|
||||
type: KotlinType,
|
||||
bindingContext: BindingContext): ExpressionReceiver {
|
||||
return ExpressionReceiver(expression, type)
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -760,7 +760,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
// Type check the base expression
|
||||
KotlinTypeInfo typeInfo = facade.safeGetTypeInfo(baseExpression, context);
|
||||
KotlinType type = ExpressionTypingUtils.safeGetType(typeInfo);
|
||||
ExpressionReceiver receiver = ExpressionReceiver.create(baseExpression, type, context.trace.getBindingContext());
|
||||
ExpressionReceiver receiver = ExpressionReceiver.Companion.create(baseExpression, type, context.trace.getBindingContext());
|
||||
|
||||
Call call = CallMaker.makeCall(receiver, expression);
|
||||
|
||||
@@ -1495,7 +1495,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
KotlinType arrayType = ExpressionTypingUtils.safeGetType(arrayTypeInfo);
|
||||
|
||||
ExpressionTypingContext context = oldContext.replaceDataFlowInfo(arrayTypeInfo.getDataFlowInfo());
|
||||
ExpressionReceiver receiver = ExpressionReceiver.create(arrayExpression, arrayType, context.trace.getBindingContext());
|
||||
ExpressionReceiver receiver = ExpressionReceiver.Companion.create(arrayExpression, arrayType, context.trace.getBindingContext());
|
||||
if (!isGet) assert rightHandSide != null;
|
||||
|
||||
Call call = isGet
|
||||
|
||||
+2
-2
@@ -79,7 +79,7 @@ public class ExpressionTypingUtils {
|
||||
) {
|
||||
KotlinType type = facade.getTypeInfo(expression, context).getType();
|
||||
if (type == null) return null;
|
||||
return ExpressionReceiver.create(expression, type, context.trace.getBindingContext());
|
||||
return ExpressionReceiver.Companion.create(expression, type, context.trace.getBindingContext());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -89,7 +89,7 @@ public class ExpressionTypingUtils {
|
||||
ExpressionTypingContext context
|
||||
) {
|
||||
KotlinType type = safeGetType(facade.safeGetTypeInfo(expression, context));
|
||||
return ExpressionReceiver.create(expression, type, context.trace.getBindingContext());
|
||||
return ExpressionReceiver.Companion.create(expression, type, context.trace.getBindingContext());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+1
-1
@@ -250,7 +250,7 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
|
||||
temporary.commit();
|
||||
return rightInfo.clearType();
|
||||
}
|
||||
ExpressionReceiver receiver = ExpressionReceiver.create(left, leftType, context.trace.getBindingContext());
|
||||
ExpressionReceiver receiver = ExpressionReceiver.Companion.create(left, leftType, context.trace.getBindingContext());
|
||||
|
||||
// We check that defined only one of '+=' and '+' operations, and call it (in the case '+' we then also assign)
|
||||
// Check for '+='
|
||||
|
||||
@@ -76,7 +76,7 @@ public abstract class AbstractResolvedCallsTest : KotlinLiteFixture() {
|
||||
}
|
||||
|
||||
private fun ReceiverValue.getText() = when (this) {
|
||||
is ExpressionReceiver -> "${getExpression().getText()} {${getType()}}"
|
||||
is ExpressionReceiver -> "${expression.getText()} {${getType()}}"
|
||||
is ClassReceiver -> "Class{${getType()}}"
|
||||
is ExtensionReceiver -> "${getType()}Ext{${getDeclarationDescriptor().getText()}}"
|
||||
else -> toString()
|
||||
|
||||
@@ -105,7 +105,7 @@ public fun <TCallable : CallableDescriptor> TCallable.substituteExtensionIfCalla
|
||||
public fun ReceiverValue.getThisReceiverOwner(bindingContext: BindingContext): DeclarationDescriptor? {
|
||||
return when (this) {
|
||||
is ExpressionReceiver -> {
|
||||
val thisRef = (KtPsiUtil.deparenthesize(this.getExpression()) as? KtThisExpression)?.getInstanceReference() ?: return null
|
||||
val thisRef = (KtPsiUtil.deparenthesize(this.expression) as? KtThisExpression)?.getInstanceReference() ?: return null
|
||||
bindingContext[BindingContext.REFERENCE_TARGET, thisRef]
|
||||
}
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ public class ConvertForEachToForLoopIntention : SelfTargetingOffsetIndependentIn
|
||||
val receiver = resolvedCall.getCall().getExplicitReceiver() as? ExpressionReceiver ?: return null
|
||||
val argument = resolvedCall.getCall().getValueArguments().singleOrNull() ?: return null
|
||||
val functionLiteral = argument.getArgumentExpression() as? KtFunctionLiteralExpression ?: return null
|
||||
return Data(expression, receiver.getExpression(), functionLiteral)
|
||||
return Data(expression, receiver.expression, functionLiteral)
|
||||
}
|
||||
|
||||
private fun generateLoop(functionLiteral: KtFunctionLiteralExpression, receiver: KtExpression): KtExpression {
|
||||
|
||||
@@ -131,7 +131,7 @@ public class KotlinPsiUnifier(
|
||||
private fun matchReceivers(rv1: ReceiverValue, rv2: ReceiverValue): Boolean {
|
||||
return when {
|
||||
rv1 is ExpressionReceiver && rv2 is ExpressionReceiver ->
|
||||
doUnify(rv1.getExpression(), rv2.getExpression()) == MATCHED
|
||||
doUnify(rv1.expression, rv2.expression) == MATCHED
|
||||
|
||||
rv1 is ThisReceiver && rv2 is ThisReceiver ->
|
||||
matchDescriptors(rv1.getDeclarationDescriptor(), rv2.getDeclarationDescriptor())
|
||||
@@ -211,7 +211,7 @@ public class KotlinPsiUnifier(
|
||||
null to null
|
||||
}
|
||||
|
||||
val thisExpression = explicitReceiver?.getExpression() as? KtThisExpression
|
||||
val thisExpression = explicitReceiver?.expression as? KtThisExpression
|
||||
if (implicitReceiver == null || thisExpression == null) return false
|
||||
|
||||
return matchDescriptors(
|
||||
|
||||
+1
-1
@@ -41,7 +41,7 @@ fun CallInfo.isNative(): Boolean = AnnotationsUtils.isNativeObject(callableDescr
|
||||
|
||||
fun CallInfo.isSuperInvocation(): Boolean {
|
||||
val dispatchReceiver = resolvedCall.getDispatchReceiver()
|
||||
return dispatchReceiver is ExpressionReceiver && dispatchReceiver.getExpression() is KtSuperExpression
|
||||
return dispatchReceiver is ExpressionReceiver && dispatchReceiver.expression is KtSuperExpression
|
||||
}
|
||||
|
||||
val VariableAccessInfo.variableDescriptor: VariableDescriptor
|
||||
|
||||
+1
-1
@@ -125,7 +125,7 @@ fun computeExplicitReceiversForInvoke(
|
||||
assert(explicitReceivers.extensionReceiver == null) { "'Invoke' call must have one receiver: $callElement" }
|
||||
|
||||
fun translateReceiverAsExpression(receiver: ReceiverValue): JsExpression? =
|
||||
(receiver as? ExpressionReceiver)?.let { Translation.translateAsExpression(it.getExpression(), context) }
|
||||
(receiver as? ExpressionReceiver)?.let { Translation.translateAsExpression(it.expression, context) }
|
||||
|
||||
val dispatchReceiver = resolvedCall.getDispatchReceiver()
|
||||
val extensionReceiver = resolvedCall.getExtensionReceiver()
|
||||
|
||||
Reference in New Issue
Block a user