mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-14 18:05:27 +07:00
RegExp: more reliable and safe serialization of inspections
GitOrigin-RevId: e3abe8b57986b72747f34e5cb31fae7227cece40
This commit is contained in:
committed by
intellij-monorepo-bot
parent
6eb6d14019
commit
7aa80aa0f3
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package org.intellij.lang.regexp.inspection.custom;
|
||||
|
||||
import com.intellij.codeInsight.daemon.HighlightDisplayKey;
|
||||
@@ -181,7 +181,7 @@ public class CustomRegExpFakeInspection extends LocalInspectionTool {
|
||||
Collections.swap(patterns, index, newIndex);
|
||||
model.fireContentsChanged(list);
|
||||
list.setSelectedIndex(newIndex);
|
||||
//saveChangesToProfile(list);
|
||||
saveChangesToProfile(list);
|
||||
}
|
||||
|
||||
private void performAdd(JList<InspectionPattern> list, @NotNull AnActionButton b) {
|
||||
@@ -194,8 +194,8 @@ public class CustomRegExpFakeInspection extends LocalInspectionTool {
|
||||
|
||||
private void performRemove(JList<InspectionPattern> list) {
|
||||
final List<InspectionPattern> patterns = myConfiguration.getPatterns();
|
||||
for (InspectionPattern configuration : list.getSelectedValuesList()) {
|
||||
patterns.remove(configuration);
|
||||
for (InspectionPattern pattern : list.getSelectedValuesList()) {
|
||||
myConfiguration.removePattern(pattern);
|
||||
}
|
||||
final int size = patterns.size();
|
||||
final int maxIndex = list.getMaxSelectionIndex();
|
||||
@@ -278,9 +278,8 @@ public class CustomRegExpFakeInspection extends LocalInspectionTool {
|
||||
final RegExpDialog dialog = new RegExpDialog(project, true, defaultPattern);
|
||||
if (!dialog.showAndGet()) return;
|
||||
|
||||
final InspectionPattern configuration = dialog.getPattern();
|
||||
final List<InspectionPattern> patterns = myConfiguration.getPatterns();
|
||||
patterns.add(configuration);
|
||||
final InspectionPattern pattern = dialog.getPattern();
|
||||
myConfiguration.addPattern(pattern);
|
||||
((MyListModel)myList.getModel()).fireContentsChanged(myList);
|
||||
saveChangesToProfile(myList);
|
||||
}
|
||||
@@ -300,14 +299,5 @@ public class CustomRegExpFakeInspection extends LocalInspectionTool {
|
||||
public void fireContentsChanged(Object source) {
|
||||
fireContentsChanged(source, -1, -1);
|
||||
}
|
||||
|
||||
public void swap(int first, int second) {
|
||||
if (second == -1) return;
|
||||
final List<InspectionPattern> patterns = myConfiguration.getPatterns();
|
||||
final InspectionPattern one = patterns.get(first);
|
||||
final InspectionPattern two = patterns.get(second);
|
||||
patterns.set(second, one);
|
||||
patterns.set(first, two);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,7 +187,9 @@ public class CustomRegExpInspection extends LocalInspectionTool implements Dynam
|
||||
}
|
||||
|
||||
public void addConfiguration(RegExpInspectionConfiguration configuration) {
|
||||
myConfigurations.add(configuration);
|
||||
if (!myConfigurations.contains(configuration)) {
|
||||
myConfigurations.add(configuration);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateConfiguration(RegExpInspectionConfiguration configuration) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package org.intellij.lang.regexp.inspection.custom;
|
||||
|
||||
import com.intellij.codeInsight.daemon.HighlightDisplayKey;
|
||||
@@ -109,10 +109,10 @@ public class MetaDataDialog extends DialogWrapper {
|
||||
protected void doOKAction() {
|
||||
super.doOKAction();
|
||||
if (getOKAction().isEnabled()) {
|
||||
myConfiguration.name = getName();
|
||||
myConfiguration.description = getDescription();
|
||||
myConfiguration.suppressId = getSuppressId();
|
||||
myConfiguration.problemDescriptor = getProblemDescriptor();
|
||||
myConfiguration.setName(getName());
|
||||
myConfiguration.setDescription(getDescription());
|
||||
myConfiguration.setSuppressId(getSuppressId());
|
||||
myConfiguration.setProblemDescriptor(getProblemDescriptor());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package org.intellij.lang.regexp.inspection.custom;
|
||||
|
||||
import com.intellij.find.FindModel;
|
||||
@@ -20,21 +20,22 @@ import java.util.UUID;
|
||||
*/
|
||||
public class RegExpInspectionConfiguration implements Comparable<RegExpInspectionConfiguration> {
|
||||
|
||||
public List<InspectionPattern> patterns;
|
||||
public @NotNull String name;
|
||||
public String description;
|
||||
public String uuid;
|
||||
public String suppressId;
|
||||
public String problemDescriptor;
|
||||
public List<InspectionPattern> patterns; // keep public for settings serialization
|
||||
private String name;
|
||||
private String description;
|
||||
private String uuid;
|
||||
private String suppressId;
|
||||
private String problemDescriptor;
|
||||
|
||||
public RegExpInspectionConfiguration(@NotNull String name) {
|
||||
this.name = name;
|
||||
uuid = UUID.nameUUIDFromBytes(name.getBytes(StandardCharsets.UTF_8)).toString();
|
||||
patterns = new SmartList<>();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public RegExpInspectionConfiguration() {}
|
||||
public RegExpInspectionConfiguration() {
|
||||
patterns = new SmartList<>();
|
||||
}
|
||||
|
||||
public RegExpInspectionConfiguration(RegExpInspectionConfiguration other) {
|
||||
patterns = new SmartList<>(other.patterns);
|
||||
@@ -51,12 +52,12 @@ public class RegExpInspectionConfiguration implements Comparable<RegExpInspectio
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
RegExpInspectionConfiguration that = (RegExpInspectionConfiguration)o;
|
||||
return uuid.equals(that.uuid);
|
||||
return Objects.equals(uuid, that.uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getUuid().hashCode();
|
||||
return name.hashCode();
|
||||
}
|
||||
|
||||
public RegExpInspectionConfiguration copy() {
|
||||
@@ -67,30 +68,78 @@ public class RegExpInspectionConfiguration implements Comparable<RegExpInspectio
|
||||
return patterns;
|
||||
}
|
||||
|
||||
public @NlsSafe @NotNull String getName() {
|
||||
public void addPattern(InspectionPattern pattern) {
|
||||
if (!patterns.contains(pattern)) {
|
||||
patterns.add(pattern);
|
||||
}
|
||||
}
|
||||
|
||||
public void removePattern(InspectionPattern pattern) {
|
||||
patterns.remove(pattern);
|
||||
}
|
||||
|
||||
public @NlsSafe String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(@NotNull String name) {
|
||||
if (uuid == null && this.name != null) { // name can be null on deserializing from settings
|
||||
uuid = UUID.nameUUIDFromBytes(this.name.getBytes(StandardCharsets.UTF_8)).toString();
|
||||
}
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public @NlsSafe String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getUuid() {
|
||||
if (uuid == null && name != null) { // name can be null on deserializing from settings
|
||||
uuid = UUID.nameUUIDFromBytes(this.name.getBytes(StandardCharsets.UTF_8)).toString();
|
||||
}
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public void setUuid(@Nullable String uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public @NlsSafe String getSuppressId() {
|
||||
return suppressId;
|
||||
}
|
||||
|
||||
public void setSuppressId(String suppressId) {
|
||||
this.suppressId = suppressId;
|
||||
}
|
||||
|
||||
public @NlsSafe String getProblemDescriptor() {
|
||||
return problemDescriptor;
|
||||
}
|
||||
|
||||
public void setProblemDescriptor(String problemDescriptor) {
|
||||
this.problemDescriptor = problemDescriptor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(@NotNull RegExpInspectionConfiguration o) {
|
||||
int result = name.compareToIgnoreCase(o.name);
|
||||
if (result == 0) result = uuid.compareTo(o.uuid);
|
||||
if (result == 0) {
|
||||
if (uuid == null) {
|
||||
if (o.uuid != null) {
|
||||
result = -1;
|
||||
}
|
||||
}
|
||||
else if (o.uuid == null) {
|
||||
result = 1;
|
||||
}
|
||||
else {
|
||||
result = uuid.compareTo(o.uuid);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -142,12 +142,13 @@ public class StructuralSearchProfileActionProvider extends InspectionProfileActi
|
||||
final InspectionProfileModifiableModel profile = myPanel.getProfile();
|
||||
final CustomRegExpInspection inspection = InspectionProfileUtil.getCustomRegExpInspection(profile);
|
||||
final RegExpInspectionConfiguration configuration = new RegExpInspectionConfiguration("new inspection");
|
||||
configuration.patterns.add(pattern);
|
||||
configuration.addPattern(pattern);
|
||||
final Project project = e.getData(CommonDataKeys.PROJECT);
|
||||
if (project == null) return;
|
||||
final MetaDataDialog metaDataDialog = new MetaDataDialog(project, inspection, configuration, true);
|
||||
if (!metaDataDialog.showAndGet()) return;
|
||||
|
||||
configuration.setUuid(null);
|
||||
inspection.addConfiguration(configuration);
|
||||
CustomRegExpInspection.addInspectionToProfile(project, profile, configuration);
|
||||
profile.setModified(true);
|
||||
|
||||
Reference in New Issue
Block a user