Search in sources :

Example 76 with XmlAttribute

use of com.intellij.psi.xml.XmlAttribute 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)

Example 77 with XmlAttribute

use of com.intellij.psi.xml.XmlAttribute in project intellij-plugins by JetBrains.

the class DartPackagePathReferenceProvider method getFilter.

public static ElementFilter getFilter() {
    return new ElementFilter() {

        @Override
        public boolean isAcceptable(Object _element, PsiElement context) {
            if (!(_element instanceof PsiElement))
                return false;
            final PsiElement element = (PsiElement) _element;
            final PsiElement parentElement = element.getParent();
            final PsiFile file = element.getContainingFile().getOriginalFile();
            final VirtualFile vFile = file.getVirtualFile();
            return vFile != null && HtmlUtil.hasHtml(file) && parentElement instanceof XmlAttribute && canContainDartPackageReference(((XmlAttribute) parentElement).getParent().getLocalName(), ((XmlAttribute) parentElement).getName()) && PubspecYamlUtil.findPubspecYamlFile(element.getProject(), vFile) != null;
        }

        @Override
        public boolean isClassAcceptable(Class hintClass) {
            return true;
        }
    };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) XmlAttribute(com.intellij.psi.xml.XmlAttribute) ElementFilter(com.intellij.psi.filters.ElementFilter)

Example 78 with XmlAttribute

use of com.intellij.psi.xml.XmlAttribute in project intellij-plugins by JetBrains.

the class FlexXmlBackedMembersIndex method getItemsByName.

public static Collection<NavigationItem> getItemsByName(final String name, Project project) {
    Collection<VirtualFile> files = FileBasedIndex.getInstance().getContainingFiles(NAME, name, GlobalSearchScope.projectScope(project));
    final Collection<NavigationItem> result = new ArrayList<>();
    for (VirtualFile vFile : files) {
        PsiFile file = PsiManager.getInstance(project).findFile(vFile);
        if (!(file instanceof XmlFile)) {
            continue;
        }
        process((XmlFile) file, element -> {
            if (name.equals(getName(element))) {
                if (element instanceof JSNamedElement) {
                    result.add((JSNamedElement) element);
                } else {
                    XmlAttribute id = ((XmlTag) element).getAttribute("id");
                    if (id != null) {
                        XmlAttributeValue valueElement = id.getValueElement();
                        PsiElement[] children;
                        if (valueElement != null && (children = valueElement.getChildren()).length == 3) {
                            result.add(new TagNavigationItem(children[1], name));
                        }
                    }
                }
            }
        }, true);
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlFile(com.intellij.psi.xml.XmlFile) ArrayList(java.util.ArrayList) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) NavigationItem(com.intellij.navigation.NavigationItem) PsiElementNavigationItem(com.intellij.navigation.PsiElementNavigationItem) JSNamedElement(com.intellij.lang.javascript.psi.JSNamedElement) FakePsiElement(com.intellij.psi.impl.FakePsiElement) XmlTag(com.intellij.psi.xml.XmlTag)

Example 79 with XmlAttribute

use of com.intellij.psi.xml.XmlAttribute in project intellij-plugins by JetBrains.

the class MxmlJSClass method addToImplementsList.

@Override
public void addToImplementsList(String refText) {
    XmlAttribute attribute = getParent().getAttribute(IMPLEMENTS_ATTRIBUTE);
    if (attribute == null) {
        getParent().setAttribute(IMPLEMENTS_ATTRIBUTE, refText);
    } else {
        attribute.setValue(attribute.getValue() + ", " + refText);
    }
    myImplementsList = null;
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute)

Example 80 with XmlAttribute

use of com.intellij.psi.xml.XmlAttribute in project intellij-plugins by JetBrains.

the class MxmlJSClass method removeFromImplementsList.

@Override
public void removeFromImplementsList(String refText) {
    String[] refs = getImplementsList().getReferenceTexts();
    LOG.assertTrue(ArrayUtil.contains(refText, refs));
    XmlAttribute attribute = getParent().getAttribute(IMPLEMENTS_ATTRIBUTE);
    if (refs.length == 1) {
        attribute.delete();
    } else {
        String[] newRefs = ArrayUtil.remove(refs, refText);
        attribute.setValue(StringUtil.join(newRefs, ", "));
    }
    myImplementsList = null;
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute)

Aggregations

XmlAttribute (com.intellij.psi.xml.XmlAttribute)220 XmlTag (com.intellij.psi.xml.XmlTag)116 PsiElement (com.intellij.psi.PsiElement)60 XmlAttributeValue (com.intellij.psi.xml.XmlAttributeValue)57 NotNull (org.jetbrains.annotations.NotNull)44 XmlFile (com.intellij.psi.xml.XmlFile)37 Nullable (org.jetbrains.annotations.Nullable)27 Project (com.intellij.openapi.project.Project)25 VirtualFile (com.intellij.openapi.vfs.VirtualFile)20 TextRange (com.intellij.openapi.util.TextRange)18 XmlAttributeDescriptor (com.intellij.xml.XmlAttributeDescriptor)18 ArrayList (java.util.ArrayList)18 PsiFile (com.intellij.psi.PsiFile)17 PsiReference (com.intellij.psi.PsiReference)17 IncorrectOperationException (com.intellij.util.IncorrectOperationException)10 DomElement (com.intellij.util.xml.DomElement)10 Result (com.intellij.openapi.application.Result)9 XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)9 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)8 XmlElement (com.intellij.psi.xml.XmlElement)6