|
11 | 11 | package com.demonwav.mcdev.platform.mixin.folding |
12 | 12 |
|
13 | 13 | import com.demonwav.mcdev.platform.mixin.MixinModuleType |
| 14 | +import com.demonwav.mcdev.platform.mixin.reference.target.TargetReference |
14 | 15 | import com.demonwav.mcdev.platform.mixin.util.MixinConstants.Annotations.AT |
15 | | -import com.demonwav.mcdev.platform.mixin.util.MixinMemberReference |
16 | | -import com.demonwav.mcdev.util.constantStringValue |
17 | 16 | import com.intellij.lang.ASTNode |
18 | 17 | import com.intellij.lang.folding.CustomFoldingBuilder |
19 | 18 | import com.intellij.lang.folding.FoldingDescriptor |
| 19 | +import com.intellij.navigation.NavigationItem |
20 | 20 | import com.intellij.openapi.editor.Document |
21 | 21 | import com.intellij.openapi.util.TextRange |
22 | 22 | import com.intellij.psi.CommonClassNames |
@@ -50,27 +50,25 @@ class MixinFoldingBuilder : CustomFoldingBuilder() { |
50 | 50 | } |
51 | 51 | } |
52 | 52 |
|
| 53 | + private fun formatElement(element: PsiElement): String? { |
| 54 | + return when (element) { |
| 55 | + is PsiMethod -> PsiFormatUtil.formatMethod(element, PsiSubstitutor.EMPTY, |
| 56 | + PsiFormatUtilBase.SHOW_NAME or PsiFormatUtilBase.SHOW_PARAMETERS or SHOW_CONTAINING_CLASS, |
| 57 | + PsiFormatUtilBase.SHOW_TYPE) |
| 58 | + is PsiVariable -> PsiFormatUtil.formatVariable(element, |
| 59 | + PsiFormatUtilBase.SHOW_NAME or SHOW_CONTAINING_CLASS, PsiSubstitutor.EMPTY) |
| 60 | + is NavigationItem -> element.presentation?.presentableText |
| 61 | + else -> null |
| 62 | + } |
| 63 | + } |
| 64 | + |
53 | 65 | override fun getLanguagePlaceholderText(node: ASTNode, range: TextRange): String { |
54 | 66 | val element = node.psi |
55 | | - when (element) { |
56 | | - is PsiTypeCastExpression -> { |
57 | | - val castText = element.castType?.text ?: return node.text |
58 | | - return "($castText)" |
59 | | - } |
60 | | - is PsiAnnotationMemberValue -> { |
61 | | - val value = element.constantStringValue ?: return node.text |
62 | | - val member = MixinMemberReference.parse(value)?.resolveMember(element.project, element.resolveScope) ?: return node.text |
63 | | - return when (member) { |
64 | | - is PsiMethod -> PsiFormatUtil.formatMethod(member, PsiSubstitutor.EMPTY, |
65 | | - PsiFormatUtilBase.SHOW_NAME or PsiFormatUtilBase.SHOW_PARAMETERS or SHOW_CONTAINING_CLASS, |
66 | | - PsiFormatUtilBase.SHOW_TYPE) |
67 | | - is PsiVariable -> PsiFormatUtil.formatVariable(member, PsiFormatUtilBase.SHOW_NAME or SHOW_CONTAINING_CLASS, PsiSubstitutor.EMPTY) |
68 | | - else -> member.presentation?.presentableText ?: node.text |
69 | | - } |
70 | | - } |
| 67 | + return when (element) { |
| 68 | + is PsiTypeCastExpression -> "(${element.castType?.text ?: return node.text})" |
| 69 | + is PsiAnnotationMemberValue -> TargetReference.resolveTarget(element)?.let { formatElement(it) } ?: node.text |
| 70 | + else -> node.text |
71 | 71 | } |
72 | | - |
73 | | - return node.text |
74 | 72 | } |
75 | 73 |
|
76 | 74 | override fun buildLanguageFoldRegions(descriptors: MutableList<FoldingDescriptor>, root: PsiElement, document: Document, quick: Boolean) { |
|
0 commit comments