mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[kotlin] support surround with finally as expression
^KTIJ-29325 fixed GitOrigin-RevId: 4463e0c5e61614e61c42af14f8314c6017ef71c6
This commit is contained in:
committed by
intellij-monorepo-bot
parent
20dea6b25e
commit
b35bac2d92
+1
@@ -16,6 +16,7 @@ public class KotlinExpressionSurroundDescriptor extends KotlinExpressionSurround
|
||||
new KotlinWithIfExpressionSurrounder(/* withElse = */true),
|
||||
new KotlinTryExpressionSurrounder.TryCatch(),
|
||||
new KotlinTryExpressionSurrounder.TryCatchFinally(),
|
||||
new KotlinTryExpressionSurrounder.TryFinally(),
|
||||
new KotlinIfElseExpressionSurrounder(/* withBraces = */false),
|
||||
new KotlinIfElseExpressionSurrounder(/* withBraces = */true)
|
||||
};
|
||||
|
||||
+17
@@ -23,6 +23,23 @@ sealed class KotlinTryExpressionSurrounder : KotlinControlFlowExpressionSurround
|
||||
|
||||
}
|
||||
|
||||
class TryFinally : KotlinTryExpressionSurrounder() {
|
||||
@NlsSafe
|
||||
override fun getTemplateDescription() = "try { expr } finally {}"
|
||||
override fun getPattern() = "try { $0 } finally {\nb\n}"
|
||||
override fun getRange(
|
||||
editor: Editor,
|
||||
replaced: KtExpression
|
||||
): TextRange? {
|
||||
val blockExpression = (replaced as KtTryExpression).finallyBlock?.finalExpression ?: return null
|
||||
val stmt = blockExpression.statements[0]
|
||||
val range = stmt.textRange
|
||||
stmt.delete()
|
||||
val offset = range?.startOffset ?: return null
|
||||
return TextRange(offset, offset)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getRange(editor: Editor, replaced: KtExpression): TextRange? {
|
||||
val tryExpression = replaced as KtTryExpression
|
||||
return KotlinTrySurrounderBase.getCatchTypeParameterTextRange(tryExpression)
|
||||
|
||||
+23
@@ -612,6 +612,29 @@ public abstract class KotlinFirSurroundWithTestGenerated extends AbstractKotlinF
|
||||
}
|
||||
}
|
||||
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
@TestMetadata("../../idea/tests/testData/codeInsight/surroundWith/tryFinallyExpression")
|
||||
public static class TryFinallyExpression extends AbstractKotlinFirSurroundWithTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTestWithTryFinallyExpressionSurrounder, this, testDataFilePath);
|
||||
}
|
||||
|
||||
@TestMetadata("asStatement.kt")
|
||||
public void testAsStatement() throws Exception {
|
||||
runTest("../../idea/tests/testData/codeInsight/surroundWith/tryFinallyExpression/asStatement.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("singleExpression.kt")
|
||||
public void testSingleExpression() throws Exception {
|
||||
runTest("../../idea/tests/testData/codeInsight/surroundWith/tryFinallyExpression/singleExpression.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("singleExpressionUnit.kt")
|
||||
public void testSingleExpressionUnit() throws Exception {
|
||||
runTest("../../idea/tests/testData/codeInsight/surroundWith/tryFinallyExpression/singleExpressionUnit.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
@TestMetadata("../../idea/tests/testData/codeInsight/surroundWith/functionLiteral")
|
||||
public static class FunctionLiteral extends AbstractKotlinFirSurroundWithTest {
|
||||
|
||||
+4
@@ -63,6 +63,10 @@ public abstract class AbstractSurroundWithTest extends KotlinLightCodeInsightFix
|
||||
doTest(path, new KotlinTryExpressionSurrounder.TryCatch());
|
||||
}
|
||||
|
||||
public void doTestWithTryFinallyExpressionSurrounder(String path) throws Exception {
|
||||
doTest(path, new KotlinTryExpressionSurrounder.TryFinally());
|
||||
}
|
||||
|
||||
public void doTestWithTryCatchFinallySurrounder(String path) throws Exception {
|
||||
doTest(path, new KotlinTryCatchFinallySurrounder());
|
||||
}
|
||||
|
||||
+23
@@ -612,6 +612,29 @@ public abstract class SurroundWithTestGenerated extends AbstractSurroundWithTest
|
||||
}
|
||||
}
|
||||
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
@TestMetadata("testData/codeInsight/surroundWith/tryFinallyExpression")
|
||||
public static class TryFinallyExpression extends AbstractSurroundWithTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTestWithTryFinallyExpressionSurrounder, this, testDataFilePath);
|
||||
}
|
||||
|
||||
@TestMetadata("asStatement.kt")
|
||||
public void testAsStatement() throws Exception {
|
||||
runTest("testData/codeInsight/surroundWith/tryFinallyExpression/asStatement.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("singleExpression.kt")
|
||||
public void testSingleExpression() throws Exception {
|
||||
runTest("testData/codeInsight/surroundWith/tryFinallyExpression/singleExpression.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("singleExpressionUnit.kt")
|
||||
public void testSingleExpressionUnit() throws Exception {
|
||||
runTest("testData/codeInsight/surroundWith/tryFinallyExpression/singleExpressionUnit.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
@TestMetadata("testData/codeInsight/surroundWith/functionLiteral")
|
||||
public static class FunctionLiteral extends AbstractSurroundWithTest {
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
// IS_APPLICABLE: true
|
||||
fun call() {}
|
||||
fun foo() {
|
||||
<selection>call()</selection>
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
// IS_APPLICABLE: true
|
||||
fun call() {}
|
||||
fun foo() {
|
||||
<selection>call()</selection>
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
fun foo() = <selection>"aaa"</selection>
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
fun foo() = try {
|
||||
"aaa"
|
||||
} finally {
|
||||
<selection><caret></selection>}
|
||||
+1
@@ -0,0 +1 @@
|
||||
fun foo() = <selection>println("")</selection>
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
fun foo() = try {
|
||||
println("")
|
||||
} finally {
|
||||
<selection><caret></selection>}
|
||||
+1
@@ -540,6 +540,7 @@ private fun assembleWorkspace(): TWorkspace = workspace {
|
||||
model("codeInsight/surroundWith/tryCatchFinally", testMethodName = "doTestWithTryCatchFinallySurrounder")
|
||||
model("codeInsight/surroundWith/tryCatchFinallyExpression", testMethodName = "doTestWithTryCatchFinallyExpressionSurrounder")
|
||||
model("codeInsight/surroundWith/tryFinally", testMethodName = "doTestWithTryFinallySurrounder")
|
||||
model("codeInsight/surroundWith/tryFinallyExpression", testMethodName = "doTestWithTryFinallyExpressionSurrounder")
|
||||
model("codeInsight/surroundWith/functionLiteral", testMethodName = "doTestWithFunctionLiteralSurrounder")
|
||||
model("codeInsight/surroundWith/withIfExpression", testMethodName = "doTestWithSurroundWithIfExpression")
|
||||
model("codeInsight/surroundWith/withIfElseExpression", testMethodName = "doTestWithSurroundWithIfElseExpression")
|
||||
|
||||
+1
@@ -44,6 +44,7 @@ internal fun MutableTWorkspace.generateK2CodeInsightTests() {
|
||||
model("../../../idea/tests/testData/codeInsight/surroundWith/tryCatchFinally", testMethodName = "doTestWithTryCatchFinallySurrounder")
|
||||
model("../../../idea/tests/testData/codeInsight/surroundWith/tryCatchFinallyExpression", testMethodName = "doTestWithTryCatchFinallyExpressionSurrounder")
|
||||
model("../../../idea/tests/testData/codeInsight/surroundWith/tryFinally", testMethodName = "doTestWithTryFinallySurrounder")
|
||||
model("../../../idea/tests/testData/codeInsight/surroundWith/tryFinallyExpression", testMethodName = "doTestWithTryFinallyExpressionSurrounder")
|
||||
model("../../../idea/tests/testData/codeInsight/surroundWith/functionLiteral", testMethodName = "doTestWithFunctionLiteralSurrounder")
|
||||
model("../../../idea/tests/testData/codeInsight/surroundWith/withIfExpression", testMethodName = "doTestWithSurroundWithIfExpression")
|
||||
model("../../../idea/tests/testData/codeInsight/surroundWith/withIfElseExpression", testMethodName = "doTestWithSurroundWithIfElseExpression")
|
||||
|
||||
Reference in New Issue
Block a user