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) {
|
if (field != null) {
|
||||||
// TODO: proper accessors
|
// TODO: proper accessors
|
||||||
|
field.invalidate()
|
||||||
val property =
|
val property =
|
||||||
JKKtPropertyImpl(field.modifierList, field.type, field.name, field.initializer, JKBlockImpl(), JKBlockImpl())
|
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) {
|
override fun visitClass(klass: JKClass) {
|
||||||
somethingChanged = true
|
somethingChanged = true
|
||||||
klass.declarationList = klass.declarationList.map {
|
klass.declarationList = klass.declarationList.map {
|
||||||
if (it is JKJavaMethod) JKKtFunctionImpl(
|
if (it is JKJavaMethod) {
|
||||||
JKTypeElementImpl(JKJavaPrimitiveTypeImpl.BOOLEAN),
|
it.invalidate()
|
||||||
it.name,
|
JKKtFunctionImpl(
|
||||||
it.valueArguments,
|
JKTypeElementImpl(JKJavaPrimitiveTypeImpl.BOOLEAN),
|
||||||
it.block,
|
it.name,
|
||||||
it.modifierList
|
it.valueArguments,
|
||||||
) else it
|
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) {
|
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 {
|
children.forEach {
|
||||||
if (it is JKTreeElement)
|
if (it is JKTreeElement)
|
||||||
it.accept(visitor, data)
|
block(it)
|
||||||
else
|
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()
|
override val children: MutableList<Any> = mutableListOf()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,8 +26,6 @@ class JKJavaFieldImpl(
|
|||||||
name: JKNameIdentifier,
|
name: JKNameIdentifier,
|
||||||
initializer: JKExpression
|
initializer: JKExpression
|
||||||
) : JKJavaField, JKBranchElementBase() {
|
) : JKJavaField, JKBranchElementBase() {
|
||||||
override val valid: Boolean
|
|
||||||
get() = true
|
|
||||||
|
|
||||||
override fun <R, D> accept(visitor: JKVisitor<R, D>, data: D): R = visitor.visitJavaField(this, data)
|
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 valueArguments: List<JKValueArgument> by children(valueArguments)
|
||||||
override var block: JKBlock by child(block)
|
override var block: JKBlock by child(block)
|
||||||
|
|
||||||
override val valid: Boolean
|
|
||||||
get() = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class JKJavaLiteralExpressionImpl(
|
class JKJavaLiteralExpressionImpl(
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ class JKClassImpl(
|
|||||||
override var modifierList by child(modifierList)
|
override var modifierList by child(modifierList)
|
||||||
override var declarationList by children<JKDeclaration>()
|
override var declarationList by children<JKDeclaration>()
|
||||||
|
|
||||||
override val valid: Boolean = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -28,8 +28,6 @@ class JKKtPropertyImpl(
|
|||||||
setter: JKBlock
|
setter: JKBlock
|
||||||
) : JKBranchElementBase(), JKKtProperty {
|
) : JKBranchElementBase(), JKKtProperty {
|
||||||
override fun <R, D> accept(visitor: JKVisitor<R, D>, data: D): R = visitor.visitKtProperty(this, data)
|
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 modifierList: JKModifierList by child(modifierList)
|
||||||
override var type by child(type)
|
override var type by child(type)
|
||||||
@@ -46,8 +44,6 @@ class JKKtFunctionImpl(
|
|||||||
block: JKBlock,
|
block: JKBlock,
|
||||||
modifierList: JKModifierList
|
modifierList: JKModifierList
|
||||||
) : JKBranchElementBase(), JKKtFunction {
|
) : JKBranchElementBase(), JKKtFunction {
|
||||||
override val valid: Boolean
|
|
||||||
get() = true
|
|
||||||
|
|
||||||
override var returnType: JKTypeElement by child(returnType)
|
override var returnType: JKTypeElement by child(returnType)
|
||||||
override var name: JKNameIdentifier by child(name)
|
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
|
import org.jetbrains.kotlin.j2k.tree.impl.JKMethodSymbol
|
||||||
|
|
||||||
interface JKJavaField : JKField {
|
interface JKJavaField : JKField, JKBranchElement {
|
||||||
val initializer: JKExpression
|
val initializer: JKExpression
|
||||||
}
|
}
|
||||||
|
|
||||||
interface JKJavaMethod : JKMethod {
|
interface JKJavaMethod : JKMethod, JKBranchElement {
|
||||||
val block: JKBlock
|
val block: JKBlock
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ interface JKTreeElement : JKElement {
|
|||||||
fun <D> acceptChildren(visitor: JKVisitor<Unit, D>, data: D)
|
fun <D> acceptChildren(visitor: JKVisitor<Unit, D>, data: D)
|
||||||
}
|
}
|
||||||
|
|
||||||
interface JKDeclaration : JKTreeElement, JKReferenceTarget
|
interface JKDeclaration : JKTreeElement
|
||||||
|
|
||||||
interface JKClass : JKDeclaration, JKModifierListOwner {
|
interface JKClass : JKDeclaration, JKModifierListOwner {
|
||||||
val name: JKNameIdentifier
|
val name: JKNameIdentifier
|
||||||
|
|||||||
@@ -34,16 +34,15 @@ interface JKElement {
|
|||||||
|
|
||||||
interface JKBranchElement : JKElement {
|
interface JKBranchElement : JKElement {
|
||||||
val children: List<Any>
|
val children: List<Any>
|
||||||
|
|
||||||
|
val valid: Boolean
|
||||||
|
fun invalidate()
|
||||||
}
|
}
|
||||||
|
|
||||||
interface JKModifierListOwner {
|
interface JKModifierListOwner {
|
||||||
var modifierList: JKModifierList
|
var modifierList: JKModifierList
|
||||||
}
|
}
|
||||||
|
|
||||||
interface JKReferenceTarget {
|
|
||||||
val valid: Boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKType
|
interface JKType
|
||||||
|
|
||||||
interface JKClassType : JKType {
|
interface JKClassType : JKType {
|
||||||
|
|||||||
Reference in New Issue
Block a user