diff --git a/compiler/backend/backend.iml b/compiler/backend/backend.iml
index 99dd590be05..37d5b825d8e 100644
--- a/compiler/backend/backend.iml
+++ b/compiler/backend/backend.iml
@@ -15,6 +15,5 @@
-
diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/extensions/ExpressionCodegenExtension.kt b/compiler/backend/src/org/jetbrains/jet/codegen/extensions/ExpressionCodegenExtension.kt
new file mode 100644
index 00000000000..1b61580ec2b
--- /dev/null
+++ b/compiler/backend/src/org/jetbrains/jet/codegen/extensions/ExpressionCodegenExtension.kt
@@ -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("org.jetbrains.kotlin.expressionCodegenExtension", javaClass())
+
+ 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?
+}
\ No newline at end of file
diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java
index cd0701a118d..5f89f92d4c4 100644
--- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java
+++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java
@@ -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 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 =
diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/JetCoreEnvironment.java b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/JetCoreEnvironment.java
index 2a4ddcffb52..ef7842b78b7 100644
--- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/JetCoreEnvironment.java
+++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/JetCoreEnvironment.java
@@ -56,6 +56,7 @@ import kotlin.Function1;
import kotlin.Unit;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.TestOnly;
+import org.jetbrains.jet.codegen.extensions.ExpressionCodegenExtension;
import org.jetbrains.jet.extensions.ExternalDeclarationsProvider;
import org.jetbrains.kotlin.asJava.JavaElementFinder;
import org.jetbrains.kotlin.asJava.KotlinLightClassForPackage;
@@ -302,6 +303,7 @@ public class JetCoreEnvironment {
}
ExternalDeclarationsProvider.OBJECT$.registerExtensionPoint(project);
+ ExpressionCodegenExtension.OBJECT$.registerExtensionPoint(project);
}
private static void registerProjectExtensionPoints(ExtensionsArea area) {
diff --git a/idea/src/META-INF/extensions/common.xml b/idea/src/META-INF/extensions/common.xml
index 4358b2f2fc2..fa3dc2573fc 100644
--- a/idea/src/META-INF/extensions/common.xml
+++ b/idea/src/META-INF/extensions/common.xml
@@ -11,5 +11,8 @@
+
diff --git a/plugins/android-compiler-plugin/android-compiler-plugin.iml b/plugins/android-compiler-plugin/android-compiler-plugin.iml
index 7f3d72c1033..f98690d4736 100644
--- a/plugins/android-compiler-plugin/android-compiler-plugin.iml
+++ b/plugins/android-compiler-plugin/android-compiler-plugin.iml
@@ -12,6 +12,7 @@
+
diff --git a/plugins/android-compiler-plugin/src/AndroidComponentRegistrar.kt b/plugins/android-compiler-plugin/src/AndroidComponentRegistrar.kt
index 7bcde46eafc..a61413727aa 100644
--- a/plugins/android-compiler-plugin/src/AndroidComponentRegistrar.kt
+++ b/plugins/android-compiler-plugin/src/AndroidComponentRegistrar.kt
@@ -29,6 +29,13 @@ import org.jetbrains.jet.lang.resolve.android.*
import com.intellij.openapi.components.ServiceManager
import org.jetbrains.jet.utils.emptyOrSingletonList
import com.intellij.openapi.project.Project
+import org.jetbrains.jet.codegen.extensions.ExpressionCodegenExtension
+import org.jetbrains.jet.lang.descriptors.CallableDescriptor
+import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall
+import org.jetbrains.jet.codegen.StackValue
+import org.jetbrains.jet.lang.descriptors.PropertyDescriptor
+import org.jetbrains.org.objectweb.asm.Type
+import org.jetbrains.jet.lang.resolve.DescriptorToSourceUtils
public object AndroidConfigurationKeys {
@@ -65,6 +72,28 @@ public class AndroidDeclarationsProvider(private val project: Project) : Externa
}
}
+public class AndroidExpressionCodegen : ExpressionCodegenExtension {
+ override fun apply(receiver: StackValue, resolvedCall: ResolvedCall<*>, c: ExpressionCodegenExtension.Context): StackValue? {
+ if (resolvedCall.getResultingDescriptor() !is PropertyDescriptor) return null
+
+ val propertyDescriptor = resolvedCall.getResultingDescriptor() as PropertyDescriptor
+
+ val file = DescriptorToSourceUtils.getContainingFile(propertyDescriptor)
+ if (file == null) return null
+
+ val androidPackage = file.getUserData(AndroidConst.ANDROID_USER_PACKAGE)
+ if (androidPackage == null) return null
+
+ val retType = c.typeMapper.mapType(propertyDescriptor.getReturnType()!!)
+ receiver.put(Type.getType("Landroid/app/Activity;"), c.v)
+ c.v.getstatic(androidPackage.replace(".", "/") + "/R\$id", propertyDescriptor.getName().asString(), "I")
+ c.v.invokevirtual("android/app/Activity", "findViewById", "(I)" + "Landroid/view/View;", false)
+ c.v.checkcast(retType)
+
+ return StackValue.onStack(retType)
+ }
+}
+
public class AndroidComponentRegistrar : ComponentRegistrar {
public override fun registerProjectComponents(project: MockProject, configuration: CompilerConfiguration) {
@@ -73,5 +102,6 @@ public class AndroidComponentRegistrar : ComponentRegistrar {
project.registerService(javaClass(), CliAndroidUIXmlProcessor(project, androidResPath, androidManifest))
ExternalDeclarationsProvider.registerExtension(project, AndroidDeclarationsProvider(project))
+ ExpressionCodegenExtension.registerExtension(project, AndroidExpressionCodegen())
}
}
\ No newline at end of file
diff --git a/plugins/android-idea-plugin/src/META-INF/plugin.xml b/plugins/android-idea-plugin/src/META-INF/plugin.xml
index 2784221df50..2bcea2154bc 100644
--- a/plugins/android-idea-plugin/src/META-INF/plugin.xml
+++ b/plugins/android-idea-plugin/src/META-INF/plugin.xml
@@ -18,5 +18,6 @@
+