From 8ebbce4ab926bcc72fef7ed0620f344b859ada46 Mon Sep 17 00:00:00 2001 From: "Svetlana.Zemlyanskay" Date: Thu, 11 Sep 2014 12:20:05 +0400 Subject: [PATCH] IDEA-95372 Arrangement: Provide visual indication for duplicate rules --- .../ArrangementMatchingRulesControl.java | 53 +++++++++++++------ .../src/messages/ApplicationBundle.properties | 1 + 2 files changed, 39 insertions(+), 15 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/application/options/codeStyle/arrangement/match/ArrangementMatchingRulesControl.java b/platform/lang-impl/src/com/intellij/application/options/codeStyle/arrangement/match/ArrangementMatchingRulesControl.java index 145ae1094e0b..08ba7df1c637 100644 --- a/platform/lang-impl/src/com/intellij/application/options/codeStyle/arrangement/match/ArrangementMatchingRulesControl.java +++ b/platform/lang-impl/src/com/intellij/application/options/codeStyle/arrangement/match/ArrangementMatchingRulesControl.java @@ -527,35 +527,58 @@ public class ArrangementMatchingRulesControl extends JBTable { private class MyValidator { @Nullable private String validate(int index) { - if (mySectionRuleManager == null || getModel().getSize() < index) { + if (getModel().getSize() < index) { return null; } + if (mySectionRuleManager != null) { + final ArrangementSectionRuleData data = extractSectionText(index); + if (data != null) { + return validateSectionRule(data, index); + } + } + + final Object target = getModel().getElementAt(index); + if (target instanceof StdArrangementMatchRule) { + final Set rules = ContainerUtil.newHashSet(); + for (int i = 0; i < index; i++) { + final Object element = getModel().getElementAt(i); + if (element instanceof StdArrangementMatchRule) { + final StdArrangementMatchRule rule = (StdArrangementMatchRule)element; + rules.add(rule.toString()); + } + } + + if (rules.contains(target.toString())) { + return ApplicationBundle.message("arrangement.settings.validation.duplicate.matching.rule"); + } + } + return null; + } + + @Nullable + private String validateSectionRule(@NotNull ArrangementSectionRuleData data, int index) { int startSectionIndex = -1; - final Set rules = ContainerUtil.newHashSet(); + final Set sectionRules = ContainerUtil.newHashSet(); for (int i = 0; i < index; i++) { final ArrangementSectionRuleData section = extractSectionText(i); if (section != null) { startSectionIndex = section.isSectionStart() ? i : -1; if (StringUtil.isNotEmpty(section.getText())) { - rules.add(section.getText()); + sectionRules.add(section.getText()); } } } + if (StringUtil.isNotEmpty(data.getText()) && sectionRules.contains(data.getText())) { + return ApplicationBundle.message("arrangement.settings.validation.duplicate.section.text"); + } - final ArrangementSectionRuleData data = extractSectionText(index); - if (data != null) { - if (StringUtil.isNotEmpty(data.getText()) && rules.contains(data.getText())) { - return ApplicationBundle.message("arrangement.settings.validation.duplicate.section.text"); + if (!data.isSectionStart()) { + if (startSectionIndex == -1) { + return ApplicationBundle.message("arrangement.settings.validation.end.section.rule.without.start"); } - - if (!data.isSectionStart()) { - if (startSectionIndex == -1) { - return ApplicationBundle.message("arrangement.settings.validation.end.section.rule.without.start"); - } - else if (startSectionIndex == index - 1) { - return ApplicationBundle.message("arrangement.settings.validation.empty.section.rule"); - } + else if (startSectionIndex == index - 1) { + return ApplicationBundle.message("arrangement.settings.validation.empty.section.rule"); } } return null; diff --git a/platform/platform-resources-en/src/messages/ApplicationBundle.properties b/platform/platform-resources-en/src/messages/ApplicationBundle.properties index 983f0212e31e..42fd4e94be46 100644 --- a/platform/platform-resources-en/src/messages/ApplicationBundle.properties +++ b/platform/platform-resources-en/src/messages/ApplicationBundle.properties @@ -623,6 +623,7 @@ arrangement.settings.additional.force.rearrange.always=Always arrangement.settings.additional.force.rearrange.never=Never arrangement.settings.additional.force.rearrange.according.to.dialog=Use current mode (toggled in the Reformat Code dialog) arrangement.settings.additional.title=Additional settings +arrangement.settings.validation.duplicate.matching.rule=Matching rule have to be unique in the current settings. Duplicated rules will be ignored. arrangement.settings.validation.duplicate.section.text=Section text have to be unique in the current settings. Rule with duplicated text will be ignored. arrangement.settings.validation.empty.section.rule=Section should contain at least one arrangement entry otherwise it will be never inserted. arrangement.settings.validation.end.section.rule.without.start=Can not find start section rule for the current end rule.