Skip to content

Commit 9775e72

Browse files
committed
update compiler page
1 parent 2260c4c commit 9775e72

File tree

1 file changed

+52
-1
lines changed

1 file changed

+52
-1
lines changed

docs/general/compiler_plugin.md

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,59 @@
11
# Compiler Plugin
22

3-
Compose works by transforming all Kotlin functions that are annotated with @Composable.
3+
Compose works by transforming all Kotlin functions that are annotated with **@Composable** and adding code for the Compose Runtime.
44
To do that it uses a Kotlin Compiler Plugin.
55

6+
7+
For instance, this Composable:
8+
```kotlin
9+
@Composable
10+
fun Hello(name: String) {
11+
Text(name)
12+
}
13+
```
14+
15+
16+
will be transformed and compiled to Jvm ByteCode. Below you can see the decompiled code as Java code
17+
18+
```java
19+
@Metadata(
20+
mv = {1, 5, 1},
21+
k = 2,
22+
xi = 48,
23+
d1 = {"\u0000\u0010\n\u0000\n\u0002\u0010\u0002\n\u0000\n\u0002\u0010\u000e\n\u0002\b\u0002\u001a\u0015\u0010\u0000\u001a\u00020\u00012\u0006\u0010\u0002\u001a\u00020\u0003H\u0007¢\u0006\u0002\u0010\u0004¨\u0006\u0005"},
24+
d2 = {"Hello", "", "name", "", "(Ljava/lang/String;Landroidx/compose/runtime/Composer;I)V", "app_debug"}
25+
)
26+
public final class GreetingKt {
27+
@Composable
28+
public static final void Hello(@NotNull final String name, @Nullable Composer $composer, final int $changed) {
29+
Intrinsics.checkNotNullParameter(name, "name");
30+
$composer = $composer.startRestartGroup(274849561);
31+
ComposerKt.sourceInformation($composer, "C(Hello)7@166L10:Greeting.kt#tlkiwl");
32+
int $dirty = $changed;
33+
if (($changed & 14) == 0) {
34+
$dirty = $changed | ($composer.changed(name) ? 4 : 2);
35+
}
36+
37+
if (($dirty & 11 ^ 2) == 0 && $composer.getSkipping()) {
38+
$composer.skipToGroupEnd();
39+
} else {
40+
TextKt.Text-fLXpl1I(name, (Modifier)null, 0L, 0L, (FontStyle)null, (FontWeight)null, (FontFamily)null, 0L, (TextDecoration)null, (TextAlign)null, 0L, 0, false, 0, (Function1)null, (TextStyle)null, $composer, 14 & $dirty, 0, 65534);
41+
}
42+
43+
ScopeUpdateScope var4 = $composer.endRestartGroup();
44+
if (var4 != null) {
45+
var4.updateScope((Function2)(new Function2() {
46+
public final void invoke(@Nullable Composer $composer, int $force) {
47+
GreetingKt.Hello(name, $composer, $changed | 1);
48+
}
49+
}));
50+
}
51+
52+
}
53+
}
54+
```
55+
56+
657
## Where can i find the source code
758
https://android.googlesource.com/platform/frameworks/support/+/refs/heads/androidx-master-dev/compose/compiler/compiler-hosted/
859

0 commit comments

Comments
 (0)