Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
More parser cleanup, added generic argument support for parent classe…
…s, started looking into implementing model support and successfully adding method statements in the class breakdown. Some attempt for internal/anonymous functions
  • Loading branch information
Amanda Hinchman-Dominguez committed May 18, 2019
1 parent 8412ebd commit 25a2909
Show file tree
Hide file tree
Showing 7 changed files with 330 additions and 179 deletions.
22 changes: 22 additions & 0 deletions Notes.md
@@ -0,0 +1,22 @@
# Notes on AST Parsing

### Generics

Generics will always look like this:
AST Parsing for ItemViewModel<SomeGenericClass>
```$xslt
CallConstructor(type=Simple(pieces=[Piece(name=ItemViewModel, typeParams=[Type(mods=[], ref=Simple(pieces=[Piece(name=CatSchedule, typeParams=[])]))])]), typeArgs=[Type(mods=[], ref=Simple(pieces=[Piece(name=CatSchedule, typeParams=[])]))], args=[], lambda=null)
```


Getting the generic type:
```$xslt
"List<" + node.expr().typeArgs().getObject(0).ref().getType() + ">"
```


##### Difference between Type Parameter and Type Argument

**Type parameter** is blueprint or placeholder for a type declared in generic.

**Type argument** is actual type used to parametrize generic.
29 changes: 8 additions & 21 deletions src/main/kotlin/com/github/ast/parser/KParser.kt
Expand Up @@ -72,9 +72,9 @@ interface KParser {
* - structs: companion objects, etc TODO get to this eventually
*
* @param className: [String] -> Node.Decl.name of class
* @param file: [Node.File] -> kastree.ast.Node.File
* @param structuredNode: [Node.Decl.Structured] -> kastree.ast.Node.Decl.Structured
*/
fun breakDownClass(className: String, file: Node.File)
fun breakDownClass(className: String, structuredNode: Node.Decl.Structured)

/**
* Convert method with [Gson] and start breaking down class methods
Expand Down Expand Up @@ -106,7 +106,7 @@ interface KParser {
* @param methodStatements: [ArrayList] -> ArrayList of [String] passed down
* to preserve methods per class
*/
fun breakdownBody(body: JsonObject, methodStatements: ArrayList<String>)
fun breakdownBody(body: JsonObject, methodStatements: ArrayList<String>): ArrayList<String>

/**
* Breakdown the contents of a method located in a block, or { }.
Expand All @@ -116,7 +116,7 @@ interface KParser {
* @param methodStatements: [ArrayList] -> ArrayList of [Method] passed down
* to preserve methods per class
*/
fun breakdownStmts(stmts: JsonArray, methodStatements: ArrayList<String>? = ArrayList())
fun breakdownStmts(stmts: JsonArray, methodStatements: ArrayList<String> = ArrayList()): ArrayList<String>

/**
* Determine whether a node declaration is an expression:
Expand Down Expand Up @@ -163,12 +163,11 @@ interface KParser {
fun breakdownExpr(
expr: JsonObject,
buildStmt: String,
methodStatements: ArrayList<String>? = arrayListOf()
methodStatements: ArrayList<String> = arrayListOf()
): String

/**
* TODO FIND THE DIFFERENCE BETWEEN PARAMS, ARGUMENTS, AND PARAMS
* Breaks down parameter values passed within a method call
* Breaks down parameter values defined in a function call
*
* @param params: [JsonArray] -> node parameters
* @param buildStmt: [String] -> Buildup of statement string to record
Expand All @@ -179,7 +178,7 @@ interface KParser {
fun getParams(params: JsonArray, buildStmt: String): String

/**
* TODO FIND THE DIFFERENCE BETWEEN PARAMS, ARGUMENTS, AND PARAMS
* TODO FIND ELEMENT DEFINITION
* Breaks down elements within a collection
*
* @param elems: [JsonArray] -> node elements
Expand All @@ -191,8 +190,7 @@ interface KParser {
fun getElems(elems: JsonArray, buildStmt: String): String

/**
* TODO FIND THE DIFFERENCE BETWEEN PARAMS, ARGUMENTS, AND PARAMS
* Breaks down parameter values passed within a method call
* Breaks down argument, the actual value passed to the function
*
* @param arguments: [JsonArray] -> node arguments
* @param buildStmt: [String] -> Buildup of statement string to record
Expand Down Expand Up @@ -268,15 +266,4 @@ interface KParser {
*/
fun getProperty(node: JsonObject, isolated: JsonObject, isolatedName: String): Property

/***
* Kastree readOnly values indicates whether a value is mutable or immutable.
*
* @param node: [JsonObject] - node property
* @param isolated: [JsonObject] - for potential dependency injection
* @param isolatedName: [String] - name assigned to property
*
* @return [String] 'val' or 'var'
*/
fun valOrVar(node: JsonObject): String

}

0 comments on commit 25a2909

Please sign in to comment.