KT-11804 J2K: incorrect closing parenthesis position for method split to several lines
#KT-11804 Fixed
This commit is contained in:
@@ -276,7 +276,7 @@ class Converter private constructor(
|
|||||||
} +
|
} +
|
||||||
otherMethods.map { method -> createParameter(convertType(method.returnType), method) }
|
otherMethods.map { method -> createParameter(convertType(method.returnType), method) }
|
||||||
|
|
||||||
val parameterList = ParameterList(parameters).assignNoPrototype()
|
val parameterList = ParameterList.withNoPrototype(parameters)
|
||||||
val constructorSignature = if (parameterList.parameters.isNotEmpty())
|
val constructorSignature = if (parameterList.parameters.isNotEmpty())
|
||||||
PrimaryConstructorSignature(Annotations.Empty, Modifiers.Empty, parameterList).assignNoPrototype()
|
PrimaryConstructorSignature(Annotations.Empty, Modifiers.Empty, parameterList).assignNoPrototype()
|
||||||
else
|
else
|
||||||
@@ -355,7 +355,7 @@ class Converter private constructor(
|
|||||||
val superAccess = QualifiedExpression(superExpression, propertyInfo.identifier).assignNoPrototype()
|
val superAccess = QualifiedExpression(superExpression, propertyInfo.identifier).assignNoPrototype()
|
||||||
val returnStatement = ReturnStatement(superAccess).assignNoPrototype()
|
val returnStatement = ReturnStatement(superAccess).assignNoPrototype()
|
||||||
val body = Block.of(returnStatement).assignNoPrototype()
|
val body = Block.of(returnStatement).assignNoPrototype()
|
||||||
val parameterList = ParameterList(emptyList()).assignNoPrototype()
|
val parameterList = ParameterList.withNoPrototype(emptyList())
|
||||||
getter = PropertyAccessor(AccessorKind.GETTER, Annotations.Empty, Modifiers.Empty, parameterList, deferredElement { body })
|
getter = PropertyAccessor(AccessorKind.GETTER, Annotations.Empty, Modifiers.Empty, parameterList, deferredElement { body })
|
||||||
getter.assignNoPrototype()
|
getter.assignNoPrototype()
|
||||||
}
|
}
|
||||||
@@ -375,7 +375,7 @@ class Converter private constructor(
|
|||||||
val parameterList = if (method.body != null || !parameterAnnotations.isEmpty) {
|
val parameterList = if (method.body != null || !parameterAnnotations.isEmpty) {
|
||||||
val parameter = FunctionParameter(convertedParameter.identifier, null, FunctionParameter.VarValModifier.None, parameterAnnotations, Modifiers.Empty)
|
val parameter = FunctionParameter(convertedParameter.identifier, null, FunctionParameter.VarValModifier.None, parameterAnnotations, Modifiers.Empty)
|
||||||
.assignPrototypesFrom(convertedParameter, CommentsAndSpacesInheritance.NO_SPACES)
|
.assignPrototypesFrom(convertedParameter, CommentsAndSpacesInheritance.NO_SPACES)
|
||||||
ParameterList(listOf(parameter)).assignNoPrototype()
|
ParameterList.withNoPrototype(listOf(parameter))
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
null
|
null
|
||||||
@@ -390,7 +390,7 @@ class Converter private constructor(
|
|||||||
val assignment = AssignmentExpression(superAccess, valueIdentifier, Operator.EQ).assignNoPrototype()
|
val assignment = AssignmentExpression(superAccess, valueIdentifier, Operator.EQ).assignNoPrototype()
|
||||||
val body = Block.of(assignment).assignNoPrototype()
|
val body = Block.of(assignment).assignNoPrototype()
|
||||||
val parameter = FunctionParameter(valueIdentifier, propertyType, FunctionParameter.VarValModifier.None, Annotations.Empty, Modifiers.Empty).assignNoPrototype()
|
val parameter = FunctionParameter(valueIdentifier, propertyType, FunctionParameter.VarValModifier.None, Annotations.Empty, Modifiers.Empty).assignNoPrototype()
|
||||||
val parameterList = ParameterList(listOf(parameter)).assignNoPrototype()
|
val parameterList = ParameterList.withNoPrototype(listOf(parameter))
|
||||||
setter = PropertyAccessor(AccessorKind.SETTER, Annotations.Empty, accessorModifiers, parameterList, deferredElement { body })
|
setter = PropertyAccessor(AccessorKind.SETTER, Annotations.Empty, accessorModifiers, parameterList, deferredElement { body })
|
||||||
setter.assignNoPrototype()
|
setter.assignNoPrototype()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -692,7 +692,7 @@ class DefaultExpressionConverter : JavaElementVisitor(), ExpressionConverter {
|
|||||||
val paramName = Identifier(it.name!!).assignNoPrototype()
|
val paramName = Identifier(it.name!!).assignNoPrototype()
|
||||||
val paramType = if (it.typeElement != null) converter.typeConverter.convertType(it.type) else null
|
val paramType = if (it.typeElement != null) converter.typeConverter.convertType(it.type) else null
|
||||||
LambdaParameter(paramName, paramType).assignPrototype(it)
|
LambdaParameter(paramName, paramType).assignPrototype(it)
|
||||||
}).assignPrototype(parameters)
|
}, lPar = null, rPar = null).assignPrototype(parameters)
|
||||||
|
|
||||||
val body = expression.body
|
val body = expression.body
|
||||||
when (body) {
|
when (body) {
|
||||||
@@ -810,7 +810,9 @@ class DefaultExpressionConverter : JavaElementVisitor(), ExpressionConverter {
|
|||||||
emptyList()
|
emptyList()
|
||||||
} else {
|
} else {
|
||||||
parameters.map { LambdaParameter(it.first, it.second).assignNoPrototype() }
|
parameters.map { LambdaParameter(it.first, it.second).assignNoPrototype() }
|
||||||
}).assignNoPrototype()
|
},
|
||||||
|
lPar = null,
|
||||||
|
rPar = null).assignNoPrototype()
|
||||||
|
|
||||||
val lambdaExpression = LambdaExpression(lambdaParameterList, Block.of(statement).assignNoPrototype()).assignNoPrototype()
|
val lambdaExpression = LambdaExpression(lambdaParameterList, Block.of(statement).assignNoPrototype()).assignNoPrototype()
|
||||||
|
|
||||||
|
|||||||
@@ -181,13 +181,19 @@ fun Converter.convertParameterList(
|
|||||||
): ParameterList {
|
): ParameterList {
|
||||||
val parameterList = method.parameterList
|
val parameterList = method.parameterList
|
||||||
val params = parameterList.parameters
|
val params = parameterList.parameters
|
||||||
return ParameterList(params.indices.map { i ->
|
val lParen = parameterList.node.findChildByType(JavaTokenType.LPARENTH)?.psi
|
||||||
val parameter = params[i]
|
val rParen = parameterList.node.findChildByType(JavaTokenType.RPARENTH)?.psi
|
||||||
val defaultValue = overloadReducer?.parameterDefault(method, i)
|
return ParameterList(
|
||||||
val defaultValueConverted = if (defaultValue != null)
|
params.indices.map { i ->
|
||||||
deferredElement { codeConverter -> codeConverter.correctCodeConverter().convertExpression(defaultValue, parameter.type) }
|
val parameter = params[i]
|
||||||
else
|
val defaultValue = overloadReducer?.parameterDefault(method, i)
|
||||||
null
|
val defaultValueConverted = if (defaultValue != null)
|
||||||
convertParameter(parameter, defaultValueConverted)
|
deferredElement { codeConverter -> codeConverter.correctCodeConverter().convertExpression(defaultValue, parameter.type) }
|
||||||
}).assignPrototype(parameterList)
|
else
|
||||||
|
null
|
||||||
|
convertParameter(parameter, defaultValueConverted)
|
||||||
|
},
|
||||||
|
LPar().assignPrototype(lParen, CommentsAndSpacesInheritance.LINE_BREAKS),
|
||||||
|
RPar().assignPrototype(rParen, CommentsAndSpacesInheritance.LINE_BREAKS)
|
||||||
|
).assignPrototype(parameterList)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -196,7 +196,7 @@ class DefaultStatementConverter : JavaElementVisitor(), StatementConverter {
|
|||||||
else
|
else
|
||||||
listOf(parameterType)
|
listOf(parameterType)
|
||||||
for (t in types) {
|
for (t in types) {
|
||||||
var convertedType = codeConverter.typeConverter.convertType(t, Nullability.NotNull)
|
val convertedType = codeConverter.typeConverter.convertType(t, Nullability.NotNull)
|
||||||
val convertedParameter = FunctionParameter(parameter.declarationIdentifier(),
|
val convertedParameter = FunctionParameter(parameter.declarationIdentifier(),
|
||||||
convertedType,
|
convertedType,
|
||||||
FunctionParameter.VarValModifier.None,
|
FunctionParameter.VarValModifier.None,
|
||||||
@@ -216,7 +216,7 @@ class DefaultStatementConverter : JavaElementVisitor(), StatementConverter {
|
|||||||
var expression: Expression = Expression.Empty
|
var expression: Expression = Expression.Empty
|
||||||
for (variable in resourceVariables.asReversed()) {
|
for (variable in resourceVariables.asReversed()) {
|
||||||
val parameter = LambdaParameter(Identifier(variable.name!!).assignNoPrototype(), null).assignNoPrototype()
|
val parameter = LambdaParameter(Identifier(variable.name!!).assignNoPrototype(), null).assignNoPrototype()
|
||||||
val parameterList = ParameterList(listOf(parameter)).assignNoPrototype()
|
val parameterList = ParameterList(listOf(parameter), lPar = null, rPar = null).assignNoPrototype()
|
||||||
val lambda = LambdaExpression(parameterList, block)
|
val lambda = LambdaExpression(parameterList, block)
|
||||||
expression = MethodCallExpression.build(codeConverter.convertExpression(variable.initializer), "use", listOf(lambda), listOf(), false)
|
expression = MethodCallExpression.build(codeConverter.convertExpression(variable.initializer), "use", listOf(lambda), listOf(), false)
|
||||||
expression.assignNoPrototype()
|
expression.assignNoPrototype()
|
||||||
|
|||||||
@@ -75,10 +75,10 @@ class PrimaryConstructorSignature(val annotations: Annotations, private val modi
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (needConstructorKeyword) {
|
if (needConstructorKeyword) {
|
||||||
builder append " constructor"
|
builder.append(" constructor")
|
||||||
}
|
}
|
||||||
|
|
||||||
builder append "(" append parameterList append ")"
|
builder.append(parameterList)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,9 +93,8 @@ class SecondaryConstructor(
|
|||||||
override fun generateCode(builder: CodeBuilder) {
|
override fun generateCode(builder: CodeBuilder) {
|
||||||
builder.append(annotations)
|
builder.append(annotations)
|
||||||
.appendWithSpaceAfter(modifiers)
|
.appendWithSpaceAfter(modifiers)
|
||||||
.append("constructor(")
|
.append("constructor")
|
||||||
.append(parameterList)
|
.append(parameterList)
|
||||||
.append(")")
|
|
||||||
|
|
||||||
if (thisOrSuperCall != null) {
|
if (thisOrSuperCall != null) {
|
||||||
builder append " : " append thisOrSuperCall
|
builder append " : " append thisOrSuperCall
|
||||||
|
|||||||
@@ -61,9 +61,7 @@ class Function(
|
|||||||
.append("fun ")
|
.append("fun ")
|
||||||
.appendWithSuffix(typeParameterList, " ")
|
.appendWithSuffix(typeParameterList, " ")
|
||||||
.append(name)
|
.append(name)
|
||||||
.append("(")
|
|
||||||
.append(parameterList)
|
.append(parameterList)
|
||||||
.append(")")
|
|
||||||
|
|
||||||
if (!returnType.isUnit()) {
|
if (!returnType.isUnit()) {
|
||||||
builder append ":" append returnType
|
builder append ":" append returnType
|
||||||
|
|||||||
@@ -19,9 +19,35 @@ package org.jetbrains.kotlin.j2k.ast
|
|||||||
import org.jetbrains.kotlin.j2k.CodeBuilder
|
import org.jetbrains.kotlin.j2k.CodeBuilder
|
||||||
import org.jetbrains.kotlin.j2k.append
|
import org.jetbrains.kotlin.j2k.append
|
||||||
|
|
||||||
class ParameterList(val parameters: List<Parameter>) : Element() {
|
class ParameterList(
|
||||||
|
val parameters: List<Parameter>,
|
||||||
|
val lPar: LPar?,
|
||||||
|
val rPar: RPar?
|
||||||
|
) : Element() {
|
||||||
override fun generateCode(builder: CodeBuilder) {
|
override fun generateCode(builder: CodeBuilder) {
|
||||||
|
lPar?.let { builder.append(it) }
|
||||||
|
|
||||||
builder.append(parameters, ", ")
|
builder.append(parameters, ", ")
|
||||||
|
|
||||||
|
rPar?.let { builder.append(it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun withNoPrototype(parameters: List<Parameter>): ParameterList {
|
||||||
|
return ParameterList(parameters, LPar().assignNoPrototype(), RPar().assignNoPrototype()).assignNoPrototype()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// we use LPar and RPar elements to better handle comments and line breaks around them
|
||||||
|
class LPar : Element() {
|
||||||
|
override fun generateCode(builder: CodeBuilder) {
|
||||||
|
builder.append("(")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class RPar : Element() {
|
||||||
|
override fun generateCode(builder: CodeBuilder) {
|
||||||
|
builder.append(")")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -94,11 +94,11 @@ class PropertyAccessor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (parameterList != null) {
|
if (parameterList != null) {
|
||||||
builder append "(" append parameterList append ")"
|
builder.append(parameterList)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (body != null) {
|
if (body != null) {
|
||||||
builder append " " append body
|
builder.append(" ").append(body)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
public interface Aaa {
|
||||||
|
void foo(
|
||||||
|
String e1,
|
||||||
|
String e2
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
interface Aaa {
|
||||||
|
fun foo(
|
||||||
|
e1: String,
|
||||||
|
e2: String
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -13,6 +13,7 @@ internal class C {
|
|||||||
|
|
||||||
fun foo4(
|
fun foo4(
|
||||||
p1: Int, p2: Int,
|
p1: Int, p2: Int,
|
||||||
p3: Int, p4: Int) {
|
p3: Int, p4: Int
|
||||||
|
) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2308,6 +2308,12 @@ public class JavaToKotlinConverterForWebDemoTestGenerated extends AbstractJavaTo
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("parameterList.java")
|
||||||
|
public void testParameterList() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("j2k/testData/fileOrElement/formatting/parameterList.java");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("staticAndNonStaticMembersWithComments.java")
|
@TestMetadata("staticAndNonStaticMembersWithComments.java")
|
||||||
public void testStaticAndNonStaticMembersWithComments() throws Exception {
|
public void testStaticAndNonStaticMembersWithComments() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("j2k/testData/fileOrElement/formatting/staticAndNonStaticMembersWithComments.java");
|
String fileName = KotlinTestUtils.navigationMetadata("j2k/testData/fileOrElement/formatting/staticAndNonStaticMembersWithComments.java");
|
||||||
|
|||||||
@@ -2308,6 +2308,12 @@ public class JavaToKotlinConverterSingleFileTestGenerated extends AbstractJavaTo
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("parameterList.java")
|
||||||
|
public void testParameterList() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("j2k/testData/fileOrElement/formatting/parameterList.java");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("staticAndNonStaticMembersWithComments.java")
|
@TestMetadata("staticAndNonStaticMembersWithComments.java")
|
||||||
public void testStaticAndNonStaticMembersWithComments() throws Exception {
|
public void testStaticAndNonStaticMembersWithComments() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("j2k/testData/fileOrElement/formatting/staticAndNonStaticMembersWithComments.java");
|
String fileName = KotlinTestUtils.navigationMetadata("j2k/testData/fileOrElement/formatting/staticAndNonStaticMembersWithComments.java");
|
||||||
|
|||||||
Reference in New Issue
Block a user