Modify top-level/extension property hierarchy

- rename KTopLevelProperty to KTopLevelVariable
- create KTopLevelExtensionProperty, a subclass of KExtensionProperty
- create KTopLevelProperty, a superclass of KTopLevelVariable and
  KTopLevelExtensionProperty. (In the future, it will have a container of type
  KPackage.)
This commit is contained in:
Alexander Udalov
2014-07-01 17:12:47 +04:00
parent f73b8b9ff8
commit d32a02f21a
11 changed files with 83 additions and 35 deletions
@@ -0,0 +1,21 @@
/*
* 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 kotlin.reflect
public trait KTopLevelExtensionProperty<T, out R> : KExtensionProperty<T, R>, KTopLevelProperty<R>
public trait KMutableTopLevelExtensionProperty<T, out R> : KTopLevelExtensionProperty<T, R>, KMutableExtensionProperty<T, R>, KMutableTopLevelProperty<R>
@@ -16,6 +16,6 @@
package kotlin.reflect
public trait KTopLevelProperty<out R> : KVariable<R>
public trait KTopLevelProperty<out R> : KProperty<R>
public trait KMutableTopLevelProperty<R> : KTopLevelProperty<R>, KMutableVariable<R>
public trait KMutableTopLevelProperty<R> : KTopLevelProperty<R>, KMutableProperty<R>
@@ -0,0 +1,21 @@
/*
* 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 kotlin.reflect
public trait KTopLevelVariable<out R> : KVariable<R>, KTopLevelProperty<R>
public trait KMutableTopLevelVariable<R> : KTopLevelVariable<R>, KMutableVariable<R>, KMutableTopLevelProperty<R>
@@ -18,11 +18,11 @@ package kotlin.reflect.jvm.internal
import java.lang.reflect.*
open class KExtensionPropertyImpl<T, out R>(
open class KTopLevelExtensionPropertyImpl<T, out R>(
public override val name: String,
protected val owner: KPackageImpl,
protected val receiverClass: Class<T>
) : KExtensionProperty<T, R>, KPropertyImpl<R> {
) : KTopLevelExtensionProperty<T, R>, KPropertyImpl<R> {
override val field: Field? get() = null
// TODO: extract, make lazy (weak?), use our descriptors knowledge, support Java fields
@@ -33,11 +33,11 @@ open class KExtensionPropertyImpl<T, out R>(
}
}
class KMutableExtensionPropertyImpl<T, R>(
class KMutableTopLevelExtensionPropertyImpl<T, R>(
name: String,
owner: KPackageImpl,
receiverClass: Class<T>
) : KMutableExtensionProperty<T, R>, KMutablePropertyImpl<R>, KExtensionPropertyImpl<T, R>(name, owner, receiverClass) {
) : KMutableTopLevelExtensionProperty<T, R>, KMutablePropertyImpl<R>, KTopLevelExtensionPropertyImpl<T, R>(name, owner, receiverClass) {
override val setter: Method = owner.jClass.getMethod(setterName(name), receiverClass, getter.getReturnType()!!)
override fun set(receiver: T, value: R) {
@@ -18,10 +18,10 @@ package kotlin.reflect.jvm.internal
import java.lang.reflect.*
open class KTopLevelPropertyImpl<out R>(
open class KTopLevelVariableImpl<out R>(
public override val name: String,
protected val owner: KPackageImpl
) : KTopLevelProperty<R>, KVariableImpl<R> {
) : KTopLevelVariable<R>, KVariableImpl<R> {
// TODO: load the field from the corresponding package part
override val field: Field? get() = null
@@ -33,10 +33,10 @@ open class KTopLevelPropertyImpl<out R>(
}
}
class KMutableTopLevelPropertyImpl<R>(
class KMutableTopLevelVariableImpl<R>(
name: String,
owner: KPackageImpl
) : KMutableTopLevelProperty<R>, KMutableVariableImpl<R>, KTopLevelPropertyImpl<R>(name, owner) {
) : KMutableTopLevelVariable<R>, KMutableVariableImpl<R>, KTopLevelVariableImpl<R>(name, owner) {
override val setter: Method = owner.jClass.getMethod(setterName(name), getter.getReturnType()!!)
override fun set(value: R) {
@@ -23,14 +23,14 @@ fun <T> kClass(jClass: Class<T>): KClassImpl<T> =
fun kPackage(jClass: Class<*>): KPackageImpl =
KPackageImpl(jClass)
fun topLevelProperty(name: String, owner: KPackageImpl): KTopLevelPropertyImpl<Any?> =
KTopLevelPropertyImpl<Any?>(name, owner)
fun topLevelVariable(name: String, owner: KPackageImpl): KTopLevelVariableImpl<Any?> =
KTopLevelVariableImpl<Any?>(name, owner)
fun mutableTopLevelProperty(name: String, owner: KPackageImpl): KMutableTopLevelPropertyImpl<Any?> =
KMutableTopLevelPropertyImpl<Any?>(name, owner)
fun mutableTopLevelVariable(name: String, owner: KPackageImpl): KMutableTopLevelVariableImpl<Any?> =
KMutableTopLevelVariableImpl<Any?>(name, owner)
fun <T> extensionProperty(name: String, owner: KPackageImpl, receiver: Class<T>): KExtensionPropertyImpl<T, Any?> =
KExtensionPropertyImpl<T, Any?>(name, owner, receiver)
fun <T> topLevelExtensionProperty(name: String, owner: KPackageImpl, receiver: Class<T>): KTopLevelExtensionPropertyImpl<T, Any?> =
KTopLevelExtensionPropertyImpl<T, Any?>(name, owner, receiver)
fun <T> mutableExtensionProperty(name: String, owner: KPackageImpl, receiver: Class<T>): KMutableExtensionPropertyImpl<T, Any?> =
KMutableExtensionPropertyImpl<T, Any?>(name, owner, receiver)
fun <T> mutableTopLevelExtensionProperty(name: String, owner: KPackageImpl, receiver: Class<T>): KMutableTopLevelExtensionPropertyImpl<T, Any?> =
KMutableTopLevelExtensionPropertyImpl<T, Any?>(name, owner, receiver)