Skip to content

Commit

Permalink
generate a test file
Browse files Browse the repository at this point in the history
  • Loading branch information
kaushikgopal committed Jun 27, 2023
1 parent c4bffc8 commit 3fa71a2
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package co.kaush.msusf.processor

import co.kaush.msusf.annotations.ViewModel
import com.google.devtools.ksp.processing.CodeGenerator
import com.google.devtools.ksp.processing.Dependencies
import com.google.devtools.ksp.processing.KSPLogger
import com.google.devtools.ksp.processing.Resolver
import com.google.devtools.ksp.processing.SymbolProcessor
import com.google.devtools.ksp.symbol.KSAnnotated
import com.google.devtools.ksp.symbol.KSClassDeclaration
import com.google.devtools.ksp.validate
import com.squareup.kotlinpoet.asClassName

/**
Expand Down Expand Up @@ -44,6 +46,50 @@ class ViewModelProcessor(
// hence the use of an iterator to check if it's empty
if (!symbols.iterator().hasNext()) return emptyList()

return emptyList()
val sourceFiles = symbols.mapNotNull { it.containingFile }
val fileText = buildString {
append("// ")
append(sourceFiles.joinToString(", "))
}
val file =
codeGenerator.createNewFile(
Dependencies(
false,
*sourceFiles.toList().toTypedArray(),
),
"your.generated.file.package",
"GeneratedLists",
)

file.write(fileText.toByteArray())

/*
symbols.forEach { classDeclaration ->
// The ViewModelContainer provide information on what Dagger Scope the generated classes
// should be added to all of these values are hard coded strings not the best, but I couldn't
// figure out a better way
val scopeArg: KSValueArgument? =
classDeclaration.annotations
.first { it.shortName.asString() == viewModelClassName.simpleName }
.arguments
.firstOrNull { arg -> arg.name?.asString() == "scope" }
if (scopeArg == null) {
classDeclaration.accept(ViewModelVisitor(codeGenerator, logger), Unit)
} else {
val scopeClassType = (scopeArg.value as KSType).toClassName()
if (scopeClassType == Nothing::class.asClassName() ||
scopeClassType == Void::class.asClassName()) {
classDeclaration.accept(ViewModelVisitor(codeGenerator, logger), Unit)
} else {
// classDeclaration.accept(Visitor(scopeClassType), Unit)
}
}
}
*/

return (symbols).filterNot { it.validate() }.toList()
}
}
3 changes: 3 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ dependencies {
ksp(libs.kotlin.inject.compiler)
implementation(libs.kotlin.inject.runtime)

ksp(project(":annotations-processors"))
implementation(project(":annotations"))

implementation(libs.kotlin.stdlib)
implementation(libs.constraintlayout)
implementation(libs.flowbinding)
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/co/kaush/msusf/movies/MSMovieVmImpl.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package co.kaush.msusf.movies

import co.kaush.msusf.annotations.ViewModel
import co.kaush.msusf.usf.UsfVmImpl
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow

@ViewModel
class MSMovieVmImpl(
private val movieRepo: MSMovieRepository,
coroutineScope: CoroutineScope,
Expand Down

0 comments on commit 3fa71a2

Please sign in to comment.