Minor: reformat code
This commit is contained in:
@@ -48,14 +48,13 @@ private val RETENTION_PARAMETER_NAME = Name.identifier("value")
|
|||||||
|
|
||||||
fun ClassDescriptor.getClassObjectReferenceTarget(): ClassDescriptor = companionObjectDescriptor ?: this
|
fun ClassDescriptor.getClassObjectReferenceTarget(): ClassDescriptor = companionObjectDescriptor ?: this
|
||||||
|
|
||||||
fun DeclarationDescriptor.getImportableDescriptor(): DeclarationDescriptor {
|
fun DeclarationDescriptor.getImportableDescriptor(): DeclarationDescriptor =
|
||||||
return when {
|
when (this) {
|
||||||
this is TypeAliasConstructorDescriptor -> containingDeclaration
|
is TypeAliasConstructorDescriptor -> containingDeclaration
|
||||||
this is ConstructorDescriptor -> containingDeclaration
|
is ConstructorDescriptor -> containingDeclaration
|
||||||
this is PropertyAccessorDescriptor -> correspondingProperty
|
is PropertyAccessorDescriptor -> correspondingProperty
|
||||||
else -> this
|
else -> this
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
val DeclarationDescriptor.fqNameUnsafe: FqNameUnsafe
|
val DeclarationDescriptor.fqNameUnsafe: FqNameUnsafe
|
||||||
get() = DescriptorUtils.getFqName(this)
|
get() = DescriptorUtils.getFqName(this)
|
||||||
@@ -71,7 +70,10 @@ val DeclarationDescriptor.module: ModuleDescriptor
|
|||||||
|
|
||||||
fun ModuleDescriptor.resolveTopLevelClass(topLevelClassFqName: FqName, location: LookupLocation): ClassDescriptor? {
|
fun ModuleDescriptor.resolveTopLevelClass(topLevelClassFqName: FqName, location: LookupLocation): ClassDescriptor? {
|
||||||
assert(!topLevelClassFqName.isRoot)
|
assert(!topLevelClassFqName.isRoot)
|
||||||
return getPackage(topLevelClassFqName.parent()).memberScope.getContributedClassifier(topLevelClassFqName.shortName(), location) as? ClassDescriptor
|
return getPackage(topLevelClassFqName.parent()).memberScope.getContributedClassifier(
|
||||||
|
topLevelClassFqName.shortName(),
|
||||||
|
location
|
||||||
|
) as? ClassDescriptor
|
||||||
}
|
}
|
||||||
|
|
||||||
val ClassifierDescriptorWithTypeParameters.denotedClassDescriptor: ClassDescriptor?
|
val ClassifierDescriptorWithTypeParameters.denotedClassDescriptor: ClassDescriptor?
|
||||||
@@ -150,13 +152,13 @@ fun ClassDescriptor.getSuperClassNotAny(): ClassDescriptor? {
|
|||||||
fun ClassDescriptor.getSuperClassOrAny(): ClassDescriptor = getSuperClassNotAny() ?: builtIns.any
|
fun ClassDescriptor.getSuperClassOrAny(): ClassDescriptor = getSuperClassNotAny() ?: builtIns.any
|
||||||
|
|
||||||
fun ClassDescriptor.getSuperInterfaces(): List<ClassDescriptor> =
|
fun ClassDescriptor.getSuperInterfaces(): List<ClassDescriptor> =
|
||||||
defaultType.constructor.supertypes
|
defaultType.constructor.supertypes
|
||||||
.filterNot { KotlinBuiltIns.isAnyOrNullableAny(it) }
|
.filterNot { KotlinBuiltIns.isAnyOrNullableAny(it) }
|
||||||
.mapNotNull {
|
.mapNotNull {
|
||||||
val superClassifier = it.constructor.declarationDescriptor
|
val superClassifier = it.constructor.declarationDescriptor
|
||||||
if (DescriptorUtils.isInterface(superClassifier)) superClassifier as ClassDescriptor
|
if (DescriptorUtils.isInterface(superClassifier)) superClassifier as ClassDescriptor
|
||||||
else null
|
else null
|
||||||
}
|
}
|
||||||
|
|
||||||
val ClassDescriptor.secondaryConstructors: List<ClassConstructorDescriptor>
|
val ClassDescriptor.secondaryConstructors: List<ClassConstructorDescriptor>
|
||||||
get() = constructors.filterNot { it.isPrimary }
|
get() = constructors.filterNot { it.isPrimary }
|
||||||
@@ -198,15 +200,15 @@ fun ValueParameterDescriptor.declaresOrInheritsDefaultValue(): Boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun Annotated.isRepeatableAnnotation(): Boolean =
|
fun Annotated.isRepeatableAnnotation(): Boolean =
|
||||||
annotations.findAnnotation(KotlinBuiltIns.FQ_NAMES.repeatable) != null
|
annotations.findAnnotation(KotlinBuiltIns.FQ_NAMES.repeatable) != null
|
||||||
|
|
||||||
fun Annotated.isDocumentedAnnotation(): Boolean =
|
fun Annotated.isDocumentedAnnotation(): Boolean =
|
||||||
annotations.findAnnotation(KotlinBuiltIns.FQ_NAMES.mustBeDocumented) != null
|
annotations.findAnnotation(KotlinBuiltIns.FQ_NAMES.mustBeDocumented) != null
|
||||||
|
|
||||||
fun Annotated.getAnnotationRetention(): KotlinRetention? {
|
fun Annotated.getAnnotationRetention(): KotlinRetention? {
|
||||||
val retentionArgumentValue =
|
val retentionArgumentValue =
|
||||||
annotations.findAnnotation(KotlinBuiltIns.FQ_NAMES.retention)?.allValueArguments?.get(RETENTION_PARAMETER_NAME)
|
annotations.findAnnotation(KotlinBuiltIns.FQ_NAMES.retention)?.allValueArguments?.get(RETENTION_PARAMETER_NAME)
|
||||||
as? EnumValue ?: return null
|
as? EnumValue ?: return null
|
||||||
return KotlinRetention.valueOf(retentionArgumentValue.enumEntryName.asString())
|
return KotlinRetention.valueOf(retentionArgumentValue.enumEntryName.asString())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,8 +236,8 @@ val CallableMemberDescriptor.propertyIfAccessor: CallableMemberDescriptor
|
|||||||
fun CallableDescriptor.fqNameOrNull(): FqName? = fqNameUnsafe.takeIf { it.isSafe }?.toSafe()
|
fun CallableDescriptor.fqNameOrNull(): FqName? = fqNameUnsafe.takeIf { it.isSafe }?.toSafe()
|
||||||
|
|
||||||
fun CallableMemberDescriptor.firstOverridden(
|
fun CallableMemberDescriptor.firstOverridden(
|
||||||
useOriginal: Boolean = false,
|
useOriginal: Boolean = false,
|
||||||
predicate: (CallableMemberDescriptor) -> Boolean
|
predicate: (CallableMemberDescriptor) -> Boolean
|
||||||
): CallableMemberDescriptor? {
|
): CallableMemberDescriptor? {
|
||||||
var result: CallableMemberDescriptor? = null
|
var result: CallableMemberDescriptor? = null
|
||||||
return DFS.dfs(listOf(this),
|
return DFS.dfs(listOf(this),
|
||||||
@@ -250,6 +252,7 @@ fun CallableMemberDescriptor.firstOverridden(
|
|||||||
result = current
|
result = current
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun result(): CallableMemberDescriptor? = result
|
override fun result(): CallableMemberDescriptor? = result
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -283,7 +286,7 @@ fun <D : CallableDescriptor> D.overriddenTreeUniqueAsSequence(useOriginal: Boole
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun CallableDescriptor.varargParameterPosition() =
|
fun CallableDescriptor.varargParameterPosition() =
|
||||||
valueParameters.indexOfFirst { it.varargElementType != null }
|
valueParameters.indexOfFirst { it.varargElementType != null }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When `Inner` is used as type outside of `Outer` class all type arguments should be specified, e.g. `Outer<String, Int>.Inner<Double>`
|
* When `Inner` is used as type outside of `Outer` class all type arguments should be specified, e.g. `Outer<String, Int>.Inner<Double>`
|
||||||
@@ -340,15 +343,15 @@ fun FunctionDescriptor.isEnumValueOfMethod(): Boolean {
|
|||||||
val methodTypeParameters = valueParameters
|
val methodTypeParameters = valueParameters
|
||||||
val nullableString = builtIns.stringType.makeNullable()
|
val nullableString = builtIns.stringType.makeNullable()
|
||||||
return DescriptorUtils.ENUM_VALUE_OF == name
|
return DescriptorUtils.ENUM_VALUE_OF == name
|
||||||
&& methodTypeParameters.size == 1
|
&& methodTypeParameters.size == 1
|
||||||
&& KotlinTypeChecker.DEFAULT.isSubtypeOf(methodTypeParameters[0].type, nullableString)
|
&& KotlinTypeChecker.DEFAULT.isSubtypeOf(methodTypeParameters[0].type, nullableString)
|
||||||
}
|
}
|
||||||
|
|
||||||
val DeclarationDescriptor.isExtensionProperty: Boolean
|
val DeclarationDescriptor.isExtensionProperty: Boolean
|
||||||
get() = this is PropertyDescriptor && extensionReceiverParameter != null
|
get() = this is PropertyDescriptor && extensionReceiverParameter != null
|
||||||
|
|
||||||
fun ClassDescriptor.getAllSuperclassesWithoutAny() =
|
fun ClassDescriptor.getAllSuperclassesWithoutAny() =
|
||||||
generateSequence(getSuperClassNotAny(), ClassDescriptor::getSuperClassNotAny).toCollection(SmartList<ClassDescriptor>())
|
generateSequence(getSuperClassNotAny(), ClassDescriptor::getSuperClassNotAny).toCollection(SmartList<ClassDescriptor>())
|
||||||
|
|
||||||
fun ClassifierDescriptor.getAllSuperClassifiers(): Sequence<ClassifierDescriptor> {
|
fun ClassifierDescriptor.getAllSuperClassifiers(): Sequence<ClassifierDescriptor> {
|
||||||
val set = hashSetOf<ClassifierDescriptor>()
|
val set = hashSetOf<ClassifierDescriptor>()
|
||||||
@@ -356,10 +359,11 @@ fun ClassifierDescriptor.getAllSuperClassifiers(): Sequence<ClassifierDescriptor
|
|||||||
fun ClassifierDescriptor.doGetAllSuperClassesAndInterfaces(): Sequence<ClassifierDescriptor> =
|
fun ClassifierDescriptor.doGetAllSuperClassesAndInterfaces(): Sequence<ClassifierDescriptor> =
|
||||||
if (original in set) {
|
if (original in set) {
|
||||||
emptySequence()
|
emptySequence()
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
set += original
|
set += original
|
||||||
sequenceOf(original) + typeConstructor.supertypes.asSequence().flatMap { it.constructor.declarationDescriptor?.doGetAllSuperClassesAndInterfaces() ?: sequenceOf() }
|
sequenceOf(original) + typeConstructor.supertypes.asSequence().flatMap {
|
||||||
|
it.constructor.declarationDescriptor?.doGetAllSuperClassesAndInterfaces() ?: sequenceOf()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return doGetAllSuperClassesAndInterfaces()
|
return doGetAllSuperClassesAndInterfaces()
|
||||||
@@ -400,8 +404,8 @@ fun DeclarationDescriptor.isPublishedApi(): Boolean {
|
|||||||
return descriptor.annotations.hasAnnotation(KotlinBuiltIns.FQ_NAMES.publishedApi)
|
return descriptor.annotations.hasAnnotation(KotlinBuiltIns.FQ_NAMES.publishedApi)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun DeclarationDescriptor.isAncestorOf(descriptor: DeclarationDescriptor, strict: Boolean): Boolean
|
fun DeclarationDescriptor.isAncestorOf(descriptor: DeclarationDescriptor, strict: Boolean): Boolean =
|
||||||
= DescriptorUtils.isAncestor(this, descriptor, strict)
|
DescriptorUtils.isAncestor(this, descriptor, strict)
|
||||||
|
|
||||||
fun DeclarationDescriptor.isCompanionObject(): Boolean = DescriptorUtils.isCompanionObject(this)
|
fun DeclarationDescriptor.isCompanionObject(): Boolean = DescriptorUtils.isCompanionObject(this)
|
||||||
|
|
||||||
@@ -422,7 +426,8 @@ fun MemberDescriptor.isEffectivelyExternal(): Boolean {
|
|||||||
|
|
||||||
if (this is PropertyDescriptor) {
|
if (this is PropertyDescriptor) {
|
||||||
if (getter?.isExternal == true &&
|
if (getter?.isExternal == true &&
|
||||||
(!isVar || setter?.isExternal == true)) return true
|
(!isVar || setter?.isExternal == true)
|
||||||
|
) return true
|
||||||
}
|
}
|
||||||
|
|
||||||
val containingClass = getContainingClass(this)
|
val containingClass = getContainingClass(this)
|
||||||
|
|||||||
Reference in New Issue
Block a user