core: cleanup 'public', property access syntax
This commit is contained in:
+2
-2
@@ -20,8 +20,8 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
|||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||||
|
|
||||||
public object FakePureImplementationsProvider {
|
object FakePureImplementationsProvider {
|
||||||
public fun getPurelyImplementedInterface(classFqName: FqName): FqName? = when(classFqName) {
|
fun getPurelyImplementedInterface(classFqName: FqName): FqName? = when(classFqName) {
|
||||||
in MUTABLE_LISTS_IMPLEMENTATIONS -> MUTABLE_LIST_FQ_NAME
|
in MUTABLE_LISTS_IMPLEMENTATIONS -> MUTABLE_LIST_FQ_NAME
|
||||||
in MUTABLE_MAPS_IMPLEMENTATIONS -> MUTABLE_MAP_FQ_NAME
|
in MUTABLE_MAPS_IMPLEMENTATIONS -> MUTABLE_MAP_FQ_NAME
|
||||||
in MUTABLE_SETS_IMPLEMENTATIONS -> MUTABLE_SET_FQ_NAME
|
in MUTABLE_SETS_IMPLEMENTATIONS -> MUTABLE_SET_FQ_NAME
|
||||||
|
|||||||
+8
-8
@@ -36,7 +36,7 @@ import java.lang.annotation.Retention
|
|||||||
import java.lang.annotation.Target
|
import java.lang.annotation.Target
|
||||||
import java.util.EnumSet
|
import java.util.EnumSet
|
||||||
|
|
||||||
public object JavaAnnotationMapper {
|
object JavaAnnotationMapper {
|
||||||
|
|
||||||
private val JAVA_TARGET_FQ_NAME = FqName(Target::class.java.canonicalName)
|
private val JAVA_TARGET_FQ_NAME = FqName(Target::class.java.canonicalName)
|
||||||
private val JAVA_RETENTION_FQ_NAME = FqName(Retention::class.java.canonicalName)
|
private val JAVA_RETENTION_FQ_NAME = FqName(Retention::class.java.canonicalName)
|
||||||
@@ -45,7 +45,7 @@ public object JavaAnnotationMapper {
|
|||||||
// Java8-specific thing
|
// Java8-specific thing
|
||||||
private val JAVA_REPEATABLE_FQ_NAME = FqName("java.lang.annotation.Repeatable")
|
private val JAVA_REPEATABLE_FQ_NAME = FqName("java.lang.annotation.Repeatable")
|
||||||
|
|
||||||
public fun mapOrResolveJavaAnnotation(annotation: JavaAnnotation, c: LazyJavaResolverContext): AnnotationDescriptor? =
|
fun mapOrResolveJavaAnnotation(annotation: JavaAnnotation, c: LazyJavaResolverContext): AnnotationDescriptor? =
|
||||||
when (annotation.classId) {
|
when (annotation.classId) {
|
||||||
ClassId.topLevel(JAVA_TARGET_FQ_NAME) -> JavaTargetAnnotationDescriptor(annotation, c)
|
ClassId.topLevel(JAVA_TARGET_FQ_NAME) -> JavaTargetAnnotationDescriptor(annotation, c)
|
||||||
ClassId.topLevel(JAVA_RETENTION_FQ_NAME) -> JavaRetentionAnnotationDescriptor(annotation, c)
|
ClassId.topLevel(JAVA_RETENTION_FQ_NAME) -> JavaRetentionAnnotationDescriptor(annotation, c)
|
||||||
@@ -55,7 +55,7 @@ public object JavaAnnotationMapper {
|
|||||||
else -> c.resolveAnnotation(annotation)
|
else -> c.resolveAnnotation(annotation)
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun findMappedJavaAnnotation(kotlinName: FqName,
|
fun findMappedJavaAnnotation(kotlinName: FqName,
|
||||||
annotationOwner: JavaAnnotationOwner,
|
annotationOwner: JavaAnnotationOwner,
|
||||||
c: LazyJavaResolverContext
|
c: LazyJavaResolverContext
|
||||||
): AnnotationDescriptor? {
|
): AnnotationDescriptor? {
|
||||||
@@ -79,7 +79,7 @@ public object JavaAnnotationMapper {
|
|||||||
KotlinBuiltIns.FQ_NAMES.repeatable to JAVA_REPEATABLE_FQ_NAME,
|
KotlinBuiltIns.FQ_NAMES.repeatable to JAVA_REPEATABLE_FQ_NAME,
|
||||||
KotlinBuiltIns.FQ_NAMES.mustBeDocumented to JAVA_DOCUMENTED_FQ_NAME)
|
KotlinBuiltIns.FQ_NAMES.mustBeDocumented to JAVA_DOCUMENTED_FQ_NAME)
|
||||||
|
|
||||||
public val javaToKotlinNameMap: Map<FqName, FqName> =
|
val javaToKotlinNameMap: Map<FqName, FqName> =
|
||||||
mapOf(JAVA_TARGET_FQ_NAME to KotlinBuiltIns.FQ_NAMES.target,
|
mapOf(JAVA_TARGET_FQ_NAME to KotlinBuiltIns.FQ_NAMES.target,
|
||||||
JAVA_RETENTION_FQ_NAME to KotlinBuiltIns.FQ_NAMES.retention,
|
JAVA_RETENTION_FQ_NAME to KotlinBuiltIns.FQ_NAMES.retention,
|
||||||
JAVA_DEPRECATED_FQ_NAME to KotlinBuiltIns.FQ_NAMES.deprecated,
|
JAVA_DEPRECATED_FQ_NAME to KotlinBuiltIns.FQ_NAMES.deprecated,
|
||||||
@@ -154,7 +154,7 @@ class JavaRetentionAnnotationDescriptor(
|
|||||||
override fun getAllValueArguments() = valueArguments()
|
override fun getAllValueArguments() = valueArguments()
|
||||||
}
|
}
|
||||||
|
|
||||||
public object JavaAnnotationTargetMapper {
|
object JavaAnnotationTargetMapper {
|
||||||
private val targetNameLists = mapOf("PACKAGE" to EnumSet.noneOf(KotlinTarget::class.java),
|
private val targetNameLists = mapOf("PACKAGE" to EnumSet.noneOf(KotlinTarget::class.java),
|
||||||
"TYPE" to EnumSet.of(KotlinTarget.CLASS, KotlinTarget.FILE),
|
"TYPE" to EnumSet.of(KotlinTarget.CLASS, KotlinTarget.FILE),
|
||||||
"ANNOTATION_TYPE" to EnumSet.of(KotlinTarget.ANNOTATION_CLASS),
|
"ANNOTATION_TYPE" to EnumSet.of(KotlinTarget.ANNOTATION_CLASS),
|
||||||
@@ -169,9 +169,9 @@ public object JavaAnnotationTargetMapper {
|
|||||||
"TYPE_USE" to EnumSet.of(KotlinTarget.TYPE)
|
"TYPE_USE" to EnumSet.of(KotlinTarget.TYPE)
|
||||||
)
|
)
|
||||||
|
|
||||||
public fun mapJavaTargetArgumentByName(argumentName: String?): Set<KotlinTarget> = targetNameLists[argumentName] ?: emptySet()
|
fun mapJavaTargetArgumentByName(argumentName: String?): Set<KotlinTarget> = targetNameLists[argumentName] ?: emptySet()
|
||||||
|
|
||||||
public fun mapJavaTargetArguments(arguments: List<JavaAnnotationArgument>, builtIns: KotlinBuiltIns): ConstantValue<*>? {
|
fun mapJavaTargetArguments(arguments: List<JavaAnnotationArgument>, builtIns: KotlinBuiltIns): ConstantValue<*>? {
|
||||||
// Map arguments: java.lang.annotation.Target -> kotlin.annotation.Target
|
// Map arguments: java.lang.annotation.Target -> kotlin.annotation.Target
|
||||||
val kotlinTargets = arguments.filterIsInstance<JavaEnumValueAnnotationArgument>()
|
val kotlinTargets = arguments.filterIsInstance<JavaEnumValueAnnotationArgument>()
|
||||||
.flatMap { mapJavaTargetArgumentByName(it.resolve()?.name?.asString()) }
|
.flatMap { mapJavaTargetArgumentByName(it.resolve()?.name?.asString()) }
|
||||||
@@ -188,7 +188,7 @@ public object JavaAnnotationTargetMapper {
|
|||||||
"SOURCE" to KotlinRetention.SOURCE
|
"SOURCE" to KotlinRetention.SOURCE
|
||||||
)
|
)
|
||||||
|
|
||||||
public fun mapJavaRetentionArgument(element: JavaAnnotationArgument, builtIns: KotlinBuiltIns): ConstantValue<*>? {
|
fun mapJavaRetentionArgument(element: JavaAnnotationArgument, builtIns: KotlinBuiltIns): ConstantValue<*>? {
|
||||||
// Map argument: java.lang.annotation.Retention -> kotlin.annotation.annotation
|
// Map argument: java.lang.annotation.Retention -> kotlin.annotation.annotation
|
||||||
return (element as? JavaEnumValueAnnotationArgument)?.let {
|
return (element as? JavaEnumValueAnnotationArgument)?.let {
|
||||||
retentionNameList[it.resolve()?.name?.asString()]?.let {
|
retentionNameList[it.resolve()?.name?.asString()]?.let {
|
||||||
|
|||||||
+5
-5
@@ -24,8 +24,8 @@ import org.jetbrains.kotlin.load.java.descriptors.SamConstructorDescriptor
|
|||||||
import org.jetbrains.kotlin.load.java.structure.JavaMethod
|
import org.jetbrains.kotlin.load.java.structure.JavaMethod
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
|
|
||||||
public interface SamConversionResolver {
|
interface SamConversionResolver {
|
||||||
public companion object EMPTY : SamConversionResolver {
|
companion object EMPTY : SamConversionResolver {
|
||||||
override fun <D : FunctionDescriptor> resolveSamAdapter(original: D) = null
|
override fun <D : FunctionDescriptor> resolveSamAdapter(original: D) = null
|
||||||
override fun resolveSamConstructor(constructorOwner: DeclarationDescriptor, classifier: () -> ClassifierDescriptor?) = null
|
override fun resolveSamConstructor(constructorOwner: DeclarationDescriptor, classifier: () -> ClassifierDescriptor?) = null
|
||||||
override fun resolveFunctionTypeIfSamInterface(
|
override fun resolveFunctionTypeIfSamInterface(
|
||||||
@@ -33,11 +33,11 @@ public interface SamConversionResolver {
|
|||||||
): KotlinType? = null
|
): KotlinType? = null
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun resolveSamConstructor(constructorOwner: DeclarationDescriptor, classifier: () -> ClassifierDescriptor?): SamConstructorDescriptor?
|
fun resolveSamConstructor(constructorOwner: DeclarationDescriptor, classifier: () -> ClassifierDescriptor?): SamConstructorDescriptor?
|
||||||
|
|
||||||
public fun <D : FunctionDescriptor> resolveSamAdapter(original: D): D?
|
fun <D : FunctionDescriptor> resolveSamAdapter(original: D): D?
|
||||||
|
|
||||||
public fun resolveFunctionTypeIfSamInterface(
|
fun resolveFunctionTypeIfSamInterface(
|
||||||
classDescriptor: JavaClassDescriptor,
|
classDescriptor: JavaClassDescriptor,
|
||||||
resolveMethod: (JavaMethod) -> FunctionDescriptor
|
resolveMethod: (JavaMethod) -> FunctionDescriptor
|
||||||
): KotlinType?
|
): KotlinType?
|
||||||
|
|||||||
+5
-5
@@ -21,19 +21,19 @@ import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
|||||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindExclude
|
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindExclude
|
||||||
|
|
||||||
public class SamConstructorDescriptor(
|
class SamConstructorDescriptor(
|
||||||
containingDeclaration: DeclarationDescriptor,
|
containingDeclaration: DeclarationDescriptor,
|
||||||
samInterface: JavaClassDescriptor
|
samInterface: JavaClassDescriptor
|
||||||
) : SimpleFunctionDescriptorImpl(
|
) : SimpleFunctionDescriptorImpl(
|
||||||
containingDeclaration,
|
containingDeclaration,
|
||||||
null,
|
null,
|
||||||
samInterface.getAnnotations(),
|
samInterface.annotations,
|
||||||
samInterface.getName(),
|
samInterface.name,
|
||||||
CallableMemberDescriptor.Kind.SYNTHESIZED,
|
CallableMemberDescriptor.Kind.SYNTHESIZED,
|
||||||
samInterface.getSource()
|
samInterface.source
|
||||||
)
|
)
|
||||||
|
|
||||||
public object SamConstructorDescriptorKindExclude : DescriptorKindExclude() {
|
object SamConstructorDescriptorKindExclude : DescriptorKindExclude() {
|
||||||
override fun excludes(descriptor: DeclarationDescriptor) = descriptor is SamConstructorDescriptor
|
override fun excludes(descriptor: DeclarationDescriptor) = descriptor is SamConstructorDescriptor
|
||||||
|
|
||||||
override val fullyExcludedDescriptorKinds: Int get() = 0
|
override val fullyExcludedDescriptorKinds: Int get() = 0
|
||||||
|
|||||||
+1
-1
@@ -28,7 +28,7 @@ import org.jetbrains.kotlin.name.Name
|
|||||||
import org.jetbrains.kotlin.storage.MemoizedFunctionToNullable
|
import org.jetbrains.kotlin.storage.MemoizedFunctionToNullable
|
||||||
import org.jetbrains.kotlin.utils.emptyOrSingletonList
|
import org.jetbrains.kotlin.utils.emptyOrSingletonList
|
||||||
|
|
||||||
public class LazyJavaPackageFragmentProvider(
|
class LazyJavaPackageFragmentProvider(
|
||||||
components: JavaResolverComponents,
|
components: JavaResolverComponents,
|
||||||
module: ModuleDescriptor,
|
module: ModuleDescriptor,
|
||||||
reflectionTypes: ReflectionTypes
|
reflectionTypes: ReflectionTypes
|
||||||
|
|||||||
+4
-4
@@ -23,11 +23,11 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
|||||||
import kotlin.properties.Delegates
|
import kotlin.properties.Delegates
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
public interface ModuleClassResolver {
|
interface ModuleClassResolver {
|
||||||
public fun resolveClass(javaClass: JavaClass): ClassDescriptor?
|
fun resolveClass(javaClass: JavaClass): ClassDescriptor?
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SingleModuleClassResolver() : ModuleClassResolver {
|
class SingleModuleClassResolver() : ModuleClassResolver {
|
||||||
override fun resolveClass(javaClass: JavaClass): ClassDescriptor? {
|
override fun resolveClass(javaClass: JavaClass): ClassDescriptor? {
|
||||||
return resolver!!.resolveClass(javaClass)
|
return resolver!!.resolveClass(javaClass)
|
||||||
}
|
}
|
||||||
@@ -37,6 +37,6 @@ public class SingleModuleClassResolver() : ModuleClassResolver {
|
|||||||
@Inject set
|
@Inject set
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ModuleClassResolverImpl(private val descriptorResolverByJavaClass: (JavaClass) -> JavaDescriptorResolver): ModuleClassResolver {
|
class ModuleClassResolverImpl(private val descriptorResolverByJavaClass: (JavaClass) -> JavaDescriptorResolver): ModuleClassResolver {
|
||||||
override fun resolveClass(javaClass: JavaClass): ClassDescriptor? = descriptorResolverByJavaClass(javaClass).resolveClass(javaClass)
|
override fun resolveClass(javaClass: JavaClass): ClassDescriptor? = descriptorResolverByJavaClass(javaClass).resolveClass(javaClass)
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -20,5 +20,5 @@ import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
|||||||
|
|
||||||
|
|
||||||
// Currently getter is null iff it's loaded from Java field
|
// Currently getter is null iff it's loaded from Java field
|
||||||
public val PropertyDescriptor.isJavaField: Boolean
|
val PropertyDescriptor.isJavaField: Boolean
|
||||||
get() = getter == null
|
get() = getter == null
|
||||||
+9
-9
@@ -38,7 +38,7 @@ import org.jetbrains.kotlin.types.*
|
|||||||
import org.jetbrains.kotlin.utils.keysToMapExceptNulls
|
import org.jetbrains.kotlin.utils.keysToMapExceptNulls
|
||||||
|
|
||||||
fun LazyJavaResolverContext.resolveAnnotation(annotation: JavaAnnotation): LazyJavaAnnotationDescriptor? {
|
fun LazyJavaResolverContext.resolveAnnotation(annotation: JavaAnnotation): LazyJavaAnnotationDescriptor? {
|
||||||
val classId = annotation.getClassId()
|
val classId = annotation.classId
|
||||||
if (classId == null || isSpecialAnnotation(classId, false)) return null
|
if (classId == null || isSpecialAnnotation(classId, false)) return null
|
||||||
return LazyJavaAnnotationDescriptor(this, annotation)
|
return LazyJavaAnnotationDescriptor(this, annotation)
|
||||||
}
|
}
|
||||||
@@ -74,12 +74,12 @@ class LazyJavaAnnotationDescriptor(
|
|||||||
override fun getSource() = source
|
override fun getSource() = source
|
||||||
|
|
||||||
private fun computeValueArguments(): Map<ValueParameterDescriptor, ConstantValue<*>> {
|
private fun computeValueArguments(): Map<ValueParameterDescriptor, ConstantValue<*>> {
|
||||||
val constructors = getAnnotationClass().getConstructors()
|
val constructors = getAnnotationClass().constructors
|
||||||
if (constructors.isEmpty()) return mapOf()
|
if (constructors.isEmpty()) return mapOf()
|
||||||
|
|
||||||
val nameToArg = javaAnnotation.getArguments().toMapBy { it.name }
|
val nameToArg = javaAnnotation.arguments.toMapBy { it.name }
|
||||||
|
|
||||||
return constructors.first().getValueParameters().keysToMapExceptNulls { valueParameter ->
|
return constructors.first().valueParameters.keysToMapExceptNulls { valueParameter ->
|
||||||
var javaAnnotationArgument = nameToArg[valueParameter.getName()]
|
var javaAnnotationArgument = nameToArg[valueParameter.getName()]
|
||||||
if (javaAnnotationArgument == null && valueParameter.getName() == DEFAULT_ANNOTATION_MEMBER_NAME) {
|
if (javaAnnotationArgument == null && valueParameter.getName() == DEFAULT_ANNOTATION_MEMBER_NAME) {
|
||||||
javaAnnotationArgument = nameToArg[null]
|
javaAnnotationArgument = nameToArg[null]
|
||||||
@@ -89,7 +89,7 @@ class LazyJavaAnnotationDescriptor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getAnnotationClass() = getType().getConstructor().getDeclarationDescriptor() as ClassDescriptor
|
private fun getAnnotationClass() = getType().getConstructor().declarationDescriptor as ClassDescriptor
|
||||||
|
|
||||||
private fun resolveAnnotationArgument(argument: JavaAnnotationArgument?): ConstantValue<*>? {
|
private fun resolveAnnotationArgument(argument: JavaAnnotationArgument?): ConstantValue<*>? {
|
||||||
return when (argument) {
|
return when (argument) {
|
||||||
@@ -116,18 +116,18 @@ class LazyJavaAnnotationDescriptor(
|
|||||||
val values = elements.map {
|
val values = elements.map {
|
||||||
argument -> resolveAnnotationArgument(argument) ?: factory.createNullValue()
|
argument -> resolveAnnotationArgument(argument) ?: factory.createNullValue()
|
||||||
}
|
}
|
||||||
return factory.createArrayValue(values, valueParameter.getType())
|
return factory.createArrayValue(values, valueParameter.type)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun resolveFromEnumValue(element: JavaField?): ConstantValue<*>? {
|
private fun resolveFromEnumValue(element: JavaField?): ConstantValue<*>? {
|
||||||
if (element == null || !element.isEnumEntry()) return null
|
if (element == null || !element.isEnumEntry) return null
|
||||||
|
|
||||||
val containingJavaClass = element.getContainingClass()
|
val containingJavaClass = element.containingClass
|
||||||
|
|
||||||
//TODO: (module refactoring) moduleClassResolver should be used here
|
//TODO: (module refactoring) moduleClassResolver should be used here
|
||||||
val enumClass = c.javaClassResolver.resolveClass(containingJavaClass) ?: return null
|
val enumClass = c.javaClassResolver.resolveClass(containingJavaClass) ?: return null
|
||||||
|
|
||||||
val classifier = enumClass.getUnsubstitutedInnerClassesScope().getContributedClassifier(element.getName(), NoLookupLocation.FROM_JAVA_LOADER)
|
val classifier = enumClass.unsubstitutedInnerClassesScope.getContributedClassifier(element.name, NoLookupLocation.FROM_JAVA_LOADER)
|
||||||
if (classifier !is ClassDescriptor) return null
|
if (classifier !is ClassDescriptor) return null
|
||||||
|
|
||||||
return factory.createEnumValue(classifier)
|
return factory.createEnumValue(classifier)
|
||||||
|
|||||||
+7
-7
@@ -57,18 +57,18 @@ class LazyJavaClassDescriptor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private val kind = when {
|
private val kind = when {
|
||||||
jClass.isAnnotationType() -> ClassKind.ANNOTATION_CLASS
|
jClass.isAnnotationType -> ClassKind.ANNOTATION_CLASS
|
||||||
jClass.isInterface() -> ClassKind.INTERFACE
|
jClass.isInterface -> ClassKind.INTERFACE
|
||||||
jClass.isEnum() -> ClassKind.ENUM_CLASS
|
jClass.isEnum -> ClassKind.ENUM_CLASS
|
||||||
else -> ClassKind.CLASS
|
else -> ClassKind.CLASS
|
||||||
}
|
}
|
||||||
|
|
||||||
private val modality = if (jClass.isAnnotationType())
|
private val modality = if (jClass.isAnnotationType)
|
||||||
Modality.FINAL
|
Modality.FINAL
|
||||||
else Modality.convertFromFlags(jClass.isAbstract() || jClass.isInterface(), !jClass.isFinal())
|
else Modality.convertFromFlags(jClass.isAbstract || jClass.isInterface, !jClass.isFinal)
|
||||||
|
|
||||||
private val visibility = jClass.getVisibility()
|
private val visibility = jClass.visibility
|
||||||
private val isInner = jClass.getOuterClass() != null && !jClass.isStatic()
|
private val isInner = jClass.outerClass != null && !jClass.isStatic
|
||||||
|
|
||||||
override fun getKind() = kind
|
override fun getKind() = kind
|
||||||
override fun getModality() = modality
|
override fun getModality() = modality
|
||||||
|
|||||||
+16
-16
@@ -60,14 +60,14 @@ import org.jetbrains.kotlin.utils.addToStdlib.check
|
|||||||
import org.jetbrains.kotlin.utils.addToStdlib.firstNotNullResult
|
import org.jetbrains.kotlin.utils.addToStdlib.firstNotNullResult
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
public class LazyJavaClassMemberScope(
|
class LazyJavaClassMemberScope(
|
||||||
c: LazyJavaResolverContext,
|
c: LazyJavaResolverContext,
|
||||||
override val ownerDescriptor: ClassDescriptor,
|
override val ownerDescriptor: ClassDescriptor,
|
||||||
private val jClass: JavaClass
|
private val jClass: JavaClass
|
||||||
) : LazyJavaScope(c) {
|
) : LazyJavaScope(c) {
|
||||||
|
|
||||||
override fun computeMemberIndex(): MemberIndex {
|
override fun computeMemberIndex(): MemberIndex {
|
||||||
return object : ClassMemberIndex(jClass, { !it.isStatic() }) {
|
return object : ClassMemberIndex(jClass, { !it.isStatic }) {
|
||||||
// For SAM-constructors
|
// For SAM-constructors
|
||||||
override fun getMethodNames(nameFilter: (Name) -> Boolean): Collection<Name>
|
override fun getMethodNames(nameFilter: (Name) -> Boolean): Collection<Name>
|
||||||
= super.getMethodNames(nameFilter) + getClassNames(DescriptorKindFilter.CLASSIFIERS, nameFilter)
|
= super.getMethodNames(nameFilter) + getClassNames(DescriptorKindFilter.CLASSIFIERS, nameFilter)
|
||||||
@@ -341,7 +341,7 @@ public class LazyJavaClassMemberScope(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun computeNonDeclaredProperties(name: Name, result: MutableCollection<PropertyDescriptor>) {
|
override fun computeNonDeclaredProperties(name: Name, result: MutableCollection<PropertyDescriptor>) {
|
||||||
if (jClass.isAnnotationType()) {
|
if (jClass.isAnnotationType) {
|
||||||
computeAnnotationProperties(name, result)
|
computeAnnotationProperties(name, result)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -506,13 +506,13 @@ public class LazyJavaClassMemberScope(
|
|||||||
classDescriptor, c.resolveAnnotations(constructor), /* isPrimary = */ false, c.components.sourceElementFactory.source(constructor)
|
classDescriptor, c.resolveAnnotations(constructor), /* isPrimary = */ false, c.components.sourceElementFactory.source(constructor)
|
||||||
)
|
)
|
||||||
|
|
||||||
val valueParameters = resolveValueParameters(c, constructorDescriptor, constructor.getValueParameters())
|
val valueParameters = resolveValueParameters(c, constructorDescriptor, constructor.valueParameters)
|
||||||
|
|
||||||
constructorDescriptor.initialize(valueParameters.descriptors, constructor.visibility)
|
constructorDescriptor.initialize(valueParameters.descriptors, constructor.visibility)
|
||||||
constructorDescriptor.setHasStableParameterNames(false)
|
constructorDescriptor.setHasStableParameterNames(false)
|
||||||
constructorDescriptor.setHasSynthesizedParameterNames(valueParameters.hasSynthesizedNames)
|
constructorDescriptor.setHasSynthesizedParameterNames(valueParameters.hasSynthesizedNames)
|
||||||
|
|
||||||
constructorDescriptor.setReturnType(classDescriptor.getDefaultType())
|
constructorDescriptor.returnType = classDescriptor.defaultType
|
||||||
|
|
||||||
c.components.javaResolverCache.recordConstructor(constructor, constructorDescriptor)
|
c.components.javaResolverCache.recordConstructor(constructor, constructorDescriptor)
|
||||||
|
|
||||||
@@ -520,8 +520,8 @@ public class LazyJavaClassMemberScope(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun createDefaultConstructor(): ConstructorDescriptor? {
|
private fun createDefaultConstructor(): ConstructorDescriptor? {
|
||||||
val isAnnotation: Boolean = jClass.isAnnotationType()
|
val isAnnotation: Boolean = jClass.isAnnotationType
|
||||||
if (jClass.isInterface() && !isAnnotation)
|
if (jClass.isInterface && !isAnnotation)
|
||||||
return null
|
return null
|
||||||
|
|
||||||
val classDescriptor = ownerDescriptor
|
val classDescriptor = ownerDescriptor
|
||||||
@@ -534,13 +534,13 @@ public class LazyJavaClassMemberScope(
|
|||||||
|
|
||||||
constructorDescriptor.initialize(valueParameters, getConstructorVisibility(classDescriptor))
|
constructorDescriptor.initialize(valueParameters, getConstructorVisibility(classDescriptor))
|
||||||
constructorDescriptor.setHasStableParameterNames(true)
|
constructorDescriptor.setHasStableParameterNames(true)
|
||||||
constructorDescriptor.setReturnType(classDescriptor.getDefaultType())
|
constructorDescriptor.returnType = classDescriptor.defaultType
|
||||||
c.components.javaResolverCache.recordConstructor(jClass, constructorDescriptor);
|
c.components.javaResolverCache.recordConstructor(jClass, constructorDescriptor);
|
||||||
return constructorDescriptor
|
return constructorDescriptor
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getConstructorVisibility(classDescriptor: ClassDescriptor): Visibility {
|
private fun getConstructorVisibility(classDescriptor: ClassDescriptor): Visibility {
|
||||||
val visibility = classDescriptor.getVisibility()
|
val visibility = classDescriptor.visibility
|
||||||
if (visibility == JavaVisibilities.PROTECTED_STATIC_VISIBILITY) {
|
if (visibility == JavaVisibilities.PROTECTED_STATIC_VISIBILITY) {
|
||||||
return JavaVisibilities.PROTECTED_AND_PACKAGE
|
return JavaVisibilities.PROTECTED_AND_PACKAGE
|
||||||
}
|
}
|
||||||
@@ -548,22 +548,22 @@ public class LazyJavaClassMemberScope(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun createAnnotationConstructorParameters(constructor: ConstructorDescriptorImpl): List<ValueParameterDescriptor> {
|
private fun createAnnotationConstructorParameters(constructor: ConstructorDescriptorImpl): List<ValueParameterDescriptor> {
|
||||||
val methods = jClass.getMethods()
|
val methods = jClass.methods
|
||||||
val result = ArrayList<ValueParameterDescriptor>(methods.size)
|
val result = ArrayList<ValueParameterDescriptor>(methods.size)
|
||||||
|
|
||||||
val attr = TypeUsage.MEMBER_SIGNATURE_INVARIANT.toAttributes(allowFlexible = false, isForAnnotationParameter = true)
|
val attr = TypeUsage.MEMBER_SIGNATURE_INVARIANT.toAttributes(allowFlexible = false, isForAnnotationParameter = true)
|
||||||
|
|
||||||
val (methodsNamedValue, otherMethods) = methods.
|
val (methodsNamedValue, otherMethods) = methods.
|
||||||
partition { it.getName() == JvmAnnotationNames.DEFAULT_ANNOTATION_MEMBER_NAME }
|
partition { it.name == JvmAnnotationNames.DEFAULT_ANNOTATION_MEMBER_NAME }
|
||||||
|
|
||||||
assert(methodsNamedValue.size <= 1) { "There can't be more than one method named 'value' in annotation class: $jClass" }
|
assert(methodsNamedValue.size <= 1) { "There can't be more than one method named 'value' in annotation class: $jClass" }
|
||||||
val methodNamedValue = methodsNamedValue.firstOrNull()
|
val methodNamedValue = methodsNamedValue.firstOrNull()
|
||||||
if (methodNamedValue != null) {
|
if (methodNamedValue != null) {
|
||||||
val parameterNamedValueJavaType = methodNamedValue.getReturnType()
|
val parameterNamedValueJavaType = methodNamedValue.returnType
|
||||||
val (parameterType, varargType) =
|
val (parameterType, varargType) =
|
||||||
if (parameterNamedValueJavaType is JavaArrayType)
|
if (parameterNamedValueJavaType is JavaArrayType)
|
||||||
Pair(c.typeResolver.transformArrayType(parameterNamedValueJavaType, attr, isVararg = true),
|
Pair(c.typeResolver.transformArrayType(parameterNamedValueJavaType, attr, isVararg = true),
|
||||||
c.typeResolver.transformJavaType(parameterNamedValueJavaType.getComponentType(), attr))
|
c.typeResolver.transformJavaType(parameterNamedValueJavaType.componentType, attr))
|
||||||
else
|
else
|
||||||
Pair(c.typeResolver.transformJavaType(parameterNamedValueJavaType, attr), null)
|
Pair(c.typeResolver.transformJavaType(parameterNamedValueJavaType, attr), null)
|
||||||
|
|
||||||
@@ -572,7 +572,7 @@ public class LazyJavaClassMemberScope(
|
|||||||
|
|
||||||
val startIndex = if (methodNamedValue != null) 1 else 0
|
val startIndex = if (methodNamedValue != null) 1 else 0
|
||||||
for ((index, method) in otherMethods.withIndex()) {
|
for ((index, method) in otherMethods.withIndex()) {
|
||||||
val parameterType = c.typeResolver.transformJavaType(method.getReturnType(), attr)
|
val parameterType = c.typeResolver.transformJavaType(method.returnType, attr)
|
||||||
result.addAnnotationValueParameter(constructor, index + startIndex, method, parameterType, null)
|
result.addAnnotationValueParameter(constructor, index + startIndex, method, parameterType, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -591,7 +591,7 @@ public class LazyJavaClassMemberScope(
|
|||||||
null,
|
null,
|
||||||
index,
|
index,
|
||||||
Annotations.EMPTY,
|
Annotations.EMPTY,
|
||||||
method.getName(),
|
method.name,
|
||||||
// Parameters of annotation constructors in Java are never nullable
|
// Parameters of annotation constructors in Java are never nullable
|
||||||
TypeUtils.makeNotNullable(returnType),
|
TypeUtils.makeNotNullable(returnType),
|
||||||
method.hasAnnotationParameterDefaultValue(),
|
method.hasAnnotationParameterDefaultValue(),
|
||||||
@@ -654,5 +654,5 @@ public class LazyJavaClassMemberScope(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toString() = "Lazy java member scope for " + jClass.getFqName()
|
override fun toString() = "Lazy java member scope for " + jClass.fqName
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -32,7 +32,7 @@ import org.jetbrains.kotlin.name.SpecialNames
|
|||||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||||
import org.jetbrains.kotlin.storage.getValue
|
import org.jetbrains.kotlin.storage.getValue
|
||||||
|
|
||||||
public class LazyJavaPackageScope(
|
class LazyJavaPackageScope(
|
||||||
c: LazyJavaResolverContext,
|
c: LazyJavaResolverContext,
|
||||||
private val jPackage: JavaPackage,
|
private val jPackage: JavaPackage,
|
||||||
override val ownerDescriptor: LazyJavaPackageFragment
|
override val ownerDescriptor: LazyJavaPackageFragment
|
||||||
@@ -58,7 +58,7 @@ public class LazyJavaPackageScope(
|
|||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun getFacadeSimpleNameForPartSimpleName(partName: String): String? =
|
fun getFacadeSimpleNameForPartSimpleName(partName: String): String? =
|
||||||
partToFacade()[partName]
|
partToFacade()[partName]
|
||||||
|
|
||||||
private val deserializedPackageScope by c.storageManager.createLazyValue {
|
private val deserializedPackageScope by c.storageManager.createLazyValue {
|
||||||
|
|||||||
+16
-16
@@ -49,7 +49,7 @@ import org.jetbrains.kotlin.utils.addIfNotNull
|
|||||||
import org.jetbrains.kotlin.utils.toReadOnlyList
|
import org.jetbrains.kotlin.utils.toReadOnlyList
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
public abstract class LazyJavaScope(protected val c: LazyJavaResolverContext) : MemberScopeImpl() {
|
abstract class LazyJavaScope(protected val c: LazyJavaResolverContext) : MemberScopeImpl() {
|
||||||
protected abstract val ownerDescriptor: DeclarationDescriptor
|
protected abstract val ownerDescriptor: DeclarationDescriptor
|
||||||
|
|
||||||
// this lazy value is not used at all in LazyPackageFragmentScopeForJavaPackage because we do not use caching there
|
// this lazy value is not used at all in LazyPackageFragmentScopeForJavaPackage because we do not use caching there
|
||||||
@@ -118,8 +118,8 @@ public abstract class LazyJavaScope(protected val c: LazyJavaResolverContext) :
|
|||||||
|
|
||||||
val c = c.child(functionDescriptorImpl, method)
|
val c = c.child(functionDescriptorImpl, method)
|
||||||
|
|
||||||
val methodTypeParameters = method.getTypeParameters().map { p -> c.typeParameterResolver.resolveTypeParameter(p)!! }
|
val methodTypeParameters = method.typeParameters.map { p -> c.typeParameterResolver.resolveTypeParameter(p)!! }
|
||||||
val valueParameters = resolveValueParameters(c, functionDescriptorImpl, method.getValueParameters())
|
val valueParameters = resolveValueParameters(c, functionDescriptorImpl, method.valueParameters)
|
||||||
|
|
||||||
val returnType = computeMethodReturnType(method, annotations, c)
|
val returnType = computeMethodReturnType(method, annotations, c)
|
||||||
|
|
||||||
@@ -131,8 +131,8 @@ public abstract class LazyJavaScope(protected val c: LazyJavaResolverContext) :
|
|||||||
effectiveSignature.typeParameters,
|
effectiveSignature.typeParameters,
|
||||||
effectiveSignature.valueParameters,
|
effectiveSignature.valueParameters,
|
||||||
effectiveSignature.returnType,
|
effectiveSignature.returnType,
|
||||||
Modality.convertFromFlags(method.isAbstract(), !method.isFinal()),
|
Modality.convertFromFlags(method.isAbstract, !method.isFinal),
|
||||||
method.getVisibility()
|
method.visibility
|
||||||
)
|
)
|
||||||
|
|
||||||
functionDescriptorImpl.setParameterNamesStatus(effectiveSignature.hasStableParameterNames, valueParameters.hasSynthesizedNames)
|
functionDescriptorImpl.setParameterNamesStatus(effectiveSignature.hasStableParameterNames, valueParameters.hasSynthesizedNames)
|
||||||
@@ -145,13 +145,13 @@ public abstract class LazyJavaScope(protected val c: LazyJavaResolverContext) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected fun computeMethodReturnType(method: JavaMethod, annotations: Annotations, c: LazyJavaResolverContext): KotlinType {
|
protected fun computeMethodReturnType(method: JavaMethod, annotations: Annotations, c: LazyJavaResolverContext): KotlinType {
|
||||||
val annotationMethod = method.getContainingClass().isAnnotationType()
|
val annotationMethod = method.containingClass.isAnnotationType
|
||||||
val returnTypeAttrs = LazyJavaTypeAttributes(
|
val returnTypeAttrs = LazyJavaTypeAttributes(
|
||||||
TypeUsage.MEMBER_SIGNATURE_COVARIANT, annotations,
|
TypeUsage.MEMBER_SIGNATURE_COVARIANT, annotations,
|
||||||
allowFlexible = !annotationMethod,
|
allowFlexible = !annotationMethod,
|
||||||
isForAnnotationParameter = annotationMethod
|
isForAnnotationParameter = annotationMethod
|
||||||
)
|
)
|
||||||
return c.typeResolver.transformJavaType(method.getReturnType(), returnTypeAttrs).let {
|
return c.typeResolver.transformJavaType(method.returnType, returnTypeAttrs).let {
|
||||||
// Annotation arguments are never null in Java
|
// Annotation arguments are never null in Java
|
||||||
if (annotationMethod) TypeUtils.makeNotNullable(it) else it
|
if (annotationMethod) TypeUtils.makeNotNullable(it) else it
|
||||||
}
|
}
|
||||||
@@ -171,17 +171,17 @@ public abstract class LazyJavaScope(protected val c: LazyJavaResolverContext) :
|
|||||||
val annotations = c.resolveAnnotations(javaParameter)
|
val annotations = c.resolveAnnotations(javaParameter)
|
||||||
val typeUsage = LazyJavaTypeAttributes(TypeUsage.MEMBER_SIGNATURE_CONTRAVARIANT, annotations)
|
val typeUsage = LazyJavaTypeAttributes(TypeUsage.MEMBER_SIGNATURE_CONTRAVARIANT, annotations)
|
||||||
val (outType, varargElementType) =
|
val (outType, varargElementType) =
|
||||||
if (javaParameter.isVararg()) {
|
if (javaParameter.isVararg) {
|
||||||
val paramType = javaParameter.getType() as? JavaArrayType
|
val paramType = javaParameter.type as? JavaArrayType
|
||||||
?: throw AssertionError("Vararg parameter should be an array: $javaParameter")
|
?: throw AssertionError("Vararg parameter should be an array: $javaParameter")
|
||||||
val outType = c.typeResolver.transformArrayType(paramType, typeUsage, true)
|
val outType = c.typeResolver.transformArrayType(paramType, typeUsage, true)
|
||||||
outType to c.module.builtIns.getArrayElementType(outType)
|
outType to c.module.builtIns.getArrayElementType(outType)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
c.typeResolver.transformJavaType(javaParameter.getType(), typeUsage) to null
|
c.typeResolver.transformJavaType(javaParameter.type, typeUsage) to null
|
||||||
}
|
}
|
||||||
|
|
||||||
val name = if (function.getName().asString() == "equals" &&
|
val name = if (function.name.asString() == "equals" &&
|
||||||
jValueParameters.size == 1 &&
|
jValueParameters.size == 1 &&
|
||||||
c.module.builtIns.getNullableAnyType() == outType) {
|
c.module.builtIns.getNullableAnyType() == outType) {
|
||||||
// This is a hack to prevent numerous warnings on Kotlin classes that inherit Java classes: if you override "equals" in such
|
// This is a hack to prevent numerous warnings on Kotlin classes that inherit Java classes: if you override "equals" in such
|
||||||
@@ -192,7 +192,7 @@ public abstract class LazyJavaScope(protected val c: LazyJavaResolverContext) :
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// TODO: parameter names may be drawn from attached sources, which is slow; it's better to make them lazy
|
// TODO: parameter names may be drawn from attached sources, which is slow; it's better to make them lazy
|
||||||
val javaName = javaParameter.getName()
|
val javaName = javaParameter.name
|
||||||
if (javaName == null) synthesizedNames = true
|
if (javaName == null) synthesizedNames = true
|
||||||
javaName ?: Name.identifier("p$index")
|
javaName ?: Name.identifier("p$index")
|
||||||
}
|
}
|
||||||
@@ -264,10 +264,10 @@ public abstract class LazyJavaScope(protected val c: LazyJavaResolverContext) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun createPropertyDescriptor(field: JavaField): PropertyDescriptorImpl {
|
private fun createPropertyDescriptor(field: JavaField): PropertyDescriptorImpl {
|
||||||
val isVar = !field.isFinal()
|
val isVar = !field.isFinal
|
||||||
val visibility = field.getVisibility()
|
val visibility = field.visibility
|
||||||
val annotations = c.resolveAnnotations(field)
|
val annotations = c.resolveAnnotations(field)
|
||||||
val propertyName = field.getName()
|
val propertyName = field.name
|
||||||
|
|
||||||
return JavaPropertyDescriptor(ownerDescriptor, annotations, Modality.FINAL, visibility, isVar, propertyName,
|
return JavaPropertyDescriptor(ownerDescriptor, annotations, Modality.FINAL, visibility, isVar, propertyName,
|
||||||
c.components.sourceElementFactory.source(field), /* original = */ null, /*isConst= */ field.isFinalStatic)
|
c.components.sourceElementFactory.source(field), /* original = */ null, /*isConst= */ field.isFinalStatic)
|
||||||
@@ -347,7 +347,7 @@ public abstract class LazyJavaScope(protected val c: LazyJavaResolverContext) :
|
|||||||
override fun toString() = "Lazy scope for ${ownerDescriptor}"
|
override fun toString() = "Lazy scope for ${ownerDescriptor}"
|
||||||
|
|
||||||
override fun printScopeStructure(p: Printer) {
|
override fun printScopeStructure(p: Printer) {
|
||||||
p.println(javaClass.getSimpleName(), " {")
|
p.println(javaClass.simpleName, " {")
|
||||||
p.pushIndent()
|
p.pushIndent()
|
||||||
|
|
||||||
p.println("containingDeclaration: ${ownerDescriptor}")
|
p.println("containingDeclaration: ${ownerDescriptor}")
|
||||||
|
|||||||
+4
-4
@@ -33,20 +33,20 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils
|
|||||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
|
|
||||||
public class LazyJavaStaticClassScope(
|
class LazyJavaStaticClassScope(
|
||||||
c: LazyJavaResolverContext,
|
c: LazyJavaResolverContext,
|
||||||
private val jClass: JavaClass,
|
private val jClass: JavaClass,
|
||||||
override val ownerDescriptor: LazyJavaClassDescriptor
|
override val ownerDescriptor: LazyJavaClassDescriptor
|
||||||
) : LazyJavaStaticScope(c) {
|
) : LazyJavaStaticScope(c) {
|
||||||
|
|
||||||
override fun computeMemberIndex(): MemberIndex {
|
override fun computeMemberIndex(): MemberIndex {
|
||||||
val delegate = ClassMemberIndex(jClass) { it.isStatic() }
|
val delegate = ClassMemberIndex(jClass) { it.isStatic }
|
||||||
return object : MemberIndex by delegate {
|
return object : MemberIndex by delegate {
|
||||||
override fun getMethodNames(nameFilter: (Name) -> Boolean): Collection<Name> {
|
override fun getMethodNames(nameFilter: (Name) -> Boolean): Collection<Name> {
|
||||||
// Should be a super call, but KT-2860
|
// Should be a super call, but KT-2860
|
||||||
return delegate.getMethodNames(nameFilter) +
|
return delegate.getMethodNames(nameFilter) +
|
||||||
// For SAM-constructors
|
// For SAM-constructors
|
||||||
jClass.getInnerClasses().map { it.getName() }
|
jClass.innerClasses.map { it.name }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -78,7 +78,7 @@ public class LazyJavaStaticClassScope(
|
|||||||
val functionsFromSupertypes = getStaticFunctionsFromJavaSuperClasses(name, ownerDescriptor)
|
val functionsFromSupertypes = getStaticFunctionsFromJavaSuperClasses(name, ownerDescriptor)
|
||||||
result.addAll(DescriptorResolverUtils.resolveOverrides(name, functionsFromSupertypes, result, ownerDescriptor, c.components.errorReporter))
|
result.addAll(DescriptorResolverUtils.resolveOverrides(name, functionsFromSupertypes, result, ownerDescriptor, c.components.errorReporter))
|
||||||
|
|
||||||
if (jClass.isEnum()) {
|
if (jClass.isEnum) {
|
||||||
when (name) {
|
when (name) {
|
||||||
DescriptorUtils.ENUM_VALUE_OF -> result.add(createEnumValueOfMethod(ownerDescriptor))
|
DescriptorUtils.ENUM_VALUE_OF -> result.add(createEnumValueOfMethod(ownerDescriptor))
|
||||||
DescriptorUtils.ENUM_VALUES -> result.add(createEnumValuesMethod(ownerDescriptor))
|
DescriptorUtils.ENUM_VALUES -> result.add(createEnumValuesMethod(ownerDescriptor))
|
||||||
|
|||||||
+1
-1
@@ -25,7 +25,7 @@ import org.jetbrains.kotlin.name.FqName
|
|||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
|
|
||||||
public abstract class LazyJavaStaticScope(c: LazyJavaResolverContext) : LazyJavaScope(c) {
|
abstract class LazyJavaStaticScope(c: LazyJavaResolverContext) : LazyJavaScope(c) {
|
||||||
|
|
||||||
override fun getDispatchReceiverParameter() = null
|
override fun getDispatchReceiverParameter() = null
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -29,7 +29,7 @@ import org.jetbrains.kotlin.types.Variance
|
|||||||
|
|
||||||
class LazyJavaTypeParameterDescriptor(
|
class LazyJavaTypeParameterDescriptor(
|
||||||
private val c: LazyJavaResolverContext,
|
private val c: LazyJavaResolverContext,
|
||||||
public val javaTypeParameter: JavaTypeParameter,
|
val javaTypeParameter: JavaTypeParameter,
|
||||||
index: Int,
|
index: Int,
|
||||||
containingDeclaration: DeclarationDescriptor
|
containingDeclaration: DeclarationDescriptor
|
||||||
) : AbstractLazyTypeParameterDescriptor(
|
) : AbstractLazyTypeParameterDescriptor(
|
||||||
|
|||||||
+3
-3
@@ -81,12 +81,12 @@ private fun <M : JavaMember> JavaClass.getAllMemberNames(filter: (M) -> Boolean,
|
|||||||
|
|
||||||
for (member in getMembers()) {
|
for (member in getMembers()) {
|
||||||
if (filter(member)) {
|
if (filter(member)) {
|
||||||
result.add(member.getName())
|
result.add(member.name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (supertype in getSupertypes()) {
|
for (supertype in supertypes) {
|
||||||
val classifier = supertype.getClassifier()
|
val classifier = supertype.classifier
|
||||||
if (classifier is JavaClass) {
|
if (classifier is JavaClass) {
|
||||||
result.addAll(classifier.getNonDeclaredMethodNames())
|
result.addAll(classifier.getNonDeclaredMethodNames())
|
||||||
classifier.visit()
|
classifier.visit()
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ class LazyJavaTypeParameterResolver(
|
|||||||
private val containingDeclaration: DeclarationDescriptor,
|
private val containingDeclaration: DeclarationDescriptor,
|
||||||
typeParameterOwner: JavaTypeParameterListOwner
|
typeParameterOwner: JavaTypeParameterListOwner
|
||||||
) : TypeParameterResolver {
|
) : TypeParameterResolver {
|
||||||
private val typeParameters: Map<JavaTypeParameter, Int> = typeParameterOwner.getTypeParameters().mapToIndex()
|
private val typeParameters: Map<JavaTypeParameter, Int> = typeParameterOwner.typeParameters.mapToIndex()
|
||||||
|
|
||||||
private val resolve = c.storageManager.createMemoizedFunctionWithNullableValues {
|
private val resolve = c.storageManager.createMemoizedFunctionWithNullableValues {
|
||||||
typeParameter: JavaTypeParameter ->
|
typeParameter: JavaTypeParameter ->
|
||||||
|
|||||||
+20
-20
@@ -45,10 +45,10 @@ class LazyJavaTypeResolver(
|
|||||||
private val typeParameterResolver: TypeParameterResolver
|
private val typeParameterResolver: TypeParameterResolver
|
||||||
) {
|
) {
|
||||||
|
|
||||||
public fun transformJavaType(javaType: JavaType, attr: JavaTypeAttributes): KotlinType {
|
fun transformJavaType(javaType: JavaType, attr: JavaTypeAttributes): KotlinType {
|
||||||
return when (javaType) {
|
return when (javaType) {
|
||||||
is JavaPrimitiveType -> {
|
is JavaPrimitiveType -> {
|
||||||
val primitiveType = javaType.getType()
|
val primitiveType = javaType.type
|
||||||
if (primitiveType != null) c.module.builtIns.getPrimitiveKotlinType(primitiveType)
|
if (primitiveType != null) c.module.builtIns.getPrimitiveKotlinType(primitiveType)
|
||||||
else c.module.builtIns.getUnitType()
|
else c.module.builtIns.getUnitType()
|
||||||
}
|
}
|
||||||
@@ -64,10 +64,10 @@ class LazyJavaTypeResolver(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun transformArrayType(arrayType: JavaArrayType, attr: JavaTypeAttributes, isVararg: Boolean = false): KotlinType {
|
fun transformArrayType(arrayType: JavaArrayType, attr: JavaTypeAttributes, isVararg: Boolean = false): KotlinType {
|
||||||
return run {
|
return run {
|
||||||
val javaComponentType = arrayType.getComponentType()
|
val javaComponentType = arrayType.componentType
|
||||||
val primitiveType = (javaComponentType as? JavaPrimitiveType)?.getType()
|
val primitiveType = (javaComponentType as? JavaPrimitiveType)?.type
|
||||||
if (primitiveType != null) {
|
if (primitiveType != null) {
|
||||||
val jetType = c.module.builtIns.getPrimitiveArrayKotlinType(primitiveType)
|
val jetType = c.module.builtIns.getPrimitiveArrayKotlinType(primitiveType)
|
||||||
return@run if (attr.allowFlexible)
|
return@run if (attr.allowFlexible)
|
||||||
@@ -101,7 +101,7 @@ class LazyJavaTypeResolver(
|
|||||||
override fun computeTypeConstructor(): TypeConstructor {
|
override fun computeTypeConstructor(): TypeConstructor {
|
||||||
val classifier = classifier()
|
val classifier = classifier()
|
||||||
if (classifier == null) {
|
if (classifier == null) {
|
||||||
return ErrorUtils.createErrorTypeConstructor("Unresolved java classifier: " + javaType.getPresentableText())
|
return ErrorUtils.createErrorTypeConstructor("Unresolved java classifier: " + javaType.presentableText)
|
||||||
}
|
}
|
||||||
return when (classifier) {
|
return when (classifier) {
|
||||||
is JavaClass -> {
|
is JavaClass -> {
|
||||||
@@ -109,16 +109,16 @@ class LazyJavaTypeResolver(
|
|||||||
|
|
||||||
val classData = mapKotlinClass(fqName) ?: c.components.moduleClassResolver.resolveClass(classifier)
|
val classData = mapKotlinClass(fqName) ?: c.components.moduleClassResolver.resolveClass(classifier)
|
||||||
|
|
||||||
classData?.getTypeConstructor()
|
classData?.typeConstructor
|
||||||
?: ErrorUtils.createErrorTypeConstructor("Unresolved java classifier: " + javaType.getPresentableText())
|
?: ErrorUtils.createErrorTypeConstructor("Unresolved java classifier: " + javaType.presentableText)
|
||||||
}
|
}
|
||||||
is JavaTypeParameter -> {
|
is JavaTypeParameter -> {
|
||||||
if (isConstructorTypeParameter()) {
|
if (isConstructorTypeParameter()) {
|
||||||
getConstructorTypeParameterSubstitute().getConstructor()
|
getConstructorTypeParameterSubstitute().getConstructor()
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
typeParameterResolver.resolveTypeParameter(classifier)?.getTypeConstructor()
|
typeParameterResolver.resolveTypeParameter(classifier)?.typeConstructor
|
||||||
?: ErrorUtils.createErrorTypeConstructor("Unresolved Java type parameter: " + javaType.getPresentableText())
|
?: ErrorUtils.createErrorTypeConstructor("Unresolved Java type parameter: " + javaType.presentableText)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else -> throw IllegalStateException("Unknown classifier kind: $classifier")
|
else -> throw IllegalStateException("Unknown classifier kind: $classifier")
|
||||||
@@ -174,18 +174,18 @@ class LazyJavaTypeResolver(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun isRaw(): Boolean {
|
private fun isRaw(): Boolean {
|
||||||
if (javaType.isRaw()) return true
|
if (javaType.isRaw) return true
|
||||||
|
|
||||||
// This option is needed because sometimes we get weird versions of JDK classes in the class path,
|
// This option is needed because sometimes we get weird versions of JDK classes in the class path,
|
||||||
// such as collections with no generics, so the Java types are not raw, formally, but they don't match with
|
// such as collections with no generics, so the Java types are not raw, formally, but they don't match with
|
||||||
// their Kotlin analogs, so we treat them as raw to avoid exceptions
|
// their Kotlin analogs, so we treat them as raw to avoid exceptions
|
||||||
// No type arguments, but some are expected => raw
|
// No type arguments, but some are expected => raw
|
||||||
return javaType.getTypeArguments().isEmpty() && !getConstructor().getParameters().isEmpty()
|
return javaType.typeArguments.isEmpty() && !getConstructor().parameters.isEmpty()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun computeArguments(): List<TypeProjection> {
|
override fun computeArguments(): List<TypeProjection> {
|
||||||
val typeConstructor = getConstructor()
|
val typeConstructor = getConstructor()
|
||||||
val typeParameters = typeConstructor.getParameters()
|
val typeParameters = typeConstructor.parameters
|
||||||
if (isRaw()) {
|
if (isRaw()) {
|
||||||
return typeParameters.map {
|
return typeParameters.map {
|
||||||
parameter ->
|
parameter ->
|
||||||
@@ -213,12 +213,12 @@ class LazyJavaTypeResolver(
|
|||||||
return getConstructorTypeParameterSubstitute().getArguments()
|
return getConstructorTypeParameterSubstitute().getArguments()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeParameters.size != javaType.getTypeArguments().size) {
|
if (typeParameters.size != javaType.typeArguments.size) {
|
||||||
// Most of the time this means there is an error in the Java code
|
// Most of the time this means there is an error in the Java code
|
||||||
return typeParameters.map { p -> TypeProjectionImpl(ErrorUtils.createErrorType(p.getName().asString())) }
|
return typeParameters.map { p -> TypeProjectionImpl(ErrorUtils.createErrorType(p.name.asString())) }
|
||||||
}
|
}
|
||||||
var howTheProjectionIsUsed = if (attr.howThisTypeIsUsed == SUPERTYPE) SUPERTYPE_ARGUMENT else TYPE_ARGUMENT
|
var howTheProjectionIsUsed = if (attr.howThisTypeIsUsed == SUPERTYPE) SUPERTYPE_ARGUMENT else TYPE_ARGUMENT
|
||||||
return javaType.getTypeArguments().withIndex().map {
|
return javaType.typeArguments.withIndex().map {
|
||||||
javaTypeParameter ->
|
javaTypeParameter ->
|
||||||
val (i, t) = javaTypeParameter
|
val (i, t) = javaTypeParameter
|
||||||
val parameter = if (i >= typeParameters.size)
|
val parameter = if (i >= typeParameters.size)
|
||||||
@@ -235,7 +235,7 @@ class LazyJavaTypeResolver(
|
|||||||
): TypeProjection {
|
): TypeProjection {
|
||||||
return when (javaType) {
|
return when (javaType) {
|
||||||
is JavaWildcardType -> {
|
is JavaWildcardType -> {
|
||||||
val bound = javaType.getBound()
|
val bound = javaType.bound
|
||||||
if (bound == null)
|
if (bound == null)
|
||||||
makeStarProjection(typeParameter, attr)
|
makeStarProjection(typeParameter, attr)
|
||||||
else {
|
else {
|
||||||
@@ -278,7 +278,7 @@ class LazyJavaTypeResolver(
|
|||||||
override fun getAnnotations() = annotations
|
override fun getAnnotations() = annotations
|
||||||
}
|
}
|
||||||
|
|
||||||
public object FlexibleJavaClassifierTypeCapabilities : FlexibleTypeCapabilities {
|
object FlexibleJavaClassifierTypeCapabilities : FlexibleTypeCapabilities {
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun create(lowerBound: KotlinType, upperBound: KotlinType) = DelegatingFlexibleType.create(lowerBound, upperBound, this)
|
fun create(lowerBound: KotlinType, upperBound: KotlinType) = DelegatingFlexibleType.create(lowerBound, upperBound, this)
|
||||||
|
|
||||||
@@ -380,8 +380,8 @@ class LazyJavaTypeAttributes(
|
|||||||
private fun hasAnnotation(fqName: FqName) = typeAnnotations.findAnnotation(fqName) != null
|
private fun hasAnnotation(fqName: FqName) = typeAnnotations.findAnnotation(fqName) != null
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun Annotations.isMarkedNotNull() = findAnnotation(JETBRAINS_NOT_NULL_ANNOTATION) != null
|
fun Annotations.isMarkedNotNull() = findAnnotation(JETBRAINS_NOT_NULL_ANNOTATION) != null
|
||||||
public fun Annotations.isMarkedNullable() = findAnnotation(JETBRAINS_NULLABLE_ANNOTATION) != null
|
fun Annotations.isMarkedNullable() = findAnnotation(JETBRAINS_NULLABLE_ANNOTATION) != null
|
||||||
|
|
||||||
fun TypeUsage.toAttributes(
|
fun TypeUsage.toAttributes(
|
||||||
allowFlexible: Boolean = true,
|
allowFlexible: Boolean = true,
|
||||||
|
|||||||
+3
-3
@@ -24,9 +24,9 @@ import org.jetbrains.kotlin.renderer.CustomFlexibleRendering
|
|||||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||||
import org.jetbrains.kotlin.types.*
|
import org.jetbrains.kotlin.types.*
|
||||||
|
|
||||||
public object RawTypeTag : TypeCapability
|
object RawTypeTag : TypeCapability
|
||||||
|
|
||||||
public object RawTypeCapabilities : TypeCapabilities {
|
object RawTypeCapabilities : TypeCapabilities {
|
||||||
private object RawSubstitutionCapability : CustomSubstitutionCapability {
|
private object RawSubstitutionCapability : CustomSubstitutionCapability {
|
||||||
override val substitution: TypeSubstitution?
|
override val substitution: TypeSubstitution?
|
||||||
get() = RawSubstitution
|
get() = RawSubstitution
|
||||||
@@ -89,7 +89,7 @@ internal object RawSubstitution : TypeSubstitution() {
|
|||||||
private val lowerTypeAttr = TypeUsage.MEMBER_SIGNATURE_INVARIANT.toAttributes().toFlexible(JavaTypeFlexibility.FLEXIBLE_LOWER_BOUND)
|
private val lowerTypeAttr = TypeUsage.MEMBER_SIGNATURE_INVARIANT.toAttributes().toFlexible(JavaTypeFlexibility.FLEXIBLE_LOWER_BOUND)
|
||||||
private val upperTypeAttr = TypeUsage.MEMBER_SIGNATURE_INVARIANT.toAttributes().toFlexible(JavaTypeFlexibility.FLEXIBLE_UPPER_BOUND)
|
private val upperTypeAttr = TypeUsage.MEMBER_SIGNATURE_INVARIANT.toAttributes().toFlexible(JavaTypeFlexibility.FLEXIBLE_UPPER_BOUND)
|
||||||
|
|
||||||
public fun eraseType(type: KotlinType): KotlinType {
|
fun eraseType(type: KotlinType): KotlinType {
|
||||||
val declaration = type.constructor.declarationDescriptor
|
val declaration = type.constructor.declarationDescriptor
|
||||||
return when (declaration) {
|
return when (declaration) {
|
||||||
is TypeParameterDescriptor -> eraseType(declaration.getErasedUpperBound())
|
is TypeParameterDescriptor -> eraseType(declaration.getErasedUpperBound())
|
||||||
|
|||||||
+2
-2
@@ -32,8 +32,8 @@ fun propertyNamesBySetMethodName(methodName: Name)
|
|||||||
= listOf(propertyNameBySetMethodName(methodName, false), propertyNameBySetMethodName(methodName, true)).filterNotNull()
|
= listOf(propertyNameBySetMethodName(methodName, false), propertyNameBySetMethodName(methodName, true)).filterNotNull()
|
||||||
|
|
||||||
private fun propertyNameFromAccessorMethodName(methodName: Name, prefix: String, removePrefix: Boolean = true, addPrefix: String? = null): Name? {
|
private fun propertyNameFromAccessorMethodName(methodName: Name, prefix: String, removePrefix: Boolean = true, addPrefix: String? = null): Name? {
|
||||||
if (methodName.isSpecial()) return null
|
if (methodName.isSpecial) return null
|
||||||
val identifier = methodName.getIdentifier()
|
val identifier = methodName.identifier
|
||||||
if (!identifier.startsWith(prefix)) return null
|
if (!identifier.startsWith(prefix)) return null
|
||||||
if (identifier.length == prefix.length) return null
|
if (identifier.length == prefix.length) return null
|
||||||
if (identifier[prefix.length] in 'a'..'z') return null
|
if (identifier[prefix.length] in 'a'..'z') return null
|
||||||
|
|||||||
+4
-4
@@ -19,10 +19,10 @@ package org.jetbrains.kotlin.load.java.sources
|
|||||||
import org.jetbrains.kotlin.load.java.structure.JavaElement
|
import org.jetbrains.kotlin.load.java.structure.JavaElement
|
||||||
import org.jetbrains.kotlin.descriptors.SourceElement
|
import org.jetbrains.kotlin.descriptors.SourceElement
|
||||||
|
|
||||||
public interface JavaSourceElementFactory {
|
interface JavaSourceElementFactory {
|
||||||
public fun source(javaElement: JavaElement): JavaSourceElement
|
fun source(javaElement: JavaElement): JavaSourceElement
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface JavaSourceElement: SourceElement {
|
interface JavaSourceElement: SourceElement {
|
||||||
public val javaElement: JavaElement
|
val javaElement: JavaElement
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-5
@@ -79,7 +79,7 @@ object BuiltinMethodsWithSpecialGenericSignature {
|
|||||||
FqName("kotlin.MutableCollection.retainAll")
|
FqName("kotlin.MutableCollection.retainAll")
|
||||||
)
|
)
|
||||||
|
|
||||||
public enum class DefaultValue(val value: Any?) {
|
enum class DefaultValue(val value: Any?) {
|
||||||
NULL(null), INDEX(-1), FALSE(false)
|
NULL(null), INDEX(-1), FALSE(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -258,7 +258,7 @@ private fun getOverriddenBuiltinThatAffectsJvmName(
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun ClassDescriptor.hasRealKotlinSuperClassWithOverrideOf(
|
fun ClassDescriptor.hasRealKotlinSuperClassWithOverrideOf(
|
||||||
specialCallableDescriptor: CallableDescriptor
|
specialCallableDescriptor: CallableDescriptor
|
||||||
): Boolean {
|
): Boolean {
|
||||||
val builtinContainerDefaultType = (specialCallableDescriptor.containingDeclaration as ClassDescriptor).defaultType
|
val builtinContainerDefaultType = (specialCallableDescriptor.containingDeclaration as ClassDescriptor).defaultType
|
||||||
@@ -286,16 +286,16 @@ public fun ClassDescriptor.hasRealKotlinSuperClassWithOverrideOf(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Util methods
|
// Util methods
|
||||||
public val CallableMemberDescriptor.isFromJava: Boolean
|
val CallableMemberDescriptor.isFromJava: Boolean
|
||||||
get() = propertyIfAccessor is JavaCallableMemberDescriptor && propertyIfAccessor.containingDeclaration is JavaClassDescriptor
|
get() = propertyIfAccessor is JavaCallableMemberDescriptor && propertyIfAccessor.containingDeclaration is JavaClassDescriptor
|
||||||
|
|
||||||
public fun CallableMemberDescriptor.isFromBuiltins(): Boolean {
|
fun CallableMemberDescriptor.isFromBuiltins(): Boolean {
|
||||||
val fqName = propertyIfAccessor.fqNameOrNull() ?: return false
|
val fqName = propertyIfAccessor.fqNameOrNull() ?: return false
|
||||||
return fqName.toUnsafe().startsWith(KotlinBuiltIns.BUILT_INS_PACKAGE_NAME) &&
|
return fqName.toUnsafe().startsWith(KotlinBuiltIns.BUILT_INS_PACKAGE_NAME) &&
|
||||||
this.module == this.builtIns.builtInsModule
|
this.module == this.builtIns.builtInsModule
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun CallableMemberDescriptor.isFromJavaOrBuiltins() = isFromJava || isFromBuiltins()
|
fun CallableMemberDescriptor.isFromJavaOrBuiltins() = isFromJava || isFromBuiltins()
|
||||||
|
|
||||||
private fun Map<FqName, Name>.getInversedShortNamesMap(): Map<Name, List<Name>> =
|
private fun Map<FqName, Name>.getInversedShortNamesMap(): Map<Name, List<Name>> =
|
||||||
entries.groupBy { it.value }.mapValues { entry -> entry.value.map { it.key.shortName() } }
|
entries.groupBy { it.value }.mapValues { entry -> entry.value.map { it.key.shortName() } }
|
||||||
+4
-4
@@ -19,10 +19,10 @@ package org.jetbrains.kotlin.load.java.structure
|
|||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
|
|
||||||
public interface JavaPackage : JavaElement {
|
interface JavaPackage : JavaElement {
|
||||||
public fun getClasses(nameFilter: (Name) -> Boolean): Collection<JavaClass>
|
fun getClasses(nameFilter: (Name) -> Boolean): Collection<JavaClass>
|
||||||
|
|
||||||
public fun getSubPackages(): Collection<JavaPackage>
|
fun getSubPackages(): Collection<JavaPackage>
|
||||||
|
|
||||||
public fun getFqName(): FqName
|
fun getFqName(): FqName
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -19,12 +19,12 @@ package org.jetbrains.kotlin.load.java.structure
|
|||||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||||
import org.jetbrains.kotlin.resolve.constants.ConstantValue
|
import org.jetbrains.kotlin.resolve.constants.ConstantValue
|
||||||
|
|
||||||
public interface JavaPropertyInitializerEvaluator {
|
interface JavaPropertyInitializerEvaluator {
|
||||||
public fun getInitializerConstant(field: JavaField, descriptor: PropertyDescriptor): ConstantValue<*>?
|
fun getInitializerConstant(field: JavaField, descriptor: PropertyDescriptor): ConstantValue<*>?
|
||||||
|
|
||||||
public fun isNotNullCompileTimeConstant(field: JavaField): Boolean
|
fun isNotNullCompileTimeConstant(field: JavaField): Boolean
|
||||||
|
|
||||||
public object DoNothing : JavaPropertyInitializerEvaluator {
|
object DoNothing : JavaPropertyInitializerEvaluator {
|
||||||
override fun getInitializerConstant(field: JavaField, descriptor: PropertyDescriptor) = null
|
override fun getInitializerConstant(field: JavaField, descriptor: PropertyDescriptor) = null
|
||||||
|
|
||||||
override fun isNotNullCompileTimeConstant(field: JavaField) = false
|
override fun isNotNullCompileTimeConstant(field: JavaField) = false
|
||||||
|
|||||||
+12
-12
@@ -18,26 +18,26 @@ package org.jetbrains.kotlin.load.java.structure
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
|
|
||||||
public interface JavaAnnotationArgument {
|
interface JavaAnnotationArgument {
|
||||||
public val name: Name?
|
val name: Name?
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface JavaLiteralAnnotationArgument : JavaAnnotationArgument {
|
interface JavaLiteralAnnotationArgument : JavaAnnotationArgument {
|
||||||
public val value: Any?
|
val value: Any?
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface JavaArrayAnnotationArgument : JavaAnnotationArgument {
|
interface JavaArrayAnnotationArgument : JavaAnnotationArgument {
|
||||||
public fun getElements(): List<JavaAnnotationArgument>
|
fun getElements(): List<JavaAnnotationArgument>
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface JavaEnumValueAnnotationArgument : JavaAnnotationArgument {
|
interface JavaEnumValueAnnotationArgument : JavaAnnotationArgument {
|
||||||
public fun resolve(): JavaField?
|
fun resolve(): JavaField?
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface JavaClassObjectAnnotationArgument : JavaAnnotationArgument {
|
interface JavaClassObjectAnnotationArgument : JavaAnnotationArgument {
|
||||||
public fun getReferencedType(): JavaType
|
fun getReferencedType(): JavaType
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface JavaAnnotationAsAnnotationArgument : JavaAnnotationArgument {
|
interface JavaAnnotationAsAnnotationArgument : JavaAnnotationArgument {
|
||||||
public fun getAnnotation(): JavaAnnotation
|
fun getAnnotation(): JavaAnnotation
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-8
@@ -20,27 +20,27 @@ import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
|||||||
import org.jetbrains.kotlin.load.java.descriptors.JavaCallableMemberDescriptor
|
import org.jetbrains.kotlin.load.java.descriptors.JavaCallableMemberDescriptor
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
|
|
||||||
public fun <D : CallableMemberDescriptor> enhanceSignatures(platformSignatures: Collection<D>): Collection<D> {
|
fun <D : CallableMemberDescriptor> enhanceSignatures(platformSignatures: Collection<D>): Collection<D> {
|
||||||
return platformSignatures.map {
|
return platformSignatures.map {
|
||||||
it.enhanceSignature()
|
it.enhanceSignature()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun <D : CallableMemberDescriptor> D.enhanceSignature(): D {
|
fun <D : CallableMemberDescriptor> D.enhanceSignature(): D {
|
||||||
// TODO type parameters
|
// TODO type parameters
|
||||||
// TODO use new type parameters while enhancing other types
|
// TODO use new type parameters while enhancing other types
|
||||||
// TODO Propagation into generic type arguments
|
// TODO Propagation into generic type arguments
|
||||||
|
|
||||||
val enhancedReceiverType =
|
val enhancedReceiverType =
|
||||||
if (getExtensionReceiverParameter() != null)
|
if (extensionReceiverParameter != null)
|
||||||
parts(isCovariant = false) { it.getExtensionReceiverParameter()!!.getType() }.enhance()
|
parts(isCovariant = false) { it.extensionReceiverParameter!!.type }.enhance()
|
||||||
else null
|
else null
|
||||||
|
|
||||||
val enhancedValueParametersTypes = getValueParameters().map {
|
val enhancedValueParametersTypes = valueParameters.map {
|
||||||
p -> parts(isCovariant = false) { it.getValueParameters()[p.index].getType() }.enhance()
|
p -> parts(isCovariant = false) { it.valueParameters[p.index].type }.enhance()
|
||||||
}
|
}
|
||||||
|
|
||||||
val enhancedReturnType = parts(isCovariant = true) { it.getReturnType()!! }.enhance()
|
val enhancedReturnType = parts(isCovariant = true) { it.returnType!! }.enhance()
|
||||||
|
|
||||||
if (this is JavaCallableMemberDescriptor) {
|
if (this is JavaCallableMemberDescriptor) {
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
@@ -64,7 +64,7 @@ private class SignatureParts(
|
|||||||
private fun <D : CallableMemberDescriptor> D.parts(isCovariant: Boolean, collector: (D) -> KotlinType): SignatureParts {
|
private fun <D : CallableMemberDescriptor> D.parts(isCovariant: Boolean, collector: (D) -> KotlinType): SignatureParts {
|
||||||
return SignatureParts(
|
return SignatureParts(
|
||||||
collector(this),
|
collector(this),
|
||||||
this.getOverriddenDescriptors().map {
|
this.overriddenDescriptors.map {
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
collector(it as D)
|
collector(it as D)
|
||||||
},
|
},
|
||||||
|
|||||||
+4
-4
@@ -71,7 +71,7 @@ private fun KotlinType.enhanceInflexible(qualifiers: (Int) -> JavaTypeQualifiers
|
|||||||
val shouldEnhance = position.shouldEnhance()
|
val shouldEnhance = position.shouldEnhance()
|
||||||
if (!shouldEnhance && getArguments().isEmpty()) return Result(this, 1)
|
if (!shouldEnhance && getArguments().isEmpty()) return Result(this, 1)
|
||||||
|
|
||||||
val originalClass = getConstructor().getDeclarationDescriptor()
|
val originalClass = getConstructor().declarationDescriptor
|
||||||
?: return Result(this, 1)
|
?: return Result(this, 1)
|
||||||
|
|
||||||
val effectiveQualifiers = qualifiers(index)
|
val effectiveQualifiers = qualifiers(index)
|
||||||
@@ -82,12 +82,12 @@ private fun KotlinType.enhanceInflexible(qualifiers: (Int) -> JavaTypeQualifiers
|
|||||||
var globalArgIndex = index + 1
|
var globalArgIndex = index + 1
|
||||||
val enhancedArguments = getArguments().mapIndexed {
|
val enhancedArguments = getArguments().mapIndexed {
|
||||||
localArgIndex, arg ->
|
localArgIndex, arg ->
|
||||||
if (arg.isStarProjection()) {
|
if (arg.isStarProjection) {
|
||||||
globalArgIndex++
|
globalArgIndex++
|
||||||
TypeUtils.makeStarProjection(enhancedClassifier.getTypeConstructor().getParameters()[localArgIndex])
|
TypeUtils.makeStarProjection(enhancedClassifier.typeConstructor.parameters[localArgIndex])
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
val (enhancedType, subtreeSize) = arg.getType().enhancePossiblyFlexible(qualifiers, globalArgIndex)
|
val (enhancedType, subtreeSize) = arg.type.enhancePossiblyFlexible(qualifiers, globalArgIndex)
|
||||||
globalArgIndex += subtreeSize
|
globalArgIndex += subtreeSize
|
||||||
createProjection(enhancedType, arg.projectionKind, typeParameterDescriptor = typeConstructor.parameters[localArgIndex])
|
createProjection(enhancedType, arg.projectionKind, typeParameterDescriptor = typeConstructor.parameters[localArgIndex])
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -95,11 +95,11 @@ fun KotlinType.computeIndexedQualifiersForOverride(fromSupertypes: Collection<Ko
|
|||||||
fun add(type: KotlinType) {
|
fun add(type: KotlinType) {
|
||||||
list.add(type)
|
list.add(type)
|
||||||
for (arg in type.getArguments()) {
|
for (arg in type.getArguments()) {
|
||||||
if (arg.isStarProjection()) {
|
if (arg.isStarProjection) {
|
||||||
list.add(arg.getType())
|
list.add(arg.type)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
add(arg.getType())
|
add(arg.type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -33,7 +33,7 @@ import org.jetbrains.kotlin.storage.StorageManager
|
|||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
public abstract class AbstractBinaryClassAnnotationAndConstantLoader<A : Any, C : Any, T : Any>(
|
abstract class AbstractBinaryClassAnnotationAndConstantLoader<A : Any, C : Any, T : Any>(
|
||||||
storageManager: StorageManager,
|
storageManager: StorageManager,
|
||||||
private val kotlinClassFinder: KotlinClassFinder,
|
private val kotlinClassFinder: KotlinClassFinder,
|
||||||
private val errorReporter: ErrorReporter
|
private val errorReporter: ErrorReporter
|
||||||
@@ -322,7 +322,7 @@ public abstract class AbstractBinaryClassAnnotationAndConstantLoader<A : Any, C
|
|||||||
}
|
}
|
||||||
|
|
||||||
private class Storage<A, C>(
|
private class Storage<A, C>(
|
||||||
public val memberAnnotations: Map<MemberSignature, List<A>>,
|
val memberAnnotations: Map<MemberSignature, List<A>>,
|
||||||
public val propertyConstants: Map<MemberSignature, C>
|
val propertyConstants: Map<MemberSignature, C>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-5
@@ -39,7 +39,7 @@ import org.jetbrains.kotlin.storage.StorageManager
|
|||||||
import org.jetbrains.kotlin.types.ErrorUtils
|
import org.jetbrains.kotlin.types.ErrorUtils
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
public class BinaryClassAnnotationAndConstantLoaderImpl(
|
class BinaryClassAnnotationAndConstantLoaderImpl(
|
||||||
private val module: ModuleDescriptor,
|
private val module: ModuleDescriptor,
|
||||||
storageManager: StorageManager,
|
storageManager: StorageManager,
|
||||||
kotlinClassFinder: KotlinClassFinder,
|
kotlinClassFinder: KotlinClassFinder,
|
||||||
@@ -131,7 +131,7 @@ public class BinaryClassAnnotationAndConstantLoaderImpl(
|
|||||||
val parameter = DescriptorResolverUtils.getAnnotationParameterByName(name, annotationClass)
|
val parameter = DescriptorResolverUtils.getAnnotationParameterByName(name, annotationClass)
|
||||||
if (parameter != null) {
|
if (parameter != null) {
|
||||||
elements.trimToSize()
|
elements.trimToSize()
|
||||||
arguments[parameter] = factory.createArrayValue(elements, parameter.getType())
|
arguments[parameter] = factory.createArrayValue(elements, parameter.type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -151,8 +151,8 @@ public class BinaryClassAnnotationAndConstantLoaderImpl(
|
|||||||
// NOTE: see analogous code in AnnotationDeserializer
|
// NOTE: see analogous code in AnnotationDeserializer
|
||||||
private fun enumEntryValue(enumClassId: ClassId, name: Name): ConstantValue<*> {
|
private fun enumEntryValue(enumClassId: ClassId, name: Name): ConstantValue<*> {
|
||||||
val enumClass = resolveClass(enumClassId)
|
val enumClass = resolveClass(enumClassId)
|
||||||
if (enumClass.getKind() == ClassKind.ENUM_CLASS) {
|
if (enumClass.kind == ClassKind.ENUM_CLASS) {
|
||||||
val classifier = enumClass.getUnsubstitutedInnerClassesScope().getContributedClassifier(name, NoLookupLocation.FROM_JAVA_LOADER)
|
val classifier = enumClass.unsubstitutedInnerClassesScope.getContributedClassifier(name, NoLookupLocation.FROM_JAVA_LOADER)
|
||||||
if (classifier is ClassDescriptor) {
|
if (classifier is ClassDescriptor) {
|
||||||
return factory.createEnumValue(classifier)
|
return factory.createEnumValue(classifier)
|
||||||
}
|
}
|
||||||
@@ -161,7 +161,7 @@ public class BinaryClassAnnotationAndConstantLoaderImpl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun visitEnd() {
|
override fun visitEnd() {
|
||||||
result.add(AnnotationDescriptorImpl(annotationClass.getDefaultType(), arguments, source))
|
result.add(AnnotationDescriptorImpl(annotationClass.defaultType, arguments, source))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createConstant(name: Name?, value: Any?): ConstantValue<*> {
|
private fun createConstant(name: Name?, value: Any?): ConstantValue<*> {
|
||||||
|
|||||||
+1
-1
@@ -27,7 +27,7 @@ import org.jetbrains.kotlin.storage.StorageManager
|
|||||||
|
|
||||||
// This class is needed only for easier injection: exact types of needed components are specified in the constructor here.
|
// This class is needed only for easier injection: exact types of needed components are specified in the constructor here.
|
||||||
// Otherwise injector generator is not smart enough to deduce, for example, which package fragment provider DeserializationComponents needs
|
// Otherwise injector generator is not smart enough to deduce, for example, which package fragment provider DeserializationComponents needs
|
||||||
public class DeserializationComponentsForJava(
|
class DeserializationComponentsForJava(
|
||||||
storageManager: StorageManager,
|
storageManager: StorageManager,
|
||||||
moduleDescriptor: ModuleDescriptor,
|
moduleDescriptor: ModuleDescriptor,
|
||||||
classDataFinder: JavaClassDataFinder,
|
classDataFinder: JavaClassDataFinder,
|
||||||
|
|||||||
+1
-1
@@ -21,7 +21,7 @@ import org.jetbrains.kotlin.serialization.ClassDataWithSource
|
|||||||
import org.jetbrains.kotlin.serialization.deserialization.ClassDataFinder
|
import org.jetbrains.kotlin.serialization.deserialization.ClassDataFinder
|
||||||
import org.jetbrains.kotlin.serialization.jvm.JvmProtoBufUtil
|
import org.jetbrains.kotlin.serialization.jvm.JvmProtoBufUtil
|
||||||
|
|
||||||
public class JavaClassDataFinder(
|
class JavaClassDataFinder(
|
||||||
private val kotlinClassFinder: KotlinClassFinder,
|
private val kotlinClassFinder: KotlinClassFinder,
|
||||||
private val deserializedDescriptorResolver: DeserializedDescriptorResolver
|
private val deserializedDescriptorResolver: DeserializedDescriptorResolver
|
||||||
) : ClassDataFinder {
|
) : ClassDataFinder {
|
||||||
|
|||||||
+1
-1
@@ -22,7 +22,7 @@ import org.jetbrains.kotlin.serialization.deserialization.TypeCapabilitiesLoader
|
|||||||
import org.jetbrains.kotlin.serialization.jvm.JvmProtoBuf
|
import org.jetbrains.kotlin.serialization.jvm.JvmProtoBuf
|
||||||
import org.jetbrains.kotlin.types.TypeCapabilities
|
import org.jetbrains.kotlin.types.TypeCapabilities
|
||||||
|
|
||||||
public object JavaTypeCapabilitiesLoader : TypeCapabilitiesLoader() {
|
object JavaTypeCapabilitiesLoader : TypeCapabilitiesLoader() {
|
||||||
override fun loadCapabilities(type: ProtoBuf.Type): TypeCapabilities =
|
override fun loadCapabilities(type: ProtoBuf.Type): TypeCapabilities =
|
||||||
if (type.hasExtension(JvmProtoBuf.isRaw)) RawTypeCapabilities else TypeCapabilities.NONE
|
if (type.hasExtension(JvmProtoBuf.isRaw)) RawTypeCapabilities else TypeCapabilities.NONE
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -19,8 +19,8 @@ package org.jetbrains.kotlin.load.kotlin
|
|||||||
import org.jetbrains.kotlin.load.java.structure.JavaClass
|
import org.jetbrains.kotlin.load.java.structure.JavaClass
|
||||||
import org.jetbrains.kotlin.name.ClassId
|
import org.jetbrains.kotlin.name.ClassId
|
||||||
|
|
||||||
public interface KotlinClassFinder {
|
interface KotlinClassFinder {
|
||||||
public fun findKotlinClass(classId: ClassId): KotlinJvmBinaryClass?
|
fun findKotlinClass(classId: ClassId): KotlinJvmBinaryClass?
|
||||||
|
|
||||||
public fun findKotlinClass(javaClass: JavaClass): KotlinJvmBinaryClass?
|
fun findKotlinClass(javaClass: JavaClass): KotlinJvmBinaryClass?
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -37,11 +37,11 @@ class KotlinJvmBinaryPackageSourceElement(
|
|||||||
override fun toString(): String = "Binary package ${jPackage.getFqName()}: ${implClassNameToBinaryClass.keys}"
|
override fun toString(): String = "Binary package ${jPackage.getFqName()}: ${implClassNameToBinaryClass.keys}"
|
||||||
override fun getContainingFile(): SourceFile = SourceFile.NO_SOURCE_FILE
|
override fun getContainingFile(): SourceFile = SourceFile.NO_SOURCE_FILE
|
||||||
|
|
||||||
public fun getRepresentativeBinaryClass(): KotlinJvmBinaryClass {
|
fun getRepresentativeBinaryClass(): KotlinJvmBinaryClass {
|
||||||
return implClassNameToBinaryClass.values.first()
|
return implClassNameToBinaryClass.values.first()
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun getContainingBinaryClass(descriptor: DeserializedCallableMemberDescriptor): KotlinJvmBinaryClass? {
|
fun getContainingBinaryClass(descriptor: DeserializedCallableMemberDescriptor): KotlinJvmBinaryClass? {
|
||||||
val name = descriptor.getImplClassNameForDeserialized() ?: return null
|
val name = descriptor.getImplClassNameForDeserialized() ?: return null
|
||||||
return implClassNameToBinaryClass[name.asString()]
|
return implClassNameToBinaryClass[name.asString()]
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -19,7 +19,7 @@ package org.jetbrains.kotlin.load.kotlin
|
|||||||
import org.jetbrains.kotlin.descriptors.SourceElement
|
import org.jetbrains.kotlin.descriptors.SourceElement
|
||||||
import org.jetbrains.kotlin.descriptors.SourceFile
|
import org.jetbrains.kotlin.descriptors.SourceFile
|
||||||
|
|
||||||
public class KotlinJvmBinarySourceElement(public val binaryClass: KotlinJvmBinaryClass) : SourceElement {
|
class KotlinJvmBinarySourceElement(val binaryClass: KotlinJvmBinaryClass) : SourceElement {
|
||||||
override fun toString() = javaClass.name + ": " + binaryClass.toString()
|
override fun toString() = javaClass.name + ": " + binaryClass.toString()
|
||||||
override fun getContainingFile(): SourceFile = SourceFile.NO_SOURCE_FILE
|
override fun getContainingFile(): SourceFile = SourceFile.NO_SOURCE_FILE
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,18 +22,16 @@ import org.jetbrains.kotlin.serialization.jvm.JvmPackageTable
|
|||||||
import java.io.ByteArrayInputStream
|
import java.io.ByteArrayInputStream
|
||||||
import java.io.DataInputStream
|
import java.io.DataInputStream
|
||||||
|
|
||||||
public class ModuleMapping private constructor(val packageFqName2Parts: Map<String, PackageParts>) {
|
class ModuleMapping private constructor(val packageFqName2Parts: Map<String, PackageParts>) {
|
||||||
|
|
||||||
fun findPackageParts(packageFqName: String): PackageParts? {
|
fun findPackageParts(packageFqName: String): PackageParts? {
|
||||||
return packageFqName2Parts[packageFqName]
|
return packageFqName2Parts[packageFqName]
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@JvmField
|
@JvmField val MAPPING_FILE_EXT: String = "kotlin_module"
|
||||||
public val MAPPING_FILE_EXT: String = "kotlin_module"
|
|
||||||
|
|
||||||
@JvmField
|
@JvmField val EMPTY: ModuleMapping = ModuleMapping(emptyMap())
|
||||||
public val EMPTY: ModuleMapping = ModuleMapping(emptyMap())
|
|
||||||
|
|
||||||
fun create(proto: ByteArray? = null): ModuleMapping {
|
fun create(proto: ByteArray? = null): ModuleMapping {
|
||||||
if (proto == null) {
|
if (proto == null) {
|
||||||
@@ -68,7 +66,7 @@ public class ModuleMapping private constructor(val packageFqName2Parts: Map<Stri
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class PackageParts(val packageFqName: String) {
|
class PackageParts(val packageFqName: String) {
|
||||||
|
|
||||||
val parts = linkedSetOf<String>()
|
val parts = linkedSetOf<String>()
|
||||||
|
|
||||||
@@ -79,8 +77,7 @@ public class PackageParts(val packageFqName: String) {
|
|||||||
packageFqName.hashCode() * 31 + parts.hashCode()
|
packageFqName.hashCode() * 31 + parts.hashCode()
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@JvmStatic
|
@JvmStatic fun PackageParts.serialize(builder: JvmPackageTable.PackageTable.Builder) {
|
||||||
public fun PackageParts.serialize(builder: JvmPackageTable.PackageTable.Builder) {
|
|
||||||
if (this.parts.isNotEmpty()) {
|
if (this.parts.isNotEmpty()) {
|
||||||
val packageParts = JvmPackageTable.PackageParts.newBuilder()
|
val packageParts = JvmPackageTable.PackageParts.newBuilder()
|
||||||
packageParts.setPackageFqName(this.packageFqName)
|
packageParts.setPackageFqName(this.packageFqName)
|
||||||
|
|||||||
+6
-10
@@ -25,31 +25,27 @@ import org.jetbrains.kotlin.serialization.deserialization.*
|
|||||||
import org.jetbrains.kotlin.utils.singletonOrEmptyList
|
import org.jetbrains.kotlin.utils.singletonOrEmptyList
|
||||||
import java.io.ByteArrayInputStream
|
import java.io.ByteArrayInputStream
|
||||||
|
|
||||||
public object JvmProtoBufUtil {
|
object JvmProtoBufUtil {
|
||||||
public val EXTENSION_REGISTRY: ExtensionRegistryLite = run {
|
val EXTENSION_REGISTRY: ExtensionRegistryLite = run {
|
||||||
val registry = ExtensionRegistryLite.newInstance()
|
val registry = ExtensionRegistryLite.newInstance()
|
||||||
JvmProtoBuf.registerAllExtensions(registry)
|
JvmProtoBuf.registerAllExtensions(registry)
|
||||||
registry
|
registry
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic fun readClassDataFrom(data: Array<String>, strings: Array<String>): ClassData =
|
||||||
public fun readClassDataFrom(data: Array<String>, strings: Array<String>): ClassData =
|
|
||||||
readClassDataFrom(BitEncoding.decodeBytes(data), strings)
|
readClassDataFrom(BitEncoding.decodeBytes(data), strings)
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic fun readClassDataFrom(bytes: ByteArray, strings: Array<String>): ClassData {
|
||||||
public fun readClassDataFrom(bytes: ByteArray, strings: Array<String>): ClassData {
|
|
||||||
val input = ByteArrayInputStream(bytes)
|
val input = ByteArrayInputStream(bytes)
|
||||||
val nameResolver = JvmNameResolver(JvmProtoBuf.StringTableTypes.parseDelimitedFrom(input, EXTENSION_REGISTRY), strings)
|
val nameResolver = JvmNameResolver(JvmProtoBuf.StringTableTypes.parseDelimitedFrom(input, EXTENSION_REGISTRY), strings)
|
||||||
val classProto = ProtoBuf.Class.parseFrom(input, EXTENSION_REGISTRY)
|
val classProto = ProtoBuf.Class.parseFrom(input, EXTENSION_REGISTRY)
|
||||||
return ClassData(nameResolver, classProto)
|
return ClassData(nameResolver, classProto)
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic fun readPackageDataFrom(data: Array<String>, strings: Array<String>): PackageData =
|
||||||
public fun readPackageDataFrom(data: Array<String>, strings: Array<String>): PackageData =
|
|
||||||
readPackageDataFrom(BitEncoding.decodeBytes(data), strings)
|
readPackageDataFrom(BitEncoding.decodeBytes(data), strings)
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic fun readPackageDataFrom(bytes: ByteArray, strings: Array<String>): PackageData {
|
||||||
public fun readPackageDataFrom(bytes: ByteArray, strings: Array<String>): PackageData {
|
|
||||||
val input = ByteArrayInputStream(bytes)
|
val input = ByteArrayInputStream(bytes)
|
||||||
val nameResolver = JvmNameResolver(JvmProtoBuf.StringTableTypes.parseDelimitedFrom(input, EXTENSION_REGISTRY), strings)
|
val nameResolver = JvmNameResolver(JvmProtoBuf.StringTableTypes.parseDelimitedFrom(input, EXTENSION_REGISTRY), strings)
|
||||||
val packageProto = ProtoBuf.Package.parseFrom(input, EXTENSION_REGISTRY)
|
val packageProto = ProtoBuf.Package.parseFrom(input, EXTENSION_REGISTRY)
|
||||||
|
|||||||
+3
-3
@@ -23,10 +23,10 @@ import org.jetbrains.kotlin.name.ClassId
|
|||||||
import org.jetbrains.kotlin.serialization.deserialization.BinaryVersion
|
import org.jetbrains.kotlin.serialization.deserialization.BinaryVersion
|
||||||
import org.jetbrains.kotlin.serialization.deserialization.ErrorReporter
|
import org.jetbrains.kotlin.serialization.deserialization.ErrorReporter
|
||||||
|
|
||||||
public object RuntimeErrorReporter : ErrorReporter {
|
object RuntimeErrorReporter : ErrorReporter {
|
||||||
// TODO: specialized exceptions
|
// TODO: specialized exceptions
|
||||||
override fun reportIncompleteHierarchy(descriptor: ClassDescriptor, unresolvedSuperClasses: MutableList<String>) {
|
override fun reportIncompleteHierarchy(descriptor: ClassDescriptor, unresolvedSuperClasses: MutableList<String>) {
|
||||||
throw IllegalStateException("Incomplete hierarchy for class ${descriptor.getName()}, unresolved classes $unresolvedSuperClasses")
|
throw IllegalStateException("Incomplete hierarchy for class ${descriptor.name}, unresolved classes $unresolvedSuperClasses")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun reportIncompatibleAbiVersion(classId: ClassId, filePath: String, actualVersion: BinaryVersion) {
|
override fun reportIncompatibleAbiVersion(classId: ClassId, filePath: String, actualVersion: BinaryVersion) {
|
||||||
@@ -36,7 +36,7 @@ public object RuntimeErrorReporter : ErrorReporter {
|
|||||||
|
|
||||||
override fun reportCannotInferVisibility(descriptor: CallableMemberDescriptor) {
|
override fun reportCannotInferVisibility(descriptor: CallableMemberDescriptor) {
|
||||||
// TODO: use DescriptorRenderer
|
// TODO: use DescriptorRenderer
|
||||||
throw IllegalStateException("Cannot infer visibility for class ${descriptor.getName()}")
|
throw IllegalStateException("Cannot infer visibility for class ${descriptor.name}")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun reportLoadingError(message: String, exception: Exception?) {
|
override fun reportLoadingError(message: String, exception: Exception?) {
|
||||||
|
|||||||
+1
-1
@@ -22,7 +22,7 @@ import org.jetbrains.kotlin.load.java.sources.JavaSourceElementFactory
|
|||||||
import org.jetbrains.kotlin.load.java.structure.JavaElement
|
import org.jetbrains.kotlin.load.java.structure.JavaElement
|
||||||
import org.jetbrains.kotlin.load.java.structure.reflect.ReflectJavaElement
|
import org.jetbrains.kotlin.load.java.structure.reflect.ReflectJavaElement
|
||||||
|
|
||||||
public object RuntimeSourceElementFactory : JavaSourceElementFactory {
|
object RuntimeSourceElementFactory : JavaSourceElementFactory {
|
||||||
private class RuntimeSourceElement(override val javaElement: ReflectJavaElement) : JavaSourceElement {
|
private class RuntimeSourceElement(override val javaElement: ReflectJavaElement) : JavaSourceElement {
|
||||||
override fun toString() = javaClass.name + ": " + javaElement.toString()
|
override fun toString() = javaClass.name + ": " + javaElement.toString()
|
||||||
override fun getContainingFile(): SourceFile = SourceFile.NO_SOURCE_FILE
|
override fun getContainingFile(): SourceFile = SourceFile.NO_SOURCE_FILE
|
||||||
|
|||||||
+4
-4
@@ -24,12 +24,12 @@ import org.jetbrains.kotlin.load.java.structure.reflect.ReflectJavaClass
|
|||||||
import org.jetbrains.kotlin.load.java.structure.reflect.ReflectJavaPackage
|
import org.jetbrains.kotlin.load.java.structure.reflect.ReflectJavaPackage
|
||||||
import org.jetbrains.kotlin.name.ClassId
|
import org.jetbrains.kotlin.name.ClassId
|
||||||
|
|
||||||
public class ReflectJavaClassFinder(private val classLoader: ClassLoader) : JavaClassFinder {
|
class ReflectJavaClassFinder(private val classLoader: ClassLoader) : JavaClassFinder {
|
||||||
override fun findClass(classId: ClassId): JavaClass? {
|
override fun findClass(classId: ClassId): JavaClass? {
|
||||||
val packageFqName = classId.getPackageFqName()
|
val packageFqName = classId.packageFqName
|
||||||
val relativeClassName = classId.getRelativeClassName().asString().replace('.', '$')
|
val relativeClassName = classId.relativeClassName.asString().replace('.', '$')
|
||||||
val name =
|
val name =
|
||||||
if (packageFqName.isRoot()) relativeClassName
|
if (packageFqName.isRoot) relativeClassName
|
||||||
else packageFqName.asString() + "." + relativeClassName
|
else packageFqName.asString() + "." + relativeClassName
|
||||||
|
|
||||||
val klass = classLoader.tryLoadClass(name)
|
val klass = classLoader.tryLoadClass(name)
|
||||||
|
|||||||
+4
-4
@@ -21,17 +21,17 @@ import org.jetbrains.kotlin.load.java.structure.JavaAnnotationArgument
|
|||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import java.lang.reflect.Method
|
import java.lang.reflect.Method
|
||||||
|
|
||||||
public class ReflectJavaAnnotation(private val annotation: Annotation) : ReflectJavaElement(), JavaAnnotation {
|
class ReflectJavaAnnotation(private val annotation: Annotation) : ReflectJavaElement(), JavaAnnotation {
|
||||||
override fun findArgument(name: Name): JavaAnnotationArgument? {
|
override fun findArgument(name: Name): JavaAnnotationArgument? {
|
||||||
return getArgumentValue(annotation.annotationClass.java.getDeclaredMethod(name.asString()))
|
return getArgumentValue(annotation.annotationClass.java.getDeclaredMethod(name.asString()))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getArguments(): Collection<JavaAnnotationArgument> {
|
override fun getArguments(): Collection<JavaAnnotationArgument> {
|
||||||
return annotation.annotationClass.java.getDeclaredMethods().map { getArgumentValue(it) }
|
return annotation.annotationClass.java.declaredMethods.map { getArgumentValue(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getArgumentValue(argument: Method): ReflectJavaAnnotationArgument {
|
private fun getArgumentValue(argument: Method): ReflectJavaAnnotationArgument {
|
||||||
return argument.invoke(annotation).let { ReflectJavaAnnotationArgument.create(it, Name.identifier(argument.getName())) }
|
return argument.invoke(annotation).let { ReflectJavaAnnotationArgument.create(it, Name.identifier(argument.name)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun resolve() = ReflectJavaClass(annotation.annotationClass.java)
|
override fun resolve() = ReflectJavaClass(annotation.annotationClass.java)
|
||||||
@@ -42,5 +42,5 @@ public class ReflectJavaAnnotation(private val annotation: Annotation) : Reflect
|
|||||||
|
|
||||||
override fun hashCode() = annotation.hashCode()
|
override fun hashCode() = annotation.hashCode()
|
||||||
|
|
||||||
override fun toString() = javaClass.getName() + ": " + annotation
|
override fun toString() = javaClass.name + ": " + annotation
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -53,7 +53,7 @@ class ReflectJavaEnumValueAnnotationArgument(
|
|||||||
) : ReflectJavaAnnotationArgument(name), JavaEnumValueAnnotationArgument {
|
) : ReflectJavaAnnotationArgument(name), JavaEnumValueAnnotationArgument {
|
||||||
override fun resolve(): ReflectJavaField {
|
override fun resolve(): ReflectJavaField {
|
||||||
val clazz = value.javaClass
|
val clazz = value.javaClass
|
||||||
val enumClass = if (clazz.isEnum()) clazz else clazz.getEnclosingClass()
|
val enumClass = if (clazz.isEnum) clazz else clazz.enclosingClass
|
||||||
return ReflectJavaField(enumClass.getDeclaredField(value.name))
|
return ReflectJavaField(enumClass.getDeclaredField(value.name))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -20,12 +20,12 @@ import org.jetbrains.kotlin.load.java.structure.JavaAnnotationOwner
|
|||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import java.lang.reflect.AnnotatedElement
|
import java.lang.reflect.AnnotatedElement
|
||||||
|
|
||||||
public interface ReflectJavaAnnotationOwner : JavaAnnotationOwner {
|
interface ReflectJavaAnnotationOwner : JavaAnnotationOwner {
|
||||||
val element: AnnotatedElement
|
val element: AnnotatedElement
|
||||||
|
|
||||||
override fun getAnnotations() = getAnnotations(element.getDeclaredAnnotations())
|
override fun getAnnotations() = getAnnotations(element.declaredAnnotations)
|
||||||
|
|
||||||
override fun findAnnotation(fqName: FqName) = findAnnotation(element.getDeclaredAnnotations(), fqName)
|
override fun findAnnotation(fqName: FqName) = findAnnotation(element.declaredAnnotations, fqName)
|
||||||
|
|
||||||
override fun isDeprecatedInJavaDoc() = false
|
override fun isDeprecatedInJavaDoc() = false
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -20,10 +20,10 @@ import org.jetbrains.kotlin.load.java.structure.JavaArrayType
|
|||||||
import java.lang.reflect.GenericArrayType
|
import java.lang.reflect.GenericArrayType
|
||||||
import java.lang.reflect.Type
|
import java.lang.reflect.Type
|
||||||
|
|
||||||
public class ReflectJavaArrayType(override val type: Type) : ReflectJavaType(), JavaArrayType {
|
class ReflectJavaArrayType(override val type: Type) : ReflectJavaType(), JavaArrayType {
|
||||||
private val componentType: ReflectJavaType = with (type) {
|
private val componentType: ReflectJavaType = with (type) {
|
||||||
when {
|
when {
|
||||||
this is GenericArrayType -> ReflectJavaType.create(getGenericComponentType())
|
this is GenericArrayType -> ReflectJavaType.create(genericComponentType)
|
||||||
this is Class<*> && isArray() -> ReflectJavaType.create(getComponentType())
|
this is Class<*> && isArray() -> ReflectJavaType.create(getComponentType())
|
||||||
else -> throw IllegalArgumentException("Not an array type (${type.javaClass}): $type")
|
else -> throw IllegalArgumentException("Not an array type (${type.javaClass}): $type")
|
||||||
}
|
}
|
||||||
|
|||||||
+21
-21
@@ -24,39 +24,39 @@ import org.jetbrains.kotlin.name.Name
|
|||||||
import java.lang.reflect.Method
|
import java.lang.reflect.Method
|
||||||
import java.util.Arrays
|
import java.util.Arrays
|
||||||
|
|
||||||
public class ReflectJavaClass(
|
class ReflectJavaClass(
|
||||||
private val klass: Class<*>
|
private val klass: Class<*>
|
||||||
) : ReflectJavaElement(), ReflectJavaAnnotationOwner, ReflectJavaModifierListOwner, JavaClass {
|
) : ReflectJavaElement(), ReflectJavaAnnotationOwner, ReflectJavaModifierListOwner, JavaClass {
|
||||||
override val element: Class<*> get() = klass
|
override val element: Class<*> get() = klass
|
||||||
|
|
||||||
override val modifiers: Int get() = klass.getModifiers()
|
override val modifiers: Int get() = klass.modifiers
|
||||||
|
|
||||||
override fun getInnerClasses() = klass.getDeclaredClasses()
|
override fun getInnerClasses() = klass.declaredClasses
|
||||||
.asSequence()
|
.asSequence()
|
||||||
.filterNot {
|
.filterNot {
|
||||||
// getDeclaredClasses() returns anonymous classes sometimes, for example enums with specialized entries (which are in fact
|
// 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
|
// 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
|
// constructor accessed from the outer class
|
||||||
it.getSimpleName().isEmpty()
|
it.simpleName.isEmpty()
|
||||||
}
|
}
|
||||||
.map(::ReflectJavaClass)
|
.map(::ReflectJavaClass)
|
||||||
.toList()
|
.toList()
|
||||||
|
|
||||||
override fun getFqName() = klass.classId.asSingleFqName()
|
override fun getFqName() = klass.classId.asSingleFqName()
|
||||||
|
|
||||||
override fun getOuterClass() = klass.getDeclaringClass()?.let(::ReflectJavaClass)
|
override fun getOuterClass() = klass.declaringClass?.let(::ReflectJavaClass)
|
||||||
|
|
||||||
override fun getSupertypes(): Collection<JavaClassifierType> {
|
override fun getSupertypes(): Collection<JavaClassifierType> {
|
||||||
if (klass == Any::class.java) return emptyList()
|
if (klass == Any::class.java) return emptyList()
|
||||||
return listOf(klass.genericSuperclass ?: Any::class.java, *klass.genericInterfaces).map(::ReflectJavaClassifierType)
|
return listOf(klass.genericSuperclass ?: Any::class.java, *klass.genericInterfaces).map(::ReflectJavaClassifierType)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getMethods() = klass.getDeclaredMethods()
|
override fun getMethods() = klass.declaredMethods
|
||||||
.asSequence()
|
.asSequence()
|
||||||
.filter { method ->
|
.filter { method ->
|
||||||
when {
|
when {
|
||||||
method.isSynthetic() -> false
|
method.isSynthetic -> false
|
||||||
isEnum() -> !isEnumValuesOrValueOf(method)
|
isEnum -> !isEnumValuesOrValueOf(method)
|
||||||
else -> true
|
else -> true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -64,22 +64,22 @@ public class ReflectJavaClass(
|
|||||||
.toList()
|
.toList()
|
||||||
|
|
||||||
private fun isEnumValuesOrValueOf(method: Method): Boolean {
|
private fun isEnumValuesOrValueOf(method: Method): Boolean {
|
||||||
return when (method.getName()) {
|
return when (method.name) {
|
||||||
"values" -> method.getParameterTypes().isEmpty()
|
"values" -> method.parameterTypes.isEmpty()
|
||||||
"valueOf" -> Arrays.equals(method.getParameterTypes(), arrayOf(String::class.java))
|
"valueOf" -> Arrays.equals(method.parameterTypes, arrayOf(String::class.java))
|
||||||
else -> false
|
else -> false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getFields() = klass.getDeclaredFields()
|
override fun getFields() = klass.declaredFields
|
||||||
.asSequence()
|
.asSequence()
|
||||||
.filter { field -> !field.isSynthetic() }
|
.filter { field -> !field.isSynthetic }
|
||||||
.map(::ReflectJavaField)
|
.map(::ReflectJavaField)
|
||||||
.toList()
|
.toList()
|
||||||
|
|
||||||
override fun getConstructors() = klass.getDeclaredConstructors()
|
override fun getConstructors() = klass.declaredConstructors
|
||||||
.asSequence()
|
.asSequence()
|
||||||
.filter { constructor -> !constructor.isSynthetic() }
|
.filter { constructor -> !constructor.isSynthetic }
|
||||||
.map(::ReflectJavaConstructor)
|
.map(::ReflectJavaConstructor)
|
||||||
.toList()
|
.toList()
|
||||||
|
|
||||||
@@ -90,17 +90,17 @@ public class ReflectJavaClass(
|
|||||||
|
|
||||||
override fun createImmediateType(substitutor: JavaTypeSubstitutor): JavaType = throw UnsupportedOperationException()
|
override fun createImmediateType(substitutor: JavaTypeSubstitutor): JavaType = throw UnsupportedOperationException()
|
||||||
|
|
||||||
override fun getName(): Name = Name.identifier(klass.getSimpleName())
|
override fun getName(): Name = Name.identifier(klass.simpleName)
|
||||||
|
|
||||||
override fun getTypeParameters() = klass.getTypeParameters().map { ReflectJavaTypeParameter(it) }
|
override fun getTypeParameters() = klass.typeParameters.map { ReflectJavaTypeParameter(it) }
|
||||||
|
|
||||||
override fun isInterface() = klass.isInterface()
|
override fun isInterface() = klass.isInterface
|
||||||
override fun isAnnotationType() = klass.isAnnotation()
|
override fun isAnnotationType() = klass.isAnnotation
|
||||||
override fun isEnum() = klass.isEnum()
|
override fun isEnum() = klass.isEnum
|
||||||
|
|
||||||
override fun equals(other: Any?) = other is ReflectJavaClass && klass == other.klass
|
override fun equals(other: Any?) = other is ReflectJavaClass && klass == other.klass
|
||||||
|
|
||||||
override fun hashCode() = klass.hashCode()
|
override fun hashCode() = klass.hashCode()
|
||||||
|
|
||||||
override fun toString() = javaClass.getName() + ": " + klass
|
override fun toString() = javaClass.name + ": " + klass
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -22,13 +22,13 @@ import java.lang.reflect.ParameterizedType
|
|||||||
import java.lang.reflect.Type
|
import java.lang.reflect.Type
|
||||||
import java.lang.reflect.TypeVariable
|
import java.lang.reflect.TypeVariable
|
||||||
|
|
||||||
public class ReflectJavaClassifierType(public override val type: Type) : ReflectJavaType(), JavaClassifierType {
|
class ReflectJavaClassifierType(public override val type: Type) : ReflectJavaType(), JavaClassifierType {
|
||||||
private val classifier: JavaClassifier = run {
|
private val classifier: JavaClassifier = run {
|
||||||
val type = type
|
val type = type
|
||||||
val classifier: JavaClassifier = when (type) {
|
val classifier: JavaClassifier = when (type) {
|
||||||
is Class<*> -> ReflectJavaClass(type)
|
is Class<*> -> ReflectJavaClass(type)
|
||||||
is TypeVariable<*> -> ReflectJavaTypeParameter(type)
|
is TypeVariable<*> -> ReflectJavaTypeParameter(type)
|
||||||
is ParameterizedType -> ReflectJavaClass(type.getRawType() as Class<*>)
|
is ParameterizedType -> ReflectJavaClass(type.rawType as Class<*>)
|
||||||
else -> throw IllegalStateException("Not a classifier type (${type.javaClass}): $type")
|
else -> throw IllegalStateException("Not a classifier type (${type.javaClass}): $type")
|
||||||
}
|
}
|
||||||
classifier
|
classifier
|
||||||
|
|||||||
+6
-6
@@ -22,27 +22,27 @@ import org.jetbrains.kotlin.load.java.structure.JavaValueParameter
|
|||||||
import java.lang.reflect.Constructor
|
import java.lang.reflect.Constructor
|
||||||
import java.lang.reflect.Modifier
|
import java.lang.reflect.Modifier
|
||||||
|
|
||||||
public class ReflectJavaConstructor(override val member: Constructor<*>) : ReflectJavaMember(), JavaConstructor {
|
class ReflectJavaConstructor(override val member: Constructor<*>) : ReflectJavaMember(), JavaConstructor {
|
||||||
// TODO: test local/anonymous classes
|
// TODO: test local/anonymous classes
|
||||||
override fun getValueParameters(): List<JavaValueParameter> {
|
override fun getValueParameters(): List<JavaValueParameter> {
|
||||||
val types = member.getGenericParameterTypes()
|
val types = member.genericParameterTypes
|
||||||
if (types.isEmpty()) return emptyList()
|
if (types.isEmpty()) return emptyList()
|
||||||
|
|
||||||
val klass = member.getDeclaringClass()
|
val klass = member.declaringClass
|
||||||
|
|
||||||
val realTypes = when {
|
val realTypes = when {
|
||||||
klass.getDeclaringClass() != null && !Modifier.isStatic(klass.getModifiers()) -> types.copyOfRange(1, types.size)
|
klass.declaringClass != null && !Modifier.isStatic(klass.modifiers) -> types.copyOfRange(1, types.size)
|
||||||
else -> types
|
else -> types
|
||||||
}
|
}
|
||||||
|
|
||||||
val annotations = member.getParameterAnnotations()
|
val annotations = member.parameterAnnotations
|
||||||
val realAnnotations = when {
|
val realAnnotations = when {
|
||||||
annotations.size < realTypes.size -> throw IllegalStateException("Illegal generic signature: $member")
|
annotations.size < realTypes.size -> throw IllegalStateException("Illegal generic signature: $member")
|
||||||
annotations.size > realTypes.size -> annotations.copyOfRange(annotations.size - realTypes.size, annotations.size)
|
annotations.size > realTypes.size -> annotations.copyOfRange(annotations.size - realTypes.size, annotations.size)
|
||||||
else -> annotations
|
else -> annotations
|
||||||
}
|
}
|
||||||
|
|
||||||
return getValueParameters(realTypes, realAnnotations, member.isVarArgs())
|
return getValueParameters(realTypes, realAnnotations, member.isVarArgs)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getTypeParameters(): List<JavaTypeParameter> {
|
override fun getTypeParameters(): List<JavaTypeParameter> {
|
||||||
|
|||||||
+1
-1
@@ -18,4 +18,4 @@ package org.jetbrains.kotlin.load.java.structure.reflect
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.load.java.structure.JavaElement
|
import org.jetbrains.kotlin.load.java.structure.JavaElement
|
||||||
|
|
||||||
public abstract class ReflectJavaElement : JavaElement
|
abstract class ReflectJavaElement : JavaElement
|
||||||
|
|||||||
+3
-3
@@ -19,8 +19,8 @@ package org.jetbrains.kotlin.load.java.structure.reflect
|
|||||||
import org.jetbrains.kotlin.load.java.structure.JavaField
|
import org.jetbrains.kotlin.load.java.structure.JavaField
|
||||||
import java.lang.reflect.Field
|
import java.lang.reflect.Field
|
||||||
|
|
||||||
public class ReflectJavaField(override val member: Field) : ReflectJavaMember(), JavaField {
|
class ReflectJavaField(override val member: Field) : ReflectJavaMember(), JavaField {
|
||||||
override fun isEnumEntry() = member.isEnumConstant()
|
override fun isEnumEntry() = member.isEnumConstant
|
||||||
|
|
||||||
override fun getType() = ReflectJavaType.create(member.getGenericType())
|
override fun getType() = ReflectJavaType.create(member.genericType)
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-6
@@ -26,16 +26,16 @@ import java.lang.reflect.Method
|
|||||||
import java.lang.reflect.Type
|
import java.lang.reflect.Type
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
public abstract class ReflectJavaMember : ReflectJavaElement(), ReflectJavaAnnotationOwner, ReflectJavaModifierListOwner, JavaMember {
|
abstract class ReflectJavaMember : ReflectJavaElement(), ReflectJavaAnnotationOwner, ReflectJavaModifierListOwner, JavaMember {
|
||||||
public abstract val member: Member
|
abstract val member: Member
|
||||||
|
|
||||||
override val element: AnnotatedElement get() = member as AnnotatedElement
|
override val element: AnnotatedElement get() = member as AnnotatedElement
|
||||||
|
|
||||||
override val modifiers: Int get() = member.getModifiers()
|
override val modifiers: Int get() = member.modifiers
|
||||||
|
|
||||||
override fun getName() = member.getName()?.let { Name.identifier(it) } ?: SpecialNames.NO_NAME_PROVIDED
|
override fun getName() = member.name?.let { Name.identifier(it) } ?: SpecialNames.NO_NAME_PROVIDED
|
||||||
|
|
||||||
override fun getContainingClass() = ReflectJavaClass(member.getDeclaringClass())
|
override fun getContainingClass() = ReflectJavaClass(member.declaringClass)
|
||||||
|
|
||||||
protected fun getValueParameters(
|
protected fun getValueParameters(
|
||||||
parameterTypes: Array<Type>,
|
parameterTypes: Array<Type>,
|
||||||
@@ -57,7 +57,7 @@ public abstract class ReflectJavaMember : ReflectJavaElement(), ReflectJavaAnnot
|
|||||||
|
|
||||||
override fun hashCode() = member.hashCode()
|
override fun hashCode() = member.hashCode()
|
||||||
|
|
||||||
override fun toString() = javaClass.getName() + ": " + member
|
override fun toString() = javaClass.name + ": " + member
|
||||||
}
|
}
|
||||||
|
|
||||||
private object Java8ParameterNamesLoader {
|
private object Java8ParameterNamesLoader {
|
||||||
|
|||||||
+5
-5
@@ -20,13 +20,13 @@ import org.jetbrains.kotlin.load.java.structure.JavaMethod
|
|||||||
import org.jetbrains.kotlin.load.java.structure.JavaValueParameter
|
import org.jetbrains.kotlin.load.java.structure.JavaValueParameter
|
||||||
import java.lang.reflect.Method
|
import java.lang.reflect.Method
|
||||||
|
|
||||||
public class ReflectJavaMethod(override val member: Method) : ReflectJavaMember(), JavaMethod {
|
class ReflectJavaMethod(override val member: Method) : ReflectJavaMember(), JavaMethod {
|
||||||
override fun getValueParameters(): List<JavaValueParameter> =
|
override fun getValueParameters(): List<JavaValueParameter> =
|
||||||
getValueParameters(member.getGenericParameterTypes(), member.getParameterAnnotations(), member.isVarArgs())
|
getValueParameters(member.genericParameterTypes, member.parameterAnnotations, member.isVarArgs)
|
||||||
|
|
||||||
override fun getReturnType() = ReflectJavaType.create(member.getGenericReturnType())
|
override fun getReturnType() = ReflectJavaType.create(member.genericReturnType)
|
||||||
|
|
||||||
override fun hasAnnotationParameterDefaultValue() = member.getDefaultValue() != null
|
override fun hasAnnotationParameterDefaultValue() = member.defaultValue != null
|
||||||
|
|
||||||
override fun getTypeParameters() = member.getTypeParameters().map { ReflectJavaTypeParameter(it) }
|
override fun getTypeParameters() = member.typeParameters.map { ReflectJavaTypeParameter(it) }
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -21,7 +21,7 @@ import org.jetbrains.kotlin.load.java.JavaVisibilities
|
|||||||
import org.jetbrains.kotlin.load.java.structure.JavaModifierListOwner
|
import org.jetbrains.kotlin.load.java.structure.JavaModifierListOwner
|
||||||
import java.lang.reflect.Modifier
|
import java.lang.reflect.Modifier
|
||||||
|
|
||||||
public interface ReflectJavaModifierListOwner : JavaModifierListOwner {
|
interface ReflectJavaModifierListOwner : JavaModifierListOwner {
|
||||||
/* protected // KT-3029 */ val modifiers: Int
|
/* protected // KT-3029 */ val modifiers: Int
|
||||||
|
|
||||||
override fun isAbstract() = Modifier.isAbstract(modifiers)
|
override fun isAbstract() = Modifier.isAbstract(modifiers)
|
||||||
|
|||||||
+2
-2
@@ -21,7 +21,7 @@ import org.jetbrains.kotlin.load.java.structure.JavaPackage
|
|||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
|
|
||||||
public class ReflectJavaPackage(private val fqName: FqName) : ReflectJavaElement(), JavaPackage {
|
class ReflectJavaPackage(private val fqName: FqName) : ReflectJavaElement(), JavaPackage {
|
||||||
override fun getFqName() = fqName
|
override fun getFqName() = fqName
|
||||||
|
|
||||||
override fun getClasses(nameFilter: (Name) -> Boolean): Collection<JavaClass> {
|
override fun getClasses(nameFilter: (Name) -> Boolean): Collection<JavaClass> {
|
||||||
@@ -38,5 +38,5 @@ public class ReflectJavaPackage(private val fqName: FqName) : ReflectJavaElement
|
|||||||
|
|
||||||
override fun hashCode() = fqName.hashCode()
|
override fun hashCode() = fqName.hashCode()
|
||||||
|
|
||||||
override fun toString() = javaClass.getName() + ": " + fqName
|
override fun toString() = javaClass.name + ": " + fqName
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -19,8 +19,8 @@ package org.jetbrains.kotlin.load.java.structure.reflect
|
|||||||
import org.jetbrains.kotlin.load.java.structure.JavaPrimitiveType
|
import org.jetbrains.kotlin.load.java.structure.JavaPrimitiveType
|
||||||
import org.jetbrains.kotlin.resolve.jvm.JvmPrimitiveType
|
import org.jetbrains.kotlin.resolve.jvm.JvmPrimitiveType
|
||||||
|
|
||||||
public class ReflectJavaPrimitiveType(override val type: Class<*>) : ReflectJavaType(), JavaPrimitiveType {
|
class ReflectJavaPrimitiveType(override val type: Class<*>) : ReflectJavaType(), JavaPrimitiveType {
|
||||||
override fun getType() =
|
override fun getType() =
|
||||||
if (type == Void.TYPE) null
|
if (type == Void.TYPE) null
|
||||||
else JvmPrimitiveType.get(type.getName()).getPrimitiveType()
|
else JvmPrimitiveType.get(type.name).primitiveType
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -22,7 +22,7 @@ import java.lang.reflect.GenericArrayType
|
|||||||
import java.lang.reflect.Type
|
import java.lang.reflect.Type
|
||||||
import java.lang.reflect.WildcardType
|
import java.lang.reflect.WildcardType
|
||||||
|
|
||||||
public abstract class ReflectJavaType : JavaType {
|
abstract class ReflectJavaType : JavaType {
|
||||||
protected abstract val type: Type
|
protected abstract val type: Type
|
||||||
|
|
||||||
override fun createArrayType(): JavaArrayType = throw UnsupportedOperationException()
|
override fun createArrayType(): JavaArrayType = throw UnsupportedOperationException()
|
||||||
@@ -30,8 +30,8 @@ public abstract class ReflectJavaType : JavaType {
|
|||||||
companion object Factory {
|
companion object Factory {
|
||||||
fun create(type: Type): ReflectJavaType {
|
fun create(type: Type): ReflectJavaType {
|
||||||
return when {
|
return when {
|
||||||
type is Class<*> && type.isPrimitive() -> ReflectJavaPrimitiveType(type)
|
type is Class<*> && type.isPrimitive -> ReflectJavaPrimitiveType(type)
|
||||||
type is GenericArrayType || type is Class<*> && type.isArray() -> ReflectJavaArrayType(type)
|
type is GenericArrayType || type is Class<*> && type.isArray -> ReflectJavaArrayType(type)
|
||||||
type is WildcardType -> ReflectJavaWildcardType(type)
|
type is WildcardType -> ReflectJavaWildcardType(type)
|
||||||
else -> ReflectJavaClassifierType(type)
|
else -> ReflectJavaClassifierType(type)
|
||||||
}
|
}
|
||||||
@@ -42,5 +42,5 @@ public abstract class ReflectJavaType : JavaType {
|
|||||||
|
|
||||||
override fun hashCode() = type.hashCode()
|
override fun hashCode() = type.hashCode()
|
||||||
|
|
||||||
override fun toString() = javaClass.getName() + ": " + type
|
override fun toString() = javaClass.name + ": " + type
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-6
@@ -25,17 +25,17 @@ import java.lang.reflect.Constructor
|
|||||||
import java.lang.reflect.Method
|
import java.lang.reflect.Method
|
||||||
import java.lang.reflect.TypeVariable
|
import java.lang.reflect.TypeVariable
|
||||||
|
|
||||||
public class ReflectJavaTypeParameter(
|
class ReflectJavaTypeParameter(
|
||||||
public val typeVariable: TypeVariable<*>
|
val typeVariable: TypeVariable<*>
|
||||||
) : ReflectJavaElement(), JavaTypeParameter {
|
) : ReflectJavaElement(), JavaTypeParameter {
|
||||||
override fun getUpperBounds(): List<ReflectJavaClassifierType> {
|
override fun getUpperBounds(): List<ReflectJavaClassifierType> {
|
||||||
val bounds = typeVariable.getBounds().map { bound -> ReflectJavaClassifierType(bound) }
|
val bounds = typeVariable.bounds.map { bound -> ReflectJavaClassifierType(bound) }
|
||||||
if (bounds.singleOrNull()?.type == Any::class.java) return emptyList()
|
if (bounds.singleOrNull()?.type == Any::class.java) return emptyList()
|
||||||
return bounds
|
return bounds
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getOwner(): JavaTypeParameterListOwner? {
|
override fun getOwner(): JavaTypeParameterListOwner? {
|
||||||
val owner = typeVariable.getGenericDeclaration()
|
val owner = typeVariable.genericDeclaration
|
||||||
return when (owner) {
|
return when (owner) {
|
||||||
is Class<*> -> ReflectJavaClass(owner)
|
is Class<*> -> ReflectJavaClass(owner)
|
||||||
is Method -> ReflectJavaMethod(owner)
|
is Method -> ReflectJavaMethod(owner)
|
||||||
@@ -48,11 +48,11 @@ public class ReflectJavaTypeParameter(
|
|||||||
|
|
||||||
override fun getTypeProvider(): JavaTypeProvider = throw UnsupportedOperationException()
|
override fun getTypeProvider(): JavaTypeProvider = throw UnsupportedOperationException()
|
||||||
|
|
||||||
override fun getName() = Name.identifier(typeVariable.getName())
|
override fun getName() = Name.identifier(typeVariable.name)
|
||||||
|
|
||||||
override fun equals(other: Any?) = other is ReflectJavaTypeParameter && typeVariable == other.typeVariable
|
override fun equals(other: Any?) = other is ReflectJavaTypeParameter && typeVariable == other.typeVariable
|
||||||
|
|
||||||
override fun hashCode() = typeVariable.hashCode()
|
override fun hashCode() = typeVariable.hashCode()
|
||||||
|
|
||||||
override fun toString() = javaClass.getName() + ": " + typeVariable
|
override fun toString() = javaClass.name + ": " + typeVariable
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -21,7 +21,7 @@ import org.jetbrains.kotlin.name.FqName
|
|||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.name.Name.guess
|
import org.jetbrains.kotlin.name.Name.guess
|
||||||
|
|
||||||
public class ReflectJavaValueParameter(
|
class ReflectJavaValueParameter(
|
||||||
private val returnType: ReflectJavaType,
|
private val returnType: ReflectJavaType,
|
||||||
private val annotations: Array<Annotation>,
|
private val annotations: Array<Annotation>,
|
||||||
private val name: String?,
|
private val name: String?,
|
||||||
@@ -37,5 +37,5 @@ public class ReflectJavaValueParameter(
|
|||||||
override fun getType() = returnType
|
override fun getType() = returnType
|
||||||
override fun isVararg() = isVararg
|
override fun isVararg() = isVararg
|
||||||
|
|
||||||
override fun toString() = javaClass.getName() + ": " + (if (isVararg) "vararg " else "") + getName() + ": " + returnType
|
override fun toString() = javaClass.name + ": " + (if (isVararg) "vararg " else "") + getName() + ": " + returnType
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -20,10 +20,10 @@ import org.jetbrains.kotlin.load.java.structure.JavaTypeProvider
|
|||||||
import org.jetbrains.kotlin.load.java.structure.JavaWildcardType
|
import org.jetbrains.kotlin.load.java.structure.JavaWildcardType
|
||||||
import java.lang.reflect.WildcardType
|
import java.lang.reflect.WildcardType
|
||||||
|
|
||||||
public class ReflectJavaWildcardType(override val type: WildcardType): ReflectJavaType(), JavaWildcardType {
|
class ReflectJavaWildcardType(override val type: WildcardType): ReflectJavaType(), JavaWildcardType {
|
||||||
override fun getBound(): ReflectJavaType? {
|
override fun getBound(): ReflectJavaType? {
|
||||||
val upperBounds = type.getUpperBounds()
|
val upperBounds = type.upperBounds
|
||||||
val lowerBounds = type.getLowerBounds()
|
val lowerBounds = type.lowerBounds
|
||||||
if (upperBounds.size > 1 || lowerBounds.size > 1) {
|
if (upperBounds.size > 1 || lowerBounds.size > 1) {
|
||||||
throw UnsupportedOperationException("Wildcard types with many bounds are not yet supported: $type")
|
throw UnsupportedOperationException("Wildcard types with many bounds are not yet supported: $type")
|
||||||
}
|
}
|
||||||
@@ -34,7 +34,7 @@ public class ReflectJavaWildcardType(override val type: WildcardType): ReflectJa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun isExtends() = type.getUpperBounds().firstOrNull() != Any::class.java
|
override fun isExtends() = type.upperBounds.firstOrNull() != Any::class.java
|
||||||
|
|
||||||
override fun getTypeProvider(): JavaTypeProvider = throw UnsupportedOperationException()
|
override fun getTypeProvider(): JavaTypeProvider = throw UnsupportedOperationException()
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-11
@@ -21,33 +21,33 @@ import org.jetbrains.kotlin.name.FqName
|
|||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import java.lang.reflect.Array
|
import java.lang.reflect.Array
|
||||||
|
|
||||||
public val Class<*>.safeClassLoader: ClassLoader
|
val Class<*>.safeClassLoader: ClassLoader
|
||||||
get() = classLoader ?: ClassLoader.getSystemClassLoader()
|
get() = classLoader ?: ClassLoader.getSystemClassLoader()
|
||||||
|
|
||||||
public fun Class<*>.isEnumClassOrSpecializedEnumEntryClass(): Boolean =
|
fun Class<*>.isEnumClassOrSpecializedEnumEntryClass(): Boolean =
|
||||||
Enum::class.java.isAssignableFrom(this)
|
Enum::class.java.isAssignableFrom(this)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* NOTE: does not perform a Java -> Kotlin mapping. If this is not expected, consider using KClassImpl#classId instead
|
* NOTE: does not perform a Java -> Kotlin mapping. If this is not expected, consider using KClassImpl#classId instead
|
||||||
*/
|
*/
|
||||||
public val Class<*>.classId: ClassId
|
val Class<*>.classId: ClassId
|
||||||
get() = when {
|
get() = when {
|
||||||
isPrimitive() -> throw IllegalArgumentException("Can't compute ClassId for primitive type: $this")
|
isPrimitive -> throw IllegalArgumentException("Can't compute ClassId for primitive type: $this")
|
||||||
isArray() -> throw IllegalArgumentException("Can't compute ClassId for array type: $this")
|
isArray -> throw IllegalArgumentException("Can't compute ClassId for array type: $this")
|
||||||
getEnclosingMethod() != null || getEnclosingConstructor() != null || getSimpleName().isEmpty() -> {
|
enclosingMethod != null || enclosingConstructor != null || simpleName.isEmpty() -> {
|
||||||
val fqName = FqName(getName())
|
val fqName = FqName(name)
|
||||||
ClassId(fqName.parent(), FqName.topLevel(fqName.shortName()), /* local = */ true)
|
ClassId(fqName.parent(), FqName.topLevel(fqName.shortName()), /* local = */ true)
|
||||||
}
|
}
|
||||||
else -> getDeclaringClass()?.classId?.createNestedClassId(Name.identifier(getSimpleName())) ?: ClassId.topLevel(FqName(getName()))
|
else -> declaringClass?.classId?.createNestedClassId(Name.identifier(simpleName)) ?: ClassId.topLevel(FqName(name))
|
||||||
}
|
}
|
||||||
|
|
||||||
public val Class<*>.desc: String
|
val Class<*>.desc: String
|
||||||
get() {
|
get() {
|
||||||
if (this == Void.TYPE) return "V"
|
if (this == Void.TYPE) return "V"
|
||||||
// This is a clever exploitation of a format returned by Class.getName(): for arrays, it's almost an internal name,
|
// This is a clever exploitation of a format returned by Class.getName(): for arrays, it's almost an internal name,
|
||||||
// but with '.' instead of '/'
|
// but with '.' instead of '/'
|
||||||
return createArrayType().getName().substring(1).replace('.', '/')
|
return createArrayType().name.substring(1).replace('.', '/')
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun Class<*>.createArrayType(): Class<*> =
|
fun Class<*>.createArrayType(): Class<*> =
|
||||||
Array.newInstance(this, 0).javaClass
|
Array.newInstance(this, 0).javaClass
|
||||||
|
|||||||
+1
-1
@@ -19,6 +19,6 @@ package org.jetbrains.kotlin.load.kotlin.reflect
|
|||||||
import org.jetbrains.kotlin.descriptors.SourceElement
|
import org.jetbrains.kotlin.descriptors.SourceElement
|
||||||
import org.jetbrains.kotlin.descriptors.SourceFile
|
import org.jetbrains.kotlin.descriptors.SourceFile
|
||||||
|
|
||||||
public class ReflectAnnotationSource(public val annotation: Annotation) : SourceElement {
|
class ReflectAnnotationSource(val annotation: Annotation) : SourceElement {
|
||||||
override fun getContainingFile(): SourceFile = SourceFile.NO_SOURCE_FILE
|
override fun getContainingFile(): SourceFile = SourceFile.NO_SOURCE_FILE
|
||||||
}
|
}
|
||||||
|
|||||||
+28
-28
@@ -39,21 +39,21 @@ private val TYPES_ELIGIBLE_FOR_SIMPLE_VISIT = setOf<Class<*>>(
|
|||||||
Class::class.java, String::class.java
|
Class::class.java, String::class.java
|
||||||
)
|
)
|
||||||
|
|
||||||
public class ReflectKotlinClass private constructor(
|
class ReflectKotlinClass private constructor(
|
||||||
public val klass: Class<*>,
|
val klass: Class<*>,
|
||||||
private val classHeader: KotlinClassHeader
|
private val classHeader: KotlinClassHeader
|
||||||
) : KotlinJvmBinaryClass {
|
) : KotlinJvmBinaryClass {
|
||||||
|
|
||||||
companion object Factory {
|
companion object Factory {
|
||||||
|
|
||||||
public fun create(klass: Class<*>): ReflectKotlinClass? {
|
fun create(klass: Class<*>): ReflectKotlinClass? {
|
||||||
val headerReader = ReadKotlinClassHeaderAnnotationVisitor()
|
val headerReader = ReadKotlinClassHeaderAnnotationVisitor()
|
||||||
ReflectClassStructure.loadClassAnnotations(klass, headerReader)
|
ReflectClassStructure.loadClassAnnotations(klass, headerReader)
|
||||||
return ReflectKotlinClass(klass, headerReader.createHeader() ?: return null)
|
return ReflectKotlinClass(klass, headerReader.createHeader() ?: return null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getLocation() = klass.getName().replace('.', '/') + ".class"
|
override fun getLocation() = klass.name.replace('.', '/') + ".class"
|
||||||
|
|
||||||
override fun getClassId() = klass.classId
|
override fun getClassId() = klass.classId
|
||||||
|
|
||||||
@@ -71,12 +71,12 @@ public class ReflectKotlinClass private constructor(
|
|||||||
|
|
||||||
override fun hashCode() = klass.hashCode()
|
override fun hashCode() = klass.hashCode()
|
||||||
|
|
||||||
override fun toString() = javaClass.getName() + ": " + klass
|
override fun toString() = javaClass.name + ": " + klass
|
||||||
}
|
}
|
||||||
|
|
||||||
private object ReflectClassStructure {
|
private object ReflectClassStructure {
|
||||||
fun loadClassAnnotations(klass: Class<*>, visitor: KotlinJvmBinaryClass.AnnotationVisitor) {
|
fun loadClassAnnotations(klass: Class<*>, visitor: KotlinJvmBinaryClass.AnnotationVisitor) {
|
||||||
for (annotation in klass.getDeclaredAnnotations()) {
|
for (annotation in klass.declaredAnnotations) {
|
||||||
processAnnotation(visitor, annotation)
|
processAnnotation(visitor, annotation)
|
||||||
}
|
}
|
||||||
visitor.visitEnd()
|
visitor.visitEnd()
|
||||||
@@ -89,14 +89,14 @@ private object ReflectClassStructure {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun loadMethodAnnotations(klass: Class<*>, memberVisitor: KotlinJvmBinaryClass.MemberVisitor) {
|
private fun loadMethodAnnotations(klass: Class<*>, memberVisitor: KotlinJvmBinaryClass.MemberVisitor) {
|
||||||
for (method in klass.getDeclaredMethods()) {
|
for (method in klass.declaredMethods) {
|
||||||
val visitor = memberVisitor.visitMethod(Name.identifier(method.getName()), SignatureSerializer.methodDesc(method)) ?: continue
|
val visitor = memberVisitor.visitMethod(Name.identifier(method.name), SignatureSerializer.methodDesc(method)) ?: continue
|
||||||
|
|
||||||
for (annotation in method.getDeclaredAnnotations()) {
|
for (annotation in method.declaredAnnotations) {
|
||||||
processAnnotation(visitor, annotation)
|
processAnnotation(visitor, annotation)
|
||||||
}
|
}
|
||||||
|
|
||||||
for ((parameterIndex, annotations) in method.getParameterAnnotations().withIndex()) {
|
for ((parameterIndex, annotations) in method.parameterAnnotations.withIndex()) {
|
||||||
for (annotation in annotations) {
|
for (annotation in annotations) {
|
||||||
val annotationType = annotation.annotationClass.java
|
val annotationType = annotation.annotationClass.java
|
||||||
visitor.visitParameterAnnotation(parameterIndex, annotationType.classId, ReflectAnnotationSource(annotation))?.let {
|
visitor.visitParameterAnnotation(parameterIndex, annotationType.classId, ReflectAnnotationSource(annotation))?.let {
|
||||||
@@ -110,14 +110,14 @@ private object ReflectClassStructure {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun loadConstructorAnnotations(klass: Class<*>, memberVisitor: KotlinJvmBinaryClass.MemberVisitor) {
|
private fun loadConstructorAnnotations(klass: Class<*>, memberVisitor: KotlinJvmBinaryClass.MemberVisitor) {
|
||||||
for (constructor in klass.getDeclaredConstructors()) {
|
for (constructor in klass.declaredConstructors) {
|
||||||
val visitor = memberVisitor.visitMethod(Name.special("<init>"), SignatureSerializer.constructorDesc(constructor)) ?: continue
|
val visitor = memberVisitor.visitMethod(Name.special("<init>"), SignatureSerializer.constructorDesc(constructor)) ?: continue
|
||||||
|
|
||||||
for (annotation in constructor.getDeclaredAnnotations()) {
|
for (annotation in constructor.declaredAnnotations) {
|
||||||
processAnnotation(visitor, annotation)
|
processAnnotation(visitor, annotation)
|
||||||
}
|
}
|
||||||
|
|
||||||
val parameterAnnotations = constructor.getParameterAnnotations()
|
val parameterAnnotations = constructor.parameterAnnotations
|
||||||
if (parameterAnnotations.isNotEmpty()) {
|
if (parameterAnnotations.isNotEmpty()) {
|
||||||
// Constructors of some classes have additional synthetic parameters:
|
// Constructors of some classes have additional synthetic parameters:
|
||||||
// - inner classes have one parameter, instance of the outer class
|
// - inner classes have one parameter, instance of the outer class
|
||||||
@@ -125,7 +125,7 @@ private object ReflectClassStructure {
|
|||||||
// - local/anonymous classes may have many parameters for captured values
|
// - local/anonymous classes may have many parameters for captured values
|
||||||
// At the moment this seems like a working heuristic for computing number of synthetic parameters for Kotlin classes,
|
// At the moment this seems like a working heuristic for computing number of synthetic parameters for Kotlin classes,
|
||||||
// although this is wrong and likely to change, see KT-6886
|
// although this is wrong and likely to change, see KT-6886
|
||||||
val shift = constructor.getParameterTypes().size - parameterAnnotations.size
|
val shift = constructor.parameterTypes.size - parameterAnnotations.size
|
||||||
|
|
||||||
for ((parameterIndex, annotations) in parameterAnnotations.withIndex()) {
|
for ((parameterIndex, annotations) in parameterAnnotations.withIndex()) {
|
||||||
for (annotation in annotations) {
|
for (annotation in annotations) {
|
||||||
@@ -144,10 +144,10 @@ private object ReflectClassStructure {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun loadFieldAnnotations(klass: Class<*>, memberVisitor: KotlinJvmBinaryClass.MemberVisitor) {
|
private fun loadFieldAnnotations(klass: Class<*>, memberVisitor: KotlinJvmBinaryClass.MemberVisitor) {
|
||||||
for (field in klass.getDeclaredFields()) {
|
for (field in klass.declaredFields) {
|
||||||
val visitor = memberVisitor.visitField(Name.identifier(field.getName()), SignatureSerializer.fieldDesc(field), null) ?: continue
|
val visitor = memberVisitor.visitField(Name.identifier(field.name), SignatureSerializer.fieldDesc(field), null) ?: continue
|
||||||
|
|
||||||
for (annotation in field.getDeclaredAnnotations()) {
|
for (annotation in field.declaredAnnotations) {
|
||||||
processAnnotation(visitor, annotation)
|
processAnnotation(visitor, annotation)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,8 +167,8 @@ private object ReflectClassStructure {
|
|||||||
annotation: Annotation,
|
annotation: Annotation,
|
||||||
annotationType: Class<*>
|
annotationType: Class<*>
|
||||||
) {
|
) {
|
||||||
for (method in annotationType.getDeclaredMethods()) {
|
for (method in annotationType.declaredMethods) {
|
||||||
processAnnotationArgumentValue(visitor, Name.identifier(method.getName()), method(annotation)!!)
|
processAnnotationArgumentValue(visitor, Name.identifier(method.name), method(annotation)!!)
|
||||||
}
|
}
|
||||||
visitor.visitEnd()
|
visitor.visitEnd()
|
||||||
}
|
}
|
||||||
@@ -181,18 +181,18 @@ private object ReflectClassStructure {
|
|||||||
}
|
}
|
||||||
clazz.isEnumClassOrSpecializedEnumEntryClass() -> {
|
clazz.isEnumClassOrSpecializedEnumEntryClass() -> {
|
||||||
// isEnum returns false for specialized enum constants (enum entries which are anonymous enum subclasses)
|
// isEnum returns false for specialized enum constants (enum entries which are anonymous enum subclasses)
|
||||||
val classId = (if (clazz.isEnum()) clazz else clazz.getEnclosingClass()).classId
|
val classId = (if (clazz.isEnum) clazz else clazz.enclosingClass).classId
|
||||||
visitor.visitEnum(name, classId, Name.identifier((value as Enum<*>).name))
|
visitor.visitEnum(name, classId, Name.identifier((value as Enum<*>).name))
|
||||||
}
|
}
|
||||||
Annotation::class.java.isAssignableFrom(clazz) -> {
|
Annotation::class.java.isAssignableFrom(clazz) -> {
|
||||||
val annotationClass = clazz.getInterfaces().single()
|
val annotationClass = clazz.interfaces.single()
|
||||||
val v = visitor.visitAnnotation(name, annotationClass.classId) ?: return
|
val v = visitor.visitAnnotation(name, annotationClass.classId) ?: return
|
||||||
processAnnotationArguments(v, value as Annotation, annotationClass)
|
processAnnotationArguments(v, value as Annotation, annotationClass)
|
||||||
}
|
}
|
||||||
clazz.isArray() -> {
|
clazz.isArray -> {
|
||||||
val v = visitor.visitArray(name) ?: return
|
val v = visitor.visitArray(name) ?: return
|
||||||
val componentType = clazz.getComponentType()
|
val componentType = clazz.componentType
|
||||||
if (componentType.isEnum()) {
|
if (componentType.isEnum) {
|
||||||
val enumClassId = componentType.classId
|
val enumClassId = componentType.classId
|
||||||
for (element in value as Array<*>) {
|
for (element in value as Array<*>) {
|
||||||
v.visitEnum(enumClassId, Name.identifier((element as Enum<*>).name))
|
v.visitEnum(enumClassId, Name.identifier((element as Enum<*>).name))
|
||||||
@@ -216,18 +216,18 @@ private object SignatureSerializer {
|
|||||||
fun methodDesc(method: Method): String {
|
fun methodDesc(method: Method): String {
|
||||||
val sb = StringBuilder()
|
val sb = StringBuilder()
|
||||||
sb.append("(")
|
sb.append("(")
|
||||||
for (parameterType in method.getParameterTypes()) {
|
for (parameterType in method.parameterTypes) {
|
||||||
sb.append(parameterType.desc)
|
sb.append(parameterType.desc)
|
||||||
}
|
}
|
||||||
sb.append(")")
|
sb.append(")")
|
||||||
sb.append(method.getReturnType().desc)
|
sb.append(method.returnType.desc)
|
||||||
return sb.toString()
|
return sb.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun constructorDesc(constructor: Constructor<*>): String {
|
fun constructorDesc(constructor: Constructor<*>): String {
|
||||||
val sb = StringBuilder()
|
val sb = StringBuilder()
|
||||||
sb.append("(")
|
sb.append("(")
|
||||||
for (parameterType in constructor.getParameterTypes()) {
|
for (parameterType in constructor.parameterTypes) {
|
||||||
sb.append(parameterType.desc)
|
sb.append(parameterType.desc)
|
||||||
}
|
}
|
||||||
sb.append(")V")
|
sb.append(")V")
|
||||||
@@ -235,6 +235,6 @@ private object SignatureSerializer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun fieldDesc(field: Field): String {
|
fun fieldDesc(field: Field): String {
|
||||||
return field.getType().desc
|
return field.type.desc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -22,7 +22,7 @@ import org.jetbrains.kotlin.load.kotlin.KotlinClassFinder
|
|||||||
import org.jetbrains.kotlin.load.kotlin.KotlinJvmBinaryClass
|
import org.jetbrains.kotlin.load.kotlin.KotlinJvmBinaryClass
|
||||||
import org.jetbrains.kotlin.name.ClassId
|
import org.jetbrains.kotlin.name.ClassId
|
||||||
|
|
||||||
public class ReflectKotlinClassFinder(private val classLoader: ClassLoader) : KotlinClassFinder {
|
class ReflectKotlinClassFinder(private val classLoader: ClassLoader) : KotlinClassFinder {
|
||||||
private fun findKotlinClass(fqName: String): KotlinJvmBinaryClass? {
|
private fun findKotlinClass(fqName: String): KotlinJvmBinaryClass? {
|
||||||
return classLoader.tryLoadClass(fqName)?.let { ReflectKotlinClass.create(it) }
|
return classLoader.tryLoadClass(fqName)?.let { ReflectKotlinClass.create(it) }
|
||||||
}
|
}
|
||||||
@@ -31,11 +31,11 @@ public class ReflectKotlinClassFinder(private val classLoader: ClassLoader) : Ko
|
|||||||
|
|
||||||
override fun findKotlinClass(javaClass: JavaClass): KotlinJvmBinaryClass? {
|
override fun findKotlinClass(javaClass: JavaClass): KotlinJvmBinaryClass? {
|
||||||
// TODO: go through javaClass's class loader
|
// TODO: go through javaClass's class loader
|
||||||
return findKotlinClass(javaClass.getFqName()?.asString() ?: return null)
|
return findKotlinClass(javaClass.fqName?.asString() ?: return null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun ClassId.toRuntimeFqName(): String {
|
private fun ClassId.toRuntimeFqName(): String {
|
||||||
val className = getRelativeClassName().asString().replace('.', '$')
|
val className = relativeClassName.asString().replace('.', '$')
|
||||||
return if (getPackageFqName().isRoot()) className else "${getPackageFqName()}.$className"
|
return if (packageFqName.isRoot) className else "${packageFqName}.$className"
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -40,12 +40,12 @@ import org.jetbrains.kotlin.serialization.deserialization.DeserializationCompone
|
|||||||
import org.jetbrains.kotlin.serialization.deserialization.LocalClassResolver
|
import org.jetbrains.kotlin.serialization.deserialization.LocalClassResolver
|
||||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
||||||
|
|
||||||
public class RuntimeModuleData private constructor(public val deserialization: DeserializationComponents, val packageFacadeProvider: RuntimePackagePartProvider) {
|
class RuntimeModuleData private constructor(val deserialization: DeserializationComponents, val packageFacadeProvider: RuntimePackagePartProvider) {
|
||||||
public val module: ModuleDescriptor get() = deserialization.moduleDescriptor
|
val module: ModuleDescriptor get() = deserialization.moduleDescriptor
|
||||||
public val localClassResolver: LocalClassResolver get() = deserialization.localClassResolver
|
val localClassResolver: LocalClassResolver get() = deserialization.localClassResolver
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
public fun create(classLoader: ClassLoader): RuntimeModuleData {
|
fun create(classLoader: ClassLoader): RuntimeModuleData {
|
||||||
val builtIns = JvmBuiltIns.Instance
|
val builtIns = JvmBuiltIns.Instance
|
||||||
val storageManager = LockBasedStorageManager()
|
val storageManager = LockBasedStorageManager()
|
||||||
val module = ModuleDescriptorImpl(Name.special("<runtime module for $classLoader>"), storageManager,
|
val module = ModuleDescriptorImpl(Name.special("<runtime module for $classLoader>"), storageManager,
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ package org.jetbrains.kotlin.builtins
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.utils.sure
|
import org.jetbrains.kotlin.utils.sure
|
||||||
|
|
||||||
public class BuiltInsInitializer<T : KotlinBuiltIns>(
|
class BuiltInsInitializer<T : KotlinBuiltIns>(
|
||||||
private val constructor: () -> T
|
private val constructor: () -> T
|
||||||
) {
|
) {
|
||||||
@Volatile private var instance: T? = null
|
@Volatile private var instance: T? = null
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ import org.jetbrains.kotlin.storage.StorageManager
|
|||||||
import java.io.DataInputStream
|
import java.io.DataInputStream
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
|
|
||||||
public class BuiltinsPackageFragment(
|
class BuiltinsPackageFragment(
|
||||||
fqName: FqName,
|
fqName: FqName,
|
||||||
storageManager: StorageManager,
|
storageManager: StorageManager,
|
||||||
module: ModuleDescriptor,
|
module: ModuleDescriptor,
|
||||||
@@ -68,7 +68,7 @@ public class BuiltinsPackageFragment(
|
|||||||
)
|
)
|
||||||
} ?: super.computeMemberScope()
|
} ?: super.computeMemberScope()
|
||||||
|
|
||||||
protected override fun loadClassNames(packageProto: ProtoBuf.Package): Collection<Name> {
|
override fun loadClassNames(packageProto: ProtoBuf.Package): Collection<Name> {
|
||||||
return packageProto.getExtension(BuiltInsProtoBuf.className)?.map { id -> nameResolver.getName(id) } ?: listOf()
|
return packageProto.getExtension(BuiltInsProtoBuf.className)?.map { id -> nameResolver.getName(id) } ?: listOf()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,22 +20,22 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
|||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
public class CompanionObjectMapping(private val builtIns: KotlinBuiltIns) {
|
class CompanionObjectMapping(private val builtIns: KotlinBuiltIns) {
|
||||||
private val classes = linkedSetOf<ClassDescriptor>()
|
private val classes = linkedSetOf<ClassDescriptor>()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
for (type in PrimitiveType.NUMBER_TYPES) {
|
for (type in PrimitiveType.NUMBER_TYPES) {
|
||||||
classes.add(builtIns.getPrimitiveClassDescriptor(type))
|
classes.add(builtIns.getPrimitiveClassDescriptor(type))
|
||||||
}
|
}
|
||||||
classes.add(builtIns.getString())
|
classes.add(builtIns.string)
|
||||||
classes.add(builtIns.getEnum())
|
classes.add(builtIns.enum)
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun allClassesWithIntrinsicCompanions(): Set<ClassDescriptor> =
|
fun allClassesWithIntrinsicCompanions(): Set<ClassDescriptor> =
|
||||||
Collections.unmodifiableSet(classes)
|
Collections.unmodifiableSet(classes)
|
||||||
|
|
||||||
public fun hasMappingToObject(classDescriptor: ClassDescriptor): Boolean {
|
fun hasMappingToObject(classDescriptor: ClassDescriptor): Boolean {
|
||||||
return DescriptorUtils.isCompanionObject(classDescriptor) &&
|
return DescriptorUtils.isCompanionObject(classDescriptor) &&
|
||||||
classDescriptor.getContainingDeclaration() in classes
|
classDescriptor.containingDeclaration in classes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ import kotlin.reflect.KProperty
|
|||||||
|
|
||||||
val KOTLIN_REFLECT_FQ_NAME = FqName("kotlin.reflect")
|
val KOTLIN_REFLECT_FQ_NAME = FqName("kotlin.reflect")
|
||||||
|
|
||||||
public class ReflectionTypes(private val module: ModuleDescriptor) {
|
class ReflectionTypes(private val module: ModuleDescriptor) {
|
||||||
private val kotlinReflectScope: MemberScope by lazy {
|
private val kotlinReflectScope: MemberScope by lazy {
|
||||||
module.getPackage(KOTLIN_REFLECT_FQ_NAME).memberScope
|
module.getPackage(KOTLIN_REFLECT_FQ_NAME).memberScope
|
||||||
}
|
}
|
||||||
@@ -49,16 +49,16 @@ public class ReflectionTypes(private val module: ModuleDescriptor) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun getKFunction(n: Int): ClassDescriptor = find("KFunction$n")
|
fun getKFunction(n: Int): ClassDescriptor = find("KFunction$n")
|
||||||
|
|
||||||
public val kClass: ClassDescriptor by ClassLookup
|
val kClass: ClassDescriptor by ClassLookup
|
||||||
public val kProperty0: ClassDescriptor by ClassLookup
|
val kProperty0: ClassDescriptor by ClassLookup
|
||||||
public val kProperty1: ClassDescriptor by ClassLookup
|
val kProperty1: ClassDescriptor by ClassLookup
|
||||||
public val kProperty2: ClassDescriptor by ClassLookup
|
val kProperty2: ClassDescriptor by ClassLookup
|
||||||
public val kMutableProperty0: ClassDescriptor by ClassLookup
|
val kMutableProperty0: ClassDescriptor by ClassLookup
|
||||||
public val kMutableProperty1: ClassDescriptor by ClassLookup
|
val kMutableProperty1: ClassDescriptor by ClassLookup
|
||||||
|
|
||||||
public fun getKClassType(annotations: Annotations, type: KotlinType): KotlinType {
|
fun getKClassType(annotations: Annotations, type: KotlinType): KotlinType {
|
||||||
val descriptor = kClass
|
val descriptor = kClass
|
||||||
if (ErrorUtils.isError(descriptor)) {
|
if (ErrorUtils.isError(descriptor)) {
|
||||||
return descriptor.defaultType
|
return descriptor.defaultType
|
||||||
@@ -68,7 +68,7 @@ public class ReflectionTypes(private val module: ModuleDescriptor) {
|
|||||||
return KotlinTypeImpl.create(annotations, descriptor, false, arguments)
|
return KotlinTypeImpl.create(annotations, descriptor, false, arguments)
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun getKFunctionType(
|
fun getKFunctionType(
|
||||||
annotations: Annotations,
|
annotations: Annotations,
|
||||||
receiverType: KotlinType?,
|
receiverType: KotlinType?,
|
||||||
parameterTypes: List<KotlinType>,
|
parameterTypes: List<KotlinType>,
|
||||||
@@ -85,7 +85,7 @@ public class ReflectionTypes(private val module: ModuleDescriptor) {
|
|||||||
return KotlinTypeImpl.create(annotations, classDescriptor, false, arguments)
|
return KotlinTypeImpl.create(annotations, classDescriptor, false, arguments)
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun getKPropertyType(annotations: Annotations, receiverType: KotlinType?, returnType: KotlinType, mutable: Boolean): KotlinType {
|
fun getKPropertyType(annotations: Annotations, receiverType: KotlinType?, returnType: KotlinType, mutable: Boolean): KotlinType {
|
||||||
val classDescriptor =
|
val classDescriptor =
|
||||||
when {
|
when {
|
||||||
receiverType != null -> when {
|
receiverType != null -> when {
|
||||||
@@ -111,12 +111,12 @@ public class ReflectionTypes(private val module: ModuleDescriptor) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
public fun isReflectionClass(descriptor: ClassDescriptor): Boolean {
|
fun isReflectionClass(descriptor: ClassDescriptor): Boolean {
|
||||||
val containingPackage = DescriptorUtils.getParentOfType(descriptor, PackageFragmentDescriptor::class.java)
|
val containingPackage = DescriptorUtils.getParentOfType(descriptor, PackageFragmentDescriptor::class.java)
|
||||||
return containingPackage != null && containingPackage.fqName == KOTLIN_REFLECT_FQ_NAME
|
return containingPackage != null && containingPackage.fqName == KOTLIN_REFLECT_FQ_NAME
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun isCallableType(type: KotlinType): Boolean =
|
fun isCallableType(type: KotlinType): Boolean =
|
||||||
KotlinBuiltIns.isFunctionOrExtensionFunctionType(type) || isKCallableType(type)
|
KotlinBuiltIns.isFunctionOrExtensionFunctionType(type) || isKCallableType(type)
|
||||||
|
|
||||||
private fun isKCallableType(type: KotlinType): Boolean =
|
private fun isKCallableType(type: KotlinType): Boolean =
|
||||||
@@ -128,7 +128,7 @@ public class ReflectionTypes(private val module: ModuleDescriptor) {
|
|||||||
return descriptor is ClassDescriptor && DescriptorUtils.getFqName(descriptor) == KotlinBuiltIns.FQ_NAMES.kCallable
|
return descriptor is ClassDescriptor && DescriptorUtils.getFqName(descriptor) == KotlinBuiltIns.FQ_NAMES.kCallable
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun createKPropertyStarType(module: ModuleDescriptor): KotlinType? {
|
fun createKPropertyStarType(module: ModuleDescriptor): KotlinType? {
|
||||||
val kPropertyClass = module.findClassAcrossModuleDependencies(KotlinBuiltIns.FQ_NAMES.kProperty) ?: return null
|
val kPropertyClass = module.findClassAcrossModuleDependencies(KotlinBuiltIns.FQ_NAMES.kProperty) ?: return null
|
||||||
return KotlinTypeImpl.create(
|
return KotlinTypeImpl.create(
|
||||||
Annotations.EMPTY, kPropertyClass, false,
|
Annotations.EMPTY, kPropertyClass, false,
|
||||||
|
|||||||
+1
-1
@@ -25,7 +25,7 @@ import org.jetbrains.kotlin.serialization.deserialization.*
|
|||||||
import org.jetbrains.kotlin.storage.StorageManager
|
import org.jetbrains.kotlin.storage.StorageManager
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
|
|
||||||
public fun createBuiltInPackageFragmentProvider(
|
fun createBuiltInPackageFragmentProvider(
|
||||||
storageManager: StorageManager,
|
storageManager: StorageManager,
|
||||||
module: ModuleDescriptor,
|
module: ModuleDescriptor,
|
||||||
packageFqNames: Set<FqName>,
|
packageFqNames: Set<FqName>,
|
||||||
|
|||||||
+2
-3
@@ -27,7 +27,7 @@ import org.jetbrains.kotlin.storage.StorageManager
|
|||||||
/**
|
/**
|
||||||
* Produces descriptors representing the fictitious classes for function types, such as kotlin.Function1 or kotlin.reflect.KFunction2.
|
* Produces descriptors representing the fictitious classes for function types, such as kotlin.Function1 or kotlin.reflect.KFunction2.
|
||||||
*/
|
*/
|
||||||
public class BuiltInFictitiousFunctionClassFactory(
|
class BuiltInFictitiousFunctionClassFactory(
|
||||||
private val storageManager: StorageManager,
|
private val storageManager: StorageManager,
|
||||||
private val module: ModuleDescriptor
|
private val module: ModuleDescriptor
|
||||||
) : ClassDescriptorFactory {
|
) : ClassDescriptorFactory {
|
||||||
@@ -35,8 +35,7 @@ public class BuiltInFictitiousFunctionClassFactory(
|
|||||||
private data class KindWithArity(val kind: Kind, val arity: Int)
|
private data class KindWithArity(val kind: Kind, val arity: Int)
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@JvmStatic
|
@JvmStatic fun parseClassName(className: String, packageFqName: FqName): KindWithArity? {
|
||||||
public fun parseClassName(className: String, packageFqName: FqName): KindWithArity? {
|
|
||||||
val kind = FunctionClassDescriptor.Kind.byPackage(packageFqName) ?: return null
|
val kind = FunctionClassDescriptor.Kind.byPackage(packageFqName) ?: return null
|
||||||
|
|
||||||
val prefix = kind.classNamePrefix
|
val prefix = kind.classNamePrefix
|
||||||
|
|||||||
+8
-8
@@ -40,14 +40,14 @@ import java.util.*
|
|||||||
* If the class represents kotlin.reflect.KFunction1, it has two supertypes: kotlin.Function1 and kotlin.reflect.KFunction.
|
* If the class represents kotlin.reflect.KFunction1, it has two supertypes: kotlin.Function1 and kotlin.reflect.KFunction.
|
||||||
* This allows to use both 'invoke' and reflection API on function references obtained by '::'.
|
* This allows to use both 'invoke' and reflection API on function references obtained by '::'.
|
||||||
*/
|
*/
|
||||||
public class FunctionClassDescriptor(
|
class FunctionClassDescriptor(
|
||||||
private val storageManager: StorageManager,
|
private val storageManager: StorageManager,
|
||||||
private val containingDeclaration: PackageFragmentDescriptor,
|
private val containingDeclaration: PackageFragmentDescriptor,
|
||||||
val functionKind: Kind,
|
val functionKind: Kind,
|
||||||
val arity: Int
|
val arity: Int
|
||||||
) : AbstractClassDescriptor(storageManager, functionKind.numberedClassName(arity)) {
|
) : AbstractClassDescriptor(storageManager, functionKind.numberedClassName(arity)) {
|
||||||
|
|
||||||
public enum class Kind(val packageFqName: FqName, val classNamePrefix: String) {
|
enum class Kind(val packageFqName: FqName, val classNamePrefix: String) {
|
||||||
Function(BUILT_INS_PACKAGE_FQ_NAME, "Function"),
|
Function(BUILT_INS_PACKAGE_FQ_NAME, "Function"),
|
||||||
KFunction(KOTLIN_REFLECT_FQ_NAME, "KFunction");
|
KFunction(KOTLIN_REFLECT_FQ_NAME, "KFunction");
|
||||||
|
|
||||||
@@ -117,11 +117,11 @@ public class FunctionClassDescriptor(
|
|||||||
val descriptor = packageFragment.getMemberScope().getContributedClassifier(name, NoLookupLocation.FROM_BUILTINS) as? ClassDescriptor
|
val descriptor = packageFragment.getMemberScope().getContributedClassifier(name, NoLookupLocation.FROM_BUILTINS) as? ClassDescriptor
|
||||||
?: error("Class $name not found in $packageFragment")
|
?: error("Class $name not found in $packageFragment")
|
||||||
|
|
||||||
val typeConstructor = descriptor.getTypeConstructor()
|
val typeConstructor = descriptor.typeConstructor
|
||||||
|
|
||||||
// Substitute all type parameters of the super class with our last type parameters
|
// Substitute all type parameters of the super class with our last type parameters
|
||||||
val arguments = getParameters().takeLast(typeConstructor.getParameters().size).map {
|
val arguments = getParameters().takeLast(typeConstructor.parameters.size).map {
|
||||||
TypeProjectionImpl(it.getDefaultType())
|
TypeProjectionImpl(it.defaultType)
|
||||||
}
|
}
|
||||||
|
|
||||||
result.add(KotlinTypeImpl.create(Annotations.EMPTY, descriptor, false, arguments))
|
result.add(KotlinTypeImpl.create(Annotations.EMPTY, descriptor, false, arguments))
|
||||||
@@ -132,7 +132,7 @@ public class FunctionClassDescriptor(
|
|||||||
|
|
||||||
// For KFunction{n}, add corresponding numbered Function{n} class, e.g. Function2 for KFunction2
|
// For KFunction{n}, add corresponding numbered Function{n} class, e.g. Function2 for KFunction2
|
||||||
if (functionKind == Kind.KFunction) {
|
if (functionKind == Kind.KFunction) {
|
||||||
val module = containingDeclaration.getContainingDeclaration()
|
val module = containingDeclaration.containingDeclaration
|
||||||
val kotlinPackageFragment = module.getPackage(BUILT_INS_PACKAGE_FQ_NAME).fragments.single()
|
val kotlinPackageFragment = module.getPackage(BUILT_INS_PACKAGE_FQ_NAME).fragments.single()
|
||||||
|
|
||||||
add(kotlinPackageFragment, Kind.Function.numberedClassName(arity))
|
add(kotlinPackageFragment, Kind.Function.numberedClassName(arity))
|
||||||
@@ -150,8 +150,8 @@ public class FunctionClassDescriptor(
|
|||||||
override fun isFinal() = false
|
override fun isFinal() = false
|
||||||
override fun getAnnotations() = Annotations.EMPTY
|
override fun getAnnotations() = Annotations.EMPTY
|
||||||
|
|
||||||
override fun toString() = getDeclarationDescriptor().toString()
|
override fun toString() = declarationDescriptor.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toString() = getName().asString()
|
override fun toString() = name.asString()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,24 +47,24 @@ class FunctionClassScope(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun getContributedFunctions(name: Name, location: LookupLocation): Collection<FunctionDescriptor> {
|
override fun getContributedFunctions(name: Name, location: LookupLocation): Collection<FunctionDescriptor> {
|
||||||
return allDescriptors().filterIsInstance<FunctionDescriptor>().filter { it.getName() == name }
|
return allDescriptors().filterIsInstance<FunctionDescriptor>().filter { it.name == name }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getContributedVariables(name: Name, location: LookupLocation): Collection<PropertyDescriptor> {
|
override fun getContributedVariables(name: Name, location: LookupLocation): Collection<PropertyDescriptor> {
|
||||||
return allDescriptors().filterIsInstance<PropertyDescriptor>().filter { it.getName() == name }
|
return allDescriptors().filterIsInstance<PropertyDescriptor>().filter { it.name == name }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createFakeOverrides(invoke: FunctionDescriptor?): List<DeclarationDescriptor> {
|
private fun createFakeOverrides(invoke: FunctionDescriptor?): List<DeclarationDescriptor> {
|
||||||
val result = ArrayList<DeclarationDescriptor>(3)
|
val result = ArrayList<DeclarationDescriptor>(3)
|
||||||
val allSuperDescriptors = functionClass.getTypeConstructor().getSupertypes()
|
val allSuperDescriptors = functionClass.typeConstructor.supertypes
|
||||||
.flatMap { it.getMemberScope().getContributedDescriptors() }
|
.flatMap { it.memberScope.getContributedDescriptors() }
|
||||||
.filterIsInstance<CallableMemberDescriptor>()
|
.filterIsInstance<CallableMemberDescriptor>()
|
||||||
for ((name, group) in allSuperDescriptors.groupBy { it.getName() }) {
|
for ((name, group) in allSuperDescriptors.groupBy { it.name }) {
|
||||||
for ((isFunction, descriptors) in group.groupBy { it is FunctionDescriptor }) {
|
for ((isFunction, descriptors) in group.groupBy { it is FunctionDescriptor }) {
|
||||||
OverridingUtil.generateOverridesInFunctionGroup(
|
OverridingUtil.generateOverridesInFunctionGroup(
|
||||||
name,
|
name,
|
||||||
/* membersFromSupertypes = */ descriptors,
|
/* membersFromSupertypes = */ descriptors,
|
||||||
/* membersFromCurrent = */ if (isFunction && name == invoke?.getName()) listOf(invoke) else listOf(),
|
/* membersFromCurrent = */ if (isFunction && name == invoke?.name) listOf(invoke) else listOf(),
|
||||||
functionClass,
|
functionClass,
|
||||||
object : OverridingUtil.DescriptorSink {
|
object : OverridingUtil.DescriptorSink {
|
||||||
override fun addFakeOverride(fakeOverride: CallableMemberDescriptor) {
|
override fun addFakeOverride(fakeOverride: CallableMemberDescriptor) {
|
||||||
|
|||||||
+6
-6
@@ -24,7 +24,7 @@ import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl
|
|||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.types.Variance
|
import org.jetbrains.kotlin.types.Variance
|
||||||
|
|
||||||
public class FunctionInvokeDescriptor private constructor(
|
class FunctionInvokeDescriptor private constructor(
|
||||||
private val container: DeclarationDescriptor,
|
private val container: DeclarationDescriptor,
|
||||||
private val original: FunctionInvokeDescriptor?,
|
private val original: FunctionInvokeDescriptor?,
|
||||||
private val callableKind: CallableMemberDescriptor.Kind
|
private val callableKind: CallableMemberDescriptor.Kind
|
||||||
@@ -63,12 +63,12 @@ public class FunctionInvokeDescriptor private constructor(
|
|||||||
val result = FunctionInvokeDescriptor(functionClass, null, CallableMemberDescriptor.Kind.DECLARATION)
|
val result = FunctionInvokeDescriptor(functionClass, null, CallableMemberDescriptor.Kind.DECLARATION)
|
||||||
result.initialize(
|
result.initialize(
|
||||||
null,
|
null,
|
||||||
functionClass.getThisAsReceiverParameter(),
|
functionClass.thisAsReceiverParameter,
|
||||||
listOf(),
|
listOf(),
|
||||||
typeParameters.takeWhile { it.getVariance() == Variance.IN_VARIANCE }
|
typeParameters.takeWhile { it.variance == Variance.IN_VARIANCE }
|
||||||
.withIndex()
|
.withIndex()
|
||||||
.map { createValueParameter(result, it.index, it.value) },
|
.map { createValueParameter(result, it.index, it.value) },
|
||||||
typeParameters.last().getDefaultType(),
|
typeParameters.last().defaultType,
|
||||||
Modality.ABSTRACT,
|
Modality.ABSTRACT,
|
||||||
Visibilities.PUBLIC
|
Visibilities.PUBLIC
|
||||||
)
|
)
|
||||||
@@ -81,7 +81,7 @@ public class FunctionInvokeDescriptor private constructor(
|
|||||||
index: Int,
|
index: Int,
|
||||||
typeParameter: TypeParameterDescriptor
|
typeParameter: TypeParameterDescriptor
|
||||||
): ValueParameterDescriptor {
|
): ValueParameterDescriptor {
|
||||||
val typeParameterName = typeParameter.getName().asString()
|
val typeParameterName = typeParameter.name.asString()
|
||||||
val name = when (typeParameterName) {
|
val name = when (typeParameterName) {
|
||||||
"T" -> "instance"
|
"T" -> "instance"
|
||||||
"E" -> "receiver"
|
"E" -> "receiver"
|
||||||
@@ -95,7 +95,7 @@ public class FunctionInvokeDescriptor private constructor(
|
|||||||
containingDeclaration, null, index,
|
containingDeclaration, null, index,
|
||||||
Annotations.EMPTY,
|
Annotations.EMPTY,
|
||||||
Name.identifier(name),
|
Name.identifier(name),
|
||||||
typeParameter.getDefaultType(),
|
typeParameter.defaultType,
|
||||||
/* declaresDefaultValue = */ false,
|
/* declaresDefaultValue = */ false,
|
||||||
/* isCrossinline = */ false,
|
/* isCrossinline = */ false,
|
||||||
/* isNoinline = */ false,
|
/* isNoinline = */ false,
|
||||||
|
|||||||
@@ -22,8 +22,7 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
|||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
|
|
||||||
object ConstUtil {
|
object ConstUtil {
|
||||||
@JvmStatic
|
@JvmStatic fun canBeUsedForConstVal(type: KotlinType) = type.canBeUsedForConstVal()
|
||||||
public fun canBeUsedForConstVal(type: KotlinType) = type.canBeUsedForConstVal()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun KotlinType.canBeUsedForConstVal() = KotlinBuiltIns.isPrimitiveType(this) || KotlinBuiltIns.isString(this)
|
fun KotlinType.canBeUsedForConstVal() = KotlinBuiltIns.isPrimitiveType(this) || KotlinBuiltIns.isString(this)
|
||||||
|
|||||||
@@ -23,12 +23,12 @@ import org.jetbrains.kotlin.platform.PlatformToKotlinClassMap
|
|||||||
import org.jetbrains.kotlin.resolve.ImportPath
|
import org.jetbrains.kotlin.resolve.ImportPath
|
||||||
import org.jetbrains.kotlin.types.TypeSubstitutor
|
import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||||
|
|
||||||
public interface ModuleDescriptor : DeclarationDescriptor, ModuleParameters {
|
interface ModuleDescriptor : DeclarationDescriptor, ModuleParameters {
|
||||||
override fun getContainingDeclaration(): DeclarationDescriptor? = null
|
override fun getContainingDeclaration(): DeclarationDescriptor? = null
|
||||||
|
|
||||||
public val builtIns: KotlinBuiltIns
|
val builtIns: KotlinBuiltIns
|
||||||
|
|
||||||
public fun isFriend(other: ModuleDescriptor): Boolean
|
fun isFriend(other: ModuleDescriptor): Boolean
|
||||||
|
|
||||||
override fun substitute(substitutor: TypeSubstitutor): ModuleDescriptor {
|
override fun substitute(substitutor: TypeSubstitutor): ModuleDescriptor {
|
||||||
return this
|
return this
|
||||||
@@ -38,9 +38,9 @@ public interface ModuleDescriptor : DeclarationDescriptor, ModuleParameters {
|
|||||||
return visitor.visitModuleDeclaration(this, data)
|
return visitor.visitModuleDeclaration(this, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun getPackage(fqName: FqName): PackageViewDescriptor
|
fun getPackage(fqName: FqName): PackageViewDescriptor
|
||||||
|
|
||||||
public fun getSubPackagesOf(fqName: FqName, nameFilter: (Name) -> Boolean): Collection<FqName>
|
fun getSubPackagesOf(fqName: FqName, nameFilter: (Name) -> Boolean): Collection<FqName>
|
||||||
|
|
||||||
fun <T> getCapability(capability: Capability<T>): T?
|
fun <T> getCapability(capability: Capability<T>): T?
|
||||||
|
|
||||||
@@ -48,8 +48,8 @@ public interface ModuleDescriptor : DeclarationDescriptor, ModuleParameters {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface ModuleParameters {
|
interface ModuleParameters {
|
||||||
public val defaultImports: List<ImportPath>
|
val defaultImports: List<ImportPath>
|
||||||
public val platformToKotlinClassMap: PlatformToKotlinClassMap
|
val platformToKotlinClassMap: PlatformToKotlinClassMap
|
||||||
|
|
||||||
object Empty: ModuleParameters {
|
object Empty: ModuleParameters {
|
||||||
override val defaultImports: List<ImportPath> = emptyList()
|
override val defaultImports: List<ImportPath> = emptyList()
|
||||||
@@ -57,7 +57,7 @@ interface ModuleParameters {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun ModuleParameters(defaultImports: List<ImportPath>, platformToKotlinClassMap: PlatformToKotlinClassMap): ModuleParameters =
|
fun ModuleParameters(defaultImports: List<ImportPath>, platformToKotlinClassMap: PlatformToKotlinClassMap): ModuleParameters =
|
||||||
object : ModuleParameters {
|
object : ModuleParameters {
|
||||||
override val defaultImports: List<ImportPath> = defaultImports
|
override val defaultImports: List<ImportPath> = defaultImports
|
||||||
override val platformToKotlinClassMap: PlatformToKotlinClassMap = platformToKotlinClassMap
|
override val platformToKotlinClassMap: PlatformToKotlinClassMap = platformToKotlinClassMap
|
||||||
|
|||||||
@@ -19,11 +19,11 @@ package org.jetbrains.kotlin.descriptors
|
|||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||||
|
|
||||||
public interface PackageFragmentDescriptor : ClassOrPackageFragmentDescriptor {
|
interface PackageFragmentDescriptor : ClassOrPackageFragmentDescriptor {
|
||||||
|
|
||||||
override fun getContainingDeclaration(): ModuleDescriptor
|
override fun getContainingDeclaration(): ModuleDescriptor
|
||||||
|
|
||||||
public val fqName: FqName
|
val fqName: FqName
|
||||||
|
|
||||||
public fun getMemberScope(): MemberScope
|
fun getMemberScope(): MemberScope
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,13 +19,13 @@ package org.jetbrains.kotlin.descriptors
|
|||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
|
|
||||||
public interface PackageFragmentProvider {
|
interface PackageFragmentProvider {
|
||||||
public fun getPackageFragments(fqName: FqName): List<PackageFragmentDescriptor>
|
fun getPackageFragments(fqName: FqName): List<PackageFragmentDescriptor>
|
||||||
|
|
||||||
public fun getSubPackagesOf(fqName: FqName, nameFilter: (Name) -> Boolean): Collection<FqName>
|
fun getSubPackagesOf(fqName: FqName, nameFilter: (Name) -> Boolean): Collection<FqName>
|
||||||
|
|
||||||
|
|
||||||
public object Empty : PackageFragmentProvider {
|
object Empty : PackageFragmentProvider {
|
||||||
override fun getPackageFragments(fqName: FqName) = emptyList<PackageFragmentDescriptor>()
|
override fun getPackageFragments(fqName: FqName) = emptyList<PackageFragmentDescriptor>()
|
||||||
|
|
||||||
override fun getSubPackagesOf(fqName: FqName, nameFilter: (Name) -> Boolean) = emptySet<FqName>()
|
override fun getSubPackagesOf(fqName: FqName, nameFilter: (Name) -> Boolean) = emptySet<FqName>()
|
||||||
|
|||||||
+2
-2
@@ -19,7 +19,7 @@ package org.jetbrains.kotlin.descriptors
|
|||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
|
|
||||||
public class PackageFragmentProviderImpl(
|
class PackageFragmentProviderImpl(
|
||||||
private val packageFragments: Collection<PackageFragmentDescriptor>
|
private val packageFragments: Collection<PackageFragmentDescriptor>
|
||||||
) : PackageFragmentProvider {
|
) : PackageFragmentProvider {
|
||||||
override fun getPackageFragments(fqName: FqName): List<PackageFragmentDescriptor> =
|
override fun getPackageFragments(fqName: FqName): List<PackageFragmentDescriptor> =
|
||||||
@@ -28,6 +28,6 @@ public class PackageFragmentProviderImpl(
|
|||||||
override fun getSubPackagesOf(fqName: FqName, nameFilter: (Name) -> Boolean): Collection<FqName> =
|
override fun getSubPackagesOf(fqName: FqName, nameFilter: (Name) -> Boolean): Collection<FqName> =
|
||||||
packageFragments.asSequence()
|
packageFragments.asSequence()
|
||||||
.map { it.fqName }
|
.map { it.fqName }
|
||||||
.filter { !it.isRoot() && it.parent() == fqName }
|
.filter { !it.isRoot && it.parent() == fqName }
|
||||||
.toList()
|
.toList()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,16 +19,16 @@ package org.jetbrains.kotlin.descriptors
|
|||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||||
|
|
||||||
public interface PackageViewDescriptor : DeclarationDescriptor {
|
interface PackageViewDescriptor : DeclarationDescriptor {
|
||||||
override fun getContainingDeclaration(): PackageViewDescriptor?
|
override fun getContainingDeclaration(): PackageViewDescriptor?
|
||||||
|
|
||||||
public val fqName: FqName
|
val fqName: FqName
|
||||||
|
|
||||||
public val memberScope: MemberScope
|
val memberScope: MemberScope
|
||||||
|
|
||||||
public val module: ModuleDescriptor
|
val module: ModuleDescriptor
|
||||||
|
|
||||||
public val fragments: List<PackageFragmentDescriptor>
|
val fragments: List<PackageFragmentDescriptor>
|
||||||
|
|
||||||
public fun isEmpty(): Boolean = fragments.isEmpty()
|
fun isEmpty(): Boolean = fragments.isEmpty()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,11 +18,11 @@ package org.jetbrains.kotlin.descriptors
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
||||||
|
|
||||||
public abstract class Visibility protected constructor(
|
abstract class Visibility protected constructor(
|
||||||
public val name: String,
|
val name: String,
|
||||||
public val isPublicAPI: Boolean
|
val isPublicAPI: Boolean
|
||||||
) {
|
) {
|
||||||
public abstract fun isVisible(receiver: ReceiverValue?, what: DeclarationDescriptorWithVisibility, from: DeclarationDescriptor): Boolean
|
abstract fun isVisible(receiver: ReceiverValue?, what: DeclarationDescriptorWithVisibility, from: DeclarationDescriptor): Boolean
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* True, if it makes sense to check this visibility in imports and not import inaccessible declarations with such visibility.
|
* True, if it makes sense to check this visibility in imports and not import inaccessible declarations with such visibility.
|
||||||
@@ -34,7 +34,7 @@ public abstract class Visibility protected constructor(
|
|||||||
* it returns true for PRIVATE, because there's no point in importing privates: they are inaccessible unless their short name is
|
* it returns true for PRIVATE, because there's no point in importing privates: they are inaccessible unless their short name is
|
||||||
* already available without an import
|
* already available without an import
|
||||||
*/
|
*/
|
||||||
public abstract fun mustCheckInImports(): Boolean
|
abstract fun mustCheckInImports(): Boolean
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return null if the answer is unknown
|
* @return null if the answer is unknown
|
||||||
@@ -43,13 +43,13 @@ public abstract class Visibility protected constructor(
|
|||||||
return Visibilities.compareLocal(this, visibility)
|
return Visibilities.compareLocal(this, visibility)
|
||||||
}
|
}
|
||||||
|
|
||||||
public open val displayName: String
|
open val displayName: String
|
||||||
get() = name
|
get() = name
|
||||||
|
|
||||||
override final fun toString() = displayName
|
override final fun toString() = displayName
|
||||||
|
|
||||||
public open fun normalize(): Visibility = this
|
open fun normalize(): Visibility = this
|
||||||
|
|
||||||
// Should be overloaded in Java visibilities
|
// Should be overloaded in Java visibilities
|
||||||
public open fun effectiveVisibility(descriptor: ClassDescriptor?) = effectiveVisibility(normalize(), descriptor)
|
open fun effectiveVisibility(descriptor: ClassDescriptor?) = effectiveVisibility(normalize(), descriptor)
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -18,7 +18,7 @@ package org.jetbrains.kotlin.descriptors.annotations
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
|
|
||||||
public enum class AnnotationUseSiteTarget(renderName: String? = null) {
|
enum class AnnotationUseSiteTarget(renderName: String? = null) {
|
||||||
FIELD(),
|
FIELD(),
|
||||||
FILE(),
|
FILE(),
|
||||||
PROPERTY(),
|
PROPERTY(),
|
||||||
@@ -28,10 +28,10 @@ public enum class AnnotationUseSiteTarget(renderName: String? = null) {
|
|||||||
CONSTRUCTOR_PARAMETER("param"),
|
CONSTRUCTOR_PARAMETER("param"),
|
||||||
SETTER_PARAMETER("setparam");
|
SETTER_PARAMETER("setparam");
|
||||||
|
|
||||||
public val renderName: String = renderName ?: name.toLowerCase()
|
val renderName: String = renderName ?: name.toLowerCase()
|
||||||
|
|
||||||
public companion object {
|
companion object {
|
||||||
public fun getAssociatedUseSiteTarget(descriptor: DeclarationDescriptor): AnnotationUseSiteTarget? = when (descriptor) {
|
fun getAssociatedUseSiteTarget(descriptor: DeclarationDescriptor): AnnotationUseSiteTarget? = when (descriptor) {
|
||||||
is PropertyDescriptor -> PROPERTY
|
is PropertyDescriptor -> PROPERTY
|
||||||
is ValueParameterDescriptor -> CONSTRUCTOR_PARAMETER
|
is ValueParameterDescriptor -> CONSTRUCTOR_PARAMETER
|
||||||
is PropertyGetterDescriptor -> PROPERTY_GETTER
|
is PropertyGetterDescriptor -> PROPERTY_GETTER
|
||||||
|
|||||||
+1
-1
@@ -16,4 +16,4 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.descriptors.annotations
|
package org.jetbrains.kotlin.descriptors.annotations
|
||||||
|
|
||||||
public data class AnnotationWithTarget(val annotation: AnnotationDescriptor, val target: AnnotationUseSiteTarget?)
|
data class AnnotationWithTarget(val annotation: AnnotationDescriptor, val target: AnnotationUseSiteTarget?)
|
||||||
@@ -20,23 +20,23 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
|||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||||
|
|
||||||
public interface Annotations : Iterable<AnnotationDescriptor> {
|
interface Annotations : Iterable<AnnotationDescriptor> {
|
||||||
|
|
||||||
public fun isEmpty(): Boolean
|
fun isEmpty(): Boolean
|
||||||
|
|
||||||
public fun findAnnotation(fqName: FqName): AnnotationDescriptor?
|
fun findAnnotation(fqName: FqName): AnnotationDescriptor?
|
||||||
|
|
||||||
public fun hasAnnotation(fqName: FqName) = findAnnotation(fqName) != null
|
fun hasAnnotation(fqName: FqName) = findAnnotation(fqName) != null
|
||||||
|
|
||||||
public fun findExternalAnnotation(fqName: FqName): AnnotationDescriptor?
|
fun findExternalAnnotation(fqName: FqName): AnnotationDescriptor?
|
||||||
|
|
||||||
public fun getUseSiteTargetedAnnotations(): List<AnnotationWithTarget>
|
fun getUseSiteTargetedAnnotations(): List<AnnotationWithTarget>
|
||||||
|
|
||||||
// Returns both targeted and annotations without target. Annotation order is preserved.
|
// Returns both targeted and annotations without target. Annotation order is preserved.
|
||||||
public fun getAllAnnotations(): List<AnnotationWithTarget>
|
fun getAllAnnotations(): List<AnnotationWithTarget>
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
public val EMPTY: Annotations = object : Annotations {
|
val EMPTY: Annotations = object : Annotations {
|
||||||
override fun isEmpty() = true
|
override fun isEmpty() = true
|
||||||
|
|
||||||
override fun findAnnotation(fqName: FqName) = null
|
override fun findAnnotation(fqName: FqName) = null
|
||||||
@@ -52,11 +52,11 @@ public interface Annotations : Iterable<AnnotationDescriptor> {
|
|||||||
override fun toString() = "EMPTY"
|
override fun toString() = "EMPTY"
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun findAnyAnnotation(annotations: Annotations, fqName: FqName): AnnotationWithTarget? {
|
fun findAnyAnnotation(annotations: Annotations, fqName: FqName): AnnotationWithTarget? {
|
||||||
return annotations.getAllAnnotations().firstOrNull { checkAnnotationName(it.annotation, fqName) }
|
return annotations.getAllAnnotations().firstOrNull { checkAnnotationName(it.annotation, fqName) }
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun findUseSiteTargetedAnnotation(annotations: Annotations, target: AnnotationUseSiteTarget, fqName: FqName): AnnotationDescriptor? {
|
fun findUseSiteTargetedAnnotation(annotations: Annotations, target: AnnotationUseSiteTarget, fqName: FqName): AnnotationDescriptor? {
|
||||||
return getUseSiteTargetedAnnotations(annotations, target).firstOrNull { checkAnnotationName(it, fqName) }
|
return getUseSiteTargetedAnnotations(annotations, target).firstOrNull { checkAnnotationName(it, fqName) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,9 +104,9 @@ class FilteredAnnotations(
|
|||||||
override fun iterator() = delegate.filter { shouldBeReturned(it) }.iterator()
|
override fun iterator() = delegate.filter { shouldBeReturned(it) }.iterator()
|
||||||
|
|
||||||
private fun shouldBeReturned(annotation: AnnotationDescriptor): Boolean {
|
private fun shouldBeReturned(annotation: AnnotationDescriptor): Boolean {
|
||||||
val descriptor = annotation.getType().getConstructor().getDeclarationDescriptor()
|
val descriptor = annotation.type.constructor.declarationDescriptor
|
||||||
return descriptor != null && DescriptorUtils.getFqName(descriptor).let { fqName ->
|
return descriptor != null && DescriptorUtils.getFqName(descriptor).let { fqName ->
|
||||||
fqName.isSafe() && fqNameFilter(fqName.toSafe())
|
fqName.isSafe && fqNameFilter(fqName.toSafe())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-6
@@ -20,7 +20,7 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
|||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||||
|
|
||||||
public class AnnotationsImpl : Annotations {
|
class AnnotationsImpl : Annotations {
|
||||||
private val annotations: List<AnnotationDescriptor>
|
private val annotations: List<AnnotationDescriptor>
|
||||||
private val targetedAnnotations: List<AnnotationWithTarget>
|
private val targetedAnnotations: List<AnnotationWithTarget>
|
||||||
|
|
||||||
@@ -41,7 +41,7 @@ public class AnnotationsImpl : Annotations {
|
|||||||
override fun isEmpty() = annotations.isEmpty()
|
override fun isEmpty() = annotations.isEmpty()
|
||||||
|
|
||||||
override fun findAnnotation(fqName: FqName) = annotations.firstOrNull {
|
override fun findAnnotation(fqName: FqName) = annotations.firstOrNull {
|
||||||
val descriptor = it.getType().getConstructor().getDeclarationDescriptor()
|
val descriptor = it.type.constructor.declarationDescriptor
|
||||||
descriptor is ClassDescriptor && fqName.toUnsafe() == DescriptorUtils.getFqName(descriptor)
|
descriptor is ClassDescriptor && fqName.toUnsafe() == DescriptorUtils.getFqName(descriptor)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,13 +60,11 @@ public class AnnotationsImpl : Annotations {
|
|||||||
override fun toString() = annotations.toString()
|
override fun toString() = annotations.toString()
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@JvmStatic
|
@JvmStatic fun create(annotationsWithTargets: List<AnnotationWithTarget>): AnnotationsImpl {
|
||||||
public fun create(annotationsWithTargets: List<AnnotationWithTarget>): AnnotationsImpl {
|
|
||||||
return AnnotationsImpl(annotationsWithTargets, 0)
|
return AnnotationsImpl(annotationsWithTargets, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic fun createWithNoTarget(vararg annotations: AnnotationDescriptor): AnnotationsImpl {
|
||||||
public fun createWithNoTarget(vararg annotations: AnnotationDescriptor): AnnotationsImpl {
|
|
||||||
return create(annotations.map { AnnotationWithTarget(it, null) })
|
return create(annotations.map { AnnotationWithTarget(it, null) })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.descriptors.annotations
|
package org.jetbrains.kotlin.descriptors.annotations
|
||||||
|
|
||||||
public enum class KotlinRetention {
|
enum class KotlinRetention {
|
||||||
RUNTIME,
|
RUNTIME,
|
||||||
BINARY,
|
BINARY,
|
||||||
SOURCE
|
SOURCE
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import java.util.*
|
|||||||
|
|
||||||
// NOTE: this enum must have the same entries with kotlin.annotation.AnnotationTarget,
|
// NOTE: this enum must have the same entries with kotlin.annotation.AnnotationTarget,
|
||||||
// and may also have some additional entries
|
// and may also have some additional entries
|
||||||
public enum class KotlinTarget(val description: String, val isDefault: Boolean = true) {
|
enum class KotlinTarget(val description: String, val isDefault: Boolean = true) {
|
||||||
CLASS("class"), // includes CLASS_ONLY, OBJECT, COMPANION_OBJECT, OBJECT_LITERAL, INTERFACE, *_CLASS but not ENUM_ENTRY
|
CLASS("class"), // includes CLASS_ONLY, OBJECT, COMPANION_OBJECT, OBJECT_LITERAL, INTERFACE, *_CLASS but not ENUM_ENTRY
|
||||||
ANNOTATION_CLASS("annotation class"),
|
ANNOTATION_CLASS("annotation class"),
|
||||||
TYPE_PARAMETER("type parameter", false),
|
TYPE_PARAMETER("type parameter", false),
|
||||||
@@ -81,13 +81,13 @@ public enum class KotlinTarget(val description: String, val isDefault: Boolean =
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun valueOrNull(name: String): KotlinTarget? = map[name]
|
fun valueOrNull(name: String): KotlinTarget? = map[name]
|
||||||
|
|
||||||
public val DEFAULT_TARGET_SET: Set<KotlinTarget> = values().filter { it.isDefault }.toSet()
|
val DEFAULT_TARGET_SET: Set<KotlinTarget> = values().filter { it.isDefault }.toSet()
|
||||||
|
|
||||||
public val ALL_TARGET_SET: Set<KotlinTarget> = values().toSet()
|
val ALL_TARGET_SET: Set<KotlinTarget> = values().toSet()
|
||||||
|
|
||||||
public fun classActualTargets(descriptor: ClassDescriptor): List<KotlinTarget> = when (descriptor.kind) {
|
fun classActualTargets(descriptor: ClassDescriptor): List<KotlinTarget> = when (descriptor.kind) {
|
||||||
ClassKind.ANNOTATION_CLASS -> listOf(ANNOTATION_CLASS, CLASS)
|
ClassKind.ANNOTATION_CLASS -> listOf(ANNOTATION_CLASS, CLASS)
|
||||||
ClassKind.CLASS ->
|
ClassKind.CLASS ->
|
||||||
if (descriptor.isInner) {
|
if (descriptor.isInner) {
|
||||||
@@ -117,7 +117,7 @@ public enum class KotlinTarget(val description: String, val isDefault: Boolean =
|
|||||||
ClassKind.ENUM_ENTRY -> listOf(ENUM_ENTRY, PROPERTY, FIELD)
|
ClassKind.ENUM_ENTRY -> listOf(ENUM_ENTRY, PROPERTY, FIELD)
|
||||||
}
|
}
|
||||||
|
|
||||||
public val USE_SITE_MAPPING: Map<AnnotationUseSiteTarget, KotlinTarget> = mapOf(
|
val USE_SITE_MAPPING: Map<AnnotationUseSiteTarget, KotlinTarget> = mapOf(
|
||||||
AnnotationUseSiteTarget.CONSTRUCTOR_PARAMETER to VALUE_PARAMETER,
|
AnnotationUseSiteTarget.CONSTRUCTOR_PARAMETER to VALUE_PARAMETER,
|
||||||
AnnotationUseSiteTarget.FIELD to FIELD,
|
AnnotationUseSiteTarget.FIELD to FIELD,
|
||||||
AnnotationUseSiteTarget.PROPERTY to PROPERTY,
|
AnnotationUseSiteTarget.PROPERTY to PROPERTY,
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import org.jetbrains.kotlin.resolve.constants.EnumValue
|
|||||||
import org.jetbrains.kotlin.resolve.constants.StringValue
|
import org.jetbrains.kotlin.resolve.constants.StringValue
|
||||||
import org.jetbrains.kotlin.types.Variance
|
import org.jetbrains.kotlin.types.Variance
|
||||||
|
|
||||||
public fun KotlinBuiltIns.createDeprecatedAnnotation(
|
fun KotlinBuiltIns.createDeprecatedAnnotation(
|
||||||
message: String,
|
message: String,
|
||||||
replaceWith: String,
|
replaceWith: String,
|
||||||
level: String = "WARNING"
|
level: String = "WARNING"
|
||||||
|
|||||||
+1
-1
@@ -23,7 +23,7 @@ import java.util.*
|
|||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.utils.toReadOnlyList
|
import org.jetbrains.kotlin.utils.toReadOnlyList
|
||||||
|
|
||||||
public class CompositePackageFragmentProvider(// can be modified from outside
|
class CompositePackageFragmentProvider(// can be modified from outside
|
||||||
private val providers: List<PackageFragmentProvider>) : PackageFragmentProvider {
|
private val providers: List<PackageFragmentProvider>) : PackageFragmentProvider {
|
||||||
|
|
||||||
override fun getPackageFragments(fqName: FqName): List<PackageFragmentDescriptor> {
|
override fun getPackageFragments(fqName: FqName): List<PackageFragmentDescriptor> {
|
||||||
|
|||||||
+2
-2
@@ -29,7 +29,7 @@ import org.jetbrains.kotlin.storage.StorageManager
|
|||||||
import org.jetbrains.kotlin.storage.getValue
|
import org.jetbrains.kotlin.storage.getValue
|
||||||
import org.jetbrains.kotlin.types.TypeSubstitutor
|
import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||||
|
|
||||||
public class LazyPackageViewDescriptorImpl(
|
class LazyPackageViewDescriptorImpl(
|
||||||
override val module: ModuleDescriptorImpl,
|
override val module: ModuleDescriptorImpl,
|
||||||
override val fqName: FqName,
|
override val fqName: FqName,
|
||||||
storageManager: StorageManager
|
storageManager: StorageManager
|
||||||
@@ -51,7 +51,7 @@ public class LazyPackageViewDescriptorImpl(
|
|||||||
})
|
})
|
||||||
|
|
||||||
override fun getContainingDeclaration(): PackageViewDescriptor? {
|
override fun getContainingDeclaration(): PackageViewDescriptor? {
|
||||||
return if (fqName.isRoot()) null else module.getPackage(fqName.parent())
|
return if (fqName.isRoot) null else module.getPackage(fqName.parent())
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
|
|||||||
+12
-12
@@ -28,7 +28,7 @@ import org.jetbrains.kotlin.storage.StorageManager
|
|||||||
import org.jetbrains.kotlin.utils.sure
|
import org.jetbrains.kotlin.utils.sure
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
public class ModuleDescriptorImpl @JvmOverloads constructor(
|
class ModuleDescriptorImpl @JvmOverloads constructor(
|
||||||
moduleName: Name,
|
moduleName: Name,
|
||||||
private val storageManager: StorageManager,
|
private val storageManager: StorageManager,
|
||||||
private val moduleParameters: ModuleParameters,
|
private val moduleParameters: ModuleParameters,
|
||||||
@@ -36,7 +36,7 @@ public class ModuleDescriptorImpl @JvmOverloads constructor(
|
|||||||
private val capabilities: Map<ModuleDescriptor.Capability<*>, Any?> = emptyMap()
|
private val capabilities: Map<ModuleDescriptor.Capability<*>, Any?> = emptyMap()
|
||||||
) : DeclarationDescriptorImpl(Annotations.EMPTY, moduleName), ModuleDescriptor, ModuleParameters by moduleParameters {
|
) : DeclarationDescriptorImpl(Annotations.EMPTY, moduleName), ModuleDescriptor, ModuleParameters by moduleParameters {
|
||||||
init {
|
init {
|
||||||
if (!moduleName.isSpecial()) {
|
if (!moduleName.isSpecial) {
|
||||||
throw IllegalArgumentException("Module name must be special: $moduleName")
|
throw IllegalArgumentException("Module name must be special: $moduleName")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -68,26 +68,26 @@ public class ModuleDescriptorImpl @JvmOverloads constructor(
|
|||||||
private val isInitialized: Boolean
|
private val isInitialized: Boolean
|
||||||
get() = packageFragmentProviderForModuleContent != null
|
get() = packageFragmentProviderForModuleContent != null
|
||||||
|
|
||||||
public fun setDependencies(dependencies: ModuleDependencies) {
|
fun setDependencies(dependencies: ModuleDependencies) {
|
||||||
assert(this.dependencies == null) { "Dependencies of $id were already set" }
|
assert(this.dependencies == null) { "Dependencies of $id were already set" }
|
||||||
this.dependencies = dependencies
|
this.dependencies = dependencies
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun setDependencies(vararg descriptors: ModuleDescriptorImpl) {
|
fun setDependencies(vararg descriptors: ModuleDescriptorImpl) {
|
||||||
setDependencies(descriptors.toList())
|
setDependencies(descriptors.toList())
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun setDependencies(descriptors: List<ModuleDescriptorImpl>) {
|
fun setDependencies(descriptors: List<ModuleDescriptorImpl>) {
|
||||||
setDependencies(ModuleDependenciesImpl(descriptors))
|
setDependencies(ModuleDependenciesImpl(descriptors))
|
||||||
}
|
}
|
||||||
|
|
||||||
private val id: String
|
private val id: String
|
||||||
get() = getName().toString()
|
get() = name.toString()
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Call initialize() to set module contents. Uninitialized module cannot be queried for its contents.
|
* Call initialize() to set module contents. Uninitialized module cannot be queried for its contents.
|
||||||
*/
|
*/
|
||||||
public fun initialize(providerForModuleContent: PackageFragmentProvider) {
|
fun initialize(providerForModuleContent: PackageFragmentProvider) {
|
||||||
assert(!isInitialized) { "Attempt to initialize module $id twice" }
|
assert(!isInitialized) { "Attempt to initialize module $id twice" }
|
||||||
this.packageFragmentProviderForModuleContent = providerForModuleContent
|
this.packageFragmentProviderForModuleContent = providerForModuleContent
|
||||||
}
|
}
|
||||||
@@ -99,7 +99,7 @@ public class ModuleDescriptorImpl @JvmOverloads constructor(
|
|||||||
|
|
||||||
override fun isFriend(other: ModuleDescriptor) = other == this || other in friendModules
|
override fun isFriend(other: ModuleDescriptor) = other == this || other in friendModules
|
||||||
|
|
||||||
public fun addFriend(friend: ModuleDescriptorImpl): Unit {
|
fun addFriend(friend: ModuleDescriptorImpl): Unit {
|
||||||
assert(friend != this) { "Attempt to make module $id a friend to itself" }
|
assert(friend != this) { "Attempt to make module $id a friend to itself" }
|
||||||
friendModules.add(friend)
|
friendModules.add(friend)
|
||||||
}
|
}
|
||||||
@@ -108,13 +108,13 @@ public class ModuleDescriptorImpl @JvmOverloads constructor(
|
|||||||
override fun <T> getCapability(capability: ModuleDescriptor.Capability<T>) = capabilities[capability] as? T
|
override fun <T> getCapability(capability: ModuleDescriptor.Capability<T>) = capabilities[capability] as? T
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface ModuleDependencies {
|
interface ModuleDependencies {
|
||||||
public val descriptors: List<ModuleDescriptorImpl>
|
val descriptors: List<ModuleDescriptorImpl>
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ModuleDependenciesImpl(override val descriptors: List<ModuleDescriptorImpl>) : ModuleDependencies
|
class ModuleDependenciesImpl(override val descriptors: List<ModuleDescriptorImpl>) : ModuleDependencies
|
||||||
|
|
||||||
public class LazyModuleDependencies(
|
class LazyModuleDependencies(
|
||||||
storageManager: StorageManager,
|
storageManager: StorageManager,
|
||||||
computeDependencies: () -> List<ModuleDescriptorImpl>
|
computeDependencies: () -> List<ModuleDescriptorImpl>
|
||||||
) : ModuleDependencies {
|
) : ModuleDependencies {
|
||||||
|
|||||||
+1
-1
@@ -21,7 +21,7 @@ import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
|||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.types.TypeSubstitutor
|
import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||||
|
|
||||||
public abstract class PackageFragmentDescriptorImpl(
|
abstract class PackageFragmentDescriptorImpl(
|
||||||
module: ModuleDescriptor,
|
module: ModuleDescriptor,
|
||||||
override val fqName: FqName
|
override val fqName: FqName
|
||||||
) : DeclarationDescriptorNonRootImpl(module, Annotations.EMPTY, fqName.shortNameOrSpecial(), SourceElement.NO_SOURCE),
|
) : DeclarationDescriptorNonRootImpl(module, Annotations.EMPTY, fqName.shortNameOrSpecial(), SourceElement.NO_SOURCE),
|
||||||
|
|||||||
@@ -28,10 +28,10 @@ import org.jetbrains.kotlin.utils.Printer
|
|||||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
public open class SubpackagesScope(private val moduleDescriptor: ModuleDescriptor, private val fqName: FqName) : MemberScopeImpl() {
|
open class SubpackagesScope(private val moduleDescriptor: ModuleDescriptor, private val fqName: FqName) : MemberScopeImpl() {
|
||||||
|
|
||||||
protected fun getPackage(name: Name): PackageViewDescriptor? {
|
protected fun getPackage(name: Name): PackageViewDescriptor? {
|
||||||
if (name.isSpecial()) {
|
if (name.isSpecial) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
val packageViewDescriptor = moduleDescriptor.getPackage(fqName.child(name))
|
val packageViewDescriptor = moduleDescriptor.getPackage(fqName.child(name))
|
||||||
@@ -44,7 +44,7 @@ public open class SubpackagesScope(private val moduleDescriptor: ModuleDescripto
|
|||||||
override fun getContributedDescriptors(kindFilter: DescriptorKindFilter,
|
override fun getContributedDescriptors(kindFilter: DescriptorKindFilter,
|
||||||
nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
|
nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
|
||||||
if (!kindFilter.acceptsKinds(DescriptorKindFilter.PACKAGES_MASK)) return listOf()
|
if (!kindFilter.acceptsKinds(DescriptorKindFilter.PACKAGES_MASK)) return listOf()
|
||||||
if (fqName.isRoot() && kindFilter.excludes.contains(DescriptorKindExclude.TopLevelPackages)) return listOf()
|
if (fqName.isRoot && kindFilter.excludes.contains(DescriptorKindExclude.TopLevelPackages)) return listOf()
|
||||||
|
|
||||||
val subFqNames = moduleDescriptor.getSubPackagesOf(fqName, nameFilter)
|
val subFqNames = moduleDescriptor.getSubPackagesOf(fqName, nameFilter)
|
||||||
val result = ArrayList<DeclarationDescriptor>(subFqNames.size)
|
val result = ArrayList<DeclarationDescriptor>(subFqNames.size)
|
||||||
@@ -58,7 +58,7 @@ public open class SubpackagesScope(private val moduleDescriptor: ModuleDescripto
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun printScopeStructure(p: Printer) {
|
override fun printScopeStructure(p: Printer) {
|
||||||
p.println(javaClass.getSimpleName(), " {")
|
p.println(javaClass.simpleName, " {")
|
||||||
p.pushIndent()
|
p.pushIndent()
|
||||||
|
|
||||||
p.popIndent()
|
p.popIndent()
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ package org.jetbrains.kotlin.incremental.components
|
|||||||
|
|
||||||
import java.io.Serializable
|
import java.io.Serializable
|
||||||
|
|
||||||
public interface LookupLocation {
|
interface LookupLocation {
|
||||||
val location: LocationInfo?
|
val location: LocationInfo?
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,7 +35,7 @@ data class Position(val line: Int, val column: Int) : Serializable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum class NoLookupLocation : LookupLocation {
|
enum class NoLookupLocation : LookupLocation {
|
||||||
FROM_IDE,
|
FROM_IDE,
|
||||||
FROM_BACKEND,
|
FROM_BACKEND,
|
||||||
FROM_TEST,
|
FROM_TEST,
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ package org.jetbrains.kotlin.incremental.components
|
|||||||
|
|
||||||
import java.io.Serializable
|
import java.io.Serializable
|
||||||
|
|
||||||
public interface LookupTracker {
|
interface LookupTracker {
|
||||||
// used in tests for more accurate checks
|
// used in tests for more accurate checks
|
||||||
val requiresPosition: Boolean
|
val requiresPosition: Boolean
|
||||||
|
|
||||||
@@ -41,7 +41,7 @@ public interface LookupTracker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum class ScopeKind {
|
enum class ScopeKind {
|
||||||
PACKAGE,
|
PACKAGE,
|
||||||
CLASSIFIER
|
CLASSIFIER
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import org.jetbrains.kotlin.incremental.components.*
|
|||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
|
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
|
||||||
|
|
||||||
public fun LookupTracker.record(from: LookupLocation, scopeOwner: DeclarationDescriptor, name: Name) {
|
fun LookupTracker.record(from: LookupLocation, scopeOwner: DeclarationDescriptor, name: Name) {
|
||||||
if (this == LookupTracker.DO_NOTHING || from is NoLookupLocation) return
|
if (this == LookupTracker.DO_NOTHING || from is NoLookupLocation) return
|
||||||
|
|
||||||
val location = from.location ?: return
|
val location = from.location ?: return
|
||||||
|
|||||||
@@ -16,10 +16,10 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.name
|
package org.jetbrains.kotlin.name
|
||||||
|
|
||||||
public fun FqName.isSubpackageOf(packageName: FqName): Boolean {
|
fun FqName.isSubpackageOf(packageName: FqName): Boolean {
|
||||||
return when {
|
return when {
|
||||||
this == packageName -> true
|
this == packageName -> true
|
||||||
packageName.isRoot() -> true
|
packageName.isRoot -> true
|
||||||
else -> isSubpackageOf(this.asString(), packageName.asString())
|
else -> isSubpackageOf(this.asString(), packageName.asString())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -28,7 +28,7 @@ private fun isSubpackageOf(subpackageNameStr: String, packageNameStr: String): B
|
|||||||
return subpackageNameStr.startsWith(packageNameStr) && subpackageNameStr[packageNameStr.length] == '.'
|
return subpackageNameStr.startsWith(packageNameStr) && subpackageNameStr[packageNameStr.length] == '.'
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun FqName.isOneSegmentFQN(): Boolean = !isRoot() && parent().isRoot()
|
fun FqName.isOneSegmentFQN(): Boolean = !isRoot && parent().isRoot
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the tail part of the FQ name by stripping a prefix. If FQ name does not begin with the given prefix, it will be returned as is.
|
* Get the tail part of the FQ name by stripping a prefix. If FQ name does not begin with the given prefix, it will be returned as is.
|
||||||
@@ -39,15 +39,15 @@ public fun FqName.isOneSegmentFQN(): Boolean = !isRoot() && parent().isRoot()
|
|||||||
* "org.jetbrains.kotlin".tail("org.jetbrains.kotlin") = ""
|
* "org.jetbrains.kotlin".tail("org.jetbrains.kotlin") = ""
|
||||||
* "org.jetbrains.kotlin".tail("org.jetbrains.gogland") = "org.jetbrains.kotlin"
|
* "org.jetbrains.kotlin".tail("org.jetbrains.gogland") = "org.jetbrains.kotlin"
|
||||||
*/
|
*/
|
||||||
public fun FqName.tail(prefix: FqName): FqName {
|
fun FqName.tail(prefix: FqName): FqName {
|
||||||
return when {
|
return when {
|
||||||
!isSubpackageOf(prefix) || prefix.isRoot() -> this
|
!isSubpackageOf(prefix) || prefix.isRoot -> this
|
||||||
this == prefix -> FqName.ROOT
|
this == prefix -> FqName.ROOT
|
||||||
else -> FqName(asString().substring(prefix.asString().length + 1))
|
else -> FqName(asString().substring(prefix.asString().length + 1))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun FqName.parentOrNull(): FqName? = if (this.isRoot) null else parent()
|
fun FqName.parentOrNull(): FqName? = if (this.isRoot) null else parent()
|
||||||
|
|
||||||
private enum class State {
|
private enum class State {
|
||||||
BEGINNING,
|
BEGINNING,
|
||||||
@@ -56,7 +56,7 @@ private enum class State {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check that it is javaName(\.javaName)* or an empty string
|
// Check that it is javaName(\.javaName)* or an empty string
|
||||||
public fun isValidJavaFqName(qualifiedName: String?): Boolean {
|
fun isValidJavaFqName(qualifiedName: String?): Boolean {
|
||||||
if (qualifiedName == null) return false
|
if (qualifiedName == null) return false
|
||||||
|
|
||||||
var state = State.BEGINNING
|
var state = State.BEGINNING
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import org.jetbrains.kotlin.types.Flexibility
|
|||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
import org.jetbrains.kotlin.types.TypeCapability
|
import org.jetbrains.kotlin.types.TypeCapability
|
||||||
|
|
||||||
public interface CustomFlexibleRendering : TypeCapability {
|
interface CustomFlexibleRendering : TypeCapability {
|
||||||
public fun renderInflexible(type: KotlinType, renderer: DescriptorRenderer): String?
|
fun renderInflexible(type: KotlinType, renderer: DescriptorRenderer): String?
|
||||||
public fun renderBounds(flexibility: Flexibility, renderer: DescriptorRenderer): Pair<String, String>?
|
fun renderBounds(flexibility: Flexibility, renderer: DescriptorRenderer): Pair<String, String>?
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,45 +26,45 @@ import org.jetbrains.kotlin.types.KotlinType
|
|||||||
import org.jetbrains.kotlin.types.TypeConstructor
|
import org.jetbrains.kotlin.types.TypeConstructor
|
||||||
import org.jetbrains.kotlin.types.TypeProjection
|
import org.jetbrains.kotlin.types.TypeProjection
|
||||||
|
|
||||||
public abstract class DescriptorRenderer : Renderer<DeclarationDescriptor> {
|
abstract class DescriptorRenderer : Renderer<DeclarationDescriptor> {
|
||||||
public fun withOptions(changeOptions: DescriptorRendererOptions.() -> Unit): DescriptorRenderer {
|
fun withOptions(changeOptions: DescriptorRendererOptions.() -> Unit): DescriptorRenderer {
|
||||||
val options = (this as DescriptorRendererImpl).options.copy()
|
val options = (this as DescriptorRendererImpl).options.copy()
|
||||||
options.changeOptions()
|
options.changeOptions()
|
||||||
options.lock()
|
options.lock()
|
||||||
return DescriptorRendererImpl(options)
|
return DescriptorRendererImpl(options)
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract fun renderType(type: KotlinType): String
|
abstract fun renderType(type: KotlinType): String
|
||||||
|
|
||||||
public abstract fun renderTypeArguments(typeArguments: List<TypeProjection>): String
|
abstract fun renderTypeArguments(typeArguments: List<TypeProjection>): String
|
||||||
|
|
||||||
public abstract fun renderTypeProjection(typeProjection: TypeProjection): String
|
abstract fun renderTypeProjection(typeProjection: TypeProjection): String
|
||||||
|
|
||||||
public abstract fun renderTypeConstructor(typeConstructor: TypeConstructor): String
|
abstract fun renderTypeConstructor(typeConstructor: TypeConstructor): String
|
||||||
|
|
||||||
public abstract fun renderClassifierName(klass: ClassifierDescriptor): String
|
abstract fun renderClassifierName(klass: ClassifierDescriptor): String
|
||||||
|
|
||||||
public abstract fun renderAnnotation(annotation: AnnotationDescriptor, target: AnnotationUseSiteTarget? = null): String
|
abstract fun renderAnnotation(annotation: AnnotationDescriptor, target: AnnotationUseSiteTarget? = null): String
|
||||||
|
|
||||||
override abstract fun render(declarationDescriptor: DeclarationDescriptor): String
|
override abstract fun render(declarationDescriptor: DeclarationDescriptor): String
|
||||||
|
|
||||||
public abstract fun renderValueParameters(parameters: Collection<ValueParameterDescriptor>, synthesizedParameterNames: Boolean): String
|
abstract fun renderValueParameters(parameters: Collection<ValueParameterDescriptor>, synthesizedParameterNames: Boolean): String
|
||||||
|
|
||||||
public fun renderFunctionParameters(functionDescriptor: FunctionDescriptor): String
|
fun renderFunctionParameters(functionDescriptor: FunctionDescriptor): String
|
||||||
= renderValueParameters(functionDescriptor.valueParameters, functionDescriptor.hasSynthesizedParameterNames())
|
= renderValueParameters(functionDescriptor.valueParameters, functionDescriptor.hasSynthesizedParameterNames())
|
||||||
|
|
||||||
public abstract fun renderName(name: Name): String
|
abstract fun renderName(name: Name): String
|
||||||
|
|
||||||
public abstract fun renderFqName(fqName: FqNameUnsafe): String
|
abstract fun renderFqName(fqName: FqNameUnsafe): String
|
||||||
|
|
||||||
public interface ValueParametersHandler {
|
interface ValueParametersHandler {
|
||||||
public fun appendBeforeValueParameters(parameterCount: Int, builder: StringBuilder)
|
fun appendBeforeValueParameters(parameterCount: Int, builder: StringBuilder)
|
||||||
public fun appendAfterValueParameters(parameterCount: Int, builder: StringBuilder)
|
fun appendAfterValueParameters(parameterCount: Int, builder: StringBuilder)
|
||||||
|
|
||||||
public fun appendBeforeValueParameter(parameter: ValueParameterDescriptor, parameterIndex: Int, parameterCount: Int, builder: StringBuilder)
|
fun appendBeforeValueParameter(parameter: ValueParameterDescriptor, parameterIndex: Int, parameterCount: Int, builder: StringBuilder)
|
||||||
public fun appendAfterValueParameter(parameter: ValueParameterDescriptor, parameterIndex: Int, parameterCount: Int, builder: StringBuilder)
|
fun appendAfterValueParameter(parameter: ValueParameterDescriptor, parameterIndex: Int, parameterCount: Int, builder: StringBuilder)
|
||||||
|
|
||||||
public object DEFAULT : ValueParametersHandler {
|
object DEFAULT : ValueParametersHandler {
|
||||||
override fun appendBeforeValueParameters(parameterCount: Int, builder: StringBuilder) {
|
override fun appendBeforeValueParameters(parameterCount: Int, builder: StringBuilder) {
|
||||||
builder.append("(")
|
builder.append("(")
|
||||||
}
|
}
|
||||||
@@ -85,33 +85,29 @@ public abstract class DescriptorRenderer : Renderer<DeclarationDescriptor> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
public fun withOptions(changeOptions: DescriptorRendererOptions.() -> Unit): DescriptorRenderer {
|
fun withOptions(changeOptions: DescriptorRendererOptions.() -> Unit): DescriptorRenderer {
|
||||||
val options = DescriptorRendererOptionsImpl()
|
val options = DescriptorRendererOptionsImpl()
|
||||||
options.changeOptions()
|
options.changeOptions()
|
||||||
options.lock()
|
options.lock()
|
||||||
return DescriptorRendererImpl(options)
|
return DescriptorRendererImpl(options)
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmField
|
@JvmField val COMPACT_WITH_MODIFIERS: DescriptorRenderer = withOptions {
|
||||||
public val COMPACT_WITH_MODIFIERS: DescriptorRenderer = withOptions {
|
|
||||||
withDefinedIn = false
|
withDefinedIn = false
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmField
|
@JvmField val COMPACT: DescriptorRenderer = withOptions {
|
||||||
public val COMPACT: DescriptorRenderer = withOptions {
|
|
||||||
withDefinedIn = false
|
withDefinedIn = false
|
||||||
modifiers = emptySet()
|
modifiers = emptySet()
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmField
|
@JvmField val COMPACT_WITH_SHORT_TYPES: DescriptorRenderer = withOptions {
|
||||||
public val COMPACT_WITH_SHORT_TYPES: DescriptorRenderer = withOptions {
|
|
||||||
modifiers = emptySet()
|
modifiers = emptySet()
|
||||||
nameShortness = NameShortness.SHORT
|
nameShortness = NameShortness.SHORT
|
||||||
parameterNameRenderingPolicy = ParameterNameRenderingPolicy.ONLY_NON_SYNTHESIZED
|
parameterNameRenderingPolicy = ParameterNameRenderingPolicy.ONLY_NON_SYNTHESIZED
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmField
|
@JvmField val ONLY_NAMES_WITH_SHORT_TYPES: DescriptorRenderer = withOptions {
|
||||||
public val ONLY_NAMES_WITH_SHORT_TYPES: DescriptorRenderer = withOptions {
|
|
||||||
withDefinedIn = false
|
withDefinedIn = false
|
||||||
modifiers = emptySet()
|
modifiers = emptySet()
|
||||||
nameShortness = NameShortness.SHORT
|
nameShortness = NameShortness.SHORT
|
||||||
@@ -123,40 +119,35 @@ public abstract class DescriptorRenderer : Renderer<DeclarationDescriptor> {
|
|||||||
startFromName = true
|
startFromName = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmField
|
@JvmField val FQ_NAMES_IN_TYPES: DescriptorRenderer = withOptions {
|
||||||
public val FQ_NAMES_IN_TYPES: DescriptorRenderer = withOptions {
|
|
||||||
modifiers = DescriptorRendererModifier.ALL
|
modifiers = DescriptorRendererModifier.ALL
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmField
|
@JvmField val SHORT_NAMES_IN_TYPES: DescriptorRenderer = withOptions {
|
||||||
public val SHORT_NAMES_IN_TYPES: DescriptorRenderer = withOptions {
|
|
||||||
nameShortness = NameShortness.SHORT
|
nameShortness = NameShortness.SHORT
|
||||||
parameterNameRenderingPolicy = ParameterNameRenderingPolicy.ONLY_NON_SYNTHESIZED
|
parameterNameRenderingPolicy = ParameterNameRenderingPolicy.ONLY_NON_SYNTHESIZED
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmField
|
@JvmField val DEBUG_TEXT: DescriptorRenderer = withOptions {
|
||||||
public val DEBUG_TEXT: DescriptorRenderer = withOptions {
|
|
||||||
debugMode = true
|
debugMode = true
|
||||||
nameShortness = NameShortness.FULLY_QUALIFIED
|
nameShortness = NameShortness.FULLY_QUALIFIED
|
||||||
modifiers = DescriptorRendererModifier.ALL
|
modifiers = DescriptorRendererModifier.ALL
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmField
|
@JvmField val FLEXIBLE_TYPES_FOR_CODE: DescriptorRenderer = withOptions {
|
||||||
public val FLEXIBLE_TYPES_FOR_CODE: DescriptorRenderer = withOptions {
|
|
||||||
flexibleTypesForCode = true
|
flexibleTypesForCode = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmField
|
@JvmField val HTML: DescriptorRenderer = withOptions {
|
||||||
public val HTML: DescriptorRenderer = withOptions {
|
|
||||||
textFormat = RenderingFormat.HTML
|
textFormat = RenderingFormat.HTML
|
||||||
modifiers = DescriptorRendererModifier.ALL
|
modifiers = DescriptorRendererModifier.ALL
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun getClassKindPrefix(klass: ClassDescriptor): String {
|
fun getClassKindPrefix(klass: ClassDescriptor): String {
|
||||||
if (klass.isCompanionObject()) {
|
if (klass.isCompanionObject) {
|
||||||
return "companion object"
|
return "companion object"
|
||||||
}
|
}
|
||||||
return when (klass.getKind()) {
|
return when (klass.kind) {
|
||||||
ClassKind.CLASS -> "class"
|
ClassKind.CLASS -> "class"
|
||||||
ClassKind.INTERFACE -> "interface"
|
ClassKind.INTERFACE -> "interface"
|
||||||
ClassKind.ENUM_CLASS -> "enum class"
|
ClassKind.ENUM_CLASS -> "enum class"
|
||||||
@@ -168,38 +159,38 @@ public abstract class DescriptorRenderer : Renderer<DeclarationDescriptor> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface DescriptorRendererOptions {
|
interface DescriptorRendererOptions {
|
||||||
public var nameShortness: NameShortness
|
var nameShortness: NameShortness
|
||||||
public var withDefinedIn: Boolean
|
var withDefinedIn: Boolean
|
||||||
public var modifiers: Set<DescriptorRendererModifier>
|
var modifiers: Set<DescriptorRendererModifier>
|
||||||
public var startFromName: Boolean
|
var startFromName: Boolean
|
||||||
public var debugMode: Boolean
|
var debugMode: Boolean
|
||||||
public var classWithPrimaryConstructor: Boolean
|
var classWithPrimaryConstructor: Boolean
|
||||||
public var verbose: Boolean
|
var verbose: Boolean
|
||||||
public var unitReturnType: Boolean
|
var unitReturnType: Boolean
|
||||||
public var withoutReturnType: Boolean
|
var withoutReturnType: Boolean
|
||||||
public var normalizedVisibilities: Boolean
|
var normalizedVisibilities: Boolean
|
||||||
public var showInternalKeyword: Boolean
|
var showInternalKeyword: Boolean
|
||||||
public var prettyFunctionTypes: Boolean
|
var prettyFunctionTypes: Boolean
|
||||||
public var uninferredTypeParameterAsName: Boolean
|
var uninferredTypeParameterAsName: Boolean
|
||||||
public var overrideRenderingPolicy: OverrideRenderingPolicy
|
var overrideRenderingPolicy: OverrideRenderingPolicy
|
||||||
public var valueParametersHandler: DescriptorRenderer.ValueParametersHandler
|
var valueParametersHandler: DescriptorRenderer.ValueParametersHandler
|
||||||
public var textFormat: RenderingFormat
|
var textFormat: RenderingFormat
|
||||||
public var excludedAnnotationClasses: Set<FqName>
|
var excludedAnnotationClasses: Set<FqName>
|
||||||
public var excludedTypeAnnotationClasses: Set<FqName>
|
var excludedTypeAnnotationClasses: Set<FqName>
|
||||||
public var includePropertyConstant: Boolean
|
var includePropertyConstant: Boolean
|
||||||
public var parameterNameRenderingPolicy: ParameterNameRenderingPolicy
|
var parameterNameRenderingPolicy: ParameterNameRenderingPolicy
|
||||||
public var withoutTypeParameters: Boolean
|
var withoutTypeParameters: Boolean
|
||||||
public var receiverAfterName: Boolean
|
var receiverAfterName: Boolean
|
||||||
public var renderCompanionObjectName: Boolean
|
var renderCompanionObjectName: Boolean
|
||||||
public var withoutSuperTypes: Boolean
|
var withoutSuperTypes: Boolean
|
||||||
public var typeNormalizer: (KotlinType) -> KotlinType
|
var typeNormalizer: (KotlinType) -> KotlinType
|
||||||
public var renderDefaultValues: Boolean
|
var renderDefaultValues: Boolean
|
||||||
public var flexibleTypesForCode: Boolean
|
var flexibleTypesForCode: Boolean
|
||||||
public var secondaryConstructorsAsPrimary: Boolean
|
var secondaryConstructorsAsPrimary: Boolean
|
||||||
public var renderAccessors: Boolean
|
var renderAccessors: Boolean
|
||||||
public var renderDefaultAnnotationArguments: Boolean
|
var renderDefaultAnnotationArguments: Boolean
|
||||||
public var alwaysRenderModifiers: Boolean
|
var alwaysRenderModifiers: Boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
object ExcludedTypeAnnotations {
|
object ExcludedTypeAnnotations {
|
||||||
@@ -214,30 +205,30 @@ object ExcludedTypeAnnotations {
|
|||||||
FqName("kotlin.internal.Exact"))
|
FqName("kotlin.internal.Exact"))
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum class RenderingFormat {
|
enum class RenderingFormat {
|
||||||
PLAIN,
|
PLAIN,
|
||||||
HTML
|
HTML
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum class NameShortness {
|
enum class NameShortness {
|
||||||
SHORT,
|
SHORT,
|
||||||
FULLY_QUALIFIED,
|
FULLY_QUALIFIED,
|
||||||
SOURCE_CODE_QUALIFIED // for local declarations qualified up to function scope
|
SOURCE_CODE_QUALIFIED // for local declarations qualified up to function scope
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum class OverrideRenderingPolicy {
|
enum class OverrideRenderingPolicy {
|
||||||
RENDER_OVERRIDE,
|
RENDER_OVERRIDE,
|
||||||
RENDER_OPEN,
|
RENDER_OPEN,
|
||||||
RENDER_OPEN_OVERRIDE
|
RENDER_OPEN_OVERRIDE
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum class ParameterNameRenderingPolicy {
|
enum class ParameterNameRenderingPolicy {
|
||||||
ALL,
|
ALL,
|
||||||
ONLY_NON_SYNTHESIZED,
|
ONLY_NON_SYNTHESIZED,
|
||||||
NONE
|
NONE
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum class DescriptorRendererModifier(val includeByDefault: Boolean) {
|
enum class DescriptorRendererModifier(val includeByDefault: Boolean) {
|
||||||
VISIBILITY(true),
|
VISIBILITY(true),
|
||||||
MODALITY(true),
|
MODALITY(true),
|
||||||
OVERRIDE(true),
|
OVERRIDE(true),
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ internal class DescriptorRendererImpl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun renderName(descriptor: DeclarationDescriptor, builder: StringBuilder) {
|
private fun renderName(descriptor: DeclarationDescriptor, builder: StringBuilder) {
|
||||||
builder.append(renderName(descriptor.getName()))
|
builder.append(renderName(descriptor.name))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun renderCompanionObjectName(descriptor: DeclarationDescriptor, builder: StringBuilder) {
|
private fun renderCompanionObjectName(descriptor: DeclarationDescriptor, builder: StringBuilder) {
|
||||||
@@ -99,15 +99,15 @@ internal class DescriptorRendererImpl(
|
|||||||
builder.append("companion object")
|
builder.append("companion object")
|
||||||
}
|
}
|
||||||
renderSpaceIfNeeded(builder)
|
renderSpaceIfNeeded(builder)
|
||||||
val containingDeclaration = descriptor.getContainingDeclaration()
|
val containingDeclaration = descriptor.containingDeclaration
|
||||||
if (containingDeclaration != null) {
|
if (containingDeclaration != null) {
|
||||||
builder.append("of ")
|
builder.append("of ")
|
||||||
builder.append(renderName(containingDeclaration.getName()))
|
builder.append(renderName(containingDeclaration.name))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (verbose || descriptor.name != SpecialNames.DEFAULT_NAME_FOR_COMPANION_OBJECT) {
|
if (verbose || descriptor.name != SpecialNames.DEFAULT_NAME_FOR_COMPANION_OBJECT) {
|
||||||
if (!startFromName) renderSpaceIfNeeded(builder)
|
if (!startFromName) renderSpaceIfNeeded(builder)
|
||||||
builder.append(renderName(descriptor.getName()))
|
builder.append(renderName(descriptor.name))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,7 +120,7 @@ internal class DescriptorRendererImpl(
|
|||||||
return klass.fullFqName.asString()
|
return klass.fullFqName.asString()
|
||||||
}
|
}
|
||||||
if (ErrorUtils.isError(klass)) {
|
if (ErrorUtils.isError(klass)) {
|
||||||
return klass.getTypeConstructor().toString()
|
return klass.typeConstructor.toString()
|
||||||
}
|
}
|
||||||
when (nameShortness) {
|
when (nameShortness) {
|
||||||
NameShortness.SHORT -> {
|
NameShortness.SHORT -> {
|
||||||
@@ -129,8 +129,8 @@ internal class DescriptorRendererImpl(
|
|||||||
// for nested classes qualified name should be used
|
// for nested classes qualified name should be used
|
||||||
var current: DeclarationDescriptor? = klass
|
var current: DeclarationDescriptor? = klass
|
||||||
do {
|
do {
|
||||||
qualifiedNameElements.add(current!!.getName())
|
qualifiedNameElements.add(current!!.name)
|
||||||
current = current.getContainingDeclaration()
|
current = current.containingDeclaration
|
||||||
}
|
}
|
||||||
while (current is ClassDescriptor)
|
while (current is ClassDescriptor)
|
||||||
|
|
||||||
@@ -162,8 +162,8 @@ internal class DescriptorRendererImpl(
|
|||||||
return renderFlexibleTypeWithBothBounds(type.flexibility().lowerBound, type.flexibility().upperBound)
|
return renderFlexibleTypeWithBothBounds(type.flexibility().lowerBound, type.flexibility().upperBound)
|
||||||
}
|
}
|
||||||
else if (flexibleTypesForCode) {
|
else if (flexibleTypesForCode) {
|
||||||
val prefix = if (nameShortness == NameShortness.SHORT) "" else Flexibility.FLEXIBLE_TYPE_CLASSIFIER.getPackageFqName().asString() + "."
|
val prefix = if (nameShortness == NameShortness.SHORT) "" else Flexibility.FLEXIBLE_TYPE_CLASSIFIER.packageFqName.asString() + "."
|
||||||
return prefix + Flexibility.FLEXIBLE_TYPE_CLASSIFIER.getRelativeClassName() + lt() + renderNormalizedType(type.flexibility().lowerBound) + ", " + renderNormalizedType(type.flexibility().upperBound) + gt()
|
return prefix + Flexibility.FLEXIBLE_TYPE_CLASSIFIER.relativeClassName + lt() + renderNormalizedType(type.flexibility().lowerBound) + ", " + renderNormalizedType(type.flexibility().upperBound) + gt()
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return renderFlexibleType(type)
|
return renderFlexibleType(type)
|
||||||
@@ -189,11 +189,11 @@ internal class DescriptorRendererImpl(
|
|||||||
}
|
}
|
||||||
if (ErrorUtils.isUninferredParameter(type)) {
|
if (ErrorUtils.isUninferredParameter(type)) {
|
||||||
if (uninferredTypeParameterAsName) {
|
if (uninferredTypeParameterAsName) {
|
||||||
return renderError((type.getConstructor() as UninferredParameterTypeConstructor).getTypeParameterDescriptor().getName().toString())
|
return renderError((type.constructor as UninferredParameterTypeConstructor).typeParameterDescriptor.name.toString())
|
||||||
}
|
}
|
||||||
return "???"
|
return "???"
|
||||||
}
|
}
|
||||||
if (type.isError()) {
|
if (type.isError) {
|
||||||
return renderDefaultType(type)
|
return renderDefaultType(type)
|
||||||
}
|
}
|
||||||
if (shouldRenderAsPrettyFunctionType(type)) {
|
if (shouldRenderAsPrettyFunctionType(type)) {
|
||||||
@@ -204,7 +204,7 @@ internal class DescriptorRendererImpl(
|
|||||||
|
|
||||||
private fun shouldRenderAsPrettyFunctionType(type: KotlinType): Boolean {
|
private fun shouldRenderAsPrettyFunctionType(type: KotlinType): Boolean {
|
||||||
return prettyFunctionTypes && KotlinBuiltIns.isExactFunctionOrExtensionFunctionType(type)
|
return prettyFunctionTypes && KotlinBuiltIns.isExactFunctionOrExtensionFunctionType(type)
|
||||||
&& type.getArguments().none { it.isStarProjection() }
|
&& type.arguments.none { it.isStarProjection }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun renderFlexibleType(type: KotlinType): String {
|
private fun renderFlexibleType(type: KotlinType): String {
|
||||||
@@ -251,15 +251,15 @@ internal class DescriptorRendererImpl(
|
|||||||
|
|
||||||
renderAnnotations(type, sb, /* needBrackets = */ true)
|
renderAnnotations(type, sb, /* needBrackets = */ true)
|
||||||
|
|
||||||
if (type.isError()) {
|
if (type.isError) {
|
||||||
sb.append(type.getConstructor().toString()) // Debug name of an error type is more informative
|
sb.append(type.constructor.toString()) // Debug name of an error type is more informative
|
||||||
sb.append(renderTypeArguments(type.getArguments()))
|
sb.append(renderTypeArguments(type.arguments))
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
sb.append(renderTypeConstructorAndArguments(type))
|
sb.append(renderTypeConstructorAndArguments(type))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type.isMarkedNullable()) {
|
if (type.isMarkedNullable) {
|
||||||
sb.append("?")
|
sb.append("?")
|
||||||
}
|
}
|
||||||
return sb.toString()
|
return sb.toString()
|
||||||
@@ -295,7 +295,7 @@ internal class DescriptorRendererImpl(
|
|||||||
|
|
||||||
|
|
||||||
override fun renderTypeConstructor(typeConstructor: TypeConstructor): String {
|
override fun renderTypeConstructor(typeConstructor: TypeConstructor): String {
|
||||||
val cd = typeConstructor.getDeclarationDescriptor()
|
val cd = typeConstructor.declarationDescriptor
|
||||||
return when (cd) {
|
return when (cd) {
|
||||||
is TypeParameterDescriptor -> renderName(cd.getName())
|
is TypeParameterDescriptor -> renderName(cd.getName())
|
||||||
is ClassDescriptor -> renderClassifierName(cd)
|
is ClassDescriptor -> renderClassifierName(cd)
|
||||||
@@ -310,24 +310,24 @@ internal class DescriptorRendererImpl(
|
|||||||
|
|
||||||
private fun appendTypeProjections(typeProjections: List<TypeProjection>, builder: StringBuilder) {
|
private fun appendTypeProjections(typeProjections: List<TypeProjection>, builder: StringBuilder) {
|
||||||
typeProjections.map {
|
typeProjections.map {
|
||||||
if (it.isStarProjection()) {
|
if (it.isStarProjection) {
|
||||||
"*"
|
"*"
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
val type = renderType(it.getType())
|
val type = renderType(it.type)
|
||||||
if (it.getProjectionKind() == Variance.INVARIANT) type else "${it.getProjectionKind()} $type"
|
if (it.projectionKind == Variance.INVARIANT) type else "${it.projectionKind} $type"
|
||||||
}
|
}
|
||||||
}.joinTo(builder, ", ")
|
}.joinTo(builder, ", ")
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun renderFunctionType(type: KotlinType): String {
|
private fun renderFunctionType(type: KotlinType): String {
|
||||||
return buildString {
|
return buildString {
|
||||||
val isNullable = type.isMarkedNullable()
|
val isNullable = type.isMarkedNullable
|
||||||
if (isNullable) append("(")
|
if (isNullable) append("(")
|
||||||
|
|
||||||
val receiverType = KotlinBuiltIns.getReceiverType(type)
|
val receiverType = KotlinBuiltIns.getReceiverType(type)
|
||||||
if (receiverType != null) {
|
if (receiverType != null) {
|
||||||
val surroundReceiver = shouldRenderAsPrettyFunctionType(receiverType) && !receiverType.isMarkedNullable()
|
val surroundReceiver = shouldRenderAsPrettyFunctionType(receiverType) && !receiverType.isMarkedNullable
|
||||||
if (surroundReceiver) {
|
if (surroundReceiver) {
|
||||||
append("(")
|
append("(")
|
||||||
}
|
}
|
||||||
@@ -375,9 +375,9 @@ internal class DescriptorRendererImpl(
|
|||||||
// See AnnotationResolver.resolveAndAppendAnnotationsFromModifiers for clarification
|
// See AnnotationResolver.resolveAndAppendAnnotationsFromModifiers for clarification
|
||||||
// This hack can be removed when modifiers will be resolved without annotations
|
// This hack can be removed when modifiers will be resolved without annotations
|
||||||
|
|
||||||
val sortedAnnotations = annotated.getAnnotations().getAllAnnotations()
|
val sortedAnnotations = annotated.annotations.getAllAnnotations()
|
||||||
for ((annotation, target) in sortedAnnotations) {
|
for ((annotation, target) in sortedAnnotations) {
|
||||||
val annotationClass = annotation.getType().getConstructor().getDeclarationDescriptor() as ClassDescriptor
|
val annotationClass = annotation.type.constructor.declarationDescriptor as ClassDescriptor
|
||||||
|
|
||||||
if (!excluded.contains(DescriptorUtils.getFqNameSafe(annotationClass))) {
|
if (!excluded.contains(DescriptorUtils.getFqNameSafe(annotationClass))) {
|
||||||
append(renderAnnotation(annotation, target)).append(" ")
|
append(renderAnnotation(annotation, target)).append(" ")
|
||||||
@@ -394,7 +394,7 @@ internal class DescriptorRendererImpl(
|
|||||||
if (target != null) {
|
if (target != null) {
|
||||||
append(target.renderName + ":")
|
append(target.renderName + ":")
|
||||||
}
|
}
|
||||||
append(renderType(annotation.getType()))
|
append(renderType(annotation.type))
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
renderAndSortAnnotationArguments(annotation).joinTo(this, ", ", "(", ")")
|
renderAndSortAnnotationArguments(annotation).joinTo(this, ", ", "(", ")")
|
||||||
}
|
}
|
||||||
@@ -402,17 +402,17 @@ internal class DescriptorRendererImpl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun renderAndSortAnnotationArguments(descriptor: AnnotationDescriptor): List<String> {
|
private fun renderAndSortAnnotationArguments(descriptor: AnnotationDescriptor): List<String> {
|
||||||
val allValueArguments = descriptor.getAllValueArguments()
|
val allValueArguments = descriptor.allValueArguments
|
||||||
val classDescriptor = if (renderDefaultAnnotationArguments) TypeUtils.getClassDescriptor(descriptor.getType()) else null
|
val classDescriptor = if (renderDefaultAnnotationArguments) TypeUtils.getClassDescriptor(descriptor.type) else null
|
||||||
val parameterDescriptorsWithDefaultValue = classDescriptor?.getUnsubstitutedPrimaryConstructor()?.getValueParameters()?.filter {
|
val parameterDescriptorsWithDefaultValue = classDescriptor?.unsubstitutedPrimaryConstructor?.valueParameters?.filter {
|
||||||
it.declaresDefaultValue()
|
it.declaresDefaultValue()
|
||||||
} ?: emptyList()
|
} ?: emptyList()
|
||||||
val defaultList = parameterDescriptorsWithDefaultValue.filter { !allValueArguments.containsKey(it) }.map {
|
val defaultList = parameterDescriptorsWithDefaultValue.filter { !allValueArguments.containsKey(it) }.map {
|
||||||
"${it.getName().asString()} = ..."
|
"${it.name.asString()} = ..."
|
||||||
}
|
}
|
||||||
val argumentList = allValueArguments.entries
|
val argumentList = allValueArguments.entries
|
||||||
.map { entry ->
|
.map { entry ->
|
||||||
val name = entry.key.getName().asString()
|
val name = entry.key.name.asString()
|
||||||
val value = if (!parameterDescriptorsWithDefaultValue.contains(entry.key)) renderConstant(entry.value) else "..."
|
val value = if (!parameterDescriptorsWithDefaultValue.contains(entry.key)) renderConstant(entry.value) else "..."
|
||||||
"$name = $value"
|
"$name = $value"
|
||||||
}
|
}
|
||||||
@@ -457,11 +457,11 @@ internal class DescriptorRendererImpl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun renderModalityForCallable(callable: CallableMemberDescriptor, builder: StringBuilder) {
|
private fun renderModalityForCallable(callable: CallableMemberDescriptor, builder: StringBuilder) {
|
||||||
if (!DescriptorUtils.isTopLevelDeclaration(callable) || callable.getModality() != Modality.FINAL) {
|
if (!DescriptorUtils.isTopLevelDeclaration(callable) || callable.modality != Modality.FINAL) {
|
||||||
if (overridesSomething(callable) && overrideRenderingPolicy == OverrideRenderingPolicy.RENDER_OVERRIDE && callable.getModality() == Modality.OPEN) {
|
if (overridesSomething(callable) && overrideRenderingPolicy == OverrideRenderingPolicy.RENDER_OVERRIDE && callable.modality == Modality.OPEN) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
renderModality(callable.getModality(), builder)
|
renderModality(callable.modality, builder)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -471,7 +471,7 @@ internal class DescriptorRendererImpl(
|
|||||||
if (overrideRenderingPolicy != OverrideRenderingPolicy.RENDER_OPEN) {
|
if (overrideRenderingPolicy != OverrideRenderingPolicy.RENDER_OPEN) {
|
||||||
builder.append("override ")
|
builder.append("override ")
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
builder.append("/*").append(callableMember.getOverriddenDescriptors().size).append("*/ ")
|
builder.append("/*").append(callableMember.overriddenDescriptors.size).append("*/ ")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -479,8 +479,8 @@ internal class DescriptorRendererImpl(
|
|||||||
|
|
||||||
private fun renderMemberKind(callableMember: CallableMemberDescriptor, builder: StringBuilder) {
|
private fun renderMemberKind(callableMember: CallableMemberDescriptor, builder: StringBuilder) {
|
||||||
if (DescriptorRendererModifier.MEMBER_KIND !in modifiers) return
|
if (DescriptorRendererModifier.MEMBER_KIND !in modifiers) return
|
||||||
if (verbose && callableMember.getKind() != CallableMemberDescriptor.Kind.DECLARATION) {
|
if (verbose && callableMember.kind != CallableMemberDescriptor.Kind.DECLARATION) {
|
||||||
builder.append("/*").append(callableMember.getKind().name.toLowerCase()).append("*/ ")
|
builder.append("/*").append(callableMember.kind.name.toLowerCase()).append("*/ ")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -526,27 +526,27 @@ internal class DescriptorRendererImpl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
builder.append("/*").append(typeParameter.getIndex()).append("*/ ")
|
builder.append("/*").append(typeParameter.index).append("*/ ")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeParameter.isReified()) {
|
if (typeParameter.isReified) {
|
||||||
builder.append(renderKeyword("reified")).append(" ")
|
builder.append(renderKeyword("reified")).append(" ")
|
||||||
}
|
}
|
||||||
val variance = typeParameter.getVariance().label
|
val variance = typeParameter.variance.label
|
||||||
if (!variance.isEmpty()) {
|
if (!variance.isEmpty()) {
|
||||||
builder.append(renderKeyword(variance)).append(" ")
|
builder.append(renderKeyword(variance)).append(" ")
|
||||||
}
|
}
|
||||||
renderName(typeParameter, builder)
|
renderName(typeParameter, builder)
|
||||||
val upperBoundsCount = typeParameter.getUpperBounds().size
|
val upperBoundsCount = typeParameter.upperBounds.size
|
||||||
if ((upperBoundsCount > 1 && !topLevel) || upperBoundsCount == 1) {
|
if ((upperBoundsCount > 1 && !topLevel) || upperBoundsCount == 1) {
|
||||||
val upperBound = typeParameter.getUpperBounds().iterator().next()
|
val upperBound = typeParameter.upperBounds.iterator().next()
|
||||||
if (!KotlinBuiltIns.isDefaultBound(upperBound)) {
|
if (!KotlinBuiltIns.isDefaultBound(upperBound)) {
|
||||||
builder.append(" : ").append(renderType(upperBound))
|
builder.append(" : ").append(renderType(upperBound))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (topLevel) {
|
else if (topLevel) {
|
||||||
var first = true
|
var first = true
|
||||||
for (upperBound in typeParameter.getUpperBounds()) {
|
for (upperBound in typeParameter.upperBounds) {
|
||||||
if (KotlinBuiltIns.isDefaultBound(upperBound)) {
|
if (KotlinBuiltIns.isDefaultBound(upperBound)) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -597,7 +597,7 @@ internal class DescriptorRendererImpl(
|
|||||||
private fun renderFunction(function: FunctionDescriptor, builder: StringBuilder) {
|
private fun renderFunction(function: FunctionDescriptor, builder: StringBuilder) {
|
||||||
if (!startFromName) {
|
if (!startFromName) {
|
||||||
renderAnnotations(function, builder)
|
renderAnnotations(function, builder)
|
||||||
renderVisibility(function.getVisibility(), builder)
|
renderVisibility(function.visibility, builder)
|
||||||
renderModalityForCallable(function, builder)
|
renderModalityForCallable(function, builder)
|
||||||
renderAdditionalModifiers(function, builder)
|
renderAdditionalModifiers(function, builder)
|
||||||
renderOverride(function, builder)
|
renderOverride(function, builder)
|
||||||
@@ -608,7 +608,7 @@ internal class DescriptorRendererImpl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
builder.append(renderKeyword("fun")).append(" ")
|
builder.append(renderKeyword("fun")).append(" ")
|
||||||
renderTypeParameters(function.getTypeParameters(), builder, true)
|
renderTypeParameters(function.typeParameters, builder, true)
|
||||||
renderReceiver(function, builder)
|
renderReceiver(function, builder)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -618,27 +618,27 @@ internal class DescriptorRendererImpl(
|
|||||||
|
|
||||||
renderReceiverAfterName(function, builder)
|
renderReceiverAfterName(function, builder)
|
||||||
|
|
||||||
val returnType = function.getReturnType()
|
val returnType = function.returnType
|
||||||
if (!withoutReturnType && (unitReturnType || (returnType == null || !KotlinBuiltIns.isUnit(returnType)))) {
|
if (!withoutReturnType && (unitReturnType || (returnType == null || !KotlinBuiltIns.isUnit(returnType)))) {
|
||||||
builder.append(": ").append(if (returnType == null) "[NULL]" else escape(renderType(returnType)))
|
builder.append(": ").append(if (returnType == null) "[NULL]" else escape(renderType(returnType)))
|
||||||
}
|
}
|
||||||
|
|
||||||
renderWhereSuffix(function.getTypeParameters(), builder)
|
renderWhereSuffix(function.typeParameters, builder)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun renderReceiverAfterName(callableDescriptor: CallableDescriptor, builder: StringBuilder) {
|
private fun renderReceiverAfterName(callableDescriptor: CallableDescriptor, builder: StringBuilder) {
|
||||||
if (!receiverAfterName) return
|
if (!receiverAfterName) return
|
||||||
|
|
||||||
val receiver = callableDescriptor.getExtensionReceiverParameter()
|
val receiver = callableDescriptor.extensionReceiverParameter
|
||||||
if (receiver != null) {
|
if (receiver != null) {
|
||||||
builder.append(" on ").append(escape(renderType(receiver.getType())))
|
builder.append(" on ").append(escape(renderType(receiver.type)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun renderReceiver(callableDescriptor: CallableDescriptor, builder: StringBuilder) {
|
private fun renderReceiver(callableDescriptor: CallableDescriptor, builder: StringBuilder) {
|
||||||
val receiver = callableDescriptor.getExtensionReceiverParameter()
|
val receiver = callableDescriptor.extensionReceiverParameter
|
||||||
if (receiver != null) {
|
if (receiver != null) {
|
||||||
val type = receiver.getType()
|
val type = receiver.type
|
||||||
var result = escape(renderType(type))
|
var result = escape(renderType(type))
|
||||||
if (shouldRenderAsPrettyFunctionType(type) && !TypeUtils.isNullableType(type)) {
|
if (shouldRenderAsPrettyFunctionType(type) && !TypeUtils.isNullableType(type)) {
|
||||||
result = "($result)"
|
result = "($result)"
|
||||||
@@ -649,12 +649,12 @@ internal class DescriptorRendererImpl(
|
|||||||
|
|
||||||
private fun renderConstructor(constructor: ConstructorDescriptor, builder: StringBuilder) {
|
private fun renderConstructor(constructor: ConstructorDescriptor, builder: StringBuilder) {
|
||||||
renderAnnotations(constructor, builder)
|
renderAnnotations(constructor, builder)
|
||||||
renderVisibility(constructor.getVisibility(), builder)
|
renderVisibility(constructor.visibility, builder)
|
||||||
renderMemberKind(constructor, builder)
|
renderMemberKind(constructor, builder)
|
||||||
|
|
||||||
builder.append(renderKeyword("constructor"))
|
builder.append(renderKeyword("constructor"))
|
||||||
if (secondaryConstructorsAsPrimary) {
|
if (secondaryConstructorsAsPrimary) {
|
||||||
val classDescriptor = constructor.getContainingDeclaration()
|
val classDescriptor = constructor.containingDeclaration
|
||||||
builder.append(" ")
|
builder.append(" ")
|
||||||
renderName(classDescriptor, builder)
|
renderName(classDescriptor, builder)
|
||||||
renderTypeParameters(classDescriptor.declaredTypeParameters, builder, false)
|
renderTypeParameters(classDescriptor.declaredTypeParameters, builder, false)
|
||||||
@@ -663,7 +663,7 @@ internal class DescriptorRendererImpl(
|
|||||||
renderValueParameters(constructor.valueParameters, constructor.hasSynthesizedParameterNames(), builder)
|
renderValueParameters(constructor.valueParameters, constructor.hasSynthesizedParameterNames(), builder)
|
||||||
|
|
||||||
if (secondaryConstructorsAsPrimary) {
|
if (secondaryConstructorsAsPrimary) {
|
||||||
renderWhereSuffix(constructor.getTypeParameters(), builder)
|
renderWhereSuffix(constructor.typeParameters, builder)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -673,9 +673,9 @@ internal class DescriptorRendererImpl(
|
|||||||
val upperBoundStrings = ArrayList<String>(0)
|
val upperBoundStrings = ArrayList<String>(0)
|
||||||
|
|
||||||
for (typeParameter in typeParameters) {
|
for (typeParameter in typeParameters) {
|
||||||
typeParameter.getUpperBounds()
|
typeParameter.upperBounds
|
||||||
.drop(1) // first parameter is rendered by renderTypeParameter
|
.drop(1) // first parameter is rendered by renderTypeParameter
|
||||||
.mapTo(upperBoundStrings) { renderName(typeParameter.getName()) + " : " + escape(renderType(it)) }
|
.mapTo(upperBoundStrings) { renderName(typeParameter.name) + " : " + escape(renderType(it)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!upperBoundStrings.isEmpty()) {
|
if (!upperBoundStrings.isEmpty()) {
|
||||||
@@ -736,11 +736,11 @@ internal class DescriptorRendererImpl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun renderValVarPrefix(variable: VariableDescriptor, builder: StringBuilder) {
|
private fun renderValVarPrefix(variable: VariableDescriptor, builder: StringBuilder) {
|
||||||
builder.append(renderKeyword(if (variable.isVar()) "var" else "val")).append(" ")
|
builder.append(renderKeyword(if (variable.isVar) "var" else "val")).append(" ")
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun renderVariable(variable: VariableDescriptor, includeName: Boolean, builder: StringBuilder, topLevel: Boolean) {
|
private fun renderVariable(variable: VariableDescriptor, includeName: Boolean, builder: StringBuilder, topLevel: Boolean) {
|
||||||
val realType = variable.getType()
|
val realType = variable.type
|
||||||
|
|
||||||
val varargElementType = (variable as? ValueParameterDescriptor)?.varargElementType
|
val varargElementType = (variable as? ValueParameterDescriptor)?.varargElementType
|
||||||
val typeToRender = varargElementType ?: realType
|
val typeToRender = varargElementType ?: realType
|
||||||
@@ -769,7 +769,7 @@ internal class DescriptorRendererImpl(
|
|||||||
private fun renderProperty(property: PropertyDescriptor, builder: StringBuilder) {
|
private fun renderProperty(property: PropertyDescriptor, builder: StringBuilder) {
|
||||||
if (!startFromName) {
|
if (!startFromName) {
|
||||||
renderAnnotations(property, builder)
|
renderAnnotations(property, builder)
|
||||||
renderVisibility(property.getVisibility(), builder)
|
renderVisibility(property.visibility, builder)
|
||||||
|
|
||||||
if (property.isConst) {
|
if (property.isConst) {
|
||||||
builder.append("const ")
|
builder.append("const ")
|
||||||
@@ -780,23 +780,23 @@ internal class DescriptorRendererImpl(
|
|||||||
renderLateInit(property, builder)
|
renderLateInit(property, builder)
|
||||||
renderMemberKind(property, builder)
|
renderMemberKind(property, builder)
|
||||||
renderValVarPrefix(property, builder)
|
renderValVarPrefix(property, builder)
|
||||||
renderTypeParameters(property.getTypeParameters(), builder, true)
|
renderTypeParameters(property.typeParameters, builder, true)
|
||||||
renderReceiver(property, builder)
|
renderReceiver(property, builder)
|
||||||
}
|
}
|
||||||
|
|
||||||
renderName(property, builder)
|
renderName(property, builder)
|
||||||
builder.append(": ").append(escape(renderType(property.getType())))
|
builder.append(": ").append(escape(renderType(property.type)))
|
||||||
|
|
||||||
renderReceiverAfterName(property, builder)
|
renderReceiverAfterName(property, builder)
|
||||||
|
|
||||||
renderInitializer(property, builder)
|
renderInitializer(property, builder)
|
||||||
|
|
||||||
renderWhereSuffix(property.getTypeParameters(), builder)
|
renderWhereSuffix(property.typeParameters, builder)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun renderInitializer(variable: VariableDescriptor, builder: StringBuilder) {
|
private fun renderInitializer(variable: VariableDescriptor, builder: StringBuilder) {
|
||||||
if (includePropertyConstant) {
|
if (includePropertyConstant) {
|
||||||
variable.getCompileTimeInitializer()?.let { constant ->
|
variable.compileTimeInitializer?.let { constant ->
|
||||||
builder.append(" = ").append(escape(renderConstant(constant)))
|
builder.append(" = ").append(escape(renderConstant(constant)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -861,7 +861,7 @@ internal class DescriptorRendererImpl(
|
|||||||
|
|
||||||
if (KotlinBuiltIns.isNothing(klass.defaultType)) return
|
if (KotlinBuiltIns.isNothing(klass.defaultType)) return
|
||||||
|
|
||||||
val supertypes = klass.getTypeConstructor().getSupertypes()
|
val supertypes = klass.typeConstructor.supertypes
|
||||||
if (supertypes.isEmpty() || supertypes.size == 1 && KotlinBuiltIns.isAnyOrNullableAny(supertypes.iterator().next())) return
|
if (supertypes.isEmpty() || supertypes.size == 1 && KotlinBuiltIns.isAnyOrNullableAny(supertypes.iterator().next())) return
|
||||||
|
|
||||||
renderSpaceIfNeeded(builder)
|
renderSpaceIfNeeded(builder)
|
||||||
@@ -890,7 +890,7 @@ internal class DescriptorRendererImpl(
|
|||||||
builder.append(renderFqName(fragment.fqName.toUnsafe()))
|
builder.append(renderFqName(fragment.fqName.toUnsafe()))
|
||||||
if (debugMode) {
|
if (debugMode) {
|
||||||
builder.append(" in ")
|
builder.append(" in ")
|
||||||
renderName(fragment.getContainingDeclaration(), builder)
|
renderName(fragment.containingDeclaration, builder)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -918,7 +918,7 @@ internal class DescriptorRendererImpl(
|
|||||||
if (renderAccessors) {
|
if (renderAccessors) {
|
||||||
renderAccessorModifiers(descriptor, builder)
|
renderAccessorModifiers(descriptor, builder)
|
||||||
builder.append("getter for ")
|
builder.append("getter for ")
|
||||||
renderProperty(descriptor.getCorrespondingProperty(), builder)
|
renderProperty(descriptor.correspondingProperty, builder)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
visitFunctionDescriptor(descriptor, builder)
|
visitFunctionDescriptor(descriptor, builder)
|
||||||
@@ -930,7 +930,7 @@ internal class DescriptorRendererImpl(
|
|||||||
if (renderAccessors) {
|
if (renderAccessors) {
|
||||||
renderAccessorModifiers(descriptor, builder)
|
renderAccessorModifiers(descriptor, builder)
|
||||||
builder.append("setter for ")
|
builder.append("setter for ")
|
||||||
renderProperty(descriptor.getCorrespondingProperty(), builder)
|
renderProperty(descriptor.correspondingProperty, builder)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
visitFunctionDescriptor(descriptor, builder)
|
visitFunctionDescriptor(descriptor, builder)
|
||||||
@@ -999,5 +999,5 @@ internal class DescriptorRendererImpl(
|
|||||||
private fun differsOnlyInNullability(lower: String, upper: String)
|
private fun differsOnlyInNullability(lower: String, upper: String)
|
||||||
= lower == upper.replace("?", "") || upper.endsWith("?") && ("$lower?") == upper || "($lower)?" == upper
|
= lower == upper.replace("?", "") || upper.endsWith("?") && ("$lower?") == upper || "($lower)?" == upper
|
||||||
|
|
||||||
private fun overridesSomething(callable: CallableMemberDescriptor) = !callable.getOverriddenDescriptors().isEmpty()
|
private fun overridesSomething(callable: CallableMemberDescriptor) = !callable.overriddenDescriptors.isEmpty()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,15 +25,15 @@ import kotlin.properties.ObservableProperty
|
|||||||
import kotlin.properties.ReadWriteProperty
|
import kotlin.properties.ReadWriteProperty
|
||||||
|
|
||||||
internal class DescriptorRendererOptionsImpl : DescriptorRendererOptions {
|
internal class DescriptorRendererOptionsImpl : DescriptorRendererOptions {
|
||||||
public var isLocked: Boolean = false
|
var isLocked: Boolean = false
|
||||||
private set
|
private set
|
||||||
|
|
||||||
public fun lock() {
|
fun lock() {
|
||||||
assert(!isLocked)
|
assert(!isLocked)
|
||||||
isLocked = true
|
isLocked = true
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun copy(): DescriptorRendererOptionsImpl {
|
fun copy(): DescriptorRendererOptionsImpl {
|
||||||
val copy = DescriptorRendererOptionsImpl()
|
val copy = DescriptorRendererOptionsImpl()
|
||||||
|
|
||||||
//TODO: use Kotlin reflection
|
//TODO: use Kotlin reflection
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user