mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fix StringTokenizerDelimiterInspection (it did not escape double-quote, EA-89721)
This commit is contained in:
+5
-2
@@ -92,6 +92,7 @@ public class StringTokenizerDelimiterInspection extends BaseJavaBatchLocalInspec
|
||||
@NotNull
|
||||
@Override
|
||||
public String getFamilyName() {
|
||||
//noinspection DialogTitleCapitalization
|
||||
return "Replace StringTokenizer delimiters parameter with unique symbols";
|
||||
}
|
||||
|
||||
@@ -99,13 +100,15 @@ public class StringTokenizerDelimiterInspection extends BaseJavaBatchLocalInspec
|
||||
public void invoke(@NotNull Project project, @NotNull PsiFile file, @NotNull PsiElement startElement, @NotNull PsiElement endElement) {
|
||||
final Set<Character> uniqueChars = new LinkedHashSet<>();
|
||||
final PsiLiteralExpression delimiterArgument = (PsiLiteralExpression)startElement;
|
||||
for (char c : ((String)delimiterArgument.getValue()).toCharArray()) {
|
||||
final Object literal = delimiterArgument.getValue();
|
||||
if(!(literal instanceof String)) return;
|
||||
for (char c : ((String)literal).toCharArray()) {
|
||||
uniqueChars.add(c);
|
||||
}
|
||||
final String newDelimiters = StringUtil.join(uniqueChars, "");
|
||||
final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(project);
|
||||
if (!FileModificationService.getInstance().prepareFileForWrite(file)) return;
|
||||
delimiterArgument.replace(elementFactory.createExpressionFromText(StringUtil.wrapWithDoubleQuote(StringUtil.escaper(true, null).fun(
|
||||
delimiterArgument.replace(elementFactory.createExpressionFromText(StringUtil.wrapWithDoubleQuote(StringUtil.escaper(true, "\"").fun(
|
||||
newDelimiters)), null));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ class A {
|
||||
|
||||
void m() {
|
||||
|
||||
new StringTokenizer("asd", "\\\t\nqwerty")
|
||||
new StringTokenizer("asd", "\"\\\t\nqwerty'")
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ class A {
|
||||
|
||||
void m() {
|
||||
|
||||
new StringTokenizer("asd", "\\\t\t\n<caret>\nqwerty")
|
||||
new StringTokenizer("asd", "\"\\\t\t\n<caret>\nqwerty''\"")
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user