[AA] support @JvmField in KtSymbolInfoProvider
^KT-54311 ^KT-54360 Fixed
This commit is contained in:
committed by
Space Team
parent
f4ae696aee
commit
01d5a5bc5b
+31
-13
@@ -18,10 +18,12 @@ import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget
|
||||
import org.jetbrains.kotlin.fir.declarations.FirProperty
|
||||
import org.jetbrains.kotlin.fir.declarations.getDeprecationForCallSite
|
||||
import org.jetbrains.kotlin.fir.declarations.getJvmNameFromAnnotation
|
||||
import org.jetbrains.kotlin.fir.declarations.hasAnnotation
|
||||
import org.jetbrains.kotlin.fir.languageVersionSettings
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol
|
||||
import org.jetbrains.kotlin.load.java.JvmAbi
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.name.StandardClassIds
|
||||
import org.jetbrains.kotlin.resolve.deprecation.DeprecationInfo
|
||||
|
||||
internal class KtFirSymbolInfoProvider(
|
||||
@@ -70,11 +72,9 @@ internal class KtFirSymbolInfoProvider(
|
||||
if (symbol is KtFirSyntheticJavaPropertySymbol) {
|
||||
return symbol.javaGetterSymbol.name
|
||||
}
|
||||
val jvmName = run {
|
||||
val firProperty = symbol.firSymbol.fir as? FirProperty ?: return@run null
|
||||
firProperty.getJvmNameFromAnnotation(AnnotationUseSiteTarget.PROPERTY_GETTER) ?: firProperty.getter?.getJvmNameFromAnnotation()
|
||||
}
|
||||
return Name.identifier(jvmName ?: JvmAbi.getterName(symbol.name.identifier))
|
||||
|
||||
val firProperty = symbol.firSymbol.fir as? FirProperty ?: return symbol.name
|
||||
return getJvmName(firProperty, isSetter = false)
|
||||
}
|
||||
|
||||
override fun getJavaSetterName(symbol: KtPropertySymbol): Name? {
|
||||
@@ -82,14 +82,32 @@ internal class KtFirSymbolInfoProvider(
|
||||
if (symbol is KtFirSyntheticJavaPropertySymbol) {
|
||||
return symbol.javaSetterSymbol?.name
|
||||
}
|
||||
return if (symbol.isVal) null
|
||||
else {
|
||||
val jvmName = run {
|
||||
val firProperty = symbol.firSymbol.fir as? FirProperty ?: return@run null
|
||||
firProperty.getJvmNameFromAnnotation(AnnotationUseSiteTarget.PROPERTY_GETTER)
|
||||
?: firProperty.setter?.getJvmNameFromAnnotation()
|
||||
}
|
||||
Name.identifier(jvmName ?: JvmAbi.setterName(symbol.name.identifier))
|
||||
|
||||
val firProperty = symbol.firSymbol.fir as? FirProperty ?: return symbol.name
|
||||
if (firProperty.isVal) return null
|
||||
|
||||
return getJvmName(firProperty, isSetter = true)
|
||||
}
|
||||
|
||||
private fun getJvmName(property: FirProperty, isSetter: Boolean): Name {
|
||||
if (property.hasAnnotation(StandardClassIds.Annotations.JvmField)) return property.name
|
||||
return Name.identifier(getJvmNameAsString(property, isSetter))
|
||||
}
|
||||
|
||||
private fun getJvmNameAsString(property: FirProperty, isSetter: Boolean): String {
|
||||
val useSiteTarget = if (isSetter) AnnotationUseSiteTarget.PROPERTY_SETTER else AnnotationUseSiteTarget.PROPERTY_GETTER
|
||||
val jvmNameFromProperty = property.getJvmNameFromAnnotation(useSiteTarget)
|
||||
if (jvmNameFromProperty != null) {
|
||||
return jvmNameFromProperty
|
||||
}
|
||||
|
||||
val accessor = if (isSetter) property.setter else property.getter
|
||||
val jvmNameFromAccessor = accessor?.getJvmNameFromAnnotation()
|
||||
if (jvmNameFromAccessor != null) {
|
||||
return jvmNameFromAccessor
|
||||
}
|
||||
|
||||
val identifier = property.name.identifier
|
||||
return if (isSetter) JvmAbi.setterName(identifier) else JvmAbi.getterName(identifier)
|
||||
}
|
||||
}
|
||||
|
||||
+6
@@ -184,6 +184,12 @@ public class FirIdeNormalAnalysisSourceModuleSymbolByPsiTestGenerated extends Ab
|
||||
runTest("analysis/analysis-api/testData/symbols/symbolByPsi/implicitReturnInLambda.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("jvmField.kt")
|
||||
public void testJvmField() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/symbols/symbolByPsi/jvmField.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("jvmName.kt")
|
||||
public void testJvmName() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user