New J2K: Introduce invalidate to mark element for removal, freeing it's children
This commit is contained in:
committed by
Ilya Kirillov
parent
7c5e9cd669
commit
b7fd8e32cb
@@ -60,6 +60,7 @@ class FieldToPropertyConversion : MatchBasedConversion() {
|
||||
|
||||
if (field != null) {
|
||||
// TODO: proper accessors
|
||||
field.invalidate()
|
||||
val property =
|
||||
JKKtPropertyImpl(field.modifierList, field.type, field.name, field.initializer, JKBlockImpl(), JKBlockImpl())
|
||||
|
||||
|
||||
+12
-7
@@ -31,13 +31,18 @@ class JavaMethodToKotlinFunctionConversion : TransformerBasedConversion() {
|
||||
override fun visitClass(klass: JKClass) {
|
||||
somethingChanged = true
|
||||
klass.declarationList = klass.declarationList.map {
|
||||
if (it is JKJavaMethod) JKKtFunctionImpl(
|
||||
JKTypeElementImpl(JKJavaPrimitiveTypeImpl.BOOLEAN),
|
||||
it.name,
|
||||
it.valueArguments,
|
||||
it.block,
|
||||
it.modifierList
|
||||
) else it
|
||||
if (it is JKJavaMethod) {
|
||||
it.invalidate()
|
||||
JKKtFunctionImpl(
|
||||
JKTypeElementImpl(JKJavaPrimitiveTypeImpl.BOOLEAN),
|
||||
it.name,
|
||||
it.valueArguments,
|
||||
it.block,
|
||||
it.modifierList
|
||||
)
|
||||
} else {
|
||||
it
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -86,13 +86,29 @@ abstract class JKBranchElementBase : JKElementBase(), JKBranchElement {
|
||||
}
|
||||
|
||||
final override fun <D> acceptChildren(visitor: JKVisitor<Unit, D>, data: D) {
|
||||
forEachChild { it.accept(visitor, data) }
|
||||
}
|
||||
|
||||
protected inline fun forEachChild(block: (JKTreeElement) -> Unit) {
|
||||
children.forEach {
|
||||
if (it is JKTreeElement)
|
||||
it.accept(visitor, data)
|
||||
block(it)
|
||||
else
|
||||
(it as? List<JKTreeElement>)?.forEach { it.accept(visitor, data) }
|
||||
(it as? List<JKTreeElement>)?.forEach { block(it) }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
final override var valid: Boolean = true
|
||||
|
||||
final override fun invalidate() {
|
||||
forEachChild { it.detach(this) }
|
||||
valid = false
|
||||
}
|
||||
|
||||
override fun onAttach() {
|
||||
check(valid)
|
||||
}
|
||||
|
||||
override val children: MutableList<Any> = mutableListOf()
|
||||
}
|
||||
|
||||
@@ -26,8 +26,6 @@ class JKJavaFieldImpl(
|
||||
name: JKNameIdentifier,
|
||||
initializer: JKExpression
|
||||
) : JKJavaField, JKBranchElementBase() {
|
||||
override val valid: Boolean
|
||||
get() = true
|
||||
|
||||
override fun <R, D> accept(visitor: JKVisitor<R, D>, data: D): R = visitor.visitJavaField(this, data)
|
||||
|
||||
@@ -53,8 +51,6 @@ class JKJavaMethodImpl(
|
||||
override var valueArguments: List<JKValueArgument> by children(valueArguments)
|
||||
override var block: JKBlock by child(block)
|
||||
|
||||
override val valid: Boolean
|
||||
get() = true
|
||||
}
|
||||
|
||||
class JKJavaLiteralExpressionImpl(
|
||||
|
||||
@@ -31,7 +31,6 @@ class JKClassImpl(
|
||||
override var modifierList by child(modifierList)
|
||||
override var declarationList by children<JKDeclaration>()
|
||||
|
||||
override val valid: Boolean = true
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -28,8 +28,6 @@ class JKKtPropertyImpl(
|
||||
setter: JKBlock
|
||||
) : JKBranchElementBase(), JKKtProperty {
|
||||
override fun <R, D> accept(visitor: JKVisitor<R, D>, data: D): R = visitor.visitKtProperty(this, data)
|
||||
override val valid: Boolean
|
||||
get() = true
|
||||
|
||||
override var modifierList: JKModifierList by child(modifierList)
|
||||
override var type by child(type)
|
||||
@@ -46,8 +44,6 @@ class JKKtFunctionImpl(
|
||||
block: JKBlock,
|
||||
modifierList: JKModifierList
|
||||
) : JKBranchElementBase(), JKKtFunction {
|
||||
override val valid: Boolean
|
||||
get() = true
|
||||
|
||||
override var returnType: JKTypeElement by child(returnType)
|
||||
override var name: JKNameIdentifier by child(name)
|
||||
|
||||
@@ -18,11 +18,11 @@ package org.jetbrains.kotlin.j2k.tree
|
||||
|
||||
import org.jetbrains.kotlin.j2k.tree.impl.JKMethodSymbol
|
||||
|
||||
interface JKJavaField : JKField {
|
||||
interface JKJavaField : JKField, JKBranchElement {
|
||||
val initializer: JKExpression
|
||||
}
|
||||
|
||||
interface JKJavaMethod : JKMethod {
|
||||
interface JKJavaMethod : JKMethod, JKBranchElement {
|
||||
val block: JKBlock
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ interface JKTreeElement : JKElement {
|
||||
fun <D> acceptChildren(visitor: JKVisitor<Unit, D>, data: D)
|
||||
}
|
||||
|
||||
interface JKDeclaration : JKTreeElement, JKReferenceTarget
|
||||
interface JKDeclaration : JKTreeElement
|
||||
|
||||
interface JKClass : JKDeclaration, JKModifierListOwner {
|
||||
val name: JKNameIdentifier
|
||||
|
||||
@@ -34,16 +34,15 @@ interface JKElement {
|
||||
|
||||
interface JKBranchElement : JKElement {
|
||||
val children: List<Any>
|
||||
|
||||
val valid: Boolean
|
||||
fun invalidate()
|
||||
}
|
||||
|
||||
interface JKModifierListOwner {
|
||||
var modifierList: JKModifierList
|
||||
}
|
||||
|
||||
interface JKReferenceTarget {
|
||||
val valid: Boolean
|
||||
}
|
||||
|
||||
interface JKType
|
||||
|
||||
interface JKClassType : JKType {
|
||||
|
||||
Reference in New Issue
Block a user