[Analysis API] Minor, prettify 'hasParentSymbol()'
This commit is contained in:
+26
-6
@@ -114,12 +114,28 @@ internal class KtFirSymbolContainingDeclarationProvider(
|
|||||||
|
|
||||||
private fun hasParentSymbol(symbol: KtSymbol): Boolean {
|
private fun hasParentSymbol(symbol: KtSymbol): Boolean {
|
||||||
when (symbol) {
|
when (symbol) {
|
||||||
is KtReceiverParameterSymbol -> return true // KT-55124
|
is KtReceiverParameterSymbol -> {
|
||||||
!is KtDeclarationSymbol -> return false
|
// KT-55124
|
||||||
is KtSamConstructorSymbol -> return false // SAM constructors are always top-level
|
return true
|
||||||
is KtScriptSymbol -> return false // Scripts are always top-level
|
}
|
||||||
else -> {
|
|
||||||
if (symbol is KtSymbolWithKind && symbol.symbolKind == KtSymbolKind.TOP_LEVEL) {
|
!is KtDeclarationSymbol -> {
|
||||||
|
// File, package, etc.
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
is KtSamConstructorSymbol -> {
|
||||||
|
// SAM constructors are always top-level
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
is KtScriptSymbol -> {
|
||||||
|
// Scripts are always top-level
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
is KtSymbolWithKind -> {
|
||||||
|
if (symbol.symbolKind == KtSymbolKind.TOP_LEVEL) {
|
||||||
val containingFile = (symbol.firSymbol.fir as? FirElementWithResolveState)?.getContainingFile()
|
val containingFile = (symbol.firSymbol.fir as? FirElementWithResolveState)?.getContainingFile()
|
||||||
if (containingFile == null || containingFile.declarations.firstOrNull() !is FirScript) {
|
if (containingFile == null || containingFile.declarations.firstOrNull() !is FirScript) {
|
||||||
// Should be replaced with proper check after KT-61451 and KT-61887
|
// Should be replaced with proper check after KT-61451 and KT-61887
|
||||||
@@ -129,6 +145,10 @@ internal class KtFirSymbolContainingDeclarationProvider(
|
|||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else -> {
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user