Rename and implement KProperty.accessible -> KCallable.isAccessible
This commit is contained in:
@@ -22,7 +22,7 @@ package kotlin.reflect
|
||||
*
|
||||
* @param cause the original exception thrown by the JVM.
|
||||
*
|
||||
* @see [kotlin.reflect.jvm.accessible]
|
||||
* @see [kotlin.reflect.jvm.isAccessible]
|
||||
*/
|
||||
public class IllegalPropertyAccessException(cause: IllegalAccessException) : Exception(cause.getMessage()) {
|
||||
init {
|
||||
|
||||
@@ -39,3 +39,9 @@ public val <T> KClass<T>.declaredProperties: Collection<KProperty1<T, *>>
|
||||
@deprecated("Use declaredMemberExtensionProperties instead.", ReplaceWith("declaredMemberExtensionProperties"))
|
||||
public val <T> KClass<T>.declaredExtensionProperties: Collection<KProperty2<T, *, *>>
|
||||
get() = declaredMemberExtensionProperties
|
||||
|
||||
|
||||
@deprecated("Use isAccessible instead.", ReplaceWith("isAccessible"))
|
||||
public var KProperty<*>.accessible: Boolean
|
||||
get() = isAccessible
|
||||
set(value) { isAccessible = value }
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* 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.jvm
|
||||
|
||||
import kotlin.reflect.KCallable
|
||||
import kotlin.reflect.KFunction
|
||||
import kotlin.reflect.KMutableProperty
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
/**
|
||||
* Provides a way to suppress JVM access checks for a callable.
|
||||
*
|
||||
* @getter returns `true` if JVM access checks are suppressed for this callable object.
|
||||
* For a property, that means that all its accessors (getter, and setter for `var` properties) are accessible.
|
||||
*
|
||||
* @setter if set to `true`, suppresses JVM access checks for this callable object.
|
||||
* For a property, both accessors are made accessible.
|
||||
*
|
||||
* @see [java.lang.reflect.AccessibleObject]
|
||||
*/
|
||||
public var KCallable<*>.isAccessible: Boolean
|
||||
get() {
|
||||
return when (this) {
|
||||
is KMutableProperty ->
|
||||
javaField?.isAccessible ?: true &&
|
||||
javaGetter?.isAccessible ?: true &&
|
||||
javaSetter?.isAccessible ?: true
|
||||
is KProperty ->
|
||||
javaField?.isAccessible ?: true &&
|
||||
javaGetter?.isAccessible ?: true
|
||||
is KFunction ->
|
||||
javaMethod?.isAccessible ?: true &&
|
||||
this.javaConstructor?.isAccessible ?: true
|
||||
else -> throw UnsupportedOperationException("Unknown callable: $this ($javaClass)")
|
||||
}
|
||||
}
|
||||
set(value) {
|
||||
when (this) {
|
||||
is KMutableProperty -> {
|
||||
javaField?.isAccessible = value
|
||||
javaGetter?.isAccessible = value
|
||||
javaSetter?.isAccessible = value
|
||||
}
|
||||
is KProperty -> {
|
||||
javaField?.isAccessible = value
|
||||
javaGetter?.isAccessible = value
|
||||
}
|
||||
is KFunction -> {
|
||||
javaMethod?.isAccessible = value
|
||||
this.javaConstructor?.isAccessible = value
|
||||
}
|
||||
else -> throw UnsupportedOperationException("Unknown callable: $this ($javaClass)")
|
||||
}
|
||||
}
|
||||
@@ -1,60 +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.jvm
|
||||
|
||||
import kotlin.reflect.KProperty
|
||||
import kotlin.reflect.jvm.internal.KMutablePropertyImpl
|
||||
import kotlin.reflect.jvm.internal.KPropertyImpl
|
||||
|
||||
/**
|
||||
* Provides a way to suppress JVM access checks for a property.
|
||||
*
|
||||
* @getter returns `true` if JVM access checks are suppressed for this property object.
|
||||
* In case of a `var` property, that means that both getter and setter are accessible.
|
||||
*
|
||||
* @setter if set to `true`, suppresses JVM access checks for this property object.
|
||||
* In case of a `var` property, both getter and setter are made accessible.
|
||||
*
|
||||
* @see [java.lang.reflect.AccessibleObject]
|
||||
*/
|
||||
public var <R> KProperty<R>.accessible: Boolean
|
||||
get() {
|
||||
return when (this) {
|
||||
is KMutablePropertyImpl<R> ->
|
||||
javaField?.isAccessible() ?: true &&
|
||||
javaGetter?.isAccessible() ?: true &&
|
||||
javaSetter?.isAccessible() ?: true
|
||||
is KPropertyImpl<R> ->
|
||||
javaField?.isAccessible() ?: true &&
|
||||
javaGetter?.isAccessible() ?: true
|
||||
else -> throw UnsupportedOperationException("Unknown property: $this ($javaClass)")
|
||||
}
|
||||
}
|
||||
set(value) {
|
||||
when (this) {
|
||||
is KMutablePropertyImpl<R> -> {
|
||||
javaField?.setAccessible(value)
|
||||
javaGetter?.setAccessible(value)
|
||||
javaSetter?.setAccessible(value)
|
||||
}
|
||||
is KPropertyImpl<R> -> {
|
||||
javaField?.setAccessible(value)
|
||||
javaGetter?.setAccessible(value)
|
||||
}
|
||||
else -> throw UnsupportedOperationException("Unknown property: $this ($javaClass)")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user