summaryrefslogtreecommitdiff
path: root/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInsight/hint/types/GroovyLocalVariableTypeHintsInlayProvider.kt
blob: 151707132aaf98a3ffc1de20991654b96806a845 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.plugins.groovy.codeInsight.hint.types

import com.intellij.codeInsight.hints.*
import com.intellij.openapi.editor.Editor
import com.intellij.psi.PsiFile
import com.intellij.ui.layout.*
import org.jetbrains.plugins.groovy.GroovyBundle
import javax.swing.JPanel

class GroovyLocalVariableTypeHintsInlayProvider : InlayHintsProvider<GroovyLocalVariableTypeHintsInlayProvider.Settings> {
  companion object {
    private val ourKey: SettingsKey<Settings> = SettingsKey("groovy.variable.type.hints")
  }

  override fun getCollectorFor(file: PsiFile, editor: Editor, settings: Settings, sink: InlayHintsSink): InlayHintsCollector = GroovyLocalVariableTypeHintsCollector(editor, settings)

  override fun createSettings(): Settings = Settings()

  data class Settings(var insertBeforeIdentifier : Boolean = false)

  override val name: String = GroovyBundle.message("local.variable.types")
  override val key: SettingsKey<Settings> = ourKey
  override val group: InlayGroup
    get() = InlayGroup.TYPES_GROUP

  override fun getProperty(key: String): String {
    return GroovyBundle.message(key)
  }

  override val previewText: String = """
def foo() {
  def x = 1
  var y = "abc"
}
  """.trimIndent()

  override fun createConfigurable(settings: Settings): ImmediateConfigurable = object : ImmediateConfigurable {
    override val cases: List<ImmediateConfigurable.Case> = listOf(
      ImmediateConfigurable.Case(GroovyBundle.message("settings.inlay.put.type.hint.before.identifier"), "inferred.parameter.types", settings::insertBeforeIdentifier),
    )

    override fun createComponent(listener: ChangeListener): JPanel = panel {}

    override val mainCheckboxText: String
      get() = GroovyBundle.message("settings.inlay.show.variable.type.hints")
  }
}