Minor cleanup: prefer actual body with return statement
This commit is contained in:
committed by
Dmitriy Novozhilov
parent
7e2c365b79
commit
1ba943eb4a
@@ -9,14 +9,16 @@ import com.intellij.psi.tree.IElementType
|
|||||||
import com.intellij.psi.tree.TokenSet
|
import com.intellij.psi.tree.TokenSet
|
||||||
import org.jetbrains.kotlin.fir.*
|
import org.jetbrains.kotlin.fir.*
|
||||||
|
|
||||||
fun FirSourceElement.getChild(type: IElementType, index: Int = 0, depth: Int = -1): FirSourceElement? =
|
fun FirSourceElement.getChild(type: IElementType, index: Int = 0, depth: Int = -1): FirSourceElement? {
|
||||||
getChild(setOf(type), index, depth)
|
return getChild(setOf(type), index, depth)
|
||||||
|
}
|
||||||
|
|
||||||
fun FirSourceElement.getChild(types: TokenSet, index: Int = 0, depth: Int = -1): FirSourceElement? =
|
fun FirSourceElement.getChild(types: TokenSet, index: Int = 0, depth: Int = -1): FirSourceElement? {
|
||||||
getChild(types.types.toSet(), index, depth)
|
return getChild(types.types.toSet(), index, depth)
|
||||||
|
}
|
||||||
|
|
||||||
fun FirSourceElement.getChild(types: Set<IElementType>, index: Int = 0, depth: Int = -1): FirSourceElement? =
|
fun FirSourceElement.getChild(types: Set<IElementType>, index: Int = 0, depth: Int = -1): FirSourceElement? {
|
||||||
when (this) {
|
return when (this) {
|
||||||
is FirPsiSourceElement<*> -> {
|
is FirPsiSourceElement<*> -> {
|
||||||
getChild(types, index, depth)
|
getChild(types, index, depth)
|
||||||
}
|
}
|
||||||
@@ -25,6 +27,7 @@ fun FirSourceElement.getChild(types: Set<IElementType>, index: Int = 0, depth: I
|
|||||||
}
|
}
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun FirPsiSourceElement<*>.getChild(types: Set<IElementType>, index: Int, depth: Int): FirSourceElement? {
|
private fun FirPsiSourceElement<*>.getChild(types: Set<IElementType>, index: Int, depth: Int): FirSourceElement? {
|
||||||
val visitor = PsiElementFinderByType(types, index, depth)
|
val visitor = PsiElementFinderByType(types, index, depth)
|
||||||
|
|||||||
+9
-6
@@ -19,20 +19,23 @@ import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertyAccessor
|
|||||||
import org.jetbrains.kotlin.fir.types.FirImplicitTypeRef
|
import org.jetbrains.kotlin.fir.types.FirImplicitTypeRef
|
||||||
import org.jetbrains.kotlin.lexer.KtTokens
|
import org.jetbrains.kotlin.lexer.KtTokens
|
||||||
|
|
||||||
internal fun isInsideExpectClass(containingClass: FirRegularClass, context: CheckerContext): Boolean =
|
internal fun isInsideExpectClass(containingClass: FirRegularClass, context: CheckerContext): Boolean {
|
||||||
isInsideSpecificClass(containingClass, context) { klass -> klass.isExpect }
|
return isInsideSpecificClass(containingClass, context) { klass -> klass.isExpect }
|
||||||
|
}
|
||||||
|
|
||||||
internal fun isInsideExternalClass(containingClass: FirRegularClass, context: CheckerContext): Boolean =
|
internal fun isInsideExternalClass(containingClass: FirRegularClass, context: CheckerContext): Boolean {
|
||||||
isInsideSpecificClass(containingClass, context) { klass -> klass.isExternal }
|
return isInsideSpecificClass(containingClass, context) { klass -> klass.isExternal }
|
||||||
|
}
|
||||||
|
|
||||||
// Note that the class that contains the currently visiting declaration will *not* be in the context's containing declarations *yet*.
|
// Note that the class that contains the currently visiting declaration will *not* be in the context's containing declarations *yet*.
|
||||||
private inline fun isInsideSpecificClass(
|
private inline fun isInsideSpecificClass(
|
||||||
containingClass: FirRegularClass,
|
containingClass: FirRegularClass,
|
||||||
context: CheckerContext,
|
context: CheckerContext,
|
||||||
predicate: (FirRegularClass) -> Boolean
|
predicate: (FirRegularClass) -> Boolean
|
||||||
): Boolean =
|
): Boolean {
|
||||||
predicate.invoke(containingClass) ||
|
return predicate.invoke(containingClass) ||
|
||||||
context.containingDeclarations.asReversed().any { it is FirRegularClass && predicate.invoke(it) }
|
context.containingDeclarations.asReversed().any { it is FirRegularClass && predicate.invoke(it) }
|
||||||
|
}
|
||||||
|
|
||||||
internal fun FirMemberDeclaration.isEffectivelyExpect(
|
internal fun FirMemberDeclaration.isEffectivelyExpect(
|
||||||
containingClass: FirRegularClass?,
|
containingClass: FirRegularClass?,
|
||||||
|
|||||||
Reference in New Issue
Block a user