Support class reference expressions without kotlin-reflect.jar in classpath

Currently not much you can do with them, but in the future '.java' extension
property will allow to get the Class instance from it.

Also introduce codegen tests with stdlib but without reflection in the
classpath.

Based on the work by @dnpetrov
This commit is contained in:
Alexander Udalov
2015-07-29 23:20:35 +03:00
parent 0b30758987
commit 628bb774fd
8 changed files with 101 additions and 21 deletions
@@ -0,0 +1,37 @@
/*
* 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.KCallable
import kotlin.reflect.KClass
import kotlin.reflect.KFunction
public class ClassReference(override val jClass: Class<*>) : KClass<Any>, DeclarationContainerImpl {
override val simpleName: String?
get() = error()
override val qualifiedName: String?
get() = error()
override val members: Collection<KCallable<*>>
get() = error()
override val constructors: Collection<KFunction<Any>>
get() = error()
private fun error(): Nothing = throw KotlinReflectionNotSupportedError()
}
@@ -0,0 +1,23 @@
/*
* 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.KDeclarationContainer
public interface DeclarationContainerImpl : KDeclarationContainer {
public val jClass: Class<*>
}
@@ -16,12 +16,11 @@
package kotlin.jvm.internal;
import kotlin.jvm.KotlinReflectionNotSupportedError;
import kotlin.reflect.*;
public class ReflectionFactory {
public KClass createKotlinClass(Class javaClass) {
return null;
return new ClassReference(javaClass);
}
public KPackage createKotlinPackage(Class javaClass) {
@@ -29,7 +28,7 @@ public class ReflectionFactory {
}
public KClass foreignKotlinClass(Class javaClass) {
throw error();
return new ClassReference(javaClass);
}
// Functions
@@ -63,8 +62,4 @@ public class ReflectionFactory {
public KMutableProperty2 mutableProperty2(MutablePropertyReference2 p) {
return p;
}
private Error error() {
throw new KotlinReflectionNotSupportedError();
}
}