mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
potential memory leak via psi element in quick fix
EA-60171
This commit is contained in:
@@ -23,8 +23,7 @@
|
||||
package com.intellij.xml.util;
|
||||
|
||||
import com.intellij.codeInsight.FileModificationService;
|
||||
import com.intellij.codeInspection.LocalQuickFix;
|
||||
import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.codeInspection.LocalQuickFixOnPsiElement;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.fileEditor.FileEditorManager;
|
||||
import com.intellij.openapi.fileEditor.OpenFileDescriptor;
|
||||
@@ -39,39 +38,33 @@ import org.jetbrains.annotations.NotNull;
|
||||
* @author Maxim Mossienko
|
||||
*/
|
||||
public class CheckValidXmlInScriptBodyInspection extends CheckValidXmlInScriptBodyInspectionBase {
|
||||
|
||||
@Override
|
||||
protected InsertQuotedCharacterQuickFix createFix(PsiFile psiFile,
|
||||
PsiElement psiElement,
|
||||
protected InsertQuotedCharacterQuickFix createFix(PsiElement psiElement,
|
||||
int offsetInElement) {
|
||||
return new InsertQuotedCharacterQuickFix(
|
||||
psiFile,
|
||||
psiElement,
|
||||
offsetInElement
|
||||
);
|
||||
}
|
||||
|
||||
private static class InsertQuotedCharacterQuickFix implements LocalQuickFix {
|
||||
private final PsiFile psiFile;
|
||||
private final PsiElement psiElement;
|
||||
private static class InsertQuotedCharacterQuickFix extends LocalQuickFixOnPsiElement {
|
||||
private final int startInElement;
|
||||
|
||||
public InsertQuotedCharacterQuickFix(PsiFile psiFile, PsiElement psiElement, int startInElement) {
|
||||
this.psiFile = psiFile;
|
||||
this.psiElement = psiElement;
|
||||
public InsertQuotedCharacterQuickFix(PsiElement psiElement, int startInElement) {
|
||||
super(psiElement);
|
||||
this.startInElement = startInElement;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getName() {
|
||||
public String getText() {
|
||||
final String character = getXmlCharacter();
|
||||
|
||||
return XmlBundle.message(
|
||||
"unescaped.xml.character.fix.message",
|
||||
character.equals("&") ?
|
||||
XmlBundle.message("unescaped.xml.character.fix.message.parameter"):
|
||||
character
|
||||
XmlBundle.message("unescaped.xml.character.fix.message.parameter") :
|
||||
character
|
||||
);
|
||||
}
|
||||
|
||||
@@ -82,9 +75,10 @@ public class CheckValidXmlInScriptBodyInspection extends CheckValidXmlInScriptBo
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor problemDescriptor) {
|
||||
public void invoke(@NotNull Project project, @NotNull PsiFile file, @NotNull PsiElement startElement, @NotNull PsiElement endElement) {
|
||||
final PsiFile psiFile = startElement.getContainingFile();
|
||||
if (!FileModificationService.getInstance().prepareFileForWrite(psiFile)) return;
|
||||
final TextRange range = psiElement.getTextRange();
|
||||
final TextRange range = startElement.getTextRange();
|
||||
OpenFileDescriptor descriptor = new OpenFileDescriptor(
|
||||
project,
|
||||
psiFile.getVirtualFile(),
|
||||
@@ -96,7 +90,7 @@ public class CheckValidXmlInScriptBodyInspection extends CheckValidXmlInScriptBo
|
||||
|
||||
final String xmlCharacter = getXmlCharacter();
|
||||
String replacement = xmlCharacter.equals("&") ? AMP_ENTITY_REFERENCE : LT_ENTITY_REFERENCE;
|
||||
replacement = psiElement.getText().replace(xmlCharacter,replacement);
|
||||
replacement = startElement.getText().replace(xmlCharacter,replacement);
|
||||
|
||||
editor.getDocument().replaceString(
|
||||
range.getStartOffset(),
|
||||
@@ -106,7 +100,7 @@ public class CheckValidXmlInScriptBodyInspection extends CheckValidXmlInScriptBo
|
||||
}
|
||||
|
||||
private String getXmlCharacter() {
|
||||
return psiElement.getText().substring(startInElement, startInElement + 1);
|
||||
return getStartElement().getText().substring(startInElement, startInElement + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -93,7 +93,7 @@ public class CheckValidXmlInScriptBodyInspectionBase extends XmlSuppressableInsp
|
||||
psiElement,
|
||||
XmlBundle.message("unescaped.xml.character"),
|
||||
ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
|
||||
createFix(psiFile, psiElement, offsetInElement)
|
||||
createFix(psiElement, offsetInElement)
|
||||
);
|
||||
|
||||
int endOfElementInScriptTag = elementRange.getEndOffset() - valueStart;
|
||||
@@ -112,7 +112,7 @@ public class CheckValidXmlInScriptBodyInspectionBase extends XmlSuppressableInsp
|
||||
};
|
||||
}
|
||||
|
||||
protected LocalQuickFix createFix(PsiFile psiFile, PsiElement psiElement, int offsetInElement) {
|
||||
protected LocalQuickFix createFix(PsiElement psiElement, int offsetInElement) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user