override fun collectFromElement()

in src/com/intellij/idea/plugin/hybris/codeInsight/hints/DynamicAttributeDeclarativeInlayHintsCollector.kt [35:82]


    override fun collectFromElement(element: PsiElement, sink: InlayTreeSink) {
        if (!element.isValid || element.project.isDefault) return
        if (element !is PsiMethodCallExpression) return

        val method = (if (JavaMethodCallElement.isCompletionMode(element)) CompletionMemory.getChosenMethod(element) else null)
            ?: element.resolveMethodGenerics().element
            ?: return

        if (method !is PsiMethod) return
        val psiClass = method.containingClass ?: return
        if (!TSUtils.isItemModelFile(psiClass)) return

        val meta = TSMetaModelAccess.getInstance(element.project).findMetaItemByName(cleanSearchName(psiClass.name)) ?: return
        val annotation = method.getAnnotation(HybrisConstants.CLASS_FQN_ANNOTATION_ACCESSOR) ?: return

        val qualifier = annotation.parameterList.attributes
            .filter { it.name == Attribute.QUALIFIER }
            .map { it.value }
            .filterIsInstance<PsiLiteralExpression>()
            .map { it.value }
            .firstOrNull { it != null } ?: return

        val attribute = meta.allAttributes[qualifier]
            ?.takeIf { it.persistence.type == PersistenceType.DYNAMIC }
            ?: return

        val identifier = element.methodExpression.lastChild

        val inlayActionData = attribute.persistence
            .attributeHandler
            ?.let { SpringHelper.resolveBeanClass(element, it) }
            ?.let { SmartPointerManager.getInstance(element.project).createSmartPsiElementPointer(it) }
            ?.let {
                InlayActionData(
                    PsiPointerInlayActionPayload(it),
                    DynamicAttributeDeclarativeInlayActionHandler.ID,
                )
            }

        sink.addPresentation(
            position = InlineInlayPosition(identifier.textRange.startOffset, true),
            payloads = null,
            tooltip = "Navigate to the ${meta.name}.${attribute.name} dynamic attribute handler",
            hintFormat = HintFormat.default,
        ) {
            text(message("hybris.ts.type.dynamic") + (inlayActionData?.let { "⌝" } ?: ""), inlayActionData)
        }
    }