mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Java: "insert ';'" quick fix for local variables and fields (IDEA-330590)
and skip JavaErrorQuickFixProvider for non-Java elements GitOrigin-RevId: 2fb2b6321c1a087d53bf52509f1513859ac4faf8
This commit is contained in:
committed by
intellij-monorepo-bot
parent
f521fc113b
commit
04ee289bc9
+2
-2
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.codeInsight.daemon.impl.analysis;
|
||||
|
||||
import com.intellij.codeInsight.daemon.QuickFixBundle;
|
||||
@@ -415,7 +415,7 @@ public final class HighlightFixUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static void registerFixesForExpressionStatement(@NotNull PsiStatement statement, @NotNull List<? super IntentionAction> registrar) {
|
||||
public static void registerFixesForExpressionStatement(@NotNull PsiElement statement, @NotNull List<? super IntentionAction> registrar) {
|
||||
if (!(statement instanceof PsiExpressionStatement)) return;
|
||||
PsiCodeBlock block = ObjectUtils.tryCast(statement.getParent(), PsiCodeBlock.class);
|
||||
if (block == null) return;
|
||||
|
||||
+5
-4
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.codeInsight.daemon.impl.analysis;
|
||||
|
||||
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
|
||||
@@ -8,8 +8,8 @@ import com.intellij.codeInsight.daemon.impl.quickfix.InsertMissingTokenFix;
|
||||
import com.intellij.codeInsight.daemon.impl.quickfix.QuickFixAction;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.codeInsight.intention.QuickFixFactory;
|
||||
import com.intellij.codeInspection.ConvertRecordToClassFix;
|
||||
import com.intellij.core.JavaPsiBundle;
|
||||
import com.intellij.lang.java.JavaLanguage;
|
||||
import com.intellij.psi.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -19,12 +19,13 @@ import java.util.List;
|
||||
public final class JavaErrorQuickFixProvider implements ErrorQuickFixProvider {
|
||||
@Override
|
||||
public void registerErrorQuickFix(@NotNull PsiErrorElement errorElement, @NotNull HighlightInfo.Builder info) {
|
||||
if (!(errorElement.getLanguage() instanceof JavaLanguage)) return;
|
||||
PsiElement parent = errorElement.getParent();
|
||||
String description = errorElement.getErrorDescription();
|
||||
List<IntentionAction> registrar = new ArrayList<>();
|
||||
if (parent instanceof PsiStatement && description.equals(JavaPsiBundle.message("expected.semicolon"))) {
|
||||
if (description.equals(JavaPsiBundle.message("expected.semicolon"))) {
|
||||
info.registerFix(new InsertMissingTokenFix(";"), null, null, null, null);
|
||||
HighlightFixUtil.registerFixesForExpressionStatement((PsiStatement)parent, registrar);
|
||||
HighlightFixUtil.registerFixesForExpressionStatement(parent, registrar);
|
||||
}
|
||||
if (parent instanceof PsiTryStatement && description.equals(JavaPsiBundle.message("expected.catch.or.finally"))) {
|
||||
registrar.add(new AddExceptionToCatchFix(false).asIntention());
|
||||
|
||||
+3
-3
@@ -1,8 +1,8 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.codeInsight.daemon.impl.quickfix;
|
||||
|
||||
import com.intellij.codeInsight.intention.PriorityAction;
|
||||
import com.intellij.ide.IdeBundle;
|
||||
import com.intellij.codeInspection.CommonQuickFixBundle;
|
||||
import com.intellij.modcommand.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -25,7 +25,7 @@ public class InsertMissingTokenFix implements ModCommandAction {
|
||||
|
||||
@Override
|
||||
public @NotNull String getFamilyName() {
|
||||
return IdeBundle.message("quickfix.text.insert.0", myToken);
|
||||
return CommonQuickFixBundle.message("fix.insert.x", myToken);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Apply all 'Insert ';'' fixes in file" "true"
|
||||
class X {
|
||||
String one = "1";
|
||||
String two;
|
||||
void test() {
|
||||
String s;
|
||||
String t = "t";
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Apply all 'Insert ;' fixes in file" "true"
|
||||
// "Apply all 'Insert ';'' fixes in file" "true"
|
||||
class X {
|
||||
void test() {
|
||||
System.out.println("Hello");
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Insert ;" "true-preview"
|
||||
// "Insert ';'" "true-preview"
|
||||
class X {
|
||||
void test() {
|
||||
System.out.println("Hello");
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Apply all 'Insert ';'' fixes in file" "true"
|
||||
class X {
|
||||
String one = "1"
|
||||
String two
|
||||
void test() {
|
||||
String s<caret>
|
||||
String t = "t";
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Apply all 'Insert ;' fixes in file" "true"
|
||||
// "Apply all 'Insert ';'' fixes in file" "true"
|
||||
class X {
|
||||
void test() {
|
||||
System.out.println("Hello")<caret>
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Insert ;" "true-preview"
|
||||
// "Insert ';'" "true-preview"
|
||||
class X {
|
||||
void test() {
|
||||
System.out.println("Hello")<caret>
|
||||
|
||||
Reference in New Issue
Block a user