Slide 1

Slide 1 text

Dynamic Exploration of Static Analysis with Compose Sam Edwards @HandstandSam

Slide 2

Slide 2 text

@HandstandSam

Slide 3

Slide 3 text

Joined Android Foundation

Slide 4

Slide 4 text

First Task “As an Android developer, I want to know which Development Apps exercise the :impl Gradle Modules my team owns.”

Slide 5

Slide 5 text

First Task “As an Android developer, I want to know which Development Apps exercise the :impl Gradle Modules my team owns.”

Slide 6

Slide 6 text

First Task “As an Android developer, I want to know which Development Apps exercise the :impl Gradle Modules my team owns.”

Slide 7

Slide 7 text

First Task “As an Android developer, I want to know which Development Apps exercise the :impl Gradle Modules my team owns.”

Slide 8

Slide 8 text

Module Structure at Square

Slide 9

Slide 9 text

Android Module Structure speakerdeck.com/vrallev/android-at-scale-at-square

Slide 10

Slide 10 text

Development Apps speakerdeck.com/vrallev/android-at-scale-at-square

Slide 11

Slide 11 text

Development Apps speakerdeck.com/vrallev/android-at-scale-at-square

Slide 12

Slide 12 text

I have a plan.

Slide 13

Slide 13 text

Dependency Guard github.com/dropbox/dependency-guard

Slide 14

Slide 14 text

Custom Gradle Plugin & Task • Con fi gure Project • Resolve all Transitive Dependencies • Execute Task • Report Output

Slide 15

Slide 15 text

Initial Output Development App -> Dependencies

Slide 16

Slide 16 text

Kotlin Source Configurations • Runtime Con fi guration • Test Con fi guration • Release Con fi guration • Debug Con fi guration • Android Test Con fi guration

Slide 17

Slide 17 text

Gradle Gradle Plugin

Slide 18

Slide 18 text

Gradle -> JSON Gradle Plugin Shared Models (data class) .json

Slide 19

Slide 19 text

Gradle -> JSON -> React JS Gradle Plugin Shared Models (data class) .json

Slide 20

Slide 20 text

Dynamic Exploration React JS

Slide 21

Slide 21 text

Kotlin Multiplatform Shared Models & Serialization Gradle Plugin

Slide 22

Slide 22 text

Kotlin Multiplatform Shared Models & Serialization Gradle Plugin Shared Models (data class) .json

Slide 23

Slide 23 text

Kotlin Multiplatform Shared Models & Serialization Gradle Plugin Shared Models (data class) .json Compose Report

Slide 24

Slide 24 text

Compose Multiplatform Web (WASM)

Slide 25

Slide 25 text

THIS IS SO COOL

Slide 26

Slide 26 text

Compose Web (WASM) - September 2023

Slide 27

Slide 27 text

Compose Multiplatform Web (WASM)

Slide 28

Slide 28 text

Compose Multiplatform Web (WASM)

Slide 29

Slide 29 text

Compose Multiplatform Web (WASM)

Slide 30

Slide 30 text

Compose Web (WASM) - September 2023 • Wow, this is cool! • I can’t paste into the search inputs. • I can’t select the text from the results table. • This isn’t the right fi t…

Slide 31

Slide 31 text

Compose Web (WASM) - October 23’ Compose Web (WASM) - Now in Alpha (Kotlin 2.0.0)

Slide 32

Slide 32 text

Compose HTML • Accessible from anywhere • Copy/Paste Support • Standalone, doesn’t require any backend (GitHub Pages) • Familiar to Kotlin developers • Dynamic Exploration

Slide 33

Slide 33 text

🔃 Invert Inverted view of your Gradle Project

Slide 34

Slide 34 text

./gradlew :invert

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

Demo!

Slide 37

Slide 37 text

Inverted Dependencies Link

Slide 38

Slide 38 text

Slide 39

Slide 39 text

Couldn’t you have used Chat GPT to do it?

Slide 40

Slide 40 text

How do I ask my codebase questions? 🤔

Slide 41

Slide 41 text

IntelliJ Search

Slide 42

Slide 42 text

Find Usages

Slide 43

Slide 43 text

Type Hierarchy

Slide 44

Slide 44 text

Code Structure

Slide 45

Slide 45 text

Context

Slide 46

Slide 46 text

Analysis Creates Context

Slide 47

Slide 47 text

No content

Slide 48

Slide 48 text

Easy Questions Examples • Find the word “Analytics” in a fi le named *.kt? • Which fi les have the import “kotlin.test.Test”? Requirements • File contents indexed & searchable

Slide 49

Slide 49 text

Hard Questions Examples • Is my code formatted correctly? • Did I follow our coding patterns in my latest commit? • Can you fi nd the usages of the Analytics interface? • What are the concrete implementations of the Analytics interface?

Slide 50

Slide 50 text

Hard Questions Requirements • Code Structure • Type Resolution • References • Build Con fi guration

Slide 51

Slide 51 text

Multiple Hard Questions 1. What are the concrete implementations of the Analytics interface? 2. What modules are they in? 3. Who are the owners of that module? 4. What fi les are they in?

Slide 52

Slide 52 text

Ask Question, Run Analysis

Slide 53

Slide 53 text

Ask Question, Run Analysis

Slide 54

Slide 54 text

What if we…

Slide 55

Slide 55 text

Run Analysis, Ask Questions

Slide 56

Slide 56 text

Run Analysis, Ask Questions

Slide 57

Slide 57 text

Context

Slide 58

Slide 58 text

Dynamic Exploration ✅ with Compose ✅ Static Analysis 🧐

Slide 59

Slide 59 text

Static Analysis

Slide 60

Slide 60 text

https://en.wikipedia.org/wiki/Static_program_analysis Static Analysis Analysis of source code without executing it.

Slide 61

Slide 61 text

Static Analysis Popular Tools

Slide 62

Slide 62 text

How do they work?

Slide 63

Slide 63 text

AST (Abstract Syntax Tree) • Kotlin PSI (Program Structure Interface) • Parses Kotlin Code into an AST Representation • Traversable

Slide 64

Slide 64 text

No content

Slide 65

Slide 65 text

K2 and FIR

Slide 66

Slide 66 text

Use Case: Finding Anvil & Dagger Injections with PSI

Slide 67

Slide 67 text

Why? Missing Dagger Bindings > Task :app:kaptKotlin FAILED /Users/samedwards/Development/invert/examples/app/build/tmp/kapt3/ stubs/main/com/squareup/invert/examples/AppComponent.java:7: error: [Dagger/MissingBinding] com.squareup.invert.examples.di.NetworkGraph cannot be provided without an @Provides-annotated method. public abstract interface AppComponent { ^ Missing binding usage: com.squareup.invert.examples.di.NetworkGraph is requested at com.squareup.invert.examples.AppComponent.networking()

Slide 68

Slide 68 text

Why? Missing Dagger Bindings > Task :app:kaptKotlin FAILED /Users/samedwards/Development/invert/examples/app/build/tmp/kapt3/ stubs/main/com/squareup/invert/examples/AppComponent.java:7: error: [Dagger/MissingBinding] com.squareup.invert.examples.di.NetworkGraph cannot be provided without an @Provides-annotated method. public abstract interface AppComponent { ^ Missing binding usage: com.squareup.invert.examples.di.NetworkGraph is requested at com.squareup.invert.examples.AppComponent.networking()

Slide 69

Slide 69 text

Missing Bindings Demo! ./gradlew :app:assemble

Slide 70

Slide 70 text

Find DI Provides and Injects • Scan the Kotlin Source fi les for each module • Where is a type provided? • Where is a type injected? • Enable dynamic exploration of results

Slide 71

Slide 71 text

Contributes @ContributesBinding(AppScope::class) class LiveNetworkGraph @Inject constructor( override val userRepo: UserRepo, override val categoryRepo: CategoryRepo, val networkConfig: NetworkConfig, val httpClient: HttpClient, ) : NetworkGraph {}

Slide 72

Slide 72 text

Contributes @ContributesBinding(AppScope::class) class LiveNetworkGraph @Inject constructor( override val userRepo: UserRepo, override val categoryRepo: CategoryRepo, val networkConfig: NetworkConfig, val httpClient: HttpClient, ) : NetworkGraph {}

Slide 73

Slide 73 text

Contributes @ContributesBinding(AppScope::class) class LiveNetworkGraph @Inject constructor( override val userRepo: UserRepo, override val categoryRepo: CategoryRepo, val networkConfig: NetworkConfig, val httpClient: HttpClient, ) : NetworkGraph {}

Slide 74

Slide 74 text

Injects @ContributesBinding(AppScope::class) class LiveNetworkGraph @Inject constructor( override val userRepo: UserRepo, override val categoryRepo: CategoryRepo, val networkConfig: NetworkConfig, val httpClient: HttpClient, ) : NetworkGraph {}

Slide 75

Slide 75 text

Injects @ContributesBinding(AppScope::class) class LiveNetworkGraph @Inject constructor( override val userRepo: UserRepo, override val categoryRepo: CategoryRepo, val networkConfig: NetworkConfig, val httpClient: HttpClient, ) : NetworkGraph {}

Slide 76

Slide 76 text

Injects @ContributesBinding(AppScope::class) class LiveNetworkGraph @Inject constructor( override val userRepo: UserRepo, override val categoryRepo: CategoryRepo, val networkConfig: NetworkConfig, val httpClient: HttpClient, ) : NetworkGraph {}

Slide 77

Slide 77 text

Injects @ContributesBinding(AppScope::class) class LiveNetworkGraph @Inject constructor( override val userRepo: UserRepo, override val categoryRepo: CategoryRepo, val networkConfig: NetworkConfig, val httpClient: HttpClient, ) : NetworkGraph {}

Slide 78

Slide 78 text

Injects @ContributesBinding(AppScope::class) class LiveNetworkGraph @Inject constructor( override val userRepo: UserRepo, override val categoryRepo: CategoryRepo, val networkConfig: NetworkConfig, val httpClient: HttpClient, ) : NetworkGraph {}

Slide 79

Slide 79 text

Live PSI Coding LiveNetworkGraph KotlinconfLiveNetworkGraphPsiTest

Slide 80

Slide 80 text

PsiViewer github.com/JetBrains/psiviewer

Slide 81

Slide 81 text

StatiK github.com/rickbusarow/statik • psiElement.printEverything() • com.rickbusarow.statik:statik-kotlin-psi:0.1.0-SNAPSHOT

Slide 82

Slide 82 text

FIR Tree plugins.jetbrains.com/plugin/23270- fi r-tree

Slide 83

Slide 83 text

Provides/Injects Report Demo ./gradlew :invert

Slide 84

Slide 84 text

No content

Slide 85

Slide 85 text

No content

Slide 86

Slide 86 text

What other questions could be asked?

Slide 87

Slide 87 text

It’s up to you.

Slide 88

Slide 88 text

🔃 Invert Playbook • Collector Plugin Ecosystem • Ability to create customized report pages • Available and Up-to-date on CI via GitHub Pages • Supports Deep Links

Slide 89

Slide 89 text

Sam Edwards @HandstandSam Thank you,
 and don’t forget
 to vote