method chain inlays: don't repeat same types to reduce visual noise

GitOrigin-RevId: da0a4065ec33f4c2b2530c640c7d945dba5cefd7
This commit is contained in:
Anna Kozlova
2019-07-04 01:31:35 +03:00
committed by intellij-monorepo-bot
parent 2f1abbd6a0
commit ace2a64535
2 changed files with 4 additions and 4 deletions
@@ -13,9 +13,6 @@ import com.intellij.util.ui.JBUI
import com.siyeh.ig.psiutils.ExpressionUtils
import org.intellij.lang.annotations.Language
import javax.swing.JPanel
import javax.swing.event.ChangeEvent
import javax.swing.event.DocumentEvent
import javax.swing.event.DocumentListener
class MethodChainsInlayProvider : InlayHintsProvider<MethodChainsInlayProvider.Settings> {
override fun getCollectorFor(file: PsiFile, editor: Editor, settings: Settings, sink: InlayHintsSink) =
@@ -41,8 +38,11 @@ class MethodChainsInlayProvider : InlayHintsProvider<MethodChainsInlayProvider.S
}
if (uniqueTypes.size < settings.uniqueTypeCount) return true // to hide hints for builders, where type is obvious
val javaFactory = JavaTypeHintsPresentationFactory(factory, 3)
var lastType : PsiType? = null
for ((index, currentCall) in chain.withIndex()) {
val type = types[index]
if (lastType == type) continue
lastType = type
val presentation = javaFactory.typeHint(type)
val project = file.project
val finalPresentation = InsetPresentation(MenuOnClickPresentation(presentation, project) {
@@ -74,7 +74,7 @@ public class Chains {
public static void main(String[] args) {
new A()
.b()<hint text="[Chains . B]"/>
.c().b()<hint text="[Chains . B]"/>
.c().b()
.a()<hint text="[Chains . A]"/>
.c()<hint text="[Chains . C]"/>
.b()<hint text="[Chains . B]"/>