alp
06/06/2022, 2:17 AM"org.jetbrains.kotlin:kotlin-compiler-embeddable:1.5.32"
, the project targets JVM only(android), and I create a simple gradle plugin to analyze some kotlin source files.
I create a KotlinCoreEnvironment
and pass there all the paths to analyze. I add them to the config like:
configuration.addKotlinSourceRoots(kotlinFiles)
configuration.addJvmClasspathRoots(classpath)
Then I create the binding context like:
analyzer.analyzeAndReport(files) {
TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(
environment.project,
files,
NoScopeRecordCliBindingTrace(),
environment.configuration,
environment::createPackagePartProvider,
::FileBasedDeclarationProviderFactory
)
}
return analyzer.analysisResult.bindingContext // I use this bindingContext
I have the binding context and start analyzing the file. The goal is to get some types and classes for methods from the expressions like:
Foo()
.bar() // returns Bar object
.baz() // returns Baz object
where Foo
, Bar
and Baz
are 3 different classes in different kt files.I want to understand all the types by parsing such piece of code but not able to. I searched this channel for BindingContext
, BindingTrace
and other keywords but nothing worked for me. I tried calling getResolvedCall
and getCall
on above expressions, everything returns null, same for trying to get Type
or anything that I think may help me to resolve the target file that contains the functions from the code snippet above. Also, played with BindingUtils
with no luck.
I’m just learning how compiler works but the information is relatively limited so I mostly use some existing projects to understand the internals. Please let me know how if what I’m indenting to do is achievable.
Thanks in advancealp
06/06/2022, 6:24 AMshikasd
06/06/2022, 6:20 PMalp
06/06/2022, 6:29 PMAnalysisHandlerExtension
docs/examples? So far I’ve seen in in arrow-kt I guessshikasd
06/06/2022, 6:34 PMalp
06/06/2022, 6:35 PMshikasd
06/06/2022, 6:36 PMalp
06/06/2022, 6:37 PMshikasd
06/06/2022, 6:38 PMalp
06/06/2022, 6:38 PMshikasd
06/06/2022, 6:39 PMalp
06/06/2022, 6:39 PMThe following are not goals of KSP:
• Examining expression-level information of source code.I need to analyze KtExpression so probably not gonna work for me
shikasd
06/06/2022, 6:40 PMshikasd
06/06/2022, 6:42 PMalp
06/06/2022, 8:49 PMalp
06/06/2022, 8:49 PM