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
|
* @return the list of possible superclass names
|
||||||
*/
|
*/
|
||||||
fun StubBasedPsiElementBase<out KotlinClassOrObjectStub<out KtClassOrObject>>.getSuperNames(): List<String> {
|
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)
|
result.add(referencedName)
|
||||||
|
|
||||||
val file = containingFile
|
val file = containingFile
|
||||||
@@ -216,8 +216,8 @@ fun StubBasedPsiElementBase<out KotlinClassOrObjectStub<out KtClassOrObject>>.ge
|
|||||||
return stub.getSuperNames()
|
return stub.getSuperNames()
|
||||||
}
|
}
|
||||||
|
|
||||||
val specifiers = (this as KtClassOrObject).superTypeListEntries
|
val specifiers = this.superTypeListEntries
|
||||||
if (specifiers.isEmpty()) return Collections.emptyList<String>()
|
if (specifiers.isEmpty()) return Collections.emptyList()
|
||||||
|
|
||||||
val result = ArrayList<String>()
|
val result = ArrayList<String>()
|
||||||
for (specifier in specifiers) {
|
for (specifier in specifiers) {
|
||||||
@@ -241,13 +241,13 @@ fun KtExpression.getAnnotationEntries(): List<KtAnnotationEntry> {
|
|||||||
return when (parent) {
|
return when (parent) {
|
||||||
is KtAnnotatedExpression -> parent.annotationEntries
|
is KtAnnotatedExpression -> parent.annotationEntries
|
||||||
is KtLabeledExpression -> parent.getAnnotationEntries()
|
is KtLabeledExpression -> parent.getAnnotationEntries()
|
||||||
else -> emptyList<KtAnnotationEntry>()
|
else -> emptyList()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun KtAnnotationsContainer.collectAnnotationEntriesFromStubOrPsi(): List<KtAnnotationEntry> {
|
fun KtAnnotationsContainer.collectAnnotationEntriesFromStubOrPsi(): List<KtAnnotationEntry> {
|
||||||
return when (this) {
|
return when (this) {
|
||||||
is StubBasedPsiElementBase<*> -> getStub()?.collectAnnotationEntriesFromStubElement() ?: collectAnnotationEntriesFromPsi()
|
is StubBasedPsiElementBase<*> -> stub?.collectAnnotationEntriesFromStubElement() ?: collectAnnotationEntriesFromPsi()
|
||||||
else -> collectAnnotationEntriesFromPsi()
|
else -> collectAnnotationEntriesFromPsi()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -257,7 +257,7 @@ private fun StubElement<*>.collectAnnotationEntriesFromStubElement(): List<KtAnn
|
|||||||
when (child.stubType) {
|
when (child.stubType) {
|
||||||
KtNodeTypes.ANNOTATION_ENTRY -> listOf(child.psi as KtAnnotationEntry)
|
KtNodeTypes.ANNOTATION_ENTRY -> listOf(child.psi as KtAnnotationEntry)
|
||||||
KtNodeTypes.ANNOTATION -> (child.psi as KtAnnotation).entries
|
KtNodeTypes.ANNOTATION -> (child.psi as KtAnnotation).entries
|
||||||
else -> emptyList<KtAnnotationEntry>()
|
else -> emptyList()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -267,7 +267,7 @@ private fun KtAnnotationsContainer.collectAnnotationEntriesFromPsi(): List<KtAnn
|
|||||||
when (child) {
|
when (child) {
|
||||||
is KtAnnotationEntry -> listOf(child)
|
is KtAnnotationEntry -> listOf(child)
|
||||||
is KtAnnotation -> child.entries
|
is KtAnnotation -> child.entries
|
||||||
else -> emptyList<KtAnnotationEntry>()
|
else -> emptyList()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -299,8 +299,8 @@ inline fun <reified T : KtElement, R> flatMapDescendantsOfTypeVisitor(
|
|||||||
fun KtNamedFunction.isContractPresentPsiCheck(): Boolean {
|
fun KtNamedFunction.isContractPresentPsiCheck(): Boolean {
|
||||||
val contractAllowedHere =
|
val contractAllowedHere =
|
||||||
isTopLevel &&
|
isTopLevel &&
|
||||||
hasBlockBody() &&
|
hasBlockBody() &&
|
||||||
!hasModifier(KtTokens.OPERATOR_KEYWORD)
|
!hasModifier(KtTokens.OPERATOR_KEYWORD)
|
||||||
if (!contractAllowedHere) return false
|
if (!contractAllowedHere) return false
|
||||||
|
|
||||||
val firstExpression = (this as? KtFunction)?.bodyBlockExpression?.statements?.firstOrNull() ?: return false
|
val firstExpression = (this as? KtFunction)?.bodyBlockExpression?.statements?.firstOrNull() ?: return false
|
||||||
@@ -469,7 +469,8 @@ val KtModifierListOwner.isPublic: Boolean
|
|||||||
fun KtModifierListOwner.visibilityModifierType(): KtModifierKeywordToken? =
|
fun KtModifierListOwner.visibilityModifierType(): KtModifierKeywordToken? =
|
||||||
visibilityModifier()?.node?.elementType as 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)
|
fun KtDeclaration.modalityModifier() = modifierFromTokenSet(MODALITY_MODIFIERS)
|
||||||
|
|
||||||
@@ -520,7 +521,7 @@ fun KtElement.containingClass(): KtClass? = getStrictParentOfType()
|
|||||||
|
|
||||||
fun KtClassOrObject.findPropertyByName(name: String): KtNamedDeclaration? {
|
fun KtClassOrObject.findPropertyByName(name: String): KtNamedDeclaration? {
|
||||||
return declarations.firstOrNull { it is KtProperty && it.name == name } as 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? {
|
fun KtClassOrObject.findFunctionByName(name: String): KtNamedDeclaration? {
|
||||||
|
|||||||
Reference in New Issue
Block a user