mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
[Java. Code Formatting] Create a migration activity for java codestyle settings
IDEA-110857 GitOrigin-RevId: 6469cfd69acf5e68dad3cced70942326ebde1c7c
This commit is contained in:
committed by
intellij-monorepo-bot
parent
0f41cc4fe5
commit
4f741ef16c
+36
@@ -0,0 +1,36 @@
|
||||
// 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.application.options.CodeStyle
|
||||
import com.intellij.lang.java.JavaLanguage
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.startup.ProjectActivity
|
||||
import com.intellij.psi.codeStyle.CodeStyleScheme.PROJECT_SCHEME_NAME
|
||||
|
||||
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 ->
|
||||
if (scheme.name != PROJECT_SCHEME_NAME) {
|
||||
migrateSettings(scheme.codeStyleSettings)
|
||||
}
|
||||
}
|
||||
applicationMigrationState.areSchemesMigrated = true
|
||||
}
|
||||
|
||||
if (!projectMigrationState.areSchemesMigrated) {
|
||||
val settings = CodeStyle.getSettings(project)
|
||||
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
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
// 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