J2K: drop line breaks in some polyadic expressions
This commit is contained in:
+2
-1
@@ -10,4 +10,5 @@
|
||||
### Tools. J2K
|
||||
- Protected members used outside of inheritors are converted as public
|
||||
- Support conversion for annotation constructor calls
|
||||
- Place comments from the middle of the call to the end
|
||||
- Place comments from the middle of the call to the end
|
||||
- Drop line breaks between operator arguments (except '+', "-", "&&" and "||")
|
||||
@@ -614,13 +614,14 @@ class DefaultExpressionConverter : JavaElementVisitor(), ExpressionConverter {
|
||||
}
|
||||
|
||||
override fun visitPolyadicExpression(expression: PsiPolyadicExpression) {
|
||||
val commentsAndSpacesInheritance = CommentsAndSpacesInheritance.LINE_BREAKS
|
||||
val args = expression.operands.map {
|
||||
codeConverter.convertExpression(it, expression.type).assignPrototype(it, commentsAndSpacesInheritance)
|
||||
codeConverter.convertExpression(it, expression.type).assignPrototype(it, CommentsAndSpacesInheritance.LINE_BREAKS)
|
||||
}
|
||||
val operators = expression.operands.mapNotNull {
|
||||
expression.getTokenBeforeOperand(it)?.let {
|
||||
Operator(it.tokenType).assignPrototype(it, commentsAndSpacesInheritance)
|
||||
val operator = Operator(it.tokenType)
|
||||
val commentsAndSpacesInheritance = if (operator.acceptLineBreakBefore()) CommentsAndSpacesInheritance.LINE_BREAKS else CommentsAndSpacesInheritance.NO_SPACES
|
||||
operator.assignPrototype(it, commentsAndSpacesInheritance)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -142,6 +142,16 @@ open class Operator(val operatorType: IElementType): Expression() {
|
||||
|
||||
fun asString() = asString(operatorType)
|
||||
|
||||
fun acceptLineBreakBefore(): Boolean {
|
||||
return when(operatorType) {
|
||||
JavaTokenType.ANDAND,
|
||||
JavaTokenType.OROR,
|
||||
JavaTokenType.PLUS,
|
||||
JavaTokenType.MINUS -> true
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
private fun asString(tokenType: IElementType): String {
|
||||
return when(tokenType) {
|
||||
JavaTokenType.EQ -> "="
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
public class A {
|
||||
public static void main(String[] args) {
|
||||
boolean ANDAND = true
|
||||
&& true
|
||||
&& true;
|
||||
boolean OROR = true
|
||||
|| true
|
||||
|| true;
|
||||
int PLUS = 1
|
||||
+ 2
|
||||
+ 3;
|
||||
int MINUS = 1
|
||||
- 2
|
||||
- 3;
|
||||
int ASTERISK = 1
|
||||
* 2
|
||||
* 3;
|
||||
int DIV = 1
|
||||
|
||||
/ 2
|
||||
|
||||
|
||||
/ 3;
|
||||
int PERC = 1
|
||||
% 2
|
||||
% 3;
|
||||
int GTGT = 1
|
||||
<< 2
|
||||
<< 3;
|
||||
int LTLT = 1
|
||||
>> 2
|
||||
>> 3;
|
||||
int XOR = 1
|
||||
^ 2
|
||||
^ 3;
|
||||
int AND = 1
|
||||
& 2
|
||||
& 3;
|
||||
int OR = 1
|
||||
% 2
|
||||
% 3;
|
||||
int GTGTGT = 1
|
||||
>>> 2
|
||||
>>> 3;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
object A {
|
||||
@JvmStatic fun main(args: Array<String>) {
|
||||
val ANDAND = true
|
||||
&& true
|
||||
&& true
|
||||
val OROR = true
|
||||
|| true
|
||||
|| true
|
||||
val PLUS = 1
|
||||
+2
|
||||
+3
|
||||
val MINUS = 1
|
||||
-2
|
||||
-3
|
||||
val ASTERISK = 1 * 2 * 3
|
||||
val DIV = 1 / 2 / 3
|
||||
val PERC = 1 % 2 % 3
|
||||
val GTGT = 1 shl 2 shl 3
|
||||
val LTLT = 1 shr 2 shr 3
|
||||
val XOR = 1 xor 2 xor 3
|
||||
val AND = 1 and 2 and 3
|
||||
val OR = 1 % 2 % 3
|
||||
val GTGTGT = 1 ushr 2 ushr 3
|
||||
}
|
||||
}
|
||||
@@ -538,6 +538,12 @@ public class JavaToKotlinConverterForWebDemoTestGenerated extends AbstractJavaTo
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("orWithNewLine.java")
|
||||
public void testOrWithNewLine() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("j2k/testData/fileOrElement/binaryExpression/orWithNewLine.java");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("plus.java")
|
||||
public void testPlus() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("j2k/testData/fileOrElement/binaryExpression/plus.java");
|
||||
|
||||
@@ -538,6 +538,12 @@ public class JavaToKotlinConverterSingleFileTestGenerated extends AbstractJavaTo
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("orWithNewLine.java")
|
||||
public void testOrWithNewLine() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("j2k/testData/fileOrElement/binaryExpression/orWithNewLine.java");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("plus.java")
|
||||
public void testPlus() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("j2k/testData/fileOrElement/binaryExpression/plus.java");
|
||||
|
||||
Reference in New Issue
Block a user