Deprecate KPackage, to be removed later
This commit is contained in:
@@ -19,4 +19,6 @@ package kotlin.reflect
|
||||
/**
|
||||
* Represents a package and provides introspection capabilities.
|
||||
*/
|
||||
@Deprecated("This class will be deleted soon because reflection on packages is going to be redesigned " +
|
||||
"after the introduction of new kinds of runtime representations of packages on JVM.")
|
||||
public interface KPackage : KDeclarationContainer
|
||||
|
||||
@@ -1,37 +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
|
||||
|
||||
import kotlin.reflect.jvm.internal.KPackageImpl
|
||||
|
||||
/**
|
||||
* Returns all non-extension properties declared in this package.
|
||||
*/
|
||||
public val KPackage.properties: Collection<KProperty0<*>>
|
||||
get() = (this as KPackageImpl)
|
||||
.getMembers(scope, declaredOnly = false, nonExtensions = true, extensions = false)
|
||||
.filterIsInstance<KProperty0<*>>()
|
||||
.toList()
|
||||
|
||||
/**
|
||||
* Returns all extension properties declared in this package.
|
||||
*/
|
||||
public val KPackage.extensionProperties: Collection<KProperty1<*, *>>
|
||||
get() = (this as KPackageImpl)
|
||||
.getMembers(scope, declaredOnly = false, nonExtensions = false, extensions = true)
|
||||
.filterIsInstance<KProperty1<*, *>>()
|
||||
.toList()
|
||||
@@ -18,7 +18,6 @@ package kotlin.reflect.jvm.internal;
|
||||
|
||||
import kotlin.jvm.internal.*;
|
||||
import kotlin.reflect.*;
|
||||
import org.jetbrains.kotlin.load.java.JvmAbi;
|
||||
|
||||
/**
|
||||
* @suppress
|
||||
@@ -31,12 +30,7 @@ public class ReflectionFactoryImpl extends ReflectionFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public KPackage createKotlinPackage(Class javaClass) {
|
||||
return createKotlinPackage(javaClass, JvmAbi.DEFAULT_MODULE_NAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KPackage createKotlinPackage(Class javaClass, String moduleName) {
|
||||
public KDeclarationContainer getOrCreateKotlinPackage(Class javaClass, String moduleName) {
|
||||
return new KPackageImpl(javaClass, moduleName);
|
||||
}
|
||||
|
||||
@@ -92,4 +86,9 @@ public class ReflectionFactoryImpl extends ReflectionFactory {
|
||||
public KClass foreignKotlinClass(Class javaClass) {
|
||||
return getOrCreateKotlinClass(javaClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KPackage createKotlinPackage(Class javaClass, String moduleName) {
|
||||
return new KPackageImpl(javaClass, moduleName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,24 +19,15 @@ package kotlin.reflect.jvm
|
||||
import org.jetbrains.kotlin.load.java.JvmAbi
|
||||
import java.lang.reflect.*
|
||||
import java.util.*
|
||||
import kotlin.jvm.internal.KotlinFileFacade
|
||||
import kotlin.jvm.internal.Reflection
|
||||
import kotlin.reflect.*
|
||||
import kotlin.reflect.jvm.internal.KCallableImpl
|
||||
import kotlin.reflect.jvm.internal.KPackageImpl
|
||||
import kotlin.reflect.jvm.internal.KPropertyImpl
|
||||
import kotlin.reflect.jvm.internal.KTypeImpl
|
||||
|
||||
// Kotlin reflection -> Java reflection
|
||||
|
||||
/**
|
||||
* Returns a Java [Class] instance that represents a Kotlin package.
|
||||
* The methods and fields of this class are generated from top level functions and properties in the Kotlin package.
|
||||
* See the [Kotlin language documentation](http://kotlinlang.org/docs/reference/java-interop.html#package-level-functions)
|
||||
* for more information.
|
||||
*/
|
||||
public val KPackage.javaFacade: Class<*>
|
||||
get() = (this as KPackageImpl).jClass
|
||||
|
||||
|
||||
/**
|
||||
* Returns a Java [Field] instance corresponding to the backing field of the given property,
|
||||
* or `null` if the property has no backing field.
|
||||
@@ -87,31 +78,6 @@ public val KType.javaType: Type
|
||||
|
||||
// Java reflection -> Kotlin reflection
|
||||
|
||||
/**
|
||||
* Returns a [KPackage] instance corresponding to the Java [Class] instance.
|
||||
* The given class is generated from top level functions and properties in the Kotlin package.
|
||||
* See the [Kotlin language documentation](http://kotlinlang.org/docs/reference/java-interop.html#package-level-functions)
|
||||
* for more information.
|
||||
*/
|
||||
@Deprecated("After dropping old package facades it would be impossible to retrieve package by java class")
|
||||
public val Class<*>.kotlinPackage: KPackage?
|
||||
get() = if (getSimpleName().endsWith("Package") &&
|
||||
getAnnotation(javaClass<kotlin.jvm.internal.KotlinPackage>()) != null) {
|
||||
try {
|
||||
val field = this.getField(JvmAbi.MODULE_NAME_FIELD)
|
||||
if (field != null) {
|
||||
KPackageImpl(this, field.get(null) as String)
|
||||
}
|
||||
else {
|
||||
null
|
||||
}
|
||||
}
|
||||
catch(e: NoSuchFieldException) {
|
||||
null
|
||||
}
|
||||
} else null
|
||||
|
||||
|
||||
/**
|
||||
* Returns a [KProperty] instance corresponding to the given Java [Field] instance,
|
||||
* or `null` if this field cannot be represented by a Kotlin property
|
||||
@@ -137,10 +103,7 @@ public val Method.kotlinFunction: KFunction<*>?
|
||||
if (isSynthetic) return null
|
||||
|
||||
if (Modifier.isStatic(modifiers)) {
|
||||
val kotlinPackage = declaringClass.kotlinPackage
|
||||
if (kotlinPackage != null) {
|
||||
return kotlinPackage.functions.firstOrNull { it.javaMethod == this }
|
||||
}
|
||||
// TODO: support file facades & multifile classes
|
||||
|
||||
// For static bridge method generated for a jvmStatic function in the companion object, also try to find the latter
|
||||
val companion = declaringClass.kotlin.companionObject
|
||||
|
||||
@@ -45,12 +45,8 @@ public class Reflection {
|
||||
return factory.createKotlinClass(javaClass);
|
||||
}
|
||||
|
||||
public static KPackage createKotlinPackage(Class javaClass) {
|
||||
return factory.createKotlinPackage(javaClass);
|
||||
}
|
||||
|
||||
public static KPackage createKotlinPackage(Class javaClass, String moduleName) {
|
||||
return factory.createKotlinPackage(javaClass, moduleName);
|
||||
public static KDeclarationContainer getOrCreateKotlinPackage(Class javaClass, String moduleName) {
|
||||
return factory.getOrCreateKotlinPackage(javaClass, moduleName);
|
||||
}
|
||||
|
||||
public static KClass getOrCreateKotlinClass(Class javaClass) {
|
||||
@@ -101,6 +97,11 @@ public class Reflection {
|
||||
|
||||
// Deprecated
|
||||
|
||||
@Deprecated
|
||||
public static KPackage createKotlinPackage(Class javaClass, String moduleName) {
|
||||
return (KPackage) factory.getOrCreateKotlinPackage(javaClass, moduleName);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static KClass foreignKotlinClass(Class javaClass) {
|
||||
return getOrCreateKotlinClass(javaClass);
|
||||
|
||||
@@ -23,11 +23,7 @@ public class ReflectionFactory {
|
||||
return new ClassReference(javaClass);
|
||||
}
|
||||
|
||||
public KPackage createKotlinPackage(Class javaClass) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public KPackage createKotlinPackage(Class javaClass, String moduleName) {
|
||||
public KDeclarationContainer getOrCreateKotlinPackage(Class javaClass, String moduleName) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -73,4 +69,9 @@ public class ReflectionFactory {
|
||||
public KClass foreignKotlinClass(Class javaClass) {
|
||||
return new ClassReference(javaClass);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public KPackage createKotlinPackage(Class javaClass, String moduleName) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user