All Downloads are FREE. Search and download functionalities are using the official Maven repository.

kotlin.reflect.KProperty.kt Maven / Gradle / Ivy

/*
 * 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

/**
 * Represents a property, such as a named `val` or `var` declaration.
 * Instances of this class are obtainable by the `::` operator.
 * See the [Kotlin language documentation](http://kotlinlang.org/docs/reference/reflection.html)
 * for more information.
 *
 * @param R the type of the property.
 */
public interface KProperty : KCallable {
    /** The getter of this property, used to obtain the value of the property. */
    public val getter: Getter

    /**
     * Represents a property accessor, which is a `get` or `set` method declared alongside the property.
     * See the [Kotlin language documentation](http://kotlinlang.org/docs/reference/properties.html#getters-and-setters)
     * for more information.
     *
     * @param R the type of the property, which it is an accessor of.
     */
    public interface Accessor {
        /** The property which this accessor is originated from. */
        public val property: KProperty
    }

    /**
     * Getter of the property is a `get` method declared alongside the property.
     */
    public interface Getter : Accessor, KFunction
}

/**
 * Represents a property declared as a `var`.
 */
public interface KMutableProperty : KProperty {
    /** The setter of this mutable property, used to change the value of the property. */
    public val setter: Setter

    /**
     * Setter of the property is a `set` method declared alongside the property.
     */
    public interface Setter : KProperty.Accessor, KFunction
}


/**
 * Represents a property without any kind of receiver.
 * Such property is either originally declared in a receiverless context such as a package,
 * or has the receiver bound to it.
 */
public interface KProperty0 : KProperty, () -> R {
    /**
     * Returns the current value of the property.
     */
    public fun get(): R

    override val getter: Getter

    public interface Getter : KProperty.Getter, () -> R
}

/**
 * Represents a `var`-property without any kind of receiver.
 */
public interface KMutableProperty0 : KProperty0, KMutableProperty {
    /**
     * Modifies the value of the property.
     *
     * @param value the new value to be assigned to this property.
     */
    public fun set(value: R)

    override val setter: Setter

    public interface Setter : KMutableProperty.Setter, (R) -> Unit
}


/**
 * Represents a property, operations on which take one receiver as a parameter.
 *
 * @param T the type of the receiver which should be used to obtain the value of the property.
 * @param R the type of the property.
 */
public interface KProperty1 : KProperty, (T) -> R {
    /**
     * Returns the current value of the property.
     *
     * @param receiver the receiver which is used to obtain the value of the property.
     *                 For example, it should be a class instance if this is a member property of that class,
     *                 or an extension receiver if this is a top level extension property.
     */
    public fun get(receiver: T): R

    override val getter: Getter

    public interface Getter : KProperty.Getter, (T) -> R
}

/**
 * Represents a `var`-property, operations on which take one receiver as a parameter.
 */
public interface KMutableProperty1 : KProperty1, KMutableProperty {
    /**
     * Modifies the value of the property.
     *
     * @param receiver the receiver which is used to modify the value of the property.
     *                 For example, it should be a class instance if this is a member property of that class,
     *                 or an extension receiver if this is a top level extension property.
     * @param value the new value to be assigned to this property.
     */
    public fun set(receiver: T, value: R)

    override val setter: Setter

    public interface Setter : KMutableProperty.Setter, (T, R) -> Unit
}


/**
 * Represents a property, operations on which take two receivers as parameters,
 * such as an extension property declared in a class.
 *
 * @param D the type of the first receiver. In case of the extension property in a class this is
 *        the type of the declaring class of the property, or any subclass of that class.
 * @param E the type of the second receiver. In case of the extension property in a class this is
 *        the type of the extension receiver.
 * @param R the type of the property.
 */
public interface KProperty2 : KProperty, (D, E) -> R {
    /**
     * Returns the current value of the property. In case of the extension property in a class,
     * the instance of the class should be passed first and the instance of the extension receiver second.
     *
     * @param receiver1 the instance of the first receiver.
     * @param receiver2 the instance of the second receiver.
     */
    public fun get(receiver1: D, receiver2: E): R

    override val getter: Getter

    public interface Getter : KProperty.Getter, (D, E) -> R
}

/**
 * Represents a `var`-property, operations on which take two receivers as parameters.
 */
public interface KMutableProperty2 : KProperty2, KMutableProperty {
    /**
     * Modifies the value of the property.
     *
     * @param receiver1 the instance of the first receiver.
     * @param receiver2 the instance of the second receiver.
     * @param value the new value to be assigned to this property.
     */
    public fun set(receiver1: D, receiver2: E, value: R)

    override val setter: Setter

    public interface Setter : KMutableProperty.Setter, (D, E, R) -> Unit
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy