InlayHints: cleanup

GitOrigin-RevId: da9e14b390e6530d5d554079ed329f75c674809a
This commit is contained in:
Roman.Ivanov
2019-07-02 07:30:13 +03:00
committed by intellij-monorepo-bot
parent 6fcdce2a61
commit 682fc042b0
@@ -40,18 +40,10 @@ class AnnotationInlayProvider : InlayHintsProvider<AnnotationInlayProvider.Setti
if (nameReferenceElement != null && element.modifierList != null &&
(shownAnnotations.add(nameReferenceElement.qualifiedName) || JavaDocInfoGenerator.isRepeatableAnnotationType(it))) {
val offset = element.modifierList!!.textRange.startOffset
val presentation = annotationPresentation(it)
val menuOnClick = MenuOnClickPresentation(presentation, project) {
val makeExplicit = InsertAnnotationAction(project, file, element)
listOf(
makeExplicit,
ToggleSettingsAction("Turn off external annotations", settings::showExternal),
ToggleSettingsAction("Turn off inferred annotations", settings::showInferred)
)
}
val presentation = createPresentation(it, element)
when (element) {
is PsiMethod -> sink.addBlockElement(offset, true, true, 0, menuOnClick)
else -> sink.addInlineElement(offset, true, menuOnClick)
is PsiMethod -> sink.addBlockElement(offset, false, true, 0, presentation)
else -> sink.addInlineElement(offset, true, presentation)
}
}
}
@@ -59,6 +51,21 @@ class AnnotationInlayProvider : InlayHintsProvider<AnnotationInlayProvider.Setti
return true
}
private fun createPresentation(
annotation: PsiAnnotation,
element: PsiModifierListOwner
): MenuOnClickPresentation {
val presentation = annotationPresentation(annotation)
return MenuOnClickPresentation(presentation, project) {
val makeExplicit = InsertAnnotationAction(project, file, element)
listOf(
makeExplicit,
ToggleSettingsAction("Turn off external annotations", settings::showExternal),
ToggleSettingsAction("Turn off inferred annotations", settings::showInferred)
)
}
}
private fun annotationPresentation(annotation: PsiAnnotation): InsetPresentation = with(factory) {
val nameReferenceElement = annotation.nameReferenceElement
val parameterList = annotation.parameterList