From 175269aa31608aa3eafc67bedcf3a466f76a5e77 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Fri, 3 Jun 2016 17:49:40 +0200 Subject: [PATCH] store state in separate class --- .../InspectionProjectProfileManagerImpl.kt | 36 +++++++++---------- .../com/intellij/util/xmlb/BeanBinding.java | 3 +- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/platform/analysis-impl/src/com/intellij/profile/codeInspection/InspectionProjectProfileManagerImpl.kt b/platform/analysis-impl/src/com/intellij/profile/codeInspection/InspectionProjectProfileManagerImpl.kt index 80fcbb4e771c..3482546f3b09 100644 --- a/platform/analysis-impl/src/com/intellij/profile/codeInspection/InspectionProjectProfileManagerImpl.kt +++ b/platform/analysis-impl/src/com/intellij/profile/codeInspection/InspectionProjectProfileManagerImpl.kt @@ -80,9 +80,6 @@ class InspectionProjectProfileManagerImpl(private val project: Project, private var state = State() - @OptionTag("USE_PROJECT_PROFILE") - private var useProjectProfile = true - init { project.messageBus.connect().subscribe(ProjectManager.TOPIC, object: ProjectManagerListener { override fun projectClosed(project: Project) { @@ -110,6 +107,9 @@ class InspectionProjectProfileManagerImpl(private val project: Project, private class State { @OptionTag("PROJECT_PROFILE") var projectProfile: String? = null + + @OptionTag("USE_PROJECT_PROFILE") + var useProjectProfile = true } override fun getProject() = project @@ -210,7 +210,9 @@ class InspectionProjectProfileManagerImpl(private val project: Project, val profileKeys = THashSet() profileKeys.addAll(profiles.keys) profiles.clear() - XmlSerializer.deserializeInto(this, state) + val newState = State() + XmlSerializer.deserializeInto(newState, state) + this.state = newState for (o in state.getChildren(PROFILE)) { val profile = applicationProfileManager.createProfile() profile.profileManager = this @@ -223,17 +225,17 @@ class InspectionProjectProfileManagerImpl(private val project: Project, profiles.put(profile.name, profile as InspectionProfile?) } } - if (state.getChild("version") == null || !Comparing.strEqual(state.getChild("version").getAttributeValue("value"), VERSION)) { - var toConvert = true + if (state.getChild("version")?.getAttributeValue("value") != VERSION) { for (o in state.getChildren("option")) { - if (Comparing.strEqual(o.getAttributeValue("name"), "USE_PROJECT_LEVEL_SETTINGS")) { - toConvert = java.lang.Boolean.parseBoolean(o.getAttributeValue("value")) + if (o.getAttributeValue("name") == "USE_PROJECT_LEVEL_SETTINGS") { + if (o.getAttributeValue("value").toBoolean()) { + if (newState.projectProfile != null) { + (inspectionProfile as ProfileEx).convert(state, project) + } + } break } } - if (toConvert) { - convert(state) - } } } @@ -262,7 +264,7 @@ class InspectionProjectProfileManagerImpl(private val project: Project, } if (!state.children.isEmpty() || isCustomProfileUsed) { - XmlSerializer.serializeInto(this, state) + XmlSerializer.serializeInto(state, state) state.addContent(Element("version").setAttribute("value", VERSION)) } @@ -294,7 +296,7 @@ class InspectionProjectProfileManagerImpl(private val project: Project, val oldProfile = state.projectProfile state.projectProfile = newProfile - useProjectProfile = newProfile != null + state.useProjectProfile = newProfile != null if (oldProfile != null) { for (adapter in profileListeners) { adapter.profileActivated(getProfile(oldProfile), if (newProfile != null) getProfile(newProfile) else null) @@ -303,7 +305,7 @@ class InspectionProjectProfileManagerImpl(private val project: Project, } @Synchronized override fun getInspectionProfile(): InspectionProfile { - if (!useProjectProfile) { + if (!state.useProjectProfile) { return applicationProfileManager.rootProfile as InspectionProfile } if (state.projectProfile == null || profiles.isEmpty) { @@ -345,12 +347,6 @@ class InspectionProjectProfileManagerImpl(private val project: Project, val profile = profiles.get(name) return profile ?: applicationProfileManager.getProfile(name, returnRootProfileIfNamedIsAbsent) } - - fun convert(element: Element) { - if (state.projectProfile != null) { - (inspectionProfile as ProfileEx).convert(element, project) - } - } } private class ProfileStateSplitter : MainConfigurationStateSplitter() { diff --git a/platform/util/src/com/intellij/util/xmlb/BeanBinding.java b/platform/util/src/com/intellij/util/xmlb/BeanBinding.java index 149e3e9fa713..d59821e6bc0c 100644 --- a/platform/util/src/com/intellij/util/xmlb/BeanBinding.java +++ b/platform/util/src/com/intellij/util/xmlb/BeanBinding.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -123,6 +123,7 @@ class BeanBinding extends Binding implements MainBinding { } @Override + @NotNull public Object deserialize(Object context, @NotNull Element element) { Object instance = ReflectionUtil.newInstance(myBeanClass); deserializeInto(instance, element, null);