Skip to content

Instantly share code, notes, and snippets.

View adibfara's full-sized avatar

Adib Faramarzi adibfara

View GitHub Profile
import com.google.devtools.ksp.processing.Resolver
import com.google.devtools.ksp.processing.SymbolProcessor
import com.google.devtools.ksp.processing.SymbolProcessorEnvironment
import com.google.devtools.ksp.symbol.KSAnnotated
class ListedProcessor(private val environment: SymbolProcessorEnvironment): SymbolProcessor {
override fun process(resolver: Resolver): List<KSAnnotated> {
return emptyList() // we'll return an empty list for now, since we haven't processed anything.
}
}
@adibfara
adibfara / Listed Annotation.kt
Created May 5, 2022 07:56
Create Listed Annotation
@Target(AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.SOURCE)
annotation class Listed(
val name: String,
)
@adibfara
adibfara / KSP Setup.kt
Last active May 5, 2022 14:17
Setup Guide for KSP
// to help the IDE recognize the KSP generated files, add the following to your app's build.gradle
android {
kotlin {
sourceSets.debug {
kotlin.srcDirs += 'build/generated/ksp/debug/kotlin'
}
sourceSets.release {
kotlin.srcDirs += 'build/generated/ksp/release/kotlin'
}
}
/**
* @author Adib Faramarzi (adibfara@gmail.com)
*/
fun Any?.isAValidName():Boolean{
return this!=null && this is String && this.length > 3
}
fun getName():String? { ... }
fun testUserName(){
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.contract
/**
* @author Adib Faramarzi (adibfara@gmail.com)
*/
@ExperimentalContracts
fun createOnce(runFunction: ()-> Unit) {
contract {
// add kotlin gradle plugin (v1.3 and above)
buildscript {
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3"
}
}
@adibfara
adibfara / sample-do-once-without-contracts.kt
Last active September 5, 2018 21:48
Kotlin contracts
/**
* @author Adib Faramarzi (adibfara@gmail.com)
*/
fun createOnce(runFunction: ()-> Unit) {
runFunction()
}
fun getKotlinVersion(): Float{
val kotlinVersion: Float