From 3e0269a95a23edab5644d54de7a097fbfce0beb9 Mon Sep 17 00:00:00 2001 From: Dmitry Gridin Date: Mon, 25 Mar 2019 19:27:06 +0700 Subject: [PATCH] Minor: refactoring & fix warnings in ktPsiUtil --- .../jetbrains/kotlin/psi/psiUtil/ktPsiUtil.kt | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/psiUtil/ktPsiUtil.kt b/compiler/psi/src/org/jetbrains/kotlin/psi/psiUtil/ktPsiUtil.kt index bcacd99d3d2..d38af537f94 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/psi/psiUtil/ktPsiUtil.kt +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/psiUtil/ktPsiUtil.kt @@ -191,7 +191,7 @@ fun KtClass.isAbstract(): Boolean = isInterface() || hasModifier(KtTokens.ABSTRA * @return the list of possible superclass names */ fun StubBasedPsiElementBase>.getSuperNames(): List { - fun addSuperName(result: MutableList, referencedName: String): Unit { + fun addSuperName(result: MutableList, referencedName: String) { result.add(referencedName) val file = containingFile @@ -216,8 +216,8 @@ fun StubBasedPsiElementBase>.ge return stub.getSuperNames() } - val specifiers = (this as KtClassOrObject).superTypeListEntries - if (specifiers.isEmpty()) return Collections.emptyList() + val specifiers = this.superTypeListEntries + if (specifiers.isEmpty()) return Collections.emptyList() val result = ArrayList() for (specifier in specifiers) { @@ -241,13 +241,13 @@ fun KtExpression.getAnnotationEntries(): List { return when (parent) { is KtAnnotatedExpression -> parent.annotationEntries is KtLabeledExpression -> parent.getAnnotationEntries() - else -> emptyList() + else -> emptyList() } } fun KtAnnotationsContainer.collectAnnotationEntriesFromStubOrPsi(): List { return when (this) { - is StubBasedPsiElementBase<*> -> getStub()?.collectAnnotationEntriesFromStubElement() ?: collectAnnotationEntriesFromPsi() + is StubBasedPsiElementBase<*> -> stub?.collectAnnotationEntriesFromStubElement() ?: collectAnnotationEntriesFromPsi() else -> collectAnnotationEntriesFromPsi() } } @@ -257,7 +257,7 @@ private fun StubElement<*>.collectAnnotationEntriesFromStubElement(): List listOf(child.psi as KtAnnotationEntry) KtNodeTypes.ANNOTATION -> (child.psi as KtAnnotation).entries - else -> emptyList() + else -> emptyList() } } } @@ -267,7 +267,7 @@ private fun KtAnnotationsContainer.collectAnnotationEntriesFromPsi(): List listOf(child) is KtAnnotation -> child.entries - else -> emptyList() + else -> emptyList() } } } @@ -299,8 +299,8 @@ inline fun flatMapDescendantsOfTypeVisitor( fun KtNamedFunction.isContractPresentPsiCheck(): Boolean { val contractAllowedHere = isTopLevel && - hasBlockBody() && - !hasModifier(KtTokens.OPERATOR_KEYWORD) + hasBlockBody() && + !hasModifier(KtTokens.OPERATOR_KEYWORD) if (!contractAllowedHere) return false val firstExpression = (this as? KtFunction)?.bodyBlockExpression?.statements?.firstOrNull() ?: return false @@ -469,7 +469,8 @@ val KtModifierListOwner.isPublic: Boolean fun KtModifierListOwner.visibilityModifierType(): KtModifierKeywordToken? = visibilityModifier()?.node?.elementType as KtModifierKeywordToken? -fun KtModifierListOwner.visibilityModifierTypeOrDefault(): KtModifierKeywordToken = visibilityModifierType() ?: KtTokens.DEFAULT_VISIBILITY_KEYWORD +fun KtModifierListOwner.visibilityModifierTypeOrDefault(): KtModifierKeywordToken = + visibilityModifierType() ?: KtTokens.DEFAULT_VISIBILITY_KEYWORD fun KtDeclaration.modalityModifier() = modifierFromTokenSet(MODALITY_MODIFIERS) @@ -520,7 +521,7 @@ fun KtElement.containingClass(): KtClass? = getStrictParentOfType() fun KtClassOrObject.findPropertyByName(name: String): KtNamedDeclaration? { return declarations.firstOrNull { it is KtProperty && it.name == name } as KtNamedDeclaration? - ?: primaryConstructorParameters.firstOrNull { it.hasValOrVar() && it.name == name } + ?: primaryConstructorParameters.firstOrNull { it.hasValOrVar() && it.name == name } } fun KtClassOrObject.findFunctionByName(name: String): KtNamedDeclaration? {