Search in sources :

Example 1 with Definition

use of com.intellij.struts.dom.tiles.Definition in project intellij-plugins by JetBrains.

the class TilesOgnlInjector method getLanguagesToInject.

@Override
public void getLanguagesToInject(@NotNull MultiHostRegistrar registrar, @NotNull PsiElement context) {
    final PsiFile containingFile = context.getContainingFile();
    if (!JamCommonUtil.isPlainXmlFile(containingFile)) {
        return;
    }
    assert context instanceof XmlAttributeValue;
    if (!((XmlAttributeValue) context).getValue().startsWith(OGNL_PREFIX)) {
        return;
    }
    PsiElement parent = context.getParent();
    if (parent instanceof XmlAttribute) {
        String name = ((XmlAttribute) parent).getLocalName();
        if ("expression".equals(name) || "templateExpression".equals(name)) {
            DomElement domElement = DomManager.getDomManager(context.getProject()).getDomElement((XmlTag) parent.getParent());
            if (domElement instanceof Put || domElement instanceof Add || domElement instanceof Definition) {
                final TextRange attributeTextRange = ElementManipulators.getValueTextRange(context);
                final TextRange ognlTextRange = TextRange.from(attributeTextRange.getStartOffset() + OGNL_PREFIX.length(), attributeTextRange.getLength() - OGNL_PREFIX.length());
                registrar.startInjecting(OgnlLanguage.INSTANCE).addPlace(OgnlLanguage.EXPRESSION_PREFIX, OgnlLanguage.EXPRESSION_SUFFIX, (PsiLanguageInjectionHost) context, ognlTextRange).doneInjecting();
            }
        }
    }
}
Also used : Add(com.intellij.struts.dom.tiles.Add) XmlAttribute(com.intellij.psi.xml.XmlAttribute) DomElement(com.intellij.util.xml.DomElement) PsiLanguageInjectionHost(com.intellij.psi.PsiLanguageInjectionHost) Definition(com.intellij.struts.dom.tiles.Definition) PsiFile(com.intellij.psi.PsiFile) TextRange(com.intellij.openapi.util.TextRange) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) PsiElement(com.intellij.psi.PsiElement) Put(com.intellij.struts.dom.tiles.Put)

Aggregations

TextRange (com.intellij.openapi.util.TextRange)1 PsiElement (com.intellij.psi.PsiElement)1 PsiFile (com.intellij.psi.PsiFile)1 PsiLanguageInjectionHost (com.intellij.psi.PsiLanguageInjectionHost)1 XmlAttribute (com.intellij.psi.xml.XmlAttribute)1 XmlAttributeValue (com.intellij.psi.xml.XmlAttributeValue)1 Add (com.intellij.struts.dom.tiles.Add)1 Definition (com.intellij.struts.dom.tiles.Definition)1 Put (com.intellij.struts.dom.tiles.Put)1 DomElement (com.intellij.util.xml.DomElement)1