dalexander
11/04/2020, 8:53 PMTransformation.newSources
from within that function, or how to create a new KtFile successfully (the KtFile I've created and added to the files list have led to a NPE with the message 'VirtualFile is null for KtFile'). Any insight into how to create the provider in a second phase of analysis would be helpful, or a way of incrementally building a file during analysis that would only be written out when analysis was completed.raulraja
11/04/2020, 9:05 PMdalexander
11/04/2020, 9:16 PMcreatePhysicalFile
instead, which seems to resolve the issue.Transform.newSources<KtFile>(fileText.file(fileName, filePath))
in the analysisCompleted
phase doesn't seem to work because internally it creates a KtFile that doesn't have a virtualPath, so trying to use that seems to cause a NPE I mentioned in the original message.raulraja
11/05/2020, 6:04 PMdalexander
11/05/2020, 6:06 PMfun Meta.reanalyze(
shouldReanalyze: () -> Boolean,
onReanalyze: () -> Unit
): ExtensionPhase =
analysis(
doAnalysis = { _, _, _, _, _, _ -> null },
analysisCompleted = { project, module, bindingTrace, files ->
if (shouldReanalyze()) {
onReanalyze()
AnalysisResult.RetryWithAdditionalRoots(
bindingTrace.bindingContext,
module,
emptyList(),
listOfNotNull(),
addToEnvironment = true
)
} else {
null
}
}
)
In case anyone else out there is trying to manage a many-to-one mapping of source files/classes to output files, adding this particular extension phase to the extension phases in a meta()
will cause analysis to be re-performed, then you can use quote syntax to generate new sources. Hopefully this saves someone some time.