mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 14:23:28 +07:00
[Java. Code Formatting] Remove bad way of migration JavaCodeStyleSettings
IDEA-110857 GitOrigin-RevId: b44f2d53170f7753d5c7c61d1caec72e0af3c432
This commit is contained in:
committed by
intellij-monorepo-bot
parent
029e881a2f
commit
a3196c0297
@@ -1,39 +0,0 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.psi.codeStyle
|
||||
|
||||
import com.intellij.lang.java.JavaLanguage
|
||||
import com.intellij.openapi.components.SimplePersistentStateComponent
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.startup.ProjectActivity
|
||||
|
||||
/**
|
||||
* JavaCodeStyleSettingsMigrationActivity is responsible for migrating the Java code style settings
|
||||
* for both application-wide and project-specific schemes.
|
||||
* All customs schemes are stored on the application level and therefore, two [SimplePersistentStateComponent] are required
|
||||
* Note, migration will not happen in case new schemes will be added.
|
||||
*/
|
||||
class JavaCodeStyleSettingsMigrationActivity : ProjectActivity {
|
||||
override suspend fun execute(project: Project) {
|
||||
val applicationMigrationState = JavaCodeStyleSettingsApplicationMigrationManager.getInstance().state
|
||||
val projectMigrationState = JavaCodeStyleSettingsProjectMigrationManager.getInstance(project).state
|
||||
|
||||
if (!applicationMigrationState.areSchemesMigrated) {
|
||||
CodeStyleSchemes.getInstance().allSchemes.forEach { scheme ->
|
||||
migrateSettings(scheme.codeStyleSettings)
|
||||
}
|
||||
applicationMigrationState.areSchemesMigrated = true
|
||||
}
|
||||
|
||||
if (!projectMigrationState.areSchemesMigrated) {
|
||||
val settings = CodeStyleSettingsManager.getInstance(project).mainProjectCodeStyle ?: return
|
||||
migrateSettings(settings)
|
||||
projectMigrationState.areSchemesMigrated = true
|
||||
}
|
||||
}
|
||||
|
||||
private fun migrateSettings(codeStyleSettings: CodeStyleSettings) {
|
||||
val commonSettings = codeStyleSettings.getCommonSettings(JavaLanguage.INSTANCE)
|
||||
val customSettings = codeStyleSettings.getCustomSettings(JavaCodeStyleSettings::class.java)
|
||||
customSettings.BLANK_LINES_AROUND_FIELD_WITH_ANNOTATIONS = commonSettings.BLANK_LINES_AROUND_FIELD
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.psi.codeStyle
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.components.*
|
||||
import com.intellij.openapi.project.Project
|
||||
|
||||
abstract class JavaCodeStyleSettingsProjectMigrationManagerBase : SimplePersistentStateComponent<MigrationState>(MigrationState())
|
||||
|
||||
@Service(Service.Level.PROJECT)
|
||||
@State(name = "JavaCodeStyleSettingsProjectMigration", storages = [Storage(StoragePathMacros.WORKSPACE_FILE)])
|
||||
class JavaCodeStyleSettingsProjectMigrationManager : JavaCodeStyleSettingsProjectMigrationManagerBase() {
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun getInstance(project: Project) = project.service<JavaCodeStyleSettingsProjectMigrationManager>()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Service(Service.Level.APP)
|
||||
@State(name = "JavaCodeStyleSettingsApplicationMigrationManager", storages = [Storage("java.code.style.migration.xml")])
|
||||
class JavaCodeStyleSettingsApplicationMigrationManager : JavaCodeStyleSettingsProjectMigrationManagerBase() {
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun getInstance() = ApplicationManager.getApplication().service<JavaCodeStyleSettingsApplicationMigrationManager>()
|
||||
}
|
||||
}
|
||||
|
||||
class MigrationState : BaseState() {
|
||||
var areSchemesMigrated by property(false)
|
||||
}
|
||||
Reference in New Issue
Block a user