mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-02-04 23:39:07 +07:00
[kotlin] J2K: Remove redundant parentheses around Java ternary operator condition
^KTIJ-30900 Fixed GitOrigin-RevId: b05a0b4ace13b64ad44ed7a1108608e4fa5cd8ad
This commit is contained in:
committed by
intellij-monorepo-bot
parent
afd89f9ffd
commit
fbdb34b321
@@ -5771,6 +5771,11 @@ public abstract class NewJavaToKotlinConverterSingleFileTestGenerated extends Ab
|
||||
runTest("../../shared/tests/testData/newJ2k/parenthesizedExpression/removeUnnecessaryParentheses.java");
|
||||
}
|
||||
|
||||
@TestMetadata("removeUnnecessaryParenthesesConditionalExpression.java")
|
||||
public void testRemoveUnnecessaryParenthesesConditionalExpression() throws Exception {
|
||||
runTest("../../shared/tests/testData/newJ2k/parenthesizedExpression/removeUnnecessaryParenthesesConditionalExpression.java");
|
||||
}
|
||||
|
||||
@TestMetadata("removeUnnecessaryParenthesesConditionalOperators.java")
|
||||
public void testRemoveUnnecessaryParenthesesConditionalOperators() throws Exception {
|
||||
runTest("../../shared/tests/testData/newJ2k/parenthesizedExpression/removeUnnecessaryParenthesesConditionalOperators.java");
|
||||
|
||||
@@ -5771,6 +5771,11 @@ public abstract class K2JavaToKotlinConverterSingleFileTestGenerated extends Abs
|
||||
runTest("../../shared/tests/testData/newJ2k/parenthesizedExpression/removeUnnecessaryParentheses.java");
|
||||
}
|
||||
|
||||
@TestMetadata("removeUnnecessaryParenthesesConditionalExpression.java")
|
||||
public void testRemoveUnnecessaryParenthesesConditionalExpression() throws Exception {
|
||||
runTest("../../shared/tests/testData/newJ2k/parenthesizedExpression/removeUnnecessaryParenthesesConditionalExpression.java");
|
||||
}
|
||||
|
||||
@TestMetadata("removeUnnecessaryParenthesesConditionalOperators.java")
|
||||
public void testRemoveUnnecessaryParenthesesConditionalOperators() throws Exception {
|
||||
runTest("../../shared/tests/testData/newJ2k/parenthesizedExpression/removeUnnecessaryParenthesesConditionalOperators.java");
|
||||
|
||||
@@ -194,8 +194,12 @@ class JavaToJKTreeBuilder(
|
||||
}
|
||||
|
||||
private fun PsiConditionalExpression.toJK(): JKIfElseExpression {
|
||||
val condition = this.condition.toJK().let {
|
||||
// Unwrap parentheses to avoid double-wrapping in Kotlin: `if ((condition))`
|
||||
if (it is JKParenthesizedExpression) it::expression.detached() else it
|
||||
}
|
||||
val expression = JKIfElseExpression(
|
||||
condition.toJK(),
|
||||
condition,
|
||||
thenExpression.toJK(),
|
||||
elseExpression.toJK(),
|
||||
type.toJK()
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
public class J {
|
||||
String test1(String s) {
|
||||
return (s != null) ? "true" : "false";
|
||||
}
|
||||
|
||||
String test2(String s) {
|
||||
return (s
|
||||
!=
|
||||
null) ? "true" : "false";
|
||||
}
|
||||
|
||||
String test3(String s) {
|
||||
return
|
||||
(s != null)
|
||||
? "true"
|
||||
: "false";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
class J {
|
||||
fun test1(s: String?): String {
|
||||
return if (s != null) "true" else "false"
|
||||
}
|
||||
|
||||
fun test2(s: String?): String {
|
||||
return if (s
|
||||
!=
|
||||
null
|
||||
) "true" else "false"
|
||||
}
|
||||
|
||||
fun test3(s: String?): String {
|
||||
return if (s != null)
|
||||
"true"
|
||||
else
|
||||
"false"
|
||||
}
|
||||
}
|
||||
@@ -10,8 +10,8 @@ class Foo {
|
||||
val product = (a[j].toLong() and LONG_MASK) * xLong + carry
|
||||
val difference = q[offset--] - product
|
||||
carry = ((product ushr 32)
|
||||
+ (if (((difference and LONG_MASK) >
|
||||
(((product.toInt().inv()).toLong() and LONG_MASK)))
|
||||
+ (if ((difference and LONG_MASK) >
|
||||
(((product.toInt().inv()).toLong() and LONG_MASK))
|
||||
) 1 else 0))
|
||||
}
|
||||
return carry.toInt()
|
||||
|
||||
Reference in New Issue
Block a user