Craig
01/03/2022, 10:00 PMComposableCallChecker
runs, which I think means it needs to happen in the frontend.
I tried this is in a AnalysisHandlerExtension
myKtNamedFunction.addAnnotationEntry(KtPsiFactory(project).createAnnotationEntry("@androidx.compose.runtime.Composable"))
but it throws "Cannot modify a read-only file 'main.kt'"Karel Petránek
01/03/2022, 10:24 PMclass MyAnalysisExtension() : AnalysisHandlerExtension {
override fun doAnalysis(
project: Project,
module: ModuleDescriptor,
projectContext: ProjectContext,
files: Collection<KtFile>,
bindingTrace: BindingTrace,
componentProvider: ComponentProvider
): AnalysisResult? {
val mutableFiles = files as ArrayList<KtFile> // WARNING: hacky, can break any time
for (i in mutableFiles.indices) {
val newSourceString = mutableFiles[i].text // Change this source code string however you like
mutableFiles[i] = replaceFile(file, newSourceString)
}
return super.doAnalysis(project, module, projectContext, files, bindingTrace, componentProvider)
}
private fun replaceFile(file: KtFile, newSource: String): KtFile {
val result = KtFile(
viewProvider =
ReplacedFileViewProvider(file.manager, file.virtualFile, newSource),
isCompiled = false
)
result.isCommonSource = file.isCommonSource
return result
}
}
class ReplacedFileViewProvider(
psiManager: PsiManager,
virtualFile: VirtualFile,
private val newSource: String
) : SingleRootFileViewProvider(psiManager, virtualFile) {
override fun getDocument(): Document? {
return super.getDocument()?.also { it.setText(newSource) }
}
}
I hope you can figure the way from here. This approach was inspired by the Arrow Meta codebase, to give credit where it’s due 🙂Craig
01/04/2022, 2:46 AMmcpiroman
01/04/2022, 10:36 AMCraig
01/04/2022, 10:52 AMComposableCallChecker
that runs on the frontend and ensures that composables are called by composables; the signature is:
override fun check(
resolvedCall: ResolvedCall<*>,
reportOn: PsiElement,
context: CallCheckerContext
) {
Chachako
01/04/2022, 11:32 AMCraig
01/04/2022, 10:58 PMKarel Petránek
01/07/2022, 12:48 PMdmitriy.novozhilov
01/07/2022, 12:49 PMdmitriy.novozhilov
01/07/2022, 12:53 PMKarel Petránek
01/07/2022, 12:53 PM