fbsamples / kotlin_ast_tools Goto Github PK
View Code? Open in Web Editor NEWUtilities and examples used in Meta to simplify migration from Java to Kotlin and maintenance of Kotlin code.
License: Apache License 2.0
Utilities and examples used in Meta to simplify migration from Java to Kotlin and maintenance of Kotlin code.
License: Apache License 2.0
./gradlew run <kotlin file>
command is failing.
The correct command is
./gradlew run --args <kotlin file path>
or
./gradlew run --args="<kotlin_file_path>"
or for multiple files
./gradlew run --args="<kotlin_file_path_1> <kotlin_file_path_2>"
By just using Kotlin Compiler APIs to parse the AST, we can only resolve AST for one particular file. But is it possible to resolve types from other files?
To resolve types and other class information of the class that is in some other file, we would need bindingContext. I assume when we are developing a compiler plugin we would get the binding context. But if we are solely relying on Kotlin compiler APIs and parsing on one file at a time, is it possible to resolve the types of classes in other files?
Relevant questions:
https://discuss.kotlinlang.org/t/how-to-get-declaring-ktfile-ktclass-using-ktcallexpression/26271/1
https://stackoverflow.com/questions/44986763/psitreevisitor-how-to-find-out-type-of-ktcallexpression-receiver
Hello, thank you for sharing this tool. I found a problem when trying to match multiline:
given:
private var otherField: String? = null
@JvmField
@Inject
var fileDownloader: FileDownloader? = null
Matcher:
.replaceAllWithVariables<KtExpression>(
matcher =
template {
val a by match<KtExpression>()
val b by match<KtExpression>()
"""
@JvmField
@Inject
var $a: $b? = null
""".trimIndent()
},
replaceWith = { (result, variables) ->
val a by variables
val b by variables
"""
@Inject
lateinit var $a: $b
""".trimIndent()
}
this tool will throw exception
Exception in thread "main" java.lang.IllegalStateException: Template references variable $a as a matcher of KtProperty, but variable was defined as a matcher of KtExpression
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.