Skip to content

Commit

Permalink
未做完的函数签名
Browse files Browse the repository at this point in the history
  • Loading branch information
dcsmf committed Jun 14, 2023
1 parent 8055100 commit 22f8a5d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.github.dcsmf.intellijformatmethodsplugin.bundle.TextBundle
import com.github.dcsmf.intellijformatmethodsplugin.model.InsertType
import com.github.dcsmf.intellijformatmethodsplugin.model.SelectSortModel
import com.github.dcsmf.intellijformatmethodsplugin.utils.ElementUtil
import com.github.dcsmf.intellijformatmethodsplugin.utils.MethodUtil.getJvmStyleSignature
import com.github.dcsmf.intellijformatmethodsplugin.utils.NotifyUtil
import com.github.dcsmf.intellijformatmethodsplugin.utils.SortUtil
import com.intellij.openapi.actionSystem.AnAction
Expand Down Expand Up @@ -78,15 +79,21 @@ class FormatMethodWithPyramidAction : AnAction() {
if (methods.isEmpty()) {
return 0
}

var sortModel: SelectSortModel? = null
if (start != -1 || end != -1) {
sortModel = SortUtil.getSelectSortModel(currentPsiClass, start, end, methods.toList())
methods = methods.filter { it.textRange.endOffset in start..end }.toTypedArray()
}
val sortedMethods = methods.stream().sorted { o1, o2 ->
o1.getSignature(PsiSubstitutor.EMPTY).toString().length.compareTo(
o2.getSignature(PsiSubstitutor.EMPTY).toString().length
)
if (o1.isConstructor) {
return@sorted 1
}
val s1 = getJvmStyleSignature(o1)
val s2 = getJvmStyleSignature(o2)

// s1.length.compareTo(s2.length)
1
}.collect(Collectors.toList())
if (SortUtil.isSameAfterSort(methods, sortedMethods)) {
return 0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.github.dcsmf.intellijformatmethodsplugin.utils

import com.intellij.psi.PsiMethod

object MethodUtil {
/**
* 构建带权限标识符、返回类型、泛型声明、函数名、参数列表和throws的JVM风格函数定义
* default <T> void buildDefaultField(String userId, @NotNull Group group, T t) throws Exception {System.out.println(t);}
*
*/
@JvmStatic
fun getJvmStyleSignature(method: PsiMethod): String {
if(method.isConstructor){
val returnTypeElement=method.returnTypeElement
}
return with(method) {
modifierList.text
}
}
}

0 comments on commit 22f8a5d

Please sign in to comment.