@@ -41,7 +41,7 @@ import org.jetbrains.kotlin.ir.util.render
4141import org.jetbrains.kotlin.name.FqName
4242
4343public class StabilityAnalyzerTransformer (
44- private val context : IrPluginContext ,
44+ context : IrPluginContext ,
4545 private val stabilityCollector : StabilityInfoCollector ? = null ,
4646) : IrElementTransformerVoidWithContext() {
4747
@@ -52,6 +52,7 @@ public class StabilityAnalyzerTransformer(
5252 FqName (" com.skydoves.compose.stability.runtime.TraceRecomposition" )
5353 private val ignoreStabilityReportFqName =
5454 FqName (" com.skydoves.compose.stability.runtime.IgnoreStabilityReport" )
55+ private val previewFqName = FqName (" androidx.compose.ui.tooling.preview.Preview" )
5556
5657 private val irBuilder = RecompositionIrBuilder (context)
5758 private var irBuilderInitialized = false
@@ -71,8 +72,9 @@ public class StabilityAnalyzerTransformer(
7172 return super .visitFunctionNew(declaration)
7273 }
7374
74- // Skip stability reporting if function has @IgnoreStabilityReport annotation
75- val shouldIgnoreReport = declaration.hasAnnotation(ignoreStabilityReportFqName)
75+ // Skip stability reporting if function has @IgnoreStabilityReport annotation or @Preview annotation
76+ val shouldIgnoreReport = declaration.hasAnnotation(ignoreStabilityReportFqName) ||
77+ hasPreviewAnnotation(declaration)
7678
7779 // Collect stability information if collector is available and not ignored
7880 if (! shouldIgnoreReport) {
@@ -601,6 +603,35 @@ public class StabilityAnalyzerTransformer(
601603 return fqName in KNOWN_STABLE_TYPES
602604 }
603605
606+ /* *
607+ * Check if a function has @Preview annotation (directly or via meta-annotation).
608+ * This includes:
609+ * - Direct @Preview annotation
610+ * - Custom annotations that are meta-annotated with @Preview
611+ */
612+ private fun hasPreviewAnnotation (function : IrFunction ): Boolean {
613+ // Check direct @Preview annotation
614+ if (function.hasAnnotation(previewFqName)) {
615+ return true
616+ }
617+
618+ // Check for meta-annotations (annotations on annotations)
619+ for (annotation in function.annotations) {
620+ try {
621+ val annotationType = annotation.type
622+ val annotationClass = annotationType.classOrNull?.owner
623+ if (annotationClass != null && annotationClass.hasAnnotation(previewFqName)) {
624+ return true
625+ }
626+ } catch (e: Exception ) {
627+ // Skip annotations that can't be resolved
628+ continue
629+ }
630+ }
631+
632+ return false
633+ }
634+
604635 /* *
605636 * Check if a type is a known unstable Java class.
606637 *
0 commit comments