New J2K: Wrap ast to a JKTreeRoot
This commit is contained in:
committed by
Ilya Kirillov
parent
ddee0deeca
commit
f28f340840
@@ -85,7 +85,7 @@ object ConversionsRunner {
|
||||
+SortClassMembersConversion()
|
||||
}
|
||||
|
||||
fun doApply(trees: List<JKTreeElement>, context: ConversionContext) {
|
||||
fun doApply(trees: List<JKTreeRoot>, context: ConversionContext) {
|
||||
val conversion = createRootConversion(context)
|
||||
conversion.runConversion(trees, context)
|
||||
}
|
||||
|
||||
@@ -116,6 +116,10 @@ class NewCodeBuilder {
|
||||
printer.print("/* !!! Hit visitElement for element type: ${treeElement::class} !!! */")
|
||||
}
|
||||
|
||||
override fun visitTreeRootRaw(treeRoot: JKTreeRoot) {
|
||||
treeRoot.element.accept(this)
|
||||
}
|
||||
|
||||
override fun visitKtTryExpressionRaw(ktTryExpression: JKKtTryExpression) {
|
||||
printer.printWithNoIndent("try ")
|
||||
ktTryExpression.tryBlock.accept(this)
|
||||
|
||||
@@ -29,6 +29,10 @@ import org.jetbrains.kotlin.nj2k.tree.JKLiteralExpression.LiteralType.NULL
|
||||
import org.jetbrains.kotlin.nj2k.tree.visitors.JKVisitor
|
||||
import org.jetbrains.kotlin.psi.KtClass
|
||||
|
||||
class JKTreeRootImpl(element: JKTreeElement) : JKTreeRoot, JKBranchElementBase() {
|
||||
override var element by child(element)
|
||||
override fun <R, D> accept(visitor: JKVisitor<R, D>, data: D): R = visitor.visitTreeRoot(this, data)
|
||||
}
|
||||
|
||||
class JKFileImpl(
|
||||
packageDeclaration: JKPackageDeclaration,
|
||||
|
||||
@@ -32,6 +32,10 @@ interface JKTreeElement : JKElement, JKNonCodeElementsListOwner {
|
||||
fun copy(): JKTreeElement
|
||||
}
|
||||
|
||||
interface JKTreeRoot : JKTreeElement {
|
||||
var element: JKTreeElement
|
||||
}
|
||||
|
||||
interface PsiOwner {
|
||||
var psi: PsiElement?
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import org.jetbrains.kotlin.nj2k.tree.*
|
||||
|
||||
interface JKVisitor<out R, in D> {
|
||||
fun visitTreeElement(treeElement: JKTreeElement, data: D): R
|
||||
fun visitTreeRoot(treeRoot: JKTreeRoot, data: D): R = visitTreeElement(treeRoot, data)
|
||||
fun visitDeclaration(declaration: JKDeclaration, data: D): R = visitTreeElement(declaration, data)
|
||||
fun visitImportStatement(importStatement: JKImportStatement, data: D): R = visitTreeElement(importStatement, data)
|
||||
fun visitFile(file: JKFile, data: D): R = visitTreeElement(file, data)
|
||||
|
||||
@@ -5,6 +5,8 @@ import org.jetbrains.kotlin.nj2k.tree.*
|
||||
interface JKVisitorVoid : JKVisitor<Unit, Nothing?> {
|
||||
fun visitTreeElement(treeElement: JKTreeElement)
|
||||
override fun visitTreeElement(treeElement: JKTreeElement, data: Nothing?) = visitTreeElement(treeElement)
|
||||
fun visitTreeRoot(treeRoot: JKTreeRoot) = visitTreeElement(treeRoot, null)
|
||||
override fun visitTreeRoot(treeRoot: JKTreeRoot, data: Nothing?) = visitTreeRoot(treeRoot)
|
||||
fun visitDeclaration(declaration: JKDeclaration) = visitTreeElement(declaration, null)
|
||||
override fun visitDeclaration(declaration: JKDeclaration, data: Nothing?) = visitDeclaration(declaration)
|
||||
fun visitImportStatement(importStatement: JKImportStatement) = visitTreeElement(importStatement, null)
|
||||
|
||||
@@ -14,6 +14,14 @@ interface JKVisitorWithCommentsPrinting : JKVisitorVoid {
|
||||
|
||||
fun visitTreeElementRaw(treeElement: JKTreeElement)
|
||||
|
||||
override fun visitTreeRoot(treeRoot: JKTreeRoot) {
|
||||
printLeftNonCodeElements(treeRoot)
|
||||
visitTreeRootRaw(treeRoot)
|
||||
printRightNonCodeElements(treeRoot)
|
||||
}
|
||||
|
||||
fun visitTreeRootRaw(treeRoot: JKTreeRoot) = visitTreeElementRaw(treeRoot)
|
||||
|
||||
override fun visitDeclaration(declaration: JKDeclaration) {
|
||||
printLeftNonCodeElements(declaration)
|
||||
visitDeclarationRaw(declaration)
|
||||
|
||||
Reference in New Issue
Block a user