AA/LC: Support annotation property->backing field move

#KT-57462 Fixed
This commit is contained in:
Mikhail Glukhikh
2023-03-24 13:32:02 +01:00
committed by Space Team
parent f6bf7560a6
commit 1f05ce2e01
119 changed files with 551 additions and 292 deletions
@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
import org.jetbrains.kotlin.fir.expressions.FirAnnotation
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
import org.jetbrains.kotlin.fir.expressions.arguments
import org.jetbrains.kotlin.fir.symbols.impl.FirBackingFieldSymbol
import org.jetbrains.kotlin.fir.types.ConeClassLikeType
import org.jetbrains.kotlin.fir.types.coneType
import org.jetbrains.kotlin.name.ClassId
@@ -67,13 +68,15 @@ fun FirAnnotationContainer.resolvedCompilerRequiredAnnotations(anchorElement: Fi
@SymbolInternals
fun FirAnnotationContainer.resolvedAnnotationsWithArguments(anchorElement: FirBasedSymbol<*>): List<FirAnnotation> {
return annotations.resolvedAnnotationsWithArguments(anchorElement)
if (isDefinitelyEmpty(anchorElement)) return emptyList()
annotations.resolveAnnotationsWithArguments(anchorElement)
// Note: this.annotations reference may be changed by the previous call!
return annotations
}
@SymbolInternals
fun List<FirAnnotation>.resolvedAnnotationsWithArguments(anchorElement: FirBasedSymbol<*>): List<FirAnnotation> {
if (isEmpty()) return emptyList()
fun List<FirAnnotation>.resolveAnnotationsWithArguments(anchorElement: FirBasedSymbol<*>) {
/**
* This loop by index is required to avoid possible [ConcurrentModificationException],
* because the annotations might be in a process of resolve from some other threads
@@ -94,28 +97,38 @@ fun List<FirAnnotation>.resolvedAnnotationsWithArguments(anchorElement: FirBased
}
anchorElement.lazyResolveToPhase(phase)
return this
}
private fun FirAnnotationContainer.isDefinitelyEmpty(anchorElement: FirBasedSymbol<*>): Boolean {
if (annotations.isEmpty()) {
if (anchorElement !is FirBackingFieldSymbol) return true
if (anchorElement.propertySymbol.annotations.none { it.useSiteTarget == null }) return true
}
return false
}
@SymbolInternals
fun FirAnnotationContainer.resolvedAnnotationsWithClassIds(anchorElement: FirBasedSymbol<*>): List<FirAnnotation> {
return annotations.resolvedAnnotationsWithClassIds(anchorElement)
if (isDefinitelyEmpty(anchorElement)) return emptyList()
when (anchorElement) {
is FirBackingFieldSymbol -> anchorElement.propertySymbol
else -> anchorElement
}.lazyResolveToPhase(FirResolvePhase.TYPES)
return annotations
}
@SymbolInternals
fun List<FirAnnotation>.resolvedAnnotationsWithClassIds(anchorElement: FirBasedSymbol<*>): List<FirAnnotation> {
if (isEmpty()) return emptyList()
fun resolveAnnotationsWithClassIds(anchorElement: FirBasedSymbol<*>) {
anchorElement.lazyResolveToPhase(FirResolvePhase.TYPES)
return this
}
@SymbolInternals
fun FirAnnotationContainer.resolvedAnnotationClassIds(anchorElement: FirBasedSymbol<*>): List<ClassId> {
if (annotations.isEmpty()) return emptyList()
anchorElement.lazyResolveToPhase(FirResolvePhase.TYPES)
return annotations.mapNotNull { (it.annotationTypeRef.coneType as? ConeClassLikeType)?.lookupTag?.classId }
return resolvedAnnotationsWithClassIds(anchorElement).mapNotNull {
(it.annotationTypeRef.coneType as? ConeClassLikeType)?.lookupTag?.classId
}
}
@RequiresOptIn
@@ -1,92 +0,0 @@
public abstract class AbstractKotlinClass /* AbstractKotlinClass*/ {
@kotlin.jvm.JvmStatic()
public static Custom companionLateinitStaticVariable;
@org.jetbrains.annotations.NotNull()
public static final AbstractKotlinClass.Companion Companion;
public Custom classLateinitVariable;
public static Custom companionLateinitVariable;
@org.jetbrains.annotations.NotNull()
public final Custom getClassLateinitVariable();// getClassLateinitVariable()
@org.jetbrains.annotations.NotNull()
public static final Custom getCompanionLateinitStaticVariable();// getCompanionLateinitStaticVariable()
public AbstractKotlinClass();// .ctor()
public final void setClassLateinitVariable(@org.jetbrains.annotations.NotNull() Custom);// setClassLateinitVariable(Custom)
public static final void setCompanionLateinitStaticVariable(@org.jetbrains.annotations.NotNull() Custom);// setCompanionLateinitStaticVariable(Custom)
class Companion ...
}
public static final class Companion /* KotlinClass.Companion*/ {
@org.jetbrains.annotations.NotNull()
public final Custom getCompanionLateinitStaticVariable();// getCompanionLateinitStaticVariable()
@org.jetbrains.annotations.NotNull()
public final Custom getCompanionLateinitVariable();// getCompanionLateinitVariable()
private Companion();// .ctor()
public final void setCompanionLateinitStaticVariable(@org.jetbrains.annotations.NotNull() Custom);// setCompanionLateinitStaticVariable(Custom)
public final void setCompanionLateinitVariable(@org.jetbrains.annotations.NotNull() Custom);// setCompanionLateinitVariable(Custom)
}
public static final class Companion /* AbstractKotlinClass.Companion*/ {
@org.jetbrains.annotations.NotNull()
public final Custom getCompanionLateinitStaticVariable();// getCompanionLateinitStaticVariable()
@org.jetbrains.annotations.NotNull()
public final Custom getCompanionLateinitVariable();// getCompanionLateinitVariable()
private Companion();// .ctor()
public final void setCompanionLateinitStaticVariable(@org.jetbrains.annotations.NotNull() Custom);// setCompanionLateinitStaticVariable(Custom)
public final void setCompanionLateinitVariable(@org.jetbrains.annotations.NotNull() Custom);// setCompanionLateinitVariable(Custom)
}
public final class Custom /* Custom*/ {
public Custom();// .ctor()
}
public final class KotlinClass /* KotlinClass*/ {
@kotlin.jvm.JvmStatic()
public static Custom companionLateinitStaticVariable;
@org.jetbrains.annotations.NotNull()
public static final KotlinClass.Companion Companion;
public Custom classLateinitVariable;
public static Custom companionLateinitVariable;
@org.jetbrains.annotations.NotNull()
public final Custom getClassLateinitVariable();// getClassLateinitVariable()
@org.jetbrains.annotations.NotNull()
public static final Custom getCompanionLateinitStaticVariable();// getCompanionLateinitStaticVariable()
public KotlinClass();// .ctor()
public final void setClassLateinitVariable(@org.jetbrains.annotations.NotNull() Custom);// setClassLateinitVariable(Custom)
public static final void setCompanionLateinitStaticVariable(@org.jetbrains.annotations.NotNull() Custom);// setCompanionLateinitStaticVariable(Custom)
class Companion ...
}
public final class LateinitPropertiesKt /* LateinitPropertiesKt*/ {
public static Custom topLevelLateinit;
@org.jetbrains.annotations.NotNull()
public static final Custom getTopLevelLateinit();// getTopLevelLateinit()
public static final void setTopLevelLateinit(@org.jetbrains.annotations.NotNull() Custom);// setTopLevelLateinit(Custom)
}
@@ -120,7 +120,6 @@ public final class Example /* Example*/ {
@Anno()
public final class F /* F*/ implements java.lang.Runnable {
@Anno(p = "p")
@org.jetbrains.annotations.NotNull()
private java.lang.String prop = "x" /* initializer type: java.lang.String */;
@@ -1,14 +1,13 @@
public final class C /* C*/ {
@kotlin.jvm.JvmStatic()
@org.jetbrains.annotations.NotNull()
private static java.lang.String x = "" /* initializer type: java.lang.String */;
@org.jetbrains.annotations.NotNull()
private static java.lang.String c1;
@org.jetbrains.annotations.NotNull()
private static java.lang.String c;
@org.jetbrains.annotations.NotNull()
private static java.lang.String x = "" /* initializer type: java.lang.String */;
@org.jetbrains.annotations.NotNull()
public static final C.Companion Companion;
@@ -150,7 +149,6 @@ public abstract interface I /* I*/ {
}
public final class Obj /* Obj*/ implements java.lang.Runnable {
@kotlin.jvm.JvmStatic()
@org.jetbrains.annotations.NotNull()
private static java.lang.String x = "" /* initializer type: java.lang.String */;