Minor: refactoring & fix warnings in ktPsiUtil
This commit is contained in:
@@ -191,7 +191,7 @@ fun KtClass.isAbstract(): Boolean = isInterface() || hasModifier(KtTokens.ABSTRA
|
||||
* @return the list of possible superclass names
|
||||
*/
|
||||
fun StubBasedPsiElementBase<out KotlinClassOrObjectStub<out KtClassOrObject>>.getSuperNames(): List<String> {
|
||||
fun addSuperName(result: MutableList<String>, referencedName: String): Unit {
|
||||
fun addSuperName(result: MutableList<String>, referencedName: String) {
|
||||
result.add(referencedName)
|
||||
|
||||
val file = containingFile
|
||||
@@ -216,8 +216,8 @@ fun StubBasedPsiElementBase<out KotlinClassOrObjectStub<out KtClassOrObject>>.ge
|
||||
return stub.getSuperNames()
|
||||
}
|
||||
|
||||
val specifiers = (this as KtClassOrObject).superTypeListEntries
|
||||
if (specifiers.isEmpty()) return Collections.emptyList<String>()
|
||||
val specifiers = this.superTypeListEntries
|
||||
if (specifiers.isEmpty()) return Collections.emptyList()
|
||||
|
||||
val result = ArrayList<String>()
|
||||
for (specifier in specifiers) {
|
||||
@@ -241,13 +241,13 @@ fun KtExpression.getAnnotationEntries(): List<KtAnnotationEntry> {
|
||||
return when (parent) {
|
||||
is KtAnnotatedExpression -> parent.annotationEntries
|
||||
is KtLabeledExpression -> parent.getAnnotationEntries()
|
||||
else -> emptyList<KtAnnotationEntry>()
|
||||
else -> emptyList()
|
||||
}
|
||||
}
|
||||
|
||||
fun KtAnnotationsContainer.collectAnnotationEntriesFromStubOrPsi(): List<KtAnnotationEntry> {
|
||||
return when (this) {
|
||||
is StubBasedPsiElementBase<*> -> getStub()?.collectAnnotationEntriesFromStubElement() ?: collectAnnotationEntriesFromPsi()
|
||||
is StubBasedPsiElementBase<*> -> stub?.collectAnnotationEntriesFromStubElement() ?: collectAnnotationEntriesFromPsi()
|
||||
else -> collectAnnotationEntriesFromPsi()
|
||||
}
|
||||
}
|
||||
@@ -257,7 +257,7 @@ private fun StubElement<*>.collectAnnotationEntriesFromStubElement(): List<KtAnn
|
||||
when (child.stubType) {
|
||||
KtNodeTypes.ANNOTATION_ENTRY -> listOf(child.psi as KtAnnotationEntry)
|
||||
KtNodeTypes.ANNOTATION -> (child.psi as KtAnnotation).entries
|
||||
else -> emptyList<KtAnnotationEntry>()
|
||||
else -> emptyList()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -267,7 +267,7 @@ private fun KtAnnotationsContainer.collectAnnotationEntriesFromPsi(): List<KtAnn
|
||||
when (child) {
|
||||
is KtAnnotationEntry -> listOf(child)
|
||||
is KtAnnotation -> child.entries
|
||||
else -> emptyList<KtAnnotationEntry>()
|
||||
else -> emptyList()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -299,8 +299,8 @@ inline fun <reified T : KtElement, R> 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? {
|
||||
|
||||
Reference in New Issue
Block a user