[AA] SymbolPointerExceptions: cleanup code
^KT-54311
This commit is contained in:
committed by
Space Team
parent
4bd604f2ed
commit
5eb0bfc180
+15
-11
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@@ -15,16 +15,16 @@ import org.jetbrains.kotlin.analysis.api.fir.symbols.pointers.KtFirTopLevelFunct
|
||||
import org.jetbrains.kotlin.analysis.api.fir.symbols.pointers.createSignature
|
||||
import org.jetbrains.kotlin.analysis.api.fir.utils.cached
|
||||
import org.jetbrains.kotlin.analysis.api.impl.base.util.kotlinFunctionInvokeCallableIds
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeToken
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtFunctionSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtValueParameterSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtSymbolKind
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.CanNotCreateSymbolPointerForLocalLibraryDeclarationException
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtPsiBasedSymbolPointer
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.WrongSymbolForSamConstructor
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeToken
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.UnsupportedSymbolKind
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtType
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.LLFirResolveSession
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.descriptors.Visibility
|
||||
@@ -58,7 +58,13 @@ internal class KtFirFunctionSymbol(
|
||||
override val hasStableParameterNames: Boolean
|
||||
get() = withValidityAssertion { firSymbol.fir.getHasStableParameterNames(firSymbol.moduleData.session) }
|
||||
|
||||
override val annotationsList by cached { KtFirAnnotationListForDeclaration.create(firSymbol, firResolveSession.useSiteFirSession, token) }
|
||||
override val annotationsList by cached {
|
||||
KtFirAnnotationListForDeclaration.create(
|
||||
firSymbol,
|
||||
firResolveSession.useSiteFirSession,
|
||||
token,
|
||||
)
|
||||
}
|
||||
|
||||
override val isSuspend: Boolean get() = withValidityAssertion { firSymbol.isSuspend }
|
||||
override val isOverride: Boolean get() = withValidityAssertion { firSymbol.isOverride }
|
||||
@@ -87,10 +93,8 @@ internal class KtFirFunctionSymbol(
|
||||
override fun createPointer(): KtSymbolPointer<KtFunctionSymbol> = withValidityAssertion {
|
||||
KtPsiBasedSymbolPointer.createForSymbolFromSource(this)?.let { return it }
|
||||
|
||||
return when (symbolKind) {
|
||||
KtSymbolKind.TOP_LEVEL ->
|
||||
KtFirTopLevelFunctionSymbolPointer(firSymbol.callableId, firSymbol.createSignature())
|
||||
|
||||
return when (val kind = symbolKind) {
|
||||
KtSymbolKind.TOP_LEVEL -> KtFirTopLevelFunctionSymbolPointer(firSymbol.callableId, firSymbol.createSignature())
|
||||
KtSymbolKind.CLASS_MEMBER ->
|
||||
KtFirMemberFunctionSymbolPointer(
|
||||
firSymbol.containingClassLookupTag()?.classId ?: error("ClassId should not be null for member function"),
|
||||
@@ -98,11 +102,11 @@ internal class KtFirFunctionSymbol(
|
||||
firSymbol.createSignature()
|
||||
)
|
||||
|
||||
KtSymbolKind.ACCESSOR -> TODO("Creating symbol for accessors fun is not supported yet")
|
||||
KtSymbolKind.LOCAL -> throw CanNotCreateSymbolPointerForLocalLibraryDeclarationException(
|
||||
callableIdIfNonLocal?.toString() ?: name.asString()
|
||||
)
|
||||
KtSymbolKind.SAM_CONSTRUCTOR -> throw WrongSymbolForSamConstructor(this::class.java.simpleName)
|
||||
|
||||
else -> throw UnsupportedSymbolKind(this::class, kind)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@@ -120,7 +120,7 @@ internal class KtFirKotlinPropertySymbol(
|
||||
override fun createPointer(): KtSymbolPointer<KtKotlinPropertySymbol> = withValidityAssertion {
|
||||
KtPsiBasedSymbolPointer.createForSymbolFromSource(this)?.let { return it }
|
||||
|
||||
return when (symbolKind) {
|
||||
return when (val kind = symbolKind) {
|
||||
KtSymbolKind.TOP_LEVEL -> TODO("Creating symbol for top level properties is not supported yet")
|
||||
KtSymbolKind.CLASS_MEMBER ->
|
||||
KtFirMemberPropertySymbolPointer(
|
||||
@@ -129,9 +129,8 @@ internal class KtFirKotlinPropertySymbol(
|
||||
firSymbol.createSignature()
|
||||
)
|
||||
|
||||
KtSymbolKind.ACCESSOR -> TODO("Creating symbol for accessors is not supported yet")
|
||||
KtSymbolKind.LOCAL -> throw CanNotCreateSymbolPointerForLocalLibraryDeclarationException(name.asString())
|
||||
KtSymbolKind.SAM_CONSTRUCTOR -> throw WrongSymbolForSamConstructor(this::class.java.simpleName)
|
||||
else -> throw UnsupportedSymbolKind(this::class, kind)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+11
-7
@@ -1,14 +1,18 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.analysis.api.symbols.pointers
|
||||
|
||||
public class CanNotCreateSymbolPointerForLocalLibraryDeclarationException(description: String) :
|
||||
IllegalStateException("Could not create a symbol pointer for local symbol $description")
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtSymbolKind
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
public class WrongSymbolForSamConstructor(symbolKind: String) :
|
||||
IllegalStateException(
|
||||
"For symbol with kind = KtSymbolKind.SAM_CONSTRUCTOR, KtSamConstructorSymbol should be created, but was $symbolKind"
|
||||
)
|
||||
public class CanNotCreateSymbolPointerForLocalLibraryDeclarationException(identifier: String) :
|
||||
IllegalStateException("Could not create a symbol pointer for local symbol $identifier")
|
||||
|
||||
public class UnsupportedSymbolKind(identifier: String, kind: KtSymbolKind) : IllegalStateException(
|
||||
"For symbol with kind = KtSymbolKind.${kind.name} was $identifier"
|
||||
) {
|
||||
public constructor(clazz: KClass<*>, kind: KtSymbolKind) : this(clazz.java.simpleName, kind)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user