-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
kotlinx/ast does not support generating code from AST kotlinx/ast#43
- Loading branch information
Showing
7 changed files
with
75 additions
and
6 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package ktcodeshift | ||
|
||
class FlattenListTransform : Transform { | ||
override fun transform(fileInfo: FileInfo, api: Api): String { | ||
val ast = api.parse(fileInfo.source) | ||
return ast.toString() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package ktcodeshift | ||
|
||
import kotlinx.ast.common.AstSource | ||
import kotlinx.ast.common.ast.Ast | ||
import kotlinx.ast.grammar.kotlin.target.antlr.kotlin.KotlinGrammarAntlrKotlinParser | ||
|
||
fun applyTransform(transform: Transform, fileInfo: FileInfo): String { | ||
val api = Api() | ||
return transform.transform(fileInfo, api) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package ktcodeshift | ||
|
||
import kotlinx.ast.common.AstSource | ||
import kotlinx.ast.common.ast.Ast | ||
import kotlinx.ast.grammar.kotlin.target.antlr.kotlin.KotlinGrammarAntlrKotlinParser | ||
|
||
interface Transform { | ||
fun transform(fileInfo: FileInfo, api: Api/*, options: Options*/): String | ||
} | ||
|
||
interface FileInfo { | ||
val path: String | ||
val source: String | ||
} | ||
|
||
//interface Api { | ||
// | ||
//} | ||
|
||
class Api { | ||
fun parse(source: String): Ast { | ||
val astSource = AstSource.String("file", source) | ||
val ast = KotlinGrammarAntlrKotlinParser.parseKotlinFile(astSource) | ||
return ast | ||
} | ||
} | ||
|
||
//interface Options { | ||
// | ||
//} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters