Skip to content

Commit 63d2920

Browse files
committed
Refactor installer
1 parent 7c61346 commit 63d2920

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

CHANGELOG.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# intellij-swift-format Changelog
22

33
## [Unreleased]
4+
### Changed
5+
- Refactor installer
46

57
## [1.0.0]
6-
### Added
7-
- Formatter based on Keith Lazuka's [intellij-elm](https://github.com/klazuka/intellij-elm) and Google
8-
Inc.'s [google-java-format](https://github.com/google/google-java-format) plugins.
8+
### Added
9+
- Formatter based on Keith Lazuka's [intellij-elm](https://github.com/klazuka/intellij-elm) and Google
10+
Inc.'s [google-java-format](https://github.com/google/google-java-format) plugins.
911
- Settings
1012

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
pluginGroup=org.swiftformat.plugin
44
pluginName=swift-format
55
# SemVer format -> https://semver.org
6-
pluginVersion=1.0.0
6+
pluginVersion=1.0.1
77
# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
88
# for insight into build numbers and IntelliJ Platform versions.
99
pluginSinceBuild=221

src/main/kotlin/org/swiftformat/plugin/SwiftFormatInstaller.kt

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ package org.swiftformat.plugin
1919

2020
import com.google.common.base.Preconditions
2121
import com.intellij.ide.plugins.PluginManagerCore
22+
import com.intellij.openapi.extensions.PluginDescriptor
2223
import com.intellij.openapi.extensions.PluginId
2324
import com.intellij.openapi.project.Project
2425
import com.intellij.openapi.project.ProjectManagerListener
2526
import com.intellij.psi.codeStyle.CodeStyleManager
26-
import com.intellij.serviceContainer.ComponentManagerImpl
27+
import kotlin.reflect.jvm.kotlinFunction
2728

2829
/**
2930
* A component that replaces the default IntelliJ [CodeStyleManager] with one that formats via
@@ -45,11 +46,21 @@ internal class SwiftFormatInstaller : ProjectManagerListener {
4546
}
4647

4748
private fun setManager(project: Project, newManager: CodeStyleManager) {
48-
val platformComponentManager = project as ComponentManagerImpl
49+
val componentManagerImplClass =
50+
(Class.forName("com.intellij.serviceContainer.ComponentManagerImpl"))
51+
val registerServiceInstanceMethod =
52+
componentManagerImplClass
53+
.getMethod(
54+
"registerServiceInstance",
55+
Class::class.java,
56+
Object::class.java,
57+
PluginDescriptor::class.java)
58+
.kotlinFunction
59+
val platformComponentManager = componentManagerImplClass.cast(project)
4960
val plugin = PluginManagerCore.getPlugin(PluginId.getId("org.swiftformat.plugin"))
5061
Preconditions.checkState(plugin != null, "Couldn't locate our own PluginDescriptor.")
51-
platformComponentManager.registerServiceInstance(
52-
CodeStyleManager::class.java, newManager, plugin!!)
62+
registerServiceInstanceMethod!!.call(
63+
platformComponentManager, CodeStyleManager::class.java, newManager, plugin!!)
5364
}
5465
}
5566
}

0 commit comments

Comments
 (0)