Deprecate KPackage, to be removed later

This commit is contained in:
Alexander Udalov
2015-10-08 16:45:28 +03:00
parent 790c59d9e5
commit 0218e0351b
15 changed files with 31 additions and 195 deletions
@@ -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