ExpressionCodegenExtension extracted
This commit is contained in:
committed by
Yan Zhulanow
parent
e10d8a6fe0
commit
5811b13ce7
@@ -15,6 +15,5 @@
|
||||
<orderEntry type="module" module-name="serialization.jvm" />
|
||||
<orderEntry type="module" module-name="backend-common" exported="" />
|
||||
<orderEntry type="module" module-name="util" />
|
||||
<orderEntry type="module" module-name="android-compiler-plugin" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2010-2014 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.jet.codegen.extensions
|
||||
|
||||
import org.jetbrains.jet.extensions.ProjectExtensionDescriptor
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall
|
||||
import org.jetbrains.jet.codegen.StackValue
|
||||
import org.jetbrains.jet.codegen.state.JetTypeMapper
|
||||
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
|
||||
|
||||
public trait ExpressionCodegenExtension {
|
||||
class object : ProjectExtensionDescriptor<ExpressionCodegenExtension>("org.jetbrains.kotlin.expressionCodegenExtension", javaClass<ExpressionCodegenExtension>())
|
||||
|
||||
public class Context(
|
||||
public val typeMapper: JetTypeMapper,
|
||||
public val v: InstructionAdapter
|
||||
)
|
||||
|
||||
// return null if not applicable
|
||||
public fun apply(receiver: StackValue, resolvedCall: ResolvedCall<*>, c: ExpressionCodegenExtension.Context): StackValue?
|
||||
}
|
||||
@@ -30,6 +30,7 @@ import kotlin.KotlinPackage;
|
||||
import kotlin.Unit;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.codegen.extensions.ExpressionCodegenExtension;
|
||||
import org.jetbrains.kotlin.backend.common.CodegenUtil;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
import org.jetbrains.kotlin.codegen.binding.CalculatedClosure;
|
||||
@@ -1888,20 +1889,10 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
if (descriptor instanceof PropertyDescriptor) {
|
||||
PropertyDescriptor propertyDescriptor = (PropertyDescriptor) descriptor;
|
||||
|
||||
JetFile file = DescriptorToSourceUtils.getContainingFile(propertyDescriptor);
|
||||
if (file != null) {
|
||||
String androidPackage = file.getUserData(ANDROID_USER_PACKAGE);
|
||||
if (androidPackage != null) {
|
||||
for (ExpressionCodegenExtension extension : ExpressionCodegenExtension.OBJECT$.getInstances(state.getProject())) {
|
||||
StackValue result = extension.apply(receiver, resolvedCall, new ExpressionCodegenExtension.Context(typeMapper, v));
|
||||
|
||||
Type retType = typeMapper.mapType(propertyDescriptor.getReturnType());
|
||||
v.load(0, Type.getType("Landroid/app/Activity;"));
|
||||
v.getstatic(androidPackage.replace(".", "/") + "/R$id",
|
||||
propertyDescriptor.getName().asString(), "I");
|
||||
v.invokevirtual("android/app/Activity", "findViewById", "(I)" + "Landroid/view/View;", false);
|
||||
v.checkcast(retType);
|
||||
|
||||
return StackValue.onStack(retType);
|
||||
}
|
||||
if (result != null) return result;
|
||||
}
|
||||
|
||||
boolean directToField =
|
||||
|
||||
Reference in New Issue
Block a user