Skip to content

Instantly share code, notes, and snippets.

View vRallev's full-sized avatar

Ralf Wondratschek vRallev

View GitHub Profile
@vRallev
vRallev / IrClass.kt
Last active July 6, 2023 13:13
Generate a class with Kotlin IR.
package com.squareup.anvil.compiler
import org.jetbrains.kotlin.backend.common.IrElementTransformerVoidWithContext
import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
import org.jetbrains.kotlin.backend.common.ir.addChild
import org.jetbrains.kotlin.backend.common.ir.addSimpleDelegatingConstructor
import org.jetbrains.kotlin.backend.common.ir.createImplicitParameterDeclarationWithWrappedDescriptor
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.WARNING
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
/**
* Used to process events returned by the UI layer in the scope that runs our presenters, which
* usually is `PresenterCoroutineScope`. Without this wrapper events would be processed on the
* main thread and could potentially block the UI or cause lag.
*
* Furthermore, the returned lambda is remembered as state within the composable, which allows
* to make [BaseModel] implementations data classes. Without remembering every [BaseModel] instance
* would not equal another instance, since different lambda instances are never equal to each
* other.
*
@vRallev
vRallev / AndroidManifestDiff.kt
Last active July 7, 2025 16:33
Gradle tasks to detect changes in the merged AndroidManifest.xml file for Android applications.
/*
* Copyright 2025 Ralf Wondratschek
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@vRallev
vRallev / ktfmt.sh
Created December 24, 2025 04:20
Script for using Ktfmt in large codebases.
#!/bin/bash
set -euo pipefail
KTFMT_VERSION="0.60"
show_help() {
cat << EOF
Usage: scripts/ktfmt.sh [OPTIONS] [DIRECTORY|FILE...]
Format Kotlin files in the codebase using ktfmt with the Google style --google-style