diff --git a/RegExpSupport/src/org/intellij/lang/regexp/inspection/custom/CustomRegExpFakeInspection.java b/RegExpSupport/src/org/intellij/lang/regexp/inspection/custom/CustomRegExpFakeInspection.java index 433644567dd3..deed1cb35983 100644 --- a/RegExpSupport/src/org/intellij/lang/regexp/inspection/custom/CustomRegExpFakeInspection.java +++ b/RegExpSupport/src/org/intellij/lang/regexp/inspection/custom/CustomRegExpFakeInspection.java @@ -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 list, @NotNull AnActionButton b) { @@ -194,8 +194,8 @@ public class CustomRegExpFakeInspection extends LocalInspectionTool { private void performRemove(JList list) { final List 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 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 patterns = myConfiguration.getPatterns(); - final InspectionPattern one = patterns.get(first); - final InspectionPattern two = patterns.get(second); - patterns.set(second, one); - patterns.set(first, two); - } } } diff --git a/RegExpSupport/src/org/intellij/lang/regexp/inspection/custom/CustomRegExpInspection.java b/RegExpSupport/src/org/intellij/lang/regexp/inspection/custom/CustomRegExpInspection.java index b84036a6e12d..260a2390a193 100644 --- a/RegExpSupport/src/org/intellij/lang/regexp/inspection/custom/CustomRegExpInspection.java +++ b/RegExpSupport/src/org/intellij/lang/regexp/inspection/custom/CustomRegExpInspection.java @@ -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) { diff --git a/RegExpSupport/src/org/intellij/lang/regexp/inspection/custom/MetaDataDialog.java b/RegExpSupport/src/org/intellij/lang/regexp/inspection/custom/MetaDataDialog.java index 5444c350da41..5d7310df5683 100644 --- a/RegExpSupport/src/org/intellij/lang/regexp/inspection/custom/MetaDataDialog.java +++ b/RegExpSupport/src/org/intellij/lang/regexp/inspection/custom/MetaDataDialog.java @@ -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()); } } diff --git a/RegExpSupport/src/org/intellij/lang/regexp/inspection/custom/RegExpInspectionConfiguration.java b/RegExpSupport/src/org/intellij/lang/regexp/inspection/custom/RegExpInspectionConfiguration.java index dd637b6fffbf..733ded0f404e 100644 --- a/RegExpSupport/src/org/intellij/lang/regexp/inspection/custom/RegExpInspectionConfiguration.java +++ b/RegExpSupport/src/org/intellij/lang/regexp/inspection/custom/RegExpInspectionConfiguration.java @@ -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 { - public List patterns; - public @NotNull String name; - public String description; - public String uuid; - public String suppressId; - public String problemDescriptor; + public List 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