This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import kotlin.contracts.ExperimentalContracts | |
| import kotlin.contracts.contract | |
| /** | |
| * @author Adib Faramarzi (adibfara@gmail.com) | |
| */ | |
| @ExperimentalContracts | |
| fun createOnce(runFunction: ()-> Unit) { | |
| contract { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * @author Adib Faramarzi (adibfara@gmail.com) | |
| */ | |
| fun Any?.isAValidName():Boolean{ | |
| return this!=null && this is String && this.length > 3 | |
| } | |
| fun getName():String? { ... } | |
| fun testUserName(){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * @author Adib Faramarzi (adibfara@gmail.com) | |
| */ | |
| fun createOnce(runFunction: ()-> Unit) { | |
| runFunction() | |
| } | |
| fun getKotlinVersion(): Float{ | |
| val kotlinVersion: Float |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // add kotlin gradle plugin (v1.3 and above) | |
| buildscript { | |
| dependencies { | |
| classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3" | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Target(AnnotationTarget.FUNCTION) | |
| @Retention(AnnotationRetention.SOURCE) | |
| annotation class Listed( | |
| val name: String, | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Inside your app's module, declare a dependency to your ksp module | |
| dependencies { | |
| implementation project(":ksp") // since you want to use your @Listed annotation | |
| ksp project(":ksp") // to make KSP work | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| internal class ListedProcessor( | |
| private val environment: SymbolProcessorEnvironment, | |
| ) : SymbolProcessor { | |
| private fun Resolver.findAnnotations( | |
| kClass: KClass<*>, | |
| ) = getSymbolsWithAnnotation( | |
| kClass.qualifiedName.toString()) | |
| .filterIsInstance<KSFunctionDeclaration>().filter { | |
| it.parameters.isEmpty() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| internal class ListedProcessor( | |
| private val environment: SymbolProcessorEnvironment, | |
| ) : SymbolProcessor { | |
| private fun Resolver.findAnnotations( | |
| kClass: KClass<*>, | |
| ) = getSymbolsWithAnnotation( | |
| kClass.qualifiedName.toString()) | |
| .filterIsInstance<KSFunctionDeclaration>().filter { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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' | |
| } | |
| } |
OlderNewer