@Override public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) { if (!element.isWritable()) return false; boolean isTwigFile = GravFileTemplateUtil.isTwigTemplateFile(element.getContainingFile()) || element.getContainingFile() instanceof HtmlFileImpl; boolean isXmlAttribute = false; if (!isTwigFile) return false; if (element.getParent() instanceof XmlAttributeValueImpl) { XmlAttributeValueImpl parent0 = ((XmlAttributeValueImpl) element.getParent()); boolean hasTwigElement = PsiTreeUtil.findChildOfType(parent0, OuterLanguageElement.class) != null; if (!hasTwigElement && parent0.getParent() instanceof XmlAttributeImpl) { XmlAttributeImpl parent1 = (XmlAttributeImpl) parent0.getParent(); if (parent1.getName().equalsIgnoreCase("href") || parent1.getName().equalsIgnoreCase("src")) isXmlAttribute = true; } } return isXmlAttribute; }
public void getLanguagesToInject(@NotNull MultiHostRegistrar registrar, @NotNull PsiElement context) { final XmlAttribute attribute = (XmlAttribute)context; if (!XsltSupport.isXPathAttribute(attribute)) return; XmlAttributeValueImpl value = (XmlAttributeValueImpl)attribute.getValueElement(); if (value == null) return; ASTNode type = value.findChildByType(XmlElementType.XML_ENTITY_REF); if (type != null) return; // workaround for inability to inject into text with entity refs (e.g. IDEA-72972) TODO: fix it final XsltChecker.LanguageLevel languageLevel = XsltSupport.getXsltLanguageLevel(attribute.getContainingFile()); final TextRange[] ranges = getInjectionRanges(attribute, languageLevel); for (TextRange range : ranges) { // workaround for http://www.jetbrains.net/jira/browse/IDEA-10096 TextRange rangeInsideHost; String prefix; if (range instanceof AVTRange) { if (((AVTRange)range).myComplete) { rangeInsideHost = range.shiftRight(2).grown(-2); prefix = ""; } else { // we need to keep the "'}' expected" parse error rangeInsideHost = range.shiftRight(2).grown(-1); prefix = "{"; } } else { rangeInsideHost = range; prefix = ""; } if (value.getTextRange().contains(rangeInsideHost.shiftRight(value.getTextRange().getStartOffset()))) { registrar.startInjecting(languageLevel.getXPathVersion().getLanguage()) .addPlace(prefix, "", value, rangeInsideHost) .doneInjecting(); } } }
public static boolean isAsControllerRef(PsiReference ref, PsiElement parent) { if (parent instanceof EmberJSAsExpression && ref == parent.getFirstChild()) { return true; } final InjectedLanguageManager injector = InjectedLanguageManager.getInstance(parent.getProject()); final PsiLanguageInjectionHost host = injector.getInjectionHost(parent); final PsiElement hostParent = host instanceof XmlAttributeValueImpl ? host.getParent() : null; final String normalized = hostParent instanceof XmlAttribute ? ComponentUtil.getAttributeName(((XmlAttribute) hostParent).getName()) : null; // TODO: Do some kind of test return true; // return "ng-controller".equals(normalized); }
public XmlAttributeLiteralEscaper(XmlAttributeValueImpl host) { super(host); PsiElement parent = host.getParent(); myXmlAttribute = parent instanceof XmlAttribute ? (XmlAttribute)parent : XmlElementFactory.getInstance(host.getProject()).createXmlAttribute("a", host.getValue()); }
@NotNull @Override public List<? extends Class<? extends PsiElement>> elementsToInjectIn() { return Arrays.asList(XmlTextImpl.class, XmlAttributeValueImpl.class); }
public XmlAttributeLiteralEscaper(XmlAttributeValueImpl host) { super(host); myXmlAttribute = (XmlAttribute)host.getParent(); }
@Override public void injectLanguages(@NotNull MultiHostRegistrar registrar, @NotNull PsiElement context) { final XmlAttribute attribute = (XmlAttribute) context; if(!XsltSupport.isXPathAttribute(attribute)) { return; } XmlAttributeValueImpl value = (XmlAttributeValueImpl) attribute.getValueElement(); if(value == null) { return; } ASTNode type = value.findChildByType(XmlElementType.XML_ENTITY_REF); if(type != null) { return; // workaround for inability to inject into text with entity refs (e.g. IDEA-72972) TODO: fix it } final XsltChecker.LanguageLevel languageLevel = XsltSupport.getXsltLanguageLevel(attribute.getContainingFile()); final TextRange[] ranges = getInjectionRanges(attribute, languageLevel); for(TextRange range : ranges) { // workaround for http://www.jetbrains.net/jira/browse/IDEA-10096 TextRange rangeInsideHost; String prefix; if(range instanceof AVTRange) { if(((AVTRange) range).myComplete) { rangeInsideHost = range.shiftRight(2).grown(-2); prefix = ""; } else { // we need to keep the "'}' expected" parse error rangeInsideHost = range.shiftRight(2).grown(-1); prefix = "{"; } } else { rangeInsideHost = range; prefix = ""; } if(value.getTextRange().contains(rangeInsideHost.shiftRight(value.getTextRange().getStartOffset()))) { registrar.startInjecting(languageLevel.getXPathVersion().getLanguage()).addPlace(prefix, "", value, rangeInsideHost).doneInjecting(); } } }
public XmlAttributeLiteralEscaper(XmlAttributeValueImpl host) { super(host); PsiElement parent = host.getParent(); myXmlAttribute = parent instanceof XmlAttribute ? (XmlAttribute) parent : XmlElementFactory.getInstance(host.getProject()).createAttribute("a", host.getValue(), parent); }