Skip to content

Commit f723d00

Browse files
authored
Merge pull request #3 from dcsmf/dev
Fix some bugs
2 parents 30158b8 + 27b5325 commit f723d00

File tree

7 files changed

+18
-21
lines changed

7 files changed

+18
-21
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
# intellij-format-methods-plugin Changelog
44

5-
## [Unreleased]
5+
## [2.0.1] (2024/01/02)
6+
- Fix some bugs
7+
- 修复了一些问题
68

79
## [2.0.0] (2023/12/07)
810
- Now minimum support *IDEA* version is 2023.3
@@ -63,7 +65,6 @@
6365
- Methods sort feature finished
6466
- 函数排序功能完成
6567

66-
[Unreleased]: https://github.com/dcsmf/intellij-format-methods-plugin/compare/v1.1.1...HEAD
6768
[1.1.1]: https://github.com/dcsmf/intellij-format-methods-plugin/compare/v1.1.0...v1.1.1
6869
[1.1.0]: https://github.com/dcsmf/intellij-format-methods-plugin/compare/v1.0.8...v1.1.0
6970
[1.0.8]: https://github.com/dcsmf/intellij-format-methods-plugin/compare/v1.0.7...v1.0.8

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pluginGroup = com.github.dcsmf.intellijformatmethodsplugin
44
pluginName = FormatMethodPyramid
55
pluginRepositoryUrl = https://github.com/dcsmf/intellij-format-methods-plugin
66
# SemVer format -> https://semver.org
7-
pluginVersion = 2.0.0
7+
pluginVersion = 2.0.1
88

99
# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
1010
pluginSinceBuild = 233

src/main/kotlin/com/github/dcsmf/plugin/formatmethods/action/FormatMethodWithPyramidAction.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import com.github.dcsmf.plugin.formatmethods.utils.ElementUtil
77
import com.github.dcsmf.plugin.formatmethods.utils.MethodUtil.getJvmStyleSignature
88
import com.github.dcsmf.plugin.formatmethods.utils.NotifyUtil
99
import com.github.dcsmf.plugin.formatmethods.utils.SortUtil
10+
import com.intellij.openapi.actionSystem.ActionUpdateThread
1011
import com.intellij.openapi.actionSystem.AnAction
1112
import com.intellij.openapi.actionSystem.AnActionEvent
1213
import com.intellij.openapi.actionSystem.CommonDataKeys
@@ -16,11 +17,13 @@ import com.intellij.openapi.project.Project
1617
import com.intellij.psi.*
1718
import com.intellij.psi.impl.source.PsiExtensibleClass
1819
import com.intellij.util.containers.stream
19-
import org.apache.commons.lang.StringUtils
2020
import java.util.*
2121
import java.util.stream.Collectors
2222

2323
class FormatMethodWithPyramidAction : AnAction() {
24+
override fun getActionUpdateThread(): ActionUpdateThread {
25+
return ActionUpdateThread.BGT
26+
}
2427

2528
override fun update(e: AnActionEvent) {
2629
// 没有打开编辑器的时候禁用按钮
@@ -58,7 +61,7 @@ class FormatMethodWithPyramidAction : AnAction() {
5861
// Check whether some areas are selected
5962
val selectionModel = editor.selectionModel
6063
try {
61-
if (StringUtils.isBlank(selectionModel.selectedText)) {
64+
if (selectionModel.selectedText.isNullOrBlank()) {
6265
// 全部格式化
6366
// Sort all
6467
sortAllClasses(project, editor)
@@ -101,8 +104,8 @@ class FormatMethodWithPyramidAction : AnAction() {
101104
if (o1.isConstructor) {
102105
return@sorted 1
103106
}
104-
val s1 = getJvmStyleSignature(o1, project)
105-
val s2 = getJvmStyleSignature(o2, project)
107+
val s1 = getJvmStyleSignature(o1)
108+
val s2 = getJvmStyleSignature(o2)
106109
s1.length.compareTo(s2.length)
107110
}.collect(Collectors.toList())
108111
if (SortUtil.isSameAfterSort(methods, sortedMethods)) {

src/main/kotlin/com/github/dcsmf/plugin/formatmethods/settings/AppSettingsConfigurable.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
package com.github.dcsmf.plugin.formatmethods.settings
22

33
import com.github.dcsmf.plugin.formatmethods.bundle.SettingsTextBundle.message
4+
import com.intellij.openapi.application.ApplicationManager
45
import com.intellij.openapi.options.BoundConfigurable
5-
import com.intellij.openapi.project.Project
66
import com.intellij.openapi.ui.DialogPanel
77
import com.intellij.ui.dsl.builder.bindSelected
88
import com.intellij.ui.dsl.builder.panel
99

10-
class AppSettingsConfigurable(project: Project) : BoundConfigurable(message("settingName")) {
10+
class AppSettingsConfigurable : BoundConfigurable(message("settingName")) {
1111

12-
private val appSettingsState: AppSettingsState = AppSettingsState.getInstance(project)
12+
private val appSettingsState: AppSettingsState = ApplicationManager.getApplication().getService(AppSettingsState().javaClass)
1313

1414
override fun createPanel(): DialogPanel {
1515
return panel {

src/main/kotlin/com/github/dcsmf/plugin/formatmethods/settings/AppSettingsState.kt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import com.intellij.openapi.components.PersistentStateComponent
44
import com.intellij.openapi.components.Service
55
import com.intellij.openapi.components.State
66
import com.intellij.openapi.components.Storage
7-
import com.intellij.openapi.project.Project
87
import com.intellij.util.xmlb.XmlSerializerUtil
98

109
@Service
@@ -43,11 +42,6 @@ class AppSettingsState : PersistentStateComponent<AppSettingsState> {
4342
*/
4443
var throws: Boolean = true
4544

46-
companion object {
47-
@JvmStatic
48-
fun getInstance(project: Project): AppSettingsState = project.getService(AppSettingsState::class.java)
49-
}
50-
5145
override fun getState(): AppSettingsState = this
5246

5347
override fun loadState(state: AppSettingsState) = XmlSerializerUtil.copyBean(state, this)

src/main/kotlin/com/github/dcsmf/plugin/formatmethods/utils/MethodUtil.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.github.dcsmf.plugin.formatmethods.utils
22

33
import com.github.dcsmf.plugin.formatmethods.settings.AppSettingsState
4-
import com.intellij.openapi.project.Project
4+
import com.intellij.openapi.application.ApplicationManager
55
import com.intellij.psi.PsiKeyword
66
import com.intellij.psi.PsiMethod
77

@@ -16,8 +16,8 @@ object MethodUtil {
1616
* default<T>voidmyMethod(String userId, @NotNull Group group, T t)throws Exception
1717
*/
1818
@JvmStatic
19-
fun getJvmStyleSignature(method: PsiMethod, project: Project): String {
20-
val state: AppSettingsState = AppSettingsState.getInstance(project)
19+
fun getJvmStyleSignature(method: PsiMethod): String {
20+
val state: AppSettingsState = ApplicationManager.getApplication().getService(AppSettingsState().javaClass)
2121
val returnTypeElementText = when (method.returnTypeElement) {
2222
null -> ""
2323
else -> method.returnTypeElement!!.text

src/main/kotlin/com/github/dcsmf/plugin/formatmethods/utils/SortUtil.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import com.github.dcsmf.plugin.formatmethods.model.SelectSortModel
55
import com.intellij.psi.PsiClass
66
import com.intellij.psi.PsiMethod
77
import com.intellij.psi.impl.source.PsiExtensibleClass
8-
import org.apache.commons.lang.ArrayUtils
98

109
object SortUtil {
1110
@JvmStatic
@@ -58,7 +57,7 @@ object SortUtil {
5857
// 还是没找到,范围扩充到查找该类所有方法
5958
// Still not found, the scope expands to find all methods of the class
6059
val methods = currentClass.allMethods
61-
return if (ArrayUtils.isEmpty(methods)) {
60+
return if (methods.isEmpty()) {
6261
SelectSortModel(start, end, InsertType.ADD, null)
6362
} else {
6463
var psiMethods = methods.toList()

0 commit comments

Comments
 (0)