Android Extensions: Generate proper receiver for clearFindViewByIdCache() call (KT-19742)
This commit is contained in:
committed by
Yan Zhulanow
parent
f84df6381e
commit
07be1e9d10
@@ -1705,7 +1705,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
|
||||
Collection<ExpressionCodegenExtension> codegenExtensions = ExpressionCodegenExtension.Companion.getInstances(state.getProject());
|
||||
if (!codegenExtensions.isEmpty() && resolvedCall != null) {
|
||||
ExpressionCodegenExtension.Context context = new ExpressionCodegenExtension.Context(typeMapper, v);
|
||||
ExpressionCodegenExtension.Context context = new ExpressionCodegenExtension.Context(this, typeMapper, v);
|
||||
KotlinType returnType = propertyDescriptor.getReturnType();
|
||||
for (ExpressionCodegenExtension extension : codegenExtensions) {
|
||||
if (returnType != null) {
|
||||
@@ -2141,7 +2141,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
|
||||
Collection<ExpressionCodegenExtension> codegenExtensions = ExpressionCodegenExtension.Companion.getInstances(state.getProject());
|
||||
if (!codegenExtensions.isEmpty()) {
|
||||
ExpressionCodegenExtension.Context context = new ExpressionCodegenExtension.Context(typeMapper, v);
|
||||
ExpressionCodegenExtension.Context context = new ExpressionCodegenExtension.Context(this, typeMapper, v);
|
||||
for (ExpressionCodegenExtension extension : codegenExtensions) {
|
||||
StackValue stackValue = extension.applyFunction(receiver, resolvedCall, context);
|
||||
if (stackValue != null) return stackValue;
|
||||
|
||||
+2
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.codegen.extensions
|
||||
|
||||
import org.jetbrains.kotlin.codegen.ExpressionCodegen
|
||||
import org.jetbrains.kotlin.codegen.ImplementationBodyCodegen
|
||||
import org.jetbrains.kotlin.codegen.StackValue
|
||||
import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper
|
||||
@@ -28,6 +29,7 @@ interface ExpressionCodegenExtension {
|
||||
"org.jetbrains.kotlin.expressionCodegenExtension", ExpressionCodegenExtension::class.java)
|
||||
|
||||
class Context(
|
||||
val codegen: ExpressionCodegen,
|
||||
val typeMapper: KotlinTypeMapper,
|
||||
val v: InstructionAdapter
|
||||
)
|
||||
|
||||
+2
-1
@@ -103,11 +103,12 @@ abstract class AbstractAndroidExtensionsExpressionCodegenExtension : ExpressionC
|
||||
}
|
||||
|
||||
if (containerOptions.containerType == AndroidContainerType.UNKNOWN) return null
|
||||
val actualReceiver = StackValue.receiver(resolvedCall, receiver, c.codegen, null)
|
||||
|
||||
return StackValue.functionCall(Type.VOID_TYPE) {
|
||||
val bytecodeClassName = c.typeMapper.mapType(container).internalName
|
||||
|
||||
receiver.put(c.typeMapper.mapType(container), it)
|
||||
actualReceiver.put(c.typeMapper.mapType(container), it)
|
||||
it.invokevirtual(bytecodeClassName, CLEAR_CACHE_METHOD_NAME, "()V", false)
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+4
-1
@@ -7,6 +7,7 @@ import android.view.View
|
||||
import android.widget.*
|
||||
import org.my.cool.MyButton
|
||||
import kotlinx.android.synthetic.main.layout.*
|
||||
import kotlinx.android.synthetic.clearFindViewByIdCache
|
||||
|
||||
class R {
|
||||
class id {
|
||||
@@ -36,7 +37,9 @@ class MyFragment(): Fragment() {
|
||||
override fun getView(): View = baseView
|
||||
|
||||
public fun box(): String {
|
||||
return if (login.toString() == "MyButton") "OK" else ""
|
||||
val result = if (login.toString() == "MyButton") "OK" else ""
|
||||
clearFindViewByIdCache()
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Vendored
+10
-5
@@ -4,6 +4,7 @@ import android.app.Activity
|
||||
import android.view.View
|
||||
import android.widget.*
|
||||
import kotlinx.android.synthetic.main.layout.*
|
||||
import kotlinx.android.synthetic.clearFindViewByIdCache
|
||||
|
||||
class R {
|
||||
class id {
|
||||
@@ -32,11 +33,15 @@ class MyActivity(): Activity() {
|
||||
}
|
||||
}
|
||||
|
||||
public fun box(): String{
|
||||
return if (textView1.toString() == "TextView" &&
|
||||
password.toString() == "EditText" &&
|
||||
login.toString() == "Button")
|
||||
"OK" else ""
|
||||
public fun box(): String {
|
||||
val result = when {
|
||||
textView1.toString() == "TextView" && password.toString() == "EditText" && login.toString() == "Button" -> "OK"
|
||||
else -> ""
|
||||
}
|
||||
|
||||
clearFindViewByIdCache()
|
||||
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user