diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInsight/hint/GroovyParameterTypeHintsCollector.kt b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInsight/hint/GroovyParameterTypeHintsCollector.kt index f2ced718dc2f..92397b583eb8 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInsight/hint/GroovyParameterTypeHintsCollector.kt +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInsight/hint/GroovyParameterTypeHintsCollector.kt @@ -3,11 +3,16 @@ package org.jetbrains.plugins.groovy.codeInsight.hint import com.intellij.codeInsight.hints.FactoryInlayHintsCollector import com.intellij.codeInsight.hints.InlayHintsSink +import com.intellij.codeInsight.hints.presentation.InlayPresentation import com.intellij.openapi.editor.Editor import com.intellij.psi.CommonClassNames import com.intellij.psi.PsiElement +import com.intellij.psi.PsiType +import com.intellij.refactoring.suggested.endOffset import org.jetbrains.plugins.groovy.intentions.style.inference.MethodParameterAugmenter import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifier.DEF +import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable +import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod import org.jetbrains.plugins.groovy.lang.psi.dataFlow.types.TypeAugmenter @@ -22,13 +27,16 @@ class GroovyParameterTypeHintsCollector(editor: Editor, return false } if (element is GrParameter && element.typeElement == null && !element.isVarArgs) { - val type = (GrVariableEnhancer.getEnhancedType(element) - ?: TypeAugmenter.inferAugmentedType(element)) - ?.takeIf { !it.equalsToText(CommonClassNames.JAVA_LANG_OBJECT) } - ?: return true + val type: PsiType = getRepresentableType(element) ?: return true val typeRepresentation = factory.buildRepresentation(type, " ").run { factory.roundWithBackground(this) } sink.addInlineElement(element.textOffset, false, typeRepresentation) } + if (element is GrClosableBlock && element.parameterList.isEmpty) { + val itParameter: GrParameter = element.allParameters.singleOrNull() ?: return true + val type: PsiType = getRepresentableType(itParameter) ?: return true + val textRepresentation: InlayPresentation = factory.roundWithBackground(factory.buildRepresentation(type, " it -> ")) + sink.addInlineElement(element.lBrace.endOffset, true, textRepresentation) + } if (settings.showTypeParameterList && element is GrMethod && !element.hasTypeParameters() && @@ -46,4 +54,9 @@ class GroovyParameterTypeHintsCollector(editor: Editor, return true } + private fun getRepresentableType(variable: GrVariable): PsiType? { + val inferredType: PsiType? = GrVariableEnhancer.getEnhancedType(variable) ?: TypeAugmenter.inferAugmentedType(variable) + return inferredType?.takeIf { !it.equalsToText(CommonClassNames.JAVA_LANG_OBJECT) } + } + } \ No newline at end of file