diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/ex/InspectionProfileTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/ex/InspectionProfileTest.java
index 027d400fccd6..bc6c6c798411 100644
--- a/java/java-tests/testSrc/com/intellij/codeInspection/ex/InspectionProfileTest.java
+++ b/java/java-tests/testSrc/com/intellij/codeInspection/ex/InspectionProfileTest.java
@@ -462,6 +462,35 @@ public class InspectionProfileTest extends LightIdeaTestCase {
assertThat(importedProfile.writeScheme()).isEqualTo(mergedElement);
}
+ public void testKeepUnloadedMergeNamingConventions() throws Exception {
+ String unchanged = "\n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ "";
+ final Element allEnabledProfile = JdomKt.loadElement(unchanged);
+ InspectionProfileImpl profile = createProfile(new InspectionProfileImpl("foo"));
+ profile.readExternal(allEnabledProfile);
+ profile.initInspectionTools();
+ assertEquals(unchanged, serialize(profile));
+ }
+
public void testMergeMethodNamingConventions() throws Exception {
final Element element = JdomKt.loadElement("\n" +
" \n" +
diff --git a/platform/lang-impl/src/com/intellij/codeInspection/naming/AbstractNamingConventionInspection.java b/platform/lang-impl/src/com/intellij/codeInspection/naming/AbstractNamingConventionInspection.java
index d489951b232d..c36838e99b4a 100644
--- a/platform/lang-impl/src/com/intellij/codeInspection/naming/AbstractNamingConventionInspection.java
+++ b/platform/lang-impl/src/com/intellij/codeInspection/naming/AbstractNamingConventionInspection.java
@@ -40,6 +40,7 @@ public abstract class AbstractNamingConventionInspection> myNamingConventions = new LinkedHashMap<>();
private final Map myNamingConventionBeans = new LinkedHashMap<>();
+ private final Map myUnloadedElements = new LinkedHashMap<>();
private final Set myDisabledShortNames = new HashSet<>();
@Nullable private final String myDefaultConventionShortName;
@@ -88,6 +89,10 @@ public abstract class AbstractNamingConventionInspection convention : myNamingConventions.values()) {
- String shortName = convention.getShortName();
+ Set shortNames = new TreeSet<>(myNamingConventions.keySet());
+ shortNames.addAll(myUnloadedElements.keySet());
+ for (String shortName : shortNames) {
+ NamingConvention convention = myNamingConventions.get(shortName);
+ if (convention == null) {
+ Element element = myUnloadedElements.get(shortName);
+ if (element != null) node.addContent(element.clone());
+ continue;
+ }
boolean disabled = myDisabledShortNames.contains(shortName);
Element element = new Element("extension")
.setAttribute("name", shortName)