[go: nahoru, domu]

Warn when composable functions are called in the wrong context

This implements three related features.

1) Allows a composable to declare what applier it requires and
what applier any lambda parameter requires via two annotations,
`ComposableTarget` and `ComposableOpenTarget`.
2) The compose plugin now infers which annotations to add to a
composable function if the compassable it calls are annotated
or are inferred in the same module.
3) Warns when a composable is used targeting the wrong applier
by using the annotations explicitly supplied or inferred.

Annotations were added to the ui composable functions to allow
reporting when they are used incorrectly.

Relnote: """Added ComposableTarget, ComposableTargetMarker and
ComposableOpenTarget that allows compile time reporting of when
a composable function is called targeting an applier it was not
designed to use.

In most cases the  annotations can be inferred by the compose
compiler plugin so using these annotation directly should be
rare . The cases that cannot be inferred include creating and
using a custom applier, abstract composable functions (such as
interface methods), fields or global variables that are
composabe lambdas (local variables and parameters are inferred),
or when using  `ComposeNode` or a related composable functions.

For custom appliers the composable functions that calls
`ComposeNode` or `ReusableComposeNode` need to add a
`CompoableTarget` annotation for the function and any
composable lambda parameter types. It is recommended, however,
to create an annotation that is annotated with
`ComposableTargetMarker` and then the  marked annotation be used
instead of `ComposableTarget` directly. A composable annotation
marked with `ComposableTargetMarker` is equivilent to a
`ComposbleTarget` with the fully qualified name of the attribute
class as the applier parameter. For an example of using
`ComposableTargetMarker` see `anroidx.compose.ui.UiComposable`.
"""

Fixes: b/194292971
Test: ./gradlew :compose:r:r:tDUT :compose:compiler:c-h:i-t:tDUT

Change-Id: I38f11b789291db89fc0bb92fc14ac5b3fcba0283
diff --git a/compose/foundation/foundation-layout/api/restricted_current.txt b/compose/foundation/foundation-layout/api/restricted_current.txt
index 9355fc6..b3425d9 100644
--- a/compose/foundation/foundation-layout/api/restricted_current.txt
+++ b/compose/foundation/foundation-layout/api/restricted_current.txt
@@ -85,7 +85,7 @@
   }
 
   public final class BoxWithConstraintsKt {
-    method @androidx.compose.runtime.Composable public static void BoxWithConstraints(optional androidx.compose.ui.Modifier modifier, optional androidx.compose.ui.Alignment contentAlignment, optional boolean propagateMinConstraints, kotlin.jvm.functions.Function1<? super androidx.compose.foundation.layout.BoxWithConstraintsScope,kotlin.Unit> content);
+    method @androidx.compose.runtime.Composable @androidx.compose.ui.UiComposable public static void BoxWithConstraints(optional androidx.compose.ui.Modifier modifier, optional androidx.compose.ui.Alignment contentAlignment, optional boolean propagateMinConstraints, kotlin.jvm.functions.Function1<? super androidx.compose.foundation.layout.BoxWithConstraintsScope,kotlin.Unit> content);
   }
 
   @androidx.compose.runtime.Stable public interface BoxWithConstraintsScope extends androidx.compose.foundation.layout.BoxScope {