New J2K: Print & filter primary constructor modifiers
This commit is contained in:
committed by
Ilya Kirillov
parent
7e7d865054
commit
0873045718
@@ -194,11 +194,10 @@ class NewCodeBuilder {
|
||||
builder.append(" ")
|
||||
printer.printWithNoIndent(klass.name.value)
|
||||
klass.typeParameterList.accept(this)
|
||||
printer.printWithNoIndent(" ")
|
||||
|
||||
val primaryConstructor = klass.primaryConstructor()
|
||||
if (primaryConstructor != null && primaryConstructor.parameters.isNotEmpty()) {
|
||||
renderParameterList(primaryConstructor.parameters)
|
||||
}
|
||||
primaryConstructor?.accept(this)
|
||||
|
||||
if (klass.inheritance.inherit.isNotEmpty()) {
|
||||
printer.printWithNoIndent(" : ")
|
||||
@@ -217,10 +216,11 @@ class NewCodeBuilder {
|
||||
//TODO should it be here?
|
||||
renderExtraTypeParametersUpperBounds(klass.typeParameterList)
|
||||
|
||||
if (klass.declarationList.any { it !is JKKtPrimaryConstructor }) {
|
||||
val declarationsToPrint = klass.declarationList.filterNot { it is JKKtPrimaryConstructor}
|
||||
if (declarationsToPrint.isNotEmpty()) {
|
||||
printer.block(multiline = true) {
|
||||
renderEnumConstants(klass.declarationList.filterIsInstance())
|
||||
renderNonEnumClassDeclarations(klass.declarationList.filterNot { it is JKEnumConstant })
|
||||
renderEnumConstants(declarationsToPrint.filterIsInstance())
|
||||
renderNonEnumClassDeclarations(declarationsToPrint.filterNot { it is JKEnumConstant })
|
||||
}
|
||||
} else {
|
||||
printer.println()
|
||||
@@ -610,7 +610,19 @@ class NewCodeBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitKtPrimaryConstructor(ktPrimaryConstructor: JKKtPrimaryConstructor) {}
|
||||
override fun visitKtPrimaryConstructor(ktPrimaryConstructor: JKKtPrimaryConstructor) {
|
||||
val hasInitDeclaration =
|
||||
(ktPrimaryConstructor.parent as JKClass).declarationList.any { it is JKKtInitDeclaration }
|
||||
val hasAccessModifier =
|
||||
ktPrimaryConstructor.modifierList.modifiers.any { it is JKAccessModifier }
|
||||
if (hasAccessModifier && hasInitDeclaration && ktPrimaryConstructor.parameters.isNotEmpty()) {
|
||||
ktPrimaryConstructor.modifierList.accept(this)
|
||||
printer.printWithNoIndent(" constructor ")
|
||||
}
|
||||
if (ktPrimaryConstructor.parameters.isNotEmpty()) {
|
||||
renderParameterList(ktPrimaryConstructor.parameters)
|
||||
}
|
||||
}
|
||||
|
||||
private inline fun Printer.indented(block: () -> Unit) {
|
||||
this.pushIndent()
|
||||
|
||||
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.j2k.conversions
|
||||
import org.jetbrains.kotlin.j2k.ConversionContext
|
||||
import org.jetbrains.kotlin.j2k.ast.Mutability
|
||||
import org.jetbrains.kotlin.j2k.tree.*
|
||||
import org.jetbrains.kotlin.j2k.tree.impl.JKKtConstructorImpl
|
||||
import org.jetbrains.kotlin.j2k.tree.impl.JKKtModifierImpl
|
||||
import org.jetbrains.kotlin.j2k.tree.impl.mutability
|
||||
import org.jetbrains.kotlin.j2k.tree.impl.visibility
|
||||
@@ -29,11 +30,18 @@ class ModifiersConversion(private val context: ConversionContext) : RecursiveApp
|
||||
if (element is JKParameter) {
|
||||
convertParameterModifiers(element)
|
||||
}
|
||||
if (element is JKKtConstructor) {
|
||||
convertConstructorModifiers(element)
|
||||
}
|
||||
element.sortModifiers()
|
||||
}
|
||||
return recurse(element)
|
||||
}
|
||||
|
||||
private fun convertConstructorModifiers(constructor: JKKtConstructor) {
|
||||
constructor.filterModifiers { it !is JKModalityModifier }
|
||||
}
|
||||
|
||||
private fun convertParameterModifiers(jkParameter: JKParameter) {
|
||||
if (jkParameter.modifierList.mutability == Mutability.Default) {
|
||||
jkParameter.modifierList.modifiers = emptyList()
|
||||
|
||||
Reference in New Issue
Block a user