How to get the entire AST instead of just the summary?
See original GitHub issueHi!
The title says it basically. How do you get the entire AST, with DefaultAstNodes converted to the Klass Data classes, from a kotlinfile. In the example the following function is invoked:
kotlinFile.summary()
This function does not include the body of a function for example. I tried to create my own function:
kotlinFile.complete()
private val completeTreeMap: TreeMap = DefaultTreeMap(
annotationsMapper,
declarationsMapper,
expressionsMapper.flattenNames("functionDeclaration"),
globalsMapper,
kotlinDefaultMapper,
modifierMapper,
stringMapper,
typesMapper
)
fun List<Ast>.complete(): AstResult<List<Ast>> {
return completeTreeMap.treeMap(this)
}
fun Ast.complete(): AstResult<List<Ast>> {
return listOf(this).complete()
}
I tried to change the Mappers in the DefaultTreeMap, but couldn’t get a configuration to be able to visit the statements in the body of functions.
Hopefully this is enough information to be able to resolve my problem.
Thanks in advance!
Issue Analytics
- State:
- Created 3 years ago
- Comments:10
Top Results From Across the Web
Python AST library to get all assignment statements
You could use ast.NodeTransformer and the visit_Assign and visit_AugAssign methods. Here's a quick demonstration: import ast import inspect ...
Read more >ast — Abstract Syntax Trees — Python 3.11.1 documentation
Each concrete class has an attribute _fields which gives the names of all child nodes. Each instance of a concrete class has one...
Read more >Manipulating AST with JavaScript - Tan Li Hau
Creating a node There are a few ways you can create an AST node. The simplest and crudest way is to manually create...
Read more >Leveling Up One's Parsing Game With ASTs | by Vaidehi Joshi
Okay, so now we have two trees to keep straight in our heads. We already had a parse tree, and how there's yet...
Read more >Introduction to Abstract Syntax Trees - Twilio
AST stands for Abstract Syntax Tree and they power a lot of parts of your development flow. Some people might have heard about...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi,
I added a new Option:
kotlinFile.summary(attachRawAst = true)
attachRawAst: Boolean
is now a required argument for summary.The Version is
c35b50fa44
Hi @miniyoung84, the Screenshot was taken from IntelliJ IDEA (https://kotlinlang.org/docs/tutorials/jvm-get-started.html)