From 17c930c84f5f1c6a021d1e5ffb44fb27ae5ceb99 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Tue, 9 Dec 2014 00:56:56 +0300 Subject: [PATCH] Use abstract factory for reflection objects on JVM Introduce an abstract factory class ReflectionFactory which is responsible for creating reflection objects (KClass, KProperty, ...). The meaningful implementation is located in "reflection.jvm" where KClassImpl/KPropertyImpl/... are accessible and can be instantiated. The default implementation will be used in the lite runtime with no reflection and will return nulls / throw exceptions there. Put all functions, calls to which are generated by JVM back-end, in one place: the class named Reflection which contains only static methods. Previously these functions were scattered across different files in module "reflection.jvm". The code using reflection may now be compiled against either runtime, but reflection features will work if and only if reflection is accessible at runtime --- .../kotlin/codegen/ExpressionCodegen.java | 40 +++++----- .../codegen/ImplementationBodyCodegen.java | 2 +- .../kotlin/codegen/MemberCodegen.java | 2 +- .../kotlin/codegen/PackageCodegen.java | 4 +- .../kotlin/codegen/ScriptCodegen.java | 2 +- .../kotlin/resolve/jvm/AsmTypes.java | 22 +++--- .../jvm/internal/ReflectionFactoryImpl.java | 68 ++++++++++++++++ .../kotlin/reflect/jvm/internal/factory.kt | 5 +- .../reflect/jvm/internal/InternalPackage.java | 33 -------- .../reflect/jvm/internal/KClassImpl.java | 22 ------ .../reflect/jvm/internal/KPackageImpl.java | 22 ------ .../KotlinReflectionNotSupportedError.java | 2 +- .../src/kotlin/jvm/internal/Reflection.java | 77 +++++++++++++++++++ .../jvm/internal/ReflectionFactory.java | 62 +++++++++++++++ 14 files changed, 247 insertions(+), 116 deletions(-) create mode 100644 core/reflection.jvm/src/kotlin/reflect/jvm/internal/ReflectionFactoryImpl.java delete mode 100644 core/reflection.stub.jvm/src/kotlin/reflect/jvm/internal/InternalPackage.java delete mode 100644 core/reflection.stub.jvm/src/kotlin/reflect/jvm/internal/KClassImpl.java delete mode 100644 core/reflection.stub.jvm/src/kotlin/reflect/jvm/internal/KPackageImpl.java rename core/{reflection.stub.jvm/src/kotlin/reflect => runtime.jvm/src/kotlin}/jvm/KotlinReflectionNotSupportedError.java (97%) create mode 100644 core/runtime.jvm/src/kotlin/jvm/internal/Reflection.java create mode 100644 core/runtime.jvm/src/kotlin/jvm/internal/ReflectionFactory.java diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java index 85f4a2c1ec7..d4c59968fef 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java @@ -2640,57 +2640,59 @@ public class ExpressionCodegen extends JetVisitor implem final ReceiverParameterDescriptor receiverParameter = descriptor.getExtensionReceiverParameter(); final Method factoryMethod; if (receiverParameter != null) { - Type[] parameterTypes = new Type[] {JAVA_STRING_TYPE, K_PACKAGE_IMPL_TYPE, getType(Class.class)}; + Type[] parameterTypes = new Type[] {JAVA_STRING_TYPE, K_PACKAGE_TYPE, getType(Class.class)}; factoryMethod = descriptor.isVar() - ? method("mutableTopLevelExtensionProperty", K_MUTABLE_TOP_LEVEL_EXTENSION_PROPERTY_IMPL_TYPE, parameterTypes) - : method("topLevelExtensionProperty", K_TOP_LEVEL_EXTENSION_PROPERTY_IMPL_TYPE, parameterTypes); + ? method("mutableTopLevelExtensionProperty", K_MUTABLE_TOP_LEVEL_EXTENSION_PROPERTY_TYPE, parameterTypes) + : method("topLevelExtensionProperty", K_TOP_LEVEL_EXTENSION_PROPERTY_TYPE, parameterTypes); } else { - Type[] parameterTypes = new Type[] {JAVA_STRING_TYPE, K_PACKAGE_IMPL_TYPE}; + Type[] parameterTypes = new Type[] {JAVA_STRING_TYPE, K_PACKAGE_TYPE}; factoryMethod = descriptor.isVar() - ? method("mutableTopLevelVariable", K_MUTABLE_TOP_LEVEL_VARIABLE_IMPL_TYPE, parameterTypes) - : method("topLevelVariable", K_TOP_LEVEL_VARIABLE_IMPL_TYPE, parameterTypes); + ? method("mutableTopLevelVariable", K_MUTABLE_TOP_LEVEL_VARIABLE_TYPE, parameterTypes) + : method("topLevelVariable", K_TOP_LEVEL_VARIABLE_TYPE, parameterTypes); } return StackValue.operation(factoryMethod.getReturnType(), new Function1() { @Override public Unit invoke(InstructionAdapter v) { v.visitLdcInsn(descriptor.getName().asString()); - v.getstatic(packageClassInternalName, JvmAbi.KOTLIN_PACKAGE_FIELD_NAME, K_PACKAGE_IMPL_TYPE.getDescriptor()); + v.getstatic(packageClassInternalName, JvmAbi.KOTLIN_PACKAGE_FIELD_NAME, K_PACKAGE_TYPE.getDescriptor()); if (receiverParameter != null) { putJavaLangClassInstance(v, typeMapper.mapType(receiverParameter)); } - v.invokestatic(REFLECTION_INTERNAL_PACKAGE, factoryMethod.getName(), factoryMethod.getDescriptor(), false); + v.invokestatic(REFLECTION, factoryMethod.getName(), factoryMethod.getDescriptor(), false); return Unit.INSTANCE$; } }); } @NotNull - private StackValue generateMemberPropertyReference(@NotNull final VariableDescriptor descriptor, @NotNull final ClassDescriptor containingClass) { - final Type classAsmType = typeMapper.mapClass(containingClass); - + private StackValue generateMemberPropertyReference( + @NotNull final VariableDescriptor descriptor, + @NotNull final ClassDescriptor containingClass + ) { final Method factoryMethod = descriptor.isVar() - ? method("mutableMemberProperty", K_MUTABLE_MEMBER_PROPERTY_TYPE, JAVA_STRING_TYPE) - : method("memberProperty", K_MEMBER_PROPERTY_TYPE, JAVA_STRING_TYPE); + ? method("mutableMemberProperty", K_MUTABLE_MEMBER_PROPERTY_TYPE, JAVA_STRING_TYPE, K_CLASS_TYPE) + : method("memberProperty", K_MEMBER_PROPERTY_TYPE, JAVA_STRING_TYPE, K_CLASS_TYPE); return StackValue.operation(factoryMethod.getReturnType(), new Function1() { @Override public Unit invoke(InstructionAdapter v) { + v.visitLdcInsn(descriptor.getName().asString()); + + Type classAsmType = typeMapper.mapClass(containingClass); + if (containingClass instanceof JavaClassDescriptor) { v.aconst(classAsmType); - v.invokestatic(REFLECTION_INTERNAL_PACKAGE, "foreignKotlinClass", - Type.getMethodDescriptor(K_CLASS_IMPL_TYPE, getType(Class.class)), false); + v.invokestatic(REFLECTION, "foreignKotlinClass", Type.getMethodDescriptor(K_CLASS_TYPE, getType(Class.class)), false); } else { - v.getstatic(classAsmType.getInternalName(), JvmAbi.KOTLIN_CLASS_FIELD_NAME, K_CLASS_IMPL_TYPE.getDescriptor()); + v.getstatic(classAsmType.getInternalName(), JvmAbi.KOTLIN_CLASS_FIELD_NAME, K_CLASS_TYPE.getDescriptor()); } - - v.visitLdcInsn(descriptor.getName().asString()); - v.invokevirtual(K_CLASS_IMPL_TYPE.getInternalName(), factoryMethod.getName(), factoryMethod.getDescriptor(), false); + v.invokestatic(REFLECTION, factoryMethod.getName(), factoryMethod.getDescriptor(), false); return Unit.INSTANCE$; } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java index 934f2849390..767fb8bd3c6 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java @@ -405,7 +405,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { return; } - generateReflectionObjectField(state, classAsmType, v, method("kClassFromKotlin", K_CLASS_IMPL_TYPE, getType(Class.class)), + generateReflectionObjectField(state, classAsmType, v, method("createKotlinClass", K_CLASS_TYPE, getType(Class.class)), JvmAbi.KOTLIN_CLASS_FIELD_NAME, createOrGetClInitCodegen().v); } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/MemberCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/MemberCodegen.java index dd36112b611..3717df9057b 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/MemberCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/MemberCodegen.java @@ -447,7 +447,7 @@ public abstract class MemberCodegen", "()V", null, null); - Method method = method("kPackage", K_PACKAGE_IMPL_TYPE, getType(Class.class)); + Method method = method("createKotlinPackage", K_PACKAGE_TYPE, getType(Class.class)); InstructionAdapter iv = new InstructionAdapter(mv); MemberCodegen.generateReflectionObjectField(state, packageClassType, v, method, JvmAbi.KOTLIN_PACKAGE_FIELD_NAME, iv); iv.areturn(Type.VOID_TYPE); diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ScriptCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ScriptCodegen.java index c939574288f..a7c162b9a89 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ScriptCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ScriptCodegen.java @@ -102,7 +102,7 @@ public class ScriptCodegen extends MemberCodegen { "java/lang/Object", ArrayUtil.EMPTY_STRING_ARRAY); - generateReflectionObjectField(state, classType, v, method("kClassFromKotlin", K_CLASS_IMPL_TYPE, getType(Class.class)), + generateReflectionObjectField(state, classType, v, method("createKotlinClass", K_CLASS_TYPE, getType(Class.class)), JvmAbi.KOTLIN_CLASS_FIELD_NAME, createOrGetClInitCodegen().v); } diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/AsmTypes.java b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/AsmTypes.java index b84c2acc3e7..ca83173a1c9 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/AsmTypes.java +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/AsmTypes.java @@ -33,24 +33,24 @@ public class AsmTypes { public static final Type PROPERTY_METADATA_TYPE = Type.getObjectType("kotlin/PropertyMetadata"); public static final Type PROPERTY_METADATA_IMPL_TYPE = Type.getObjectType("kotlin/PropertyMetadataImpl"); - public static final Type K_MEMBER_PROPERTY_TYPE = Type.getObjectType("kotlin/reflect/KMemberProperty"); - public static final Type K_MUTABLE_MEMBER_PROPERTY_TYPE = Type.getObjectType("kotlin/reflect/KMutableMemberProperty"); + public static final Type K_CLASS_TYPE = reflect("KClass"); + public static final Type K_PACKAGE_TYPE = reflect("KPackage"); - public static final Type K_CLASS_IMPL_TYPE = reflectInternal("KClassImpl"); - public static final Type K_PACKAGE_IMPL_TYPE = reflectInternal("KPackageImpl"); - public static final Type K_TOP_LEVEL_VARIABLE_IMPL_TYPE = reflectInternal("KTopLevelVariableImpl"); - public static final Type K_MUTABLE_TOP_LEVEL_VARIABLE_IMPL_TYPE = reflectInternal("KMutableTopLevelVariableImpl"); - public static final Type K_TOP_LEVEL_EXTENSION_PROPERTY_IMPL_TYPE = reflectInternal("KTopLevelExtensionPropertyImpl"); - public static final Type K_MUTABLE_TOP_LEVEL_EXTENSION_PROPERTY_IMPL_TYPE = reflectInternal("KMutableTopLevelExtensionPropertyImpl"); + public static final Type K_MEMBER_PROPERTY_TYPE = reflect("KMemberProperty"); + public static final Type K_MUTABLE_MEMBER_PROPERTY_TYPE = reflect("KMutableMemberProperty"); + public static final Type K_TOP_LEVEL_VARIABLE_TYPE = reflect("KTopLevelVariable"); + public static final Type K_MUTABLE_TOP_LEVEL_VARIABLE_TYPE = reflect("KMutableTopLevelVariable"); + public static final Type K_TOP_LEVEL_EXTENSION_PROPERTY_TYPE = reflect("KTopLevelExtensionProperty"); + public static final Type K_MUTABLE_TOP_LEVEL_EXTENSION_PROPERTY_TYPE = reflect("KMutableTopLevelExtensionProperty"); - public static final String REFLECTION_INTERNAL_PACKAGE = reflectInternal("InternalPackage").getInternalName(); + public static final String REFLECTION = "kotlin/jvm/internal/Reflection"; public static final String REF_TYPE_PREFIX = "kotlin/jvm/internal/Ref$"; public static final Type OBJECT_REF_TYPE = Type.getObjectType(REF_TYPE_PREFIX + "ObjectRef"); @NotNull - private static Type reflectInternal(@NotNull String className) { - return Type.getObjectType("kotlin/reflect/jvm/internal/" + className); + private static Type reflect(@NotNull String className) { + return Type.getObjectType("kotlin/reflect/" + className); } @NotNull diff --git a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/ReflectionFactoryImpl.java b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/ReflectionFactoryImpl.java new file mode 100644 index 00000000000..d18f14a9887 --- /dev/null +++ b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/ReflectionFactoryImpl.java @@ -0,0 +1,68 @@ +/* + * 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 kotlin.reflect.jvm.internal; + +import kotlin.jvm.internal.ReflectionFactory; +import kotlin.reflect.*; + +@SuppressWarnings({"UnusedDeclaration", "unchecked"}) +public class ReflectionFactoryImpl extends ReflectionFactory { + @Override + public KClass createKotlinClass(Class javaClass) { + return new KClassImpl(javaClass, true); + } + + @Override + public KPackage createKotlinPackage(Class javaClass) { + return new KPackageImpl(javaClass); + } + + @Override + public KClass foreignKotlinClass(Class javaClass) { + return InternalPackage.foreignKotlinClass(javaClass); + } + + @Override + public KMemberProperty memberProperty(String name, KClass owner) { + return ((KClassImpl) owner).memberProperty(name); + } + + @Override + public KMutableMemberProperty mutableMemberProperty(String name, KClass owner) { + return ((KClassImpl) owner).mutableMemberProperty(name); + } + + @Override + public KTopLevelVariable topLevelVariable(String name, KPackage owner) { + return new KTopLevelVariableImpl(name, ((KPackageImpl) owner)); + } + + @Override + public KMutableTopLevelVariable mutableTopLevelVariable(String name, KPackage owner) { + return new KMutableTopLevelVariableImpl(name, (KPackageImpl) owner); + } + + @Override + public KTopLevelExtensionProperty topLevelExtensionProperty(String name, KPackage owner, Class receiver) { + return new KTopLevelExtensionPropertyImpl(name, (KPackageImpl) owner, receiver); + } + + @Override + public KMutableTopLevelExtensionProperty mutableTopLevelExtensionProperty(String name, KPackage owner, Class receiver) { + return new KMutableTopLevelExtensionPropertyImpl(name, (KPackageImpl) owner, receiver); + } +} diff --git a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/factory.kt b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/factory.kt index c3df6994d27..cad22694cf6 100644 --- a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/factory.kt +++ b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/factory.kt @@ -18,12 +18,11 @@ package kotlin.reflect.jvm.internal import kotlin.reflect.* +// TODO: drop these functions, use ReflectionFactory instead + fun kClass(jClass: Class): KClassImpl = KClassImpl(jClass, false) -fun kClassFromKotlin(jClass: Class): KClassImpl = - KClassImpl(jClass, true) - fun kPackage(jClass: Class<*>): KPackageImpl = KPackageImpl(jClass) diff --git a/core/reflection.stub.jvm/src/kotlin/reflect/jvm/internal/InternalPackage.java b/core/reflection.stub.jvm/src/kotlin/reflect/jvm/internal/InternalPackage.java deleted file mode 100644 index 561c7aab729..00000000000 --- a/core/reflection.stub.jvm/src/kotlin/reflect/jvm/internal/InternalPackage.java +++ /dev/null @@ -1,33 +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 kotlin.reflect.jvm.internal; - -import kotlin.reflect.jvm.KotlinReflectionNotSupportedError; - -public class InternalPackage { - public static KClassImpl foreignKotlinClass(Class jClass) { - throw new KotlinReflectionNotSupportedError(); - } - - public static KClassImpl kClassFromKotlin(Class jClass) { - return null; - } - - public static KPackageImpl kPackage(Class c) { - return null; - } -} diff --git a/core/reflection.stub.jvm/src/kotlin/reflect/jvm/internal/KClassImpl.java b/core/reflection.stub.jvm/src/kotlin/reflect/jvm/internal/KClassImpl.java deleted file mode 100644 index f693269269f..00000000000 --- a/core/reflection.stub.jvm/src/kotlin/reflect/jvm/internal/KClassImpl.java +++ /dev/null @@ -1,22 +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 kotlin.reflect.jvm.internal; - -import kotlin.reflect.KClass; - -public abstract class KClassImpl implements KClass { -} diff --git a/core/reflection.stub.jvm/src/kotlin/reflect/jvm/internal/KPackageImpl.java b/core/reflection.stub.jvm/src/kotlin/reflect/jvm/internal/KPackageImpl.java deleted file mode 100644 index 90e52e48ab1..00000000000 --- a/core/reflection.stub.jvm/src/kotlin/reflect/jvm/internal/KPackageImpl.java +++ /dev/null @@ -1,22 +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 kotlin.reflect.jvm.internal; - -import kotlin.reflect.KPackage; - -public abstract class KPackageImpl implements KPackage { -} diff --git a/core/reflection.stub.jvm/src/kotlin/reflect/jvm/KotlinReflectionNotSupportedError.java b/core/runtime.jvm/src/kotlin/jvm/KotlinReflectionNotSupportedError.java similarity index 97% rename from core/reflection.stub.jvm/src/kotlin/reflect/jvm/KotlinReflectionNotSupportedError.java rename to core/runtime.jvm/src/kotlin/jvm/KotlinReflectionNotSupportedError.java index deb6fd1a2b7..9cf69482e06 100644 --- a/core/reflection.stub.jvm/src/kotlin/reflect/jvm/KotlinReflectionNotSupportedError.java +++ b/core/runtime.jvm/src/kotlin/jvm/KotlinReflectionNotSupportedError.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package kotlin.reflect.jvm; +package kotlin.jvm; public class KotlinReflectionNotSupportedError extends Error { public KotlinReflectionNotSupportedError() { diff --git a/core/runtime.jvm/src/kotlin/jvm/internal/Reflection.java b/core/runtime.jvm/src/kotlin/jvm/internal/Reflection.java new file mode 100644 index 00000000000..f6da8f40534 --- /dev/null +++ b/core/runtime.jvm/src/kotlin/jvm/internal/Reflection.java @@ -0,0 +1,77 @@ +/* + * 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 kotlin.jvm.internal; + +import kotlin.reflect.*; + +/** + * This class serves as a facade to the actual reflection implementation. JVM back-end generates calls to static methods of this class + * on any reflection-using construct. + */ +public class Reflection { + private static final ReflectionFactory factory; + + static { + ReflectionFactory impl; + try { + Class implClass = Class.forName("kotlin.reflect.jvm.internal.ReflectionFactoryImpl"); + impl = (ReflectionFactory) implClass.newInstance(); + } + catch (ClassCastException e) { impl = null; } + catch (ClassNotFoundException e) { impl = null; } + catch (InstantiationException e) { impl = null; } + catch (IllegalAccessException e) { impl = null; } + + factory = impl != null ? impl : new ReflectionFactory(); + } + + public static KClass createKotlinClass(Class javaClass) { + return factory.createKotlinClass(javaClass); + } + + public static KPackage createKotlinPackage(Class javaClass) { + return factory.createKotlinPackage(javaClass); + } + + public static KClass foreignKotlinClass(Class javaClass) { + return factory.foreignKotlinClass(javaClass); + } + + public static KMemberProperty memberProperty(String name, KClass owner) { + return factory.memberProperty(name, owner); + } + + public static KMutableMemberProperty mutableMemberProperty(String name, KClass owner) { + return factory.mutableMemberProperty(name, owner); + } + + public static KTopLevelVariable topLevelVariable(String name, KPackage owner) { + return factory.topLevelVariable(name, owner); + } + + public static KMutableTopLevelVariable mutableTopLevelVariable(String name, KPackage owner) { + return factory.mutableTopLevelVariable(name, owner); + } + + public static KTopLevelExtensionProperty topLevelExtensionProperty(String name, KPackage owner, Class receiver) { + return factory.topLevelExtensionProperty(name, owner, receiver); + } + + public static KMutableTopLevelExtensionProperty mutableTopLevelExtensionProperty(String name, KPackage owner, Class receiver) { + return factory.mutableTopLevelExtensionProperty(name, owner, receiver); + } +} diff --git a/core/runtime.jvm/src/kotlin/jvm/internal/ReflectionFactory.java b/core/runtime.jvm/src/kotlin/jvm/internal/ReflectionFactory.java new file mode 100644 index 00000000000..ef58a4f5fa5 --- /dev/null +++ b/core/runtime.jvm/src/kotlin/jvm/internal/ReflectionFactory.java @@ -0,0 +1,62 @@ +/* + * 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 kotlin.jvm.internal; + +import kotlin.jvm.KotlinReflectionNotSupportedError; +import kotlin.reflect.*; + +public class ReflectionFactory { + public KClass createKotlinClass(Class javaClass) { + return null; + } + + public KPackage createKotlinPackage(Class javaClass) { + return null; + } + + public KClass foreignKotlinClass(Class javaClass) { + throw error(); + } + + public KMemberProperty memberProperty(String name, KClass owner) { + throw error(); + } + + public KMutableMemberProperty mutableMemberProperty(String name, KClass owner) { + throw error(); + } + + public KTopLevelVariable topLevelVariable(String name, KPackage owner) { + throw error(); + } + + public KMutableTopLevelVariable mutableTopLevelVariable(String name, KPackage owner) { + throw error(); + } + + public KTopLevelExtensionProperty topLevelExtensionProperty(String name, KPackage owner, Class receiver) { + throw error(); + } + + public KMutableTopLevelExtensionProperty mutableTopLevelExtensionProperty(String name, KPackage owner, Class receiver) { + throw error(); + } + + private Error error() { + throw new KotlinReflectionNotSupportedError(); + } +}