From 2c98eae0f09cbef57086f7600a5e639a165d95f6 Mon Sep 17 00:00:00 2001 From: "Gregory.Shrago" Date: Wed, 5 Dec 2012 18:46:45 +0400 Subject: [PATCH] IDEA-96656 IntelliLang allows duplicate injection definitions in IntelliLang.xml --- .../plugins/intelliLang/Configuration.java | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/Configuration.java b/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/Configuration.java index d4c1ededfb36..466d72c474f1 100644 --- a/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/Configuration.java +++ b/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/Configuration.java @@ -271,14 +271,16 @@ public class Configuration implements PersistentStateComponent, Modific if (enumeration == null || !enumeration.hasMoreElements()) { LOG.warn(descriptor.getPluginId() +": " + configBean.getConfigUrl() + " was not found"); } - while (enumeration.hasMoreElements()) { - URL url = enumeration.nextElement(); - if (!visited.add(url.getFile())) continue; // for DEBUG mode - try { - cfgList.add(load(url.openStream())); - } - catch (Exception e) { - LOG.warn(e); + else { + while (enumeration.hasMoreElements()) { + URL url = enumeration.nextElement(); + if (!visited.add(url.getFile())) continue; // for DEBUG mode + try { + cfgList.add(load(url.openStream())); + } + catch (Exception e) { + LOG.warn(e); + } } } } @@ -302,16 +304,17 @@ public class Configuration implements PersistentStateComponent, Modific } protected Element getState(final Element element) { - final List injectorIds = new ArrayList(myInjections.keySet()); + Comparator comparator = new Comparator() { + public int compare(final BaseInjection o1, final BaseInjection o2) { + return Comparing.compare(o1.getDisplayName(), o2.getDisplayName()); + } + }; + List injectorIds = new ArrayList(myInjections.keySet()); Collections.sort(injectorIds); for (String key : injectorIds) { - final List injections = new ArrayList(myInjections.get(key)); + TreeSet injections = new TreeSet(comparator); + injections.addAll(myInjections.get(key)); injections.removeAll(getDefaultInjections()); - Collections.sort(injections, new Comparator() { - public int compare(final BaseInjection o1, final BaseInjection o2) { - return Comparing.compare(o1.getDisplayName(), o2.getDisplayName()); - } - }); for (BaseInjection injection : injections) { element.addContent(injection.getState()); } @@ -357,6 +360,7 @@ public class Configuration implements PersistentStateComponent, Modific } else { elements.add(rootElement); + //noinspection unchecked elements.addAll(rootElement.getChildren("component")); state = ContainerUtil.find(elements, new Condition() { public boolean value(final Element element) {