Introduce KAnnotatedElement and val annotations: List<Annotation>
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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.internal
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotated
|
||||
import org.jetbrains.kotlin.load.kotlin.reflect.ReflectAnnotationSource
|
||||
import kotlin.reflect.KAnnotatedElement
|
||||
|
||||
interface KAnnotatedElementImpl : KAnnotatedElement {
|
||||
val annotated: Annotated
|
||||
|
||||
override val annotations: List<Annotation>
|
||||
get() = annotated.annotations.map {
|
||||
(it.source as? ReflectAnnotationSource)?.annotation
|
||||
}.filterNotNull()
|
||||
}
|
||||
@@ -17,14 +17,17 @@
|
||||
package kotlin.reflect.jvm.internal
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotated
|
||||
import java.util.ArrayList
|
||||
import kotlin.reflect.KCallable
|
||||
import kotlin.reflect.KParameter
|
||||
import kotlin.reflect.KType
|
||||
|
||||
interface KCallableImpl<out R> : KCallable<R> {
|
||||
interface KCallableImpl<out R> : KCallable<R>, KAnnotatedElementImpl {
|
||||
val descriptor: CallableMemberDescriptor
|
||||
|
||||
override val annotated: Annotated get() = descriptor
|
||||
|
||||
override val parameters: List<KParameter>
|
||||
get() {
|
||||
val result = ArrayList<KParameter>()
|
||||
|
||||
@@ -18,6 +18,7 @@ package kotlin.reflect.jvm.internal
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
import org.jetbrains.kotlin.descriptors.ConstructorDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotated
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.resolve.scopes.ChainedScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScope
|
||||
@@ -26,7 +27,7 @@ import kotlin.reflect.KClass
|
||||
import kotlin.reflect.KFunction
|
||||
import kotlin.reflect.KotlinReflectionInternalError
|
||||
|
||||
class KClassImpl<T>(override val jClass: Class<T>) : KCallableContainerImpl(), KClass<T> {
|
||||
class KClassImpl<T>(override val jClass: Class<T>) : KCallableContainerImpl(), KClass<T>, KAnnotatedElementImpl {
|
||||
val descriptor by ReflectProperties.lazySoft {
|
||||
val classId = classId
|
||||
|
||||
@@ -37,6 +38,8 @@ class KClassImpl<T>(override val jClass: Class<T>) : KCallableContainerImpl(), K
|
||||
descriptor ?: throw KotlinReflectionInternalError("Class not resolved: $jClass")
|
||||
}
|
||||
|
||||
override val annotated: Annotated get() = descriptor
|
||||
|
||||
private val classId: ClassId get() = RuntimeTypeMapper.mapJvmClassToKotlinClassId(jClass)
|
||||
|
||||
override val scope: JetScope get() = ChainedScope(
|
||||
|
||||
@@ -18,15 +18,18 @@ package kotlin.reflect.jvm.internal
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.ParameterDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotated
|
||||
import kotlin.reflect.KParameter
|
||||
import kotlin.reflect.KType
|
||||
|
||||
class KParameterImpl(
|
||||
override val index: Int,
|
||||
private val computeDescriptor: () -> ParameterDescriptor
|
||||
) : KParameter {
|
||||
) : KParameter, KAnnotatedElementImpl {
|
||||
private val descriptor: ParameterDescriptor by ReflectProperties.lazySoft(computeDescriptor)
|
||||
|
||||
override val annotated: Annotated get() = descriptor
|
||||
|
||||
override val name: String? get() {
|
||||
val valueParameter = descriptor as? ValueParameterDescriptor ?: return null
|
||||
if (valueParameter.containingDeclaration.hasSynthesizedParameterNames()) return null
|
||||
|
||||
Reference in New Issue
Block a user