[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.
|
* 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.symbols.pointers.createSignature
|
||||||
import org.jetbrains.kotlin.analysis.api.fir.utils.cached
|
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.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.KtFunctionSymbol
|
||||||
import org.jetbrains.kotlin.analysis.api.symbols.KtValueParameterSymbol
|
import org.jetbrains.kotlin.analysis.api.symbols.KtValueParameterSymbol
|
||||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtSymbolKind
|
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.CanNotCreateSymbolPointerForLocalLibraryDeclarationException
|
||||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtPsiBasedSymbolPointer
|
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.KtSymbolPointer
|
||||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.WrongSymbolForSamConstructor
|
import org.jetbrains.kotlin.analysis.api.symbols.pointers.UnsupportedSymbolKind
|
||||||
import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeToken
|
|
||||||
import org.jetbrains.kotlin.analysis.api.types.KtType
|
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.analysis.low.level.api.fir.api.LLFirResolveSession
|
||||||
import org.jetbrains.kotlin.descriptors.Modality
|
import org.jetbrains.kotlin.descriptors.Modality
|
||||||
import org.jetbrains.kotlin.descriptors.Visibility
|
import org.jetbrains.kotlin.descriptors.Visibility
|
||||||
@@ -58,7 +58,13 @@ internal class KtFirFunctionSymbol(
|
|||||||
override val hasStableParameterNames: Boolean
|
override val hasStableParameterNames: Boolean
|
||||||
get() = withValidityAssertion { firSymbol.fir.getHasStableParameterNames(firSymbol.moduleData.session) }
|
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 isSuspend: Boolean get() = withValidityAssertion { firSymbol.isSuspend }
|
||||||
override val isOverride: Boolean get() = withValidityAssertion { firSymbol.isOverride }
|
override val isOverride: Boolean get() = withValidityAssertion { firSymbol.isOverride }
|
||||||
@@ -87,10 +93,8 @@ internal class KtFirFunctionSymbol(
|
|||||||
override fun createPointer(): KtSymbolPointer<KtFunctionSymbol> = withValidityAssertion {
|
override fun createPointer(): KtSymbolPointer<KtFunctionSymbol> = withValidityAssertion {
|
||||||
KtPsiBasedSymbolPointer.createForSymbolFromSource(this)?.let { return it }
|
KtPsiBasedSymbolPointer.createForSymbolFromSource(this)?.let { return it }
|
||||||
|
|
||||||
return when (symbolKind) {
|
return when (val kind = symbolKind) {
|
||||||
KtSymbolKind.TOP_LEVEL ->
|
KtSymbolKind.TOP_LEVEL -> KtFirTopLevelFunctionSymbolPointer(firSymbol.callableId, firSymbol.createSignature())
|
||||||
KtFirTopLevelFunctionSymbolPointer(firSymbol.callableId, firSymbol.createSignature())
|
|
||||||
|
|
||||||
KtSymbolKind.CLASS_MEMBER ->
|
KtSymbolKind.CLASS_MEMBER ->
|
||||||
KtFirMemberFunctionSymbolPointer(
|
KtFirMemberFunctionSymbolPointer(
|
||||||
firSymbol.containingClassLookupTag()?.classId ?: error("ClassId should not be null for member function"),
|
firSymbol.containingClassLookupTag()?.classId ?: error("ClassId should not be null for member function"),
|
||||||
@@ -98,11 +102,11 @@ internal class KtFirFunctionSymbol(
|
|||||||
firSymbol.createSignature()
|
firSymbol.createSignature()
|
||||||
)
|
)
|
||||||
|
|
||||||
KtSymbolKind.ACCESSOR -> TODO("Creating symbol for accessors fun is not supported yet")
|
|
||||||
KtSymbolKind.LOCAL -> throw CanNotCreateSymbolPointerForLocalLibraryDeclarationException(
|
KtSymbolKind.LOCAL -> throw CanNotCreateSymbolPointerForLocalLibraryDeclarationException(
|
||||||
callableIdIfNonLocal?.toString() ?: name.asString()
|
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.
|
* 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 {
|
override fun createPointer(): KtSymbolPointer<KtKotlinPropertySymbol> = withValidityAssertion {
|
||||||
KtPsiBasedSymbolPointer.createForSymbolFromSource(this)?.let { return it }
|
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.TOP_LEVEL -> TODO("Creating symbol for top level properties is not supported yet")
|
||||||
KtSymbolKind.CLASS_MEMBER ->
|
KtSymbolKind.CLASS_MEMBER ->
|
||||||
KtFirMemberPropertySymbolPointer(
|
KtFirMemberPropertySymbolPointer(
|
||||||
@@ -129,9 +129,8 @@ internal class KtFirKotlinPropertySymbol(
|
|||||||
firSymbol.createSignature()
|
firSymbol.createSignature()
|
||||||
)
|
)
|
||||||
|
|
||||||
KtSymbolKind.ACCESSOR -> TODO("Creating symbol for accessors is not supported yet")
|
|
||||||
KtSymbolKind.LOCAL -> throw CanNotCreateSymbolPointerForLocalLibraryDeclarationException(name.asString())
|
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.
|
* 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
|
package org.jetbrains.kotlin.analysis.api.symbols.pointers
|
||||||
|
|
||||||
public class CanNotCreateSymbolPointerForLocalLibraryDeclarationException(description: String) :
|
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtSymbolKind
|
||||||
IllegalStateException("Could not create a symbol pointer for local symbol $description")
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
public class WrongSymbolForSamConstructor(symbolKind: String) :
|
public class CanNotCreateSymbolPointerForLocalLibraryDeclarationException(identifier: String) :
|
||||||
IllegalStateException(
|
IllegalStateException("Could not create a symbol pointer for local symbol $identifier")
|
||||||
"For symbol with kind = KtSymbolKind.SAM_CONSTRUCTOR, KtSamConstructorSymbol should be created, but was $symbolKind"
|
|
||||||
)
|
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