mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Java: improve inspection messages and fix replacement with tab character
in "Unnecessary Unicode escape sequence" inspection GitOrigin-RevId: 53cd08d56aba3aa23ab4580ebbaf0c3807a7047b
This commit is contained in:
committed by
intellij-monorepo-bot
parent
fdb548f245
commit
e24bcbd00c
@@ -1955,7 +1955,7 @@ boolean.parameters.problem.descriptor='public' method <code>#ref()</code> with '
|
||||
boolean.parameter.constructor.problem.descriptor='public' constructor <code>#ref()</code> with 'boolean' parameter #loc
|
||||
boolean.parameters.constructor.problem.descriptor='public' constructor <code>#ref()</code> with 'boolean' parameters #loc
|
||||
boolean.parameter.only.report.multiple.option=Only report methods with multiple boolean parameters
|
||||
unnecessary.unicode.escape.display.name=Unnecessary unicode escape sequence
|
||||
unnecessary.unicode.escape.display.name=Unnecessary Unicode escape sequence
|
||||
unnecessary.unicode.escape.problem.descriptor=Unicode escape sequence <code>#ref</code> can be replaced with ''{0}'' #loc
|
||||
unnecessary.unicode.escape.problem.newline.descriptor=Unicode escape sequence <code>#ref</code> can be replaced with a line feed character #loc
|
||||
missing.package.info.display.name=Missing 'package-info.java'
|
||||
@@ -2397,7 +2397,7 @@ swap.equals.fix.family.name=Flip method call
|
||||
remove.modifier.fix.family.name=Remove modifier
|
||||
shift.out.of.range.fix.family.name=Fix shift value
|
||||
unnecessary.unicode.escape.fix.family.name=Replace with character
|
||||
unnecessary.unicode.escape.fix.text=Replace with line feed character
|
||||
unnecessary.unicode.escape.fix.text=Replace with {0, choice, 1#new line|2#tab|3#space} character
|
||||
absolute.alignment.in.user.interface.fix.family.name=Replace with constant
|
||||
static.inheritance.fix.family.name=Replace inheritance with qualified reference
|
||||
suspicious.to.array.call.fix.family.name=Replace with proper array
|
||||
|
||||
+10
-6
@@ -16,6 +16,8 @@ import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.impl.source.tree.ElementType;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
@@ -64,10 +66,12 @@ public final class UnnecessaryUnicodeEscapeInspection extends BaseInspection {
|
||||
|
||||
@Override
|
||||
public @NotNull String getName() {
|
||||
if (c == '\n') {
|
||||
return InspectionGadgetsBundle.message("unnecessary.unicode.escape.fix.text");
|
||||
}
|
||||
return CommonQuickFixBundle.message("fix.replace.with.x", (c == '\t') ? "\\t" : c);
|
||||
return switch (c) {
|
||||
case '\n' -> InspectionGadgetsBundle.message("unnecessary.unicode.escape.fix.text", 1);
|
||||
case '\t' -> InspectionGadgetsBundle.message("unnecessary.unicode.escape.fix.text", 2);
|
||||
case ' ' -> InspectionGadgetsBundle.message("unnecessary.unicode.escape.fix.text", 3);
|
||||
default -> CommonQuickFixBundle.message("fix.replace.with.x", c);
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -78,7 +82,7 @@ public final class UnnecessaryUnicodeEscapeInspection extends BaseInspection {
|
||||
@Override
|
||||
protected void applyFix(@NotNull Project project, @NotNull PsiElement startElement, @NotNull ModPsiUpdater updater) {
|
||||
Document document = startElement.getContainingFile().getFileDocument();
|
||||
String replacement = c == '\t' ? "\\t" : String.valueOf(c);
|
||||
String replacement = c == '\t' && PsiUtil.isJavaToken(startElement, ElementType.STRING_LITERALS) ? "\\t" : String.valueOf(c);
|
||||
document.replaceString(myRangeMarker.getStartOffset(), myRangeMarker.getEndOffset(), replacement);
|
||||
}
|
||||
}
|
||||
@@ -126,7 +130,7 @@ public final class UnnecessaryUnicodeEscapeInspection extends BaseInspection {
|
||||
final int escapeEnd = nextChar + 4;
|
||||
final char d = (char)Integer.parseInt(text.substring(nextChar, escapeEnd), 16);
|
||||
if (d == '\uFFFD' || (d == '\\' && detectUnicodeEscape(text, escapeEnd - 1, length) != -1)) {
|
||||
// this character is used as a replacement when a unicode character can't be displayed
|
||||
// this character is used as a replacement when a Unicode character can't be displayed
|
||||
// replacing the escape with the character may cause confusion, so ignore it.
|
||||
// skip if another escape sequence follows '\' without being properly escaped.
|
||||
continue;
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
// "Fix all 'Unnecessary unicode escape sequence' problems in file" "true"
|
||||
// "Fix all 'Unnecessary Unicode escape sequence' problems in file" "true"
|
||||
class X {
|
||||
void test() {
|
||||
void test() {
|
||||
String s = "abcd";
|
||||
String t = """
|
||||
\t
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
// "Fix all 'Unnecessary unicode escape sequence' problems in file" "true"
|
||||
// "Fix all 'Unnecessary Unicode escape sequence' problems in file" "true"
|
||||
class X {
|
||||
void test() {
|
||||
\u0009void test() {
|
||||
String s = "\u<caret>0061\u0062\u0063\u0064";
|
||||
String t = """
|
||||
\u0009\u000A""";
|
||||
|
||||
Reference in New Issue
Block a user