New J2K: Add conversion which will initialize java implicit initialized fields

This commit is contained in:
Simon Ogorodnik
2018-08-04 08:16:12 +03:00
committed by Ilya Kirillov
parent 61fd76a89a
commit 4637903e00
5 changed files with 29 additions and 5 deletions
@@ -23,6 +23,7 @@ object ConversionsRunner {
private fun createConversions(context: ConversionContext) = listOf( private fun createConversions(context: ConversionContext) = listOf(
ModalityConversion(context), ModalityConversion(context),
ImplicitInitializerConversion(),
TypeMappingConversion(context), TypeMappingConversion(context),
FieldToPropertyConversion(), FieldToPropertyConversion(),
AssignmentAsExpressionToAlsoConversion(context), AssignmentAsExpressionToAlsoConversion(context),
@@ -33,7 +34,7 @@ object ConversionsRunner {
JavaMethodToKotlinFunctionConversion(), JavaMethodToKotlinFunctionConversion(),
LiteralConversion(), LiteralConversion(),
InnerClassConversion(), InnerClassConversion(),
ModifiersConversion(), ModifiersConversion(context),
PolyadicExpressionConversion(), PolyadicExpressionConversion(),
BinaryExpressionConversion() BinaryExpressionConversion()
) )
@@ -0,0 +1,23 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.j2k.conversions
import org.jetbrains.kotlin.j2k.tree.*
import org.jetbrains.kotlin.j2k.tree.impl.JKNullLiteral
import org.jetbrains.kotlin.j2k.tree.impl.JKUnresolvedClassType
class ImplicitInitializerConversion : RecursiveApplicableConversionBase() {
override fun applyToElement(element: JKTreeElement): JKTreeElement {
if (element !is JKJavaField) return recurse(element)
if (element.initializer !is JKStubExpression) return recurse(element)
if (element.type.type is JKClassType || element.type.type is JKUnresolvedClassType) element.initializer = JKNullLiteral()
return element
}
}
@@ -79,7 +79,7 @@ class JKParameterImpl(
override fun <R, D> accept(visitor: JKVisitor<R, D>, data: D): R = visitor.visitParameter(this, data) override fun <R, D> accept(visitor: JKVisitor<R, D>, data: D): R = visitor.visitParameter(this, data)
override var modifierList by child(modifierList) override var modifierList by child(modifierList)
override val initializer by child(initializer) override var initializer by child(initializer)
override val name by child(name) override val name by child(name)
override var type by child(type) override var type by child(type)
} }
@@ -203,7 +203,7 @@ class JKBooleanLiteral(val value: Boolean) : JKLiteralExpression, JKElementBase(
class JKLocalVariableImpl(modifierList: JKModifierList, type: JKTypeElement, name: JKNameIdentifier, initializer: JKExpression) : class JKLocalVariableImpl(modifierList: JKModifierList, type: JKTypeElement, name: JKNameIdentifier, initializer: JKExpression) :
JKLocalVariable, JKBranchElementBase() { JKLocalVariable, JKBranchElementBase() {
override var modifierList by child(modifierList) override var modifierList by child(modifierList)
override val initializer by child(initializer) override var initializer by child(initializer)
override val name by child(name) override val name by child(name)
override val type by child(type) override val type by child(type)
@@ -36,7 +36,7 @@ class JKKtPropertyImpl(
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)
override var name: JKNameIdentifier by child(name) override var name: JKNameIdentifier by child(name)
override val initializer: JKExpression by child(initializer) override var initializer: JKExpression by child(initializer)
override val getter: JKBlock by child(getter) override val getter: JKBlock by child(getter)
override val setter: JKBlock by child(setter) override val setter: JKBlock by child(setter)
} }
@@ -63,7 +63,7 @@ interface JKMethod : JKDeclaration, JKModifierListOwner {
interface JKField : JKDeclaration, JKModifierListOwner { interface JKField : JKDeclaration, JKModifierListOwner {
val type: JKTypeElement val type: JKTypeElement
val name: JKNameIdentifier val name: JKNameIdentifier
val initializer: JKExpression var initializer: JKExpression
} }
interface JKLocalVariable : JKField interface JKLocalVariable : JKField