From 361fdda4655e0ec2d25c8feb20867e781fe1ac98 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Fri, 14 Oct 2016 16:25:38 +0200 Subject: [PATCH] =?UTF-8?q?use=20correct=20serialization=20implementation?= =?UTF-8?q?=20in=20the=20copyProfile=20=E2=80=93=20otherwise=20when=20modi?= =?UTF-8?q?fiable=20model=20of=20scheme=20is=20created,=20lazy=20loaded=20?= =?UTF-8?q?element=20data=20is=20not=20used=20(and=20as=20result,=20locked?= =?UTF-8?q?=20attribute=20is=20not=20correctly=20set)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit testPreserveCompatibility is removed because we not DO NOT TOUCH files unless it is really modified In production we "do not preserve compatibility" (flag) since spring 2016 --- .../ex/InspectionProfileTest.java | 38 ++++--------- .../codeInspection/ex/InspectionSchemeTest.kt | 2 +- .../src/com/intellij/profile/Profile.java | 7 --- .../daemon/InspectionProfileConvertor.java | 9 +-- .../ex/InspectionProfileImpl.java | 55 +++++++------------ .../src/com/intellij/profile/ProfileEx.java | 34 ++++++------ .../ProjectInspectionProfileManager.kt | 5 +- .../src/SchemeManagerImpl.kt | 16 +++--- .../ApplicationInspectionProfileManager.java | 21 +++---- .../header/InspectionToolsConfigurable.java | 2 +- .../configurationStore/scheme-impl.kt | 2 +- .../com/intellij/testFramework/assertJEx.kt | 9 +++ .../idea/copyright/CopyrightProfile.java | 2 +- 13 files changed, 81 insertions(+), 121 deletions(-) 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 1600bfa069f4..922d706384e2 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/ex/InspectionProfileTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/ex/InspectionProfileTest.java @@ -27,7 +27,6 @@ import com.intellij.openapi.util.JDOMUtil; import com.intellij.openapi.util.WriteExternalException; import com.intellij.profile.Profile; import com.intellij.profile.codeInspection.InspectionProfileManager; -import com.intellij.profile.codeInspection.InspectionProjectProfileManager; import com.intellij.profile.codeInspection.ProjectInspectionProfileManager; import com.intellij.profile.codeInspection.ui.header.InspectionToolsConfigurable; import com.intellij.psi.PsiModifier; @@ -43,8 +42,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import static com.intellij.profile.ProfileEx.serializeProfile; -import static com.intellij.testFramework.PlatformTestUtil.assertElementsEqual; +import static com.intellij.testFramework.Assertions.assertThat; /** * @author Anna.Kozlova @@ -80,7 +78,7 @@ public class InspectionProfileTest extends LightIdeaTestCase { profile.readExternal(element); final ModifiableModel model = profile.getModifiableModel(); model.commit(); - assertElementsEqual(element, serializeProfile(profile)); + assertThat(profile.writeScheme()).isEqualTo(element); } private static InspectionProfileImpl createProfile() { @@ -150,7 +148,7 @@ public class InspectionProfileTest extends LightIdeaTestCase { ModifiableModel model = profile.getModifiableModel(); model.commit(); - assertElementsEqual(loadProfile(), serializeProfile(profile)); + assertThat(profile.writeScheme()).isEqualTo(loadProfile()); } private static Element loadProfile() throws IOException, JDOMException { @@ -206,7 +204,7 @@ public class InspectionProfileTest extends LightIdeaTestCase { profile.readExternal(element); final ModifiableModel model = profile.getModifiableModel(); model.commit(); - assertElementsEqual(element, serializeProfile(profile)); + assertThat(profile.writeScheme()).isEqualTo(element); } public void testMergeUnusedDeclarationAndUnusedSymbol() throws Exception { @@ -218,7 +216,7 @@ public class InspectionProfileTest extends LightIdeaTestCase { profile.readExternal(element); ModifiableModel model = profile.getModifiableModel(); model.commit(); - assertElementsEqual(element, serializeProfile(profile)); + assertThat(profile.writeScheme()).isEqualTo(element); //settings to merge @@ -290,7 +288,7 @@ public class InspectionProfileTest extends LightIdeaTestCase { ""; assertEquals(mergedText, serialize(profile)); - Element toImportElement = serializeProfile(profile); + Element toImportElement = profile.writeScheme(); final InspectionProfileImpl importedProfile = InspectionToolsConfigurable.importInspectionProfile(toImportElement, InspectionProfileManager.getInstance(), getProject(), null); @@ -300,9 +298,9 @@ public class InspectionProfileTest extends LightIdeaTestCase { profile.readExternal(mergedElement); model = profile.getModifiableModel(); model.commit(); - assertElementsEqual(mergedElement, serializeProfile(profile)); + assertThat(profile.writeScheme()).isEqualTo(mergedElement); - assertElementsEqual(mergedElement, serializeProfile(importedProfile)); + assertThat(importedProfile.writeScheme()).isEqualTo(mergedElement); } public void testStoredMemberVisibility() throws Exception { @@ -510,7 +508,7 @@ public class InspectionProfileTest extends LightIdeaTestCase { "", serialize(profile)); - Element element = serializeProfile(profile); + Element element = profile.writeScheme(); list.add(createTool("bar", true)); list.add(createTool("disabled", false)); @@ -537,7 +535,7 @@ public class InspectionProfileTest extends LightIdeaTestCase { } private static String serialize(InspectionProfileImpl profile) throws WriteExternalException { - return JDOMUtil.writeElement(serializeProfile(profile)); + return JDOMUtil.writeElement(profile.writeScheme()); } private static InspectionProfileImpl createProfile(@NotNull InspectionToolRegistrar registrar) { @@ -596,7 +594,7 @@ public class InspectionProfileTest extends LightIdeaTestCase { profile.enableTool(id, getProject()); } assertEquals(0, countInitializedTools(profile)); - serializeProfile(profile); + profile.writeScheme(); List initializedTools = getInitializedTools(profile); if (initializedTools.size() > 0) { for (InspectionToolWrapper initializedTool : initializedTools) { @@ -619,20 +617,6 @@ public class InspectionProfileTest extends LightIdeaTestCase { assertEquals(1, countInitializedTools(foo)); } - public void testPreserveCompatibility() throws Exception { - InspectionProfileImpl foo = new InspectionProfileImpl("foo", InspectionToolRegistrar.getInstance(), InspectionProjectProfileManager.getInstance(getProject())); - String test = "\n" + - " "; - foo.readExternal(JDOMUtil.loadDocument(test).getRootElement()); - foo.initInspectionTools(getProject()); - assertEquals(test, JDOMUtil.writeElement(serializeProfile(foo))); - } - public static int countInitializedTools(@NotNull Profile foo) { return getInitializedTools((InspectionProfileImpl)foo).size(); } diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/ex/InspectionSchemeTest.kt b/java/java-tests/testSrc/com/intellij/codeInspection/ex/InspectionSchemeTest.kt index 8709ee796ef3..974c9661cba7 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/ex/InspectionSchemeTest.kt +++ b/java/java-tests/testSrc/com/intellij/codeInspection/ex/InspectionSchemeTest.kt @@ -41,7 +41,7 @@ class InspectionSchemeTest { @Test fun loadSchemes() { val schemeFile = fsRule.fs.getPath("inspection/Bar.xml") val schemeData = """ - + """.trimIndent() diff --git a/platform/analysis-api/src/com/intellij/profile/Profile.java b/platform/analysis-api/src/com/intellij/profile/Profile.java index 08e65fc15cc3..163875cb8423 100644 --- a/platform/analysis-api/src/com/intellij/profile/Profile.java +++ b/platform/analysis-api/src/com/intellij/profile/Profile.java @@ -17,7 +17,6 @@ package com.intellij.profile; import com.intellij.openapi.options.Scheme; import com.intellij.util.xmlb.annotations.Transient; -import org.jdom.Element; import org.jetbrains.annotations.NotNull; /** @@ -25,8 +24,6 @@ import org.jetbrains.annotations.NotNull; * Date: 20-Nov-2005 */ public interface Profile extends Comparable, Scheme { - void copyFrom(@NotNull Profile profile); - @Transient boolean isProjectLevel(); @@ -42,8 +39,4 @@ public interface Profile extends Comparable, Scheme { @NotNull ProfileManager getProfileManager(); - - void readExternal(Element element); - - void writeExternal(Element element); } diff --git a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/InspectionProfileConvertor.java b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/InspectionProfileConvertor.java index f45ffc640444..63fadcb0afa5 100644 --- a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/InspectionProfileConvertor.java +++ b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/InspectionProfileConvertor.java @@ -26,13 +26,13 @@ import com.intellij.openapi.util.JDOMUtil; import com.intellij.openapi.util.io.FileUtil; import com.intellij.profile.codeInspection.InspectionProfileManager; import com.intellij.profile.codeInspection.SeverityProvider; -import org.jdom.Document; import org.jdom.Element; import org.jdom.JDOMException; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import java.io.File; +import java.io.FileOutputStream; import java.io.IOException; import java.util.HashMap; import java.util.Map; @@ -50,7 +50,6 @@ public class InspectionProfileConvertor { @NonNls private static final String NAME_ATT = "name"; @NonNls private static final String VERSION_ATT = "version"; - @NonNls private static final String PROFILE_NAME_ATT = "profile_name"; @NonNls private static final String OPTION_TAG = "option"; @NonNls private static final String DISPLAY_LEVEL_MAP_OPTION = "DISPLAY_LEVEL_MAP"; @NonNls protected static final String VALUE_ATT = "value"; @@ -110,11 +109,9 @@ public class InspectionProfileConvertor { return; } try { - Document doc = JDOMUtil.loadDocument(files[0]); - Element root = doc.getRootElement(); + Element root = JDOMUtil.load(files[0]); if (root.getAttributeValue(VERSION_ATT) == null){ - root.setAttribute(PROFILE_NAME_ATT, OLD_DEFAUL_PROFILE); - JDOMUtil.writeDocument(doc, new File(profileDirectory, OLD_DEFAUL_PROFILE + XML_EXTENSION), "\n"); + JDOMUtil.writeParent(root, new FileOutputStream(new File(profileDirectory, OLD_DEFAUL_PROFILE + XML_EXTENSION)), "\n"); FileUtil.delete(files[0]); } } diff --git a/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionProfileImpl.java b/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionProfileImpl.java index ac9028837678..5f6ac4764dba 100644 --- a/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionProfileImpl.java +++ b/platform/analysis-impl/src/com/intellij/codeInspection/ex/InspectionProfileImpl.java @@ -33,10 +33,7 @@ import com.intellij.openapi.util.*; import com.intellij.profile.ProfileEx; import com.intellij.profile.ProfileManager; import com.intellij.profile.codeInspection.InspectionProfileManager; -import com.intellij.profile.codeInspection.ProjectInspectionProfileManager; -import com.intellij.profile.codeInspection.ProjectInspectionProfileManagerKt; import com.intellij.profile.codeInspection.SeverityProvider; -import com.intellij.project.ProjectKt; import com.intellij.psi.PsiElement; import com.intellij.psi.search.scope.packageSet.NamedScope; import com.intellij.util.ArrayUtil; @@ -281,26 +278,15 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel, @NotNull public Element writeScheme() { - if (myDataHolder != null) { - return myDataHolder.read(); - } - - Element element = new Element("profile"); - Element result = isProjectLevel() ? element.setAttribute("version", "1.0") : element.setAttribute("profile_name", getName()); - serializeInto(result, false); - - if (isProjectLevel() && ProjectKt.isDirectoryBased(((ProjectInspectionProfileManager)myProfileManager).getProject())) { - return new Element("component").setAttribute("name", "InspectionProjectProfileManager").addContent(result); - } - return result; + return myDataHolder == null ? super.writeScheme() : myDataHolder.read(); } @Override - public void serializeInto(@NotNull Element element, boolean preserveCompatibility) { + public void writeExternal(@NotNull Element element) { // must be first - compatibility element.setAttribute(VERSION_TAG, VALID_VERSION); - super.serializeInto(element, preserveCompatibility); + super.writeExternal(element); synchronized (myLock) { if (!myInitialized) { @@ -857,24 +843,23 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel, initInspectionTools(project); for (Element scopeElement : scopes.getChildren(SCOPE)) { - final String profile = scopeElement.getAttributeValue(ProjectInspectionProfileManagerKt.PROFILE); - if (profile != null) { - final InspectionProfileImpl inspectionProfile = (InspectionProfileImpl)getProfileManager().getProfile(profile); - if (inspectionProfile != null) { - final NamedScope scope = getProfileManager().getScopesManager().getScope(scopeElement.getAttributeValue(NAME)); - if (scope != null) { - for (InspectionToolWrapper toolWrapper : inspectionProfile.getInspectionTools(null)) { - final HighlightDisplayKey key = HighlightDisplayKey.find(toolWrapper.getShortName()); - try { - InspectionToolWrapper toolWrapperCopy = copyToolSettings(toolWrapper); - HighlightDisplayLevel errorLevel = inspectionProfile.getErrorLevel(key, null, project); - getTools(toolWrapper.getShortName(), project).addTool(scope, toolWrapperCopy, inspectionProfile.isToolEnabled(key), errorLevel); - } - catch (Exception e) { - LOG.error(e); - } - } - } + final String profile = scopeElement.getAttributeValue(PROFILE); + InspectionProfileImpl inspectionProfile = profile == null ? null : (InspectionProfileImpl)getProfileManager().getProfile(profile); + NamedScope scope = inspectionProfile == null ? null : getProfileManager().getScopesManager().getScope(scopeElement.getAttributeValue(NAME)); + if (scope == null) { + continue; + } + + for (InspectionToolWrapper toolWrapper : inspectionProfile.getInspectionTools(null)) { + final HighlightDisplayKey key = HighlightDisplayKey.find(toolWrapper.getShortName()); + try { + InspectionToolWrapper toolWrapperCopy = copyToolSettings(toolWrapper); + HighlightDisplayLevel errorLevel = inspectionProfile.getErrorLevel(key, null, project); + getTools(toolWrapper.getShortName(), project) + .addTool(scope, toolWrapperCopy, inspectionProfile.isToolEnabled(key), errorLevel); + } + catch (Exception e) { + LOG.error(e); } } } diff --git a/platform/analysis-impl/src/com/intellij/profile/ProfileEx.java b/platform/analysis-impl/src/com/intellij/profile/ProfileEx.java index 9ff4b6785519..6060227b2c09 100644 --- a/platform/analysis-impl/src/com/intellij/profile/ProfileEx.java +++ b/platform/analysis-impl/src/com/intellij/profile/ProfileEx.java @@ -15,7 +15,8 @@ */ package com.intellij.profile; -import com.intellij.profile.codeInspection.ProjectInspectionProfileManagerKt; +import com.intellij.profile.codeInspection.ProjectInspectionProfileManager; +import com.intellij.project.ProjectKt; import com.intellij.util.xmlb.SmartSerializer; import com.intellij.util.xmlb.annotations.OptionTag; import com.intellij.util.xmlb.annotations.Transient; @@ -29,6 +30,7 @@ import org.jetbrains.annotations.NotNull; public abstract class ProfileEx implements Profile { public static final String SCOPE = "scope"; public static final String NAME = "name"; + public static final String PROFILE = "profile"; private final SmartSerializer mySerializer; @@ -84,18 +86,12 @@ public abstract class ProfileEx implements Profile { myProfileManager = profileManager; } - @Override public void readExternal(Element element) { mySerializer.readExternal(this, element); } - public void serializeInto(@NotNull Element element, boolean preserveCompatibility) { - mySerializer.writeExternal(this, element, preserveCompatibility); - } - - @Override - public final void writeExternal(Element element) { - serializeInto(element, true); + public void writeExternal(@NotNull Element element) { + mySerializer.writeExternal(this, element, false); } public boolean equals(Object o) { @@ -114,15 +110,21 @@ public abstract class ProfileEx implements Profile { return 0; } - @Override - public final void copyFrom(@NotNull Profile profile) { - readExternal(serializeProfile(profile)); + public final void copyFrom(@NotNull ProfileEx profile) { + readExternal(profile.writeScheme()); } @NotNull - public static Element serializeProfile(@NotNull Profile profile) { - Element result = new Element(ProjectInspectionProfileManagerKt.PROFILE); - profile.writeExternal(result); - return result; + public Element writeScheme() { + Element element = new Element(PROFILE); + if (isProjectLevel()) { + element.setAttribute("version", "1.0"); + } + writeExternal(element); + + if (isProjectLevel() && ProjectKt.isDirectoryBased(((ProjectInspectionProfileManager)myProfileManager).getProject())) { + return new Element("component").setAttribute("name", "InspectionProjectProfileManager").addContent(element); + } + return element; } } diff --git a/platform/analysis-impl/src/com/intellij/profile/codeInspection/ProjectInspectionProfileManager.kt b/platform/analysis-impl/src/com/intellij/profile/codeInspection/ProjectInspectionProfileManager.kt index d0593856fc8a..f7f31fc78e52 100644 --- a/platform/analysis-impl/src/com/intellij/profile/codeInspection/ProjectInspectionProfileManager.kt +++ b/platform/analysis-impl/src/com/intellij/profile/codeInspection/ProjectInspectionProfileManager.kt @@ -33,6 +33,7 @@ import com.intellij.openapi.util.Disposer import com.intellij.openapi.util.text.StringUtil import com.intellij.packageDependencies.DependencyValidationManager import com.intellij.profile.Profile +import com.intellij.profile.ProfileEx import com.intellij.project.isDirectoryBased import com.intellij.psi.search.scope.packageSet.NamedScopeManager import com.intellij.psi.search.scope.packageSet.NamedScopesHolder @@ -50,8 +51,6 @@ import org.jetbrains.concurrency.runAsync import java.util.* import java.util.function.Function -const val PROFILE = "profile" - private const val VERSION = "1.0" private const val SCOPE = "scope" private const val NAME = "name" @@ -308,7 +307,7 @@ class ProjectInspectionProfileManager(val project: Project, if (currentScheme == null) { currentScheme = InspectionProfileImpl(PROJECT_DEFAULT_PROFILE_NAME, InspectionToolRegistrar.getInstance(), this, InspectionProfileImpl.getDefaultProfile(), null) - currentScheme.copyFrom(applicationProfileManager.currentProfile) + currentScheme.copyFrom(applicationProfileManager.currentProfile as ProfileEx) currentScheme.isProjectLevel = true currentScheme.name = PROJECT_DEFAULT_PROFILE_NAME schemeManager.addScheme(currentScheme) diff --git a/platform/configuration-store-impl/src/SchemeManagerImpl.kt b/platform/configuration-store-impl/src/SchemeManagerImpl.kt index eb9b341f4316..a210200778f6 100644 --- a/platform/configuration-store-impl/src/SchemeManagerImpl.kt +++ b/platform/configuration-store-impl/src/SchemeManagerImpl.kt @@ -233,11 +233,11 @@ class SchemeManagerImpl(val fileSpec: String, val bytes = URLUtil.openStream(url).readBytes() lazyPreloadScheme(bytes, isUseOldFileNameSanitize) { name, parser -> val attributeProvider = Function { parser.getAttributeValue(null, it) } - val schemeName = name ?: (processor as LazySchemeProcessor).getName(attributeProvider) - val fileName = PathUtilRt.getFileName(url.path) val extension = getFileExtension(fileName, true) val externalInfo = ExternalInfo(fileName.substring(0, fileName.length - extension.length), extension) + + val schemeName = name ?: (processor as LazySchemeProcessor).getName(attributeProvider, externalInfo.fileNameWithoutExtension) externalInfo.schemeName = schemeName val scheme = (processor as LazySchemeProcessor).createScheme(SchemeDataHolderImpl(bytes, externalInfo), schemeName, attributeProvider, true) @@ -316,7 +316,7 @@ class SchemeManagerImpl(val fileSpec: String, processPendingCurrentSchemeName(scheme) } - messageBus?.let { it.connect().subscribe(VirtualFileManager.VFS_CHANGES, SchemeFileTracker()) } + messageBus?.connect()?.subscribe(VirtualFileManager.VFS_CHANGES, SchemeFileTracker()) return schemes.subList(newSchemesOffset, schemes.size) } @@ -438,7 +438,7 @@ class SchemeManagerImpl(val fileSpec: String, val bytes = input.readBytes() lazyPreloadScheme(bytes, isUseOldFileNameSanitize) { name, parser -> val attributeProvider = Function { parser.getAttributeValue(null, it) } - val schemeName = name ?: processor.getName(attributeProvider) + val schemeName = name ?: processor.getName(attributeProvider, fileNameWithoutExtension) if (!checkExisting(schemeName)) { return null } @@ -573,7 +573,7 @@ class SchemeManagerImpl(val fileSpec: String, var externalInfo: ExternalInfo? = schemeToInfo.get(scheme) val currentFileNameWithoutExtension = externalInfo?.fileNameWithoutExtension val parent = processor.writeScheme(scheme) - val element = if (parent is Element) parent else (parent as Document).detachRootElement() + val element = parent as? Element ?: (parent as Document).detachRootElement() if (element.isEmpty()) { externalInfo?.scheduleDelete() return @@ -685,7 +685,7 @@ class SchemeManagerImpl(val fileSpec: String, val bundledScheme = readOnlyExternalizableSchemes.get(scheme.name) if (bundledScheme == null) { - if ((processor as? LazySchemeProcessor)?.let { it.isSchemeEqualToBundled(scheme) } ?: false) { + if ((processor as? LazySchemeProcessor)?.isSchemeEqualToBundled(scheme) ?: false) { externalInfo?.scheduleDelete() return true } @@ -875,9 +875,7 @@ class SchemeManagerImpl(val fileSpec: String, private fun collectExistingNames(schemes: Collection): Collection { val result = THashSet(schemes.size) - for (scheme in schemes) { - result.add(scheme.name) - } + schemes.mapTo(result) { it.name } return result } diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ex/ApplicationInspectionProfileManager.java b/platform/lang-impl/src/com/intellij/codeInspection/ex/ApplicationInspectionProfileManager.java index 93ec446cb6f5..91b13c8643d4 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ex/ApplicationInspectionProfileManager.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ex/ApplicationInspectionProfileManager.java @@ -22,7 +22,6 @@ import com.intellij.codeInsight.daemon.impl.HighlightInfoType; import com.intellij.codeInsight.daemon.impl.SeveritiesProvider; import com.intellij.codeInsight.daemon.impl.SeverityRegistrar; import com.intellij.codeInsight.daemon.impl.analysis.HighlightingSettingsPerFile; -import com.intellij.codeInspection.InspectionProfile; import com.intellij.codeInspection.InspectionsBundle; import com.intellij.configurationStore.BundledSchemeEP; import com.intellij.configurationStore.SchemeDataHolder; @@ -93,8 +92,8 @@ public class ApplicationInspectionProfileManager extends BaseInspectionProfileMa mySchemeManager = schemeManagerFactory.create(INSPECTION_DIR, new InspectionProfileProcessor() { @NotNull @Override - public String getName(@NotNull Function attributeProvider) { - return "unnamed"; + public String getName(@NotNull Function attributeProvider, String fileNameWithoutExtension) { + return fileNameWithoutExtension; } @NotNull @@ -102,11 +101,7 @@ public class ApplicationInspectionProfileManager extends BaseInspectionProfileMa @NotNull String name, @NotNull Function attributeProvider, boolean isBundled) { - InspectionProfileImpl profile = new InspectionProfileImpl(name, myRegistrar, ApplicationInspectionProfileManager.this, dataHolder); - if (isBundled) { - profile.lockProfile(true); - } - return profile; + return new InspectionProfileImpl(name, myRegistrar, ApplicationInspectionProfileManager.this, dataHolder); } @Override @@ -169,12 +164,10 @@ public class ApplicationInspectionProfileManager extends BaseInspectionProfileMa } public void initProfiles() { - if (!myProfilesAreInitialized.compareAndSet(false, true)) { + if (!myProfilesAreInitialized.compareAndSet(false, true) || !LOAD_PROFILES) { return; } - if (!LOAD_PROFILES) return; - loadBundledSchemes(); mySchemeManager.loadSchemes(); createDefaultProfile(); @@ -270,12 +263,12 @@ public class ApplicationInspectionProfileManager extends BaseInspectionProfileMa @NotNull @Override - public InspectionProfile getCurrentProfile() { + public InspectionProfileImpl getCurrentProfile() { initProfiles(); - Profile current = mySchemeManager.getCurrentScheme(); + InspectionProfileImpl current = mySchemeManager.getCurrentScheme(); if (current != null) { - return (InspectionProfile)current; + return current; } // use default as base, not random custom profile diff --git a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/header/InspectionToolsConfigurable.java b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/header/InspectionToolsConfigurable.java index fc8ff4abd3e9..9da66f7a13d8 100644 --- a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/header/InspectionToolsConfigurable.java +++ b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/header/InspectionToolsConfigurable.java @@ -108,7 +108,7 @@ public abstract class InspectionToolsConfigurable extends BaseConfigurable } @NotNull - private InspectionProfileImpl copyToNewProfile(ModifiableModel selectedProfile, + private InspectionProfileImpl copyToNewProfile(@NotNull InspectionProfileImpl selectedProfile, @NotNull Project project, boolean modifyName, boolean modifyLevel) { diff --git a/platform/projectModel-impl/src/com/intellij/configurationStore/scheme-impl.kt b/platform/projectModel-impl/src/com/intellij/configurationStore/scheme-impl.kt index cc6b497a61ce..d152cce89576 100644 --- a/platform/projectModel-impl/src/com/intellij/configurationStore/scheme-impl.kt +++ b/platform/projectModel-impl/src/com/intellij/configurationStore/scheme-impl.kt @@ -54,7 +54,7 @@ interface SchemeExtensionProvider { } abstract class LazySchemeProcessor(private val nameAttribute: String = "name") : SchemeProcessor() { - open fun getName(attributeProvider: Function): String { + open fun getName(attributeProvider: Function, fileNameWithoutExtension: String): String { return attributeProvider.apply(nameAttribute) ?: throw IllegalStateException("name is missed in the scheme data") } diff --git a/platform/testFramework/testSrc/com/intellij/testFramework/assertJEx.kt b/platform/testFramework/testSrc/com/intellij/testFramework/assertJEx.kt index 6903d23efaa4..455744a91dde 100644 --- a/platform/testFramework/testSrc/com/intellij/testFramework/assertJEx.kt +++ b/platform/testFramework/testSrc/com/intellij/testFramework/assertJEx.kt @@ -44,6 +44,15 @@ class JdomAssert(actual: Element?) : AbstractAssert(actual return isEqualTo(file.readText()) } + fun isEqualTo(element: Element): JdomAssert { + isNotNull + + if (!JDOMUtil.areElementsEqual(actual, element)) { + isEqualTo(JDOMUtil.writeElement(element)) + } + return this + } + fun isEqualTo(expected: String): JdomAssert { isNotNull diff --git a/plugins/copyright/src/com/maddyhome/idea/copyright/CopyrightProfile.java b/plugins/copyright/src/com/maddyhome/idea/copyright/CopyrightProfile.java index b880fbad0ffa..642f5e79ac6b 100644 --- a/plugins/copyright/src/com/maddyhome/idea/copyright/CopyrightProfile.java +++ b/plugins/copyright/src/com/maddyhome/idea/copyright/CopyrightProfile.java @@ -34,7 +34,7 @@ public class CopyrightProfile extends ProfileEx { //read external public CopyrightProfile() { - super("", new SmartSerializer()); + this(""); } public CopyrightProfile(String profileName) {