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