Reformat modules descriptors.jvm, descriptors.runtime
Also remove several unused files (BuiltinOverridabilityCondition.kt, PackageMappingProvider.kt)
This commit is contained in:
+7
-8
@@ -30,8 +30,8 @@ class ReflectJavaClassFinder(private val classLoader: ClassLoader) : JavaClassFi
|
||||
val packageFqName = classId.packageFqName
|
||||
val relativeClassName = classId.relativeClassName.asString().replace('.', '$')
|
||||
val name =
|
||||
if (packageFqName.isRoot) relativeClassName
|
||||
else packageFqName.asString() + "." + relativeClassName
|
||||
if (packageFqName.isRoot) relativeClassName
|
||||
else packageFqName.asString() + "." + relativeClassName
|
||||
|
||||
val klass = classLoader.tryLoadClass(name)
|
||||
return if (klass != null) ReflectJavaClass(klass) else null
|
||||
@@ -46,9 +46,8 @@ class ReflectJavaClassFinder(private val classLoader: ClassLoader) : JavaClassFi
|
||||
}
|
||||
|
||||
fun ClassLoader.tryLoadClass(fqName: String) =
|
||||
try {
|
||||
loadClass(fqName)
|
||||
}
|
||||
catch (e: ClassNotFoundException) {
|
||||
null
|
||||
}
|
||||
try {
|
||||
loadClass(fqName)
|
||||
} catch (e: ClassNotFoundException) {
|
||||
null
|
||||
}
|
||||
|
||||
+17
-21
@@ -35,23 +35,22 @@ import kotlin.reflect.jvm.internal.structure.isEnumClassOrSpecializedEnumEntryCl
|
||||
|
||||
@Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN")
|
||||
private val TYPES_ELIGIBLE_FOR_SIMPLE_VISIT = setOf<Class<*>>(
|
||||
// Primitives
|
||||
java.lang.Integer::class.java, java.lang.Character::class.java, java.lang.Byte::class.java, java.lang.Long::class.java,
|
||||
java.lang.Short::class.java, java.lang.Boolean::class.java, java.lang.Double::class.java, java.lang.Float::class.java,
|
||||
// Arrays of primitives
|
||||
IntArray::class.java, CharArray::class.java, ByteArray::class.java, LongArray::class.java,
|
||||
ShortArray::class.java, BooleanArray::class.java, DoubleArray::class.java, FloatArray::class.java,
|
||||
// Others
|
||||
Class::class.java, String::class.java
|
||||
// Primitives
|
||||
java.lang.Integer::class.java, java.lang.Character::class.java, java.lang.Byte::class.java, java.lang.Long::class.java,
|
||||
java.lang.Short::class.java, java.lang.Boolean::class.java, java.lang.Double::class.java, java.lang.Float::class.java,
|
||||
// Arrays of primitives
|
||||
IntArray::class.java, CharArray::class.java, ByteArray::class.java, LongArray::class.java,
|
||||
ShortArray::class.java, BooleanArray::class.java, DoubleArray::class.java, FloatArray::class.java,
|
||||
// Others
|
||||
Class::class.java, String::class.java
|
||||
)
|
||||
|
||||
class ReflectKotlinClass private constructor(
|
||||
val klass: Class<*>,
|
||||
override val classHeader: KotlinClassHeader
|
||||
val klass: Class<*>,
|
||||
override val classHeader: KotlinClassHeader
|
||||
) : KotlinJvmBinaryClass {
|
||||
|
||||
companion object Factory {
|
||||
|
||||
fun create(klass: Class<*>): ReflectKotlinClass? {
|
||||
val headerReader = ReadKotlinClassHeaderAnnotationVisitor()
|
||||
ReflectClassStructure.loadClassAnnotations(klass, headerReader)
|
||||
@@ -137,7 +136,7 @@ private object ReflectClassStructure {
|
||||
for (annotation in annotations) {
|
||||
val annotationType = annotation.annotationClass.java
|
||||
visitor.visitParameterAnnotation(
|
||||
parameterIndex + shift, annotationType.classId, ReflectAnnotationSource(annotation)
|
||||
parameterIndex + shift, annotationType.classId, ReflectAnnotationSource(annotation)
|
||||
)?.let {
|
||||
processAnnotationArguments(it, annotation, annotationType)
|
||||
}
|
||||
@@ -169,15 +168,14 @@ private object ReflectClassStructure {
|
||||
}
|
||||
|
||||
private fun processAnnotationArguments(
|
||||
visitor: KotlinJvmBinaryClass.AnnotationArgumentVisitor,
|
||||
annotation: Annotation,
|
||||
annotationType: Class<*>
|
||||
visitor: KotlinJvmBinaryClass.AnnotationArgumentVisitor,
|
||||
annotation: Annotation,
|
||||
annotationType: Class<*>
|
||||
) {
|
||||
for (method in annotationType.declaredMethods) {
|
||||
val value = try {
|
||||
method(annotation)!!
|
||||
}
|
||||
catch (e: IllegalAccessException) {
|
||||
} catch (e: IllegalAccessException) {
|
||||
// This is possible if the annotation class is package local. In this case, we can't read the value into descriptor.
|
||||
// However, this might be OK, because we do not use any data from AnnotationDescriptor in KAnnotatedElement implementations
|
||||
// anyway; we use the source element and the underlying physical Annotation object to implement the needed API
|
||||
@@ -241,13 +239,11 @@ private object ReflectClassStructure {
|
||||
for (element in value as Array<*>) {
|
||||
v.visitEnum(enumClassId, Name.identifier((element as Enum<*>).name))
|
||||
}
|
||||
}
|
||||
else if (componentType == Class::class.java) {
|
||||
} else if (componentType == Class::class.java) {
|
||||
for (element in value as Array<*>) {
|
||||
v.visitClassLiteral((element as Class<*>).classLiteralValue())
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
for (element in value as Array<*>) {
|
||||
v.visit(element)
|
||||
}
|
||||
|
||||
+13
-15
@@ -47,8 +47,8 @@ import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
||||
import org.jetbrains.kotlin.utils.Jsr305State
|
||||
|
||||
class RuntimeModuleData private constructor(
|
||||
val deserialization: DeserializationComponents,
|
||||
val packagePartProvider: RuntimePackagePartProvider
|
||||
val deserialization: DeserializationComponents,
|
||||
val packagePartProvider: RuntimePackagePartProvider
|
||||
) {
|
||||
val module: ModuleDescriptor get() = deserialization.moduleDescriptor
|
||||
|
||||
@@ -66,15 +66,13 @@ class RuntimeModuleData private constructor(
|
||||
val notFoundClasses = NotFoundClasses(storageManager, module)
|
||||
val annotationTypeQualifierResolver = AnnotationTypeQualifierResolver(storageManager, Jsr305State.DISABLED)
|
||||
val globalJavaResolverContext = JavaResolverComponents(
|
||||
storageManager, ReflectJavaClassFinder(classLoader), reflectKotlinClassFinder, deserializedDescriptorResolver,
|
||||
SignaturePropagator.DO_NOTHING, RuntimeErrorReporter, javaResolverCache,
|
||||
JavaPropertyInitializerEvaluator.DoNothing, SamConversionResolver.Empty, RuntimeSourceElementFactory, singleModuleClassResolver,
|
||||
runtimePackagePartProvider, SupertypeLoopChecker.EMPTY, LookupTracker.DO_NOTHING, module,
|
||||
ReflectionTypes(module, notFoundClasses),
|
||||
annotationTypeQualifierResolver,
|
||||
SignatureEnhancement(annotationTypeQualifierResolver, Jsr305State.DISABLED),
|
||||
JavaClassesTracker.Default,
|
||||
JavaResolverSettings.Default
|
||||
storageManager, ReflectJavaClassFinder(classLoader), reflectKotlinClassFinder, deserializedDescriptorResolver,
|
||||
SignaturePropagator.DO_NOTHING, RuntimeErrorReporter, javaResolverCache,
|
||||
JavaPropertyInitializerEvaluator.DoNothing, SamConversionResolver.Empty, RuntimeSourceElementFactory,
|
||||
singleModuleClassResolver, runtimePackagePartProvider, SupertypeLoopChecker.EMPTY, LookupTracker.DO_NOTHING, module,
|
||||
ReflectionTypes(module, notFoundClasses), annotationTypeQualifierResolver,
|
||||
SignatureEnhancement(annotationTypeQualifierResolver, Jsr305State.DISABLED),
|
||||
JavaClassesTracker.Default, JavaResolverSettings.Default
|
||||
)
|
||||
|
||||
val lazyJavaPackageFragmentProvider = LazyJavaPackageFragmentProvider(globalJavaResolverContext)
|
||||
@@ -84,12 +82,12 @@ class RuntimeModuleData private constructor(
|
||||
val javaDescriptorResolver = JavaDescriptorResolver(lazyJavaPackageFragmentProvider, javaResolverCache)
|
||||
val javaClassDataFinder = JavaClassDataFinder(reflectKotlinClassFinder, deserializedDescriptorResolver)
|
||||
val binaryClassAnnotationAndConstantLoader = BinaryClassAnnotationAndConstantLoaderImpl(
|
||||
module, notFoundClasses, storageManager, reflectKotlinClassFinder
|
||||
module, notFoundClasses, storageManager, reflectKotlinClassFinder
|
||||
)
|
||||
val deserializationComponentsForJava = DeserializationComponentsForJava(
|
||||
storageManager, module, DeserializationConfiguration.Default, javaClassDataFinder,
|
||||
binaryClassAnnotationAndConstantLoader, lazyJavaPackageFragmentProvider, notFoundClasses,
|
||||
RuntimeErrorReporter, LookupTracker.DO_NOTHING, ContractDeserializer.DEFAULT
|
||||
storageManager, module, DeserializationConfiguration.Default, javaClassDataFinder,
|
||||
binaryClassAnnotationAndConstantLoader, lazyJavaPackageFragmentProvider, notFoundClasses,
|
||||
RuntimeErrorReporter, LookupTracker.DO_NOTHING, ContractDeserializer.DEFAULT
|
||||
)
|
||||
|
||||
singleModuleClassResolver.resolver = javaDescriptorResolver
|
||||
|
||||
+11
-11
@@ -21,7 +21,7 @@ import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
abstract class ReflectJavaAnnotationArgument(
|
||||
override val name: Name?
|
||||
override val name: Name?
|
||||
) : JavaAnnotationArgument {
|
||||
companion object Factory {
|
||||
fun create(value: Any, name: Name?): ReflectJavaAnnotationArgument {
|
||||
@@ -37,20 +37,20 @@ abstract class ReflectJavaAnnotationArgument(
|
||||
}
|
||||
|
||||
class ReflectJavaLiteralAnnotationArgument(
|
||||
name: Name?,
|
||||
override val value: Any
|
||||
name: Name?,
|
||||
override val value: Any
|
||||
) : ReflectJavaAnnotationArgument(name), JavaLiteralAnnotationArgument
|
||||
|
||||
class ReflectJavaArrayAnnotationArgument(
|
||||
name: Name?,
|
||||
private val values: Array<*>
|
||||
name: Name?,
|
||||
private val values: Array<*>
|
||||
) : ReflectJavaAnnotationArgument(name), JavaArrayAnnotationArgument {
|
||||
override fun getElements() = values.map { ReflectJavaAnnotationArgument.create(it!!, null) }
|
||||
}
|
||||
|
||||
class ReflectJavaEnumValueAnnotationArgument(
|
||||
name: Name?,
|
||||
private val value: Enum<*>
|
||||
name: Name?,
|
||||
private val value: Enum<*>
|
||||
) : ReflectJavaAnnotationArgument(name), JavaEnumValueAnnotationArgument {
|
||||
override val enumClassId: ClassId?
|
||||
get() {
|
||||
@@ -64,15 +64,15 @@ class ReflectJavaEnumValueAnnotationArgument(
|
||||
}
|
||||
|
||||
class ReflectJavaClassObjectAnnotationArgument(
|
||||
name: Name?,
|
||||
private val klass: Class<*>
|
||||
name: Name?,
|
||||
private val klass: Class<*>
|
||||
) : ReflectJavaAnnotationArgument(name), JavaClassObjectAnnotationArgument {
|
||||
override fun getReferencedType(): JavaType = ReflectJavaType.create(klass)
|
||||
}
|
||||
|
||||
class ReflectJavaAnnotationAsAnnotationArgument(
|
||||
name: Name?,
|
||||
private val annotation: Annotation
|
||||
name: Name?,
|
||||
private val annotation: Annotation
|
||||
) : ReflectJavaAnnotationArgument(name), JavaAnnotationAsAnnotationArgument {
|
||||
override fun getAnnotation(): JavaAnnotation = ReflectJavaAnnotation(annotation)
|
||||
}
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ interface ReflectJavaAnnotationOwner : JavaAnnotationOwner {
|
||||
get() = element?.declaredAnnotations?.getAnnotations() ?: emptyList()
|
||||
|
||||
override fun findAnnotation(fqName: FqName) =
|
||||
element?.declaredAnnotations?.findAnnotation(fqName)
|
||||
element?.declaredAnnotations?.findAnnotation(fqName)
|
||||
|
||||
override val isDeprecatedInJavaDoc: Boolean
|
||||
get() = false
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ import java.lang.reflect.GenericArrayType
|
||||
import java.lang.reflect.Type
|
||||
|
||||
class ReflectJavaArrayType(override val reflectType: Type) : ReflectJavaType(), JavaArrayType {
|
||||
override val componentType: ReflectJavaType = with (reflectType) {
|
||||
override val componentType: ReflectJavaType = with(reflectType) {
|
||||
when {
|
||||
this is GenericArrayType -> ReflectJavaType.create(genericComponentType)
|
||||
this is Class<*> && isArray() -> ReflectJavaType.create(getComponentType())
|
||||
|
||||
+30
-30
@@ -25,7 +25,7 @@ import java.lang.reflect.Method
|
||||
import java.util.*
|
||||
|
||||
class ReflectJavaClass(
|
||||
private val klass: Class<*>
|
||||
private val klass: Class<*>
|
||||
) : ReflectJavaElement(), ReflectJavaAnnotationOwner, ReflectJavaModifierListOwner, JavaClass {
|
||||
override val element: Class<*> get() = klass
|
||||
|
||||
@@ -33,20 +33,20 @@ class ReflectJavaClass(
|
||||
|
||||
override val innerClassNames: List<Name>
|
||||
get() = klass.declaredClasses
|
||||
.asSequence()
|
||||
.filterNot {
|
||||
// getDeclaredClasses() returns anonymous classes sometimes, for example enums with specialized entries (which are
|
||||
// in fact anonymous classes) or in case of a special anonymous class created for the synthetic accessor to a private
|
||||
// nested class constructor accessed from the outer class
|
||||
it.simpleName.isEmpty()
|
||||
}
|
||||
.mapNotNull { it.simpleName.takeIf(Name::isValidIdentifier)?.let(Name::identifier) }.toList()
|
||||
.asSequence()
|
||||
.filterNot {
|
||||
// getDeclaredClasses() returns anonymous classes sometimes, for example enums with specialized entries (which are
|
||||
// in fact anonymous classes) or in case of a special anonymous class created for the synthetic accessor to a private
|
||||
// nested class constructor accessed from the outer class
|
||||
it.simpleName.isEmpty()
|
||||
}
|
||||
.mapNotNull { it.simpleName.takeIf(Name::isValidIdentifier)?.let(Name::identifier) }.toList()
|
||||
|
||||
override fun findInnerClass(name: Name) = klass.declaredClasses
|
||||
.asSequence()
|
||||
.firstOrNull {
|
||||
it.simpleName == name.asString()
|
||||
}?.let(::ReflectJavaClass)
|
||||
.asSequence()
|
||||
.firstOrNull {
|
||||
it.simpleName == name.asString()
|
||||
}?.let(::ReflectJavaClass)
|
||||
|
||||
override val fqName: FqName
|
||||
get() = klass.classId.asSingleFqName()
|
||||
@@ -62,16 +62,16 @@ class ReflectJavaClass(
|
||||
|
||||
override val methods: List<ReflectJavaMethod>
|
||||
get() = klass.declaredMethods
|
||||
.asSequence()
|
||||
.filter { method ->
|
||||
when {
|
||||
method.isSynthetic -> false
|
||||
isEnum -> !isEnumValuesOrValueOf(method)
|
||||
else -> true
|
||||
}
|
||||
.asSequence()
|
||||
.filter { method ->
|
||||
when {
|
||||
method.isSynthetic -> false
|
||||
isEnum -> !isEnumValuesOrValueOf(method)
|
||||
else -> true
|
||||
}
|
||||
.map(::ReflectJavaMethod)
|
||||
.toList()
|
||||
}
|
||||
.map(::ReflectJavaMethod)
|
||||
.toList()
|
||||
|
||||
private fun isEnumValuesOrValueOf(method: Method): Boolean {
|
||||
return when (method.name) {
|
||||
@@ -83,17 +83,17 @@ class ReflectJavaClass(
|
||||
|
||||
override val fields: List<ReflectJavaField>
|
||||
get() = klass.declaredFields
|
||||
.asSequence()
|
||||
.filter { field -> !field.isSynthetic }
|
||||
.map(::ReflectJavaField)
|
||||
.toList()
|
||||
.asSequence()
|
||||
.filter { field -> !field.isSynthetic }
|
||||
.map(::ReflectJavaField)
|
||||
.toList()
|
||||
|
||||
override val constructors: List<ReflectJavaConstructor>
|
||||
get() = klass.declaredConstructors
|
||||
.asSequence()
|
||||
.filter { constructor -> !constructor.isSynthetic }
|
||||
.map(::ReflectJavaConstructor)
|
||||
.toList()
|
||||
.asSequence()
|
||||
.filter { constructor -> !constructor.isSynthetic }
|
||||
.map(::ReflectJavaConstructor)
|
||||
.toList()
|
||||
|
||||
override val lightClassOriginKind: LightClassOriginKind?
|
||||
get() = null
|
||||
|
||||
+4
-5
@@ -40,9 +40,9 @@ abstract class ReflectJavaMember : ReflectJavaElement(), ReflectJavaAnnotationOw
|
||||
get() = ReflectJavaClass(member.declaringClass)
|
||||
|
||||
protected fun getValueParameters(
|
||||
parameterTypes: Array<Type>,
|
||||
parameterAnnotations: Array<Array<Annotation>>,
|
||||
isVararg: Boolean
|
||||
parameterTypes: Array<Type>,
|
||||
parameterAnnotations: Array<Array<Annotation>>,
|
||||
isVararg: Boolean
|
||||
): List<JavaValueParameter> {
|
||||
val result = ArrayList<JavaValueParameter>(parameterTypes.size)
|
||||
val names = Java8ParameterNamesLoader.loadParameterNames(member)
|
||||
@@ -79,8 +79,7 @@ private object Java8ParameterNamesLoader {
|
||||
|
||||
val getParameters = try {
|
||||
methodOrConstructorClass.getMethod("getParameters")
|
||||
}
|
||||
catch (e: NoSuchMethodException) {
|
||||
} catch (e: NoSuchMethodException) {
|
||||
return Cache(null, null)
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ import java.lang.reflect.AnnotatedElement
|
||||
import java.lang.reflect.TypeVariable
|
||||
|
||||
class ReflectJavaTypeParameter(
|
||||
val typeVariable: TypeVariable<*>
|
||||
val typeVariable: TypeVariable<*>
|
||||
) : ReflectJavaElement(), JavaTypeParameter, ReflectJavaAnnotationOwner {
|
||||
override val upperBounds: List<ReflectJavaClassifierType>
|
||||
get() {
|
||||
|
||||
+5
-5
@@ -21,16 +21,16 @@ import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
class ReflectJavaValueParameter(
|
||||
override val type: ReflectJavaType,
|
||||
private val reflectAnnotations: Array<Annotation>,
|
||||
private val reflectName: String?,
|
||||
override val isVararg: Boolean
|
||||
override val type: ReflectJavaType,
|
||||
private val reflectAnnotations: Array<Annotation>,
|
||||
private val reflectName: String?,
|
||||
override val isVararg: Boolean
|
||||
) : ReflectJavaElement(), JavaValueParameter {
|
||||
override val annotations: List<ReflectJavaAnnotation>
|
||||
get() = reflectAnnotations.getAnnotations()
|
||||
|
||||
override fun findAnnotation(fqName: FqName) =
|
||||
reflectAnnotations.findAnnotation(fqName)
|
||||
reflectAnnotations.findAnnotation(fqName)
|
||||
|
||||
override val isDeprecatedInJavaDoc: Boolean
|
||||
get() = false
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@ package kotlin.reflect.jvm.internal.structure
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaWildcardType
|
||||
import java.lang.reflect.WildcardType
|
||||
|
||||
class ReflectJavaWildcardType(override val reflectType: WildcardType): ReflectJavaType(), JavaWildcardType {
|
||||
class ReflectJavaWildcardType(override val reflectType: WildcardType) : ReflectJavaType(), JavaWildcardType {
|
||||
override val bound: ReflectJavaType?
|
||||
get() {
|
||||
val upperBounds = reflectType.upperBounds
|
||||
|
||||
+10
-10
@@ -27,10 +27,10 @@ val Class<*>.safeClassLoader: ClassLoader
|
||||
get() = classLoader ?: ClassLoader.getSystemClassLoader()
|
||||
|
||||
fun Class<*>.isEnumClassOrSpecializedEnumEntryClass(): Boolean =
|
||||
Enum::class.java.isAssignableFrom(this)
|
||||
Enum::class.java.isAssignableFrom(this)
|
||||
|
||||
private val PRIMITIVE_CLASSES =
|
||||
listOf(Boolean::class, Byte::class, Char::class, Double::class, Float::class, Int::class, Long::class, Short::class)
|
||||
listOf(Boolean::class, Byte::class, Char::class, Double::class, Float::class, Int::class, Long::class, Short::class)
|
||||
private val WRAPPER_TO_PRIMITIVE = PRIMITIVE_CLASSES.map { it.javaObjectType to it.javaPrimitiveType }.toMap()
|
||||
private val PRIMITIVE_TO_WRAPPER = PRIMITIVE_CLASSES.map { it.javaPrimitiveType to it.javaObjectType }.toMap()
|
||||
|
||||
@@ -41,13 +41,13 @@ val Class<*>.wrapperByPrimitive: Class<*>?
|
||||
get() = PRIMITIVE_TO_WRAPPER[this]
|
||||
|
||||
private val FUNCTION_CLASSES =
|
||||
listOf(
|
||||
Function0::class.java, Function1::class.java, Function2::class.java, Function3::class.java, Function4::class.java,
|
||||
Function5::class.java, Function6::class.java, Function7::class.java, Function8::class.java, Function9::class.java,
|
||||
Function10::class.java, Function11::class.java, Function12::class.java, Function13::class.java, Function14::class.java,
|
||||
Function15::class.java, Function16::class.java, Function17::class.java, Function18::class.java, Function19::class.java,
|
||||
Function20::class.java, Function21::class.java, Function22::class.java
|
||||
).mapIndexed { i, clazz -> clazz to i }.toMap()
|
||||
listOf(
|
||||
Function0::class.java, Function1::class.java, Function2::class.java, Function3::class.java, Function4::class.java,
|
||||
Function5::class.java, Function6::class.java, Function7::class.java, Function8::class.java, Function9::class.java,
|
||||
Function10::class.java, Function11::class.java, Function12::class.java, Function13::class.java, Function14::class.java,
|
||||
Function15::class.java, Function16::class.java, Function17::class.java, Function18::class.java, Function19::class.java,
|
||||
Function20::class.java, Function21::class.java, Function22::class.java
|
||||
).mapIndexed { i, clazz -> clazz to i }.toMap()
|
||||
|
||||
val Class<*>.functionClassArity: Int?
|
||||
get() = FUNCTION_CLASSES[this]
|
||||
@@ -75,7 +75,7 @@ val Class<*>.desc: String
|
||||
}
|
||||
|
||||
fun Class<*>.createArrayType(): Class<*> =
|
||||
Array.newInstance(this, 0)::class.java
|
||||
Array.newInstance(this, 0)::class.java
|
||||
|
||||
/**
|
||||
* @return all arguments of a parameterized type, including those of outer classes in case this type represents an inner generic.
|
||||
|
||||
+40
-32
@@ -47,7 +47,7 @@ abstract class AbstractJvmRuntimeDescriptorLoaderTest : TestCaseWithTmpdir() {
|
||||
private val renderer = DescriptorRenderer.withOptions {
|
||||
withDefinedIn = false
|
||||
excludedAnnotationClasses = setOf(
|
||||
FqName(ExpectedLoadErrorsUtil.ANNOTATION_CLASS_NAME)
|
||||
FqName(ExpectedLoadErrorsUtil.ANNOTATION_CLASS_NAME)
|
||||
)
|
||||
overrideRenderingPolicy = OverrideRenderingPolicy.RENDER_OPEN_OVERRIDE
|
||||
parameterNameRenderingPolicy = ParameterNameRenderingPolicy.NONE
|
||||
@@ -71,8 +71,8 @@ abstract class AbstractJvmRuntimeDescriptorLoaderTest : TestCaseWithTmpdir() {
|
||||
if (InTextDirectivesUtils.isDirectiveDefined(text, "SKIP_IN_RUNTIME_TEST")) return
|
||||
|
||||
val jdkKind =
|
||||
if (InTextDirectivesUtils.isDirectiveDefined(text, "FULL_JDK")) TestJdkKind.FULL_JDK
|
||||
else defaultJdkKind
|
||||
if (InTextDirectivesUtils.isDirectiveDefined(text, "FULL_JDK")) TestJdkKind.FULL_JDK
|
||||
else defaultJdkKind
|
||||
|
||||
compileFile(file, text, jdkKind)
|
||||
|
||||
@@ -81,14 +81,14 @@ abstract class AbstractJvmRuntimeDescriptorLoaderTest : TestCaseWithTmpdir() {
|
||||
val actual = createReflectedPackageView(classLoader, KotlinTestUtils.TEST_MODULE_NAME)
|
||||
|
||||
val comparatorConfiguration = Configuration(
|
||||
/* checkPrimaryConstructors = */ fileName.endsWith(".kt"),
|
||||
/* checkPropertyAccessors = */ true,
|
||||
/* includeMethodsOfKotlinAny = */ false,
|
||||
/* renderDeclarationsFromOtherModules = */ true,
|
||||
/* checkFunctionContract = */ false,
|
||||
// Skip Java annotation constructors because order of their parameters is not retained at runtime
|
||||
{ descriptor -> !descriptor!!.isJavaAnnotationConstructor() },
|
||||
errorTypesForbidden(), renderer
|
||||
/* checkPrimaryConstructors = */ fileName.endsWith(".kt"),
|
||||
/* checkPropertyAccessors = */ true,
|
||||
/* includeMethodsOfKotlinAny = */ false,
|
||||
/* renderDeclarationsFromOtherModules = */ true,
|
||||
/* checkFunctionContract = */ false,
|
||||
// Skip Java annotation constructors because order of their parameters is not retained at runtime
|
||||
{ descriptor -> !descriptor!!.isJavaAnnotationConstructor() },
|
||||
errorTypesForbidden(), renderer
|
||||
)
|
||||
|
||||
val differentResultFile = KotlinTestUtils.replaceExtension(file, "runtime.txt")
|
||||
@@ -98,16 +98,16 @@ abstract class AbstractJvmRuntimeDescriptorLoaderTest : TestCaseWithTmpdir() {
|
||||
}
|
||||
|
||||
val expected = LoadDescriptorUtil.loadTestPackageAndBindingContextFromJavaRoot(
|
||||
tmpdir, testRootDisposable, jdkKind, ConfigurationKind.ALL, true, false, false, null
|
||||
tmpdir, testRootDisposable, jdkKind, ConfigurationKind.ALL, true, false, false, null
|
||||
).first
|
||||
|
||||
RecursiveDescriptorComparator.validateAndCompareDescriptors(expected, actual, comparatorConfiguration, null)
|
||||
}
|
||||
|
||||
private fun DeclarationDescriptor.isJavaAnnotationConstructor() =
|
||||
this is ClassConstructorDescriptor &&
|
||||
containingDeclaration is JavaClassDescriptor &&
|
||||
containingDeclaration.kind == ClassKind.ANNOTATION_CLASS
|
||||
this is ClassConstructorDescriptor &&
|
||||
containingDeclaration is JavaClassDescriptor &&
|
||||
containingDeclaration.kind == ClassKind.ANNOTATION_CLASS
|
||||
|
||||
private fun compileFile(file: File, text: String, jdkKind: TestJdkKind) {
|
||||
val fileName = file.name
|
||||
@@ -124,7 +124,7 @@ abstract class AbstractJvmRuntimeDescriptorLoaderTest : TestCaseWithTmpdir() {
|
||||
}
|
||||
fileName.endsWith(".kt") -> {
|
||||
val environment = KotlinTestUtils.createEnvironmentWithJdkAndNullabilityAnnotationsFromIdea(
|
||||
myTestRootDisposable, ConfigurationKind.ALL, jdkKind
|
||||
myTestRootDisposable, ConfigurationKind.ALL, jdkKind
|
||||
)
|
||||
for (root in environment.configuration.getList(CLIConfigurationKeys.CONTENT_ROOTS)) {
|
||||
LOG.info("root: " + root.toString())
|
||||
@@ -157,8 +157,7 @@ abstract class AbstractJvmRuntimeDescriptorLoaderTest : TestCaseWithTmpdir() {
|
||||
if (!packageScopes.contains(packageView.memberScope)) {
|
||||
packageScopes.add(packageView.memberScope)
|
||||
}
|
||||
}
|
||||
else if (header == null || header.kind == KotlinClassHeader.Kind.CLASS) {
|
||||
} else if (header == null || header.kind == KotlinClassHeader.Kind.CLASS) {
|
||||
// Either a normal Kotlin class or a Java class
|
||||
val classId = klass.classId
|
||||
if (!classId.isLocal) {
|
||||
@@ -180,16 +179,18 @@ abstract class AbstractJvmRuntimeDescriptorLoaderTest : TestCaseWithTmpdir() {
|
||||
val adaptedSource = typeAnnotations.fold(text) { text, annotation -> text.replace("@$annotation", "") }
|
||||
if ("@Retention" !in adaptedSource) {
|
||||
return adaptedSource.replace(
|
||||
"@interface",
|
||||
"@java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME) @interface"
|
||||
"@interface",
|
||||
"@java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME) @interface"
|
||||
)
|
||||
}
|
||||
return adaptedSource
|
||||
}
|
||||
|
||||
private class SyntheticPackageViewForTest(override val module: ModuleDescriptor,
|
||||
packageScopes: List<MemberScope>,
|
||||
classes: List<ClassifierDescriptor>) : PackageViewDescriptor {
|
||||
private class SyntheticPackageViewForTest(
|
||||
override val module: ModuleDescriptor,
|
||||
packageScopes: List<MemberScope>,
|
||||
classes: List<ClassifierDescriptor>
|
||||
) : PackageViewDescriptor {
|
||||
private val scope: MemberScope
|
||||
|
||||
init {
|
||||
@@ -204,13 +205,13 @@ abstract class AbstractJvmRuntimeDescriptorLoaderTest : TestCaseWithTmpdir() {
|
||||
override val memberScope: MemberScope
|
||||
get() = scope
|
||||
override val fragments: List<PackageFragmentDescriptor> = listOf(
|
||||
object : PackageFragmentDescriptorImpl(module, fqName) {
|
||||
override fun getMemberScope(): MemberScope = scope
|
||||
}
|
||||
object : PackageFragmentDescriptorImpl(module, fqName) {
|
||||
override fun getMemberScope(): MemberScope = scope
|
||||
}
|
||||
)
|
||||
|
||||
override fun <R, D> accept(visitor: DeclarationDescriptorVisitor<R, D>, data: D): R =
|
||||
visitor.visitPackageViewDescriptor(this, data)
|
||||
visitor.visitPackageViewDescriptor(this, data)
|
||||
|
||||
override fun getContainingDeclaration() = null
|
||||
override fun getOriginal() = throw UnsupportedOperationException()
|
||||
@@ -226,16 +227,23 @@ abstract class AbstractJvmRuntimeDescriptorLoaderTest : TestCaseWithTmpdir() {
|
||||
init {
|
||||
for (classifier in classifiers) {
|
||||
classifierMap.put(classifier.name, classifier)?.let {
|
||||
throw IllegalStateException(String.format("Redeclaration: %s (%s) and %s (%s) (no line info available)",
|
||||
DescriptorUtils.getFqName(it), it,
|
||||
DescriptorUtils.getFqName(classifier), classifier))
|
||||
throw IllegalStateException(
|
||||
String.format(
|
||||
"Redeclaration: %s (%s) and %s (%s) (no line info available)",
|
||||
DescriptorUtils.getFqName(it), it,
|
||||
DescriptorUtils.getFqName(classifier), classifier
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun getContributedClassifier(name: Name, location: LookupLocation): ClassifierDescriptor? = classifierMap[name]
|
||||
|
||||
override fun getContributedDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> = classifierMap.values
|
||||
override fun getContributedDescriptors(
|
||||
kindFilter: DescriptorKindFilter,
|
||||
nameFilter: (Name) -> Boolean
|
||||
): Collection<DeclarationDescriptor> = classifierMap.values
|
||||
|
||||
override fun printScopeStructure(p: Printer) {
|
||||
p.println("runtime descriptor loader test")
|
||||
@@ -244,4 +252,4 @@ abstract class AbstractJvmRuntimeDescriptorLoaderTest : TestCaseWithTmpdir() {
|
||||
|
||||
}
|
||||
|
||||
private val LOG = Logger.getInstance(KotlinMultiFileTestWithJava::class.java)
|
||||
private val LOG = Logger.getInstance(KotlinMultiFileTestWithJava::class.java)
|
||||
|
||||
Reference in New Issue
Block a user