New J2K: make initial generating code formatting better
This commit is contained in:
+12
-2
@@ -33,10 +33,12 @@ import com.intellij.util.LocalTimeCounter
|
|||||||
import org.jetbrains.annotations.TestOnly
|
import org.jetbrains.annotations.TestOnly
|
||||||
import org.jetbrains.kotlin.asJava.toLightClass
|
import org.jetbrains.kotlin.asJava.toLightClass
|
||||||
import org.jetbrains.kotlin.idea.KotlinFileType
|
import org.jetbrains.kotlin.idea.KotlinFileType
|
||||||
|
import org.jetbrains.kotlin.idea.core.util.range
|
||||||
import org.jetbrains.kotlin.idea.editor.KotlinEditorOptions
|
import org.jetbrains.kotlin.idea.editor.KotlinEditorOptions
|
||||||
import org.jetbrains.kotlin.idea.util.application.runWriteAction
|
import org.jetbrains.kotlin.idea.util.application.runWriteAction
|
||||||
import org.jetbrains.kotlin.idea.util.projectStructure.module
|
import org.jetbrains.kotlin.idea.util.projectStructure.module
|
||||||
import org.jetbrains.kotlin.j2k.ConversionType
|
import org.jetbrains.kotlin.j2k.ConversionType
|
||||||
|
import org.jetbrains.kotlin.j2k.J2kConverterExtension
|
||||||
import org.jetbrains.kotlin.j2k.logJ2kConversionStatistics
|
import org.jetbrains.kotlin.j2k.logJ2kConversionStatistics
|
||||||
import org.jetbrains.kotlin.lexer.KtTokens
|
import org.jetbrains.kotlin.lexer.KtTokens
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
@@ -140,11 +142,19 @@ class ConvertTextJavaCopyPasteProcessor : CopyPastePostProcessor<TextBlockTransf
|
|||||||
val endOffsetAfterCopy = startOffset + convertedText.length
|
val endOffsetAfterCopy = startOffset + convertedText.length
|
||||||
editor.caretModel.moveToOffset(endOffsetAfterCopy)
|
editor.caretModel.moveToOffset(endOffsetAfterCopy)
|
||||||
|
|
||||||
TextRange(startOffset, startOffset + convertedText.length)
|
editor.document.createRangeMarker(startOffset, startOffset + convertedText.length)
|
||||||
}
|
}
|
||||||
|
|
||||||
psiDocumentManager.commitAllDocuments()
|
psiDocumentManager.commitAllDocuments()
|
||||||
runPostProcessing(project, targetFile, newBounds, convertedResult.converterContext, useNewJ2k)
|
|
||||||
|
if (useNewJ2k) {
|
||||||
|
val postProcessor = J2kConverterExtension.extension(useNewJ2k).createPostProcessor(formatCode = true)
|
||||||
|
convertedResult.importsToAdd.forEach { fqName ->
|
||||||
|
postProcessor.insertImport(targetFile, fqName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
runPostProcessing(project, targetFile, newBounds.range, convertedResult.converterContext, useNewJ2k)
|
||||||
|
|
||||||
conversionPerformed = true
|
conversionPerformed = true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,14 +10,12 @@ import org.jetbrains.kotlin.nj2k.symbols.*
|
|||||||
import org.jetbrains.kotlin.nj2k.tree.*
|
import org.jetbrains.kotlin.nj2k.tree.*
|
||||||
import org.jetbrains.kotlin.nj2k.tree.visitors.JKVisitorWithCommentsPrinting
|
import org.jetbrains.kotlin.nj2k.tree.visitors.JKVisitorWithCommentsPrinting
|
||||||
import org.jetbrains.kotlin.nj2k.types.*
|
import org.jetbrains.kotlin.nj2k.types.*
|
||||||
import org.jetbrains.kotlin.utils.Printer
|
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||||
|
|
||||||
|
|
||||||
class NewCodeBuilder(context: NewJ2kConverterContext) {
|
class NewCodeBuilder(context: NewJ2kConverterContext) {
|
||||||
private val elementInfoStorage = context.elementsInfoStorage
|
private val elementInfoStorage = context.elementsInfoStorage
|
||||||
private val builder = StringBuilder()
|
private val printer = JKPrinter(elementInfoStorage)
|
||||||
private val printer = JKPrinter(builder, elementInfoStorage)
|
|
||||||
|
|
||||||
private fun classKindString(kind: JKClass.ClassKind): String = when (kind) {
|
private fun classKindString(kind: JKClass.ClassKind): String = when (kind) {
|
||||||
JKClass.ClassKind.ANNOTATION -> "annotation class"
|
JKClass.ClassKind.ANNOTATION -> "annotation class"
|
||||||
@@ -57,7 +55,7 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
|
|||||||
|
|
||||||
override fun printLeftNonCodeElements(element: JKFormattingOwner) {
|
override fun printLeftNonCodeElements(element: JKFormattingOwner) {
|
||||||
val text = element.trailingComments.createText()
|
val text = element.trailingComments.createText()
|
||||||
printer.printWithNoIndent(text)
|
printer.print(text)
|
||||||
|
|
||||||
val addNewLine = element.hasTrailingLineBreak
|
val addNewLine = element.hasTrailingLineBreak
|
||||||
|| element is JKDeclaration && element.trailingComments.isNotEmpty() // add new line between comment & declaration
|
|| element is JKDeclaration && element.trailingComments.isNotEmpty() // add new line between comment & declaration
|
||||||
@@ -69,7 +67,7 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
|
|||||||
|
|
||||||
override fun printRightNonCodeElements(element: JKFormattingOwner) {
|
override fun printRightNonCodeElements(element: JKFormattingOwner) {
|
||||||
val text = element.leadingComments.createText()
|
val text = element.leadingComments.createText()
|
||||||
printer.printWithNoIndent(text)
|
printer.print(text)
|
||||||
|
|
||||||
val addNewLine = element.hasLeadingLineBreak || text.hasNoLineBreakAfterSingleLineComment()
|
val addNewLine = element.hasLeadingLineBreak || text.hasNoLineBreakAfterSingleLineComment()
|
||||||
if (addNewLine) printer.println()
|
if (addNewLine) printer.println()
|
||||||
@@ -77,13 +75,13 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
|
|||||||
|
|
||||||
private fun renderTokenElement(tokenElement: JKTokenElement) {
|
private fun renderTokenElement(tokenElement: JKTokenElement) {
|
||||||
printLeftNonCodeElements(tokenElement)
|
printLeftNonCodeElements(tokenElement)
|
||||||
printer.printWithNoIndent(tokenElement.text)
|
printer.print(tokenElement.text)
|
||||||
printRightNonCodeElements(tokenElement)
|
printRightNonCodeElements(tokenElement)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitModifierElementRaw(modifierElement: JKModifierElement) {
|
override fun visitModifierElementRaw(modifierElement: JKModifierElement) {
|
||||||
if (modifierElement.modifier != Modality.FINAL) {
|
if (modifierElement.modifier != Modality.FINAL) {
|
||||||
printer.printWithNoIndent(modifierElement.modifier.text)
|
printer.print(modifierElement.modifier.text)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,7 +89,7 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
|
|||||||
val extraTypeBounds = typeParameterList.typeParameters
|
val extraTypeBounds = typeParameterList.typeParameters
|
||||||
.filter { it.upperBounds.size > 1 }
|
.filter { it.upperBounds.size > 1 }
|
||||||
if (extraTypeBounds.isNotEmpty()) {
|
if (extraTypeBounds.isNotEmpty()) {
|
||||||
printer.printWithNoIndent(" where ")
|
printer.print(" where ")
|
||||||
val typeParametersWithBoudnds =
|
val typeParametersWithBoudnds =
|
||||||
extraTypeBounds.flatMap { typeParameter ->
|
extraTypeBounds.flatMap { typeParameter ->
|
||||||
typeParameter.upperBounds.map { bound ->
|
typeParameter.upperBounds.map { bound ->
|
||||||
@@ -100,7 +98,7 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
|
|||||||
}
|
}
|
||||||
printer.renderList(typeParametersWithBoudnds) { (name, bound) ->
|
printer.renderList(typeParametersWithBoudnds) { (name, bound) ->
|
||||||
name.accept(this)
|
name.accept(this)
|
||||||
printer.printWithNoIndent(" : ")
|
printer.print(" : ")
|
||||||
bound.accept(this)
|
bound.accept(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -115,17 +113,17 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun visitKtTryExpressionRaw(ktTryExpression: JKKtTryExpression) {
|
override fun visitKtTryExpressionRaw(ktTryExpression: JKKtTryExpression) {
|
||||||
printer.printWithNoIndent("try ")
|
printer.print("try ")
|
||||||
ktTryExpression.tryBlock.accept(this)
|
ktTryExpression.tryBlock.accept(this)
|
||||||
ktTryExpression.catchSections.forEach { it.accept(this) }
|
ktTryExpression.catchSections.forEach { it.accept(this) }
|
||||||
if (ktTryExpression.finallyBlock != JKBodyStub) {
|
if (ktTryExpression.finallyBlock != JKBodyStub) {
|
||||||
printer.printWithNoIndent("finally ")
|
printer.print("finally ")
|
||||||
ktTryExpression.finallyBlock.accept(this)
|
ktTryExpression.finallyBlock.accept(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitKtTryCatchSectionRaw(ktTryCatchSection: JKKtTryCatchSection) {
|
override fun visitKtTryCatchSectionRaw(ktTryCatchSection: JKKtTryCatchSection) {
|
||||||
printer.printWithNoIndent("catch ")
|
printer.print("catch ")
|
||||||
printer.par {
|
printer.par {
|
||||||
ktTryCatchSection.parameter.accept(this)
|
ktTryCatchSection.parameter.accept(this)
|
||||||
}
|
}
|
||||||
@@ -133,29 +131,29 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun visitForInStatementRaw(forInStatement: JKForInStatement) {
|
override fun visitForInStatementRaw(forInStatement: JKForInStatement) {
|
||||||
printer.printWithNoIndent("for (")
|
printer.print("for (")
|
||||||
forInStatement.declaration.accept(this)
|
forInStatement.declaration.accept(this)
|
||||||
printer.printWithNoIndent(" in ")
|
printer.print(" in ")
|
||||||
forInStatement.iterationExpression.accept(this)
|
forInStatement.iterationExpression.accept(this)
|
||||||
printer.printWithNoIndent(") ")
|
printer.print(") ")
|
||||||
if (forInStatement.body.isEmpty()) {
|
if (forInStatement.body.isEmpty()) {
|
||||||
printer.printWithNoIndent(";")
|
printer.print(";")
|
||||||
} else {
|
} else {
|
||||||
forInStatement.body.accept(this)
|
forInStatement.body.accept(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitKtThrowExpressionRaw(ktThrowExpression: JKKtThrowExpression) {
|
override fun visitKtThrowExpressionRaw(ktThrowExpression: JKKtThrowExpression) {
|
||||||
printer.printWithNoIndent("throw ")
|
printer.print("throw ")
|
||||||
ktThrowExpression.exception.accept(this)
|
ktThrowExpression.exception.accept(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitDoWhileStatementRaw(doWhileStatement: JKDoWhileStatement) {
|
override fun visitDoWhileStatementRaw(doWhileStatement: JKDoWhileStatement) {
|
||||||
printer.printWithNoIndent("do ")
|
printer.print("do ")
|
||||||
doWhileStatement.body.accept(this)
|
doWhileStatement.body.accept(this)
|
||||||
printer.printWithNoIndent(" while (")
|
printer.print(" while (")
|
||||||
doWhileStatement.condition.accept(this)
|
doWhileStatement.condition.accept(this)
|
||||||
printer.printWithNoIndent(")")
|
printer.print(")")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitClassAccessExpressionRaw(classAccessExpression: JKClassAccessExpression) {
|
override fun visitClassAccessExpressionRaw(classAccessExpression: JKClassAccessExpression) {
|
||||||
@@ -172,9 +170,10 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
|
|||||||
|
|
||||||
|
|
||||||
override fun visitPackageDeclarationRaw(packageDeclaration: JKPackageDeclaration) {
|
override fun visitPackageDeclarationRaw(packageDeclaration: JKPackageDeclaration) {
|
||||||
printer.printWithNoIndent("package ")
|
printer.print("package ")
|
||||||
val packageNameEscaped = packageDeclaration.name.value.escapedAsQualifiedName()
|
val packageNameEscaped = packageDeclaration.name.value.escapedAsQualifiedName()
|
||||||
printer.printlnWithNoIndent(packageNameEscaped)
|
printer.print(packageNameEscaped)
|
||||||
|
printer.println()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitImportListRaw(importList: JKImportList) {
|
override fun visitImportListRaw(importList: JKImportList) {
|
||||||
@@ -182,14 +181,15 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun visitImportStatementRaw(importStatement: JKImportStatement) {
|
override fun visitImportStatementRaw(importStatement: JKImportStatement) {
|
||||||
printer.printWithNoIndent("import ")
|
printer.print("import ")
|
||||||
val importNameEscaped =
|
val importNameEscaped =
|
||||||
importStatement.name.value.escapedAsQualifiedName()
|
importStatement.name.value.escapedAsQualifiedName()
|
||||||
printer.printlnWithNoIndent(importNameEscaped)
|
printer.print(importNameEscaped)
|
||||||
|
printer.println()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitBreakStatementRaw(breakStatement: JKBreakStatement) {
|
override fun visitBreakStatementRaw(breakStatement: JKBreakStatement) {
|
||||||
printer.printWithNoIndent("break")
|
printer.print("break")
|
||||||
breakStatement.label.accept(this)
|
breakStatement.label.accept(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,7 +209,7 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
|
|||||||
} else {
|
} else {
|
||||||
modifierElement.accept(this)
|
modifierElement.accept(this)
|
||||||
}
|
}
|
||||||
printer.printWithNoIndent(" ")
|
printer.print(" ")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,18 +219,18 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
|
|||||||
printer.println()
|
printer.println()
|
||||||
}
|
}
|
||||||
renderModifiersList(klass)
|
renderModifiersList(klass)
|
||||||
builder.append(" ")
|
printer.print(" ")
|
||||||
printer.print(classKindString(klass.classKind))
|
printer.print(classKindString(klass.classKind))
|
||||||
builder.append(" ")
|
printer.print(" ")
|
||||||
klass.name.accept(this)
|
klass.name.accept(this)
|
||||||
klass.typeParameterList.accept(this)
|
klass.typeParameterList.accept(this)
|
||||||
printer.printWithNoIndent(" ")
|
printer.print(" ")
|
||||||
|
|
||||||
val primaryConstructor = klass.primaryConstructor()
|
val primaryConstructor = klass.primaryConstructor()
|
||||||
primaryConstructor?.accept(this)
|
primaryConstructor?.accept(this)
|
||||||
|
|
||||||
if (klass.inheritance.present()) {
|
if (klass.inheritance.present()) {
|
||||||
printer.printWithNoIndent(" : ")
|
printer.print(" : ")
|
||||||
klass.inheritance.accept(this)
|
klass.inheritance.accept(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -257,13 +257,13 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
|
|||||||
if (delegationCall != null) {
|
if (delegationCall != null) {
|
||||||
printer.par { delegationCall.arguments.accept(this) }
|
printer.par { delegationCall.arguments.accept(this) }
|
||||||
} else if (!superType.isInterface() && primaryConstructor != null) {
|
} else if (!superType.isInterface() && primaryConstructor != null) {
|
||||||
printer.printWithNoIndent("()")
|
printer.print("()")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (implementTypes.isNotEmpty() && extendTypes.size == 1) {
|
if (implementTypes.isNotEmpty() && extendTypes.size == 1) {
|
||||||
printer.printWithNoIndent(", ")
|
printer.print(", ")
|
||||||
}
|
}
|
||||||
printer.renderList(implementTypes) { printer.renderType(it, null) }
|
printer.renderList(implementTypes) { printer.renderType(it, null) }
|
||||||
}
|
}
|
||||||
@@ -289,14 +289,14 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
|
|||||||
}
|
}
|
||||||
renderModifiersList(field)
|
renderModifiersList(field)
|
||||||
|
|
||||||
printer.printWithNoIndent(" ")
|
printer.print(" ")
|
||||||
field.name.accept(this)
|
field.name.accept(this)
|
||||||
if (field.type.present()) {
|
if (field.type.present()) {
|
||||||
printer.printWithNoIndent(":")
|
printer.print(":")
|
||||||
field.type.accept(this)
|
field.type.accept(this)
|
||||||
}
|
}
|
||||||
if (field.initializer !is JKStubExpression) {
|
if (field.initializer !is JKStubExpression) {
|
||||||
printer.printWithNoIndent(" = ")
|
printer.print(" = ")
|
||||||
field.initializer.accept(this)
|
field.initializer.accept(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -315,7 +315,6 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
|
|||||||
|
|
||||||
override fun visitKtInitDeclarationRaw(ktInitDeclaration: JKKtInitDeclaration) {
|
override fun visitKtInitDeclarationRaw(ktInitDeclaration: JKKtInitDeclaration) {
|
||||||
if (ktInitDeclaration.block.statements.isNotEmpty()) {
|
if (ktInitDeclaration.block.statements.isNotEmpty()) {
|
||||||
printer.println()
|
|
||||||
printer.print("init ")
|
printer.print("init ")
|
||||||
ktInitDeclaration.block.accept(this)
|
ktInitDeclaration.block.accept(this)
|
||||||
}
|
}
|
||||||
@@ -324,17 +323,17 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
|
|||||||
|
|
||||||
override fun visitIsExpressionRaw(isExpression: JKIsExpression) {
|
override fun visitIsExpressionRaw(isExpression: JKIsExpression) {
|
||||||
isExpression.expression.accept(this)
|
isExpression.expression.accept(this)
|
||||||
printer.printWithNoIndent(" is ")
|
printer.print(" is ")
|
||||||
isExpression.type.accept(this)
|
isExpression.type.accept(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitParameterRaw(parameter: JKParameter) {
|
override fun visitParameterRaw(parameter: JKParameter) {
|
||||||
renderModifiersList(parameter)
|
renderModifiersList(parameter)
|
||||||
printer.printWithNoIndent(" ")
|
printer.print(" ")
|
||||||
parameter.annotationList.accept(this)
|
parameter.annotationList.accept(this)
|
||||||
printer.printWithNoIndent(" ")
|
printer.print(" ")
|
||||||
if (parameter.isVarArgs) {
|
if (parameter.isVarArgs) {
|
||||||
printer.printWithNoIndent("vararg ")
|
printer.print("vararg ")
|
||||||
}
|
}
|
||||||
if (parameter.parent is JKKtPrimaryConstructor
|
if (parameter.parent is JKKtPrimaryConstructor
|
||||||
&& (parameter.parent?.parent?.parent as? JKClass)?.classKind == JKClass.ClassKind.ANNOTATION
|
&& (parameter.parent?.parent?.parent as? JKClass)?.classKind == JKClass.ClassKind.ANNOTATION
|
||||||
@@ -343,11 +342,11 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
|
|||||||
}
|
}
|
||||||
parameter.name.accept(this)
|
parameter.name.accept(this)
|
||||||
if (parameter.type.present() && parameter.type.type !is JKContextType) {
|
if (parameter.type.present() && parameter.type.type !is JKContextType) {
|
||||||
printer.printWithNoIndent(":")
|
printer.print(":")
|
||||||
parameter.type.accept(this)
|
parameter.type.accept(this)
|
||||||
}
|
}
|
||||||
if (parameter.initializer !is JKStubExpression) {
|
if (parameter.initializer !is JKStubExpression) {
|
||||||
printer.printWithNoIndent(" = ")
|
printer.print(" = ")
|
||||||
parameter.initializer.accept(this)
|
parameter.initializer.accept(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -363,23 +362,22 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
|
|||||||
override fun visitForLoopVariableRaw(forLoopVariable: JKForLoopVariable) {
|
override fun visitForLoopVariableRaw(forLoopVariable: JKForLoopVariable) {
|
||||||
forLoopVariable.name.accept(this)
|
forLoopVariable.name.accept(this)
|
||||||
if (forLoopVariable.type.present() && forLoopVariable.type.type !is JKContextType) {
|
if (forLoopVariable.type.present() && forLoopVariable.type.type !is JKContextType) {
|
||||||
printer.printWithNoIndent(": ")
|
printer.print(": ")
|
||||||
forLoopVariable.type.accept(this)
|
forLoopVariable.type.accept(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitMethodRaw(method: JKMethod) {
|
override fun visitMethodRaw(method: JKMethod) {
|
||||||
printer.printIndent()
|
|
||||||
if (method.annotationList.annotations.isNotEmpty()) {
|
if (method.annotationList.annotations.isNotEmpty()) {
|
||||||
method.annotationList.accept(this)
|
method.annotationList.accept(this)
|
||||||
printer.printlnWithNoIndent(" ")
|
printer.print(" ")
|
||||||
}
|
}
|
||||||
renderModifiersList(method)
|
renderModifiersList(method)
|
||||||
printer.printWithNoIndent(" fun ")
|
printer.print(" fun ")
|
||||||
method.typeParameterList.accept(this)
|
method.typeParameterList.accept(this)
|
||||||
|
|
||||||
elementInfoStorage.getOrCreateInfoForElement(method).let {
|
elementInfoStorage.getOrCreateInfoForElement(method).let {
|
||||||
printer.printWithNoIndent(it.render())
|
printer.print(it.render())
|
||||||
}
|
}
|
||||||
method.name.accept(this)
|
method.name.accept(this)
|
||||||
renderTokenElement(method.leftParen)
|
renderTokenElement(method.leftParen)
|
||||||
@@ -387,35 +385,35 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
|
|||||||
it.accept(this)
|
it.accept(this)
|
||||||
}
|
}
|
||||||
renderTokenElement(method.rightParen)
|
renderTokenElement(method.rightParen)
|
||||||
printer.printWithNoIndent(": ")
|
printer.print(": ")
|
||||||
method.returnType.accept(this)
|
method.returnType.accept(this)
|
||||||
renderExtraTypeParametersUpperBounds(method.typeParameterList)
|
renderExtraTypeParametersUpperBounds(method.typeParameterList)
|
||||||
method.block.accept(this)
|
method.block.accept(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitIfElseExpressionRaw(ifElseExpression: JKIfElseExpression) {
|
override fun visitIfElseExpressionRaw(ifElseExpression: JKIfElseExpression) {
|
||||||
printer.printWithNoIndent("if (")
|
printer.print("if (")
|
||||||
ifElseExpression.condition.accept(this)
|
ifElseExpression.condition.accept(this)
|
||||||
printer.printWithNoIndent(")")
|
printer.print(")")
|
||||||
ifElseExpression.thenBranch.accept(this)
|
ifElseExpression.thenBranch.accept(this)
|
||||||
if (ifElseExpression.elseBranch !is JKStubExpression) {
|
if (ifElseExpression.elseBranch !is JKStubExpression) {
|
||||||
printer.printWithNoIndent(" else ")
|
printer.print(" else ")
|
||||||
ifElseExpression.elseBranch.accept(this)
|
ifElseExpression.elseBranch.accept(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
override fun visitIfElseStatementRaw(ifElseStatement: JKIfElseStatement) {
|
override fun visitIfElseStatementRaw(ifElseStatement: JKIfElseStatement) {
|
||||||
printer.printWithNoIndent("if (")
|
printer.print("if (")
|
||||||
ifElseStatement.condition.accept(this)
|
ifElseStatement.condition.accept(this)
|
||||||
printer.printWithNoIndent(")")
|
printer.print(")")
|
||||||
if (ifElseStatement.thenBranch.isEmpty()) {
|
if (ifElseStatement.thenBranch.isEmpty()) {
|
||||||
printer.printWithNoIndent(";")
|
printer.print(";")
|
||||||
} else {
|
} else {
|
||||||
ifElseStatement.thenBranch.accept(this)
|
ifElseStatement.thenBranch.accept(this)
|
||||||
}
|
}
|
||||||
if (!ifElseStatement.elseBranch.isEmpty()) {
|
if (!ifElseStatement.elseBranch.isEmpty()) {
|
||||||
printer.printWithNoIndent(" else ")
|
printer.print(" else ")
|
||||||
ifElseStatement.elseBranch.accept(this)
|
ifElseStatement.elseBranch.accept(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -423,9 +421,9 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
|
|||||||
|
|
||||||
override fun visitBinaryExpressionRaw(binaryExpression: JKBinaryExpression) {
|
override fun visitBinaryExpressionRaw(binaryExpression: JKBinaryExpression) {
|
||||||
binaryExpression.left.accept(this)
|
binaryExpression.left.accept(this)
|
||||||
printer.printWithNoIndent(" ")
|
printer.print(" ")
|
||||||
printer.printWithNoIndent(binaryExpression.operator.token.text)
|
printer.print(binaryExpression.operator.token.text)
|
||||||
printer.printWithNoIndent(" ")
|
printer.print(" ")
|
||||||
binaryExpression.right.accept(this)
|
binaryExpression.right.accept(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -442,34 +440,34 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
|
|||||||
override fun visitTypeParameterRaw(typeParameter: JKTypeParameter) {
|
override fun visitTypeParameterRaw(typeParameter: JKTypeParameter) {
|
||||||
typeParameter.name.accept(this)
|
typeParameter.name.accept(this)
|
||||||
if (typeParameter.upperBounds.size == 1) {
|
if (typeParameter.upperBounds.size == 1) {
|
||||||
printer.printWithNoIndent(" : ")
|
printer.print(" : ")
|
||||||
typeParameter.upperBounds.single().accept(this)
|
typeParameter.upperBounds.single().accept(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitLiteralExpressionRaw(literalExpression: JKLiteralExpression) {
|
override fun visitLiteralExpressionRaw(literalExpression: JKLiteralExpression) {
|
||||||
printer.printWithNoIndent(literalExpression.literal)
|
printer.print(literalExpression.literal)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitPrefixExpressionRaw(prefixExpression: JKPrefixExpression) {
|
override fun visitPrefixExpressionRaw(prefixExpression: JKPrefixExpression) {
|
||||||
printer.printWithNoIndent(prefixExpression.operator.token.text)
|
printer.print(prefixExpression.operator.token.text)
|
||||||
prefixExpression.expression.accept(this)
|
prefixExpression.expression.accept(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitThisExpressionRaw(thisExpression: JKThisExpression) {
|
override fun visitThisExpressionRaw(thisExpression: JKThisExpression) {
|
||||||
printer.printWithNoIndent("this")
|
printer.print("this")
|
||||||
thisExpression.qualifierLabel.accept(this)
|
thisExpression.qualifierLabel.accept(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitSuperExpressionRaw(superExpression: JKSuperExpression) {
|
override fun visitSuperExpressionRaw(superExpression: JKSuperExpression) {
|
||||||
printer.printWithNoIndent("super")
|
printer.print("super")
|
||||||
superExpression.qualifierLabel.accept(this)
|
superExpression.qualifierLabel.accept(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitContinueStatementRaw(continueStatement: JKContinueStatement) {
|
override fun visitContinueStatementRaw(continueStatement: JKContinueStatement) {
|
||||||
printer.printWithNoIndent("continue")
|
printer.print("continue")
|
||||||
continueStatement.label.accept(this)
|
continueStatement.label.accept(this)
|
||||||
printer.printWithNoIndent(" ")
|
printer.print(" ")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitLabelEmptyRaw(labelEmpty: JKLabelEmpty) {
|
override fun visitLabelEmptyRaw(labelEmpty: JKLabelEmpty) {
|
||||||
@@ -477,31 +475,31 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun visitLabelTextRaw(labelText: JKLabelText) {
|
override fun visitLabelTextRaw(labelText: JKLabelText) {
|
||||||
printer.printWithNoIndent("@")
|
printer.print("@")
|
||||||
labelText.label.accept(this)
|
labelText.label.accept(this)
|
||||||
printer.printWithNoIndent(" ")
|
printer.print(" ")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitLabeledExpressionRaw(labeledExpression: JKLabeledExpression) {
|
override fun visitLabeledExpressionRaw(labeledExpression: JKLabeledExpression) {
|
||||||
for (label in labeledExpression.labels) {
|
for (label in labeledExpression.labels) {
|
||||||
label.accept(this)
|
label.accept(this)
|
||||||
printer.printWithNoIndent("@")
|
printer.print("@")
|
||||||
}
|
}
|
||||||
labeledExpression.statement.accept(this)
|
labeledExpression.statement.accept(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitNameIdentifierRaw(nameIdentifier: JKNameIdentifier) {
|
override fun visitNameIdentifierRaw(nameIdentifier: JKNameIdentifier) {
|
||||||
printer.printWithNoIndent(nameIdentifier.value.escaped())
|
printer.print(nameIdentifier.value.escaped())
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitPostfixExpressionRaw(postfixExpression: JKPostfixExpression) {
|
override fun visitPostfixExpressionRaw(postfixExpression: JKPostfixExpression) {
|
||||||
postfixExpression.expression.accept(this)
|
postfixExpression.expression.accept(this)
|
||||||
printer.printWithNoIndent(postfixExpression.operator.token.text)
|
printer.print(postfixExpression.operator.token.text)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitQualifiedExpressionRaw(qualifiedExpression: JKQualifiedExpression) {
|
override fun visitQualifiedExpressionRaw(qualifiedExpression: JKQualifiedExpression) {
|
||||||
qualifiedExpression.receiver.accept(this)
|
qualifiedExpression.receiver.accept(this)
|
||||||
printer.printWithNoIndent(".")
|
printer.print(".")
|
||||||
qualifiedExpression.selector.accept(this)
|
qualifiedExpression.selector.accept(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -516,7 +514,7 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
|
|||||||
|
|
||||||
override fun visitNamedArgumentRaw(namedArgument: JKNamedArgument) {
|
override fun visitNamedArgumentRaw(namedArgument: JKNamedArgument) {
|
||||||
namedArgument.name.accept(this)
|
namedArgument.name.accept(this)
|
||||||
printer.printWithNoIndent(" = ")
|
printer.print(" = ")
|
||||||
namedArgument.value.accept(this)
|
namedArgument.value.accept(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -552,34 +550,34 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
|
|||||||
|
|
||||||
override fun visitTypeCastExpressionRaw(typeCastExpression: JKTypeCastExpression) {
|
override fun visitTypeCastExpressionRaw(typeCastExpression: JKTypeCastExpression) {
|
||||||
typeCastExpression.expression.accept(this)
|
typeCastExpression.expression.accept(this)
|
||||||
printer.printWithNoIndent(" as ")
|
printer.print(" as ")
|
||||||
typeCastExpression.type.accept(this)
|
typeCastExpression.type.accept(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitWhileStatementRaw(whileStatement: JKWhileStatement) {
|
override fun visitWhileStatementRaw(whileStatement: JKWhileStatement) {
|
||||||
printer.print("while(")
|
printer.print("while (")
|
||||||
whileStatement.condition.accept(this)
|
whileStatement.condition.accept(this)
|
||||||
printer.printWithNoIndent(")")
|
printer.print(")")
|
||||||
if (whileStatement.body.isEmpty()) {
|
if (whileStatement.body.isEmpty()) {
|
||||||
printer.printWithNoIndent(";")
|
printer.print(";")
|
||||||
} else {
|
} else {
|
||||||
whileStatement.body.accept(this)
|
whileStatement.body.accept(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitLocalVariableRaw(localVariable: JKLocalVariable) {
|
override fun visitLocalVariableRaw(localVariable: JKLocalVariable) {
|
||||||
printer.printWithNoIndent(" ")
|
printer.print(" ")
|
||||||
localVariable.annotationList.accept(this)
|
localVariable.annotationList.accept(this)
|
||||||
printer.printWithNoIndent(" ")
|
printer.print(" ")
|
||||||
renderModifiersList(localVariable)
|
renderModifiersList(localVariable)
|
||||||
printer.printWithNoIndent(" ")
|
printer.print(" ")
|
||||||
localVariable.name.accept(this)
|
localVariable.name.accept(this)
|
||||||
if (localVariable.type.present() && localVariable.type.type != JKContextType) {
|
if (localVariable.type.present() && localVariable.type.type != JKContextType) {
|
||||||
printer.printWithNoIndent(": ")
|
printer.print(": ")
|
||||||
localVariable.type.accept(this)
|
localVariable.type.accept(this)
|
||||||
}
|
}
|
||||||
if (localVariable.initializer !is JKStubExpression) {
|
if (localVariable.initializer !is JKStubExpression) {
|
||||||
printer.printWithNoIndent(" = ")
|
printer.print(" = ")
|
||||||
localVariable.initializer.accept(this)
|
localVariable.initializer.accept(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -594,13 +592,13 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
|
|||||||
ktConvertedFromForLoopSyntheticWhileStatement: JKKtConvertedFromForLoopSyntheticWhileStatement
|
ktConvertedFromForLoopSyntheticWhileStatement: JKKtConvertedFromForLoopSyntheticWhileStatement
|
||||||
) {
|
) {
|
||||||
ktConvertedFromForLoopSyntheticWhileStatement.variableDeclaration.accept(this)
|
ktConvertedFromForLoopSyntheticWhileStatement.variableDeclaration.accept(this)
|
||||||
printer.printlnWithNoIndent()
|
printer.println()
|
||||||
ktConvertedFromForLoopSyntheticWhileStatement.whileStatement.accept(this)
|
ktConvertedFromForLoopSyntheticWhileStatement.whileStatement.accept(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitNewExpressionRaw(newExpression: JKNewExpression) {
|
override fun visitNewExpressionRaw(newExpression: JKNewExpression) {
|
||||||
if (newExpression.isAnonymousClass) {
|
if (newExpression.isAnonymousClass) {
|
||||||
printer.printWithNoIndent("object : ")
|
printer.print("object : ")
|
||||||
}
|
}
|
||||||
printer.renderSymbol(newExpression.classSymbol, newExpression)
|
printer.renderSymbol(newExpression.classSymbol, newExpression)
|
||||||
newExpression.typeArgumentList.accept(this)
|
newExpression.typeArgumentList.accept(this)
|
||||||
@@ -615,24 +613,31 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun visitKtItExpressionRaw(ktItExpression: JKKtItExpression) {
|
override fun visitKtItExpressionRaw(ktItExpression: JKKtItExpression) {
|
||||||
printer.printWithNoIndent("it")
|
printer.print("it")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitClassBodyRaw(classBody: JKClassBody) {
|
override fun visitClassBodyRaw(classBody: JKClassBody) {
|
||||||
val declarationsToPrint = classBody.declarations.filterNot { it is JKKtPrimaryConstructor }
|
val declarationsToPrint = classBody.declarations.filterNot { it is JKKtPrimaryConstructor }
|
||||||
renderTokenElement(classBody.leftBrace)
|
renderTokenElement(classBody.leftBrace)
|
||||||
val enumConstants = declarationsToPrint.filterIsInstance<JKEnumConstant>()
|
if (declarationsToPrint.isNotEmpty()) {
|
||||||
val otherDeclarations = declarationsToPrint.filterNot { it is JKEnumConstant }
|
printer.indented {
|
||||||
renderEnumConstants(enumConstants)
|
printer.println()
|
||||||
if ((classBody.parent as? JKClass)?.classKind == JKClass.ClassKind.ENUM
|
val enumConstants = declarationsToPrint.filterIsInstance<JKEnumConstant>()
|
||||||
&& otherDeclarations.isNotEmpty()
|
val otherDeclarations = declarationsToPrint.filterNot { it is JKEnumConstant }
|
||||||
) {
|
renderEnumConstants(enumConstants)
|
||||||
printer.printlnWithNoIndent(";")
|
if ((classBody.parent as? JKClass)?.classKind == JKClass.ClassKind.ENUM
|
||||||
}
|
&& otherDeclarations.isNotEmpty()
|
||||||
if (enumConstants.isNotEmpty() && otherDeclarations.isNotEmpty()) {
|
) {
|
||||||
|
printer.print(";")
|
||||||
|
printer.println()
|
||||||
|
}
|
||||||
|
if (enumConstants.isNotEmpty() && otherDeclarations.isNotEmpty()) {
|
||||||
|
printer.println()
|
||||||
|
}
|
||||||
|
renderNonEnumClassDeclarations(otherDeclarations)
|
||||||
|
}
|
||||||
printer.println()
|
printer.println()
|
||||||
}
|
}
|
||||||
renderNonEnumClassDeclarations(otherDeclarations)
|
|
||||||
renderTokenElement(classBody.rightBrace)
|
renderTokenElement(classBody.rightBrace)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -642,8 +647,14 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
|
|||||||
|
|
||||||
override fun visitBlockRaw(block: JKBlock) {
|
override fun visitBlockRaw(block: JKBlock) {
|
||||||
renderTokenElement(block.leftBrace)
|
renderTokenElement(block.leftBrace)
|
||||||
printer.renderList(block.statements, { printer.println() }) {
|
if (block.statements.isNotEmpty()) {
|
||||||
it.accept(this)
|
printer.indented {
|
||||||
|
printer.println()
|
||||||
|
printer.renderList(block.statements, { printer.println() }) {
|
||||||
|
it.accept(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printer.println()
|
||||||
}
|
}
|
||||||
renderTokenElement(block.rightBrace)
|
renderTokenElement(block.rightBrace)
|
||||||
}
|
}
|
||||||
@@ -675,13 +686,13 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
|
|||||||
|
|
||||||
override fun visitMethodReferenceExpressionRaw(methodReferenceExpression: JKMethodReferenceExpression) {
|
override fun visitMethodReferenceExpressionRaw(methodReferenceExpression: JKMethodReferenceExpression) {
|
||||||
methodReferenceExpression.qualifier.accept(this)
|
methodReferenceExpression.qualifier.accept(this)
|
||||||
printer.printWithNoIndent("::")
|
printer.print("::")
|
||||||
val needFqName = methodReferenceExpression.qualifier is JKStubExpression
|
val needFqName = methodReferenceExpression.qualifier is JKStubExpression
|
||||||
val displayName =
|
val displayName =
|
||||||
if (needFqName) methodReferenceExpression.identifier.getDisplayName()
|
if (needFqName) methodReferenceExpression.identifier.getDisplayName()
|
||||||
else methodReferenceExpression.identifier.name
|
else methodReferenceExpression.identifier.name
|
||||||
|
|
||||||
printer.printWithNoIndent(displayName.escapedAsQualifiedName())
|
printer.print(displayName.escapedAsQualifiedName())
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -709,7 +720,7 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
|
|||||||
printer.print(" constructor")
|
printer.print(" constructor")
|
||||||
renderParameterList(constructor.parameters)
|
renderParameterList(constructor.parameters)
|
||||||
if (constructor.delegationCall !is JKStubExpression) {
|
if (constructor.delegationCall !is JKStubExpression) {
|
||||||
builder.append(" : ")
|
printer.print(" : ")
|
||||||
constructor.delegationCall.accept(this)
|
constructor.delegationCall.accept(this)
|
||||||
}
|
}
|
||||||
constructor.block.accept(this)
|
constructor.block.accept(this)
|
||||||
@@ -717,9 +728,9 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
|
|||||||
|
|
||||||
override fun visitKtPrimaryConstructorRaw(ktPrimaryConstructor: JKKtPrimaryConstructor) {
|
override fun visitKtPrimaryConstructorRaw(ktPrimaryConstructor: JKKtPrimaryConstructor) {
|
||||||
ktPrimaryConstructor.annotationList.accept(this)
|
ktPrimaryConstructor.annotationList.accept(this)
|
||||||
printer.printWithNoIndent(" ")
|
printer.print(" ")
|
||||||
renderModifiersList(ktPrimaryConstructor)
|
renderModifiersList(ktPrimaryConstructor)
|
||||||
printer.printWithNoIndent(" constructor ")
|
printer.print(" constructor ")
|
||||||
if (ktPrimaryConstructor.parameters.isNotEmpty()) {
|
if (ktPrimaryConstructor.parameters.isNotEmpty()) {
|
||||||
renderParameterList(ktPrimaryConstructor.parameters)
|
renderParameterList(ktPrimaryConstructor.parameters)
|
||||||
} else {
|
} else {
|
||||||
@@ -734,9 +745,9 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
|
|||||||
if (lambdaExpression.statement.statements.size > 1)
|
if (lambdaExpression.statement.statements.size > 1)
|
||||||
printer.println()
|
printer.println()
|
||||||
lambdaExpression.parameters.firstOrNull()?.accept(this)
|
lambdaExpression.parameters.firstOrNull()?.accept(this)
|
||||||
lambdaExpression.parameters.asSequence().drop(1).forEach { printer.printWithNoIndent(", "); it.accept(this) }
|
lambdaExpression.parameters.asSequence().drop(1).forEach { printer.print(", "); it.accept(this) }
|
||||||
if (lambdaExpression.parameters.isNotEmpty()) {
|
if (lambdaExpression.parameters.isNotEmpty()) {
|
||||||
printer.printWithNoIndent(" -> ")
|
printer.print(" -> ")
|
||||||
}
|
}
|
||||||
|
|
||||||
val statement = lambdaExpression.statement
|
val statement = lambdaExpression.statement
|
||||||
@@ -751,7 +762,7 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
|
|||||||
}
|
}
|
||||||
if (lambdaExpression.functionalType.present()) {
|
if (lambdaExpression.functionalType.present()) {
|
||||||
printer.renderType(lambdaExpression.functionalType.type, lambdaExpression)
|
printer.renderType(lambdaExpression.functionalType.type, lambdaExpression)
|
||||||
printer.printWithNoIndent(" ")
|
printer.print(" ")
|
||||||
printer.par(ParenthesisKind.ROUND, printLambda)
|
printer.par(ParenthesisKind.ROUND, printLambda)
|
||||||
} else {
|
} else {
|
||||||
printLambda()
|
printLambda()
|
||||||
@@ -764,34 +775,34 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
|
|||||||
|
|
||||||
override fun visitKtAssignmentStatementRaw(ktAssignmentStatement: JKKtAssignmentStatement) {
|
override fun visitKtAssignmentStatementRaw(ktAssignmentStatement: JKKtAssignmentStatement) {
|
||||||
ktAssignmentStatement.field.accept(this)
|
ktAssignmentStatement.field.accept(this)
|
||||||
printer.printWithNoIndent(" ")
|
printer.print(" ")
|
||||||
printer.printWithNoIndent(ktAssignmentStatement.token.text)
|
printer.print(ktAssignmentStatement.token.text)
|
||||||
printer.printWithNoIndent(" ")
|
printer.print(" ")
|
||||||
ktAssignmentStatement.expression.accept(this)
|
ktAssignmentStatement.expression.accept(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitAssignmentChainAlsoLinkRaw(assignmentChainAlsoLink: JKAssignmentChainAlsoLink) {
|
override fun visitAssignmentChainAlsoLinkRaw(assignmentChainAlsoLink: JKAssignmentChainAlsoLink) {
|
||||||
assignmentChainAlsoLink.receiver.accept(this)
|
assignmentChainAlsoLink.receiver.accept(this)
|
||||||
printer.printWithNoIndent(".also({ ")
|
printer.print(".also({ ")
|
||||||
assignmentChainAlsoLink.assignmentStatement.accept(this)
|
assignmentChainAlsoLink.assignmentStatement.accept(this)
|
||||||
printer.printWithNoIndent(" })")
|
printer.print(" })")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitAssignmentChainLetLinkRaw(assignmentChainLetLink: JKAssignmentChainLetLink) {
|
override fun visitAssignmentChainLetLinkRaw(assignmentChainLetLink: JKAssignmentChainLetLink) {
|
||||||
assignmentChainLetLink.receiver.accept(this)
|
assignmentChainLetLink.receiver.accept(this)
|
||||||
printer.printWithNoIndent(".let({ ")
|
printer.print(".let({ ")
|
||||||
assignmentChainLetLink.assignmentStatement.accept(this)
|
assignmentChainLetLink.assignmentStatement.accept(this)
|
||||||
printer.printWithNoIndent("; ")
|
printer.print("; ")
|
||||||
assignmentChainLetLink.field.accept(this)
|
assignmentChainLetLink.field.accept(this)
|
||||||
printer.printWithNoIndent(" })")
|
printer.print(" })")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitKtWhenStatementRaw(ktWhenStatement: JKKtWhenStatement) {
|
override fun visitKtWhenStatementRaw(ktWhenStatement: JKKtWhenStatement) {
|
||||||
printer.printWithNoIndent("when(")
|
printer.print("when(")
|
||||||
ktWhenStatement.expression.accept(this)
|
ktWhenStatement.expression.accept(this)
|
||||||
printer.printWithNoIndent(")")
|
printer.print(")")
|
||||||
printer.block() {
|
printer.block() {
|
||||||
printer.renderList(ktWhenStatement.cases, { printer.printlnWithNoIndent() }) {
|
printer.renderList(ktWhenStatement.cases, { printer.println() }) {
|
||||||
it.accept(this)
|
it.accept(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -804,8 +815,8 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun visitAnnotationRaw(annotation: JKAnnotation) {
|
override fun visitAnnotationRaw(annotation: JKAnnotation) {
|
||||||
printer.printWithNoIndent("@")
|
printer.print("@")
|
||||||
printer.printWithNoIndent(annotation.classSymbol.fqName.escapedAsQualifiedName())
|
printer.print(annotation.classSymbol.fqName.escapedAsQualifiedName())
|
||||||
if (annotation.arguments.isNotEmpty()) {
|
if (annotation.arguments.isNotEmpty()) {
|
||||||
printer.par {
|
printer.par {
|
||||||
printer.renderList(annotation.arguments) { it.accept(this) }
|
printer.renderList(annotation.arguments) { it.accept(this) }
|
||||||
@@ -825,14 +836,14 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
|
|||||||
|
|
||||||
override fun visitClassLiteralExpressionRaw(classLiteralExpression: JKClassLiteralExpression) {
|
override fun visitClassLiteralExpressionRaw(classLiteralExpression: JKClassLiteralExpression) {
|
||||||
if (classLiteralExpression.literalType == JKClassLiteralExpression.ClassLiteralType.JAVA_VOID_TYPE) {
|
if (classLiteralExpression.literalType == JKClassLiteralExpression.ClassLiteralType.JAVA_VOID_TYPE) {
|
||||||
printer.printWithNoIndent("Void.TYPE")
|
printer.print("Void.TYPE")
|
||||||
} else {
|
} else {
|
||||||
printer.renderType(classLiteralExpression.classType.type, classLiteralExpression)
|
printer.renderType(classLiteralExpression.classType.type, classLiteralExpression)
|
||||||
printer.printWithNoIndent("::")
|
printer.print("::")
|
||||||
when (classLiteralExpression.literalType) {
|
when (classLiteralExpression.literalType) {
|
||||||
JKClassLiteralExpression.ClassLiteralType.KOTLIN_CLASS -> printer.printWithNoIndent("class")
|
JKClassLiteralExpression.ClassLiteralType.KOTLIN_CLASS -> printer.print("class")
|
||||||
JKClassLiteralExpression.ClassLiteralType.JAVA_CLASS -> printer.printWithNoIndent("class.java")
|
JKClassLiteralExpression.ClassLiteralType.JAVA_CLASS -> printer.print("class.java")
|
||||||
JKClassLiteralExpression.ClassLiteralType.JAVA_PRIMITIVE_CLASS -> printer.printWithNoIndent("class.javaPrimitiveType")
|
JKClassLiteralExpression.ClassLiteralType.JAVA_PRIMITIVE_CLASS -> printer.print("class.javaPrimitiveType")
|
||||||
JKClassLiteralExpression.ClassLiteralType.JAVA_VOID_TYPE -> {
|
JKClassLiteralExpression.ClassLiteralType.JAVA_VOID_TYPE -> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -843,12 +854,12 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
|
|||||||
printer.renderList(ktWhenCase.labels, ", ") {
|
printer.renderList(ktWhenCase.labels, ", ") {
|
||||||
it.accept(this)
|
it.accept(this)
|
||||||
}
|
}
|
||||||
printer.printWithNoIndent(" -> ")
|
printer.print(" -> ")
|
||||||
ktWhenCase.statement.accept(this)
|
ktWhenCase.statement.accept(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitKtElseWhenLabelRaw(ktElseWhenLabel: JKKtElseWhenLabel) {
|
override fun visitKtElseWhenLabelRaw(ktElseWhenLabel: JKKtElseWhenLabel) {
|
||||||
printer.printWithNoIndent("else")
|
printer.print("else")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitKtValueWhenLabelRaw(ktValueWhenLabel: JKKtValueWhenLabel) {
|
override fun visitKtValueWhenLabelRaw(ktValueWhenLabel: JKKtValueWhenLabel) {
|
||||||
@@ -859,28 +870,48 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
|
|||||||
|
|
||||||
fun printCodeOut(root: JKTreeElement): String {
|
fun printCodeOut(root: JKTreeElement): String {
|
||||||
Visitor().also { root.accept(it) }
|
Visitor().also { root.accept(it) }
|
||||||
return builder.toString().replace("\r\n", "\n")
|
return printer.toString().replace("\r\n", "\n")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class ParenthesisKind(val open: String, val close: String) {
|
enum class ParenthesisKind(val open: String, val close: String) {
|
||||||
ROUND("(", ")"),
|
ROUND("(", ")"),
|
||||||
SQUARE("[", "]"),
|
|
||||||
CURVED("{", "}"),
|
CURVED("{", "}"),
|
||||||
CURVED_MULTILINE("{\n", "}\n"),
|
|
||||||
INLINE_COMMENT("/*", "*/"),
|
|
||||||
ANGLE("<", ">")
|
ANGLE("<", ">")
|
||||||
}
|
}
|
||||||
|
|
||||||
private class JKPrinter(
|
private class JKPrinter(
|
||||||
stringBuilder: StringBuilder,
|
|
||||||
private val elementInfoStorage: JKElementInfoStorage
|
private val elementInfoStorage: JKElementInfoStorage
|
||||||
) : Printer(stringBuilder) {
|
) {
|
||||||
|
private val stringBuilder: StringBuilder = StringBuilder()
|
||||||
|
private var currentIndent = 0;
|
||||||
|
private val indentSymbol = " ".repeat(4)
|
||||||
|
|
||||||
|
private var lastSymbolIsLineBreak = false
|
||||||
|
|
||||||
|
override fun toString(): String = stringBuilder.toString()
|
||||||
|
|
||||||
|
fun print(value: String) {
|
||||||
|
if (value.isNotEmpty()) {
|
||||||
|
lastSymbolIsLineBreak = false
|
||||||
|
}
|
||||||
|
stringBuilder.append(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun println() {
|
||||||
|
if (lastSymbolIsLineBreak) return
|
||||||
|
stringBuilder.append('\n')
|
||||||
|
repeat(currentIndent) {
|
||||||
|
stringBuilder.append(indentSymbol)
|
||||||
|
}
|
||||||
|
lastSymbolIsLineBreak = true
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
inline fun indented(block: () -> Unit) {
|
inline fun indented(block: () -> Unit) {
|
||||||
this.pushIndent()
|
currentIndent++
|
||||||
block()
|
block()
|
||||||
this.popIndent()
|
currentIndent--
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun block(crossinline body: () -> Unit) {
|
inline fun block(crossinline body: () -> Unit) {
|
||||||
@@ -890,9 +921,9 @@ private class JKPrinter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline fun par(kind: ParenthesisKind = ParenthesisKind.ROUND, body: () -> Unit) {
|
inline fun par(kind: ParenthesisKind = ParenthesisKind.ROUND, body: () -> Unit) {
|
||||||
printWithNoIndent(kind.open)
|
this.print(kind.open)
|
||||||
body()
|
body()
|
||||||
printWithNoIndent(kind.close)
|
this.print(kind.close)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun JKSymbol.needFqName(): Boolean {
|
private fun JKSymbol.needFqName(): Boolean {
|
||||||
@@ -901,7 +932,7 @@ private class JKPrinter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun JKType.renderTypeInfo() {
|
private fun JKType.renderTypeInfo() {
|
||||||
print(elementInfoStorage.getOrCreateInfoForElement(this).render())
|
this@JKPrinter.print(elementInfoStorage.getOrCreateInfoForElement(this).render())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun renderType(type: JKType, owner: JKTreeElement?) {
|
fun renderType(type: JKType, owner: JKTreeElement?) {
|
||||||
@@ -913,7 +944,7 @@ private class JKPrinter(
|
|||||||
}
|
}
|
||||||
is JKStarProjectionType -> {
|
is JKStarProjectionType -> {
|
||||||
type.renderTypeInfo()
|
type.renderTypeInfo()
|
||||||
print("Any?")
|
this.print("Any?")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@@ -925,17 +956,17 @@ private class JKPrinter(
|
|||||||
}
|
}
|
||||||
is JKContextType -> return
|
is JKContextType -> return
|
||||||
is JKStarProjectionType ->
|
is JKStarProjectionType ->
|
||||||
printWithNoIndent("*")
|
this.print("*")
|
||||||
is JKTypeParameterType ->
|
is JKTypeParameterType ->
|
||||||
printWithNoIndent(type.identifier.name)
|
this.print(type.identifier.name)
|
||||||
is JKVarianceTypeParameterType -> {
|
is JKVarianceTypeParameterType -> {
|
||||||
when (type.variance) {
|
when (type.variance) {
|
||||||
JKVarianceTypeParameterType.Variance.IN -> printWithNoIndent("in ")
|
JKVarianceTypeParameterType.Variance.IN -> this.print("in ")
|
||||||
JKVarianceTypeParameterType.Variance.OUT -> printWithNoIndent("out ")
|
JKVarianceTypeParameterType.Variance.OUT -> this.print("out ")
|
||||||
}
|
}
|
||||||
renderType(type.boundType, null)
|
renderType(type.boundType, null)
|
||||||
}
|
}
|
||||||
else -> printWithNoIndent("Unit /* TODO: ${type::class} */")
|
else -> this.print("Unit /* TODO: ${type::class} */")
|
||||||
}
|
}
|
||||||
if (type is JKParametrizedType && type.parameters.isNotEmpty()) {
|
if (type is JKParametrizedType && type.parameters.isNotEmpty()) {
|
||||||
par(ParenthesisKind.ANGLE) {
|
par(ParenthesisKind.ANGLE) {
|
||||||
@@ -948,18 +979,18 @@ private class JKPrinter(
|
|||||||
&& owner?.safeAs<JKLambdaExpression>()?.functionalType?.type != type
|
&& owner?.safeAs<JKLambdaExpression>()?.functionalType?.type != type
|
||||||
|| type.nullability == Nullability.Nullable)
|
|| type.nullability == Nullability.Nullable)
|
||||||
) {
|
) {
|
||||||
printWithNoIndent("?")
|
this.print("?")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun renderSymbol(symbol: JKSymbol, owner: JKTreeElement?) {
|
fun renderSymbol(symbol: JKSymbol, owner: JKTreeElement?) {
|
||||||
val needFqName = symbol.needFqName() && owner?.isSelectorOfQualifiedExpression() != true
|
val needFqName = symbol.needFqName() && owner?.isSelectorOfQualifiedExpression() != true
|
||||||
val displayName = if (needFqName) symbol.getDisplayName() else symbol.name
|
val displayName = if (needFqName) symbol.getDisplayName() else symbol.name
|
||||||
printWithNoIndent(displayName.escapedAsQualifiedName())
|
this.print(displayName.escapedAsQualifiedName())
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun <T> renderList(list: List<T>, separator: String = ", ", renderElement: (T) -> Unit) =
|
inline fun <T> renderList(list: List<T>, separator: String = ", ", renderElement: (T) -> Unit) =
|
||||||
renderList(list, { printWithNoIndent(separator) }, renderElement)
|
renderList(list, { this.print(separator) }, renderElement)
|
||||||
|
|
||||||
inline fun <T> renderList(list: List<T>, separator: () -> Unit, renderElement: (T) -> Unit) {
|
inline fun <T> renderList(list: List<T>, separator: () -> Unit, renderElement: (T) -> Unit) {
|
||||||
val (head, tail) = list.headTail()
|
val (head, tail) = list.headTail()
|
||||||
|
|||||||
@@ -1,11 +1,8 @@
|
|||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
annotation class Ann(vararg val value: Inner, val test1: Array<InnerParam> = [InnerParam(C::class)])
|
annotation class Ann(vararg val value: Inner, val test1: Array<InnerParam> = [InnerParam(C::class)])
|
||||||
|
|
||||||
annotation class Inner
|
annotation class Inner
|
||||||
|
|
||||||
annotation class InnerParam(val value: KClass<*>)
|
annotation class InnerParam(val value: KClass<*>)
|
||||||
|
|
||||||
@Ann(value = [Inner(), Inner()], test1 = [InnerParam(C::class)])
|
@Ann(value = [Inner(), Inner()], test1 = [InnerParam(C::class)])
|
||||||
class C
|
class C
|
||||||
|
|
||||||
@@ -16,4 +13,4 @@ class D
|
|||||||
class E
|
class E
|
||||||
|
|
||||||
@Ann(value = [Inner()], test1 = [InnerParam(value = C::class)])
|
@Ann(value = [Inner()], test1 = [InnerParam(value = C::class)])
|
||||||
class F
|
class F
|
||||||
+1
-2
@@ -1,6 +1,5 @@
|
|||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
annotation class Ann(val i: Int = 1, val i2: IntArray = [1], val i3: IntArray = [1], val klass: KClass<*> = A::class, val klass2: Array<KClass<*>> = [A::class], val klass3: Array<KClass<*>> = [A::class], val ann: Inner = Inner(), val ann2: Array<Inner> = [Inner()], val ann3: Array<Inner> = [Inner(), Inner()])
|
annotation class Ann(val i: Int = 1, val i2: IntArray = [1], val i3: IntArray = [1], val klass: KClass<*> = A::class, val klass2: Array<KClass<*>> = [A::class], val klass3: Array<KClass<*>> = [A::class], val ann: Inner = Inner(), val ann2: Array<Inner> = [Inner()], val ann3: Array<Inner> = [Inner(), Inner()])
|
||||||
|
|
||||||
class A
|
class A
|
||||||
annotation class Inner
|
annotation class Inner
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
internal annotation class Anon(val stringArray: Array<String>, val intArray: IntArray, // string
|
internal annotation class Anon(val stringArray: Array<String>, val intArray: IntArray, // string
|
||||||
val string: String)
|
val string: String)
|
||||||
|
|
||||||
@Anon(string = "a", stringArray = ["a", "b"], intArray = [1, 2])
|
@Anon(string = "a", stringArray = ["a", "b"], intArray = [1, 2])
|
||||||
@@ -9,4 +9,4 @@ internal annotation class I
|
|||||||
internal annotation class J
|
internal annotation class J
|
||||||
|
|
||||||
@Target
|
@Target
|
||||||
internal annotation class K
|
internal annotation class K
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
internal annotation class Anon(val s: String = "a", val stringArray: Array<String> = ["a", "b"], val intArray: IntArray)
|
internal annotation class Anon(val s: String = "a", val stringArray: Array<String> = ["a", "b"], val intArray: IntArray)
|
||||||
|
|
||||||
@Anon(intArray = [1, 2])
|
@Anon(intArray = [1, 2])
|
||||||
internal class A
|
internal class A
|
||||||
@@ -1,5 +1,8 @@
|
|||||||
internal annotation class Anon(val value: String) {
|
internal annotation class Anon(val value: String) {
|
||||||
enum class E { A, B }
|
enum class E {
|
||||||
|
A, B
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
var field = E.A
|
var field = E.A
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
internal annotation class Anon(vararg val value: String, val x: Int = 1)
|
internal annotation class Anon(vararg val value: String, val x: Int = 1)
|
||||||
|
|
||||||
@Anon("a", "b")
|
@Anon("a", "b")
|
||||||
internal interface I1
|
internal interface I1
|
||||||
|
|
||||||
@@ -10,4 +9,4 @@ internal interface I2
|
|||||||
internal interface I3
|
internal interface I3
|
||||||
|
|
||||||
@Anon(value = ["c", "d"])
|
@Anon(value = ["c", "d"])
|
||||||
internal interface I4
|
internal interface I4
|
||||||
+1
-4
@@ -23,13 +23,10 @@ internal class C {
|
|||||||
@Anon5(1)
|
@Anon5(1)
|
||||||
@Deprecated("")
|
@Deprecated("")
|
||||||
private val field1 = 0
|
private val field1 = 0
|
||||||
|
|
||||||
@Anon5(1)
|
@Anon5(1)
|
||||||
private val field2 = 0
|
private val field2 = 0
|
||||||
|
|
||||||
@Anon5(1)
|
@Anon5(1)
|
||||||
var field3 = 0
|
var field3 = 0
|
||||||
|
|
||||||
@Anon5(1)
|
@Anon5(1)
|
||||||
var field4 = 0
|
var field4 = 0
|
||||||
|
|
||||||
@@ -41,4 +38,4 @@ internal class C {
|
|||||||
@Anon5(1)
|
@Anon5(1)
|
||||||
fun bar() {
|
fun bar() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,7 @@
|
|||||||
internal annotation class An(val value: String)
|
internal annotation class An(val value: String)
|
||||||
|
|
||||||
|
|
||||||
class Test {
|
class Test {
|
||||||
@get:An(value = "get")
|
@get:An(value = "get")
|
||||||
@set:An(value = "set")
|
@set:An(value = "set")
|
||||||
var id = 0
|
var id = 0
|
||||||
}
|
|
||||||
|
}
|
||||||
+1
-2
@@ -1,6 +1,5 @@
|
|||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
internal annotation class Ann(val value: KClass<*>, val other: KClass<*>)
|
internal annotation class Ann(val value: KClass<*>, val other: KClass<*>)
|
||||||
|
|
||||||
@Ann(other = String::class, value = Any::class)
|
@Ann(other = String::class, value = Any::class)
|
||||||
internal class C
|
internal class C
|
||||||
@@ -1,9 +1,8 @@
|
|||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
internal annotation class Ann(vararg val value: KClass<*>)
|
internal annotation class Ann(vararg val value: KClass<*>)
|
||||||
|
|
||||||
@Ann(String::class, Any::class)
|
@Ann(String::class, Any::class)
|
||||||
internal class C
|
internal class C
|
||||||
|
|
||||||
@Ann
|
@Ann
|
||||||
internal class D
|
internal class D
|
||||||
+1
-3
@@ -5,9 +5,7 @@ package test
|
|||||||
|
|
||||||
class Test(str: String) {
|
class Test(str: String) {
|
||||||
internal var myStr = "String2"
|
internal var myStr = "String2"
|
||||||
fun sout(str: String) {
|
fun sout(str: String) { // UNNECESSARY_NOT_NULL_ASSERTION heuristic does not work any more, instead we can skip generating !! altogether
|
||||||
// UNNECESSARY_NOT_NULL_ASSERTION heuristic does not work any more, instead we can skip generating !! altogether
|
|
||||||
|
|
||||||
println(str)
|
println(str)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@ import javaApi.SpecialExternal
|
|||||||
|
|
||||||
//Annotation class:
|
//Annotation class:
|
||||||
annotation class Special(val names: Array<String> //array is used
|
annotation class Special(val names: Array<String> //array is used
|
||||||
) //Class with annotation:
|
) //Class with annotation:
|
||||||
|
|
||||||
@Special(names = ["name1"])
|
@Special(names = ["name1"])
|
||||||
class JClass
|
class JClass
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
internal class C @Deprecated("")
|
internal class C @Deprecated("") constructor()
|
||||||
constructor()
|
|
||||||
+1
-5
@@ -1,8 +1,4 @@
|
|||||||
class A {
|
class A {
|
||||||
|
|
||||||
var b = 0
|
var b = 0
|
||||||
|
fun a(i: Int) {}
|
||||||
fun a(i: Int) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
internal abstract class C {
|
internal abstract class C {
|
||||||
fun foo() {
|
fun foo() {
|
||||||
val s1 = f()!!
|
val s1 = f()!!
|
||||||
|
|
||||||
val s2 = g() ?: error("g should not return null")
|
val s2 = g() ?: error("g should not return null")
|
||||||
val h = s2.hashCode()
|
val h = s2.hashCode()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
class AssignmentAsExpression {
|
class AssignmentAsExpression {
|
||||||
private var field = 0
|
private var field = 0
|
||||||
private var field2 = 0
|
private var field2 = 0
|
||||||
|
|
||||||
fun assign(value: Int) {
|
fun assign(value: Int) {
|
||||||
field = value
|
field = value
|
||||||
val v = field
|
val v = field
|
||||||
|
|||||||
@@ -11,21 +11,13 @@ internal object Test {
|
|||||||
b += c
|
b += c
|
||||||
a = b
|
a = b
|
||||||
//-----
|
//-----
|
||||||
|
|
||||||
|
|
||||||
a = b
|
a = b
|
||||||
//-----
|
//-----
|
||||||
|
|
||||||
|
|
||||||
a += b
|
a += b
|
||||||
//-----
|
//-----
|
||||||
|
|
||||||
|
|
||||||
b = c
|
b = c
|
||||||
a += b
|
a += b
|
||||||
//-----
|
//-----
|
||||||
|
|
||||||
|
|
||||||
b += c
|
b += c
|
||||||
a = b
|
a = b
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-9
@@ -10,21 +10,13 @@ internal object Test {
|
|||||||
b += c
|
b += c
|
||||||
a = b
|
a = b
|
||||||
//-----
|
//-----
|
||||||
|
|
||||||
|
|
||||||
a = b
|
a = b
|
||||||
//-----
|
//-----
|
||||||
|
|
||||||
|
|
||||||
a += b
|
a += b
|
||||||
//-----
|
//-----
|
||||||
|
|
||||||
|
|
||||||
b = c
|
b = c
|
||||||
a += b
|
a += b
|
||||||
//-----
|
//-----
|
||||||
|
|
||||||
|
|
||||||
a = c.let { b += it; b }
|
a = c.let { b += it; b }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,27 +7,20 @@ internal object Test {
|
|||||||
var d = 0
|
var d = 0
|
||||||
val e = 0
|
val e = 0
|
||||||
//-----
|
//-----
|
||||||
|
|
||||||
d *= e
|
d *= e
|
||||||
c = d
|
c = d
|
||||||
b += c
|
b += c
|
||||||
a = b
|
a = b
|
||||||
val f = a
|
val f = a
|
||||||
//-----
|
//-----
|
||||||
val g = a
|
val g = a
|
||||||
//-----
|
//-----
|
||||||
|
|
||||||
|
|
||||||
a = b
|
a = b
|
||||||
val h = a
|
val h = a
|
||||||
//-----
|
//-----
|
||||||
|
|
||||||
|
|
||||||
a += b
|
a += b
|
||||||
val i = a
|
val i = a
|
||||||
//-----
|
//-----
|
||||||
|
|
||||||
|
|
||||||
b = c
|
b = c
|
||||||
a += b
|
a += b
|
||||||
val j = a
|
val j = a
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ class Test {
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
val p = Test().toString() + "123"
|
val p = Test().toString() + "123"
|
||||||
|
|||||||
@@ -17,10 +17,7 @@ object A {
|
|||||||
* 2
|
* 2
|
||||||
* 3)
|
* 3)
|
||||||
val DIV = (1
|
val DIV = (1
|
||||||
|
|
||||||
/ 2
|
/ 2
|
||||||
|
|
||||||
|
|
||||||
/ 3)
|
/ 3)
|
||||||
val PERC = (1
|
val PERC = (1
|
||||||
% 2
|
% 2
|
||||||
|
|||||||
-2
@@ -4,11 +4,9 @@ fun foo() {
|
|||||||
val a = 1
|
val a = 1
|
||||||
bar(a)
|
bar(a)
|
||||||
}
|
}
|
||||||
|
|
||||||
run {
|
run {
|
||||||
val a = 2
|
val a = 2
|
||||||
bar(a)
|
bar(a)
|
||||||
}
|
}
|
||||||
|
|
||||||
run { bar(3) }
|
run { bar(3) }
|
||||||
}
|
}
|
||||||
@@ -6,7 +6,6 @@ internal object Library {
|
|||||||
|
|
||||||
internal class User {
|
internal class User {
|
||||||
fun main() {
|
fun main() {
|
||||||
|
|
||||||
Library.ourOut!!.print(1)
|
Library.ourOut!!.print(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,7 @@
|
|||||||
internal object Library {
|
internal object Library {
|
||||||
fun call() {}
|
fun call() {}
|
||||||
|
|
||||||
val string: String
|
val string: String
|
||||||
get() = ""
|
get() = ""
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class User {
|
internal class User {
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
internal class Library {
|
internal class Library {
|
||||||
fun call() {}
|
fun call() {}
|
||||||
|
|
||||||
val string: String
|
val string: String
|
||||||
get() = ""
|
get() = ""
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class User {
|
internal class User {
|
||||||
@@ -11,7 +9,6 @@ internal class User {
|
|||||||
val lib = Library()
|
val lib = Library()
|
||||||
lib.call()
|
lib.call()
|
||||||
lib.string.isEmpty()
|
lib.string.isEmpty()
|
||||||
|
|
||||||
Library().call()
|
Library().call()
|
||||||
Library().string.isEmpty()
|
Library().string.isEmpty()
|
||||||
}
|
}
|
||||||
|
|||||||
-1
@@ -1,6 +1,5 @@
|
|||||||
internal abstract class A {
|
internal abstract class A {
|
||||||
internal abstract fun callme()
|
internal abstract fun callme()
|
||||||
|
|
||||||
fun callmetoo() {
|
fun callmetoo() {
|
||||||
print("This is a concrete method.")
|
print("This is a concrete method.")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
internal abstract class Shape {
|
internal abstract class Shape {
|
||||||
var color: String? = null
|
var color: String? = null
|
||||||
|
|
||||||
abstract fun area(): Double
|
abstract fun area(): Double
|
||||||
}
|
}
|
||||||
+1
-3
@@ -1,7 +1,5 @@
|
|||||||
internal class A {
|
internal class A {
|
||||||
internal enum class E {
|
internal enum class E {
|
||||||
A,
|
A, B, C
|
||||||
B,
|
|
||||||
C
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
-1
@@ -3,7 +3,6 @@ object Util {
|
|||||||
internal const val protectedStr = ""
|
internal const val protectedStr = ""
|
||||||
internal const val packageStr = ""
|
internal const val packageStr = ""
|
||||||
private const val privateStr = ""
|
private const val privateStr = ""
|
||||||
|
|
||||||
fun publicMethod() {}
|
fun publicMethod() {}
|
||||||
internal fun protectedMethod() {}
|
internal fun protectedMethod() {}
|
||||||
internal fun packageMethod() {}
|
internal fun packageMethod() {}
|
||||||
|
|||||||
+3
-7
@@ -3,13 +3,9 @@ package test
|
|||||||
object Test {
|
object Test {
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
println()
|
println() // Comment
|
||||||
// Comment
|
foo() // Comment1
|
||||||
|
// Comment2
|
||||||
foo()
|
|
||||||
// Comment1
|
|
||||||
|
|
||||||
// Comment2
|
|
||||||
.indexOf("s")
|
.indexOf("s")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-10
@@ -2,27 +2,20 @@
|
|||||||
package foo
|
package foo
|
||||||
|
|
||||||
// we use package 'foo'
|
// we use package 'foo'
|
||||||
|
|
||||||
// imports:
|
// imports:
|
||||||
|
|
||||||
// we need ArrayList
|
// we need ArrayList
|
||||||
// let's declare a class:
|
// let's declare a class:
|
||||||
internal class A /* just a sample name*/ : Runnable /* let's implement Runnable */ {
|
internal class A /* just a sample name*/ : Runnable /* let's implement Runnable */ {
|
||||||
fun foo /* again a sample name */(p: Int /* parameter p */, c: Char /* parameter c */) {
|
fun foo /* again a sample name */(p: Int /* parameter p */, c: Char /* parameter c */) { // let's print something:
|
||||||
// let's print something:
|
|
||||||
println("1") // print 1
|
println("1") // print 1
|
||||||
println("2") // print 2
|
println("2") // print 2
|
||||||
|
|
||||||
println("3") // print 3
|
println("3") // print 3
|
||||||
|
|
||||||
// end of printing
|
// end of printing
|
||||||
|
|
||||||
if (p > 0) { // do this only when p > 0
|
if (p > 0) { // do this only when p > 0
|
||||||
// we print 4 and return
|
// we print 4 and return
|
||||||
println("3")
|
println("3")
|
||||||
return // do not continue
|
return // do not continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// some code to be added
|
// some code to be added
|
||||||
}
|
}
|
||||||
} // end of class A
|
} // end of class A
|
||||||
|
|||||||
+2
-2
@@ -26,7 +26,7 @@ internal class A {
|
|||||||
*/
|
*/
|
||||||
fun foo(param1: String?, param2: String?, param3: String?) {}
|
fun foo(param1: String?, param2: String?, param3: String?) {}
|
||||||
|
|
||||||
companion object { /*it's public*/ /*and static*/ /*and final*/
|
companion object {
|
||||||
const val C = 1
|
/*it's public*/ /*and static*/ /*and final*/ const val C = 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+15
-17
@@ -1,34 +1,32 @@
|
|||||||
internal class A // end of primary constructor body
|
internal class A // this is a primary constructor
|
||||||
|
// this is a secondary constructor 1
|
||||||
|
// end of primary constructor body
|
||||||
@JvmOverloads constructor(p: Int = 1) {
|
@JvmOverloads constructor(p: Int = 1) {
|
||||||
private val v = 1
|
private val v = 1
|
||||||
|
|
||||||
// this is a secondary constructor 2
|
// this is a secondary constructor 2
|
||||||
constructor(s: String) : this(s.length) {} // end of secondary constructor 2 body
|
constructor(s: String) : this(s.length) {} // end of secondary constructor 2 body
|
||||||
|
|
||||||
// this is a primary constructor
|
|
||||||
// this is a secondary constructor 1
|
|
||||||
|
|
||||||
|
|
||||||
// end of secondary constructor 1 body
|
// end of secondary constructor 1 body
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class B // end of constructor body
|
internal class B // this constructor will disappear
|
||||||
|
// end of constructor body
|
||||||
(private val x: Int) {
|
(private val x: Int) {
|
||||||
fun foo() {}
|
fun foo() {}
|
||||||
// this constructor will disappear
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class CtorComment {
|
internal class CtorComment /*
|
||||||
var myA = "a"
|
* The magic of comments
|
||||||
/*
|
*/
|
||||||
* The magic of comments
|
// single line magic comments
|
||||||
*/
|
{
|
||||||
// single line magic comments
|
var myA = "a"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class CtorComment2 /*
|
internal class CtorComment2 /*
|
||||||
* The magic of comments
|
* The magic of comments
|
||||||
*/
|
*/
|
||||||
// single line magic comments
|
// single line magic comments
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
class Check {
|
class Check {
|
||||||
fun a() {
|
fun a() {
|
||||||
|
|
||||||
val d = String() as Int
|
val d = String() as Int
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+1
-4
@@ -1,6 +1,3 @@
|
|||||||
fun foo(b: Boolean) {
|
fun foo(b: Boolean) {
|
||||||
if (b)
|
if (b) println("true") else println("false")
|
||||||
println("true")
|
|
||||||
else
|
|
||||||
println("false")
|
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
package pack
|
package pack
|
||||||
|
|
||||||
internal class C @JvmOverloads constructor(arg1: Int, arg2: Int = 0, arg3: Int = 0)
|
internal class C @JvmOverloads constructor(arg1: Int, arg2: Int = 0, arg3: Int = 0)
|
||||||
|
|
||||||
object User {
|
object User {
|
||||||
fun main() {
|
fun main() {
|
||||||
val c1 = C(100, 100, 100)
|
val c1 = C(100, 100, 100)
|
||||||
|
|||||||
-1
@@ -1,5 +1,4 @@
|
|||||||
internal class C(arg1: Int, arg2: Int, arg3: Int) {
|
internal class C(arg1: Int, arg2: Int, arg3: Int) {
|
||||||
|
|
||||||
constructor(arg1: Int, arg2: Int) : this(arg1, arg2, 0) {
|
constructor(arg1: Int, arg2: Int) : this(arg1, arg2, 0) {
|
||||||
println()
|
println()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,8 @@ internal class A @Anon5(10) constructor(private val a: Int, private val b: Int)
|
|||||||
@Deprecated("")
|
@Deprecated("")
|
||||||
constructor(a: Int) : this(a, 1) {
|
constructor(a: Int) : this(a, 1) {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class B @Anon5(11) constructor()
|
internal class B @Anon5(11) constructor()
|
||||||
internal class C @Anon5(12) private constructor()
|
internal class C @Anon5(12) private constructor()
|
||||||
@@ -1,2 +1,2 @@
|
|||||||
internal open class Base(o: Any?, l: Int)
|
internal open class Base(o: Any?, l: Int)
|
||||||
internal class C(private val string: String) : Base(string, string.length)
|
internal class C(private val string: String) : Base(string, string.length)
|
||||||
@@ -17,6 +17,7 @@ class Identifier {
|
|||||||
myHasDollar = hasDollar
|
myHasDollar = hasDollar
|
||||||
myNullable = isNullable
|
myNullable = isNullable
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
object User {
|
object User {
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
internal class C1(arg1: Int,
|
internal class C1(arg1: Int,
|
||||||
arg2: Int,
|
arg2: Int,
|
||||||
arg3: Int) {
|
arg3: Int) {
|
||||||
|
|
||||||
constructor(x: Int,
|
constructor(x: Int,
|
||||||
y: Int) : this(x, x + y, 0) {
|
y: Int) : this(x, x + y, 0) {
|
||||||
}
|
}
|
||||||
@@ -9,4 +8,4 @@ internal class C1(arg1: Int,
|
|||||||
|
|
||||||
internal class C2(private val arg1: Int,
|
internal class C2(private val arg1: Int,
|
||||||
private val arg2: Int,
|
private val arg2: Int,
|
||||||
arg3: Int)
|
arg3: Int)
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
internal class C(private val arg1: Int, private val arg2: Int, private val arg3: Int) {
|
internal class C(private val arg1: Int, private val arg2: Int, private val arg3: Int) {
|
||||||
|
|
||||||
fun foo(p: Int): Int {
|
fun foo(p: Int): Int {
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
@@ -17,4 +16,5 @@ internal class C(private val arg1: Int, private val arg2: Int, private val arg3:
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
}
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
internal open class Base
|
internal open class Base
|
||||||
|
|
||||||
internal class C : Base {
|
internal class C : Base {
|
||||||
constructor(arg1: Int, arg2: Int, arg3: Int) {}
|
constructor(arg1: Int, arg2: Int, arg3: Int) {}
|
||||||
|
|
||||||
constructor(arg1: Int, arg2: Int) : this(arg1, arg2, 0) {
|
constructor(arg1: Int, arg2: Int) : this(arg1, arg2, 0) {
|
||||||
println()
|
println()
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-2
@@ -1,6 +1,5 @@
|
|||||||
package pack
|
package pack
|
||||||
|
|
||||||
internal class C @JvmOverloads constructor(a: Int = 0, b: Int = 0, c: Int = 0, d: Int = 0, e: Int = 0) {
|
internal class C @JvmOverloads constructor(a: Int = 0, b: Int = 0, c: Int = 0, d: Int = 0, e: Int = 0) {
|
||||||
|
|
||||||
constructor(a: Int) : this(a, 0, 0, 0, 1) {}
|
constructor(a: Int) : this(a, 0, 0, 0, 1) {}
|
||||||
}
|
}
|
||||||
+1
-3
@@ -1,8 +1,6 @@
|
|||||||
package pack
|
package pack
|
||||||
|
|
||||||
internal class C @JvmOverloads constructor(a: Int = 0, b: Int = 0, c: Int = 0, d: Int = 0, e: Int = 0) {
|
internal class C @JvmOverloads constructor(a: Int = 0, b: Int = 0, c: Int = 0, d: Int = 0, e: Int = 0) {
|
||||||
|
|
||||||
constructor(a1: Int, b1: Int, c1: Int) : this(a1, b1, c1, 0, 0) {}
|
constructor(a1: Int, b1: Int, c1: Int) : this(a1, b1, c1, 0, 0) {}
|
||||||
|
|
||||||
constructor(b: Byte) : this(b.toInt(), 0, 0, 0, 0) {}
|
constructor(b: Byte) : this(b.toInt(), 0, 0, 0, 0) {}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
package pack
|
package pack
|
||||||
|
|
||||||
internal class C @JvmOverloads constructor(a: Int = 0, b: Int = 0, c: Int = 0, d: Int = 0, e: Int = 0) {
|
internal class C @JvmOverloads constructor(a: Int = 0, b: Int = 0, c: Int = 0, d: Int = 0, e: Int = 0) {
|
||||||
|
|
||||||
constructor(a: Int, b: Int, c: Int) : this(b, a, c, 0, 0) {}
|
constructor(a: Int, b: Int, c: Int) : this(b, a, c, 0, 0) {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
internal class C private constructor(arg1: Int, arg2: Int, arg3: Int = 0) {
|
internal class C private constructor(arg1: Int, arg2: Int, arg3: Int = 0) {
|
||||||
|
|
||||||
constructor(arg1: Int) : this(arg1, 0, 0) {}
|
constructor(arg1: Int) : this(arg1, 0, 0) {}
|
||||||
}
|
}
|
||||||
@@ -3,6 +3,7 @@ internal class C(private val arg1: Int, private val arg2: Int, private val arg3:
|
|||||||
constructor(arg1: Int, arg2: Int, other: C) : this(arg1, arg2, 0) {
|
constructor(arg1: Int, arg2: Int, other: C) : this(arg1, arg2, 0) {
|
||||||
println(this.arg1 + other.arg2)
|
println(this.arg1 + other.arg2)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class User {
|
internal class User {
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ internal class A {
|
|||||||
private var x = 0
|
private var x = 0
|
||||||
|
|
||||||
constructor() {}
|
constructor() {}
|
||||||
|
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
constructor(p: Int, s: String, x: Int = 1) {
|
constructor(p: Int, s: String, x: Int = 1) {
|
||||||
this.s = s
|
this.s = s
|
||||||
|
|||||||
@@ -1,38 +1,25 @@
|
|||||||
internal class Outer {
|
internal class Outer {
|
||||||
private inner class Inner1() {
|
private inner class Inner1() {
|
||||||
|
|
||||||
constructor(a: Int) : this() {}
|
constructor(a: Int) : this() {}
|
||||||
|
|
||||||
protected constructor(c: Char) : this() {}
|
protected constructor(c: Char) : this() {}
|
||||||
|
|
||||||
private constructor(b: Boolean) : this() {}
|
private constructor(b: Boolean) : this() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected inner class Inner2() {
|
protected inner class Inner2() {
|
||||||
|
|
||||||
constructor(a: Int) : this() {}
|
constructor(a: Int) : this() {}
|
||||||
|
|
||||||
protected constructor(c: Char) : this() {}
|
protected constructor(c: Char) : this() {}
|
||||||
|
|
||||||
private constructor(b: Boolean) : this() {}
|
private constructor(b: Boolean) : this() {}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal inner class Inner3() {
|
internal inner class Inner3() {
|
||||||
|
|
||||||
constructor(a: Int) : this() {}
|
constructor(a: Int) : this() {}
|
||||||
|
|
||||||
protected constructor(c: Char) : this() {}
|
protected constructor(c: Char) : this() {}
|
||||||
|
|
||||||
private constructor(b: Boolean) : this() {}
|
private constructor(b: Boolean) : this() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
inner class Inner4() {
|
inner class Inner4() {
|
||||||
|
|
||||||
constructor(a: Int) : this() {}
|
constructor(a: Int) : this() {}
|
||||||
|
|
||||||
protected constructor(c: Char) : this() {}
|
protected constructor(c: Char) : this() {}
|
||||||
|
|
||||||
private constructor(b: Boolean) : this() {}
|
private constructor(b: Boolean) : this() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,4 +29,4 @@ internal class Outer {
|
|||||||
val inner3 = Inner3(3)
|
val inner3 = Inner3(3)
|
||||||
val inner4 = Inner4(4)
|
val inner4 = Inner4(4)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,39 +8,26 @@ internal object Outer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private class Nested1() {
|
private class Nested1() {
|
||||||
|
|
||||||
constructor(a: Int) : this() {}
|
constructor(a: Int) : this() {}
|
||||||
|
|
||||||
protected constructor(c: Char) : this() {}
|
protected constructor(c: Char) : this() {}
|
||||||
|
|
||||||
private constructor(b: Boolean) : this() {}
|
private constructor(b: Boolean) : this() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected class Nested2() {
|
protected class Nested2() {
|
||||||
|
|
||||||
constructor(a: Int) : this() {}
|
constructor(a: Int) : this() {}
|
||||||
|
|
||||||
protected constructor(c: Char) : this() {}
|
protected constructor(c: Char) : this() {}
|
||||||
|
|
||||||
private constructor(b: Boolean) : this() {}
|
private constructor(b: Boolean) : this() {}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class Nested3() {
|
internal class Nested3() {
|
||||||
|
|
||||||
constructor(a: Int) : this() {}
|
constructor(a: Int) : this() {}
|
||||||
|
|
||||||
protected constructor(c: Char) : this() {}
|
protected constructor(c: Char) : this() {}
|
||||||
|
|
||||||
private constructor(b: Boolean) : this() {}
|
private constructor(b: Boolean) : this() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Nested4() {
|
class Nested4() {
|
||||||
|
|
||||||
constructor(a: Int) : this() {}
|
constructor(a: Int) : this() {}
|
||||||
|
|
||||||
protected constructor(c: Char) : this() {}
|
protected constructor(c: Char) : this() {}
|
||||||
|
|
||||||
private constructor(b: Boolean) : this() {}
|
private constructor(b: Boolean) : this() {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,21 +1,13 @@
|
|||||||
internal class A() {
|
internal class A() {
|
||||||
|
|
||||||
constructor(a: Int) : this() {}
|
constructor(a: Int) : this() {}
|
||||||
|
|
||||||
protected constructor(c: Char) : this() {}
|
protected constructor(c: Char) : this() {}
|
||||||
|
|
||||||
constructor(f: Float) : this() {}
|
constructor(f: Float) : this() {}
|
||||||
|
|
||||||
private constructor(d: Double) : this() {}
|
private constructor(d: Double) : this() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
class B() {
|
class B() {
|
||||||
|
|
||||||
constructor(a: Int) : this() {}
|
constructor(a: Int) : this() {}
|
||||||
|
|
||||||
protected constructor(c: Char) : this() {}
|
protected constructor(c: Char) : this() {}
|
||||||
|
|
||||||
internal constructor(f: Float) : this() {}
|
internal constructor(f: Float) : this() {}
|
||||||
|
|
||||||
private constructor(d: Double) : this() {}
|
private constructor(d: Double) : this() {}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
internal class C() {
|
internal class C() {
|
||||||
|
|
||||||
constructor(p: Int) : this() {
|
constructor(p: Int) : this() {
|
||||||
println(staticField1 + staticField2)
|
println(staticField1 + staticField2)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ class X {
|
|||||||
internal fun foo() {
|
internal fun foo() {
|
||||||
val runnable: Runnable = object : Runnable {
|
val runnable: Runnable = object : Runnable {
|
||||||
var value = 10
|
var value = 10
|
||||||
|
|
||||||
override fun run() {
|
override fun run() {
|
||||||
println(value)
|
println(value)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
class C {
|
class C {
|
||||||
var x: String? = null
|
var x: String? = null
|
||||||
internal set
|
internal set
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
class C {
|
class C {
|
||||||
private var x = ""
|
private var x = ""
|
||||||
internal var other: C? = null
|
internal var other: C? = null
|
||||||
|
|
||||||
fun getX(): String {
|
fun getX(): String {
|
||||||
return x
|
return x
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
class AAA {
|
class AAA {
|
||||||
private var x = 42
|
private var x = 42
|
||||||
|
|
||||||
fun setX(x: Int) {
|
fun setX(x: Int) {
|
||||||
this.x = x
|
this.x = x
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+2
-2
@@ -1,11 +1,12 @@
|
|||||||
internal class A(// comment for field2 setter
|
internal class A(// comment for field2 setter
|
||||||
// comment for field2 getter
|
// comment for field2 getter
|
||||||
var field2 // comment for field2
|
var field2 // comment for field2
|
||||||
: Int) { // Comment for field1
|
: Int) {
|
||||||
/**
|
/**
|
||||||
* Comment for field1 setter
|
* Comment for field1 setter
|
||||||
*/
|
*/
|
||||||
// Comment for field1 getter
|
// Comment for field1 getter
|
||||||
|
// Comment for field1
|
||||||
var field1 = 0
|
var field1 = 0
|
||||||
// comment for field3 setter
|
// comment for field3 setter
|
||||||
// comment for field3 getter
|
// comment for field3 getter
|
||||||
@@ -21,5 +22,4 @@ internal class A(// comment for field2 setter
|
|||||||
get() = 1
|
get() = 1
|
||||||
set(value) {}
|
set(value) {}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -4,6 +4,7 @@ internal interface I {
|
|||||||
val isSomething1: Boolean
|
val isSomething1: Boolean
|
||||||
val isSomething2: Boolean?
|
val isSomething2: Boolean?
|
||||||
val isSomething3: Int
|
val isSomething3: Int
|
||||||
|
|
||||||
fun isSomething4(): Boolean
|
fun isSomething4(): Boolean
|
||||||
fun setSomething4(value: Boolean)
|
fun setSomething4(value: Boolean)
|
||||||
fun isSomething5(): Boolean
|
fun isSomething5(): Boolean
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
class Test(var id: String, val name: String, val age: Int) {
|
class Test(var id: String, val name: String, val age: Int) {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
println(age)
|
println(age)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
class AAA {
|
class AAA {
|
||||||
var x = 42
|
var x = 42
|
||||||
}
|
|
||||||
|
}
|
||||||
+1
-2
@@ -1,7 +1,6 @@
|
|||||||
class AAA {
|
class AAA {
|
||||||
private val x = 42
|
private val x = 42
|
||||||
private val other = AAA()
|
private val other = AAA()
|
||||||
|
|
||||||
fun getX(): Int {
|
fun getX(): Int {
|
||||||
return other.x
|
return other.x
|
||||||
}
|
}
|
||||||
@@ -9,4 +8,4 @@ class AAA {
|
|||||||
fun issue(): Boolean {
|
fun issue(): Boolean {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+2
-1
@@ -3,4 +3,5 @@ class AAA {
|
|||||||
set(x) {
|
set(x) {
|
||||||
field += x
|
field += x
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
internal class A {
|
internal class A {
|
||||||
private val s: String? = null
|
private val s: String? = null
|
||||||
|
|
||||||
val value: Any?
|
val value: Any?
|
||||||
get() = s
|
get() = s
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
class C {
|
class C {
|
||||||
private var myX = ""
|
private var myX = ""
|
||||||
|
|
||||||
var x: String
|
var x: String
|
||||||
get() {
|
get() {
|
||||||
println("getter invoked")
|
println("getter invoked")
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
class C {
|
class C {
|
||||||
private var x = ""
|
private var x = ""
|
||||||
|
|
||||||
fun getX(): String {
|
fun getX(): String {
|
||||||
println("getter invoked")
|
println("getter invoked")
|
||||||
return x
|
return x
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
class C {
|
class C {
|
||||||
var x = ""
|
var x = ""
|
||||||
|
|
||||||
fun getX(): String {
|
fun getX(): String {
|
||||||
println("getter invoked")
|
println("getter invoked")
|
||||||
return x
|
return x
|
||||||
@@ -9,4 +8,4 @@ class C {
|
|||||||
fun setX(x: String) {
|
fun setX(x: String) {
|
||||||
this.x = x
|
this.x = x
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,4 +4,5 @@ class C {
|
|||||||
println("getter invoked")
|
println("getter invoked")
|
||||||
return field
|
return field
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
}
|
||||||
@@ -4,4 +4,5 @@ class C {
|
|||||||
println("getter invoked")
|
println("getter invoked")
|
||||||
return field
|
return field
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
}
|
||||||
@@ -4,7 +4,7 @@ class AAA {
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
var x = 42
|
var x = 42
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
internal interface I {
|
internal interface I {
|
||||||
val something1: Int
|
val something1: Int
|
||||||
var something2: Int
|
var something2: Int
|
||||||
|
|
||||||
fun setSomething3(value: Int)
|
fun setSomething3(value: Int)
|
||||||
fun getSomething4(): Int
|
fun getSomething4(): Int
|
||||||
fun setSomething4(value: String?)
|
fun setSomething4(value: String?)
|
||||||
val something5: Int
|
val something5: Int
|
||||||
|
|
||||||
fun setSomething5(value: Int): Int
|
fun setSomething5(value: Int): Int
|
||||||
}
|
}
|
||||||
+2
-1
@@ -5,8 +5,9 @@ object AAA {
|
|||||||
set(z) {
|
set(z) {
|
||||||
Other.z = z
|
Other.z = z
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal object Other {
|
internal object Other {
|
||||||
var z = 0
|
var z = 0
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,7 @@ internal interface I {
|
|||||||
val isSomething1: Boolean
|
val isSomething1: Boolean
|
||||||
val isSomething2: Boolean?
|
val isSomething2: Boolean?
|
||||||
val isSomething3: Int
|
val isSomething3: Int
|
||||||
|
|
||||||
fun isSomething4(): Boolean
|
fun isSomething4(): Boolean
|
||||||
fun setSomething4(value: Boolean)
|
fun setSomething4(value: Boolean)
|
||||||
fun isSomething5(): Boolean
|
fun isSomething5(): Boolean
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ internal interface I {
|
|||||||
val something1: Int
|
val something1: Int
|
||||||
val something2: Int
|
val something2: Int
|
||||||
var something3: Int
|
var something3: Int
|
||||||
|
|
||||||
fun getSomething4(): Int
|
fun getSomething4(): Int
|
||||||
fun setSomething4(value: Int)
|
fun setSomething4(value: Int)
|
||||||
fun getSomething5(): Int
|
fun getSomething5(): Int
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ internal class C {
|
|||||||
private val bbb = 0
|
private val bbb = 0
|
||||||
private val ccc = 0
|
private val ccc = 0
|
||||||
private val ddd = 0
|
private val ddd = 0
|
||||||
|
|
||||||
fun getAaa(): Int {
|
fun getAaa(): Int {
|
||||||
return bbb
|
return bbb
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
class C {
|
class C {
|
||||||
private var myX = ""
|
private var myX = ""
|
||||||
|
|
||||||
var x: String
|
var x: String
|
||||||
get() = myX
|
get() = myX
|
||||||
set(x) {
|
set(x) {
|
||||||
@@ -11,4 +10,4 @@ class C {
|
|||||||
internal fun foo() {
|
internal fun foo() {
|
||||||
myX = "a"
|
myX = "a"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
class C {
|
class C {
|
||||||
private var x = ""
|
private var x = ""
|
||||||
|
|
||||||
fun getX(): String {
|
fun getX(): String {
|
||||||
return x
|
return x
|
||||||
}
|
}
|
||||||
@@ -13,4 +12,4 @@ class C {
|
|||||||
internal fun foo() {
|
internal fun foo() {
|
||||||
x = "a"
|
x = "a"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
class C {
|
class C {
|
||||||
protected var x = ""
|
protected var x = ""
|
||||||
|
|
||||||
fun getX(): String {
|
fun getX(): String {
|
||||||
return x
|
return x
|
||||||
}
|
}
|
||||||
@@ -9,4 +8,4 @@ class C {
|
|||||||
println("setter invoked")
|
println("setter invoked")
|
||||||
this.x = x
|
this.x = x
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,4 +4,5 @@ class C {
|
|||||||
println("setter invoked")
|
println("setter invoked")
|
||||||
field = value
|
field = value
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -4,4 +4,5 @@ class C {
|
|||||||
println("setter invoked")
|
println("setter invoked")
|
||||||
field = x
|
field = x
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -4,4 +4,5 @@ class C {
|
|||||||
println("old value: " + this.x)
|
println("old value: " + this.x)
|
||||||
field = x
|
field = x
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
}
|
||||||
@@ -1,2 +1,3 @@
|
|||||||
class Nya /*comment before*/ /* comment after*/ // and after again
|
class Nya /*comment before*/
|
||||||
|
/* comment after*/ // and after again
|
||||||
(/*1*/ /*3*/ /*4*/private val i: Int)
|
(/*1*/ /*3*/ /*4*/private val i: Int)
|
||||||
+1
-2
@@ -1,9 +1,8 @@
|
|||||||
//Interface
|
//Interface
|
||||||
interface Parent {
|
interface Parent {
|
||||||
val x: Unit
|
val x: Unit
|
||||||
}
|
} //Subclass
|
||||||
|
|
||||||
//Subclass
|
|
||||||
class Child : Parent {
|
class Child : Parent {
|
||||||
override val x: Unit get() {}
|
override val x: Unit get() {}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,2 @@
|
|||||||
@Deprecated("Ph'nglui mglw'nafh\n" +
|
@Deprecated("Ph'nglui mglw'nafh\n" + " Cthulhu R'lyeh wgah'nagl fhtagn.\n" + " 'In His House at R'lyeh\n" + " Dead Cthulhu waits dreaming,\n" + " yet He shall rise and His kingdom\n" + " shall cover the Earth.'")
|
||||||
" Cthulhu R'lyeh wgah'nagl fhtagn.\n" +
|
class TestDeprecatedInJavadocWithMultilineMessage
|
||||||
" 'In His House at R'lyeh\n" +
|
|
||||||
" Dead Cthulhu waits dreaming,\n" +
|
|
||||||
" yet He shall rise and His kingdom\n" +
|
|
||||||
" shall cover the Earth.'")
|
|
||||||
class TestDeprecatedInJavadocWithMultilineMessage
|
|
||||||
+1
@@ -2,4 +2,5 @@ package demo
|
|||||||
|
|
||||||
internal enum class MyEnum(val color: Int) {
|
internal enum class MyEnum(val color: Int) {
|
||||||
RED(10), BLUE(20);
|
RED(10), BLUE(20);
|
||||||
|
|
||||||
}
|
}
|
||||||
+2
-5
@@ -1,10 +1,7 @@
|
|||||||
enum class TestEnum {
|
enum class TestEnum {
|
||||||
A,
|
A, B;
|
||||||
B;
|
|
||||||
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
fun parse(): TestEnum {
|
fun parse(): TestEnum {
|
||||||
return A
|
return A
|
||||||
}
|
}
|
||||||
@@ -15,4 +12,4 @@ internal class Go {
|
|||||||
fun fn() {
|
fun fn() {
|
||||||
val x = TestEnum.parse()
|
val x = TestEnum.parse()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+2
-4
@@ -1,9 +1,7 @@
|
|||||||
enum class E {
|
enum class E {
|
||||||
A,
|
A, B {
|
||||||
|
|
||||||
B {
|
|
||||||
override fun bar() {}
|
override fun bar() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
internal open fun bar() {}
|
internal open fun bar() {}
|
||||||
}
|
}
|
||||||
+2
-3
@@ -5,12 +5,11 @@ enum class E(private val p: Int) {
|
|||||||
foo(p)
|
foo(p)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
B(2) {
|
B(2) {
|
||||||
override fun bar() {}
|
override fun bar() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
internal fun foo(p: Int) {}
|
internal fun foo(p: Int) {}
|
||||||
|
|
||||||
internal abstract fun bar()
|
internal abstract fun bar()
|
||||||
}
|
|
||||||
|
}
|
||||||
+4
-1
@@ -1,4 +1,7 @@
|
|||||||
internal enum class E { FOO }
|
internal enum class E {
|
||||||
|
FOO
|
||||||
|
}
|
||||||
|
|
||||||
internal object A {
|
internal object A {
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
internal enum class Color(val code: Int) {
|
internal enum class Color(val code: Int) {
|
||||||
WHITE(21), BLACK(22), RED(23), YELLOW(24), BLUE(25);
|
WHITE(21), BLACK(22), RED(23), YELLOW(24), BLUE(25);
|
||||||
|
|
||||||
}
|
}
|
||||||
+1
-6
@@ -1,9 +1,6 @@
|
|||||||
internal interface I
|
internal interface I
|
||||||
|
|
||||||
internal class C
|
internal class C
|
||||||
|
|
||||||
internal class O
|
internal class O
|
||||||
|
|
||||||
internal class E {
|
internal class E {
|
||||||
override fun equals(o: Any?): Boolean {
|
override fun equals(o: Any?): Boolean {
|
||||||
return super.equals(o)
|
return super.equals(o)
|
||||||
@@ -17,7 +14,6 @@ internal open class B {
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal class BB : B()
|
internal class BB : B()
|
||||||
|
|
||||||
internal enum class EE {
|
internal enum class EE {
|
||||||
A, B, C
|
A, B, C
|
||||||
}
|
}
|
||||||
@@ -35,8 +31,7 @@ internal class X {
|
|||||||
if (bb1 === bb2) return
|
if (bb1 === bb2) return
|
||||||
if (arr1 == arr2) return
|
if (arr1 == arr2) return
|
||||||
if (ee1 == ee2 || ee1 == null) return
|
if (ee1 == ee2 || ee1 == null) return
|
||||||
|
|
||||||
if (s1 !== s2) return
|
if (s1 !== s2) return
|
||||||
if (c1 != c2) return
|
if (c1 != c2) return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
-1
@@ -1,5 +1,4 @@
|
|||||||
internal interface I
|
internal interface I
|
||||||
|
|
||||||
internal class C {
|
internal class C {
|
||||||
fun foo1(i1: I, i2: I): Boolean {
|
fun foo1(i1: I, i2: I): Boolean {
|
||||||
return i1 == i2
|
return i1 == i2
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
internal interface I
|
internal interface I
|
||||||
|
|
||||||
internal class C {
|
internal class C {
|
||||||
fun foo1(i1: I?, i2: I?): Boolean {
|
fun foo1(i1: I?, i2: I?): Boolean {
|
||||||
return i1 == i2
|
return i1 == i2
|
||||||
|
|||||||
-2
@@ -1,12 +1,10 @@
|
|||||||
internal class A {
|
internal class A {
|
||||||
private var i = byte.toInt()
|
private var i = byte.toInt()
|
||||||
|
|
||||||
fun foo() {
|
fun foo() {
|
||||||
i = 10
|
i = 10
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
val byte: Byte
|
val byte: Byte
|
||||||
get() = 0
|
get() = 0
|
||||||
}
|
}
|
||||||
|
|||||||
-1
@@ -1,5 +1,4 @@
|
|||||||
internal class Foo(a: Int, b: Int)
|
internal class Foo(a: Int, b: Int)
|
||||||
|
|
||||||
internal class C {
|
internal class C {
|
||||||
val f = Foo(1, 2)
|
val f = Foo(1, 2)
|
||||||
}
|
}
|
||||||
-1
@@ -1,5 +1,4 @@
|
|||||||
internal class Foo(a: Int, b: Int)
|
internal class Foo(a: Int, b: Int)
|
||||||
|
|
||||||
internal class C {
|
internal class C {
|
||||||
var f = Foo(1, 2)
|
var f = Foo(1, 2)
|
||||||
}
|
}
|
||||||
@@ -3,10 +3,8 @@ internal class A {
|
|||||||
@Deprecated("")
|
@Deprecated("")
|
||||||
@Volatile
|
@Volatile
|
||||||
var field1 = 0
|
var field1 = 0
|
||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
var field2 = 1
|
var field2 = 1
|
||||||
|
|
||||||
// Should work even for bad modifiers
|
// Should work even for bad modifiers
|
||||||
@Strictfp
|
@Strictfp
|
||||||
var field3 = 2.0
|
var field3 = 2.0
|
||||||
|
|||||||
+1
-2
@@ -7,11 +7,10 @@ internal class A {
|
|||||||
i *= 2
|
i *= 2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var i = 1
|
var i = 1
|
||||||
while (i < 2000) {
|
while (i < 2000) {
|
||||||
println(i)
|
println(i)
|
||||||
i *= 2
|
i *= 2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user