Revert "Quick fix for deprecated async syntax"
This reverts commit afc1e24571.
This commit is contained in:
+8
-15
@@ -40,25 +40,18 @@ public class KotlinParenthesesSurrounder extends KotlinExpressionSurrounder {
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public TextRange surroundExpression(@NotNull Project project, @NotNull Editor editor, @NotNull KtExpression expression) {
|
public TextRange surroundExpression( @NotNull Project project, @NotNull Editor editor, @NotNull KtExpression expression) {
|
||||||
expression = surroundWithParentheses(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);
|
CodeInsightUtilBase.forcePsiPostprocessAndRestoreElement(expression);
|
||||||
|
|
||||||
int offset = expression.getTextRange().getEndOffset();
|
int offset = expression.getTextRange().getEndOffset();
|
||||||
return new TextRange(offset, offset);
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,8 +98,7 @@ class KotlinCleanupInspection(): LocalInspectionTool(), CleanupLocalInspectionTo
|
|||||||
Errors.CALLABLE_REFERENCE_TO_MEMBER_OR_EXTENSION_WITH_EMPTY_LHS,
|
Errors.CALLABLE_REFERENCE_TO_MEMBER_OR_EXTENSION_WITH_EMPTY_LHS,
|
||||||
Errors.DEPRECATED_TYPE_PARAMETER_SYNTAX,
|
Errors.DEPRECATED_TYPE_PARAMETER_SYNTAX,
|
||||||
Errors.MISPLACED_TYPE_PARAMETER_CONSTRAINTS,
|
Errors.MISPLACED_TYPE_PARAMETER_CONSTRAINTS,
|
||||||
Errors.COMMA_IN_WHEN_CONDITION_WITHOUT_ARGUMENT,
|
Errors.COMMA_IN_WHEN_CONDITION_WITHOUT_ARGUMENT
|
||||||
Errors.UNSUPPORTED
|
|
||||||
)
|
)
|
||||||
|
|
||||||
private fun Diagnostic.isObsoleteLabel(): Boolean {
|
private fun Diagnostic.isObsoleteLabel(): Boolean {
|
||||||
|
|||||||
@@ -378,8 +378,6 @@ class QuickFixRegistrar : QuickFixContributor {
|
|||||||
|
|
||||||
COMMA_IN_WHEN_CONDITION_WITHOUT_ARGUMENT.registerFactory(CommaInWhenConditionWithoutArgumentFix)
|
COMMA_IN_WHEN_CONDITION_WITHOUT_ARGUMENT.registerFactory(CommaInWhenConditionWithoutArgumentFix)
|
||||||
|
|
||||||
UNSUPPORTED.registerFactory(UnsupportedAsyncFix)
|
|
||||||
|
|
||||||
DATA_CLASS_NOT_PROPERTY_PARAMETER.registerFactory(AddValVarToConstructorParameterAction.QuickFixFactory)
|
DATA_CLASS_NOT_PROPERTY_PARAMETER.registerFactory(AddValVarToConstructorParameterAction.QuickFixFactory)
|
||||||
|
|
||||||
NON_LOCAL_RETURN_NOT_ALLOWED.registerFactory(AddCrossInlineFix)
|
NON_LOCAL_RETURN_NOT_ALLOWED.registerFactory(AddCrossInlineFix)
|
||||||
|
|||||||
@@ -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>(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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-20
@@ -74,23 +74,3 @@ val x = C() willBeInfix 1
|
|||||||
fun infixTest() {
|
fun infixTest() {
|
||||||
arrayListOf(1, 2, 3) map { it }
|
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 () {})
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -73,23 +73,3 @@ val x = C() willBeInfix 1
|
|||||||
fun infixTest() {
|
fun infixTest() {
|
||||||
arrayListOf(1, 2, 3).map { it }
|
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 () {})
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
// "Migrate unsupported async syntax" "true"
|
|
||||||
infix fun Any.async(f: () -> Unit) = f()
|
|
||||||
|
|
||||||
fun test(foo: Any) {
|
|
||||||
foo <caret>async { }
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
// "Migrate unsupported async syntax" "true"
|
|
||||||
infix fun Any.async(f: () -> Unit) = f()
|
|
||||||
|
|
||||||
fun test(foo: Any) {
|
|
||||||
foo <caret>async ({ })
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
// "Migrate unsupported async syntax" "true"
|
|
||||||
infix fun Any.async(f: () -> Unit) = f()
|
|
||||||
|
|
||||||
fun test(foo: Any) {
|
|
||||||
foo async<caret> fun () {}
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
// "Migrate unsupported async syntax" "true"
|
|
||||||
infix fun Any.async(f: () -> Unit) = f()
|
|
||||||
|
|
||||||
fun test(foo: Any) {
|
|
||||||
foo async<caret> (fun () {})
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
// "Migrate unsupported async syntax" "true"
|
|
||||||
fun async(f: () -> Unit) {}
|
|
||||||
|
|
||||||
fun test() {
|
|
||||||
asy<caret>nc { }
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
// "Migrate unsupported async syntax" "true"
|
|
||||||
fun async(f: () -> Unit) {}
|
|
||||||
|
|
||||||
fun test() {
|
|
||||||
asy<caret>nc() { }
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
// "Migrate unsupported async syntax" "true"
|
|
||||||
fun async(f: () -> Unit) {}
|
|
||||||
|
|
||||||
fun test() {
|
|
||||||
async<caret> /**/ { }
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
// "Migrate unsupported async syntax" "true"
|
|
||||||
fun async(f: () -> Unit) {}
|
|
||||||
|
|
||||||
fun test() {
|
|
||||||
async<caret>() /**/ { }
|
|
||||||
}
|
|
||||||
@@ -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")
|
@TestMetadata("idea/testData/quickfix/autoImports")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
|||||||
Reference in New Issue
Block a user