Skip to content

Commit 744f851

Browse files
committed
style: detekt
1 parent 28365d9 commit 744f851

File tree

5 files changed

+27
-24
lines changed

5 files changed

+27
-24
lines changed

detekt.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# https://github.com/detekt/detekt/blob/master/detekt-core/src/main/resources/default-detekt-config.yml
33

44
build:
5-
maxIssues: 22 #todo: zero out
5+
maxIssues: 18 #todo: zero out
66

77
formatting:
88
Indentation:

marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/service/JVMArtifactCreationService.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import java.util.*
4646
* @since 0.4.0
4747
* @author [Brandon Fergerson](mailto:bfergerson@apache.org)
4848
*/
49+
@Suppress("TooManyFunctions") // public API
4950
class JVMArtifactCreationService : IArtifactCreationService {
5051

5152
companion object {

marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/service/JVMArtifactMarkService.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import com.intellij.ui.treeStructure.SimpleNode
2525
import spp.jetbrains.marker.SourceMarkerUtils
2626
import spp.jetbrains.marker.jvm.presentation.JVMVariableNode
2727
import spp.jetbrains.marker.jvm.service.utils.JVMMarkerUtils
28+
import spp.jetbrains.marker.service.ArtifactTypeService
2829
import spp.jetbrains.marker.service.define.IArtifactMarkService
2930
import spp.jetbrains.marker.source.mark.api.SourceMark
3031
import spp.jetbrains.marker.source.mark.inlay.config.InlayMarkVirtualText
@@ -64,13 +65,13 @@ class JVMArtifactMarkService : IArtifactMarkService {
6465
)
6566
}
6667
} else {
67-
if (JVMMarkerUtils.isJvmMethod(statement.parent)) {
68+
if (ArtifactTypeService.isFunction(statement.parent)) {
6869
virtualText.spacingTillMethodText = SourceMarkerUtils.getPrefixSpacingCount(statement.parent)
6970
}
7071

7172
var startOffset = statement.textRange.startOffset
7273
if (virtualText.showBeforeAnnotationsWhenBlock) {
73-
if (JVMMarkerUtils.isJvmMethod(statement.parent)) {
74+
if (ArtifactTypeService.isFunction(statement.parent)) {
7475
val annotations = JVMMarkerUtils.getMethodAnnotations(statement.parent)
7576
if (annotations.isNotEmpty()) {
7677
startOffset = annotations[0].textRange.startOffset

marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/service/utils/JVMMarkerUtils.kt

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ object JVMMarkerUtils {
6464
)?.let { getFullyQualifiedName(it) }
6565
}
6666
if (parentIdentifier == null) {
67-
error("Could not determine parent of element: $element") //todo: extension function, see SourceMarkerConfig, make test, groovy import statements
67+
//todo: extension function, see SourceMarkerConfig, make test, groovy import statements
68+
error("Could not determine parent of element: $element")
6869
}
6970

7071
element.textRange.startOffset.let {
@@ -130,13 +131,7 @@ object JVMMarkerUtils {
130131
)
131132
}
132133

133-
fun isJvmMethod(element: PsiElement): Boolean {
134-
return element is PsiMethod || element is KtFunction
135-
}
136-
137134
fun getMethodAnnotations(element: PsiElement): List<PsiElement> {
138-
require(isJvmMethod(element)) { "Element is not a JVM method: $element" }
139-
140135
return when (element) {
141136
is PsiMethod -> element.annotations.toList()
142137
is KtFunction -> element.annotationEntries

marker/src/main/kotlin/spp/jetbrains/marker/plugin/SourceInlayHintProvider.kt

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import com.intellij.openapi.application.ApplicationManager
2424
import com.intellij.openapi.diagnostic.logger
2525
import com.intellij.openapi.editor.DefaultLanguageHighlighterColors.INLINE_PARAMETER_HINT
2626
import com.intellij.openapi.editor.Editor
27+
import com.intellij.openapi.editor.Inlay
2728
import com.intellij.openapi.editor.colors.EditorFontType
2829
import com.intellij.openapi.editor.impl.EditorImpl
2930
import com.intellij.openapi.editor.markup.EffectType
@@ -36,6 +37,7 @@ import com.intellij.ui.paint.EffectPainter
3637
import org.joor.Reflect
3738
import spp.jetbrains.marker.SourceMarker
3839
import spp.jetbrains.marker.service.ArtifactMarkService
40+
import spp.jetbrains.marker.source.mark.api.SourceMark
3941
import spp.jetbrains.marker.source.mark.api.event.SourceMarkEventCode.MARK_REMOVED
4042
import spp.jetbrains.marker.source.mark.api.event.SourceMarkEventListener
4143
import spp.jetbrains.marker.source.mark.api.key.SourceKey
@@ -100,20 +102,7 @@ class SourceInlayHintProvider : InlayHintsProvider<NoSettings> {
100102
FileEditorManager.getInstance(event.sourceMark.project).selectedTextEditor?.inlayModel
101103
//todo: smaller range
102104
?.getBlockElementsInRange(0, Integer.MAX_VALUE)?.forEach {
103-
if (it.renderer is BlockInlayRenderer) {
104-
val cachedPresentation = Reflect.on(it.renderer).field("cachedPresentation").get<Any>()
105-
if (cachedPresentation is RecursivelyUpdatingRootPresentation) {
106-
if (cachedPresentation.content is StaticDelegatePresentation) {
107-
val delegatePresentation = cachedPresentation.content as StaticDelegatePresentation
108-
if (delegatePresentation.presentation is DynamicTextInlayPresentation) {
109-
val dynamicPresentation = delegatePresentation.presentation as DynamicTextInlayPresentation
110-
if (dynamicPresentation.inlayMark == event.sourceMark) {
111-
Disposer.dispose(it)
112-
}
113-
}
114-
}
115-
}
116-
}
105+
disposeInlayIfNecessary(it, event.sourceMark)
117106
}
118107

119108
InlayHintsPassFactory.forceHintsUpdateOnNextPass()
@@ -122,6 +111,23 @@ class SourceInlayHintProvider : InlayHintsProvider<NoSettings> {
122111
}
123112
}
124113

114+
private fun disposeInlayIfNecessary(it: Inlay<*>, sourceMark: SourceMark) {
115+
if (it.renderer is BlockInlayRenderer) {
116+
val cachedPresentation = Reflect.on(it.renderer).field("cachedPresentation").get<Any>()
117+
if (cachedPresentation is RecursivelyUpdatingRootPresentation) {
118+
if (cachedPresentation.content is StaticDelegatePresentation) {
119+
val delegatePresentation = cachedPresentation.content as StaticDelegatePresentation
120+
if (delegatePresentation.presentation is DynamicTextInlayPresentation) {
121+
val dynamicPresentation = delegatePresentation.presentation as DynamicTextInlayPresentation
122+
if (dynamicPresentation.inlayMark == sourceMark) {
123+
Disposer.dispose(it)
124+
}
125+
}
126+
}
127+
}
128+
}
129+
}
130+
125131
@Volatile
126132
@JvmField
127133
var latestInlayMarkAddedAt: Long = -1L

0 commit comments

Comments
 (0)