Editing of Custom RegExp inspection should happen on a copy (IDEA-318426)

so that changes are not applied when cancelled

GitOrigin-RevId: b1b975edc24c5f452adb58b6ab1cff2b50ac5ed3
This commit is contained in:
Bas Leijdekkers
2023-04-19 23:58:00 +02:00
committed by intellij-monorepo-bot
parent 90eba4d6d2
commit 6352170061
3 changed files with 29 additions and 11 deletions

View File

@@ -246,12 +246,9 @@ public class CustomRegExpFakeInspection extends LocalInspectionTool {
saveChangesToProfile(list);
}
private void saveChangesToProfile(JList<InspectionPattern> list) {
private static void saveChangesToProfile(JList<InspectionPattern> list) {
final InspectionProfileModifiableModel profile = getInspectionProfile(list);
if (profile == null) return;
final CustomRegExpInspection inspection = getRegExpInspection(profile);
inspection.updateConfiguration(myConfiguration);
profile.setModified(true);
if (profile != null) profile.setModified(true);
}
@NotNull

View File

@@ -27,7 +27,7 @@ public class CustomRegExpInspectionToolWrapper extends LocalInspectionToolWrappe
@Override
public LocalInspectionToolWrapper createCopy() {
final CustomRegExpFakeInspection inspection = (CustomRegExpFakeInspection)getTool();
RegExpInspectionConfiguration configuration = inspection.getConfiguration();
RegExpInspectionConfiguration configuration = inspection.getConfiguration().copy();
return new CustomRegExpInspectionToolWrapper(configuration);
}

View File

@@ -38,8 +38,11 @@ public class RegExpInspectionConfiguration implements Comparable<RegExpInspectio
patterns = new SmartList<>();
}
public RegExpInspectionConfiguration(RegExpInspectionConfiguration other) {
patterns = new SmartList<>(other.patterns);
private RegExpInspectionConfiguration(RegExpInspectionConfiguration other) {
patterns = new SmartList<>();
for (InspectionPattern pattern : other.patterns) {
patterns.add(pattern.copy());
}
name = other.name;
description = other.description;
uuid = other.uuid;
@@ -180,7 +183,21 @@ public class RegExpInspectionConfiguration implements Comparable<RegExpInspectio
public InspectionPattern() {
}
public @NlsSafe String regExp() { return regExp; }
InspectionPattern(InspectionPattern copy) {
regExp = copy.regExp;
fileType = copy.fileType;
_fileType = copy._fileType;
searchContext = copy.searchContext;
replacement = copy.replacement;
}
public InspectionPattern copy() {
return new InspectionPattern(this);
}
public @NlsSafe String regExp() {
return regExp;
}
public @Nullable FileType fileType() {
if (fileType == null && _fileType != null) {
@@ -192,9 +209,13 @@ public class RegExpInspectionConfiguration implements Comparable<RegExpInspectio
return fileType;
}
public FindModel.SearchContext searchContext() { return searchContext; }
public FindModel.SearchContext searchContext() {
return searchContext;
}
public @NlsSafe @Nullable String replacement() { return replacement; }
public @NlsSafe @Nullable String replacement() {
return replacement;
}
@Override
public boolean equals(Object obj) {