Revert "Reserve "async* {}", extend the quick-fix"
This reverts commit a7e7d53e2b.
This commit is contained in:
@@ -398,6 +398,6 @@ object WhenChecker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun checkReservedPrefix(trace: BindingTrace, expression: KtWhenExpression) {
|
fun checkReservedPrefix(trace: BindingTrace, expression: KtWhenExpression) {
|
||||||
checkReservedPrefixWord(trace, expression.whenKeyword, "sealed", TokenSet.EMPTY, "sealed when")
|
checkReservedPrefixWord(trace, expression.whenKeyword, "sealed", "sealed when")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -251,11 +251,6 @@ public interface KtTokens {
|
|||||||
NOT_IN, NOT_IS,
|
NOT_IN, NOT_IS,
|
||||||
IDENTIFIER);
|
IDENTIFIER);
|
||||||
|
|
||||||
TokenSet BINARY_OPERATIONS = TokenSet.create(AS_KEYWORD, AS_SAFE, IS_KEYWORD, IN_KEYWORD, MUL, PLUS,
|
|
||||||
MINUS, DIV, PERC, LT, GT, LTEQ, GTEQ, EQEQEQ, EXCLEQEQEQ, EQEQ, EXCLEQ, ANDAND, OROR,
|
|
||||||
ELVIS, RANGE, EQ, MULTEQ, DIVEQ, PERCEQ, PLUSEQ, MINUSEQ,
|
|
||||||
NOT_IN, NOT_IS);
|
|
||||||
|
|
||||||
TokenSet AUGMENTED_ASSIGNMENTS = TokenSet.create(PLUSEQ, MINUSEQ, MULTEQ, PERCEQ, DIVEQ);
|
TokenSet AUGMENTED_ASSIGNMENTS = TokenSet.create(PLUSEQ, MINUSEQ, MULTEQ, PERCEQ, DIVEQ);
|
||||||
TokenSet ALL_ASSIGNMENTS = TokenSet.create(EQ, PLUSEQ, MINUSEQ, MULTEQ, PERCEQ, DIVEQ);
|
TokenSet ALL_ASSIGNMENTS = TokenSet.create(EQ, PLUSEQ, MINUSEQ, MULTEQ, PERCEQ, DIVEQ);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ import com.intellij.psi.PsiElement;
|
|||||||
import com.intellij.psi.PsiFile;
|
import com.intellij.psi.PsiFile;
|
||||||
import com.intellij.psi.PsiWhiteSpace;
|
import com.intellij.psi.PsiWhiteSpace;
|
||||||
import com.intellij.psi.tree.IElementType;
|
import com.intellij.psi.tree.IElementType;
|
||||||
import com.intellij.psi.tree.TokenSet;
|
|
||||||
import com.intellij.psi.util.PsiTreeUtil;
|
import com.intellij.psi.util.PsiTreeUtil;
|
||||||
import com.intellij.util.codeInsight.CommentUtilCore;
|
import com.intellij.util.codeInsight.CommentUtilCore;
|
||||||
import org.jetbrains.annotations.Contract;
|
import org.jetbrains.annotations.Contract;
|
||||||
@@ -598,21 +597,9 @@ public class KtPsiUtil {
|
|||||||
return prev;
|
return prev;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Example:
|
|
||||||
* code: async* {}
|
|
||||||
* element = "{}"
|
|
||||||
* word = "async"
|
|
||||||
* suffixTokens = [+, -, *, /, %]
|
|
||||||
*
|
|
||||||
* result = async
|
|
||||||
*/
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static PsiElement getPreviousWord(@NotNull PsiElement element, @NotNull String word, @NotNull TokenSet suffixTokens) {
|
public static PsiElement getPreviousWord(@NotNull PsiElement element, @NotNull String word) {
|
||||||
PsiElement prev = prevLeafIgnoringWhitespaceAndComments(element);
|
PsiElement prev = prevLeafIgnoringWhitespaceAndComments(element);
|
||||||
if (prev != null && suffixTokens.contains(prev.getNode().getElementType())) {
|
|
||||||
prev = PsiTreeUtil.prevLeaf(prev, false);
|
|
||||||
}
|
|
||||||
if (prev != null && prev.getNode().getElementType() == KtTokens.IDENTIFIER && word.equals(prev.getText())) {
|
if (prev != null && prev.getNode().getElementType() == KtTokens.IDENTIFIER && word.equals(prev.getText())) {
|
||||||
return prev;
|
return prev;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -448,8 +448,8 @@ fun canPlaceAfterSimpleNameEntry(element: PsiElement?): Boolean {
|
|||||||
return !BAD_NEIGHBOUR_FOR_SIMPLE_TEMPLATE_ENTRY_PATTERN.matches(entryText)
|
return !BAD_NEIGHBOUR_FOR_SIMPLE_TEMPLATE_ENTRY_PATTERN.matches(entryText)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun checkReservedPrefixWord(sink: DiagnosticSink, element: PsiElement, word: String, suffixTokens: TokenSet, message: String) {
|
fun checkReservedPrefixWord(sink: DiagnosticSink, element: PsiElement, word: String, message: String) {
|
||||||
KtPsiUtil.getPreviousWord(element, word, suffixTokens)?.let {
|
KtPsiUtil.getPreviousWord(element, word)?.let {
|
||||||
sink.report(Errors.UNSUPPORTED.on(it, message))
|
sink.report(Errors.UNSUPPORTED.on(it, message))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -458,4 +458,4 @@ fun KtElement.nonStaticOuterClasses(): Sequence<KtClass> {
|
|||||||
return generateSequence(containingClass()) { if (it.isInner()) it.containingClass() else null }
|
return generateSequence(containingClass()) { if (it.isInner()) it.containingClass() else null }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun KtElement.containingClass(): KtClass? = getStrictParentOfType<KtClass>()
|
fun KtElement.containingClass(): KtClass? = getStrictParentOfType<KtClass>()
|
||||||
|
|||||||
+1
-1
@@ -160,7 +160,7 @@ internal class FunctionsTypingVisitor(facade: ExpressionTypingInternals) : Expre
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun checkReservedAsync(context: ExpressionTypingContext, expression: PsiElement) {
|
private fun checkReservedAsync(context: ExpressionTypingContext, expression: PsiElement) {
|
||||||
checkReservedPrefixWord(context.trace, expression, "async", KtTokens.BINARY_OPERATIONS, "async block/lambda. Use 'async() { ... }' or 'async(fun...)'")
|
checkReservedPrefixWord(context.trace, expression, "async", "async block/lambda. Use 'async() { ... }' or 'async(fun...)'")
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createFunctionLiteralDescriptor(
|
private fun createFunctionLiteralDescriptor(
|
||||||
|
|||||||
@@ -20,26 +20,4 @@ fun test(foo: Any) {
|
|||||||
foo async (fun () {})
|
foo async (fun () {})
|
||||||
|
|
||||||
async (fun () {})
|
async (fun () {})
|
||||||
}
|
|
||||||
|
|
||||||
object async {
|
|
||||||
operator fun plus(f: () -> Unit) = f()
|
|
||||||
operator fun minus(f: () -> Unit) = f()
|
|
||||||
operator fun times(f: () -> Unit) = f()
|
|
||||||
operator fun div(f: () -> Unit) = f()
|
|
||||||
operator fun mod(f: () -> Unit) = f()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun test() {
|
|
||||||
<!UNSUPPORTED!>async<!>+ {}
|
|
||||||
<!UNSUPPORTED!>async<!>- {}
|
|
||||||
<!UNSUPPORTED!>async<!>* {}
|
|
||||||
<!UNSUPPORTED!>async<!>/ {}
|
|
||||||
<!UNSUPPORTED!>async<!>% {}
|
|
||||||
|
|
||||||
async + {}
|
|
||||||
async - {}
|
|
||||||
async * {}
|
|
||||||
async / {}
|
|
||||||
async % {}
|
|
||||||
}
|
}
|
||||||
@@ -1,18 +1,5 @@
|
|||||||
package
|
package
|
||||||
|
|
||||||
public fun async(/*0*/ f: () -> kotlin.Unit): kotlin.Unit
|
public fun async(/*0*/ f: () -> kotlin.Unit): kotlin.Unit
|
||||||
public fun test(): kotlin.Unit
|
|
||||||
public fun test(/*0*/ foo: kotlin.Any): kotlin.Unit
|
public fun test(/*0*/ foo: kotlin.Any): kotlin.Unit
|
||||||
public infix fun kotlin.Any.async(/*0*/ f: () -> kotlin.Unit): kotlin.Unit
|
public infix fun kotlin.Any.async(/*0*/ f: () -> kotlin.Unit): kotlin.Unit
|
||||||
|
|
||||||
public object async {
|
|
||||||
private constructor async()
|
|
||||||
public final operator fun div(/*0*/ f: () -> kotlin.Unit): kotlin.Unit
|
|
||||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
|
||||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
|
||||||
public final operator fun minus(/*0*/ f: () -> kotlin.Unit): kotlin.Unit
|
|
||||||
public final operator fun mod(/*0*/ f: () -> kotlin.Unit): kotlin.Unit
|
|
||||||
public final operator fun plus(/*0*/ f: () -> kotlin.Unit): kotlin.Unit
|
|
||||||
public final operator fun times(/*0*/ f: () -> kotlin.Unit): kotlin.Unit
|
|
||||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ import com.intellij.psi.PsiElement
|
|||||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||||
import org.jetbrains.kotlin.diagnostics.Errors
|
import org.jetbrains.kotlin.diagnostics.Errors
|
||||||
import org.jetbrains.kotlin.idea.codeInsight.surroundWith.expression.KotlinParenthesesSurrounder
|
import org.jetbrains.kotlin.idea.codeInsight.surroundWith.expression.KotlinParenthesesSurrounder
|
||||||
import org.jetbrains.kotlin.lexer.KtTokens
|
|
||||||
import org.jetbrains.kotlin.psi.KtBinaryExpression
|
import org.jetbrains.kotlin.psi.KtBinaryExpression
|
||||||
import org.jetbrains.kotlin.psi.KtCallExpression
|
import org.jetbrains.kotlin.psi.KtCallExpression
|
||||||
import org.jetbrains.kotlin.psi.KtFile
|
import org.jetbrains.kotlin.psi.KtFile
|
||||||
@@ -34,15 +33,8 @@ class UnsupportedAsyncFix(val psiElement: PsiElement): KotlinQuickFixAction<PsiE
|
|||||||
override fun getText(): String = familyName
|
override fun getText(): String = familyName
|
||||||
|
|
||||||
override fun invoke(project: Project, editor: Editor?, file: KtFile) {
|
override fun invoke(project: Project, editor: Editor?, file: KtFile) {
|
||||||
if (element is KtBinaryExpression) {
|
if (element is KtBinaryExpression && element.right != null) {
|
||||||
if (element.operationToken != KtTokens.IDENTIFIER) {
|
KotlinParenthesesSurrounder.surroundWithParentheses(element.right!!)
|
||||||
// async+ {}
|
|
||||||
element.addBefore(KtPsiFactory(element).createWhiteSpace(), element.operationReference)
|
|
||||||
}
|
|
||||||
else if (element.right != null) {
|
|
||||||
// foo async {}
|
|
||||||
KotlinParenthesesSurrounder.surroundWithParentheses(element.right!!)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (element is KtCallExpression) {
|
if (element is KtCallExpression) {
|
||||||
|
|||||||
@@ -77,9 +77,6 @@ fun infixTest() {
|
|||||||
|
|
||||||
fun async(f: () -> Unit) {}
|
fun async(f: () -> Unit) {}
|
||||||
infix fun Any.async(f: () -> Unit) {}
|
infix fun Any.async(f: () -> Unit) {}
|
||||||
object async {
|
|
||||||
operator fun times(f: () -> Unit) = f()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun test(foo: Any) {
|
fun test(foo: Any) {
|
||||||
async { }
|
async { }
|
||||||
@@ -95,7 +92,5 @@ fun test(foo: Any) {
|
|||||||
foo async (fun () {})
|
foo async (fun () {})
|
||||||
|
|
||||||
async (fun () {})
|
async (fun () {})
|
||||||
|
|
||||||
async* {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -76,9 +76,6 @@ fun infixTest() {
|
|||||||
|
|
||||||
fun async(f: () -> Unit) {}
|
fun async(f: () -> Unit) {}
|
||||||
infix fun Any.async(f: () -> Unit) {}
|
infix fun Any.async(f: () -> Unit) {}
|
||||||
object async {
|
|
||||||
operator fun times(f: () -> Unit) = f()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun test(foo: Any) {
|
fun test(foo: Any) {
|
||||||
async() { }
|
async() { }
|
||||||
@@ -94,7 +91,5 @@ fun test(foo: Any) {
|
|||||||
foo async (fun () {})
|
foo async (fun () {})
|
||||||
|
|
||||||
async (fun () {})
|
async (fun () {})
|
||||||
|
|
||||||
async * {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
// "Migrate unsupported async syntax" "true"
|
|
||||||
object async {
|
|
||||||
operator fun times(f: () -> Unit) = f()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun test() {
|
|
||||||
asy<caret>nc* { }
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
// "Migrate unsupported async syntax" "true"
|
|
||||||
object async {
|
|
||||||
operator fun times(f: () -> Unit) = f()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun test() {
|
|
||||||
asy<caret>nc * { }
|
|
||||||
}
|
|
||||||
@@ -615,12 +615,6 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
|||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/asyncUnsupported/asyncWithLambdaAndComment.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/asyncUnsupported/asyncWithLambdaAndComment.kt");
|
||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("asyncWithTimes.kt")
|
|
||||||
public void testAsyncWithTimes() throws Exception {
|
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/asyncUnsupported/asyncWithTimes.kt");
|
|
||||||
doTest(fileName);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("idea/testData/quickfix/autoImports")
|
@TestMetadata("idea/testData/quickfix/autoImports")
|
||||||
|
|||||||
Reference in New Issue
Block a user