override fun annotate()

in src/com/intellij/idea/plugin/hybris/polyglotQuery/lang/annotation/PolyglotQueryAnnotator.kt [35:84]


    override fun annotate(element: PsiElement, holder: AnnotationHolder) {
        when (element.elementType) {
            IDENTIFIER -> when (element.parent.elementType) {
                TYPE_KEY_NAME -> highlightReference(TYPE_KEY_NAME, holder, element, "hybris.inspections.pgq.unresolved.type.key")
                ATTRIBUTE_KEY_NAME -> highlightReference(ATTRIBUTE_KEY_NAME, holder, element, "hybris.inspections.pgq.unresolved.attribute.key")
                BIND_PARAMETER -> highlight(BIND_PARAMETER, holder, element)
                LOCALIZED_NAME -> {
                    val language = element.text.trim()

                    val propertyService = PropertyService.getInstance(element.project) ?: return
                    val supportedLanguages = propertyService.getLanguages()

                    if (propertyService.containsLanguage(language, supportedLanguages)) {
                        highlight(LOCALIZED_NAME, holder, element)
                    } else {
                        highlightError(
                            holder, element,
                            message(
                                "hybris.inspections.language.unsupported",
                                language,
                                supportedLanguages.joinToString()
                            )
                        )
                    }
                }
            }

            QUESTION_MARK -> when (element.parent.elementType) {
                BIND_PARAMETER -> highlight(BIND_PARAMETER, holder, element)
            }

            LOCALIZED -> {
                element.parent.childrenOfType<PolyglotQueryAttributeKeyName>()
                    .firstOrNull()
                    ?.let { attribute ->
                        val featureName = attribute.text.trim()
                        (attribute.reference as? PsiReferenceBase.Poly<*>)
                            ?.multiResolve(false)
                            ?.firstOrNull()
                            ?.takeIf { !TSResolveResultUtil.isLocalized(it, featureName) }
                            ?.let {
                                highlightError(
                                    holder, element,
                                    message("hybris.inspections.language.unexpected", featureName)
                                )
                            }
                    }
            }
        }
    }