diff --git a/idea/src/org/jetbrains/kotlin/idea/codeInsight/surroundWith/expression/KotlinParenthesesSurrounder.java b/idea/src/org/jetbrains/kotlin/idea/codeInsight/surroundWith/expression/KotlinParenthesesSurrounder.java index 88ee52fd71f..916c7f2e7ab 100644 --- a/idea/src/org/jetbrains/kotlin/idea/codeInsight/surroundWith/expression/KotlinParenthesesSurrounder.java +++ b/idea/src/org/jetbrains/kotlin/idea/codeInsight/surroundWith/expression/KotlinParenthesesSurrounder.java @@ -40,25 +40,18 @@ public class KotlinParenthesesSurrounder extends KotlinExpressionSurrounder { @Nullable @Override - public TextRange surroundExpression(@NotNull Project project, @NotNull Editor editor, @NotNull KtExpression expression) { - expression = surroundWithParentheses(expression); + public TextRange surroundExpression( @NotNull Project project, @NotNull Editor editor, @NotNull KtExpression expression) { + KtParenthesizedExpression parenthesizedExpression = (KtParenthesizedExpression) KtPsiFactoryKt + .KtPsiFactory(expression).createExpression("(a)"); + KtExpression expressionWithoutParentheses = parenthesizedExpression.getExpression(); + assert expressionWithoutParentheses != null : "JetExpression should exists for " + parenthesizedExpression.getText() + " expression"; + expressionWithoutParentheses.replace(expression); + + expression = (KtExpression) expression.replace(parenthesizedExpression); CodeInsightUtilBase.forcePsiPostprocessAndRestoreElement(expression); int offset = expression.getTextRange().getEndOffset(); return new TextRange(offset, offset); } - - @NotNull - public static KtExpression surroundWithParentheses(@NotNull KtExpression expression) { - KtParenthesizedExpression parenthesizedExpression = - (KtParenthesizedExpression) KtPsiFactoryKt.KtPsiFactory(expression).createExpression("(a)"); - - KtExpression expressionWithoutParentheses = parenthesizedExpression.getExpression(); - assert expressionWithoutParentheses != null : "JetExpression should exists for " + parenthesizedExpression.getText() + " expression"; - expressionWithoutParentheses.replace(expression); - - expression = (KtExpression) expression.replace(parenthesizedExpression); - return expression; - } } diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/KotlinCleanupInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/KotlinCleanupInspection.kt index 527f819e257..2126243945e 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/KotlinCleanupInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/KotlinCleanupInspection.kt @@ -98,8 +98,7 @@ class KotlinCleanupInspection(): LocalInspectionTool(), CleanupLocalInspectionTo Errors.CALLABLE_REFERENCE_TO_MEMBER_OR_EXTENSION_WITH_EMPTY_LHS, Errors.DEPRECATED_TYPE_PARAMETER_SYNTAX, Errors.MISPLACED_TYPE_PARAMETER_CONSTRAINTS, - Errors.COMMA_IN_WHEN_CONDITION_WITHOUT_ARGUMENT, - Errors.UNSUPPORTED + Errors.COMMA_IN_WHEN_CONDITION_WITHOUT_ARGUMENT ) private fun Diagnostic.isObsoleteLabel(): Boolean { diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt index 7025ff153d1..d0660cb7cbd 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt @@ -378,8 +378,6 @@ class QuickFixRegistrar : QuickFixContributor { COMMA_IN_WHEN_CONDITION_WITHOUT_ARGUMENT.registerFactory(CommaInWhenConditionWithoutArgumentFix) - UNSUPPORTED.registerFactory(UnsupportedAsyncFix) - DATA_CLASS_NOT_PROPERTY_PARAMETER.registerFactory(AddValVarToConstructorParameterAction.QuickFixFactory) NON_LOCAL_RETURN_NOT_ALLOWED.registerFactory(AddCrossInlineFix) diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/UnsupportedAsyncFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/UnsupportedAsyncFix.kt deleted file mode 100644 index 590e96aef7a..00000000000 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/UnsupportedAsyncFix.kt +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.idea.quickfix - -import com.intellij.codeInsight.intention.IntentionAction -import com.intellij.openapi.editor.Editor -import com.intellij.openapi.project.Project -import com.intellij.psi.PsiElement -import org.jetbrains.kotlin.diagnostics.Diagnostic -import org.jetbrains.kotlin.diagnostics.Errors -import org.jetbrains.kotlin.idea.codeInsight.surroundWith.expression.KotlinParenthesesSurrounder -import org.jetbrains.kotlin.psi.KtBinaryExpression -import org.jetbrains.kotlin.psi.KtCallExpression -import org.jetbrains.kotlin.psi.KtFile -import org.jetbrains.kotlin.psi.KtPsiFactory - -class UnsupportedAsyncFix(val psiElement: PsiElement): KotlinQuickFixAction(psiElement), CleanupFix { - override fun getFamilyName(): String = "Migrate unsupported async syntax" - override fun getText(): String = familyName - - override fun invoke(project: Project, editor: Editor?, file: KtFile) { - if (element is KtBinaryExpression && element.right != null) { - KotlinParenthesesSurrounder.surroundWithParentheses(element.right!!) - } - - if (element is KtCallExpression) { - val ktExpression = element.calleeExpression ?: return - - // Add after "async" reference in call - element.addAfter(KtPsiFactory(element).createCallArguments("()"), ktExpression) - } - } - - companion object : KotlinSingleIntentionActionFactory() { - override fun createAction(diagnostic: Diagnostic): IntentionAction? { - if (diagnostic.psiElement.text != "async" || - !Errors.UNSUPPORTED.cast(diagnostic).a.startsWith("async block/lambda")) return null - - // Identifier -> Expression -> Call (normal call) or Identifier -> Operation Reference -> Binary Expression (for infix usage) - val grand = diagnostic.psiElement.parent.parent - if (grand is KtBinaryExpression || grand is KtCallExpression) { - return UnsupportedAsyncFix(grand) - } - - return null - } - } -} diff --git a/idea/testData/inspections/cleanup/cleanup.kt b/idea/testData/inspections/cleanup/cleanup.kt index bb1a0174789..0d5f78e6ace 100644 --- a/idea/testData/inspections/cleanup/cleanup.kt +++ b/idea/testData/inspections/cleanup/cleanup.kt @@ -74,23 +74,3 @@ val x = C() willBeInfix 1 fun infixTest() { arrayListOf(1, 2, 3) map { it } } - -fun async(f: () -> Unit) {} -infix fun Any.async(f: () -> Unit) {} - -fun test(foo: Any) { - async { } - async /**/ { } - foo async { } - - async() { } - - async({ }) - foo async ({ }) - - foo async fun () {} - foo async (fun () {}) - - async (fun () {}) -} - diff --git a/idea/testData/inspections/cleanup/cleanup.kt.after b/idea/testData/inspections/cleanup/cleanup.kt.after index 6f4915b481b..58ec1acd121 100644 --- a/idea/testData/inspections/cleanup/cleanup.kt.after +++ b/idea/testData/inspections/cleanup/cleanup.kt.after @@ -73,23 +73,3 @@ val x = C() willBeInfix 1 fun infixTest() { arrayListOf(1, 2, 3).map { it } } - -fun async(f: () -> Unit) {} -infix fun Any.async(f: () -> Unit) {} - -fun test(foo: Any) { - async() { } - async() /**/ { } - foo async ({ }) - - async() { } - - async({ }) - foo async ({ }) - - foo async (fun () {}) - foo async (fun () {}) - - async (fun () {}) -} - diff --git a/idea/testData/quickfix/asyncUnsupported/asyncInfixCall.kt b/idea/testData/quickfix/asyncUnsupported/asyncInfixCall.kt deleted file mode 100644 index 0ed56d6c7ff..00000000000 --- a/idea/testData/quickfix/asyncUnsupported/asyncInfixCall.kt +++ /dev/null @@ -1,6 +0,0 @@ -// "Migrate unsupported async syntax" "true" -infix fun Any.async(f: () -> Unit) = f() - -fun test(foo: Any) { - foo async { } -} \ No newline at end of file diff --git a/idea/testData/quickfix/asyncUnsupported/asyncInfixCall.kt.after b/idea/testData/quickfix/asyncUnsupported/asyncInfixCall.kt.after deleted file mode 100644 index 7aa4e629898..00000000000 --- a/idea/testData/quickfix/asyncUnsupported/asyncInfixCall.kt.after +++ /dev/null @@ -1,6 +0,0 @@ -// "Migrate unsupported async syntax" "true" -infix fun Any.async(f: () -> Unit) = f() - -fun test(foo: Any) { - foo async ({ }) -} \ No newline at end of file diff --git a/idea/testData/quickfix/asyncUnsupported/asyncInfixCallWithFun.kt b/idea/testData/quickfix/asyncUnsupported/asyncInfixCallWithFun.kt deleted file mode 100644 index cc3c351be14..00000000000 --- a/idea/testData/quickfix/asyncUnsupported/asyncInfixCallWithFun.kt +++ /dev/null @@ -1,6 +0,0 @@ -// "Migrate unsupported async syntax" "true" -infix fun Any.async(f: () -> Unit) = f() - -fun test(foo: Any) { - foo async fun () {} -} \ No newline at end of file diff --git a/idea/testData/quickfix/asyncUnsupported/asyncInfixCallWithFun.kt.after b/idea/testData/quickfix/asyncUnsupported/asyncInfixCallWithFun.kt.after deleted file mode 100644 index 171ad9cf6b0..00000000000 --- a/idea/testData/quickfix/asyncUnsupported/asyncInfixCallWithFun.kt.after +++ /dev/null @@ -1,6 +0,0 @@ -// "Migrate unsupported async syntax" "true" -infix fun Any.async(f: () -> Unit) = f() - -fun test(foo: Any) { - foo async (fun () {}) -} \ No newline at end of file diff --git a/idea/testData/quickfix/asyncUnsupported/asyncWithLambda.kt b/idea/testData/quickfix/asyncUnsupported/asyncWithLambda.kt deleted file mode 100644 index 1cb7d6b57bf..00000000000 --- a/idea/testData/quickfix/asyncUnsupported/asyncWithLambda.kt +++ /dev/null @@ -1,6 +0,0 @@ -// "Migrate unsupported async syntax" "true" -fun async(f: () -> Unit) {} - -fun test() { - async { } -} diff --git a/idea/testData/quickfix/asyncUnsupported/asyncWithLambda.kt.after b/idea/testData/quickfix/asyncUnsupported/asyncWithLambda.kt.after deleted file mode 100644 index b152f5674b4..00000000000 --- a/idea/testData/quickfix/asyncUnsupported/asyncWithLambda.kt.after +++ /dev/null @@ -1,6 +0,0 @@ -// "Migrate unsupported async syntax" "true" -fun async(f: () -> Unit) {} - -fun test() { - async() { } -} diff --git a/idea/testData/quickfix/asyncUnsupported/asyncWithLambdaAndComment.kt b/idea/testData/quickfix/asyncUnsupported/asyncWithLambdaAndComment.kt deleted file mode 100644 index fcb2b53286a..00000000000 --- a/idea/testData/quickfix/asyncUnsupported/asyncWithLambdaAndComment.kt +++ /dev/null @@ -1,6 +0,0 @@ -// "Migrate unsupported async syntax" "true" -fun async(f: () -> Unit) {} - -fun test() { - async /**/ { } -} diff --git a/idea/testData/quickfix/asyncUnsupported/asyncWithLambdaAndComment.kt.after b/idea/testData/quickfix/asyncUnsupported/asyncWithLambdaAndComment.kt.after deleted file mode 100644 index bed586cfc60..00000000000 --- a/idea/testData/quickfix/asyncUnsupported/asyncWithLambdaAndComment.kt.after +++ /dev/null @@ -1,6 +0,0 @@ -// "Migrate unsupported async syntax" "true" -fun async(f: () -> Unit) {} - -fun test() { - async() /**/ { } -} diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java index f0910b1e702..4f286522061 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java @@ -584,39 +584,6 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest { } } - @TestMetadata("idea/testData/quickfix/asyncUnsupported") - @TestDataPath("$PROJECT_ROOT") - @RunWith(JUnit3RunnerWithInners.class) - public static class AsyncUnsupported extends AbstractQuickFixTest { - public void testAllFilesPresentInAsyncUnsupported() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/asyncUnsupported"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), true); - } - - @TestMetadata("asyncInfixCall.kt") - public void testAsyncInfixCall() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/asyncUnsupported/asyncInfixCall.kt"); - doTest(fileName); - } - - @TestMetadata("asyncInfixCallWithFun.kt") - public void testAsyncInfixCallWithFun() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/asyncUnsupported/asyncInfixCallWithFun.kt"); - doTest(fileName); - } - - @TestMetadata("asyncWithLambda.kt") - public void testAsyncWithLambda() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/asyncUnsupported/asyncWithLambda.kt"); - doTest(fileName); - } - - @TestMetadata("asyncWithLambdaAndComment.kt") - public void testAsyncWithLambdaAndComment() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/asyncUnsupported/asyncWithLambdaAndComment.kt"); - doTest(fileName); - } - } - @TestMetadata("idea/testData/quickfix/autoImports") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)