Search in sources :

Example 71 with DomElement

use of com.intellij.util.xml.DomElement in project intellij-community by JetBrains.

the class MavenDomGutterAnnotator method annotateMavenDomPlugin.

private static void annotateMavenDomPlugin(@NotNull MavenDomPlugin plugin, @NotNull AnnotationHolder holder) {
    XmlTag xmlTag = plugin.getArtifactId().getXmlTag();
    if (xmlTag == null)
        return;
    DomElement plugins = plugin.getParent();
    if (plugins == null)
        return;
    DomElement parent = plugins.getParent();
    if (parent instanceof MavenDomPluginManagement) {
        annotateMavenDomPluginInManagement(plugin, holder);
        return;
    }
    MavenDomPlugin managingPlugin = MavenDomProjectProcessorUtils.searchManagingPlugin(plugin);
    if (managingPlugin != null) {
        NavigationGutterIconBuilder<MavenDomPlugin> iconBuilder = NavigationGutterIconBuilder.create(AllIcons.General.OverridingMethod, PluginConverter.INSTANCE);
        iconBuilder.setTargets(Collections.singletonList(managingPlugin)).setTooltipText(MavenDomBundle.message("overriden.plugin.title")).install(holder, xmlTag);
    }
}
Also used : DomElement(com.intellij.util.xml.DomElement) XmlTag(com.intellij.psi.xml.XmlTag)

Example 72 with DomElement

use of com.intellij.util.xml.DomElement in project intellij-community by JetBrains.

the class DomElementsGroupNode method hasErrors.

private boolean hasErrors() {
    if (!myParentElement.isValid())
        return false;
    for (DomElement domElement : myChildDescription.getStableValues(myParentElement)) {
        final DomElementAnnotationsManager annotationsManager = DomElementAnnotationsManager.getInstance(getProject());
        final DomElementsProblemsHolder holder = annotationsManager.getCachedProblemHolder(domElement);
        final List<DomElementProblemDescriptor> problems = holder.getProblems(domElement, true, HighlightSeverity.ERROR);
        if (problems.size() > 0)
            return true;
    }
    return false;
}
Also used : DomElementsProblemsHolder(com.intellij.util.xml.highlighting.DomElementsProblemsHolder) DomElement(com.intellij.util.xml.DomElement) DomElementProblemDescriptor(com.intellij.util.xml.highlighting.DomElementProblemDescriptor) DomElementAnnotationsManager(com.intellij.util.xml.highlighting.DomElementAnnotationsManager)

Example 73 with DomElement

use of com.intellij.util.xml.DomElement in project intellij-community by JetBrains.

the class RemoveDomElementQuickFix method applyFix.

@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
    if (myIsTag) {
        final XmlTag tag = (XmlTag) descriptor.getPsiElement();
        final XmlTag parentTag = tag.getParentTag();
        final DomElement domElement = DomManager.getDomManager(project).getDomElement(tag);
        assert domElement != null;
        domElement.undefine();
        if (parentTag != null && parentTag.isValid()) {
            parentTag.collapseIfEmpty();
        }
    } else {
        final DomElement domElement = DomManager.getDomManager(project).getDomElement((XmlAttribute) descriptor.getPsiElement());
        assert domElement != null;
        domElement.undefine();
    }
}
Also used : DomElement(com.intellij.util.xml.DomElement) XmlTag(com.intellij.psi.xml.XmlTag)

Example 74 with DomElement

use of com.intellij.util.xml.DomElement in project intellij-community by JetBrains.

the class AbstractDomChildrenDescriptor method getElementDescriptor.

@Override
@Nullable
public XmlElementDescriptor getElementDescriptor(@NotNull final XmlTag childTag, @Nullable XmlTag contextTag) {
    DomElement domElement = myManager.getDomElement(childTag);
    if (domElement == null) {
        domElement = myManager.getDomElement(contextTag);
        if (domElement != null) {
            AbstractDomChildrenDescription description = myManager.findChildrenDescription(childTag, domElement);
            if (description instanceof DomChildrenDescription) {
                return new DomElementXmlDescriptor((DomChildrenDescription) description, myManager);
            }
        }
        return null;
    }
    final DomElement parent = domElement.getParent();
    if (parent == null)
        return new DomElementXmlDescriptor(domElement);
    final AbstractDomChildrenDescription description = domElement.getChildDescription();
    if (description instanceof CustomDomChildrenDescription) {
        final DomElement finalDomElement = domElement;
        return new AbstractDomChildrenDescriptor(myManager) {

            @Override
            public String getDefaultName() {
                return finalDomElement.getXmlElementName();
            }

            @Override
            @Nullable
            public PsiElement getDeclaration() {
                final PomTarget target = ((CustomDomChildrenDescription) description).getTagNameDescriptor().findDeclaration(finalDomElement);
                if (target == description) {
                    return childTag;
                }
                return target == null ? null : PomService.convertToPsi(childTag.getProject(), target);
            }
        };
    }
    if (!(description instanceof DomChildrenDescription))
        return null;
    return new DomElementXmlDescriptor((DomChildrenDescription) description, myManager);
}
Also used : PomTarget(com.intellij.pom.PomTarget) DomElement(com.intellij.util.xml.DomElement) Nullable(org.jetbrains.annotations.Nullable)

Example 75 with DomElement

use of com.intellij.util.xml.DomElement in project intellij-community by JetBrains.

the class AbstractDomChildrenDescriptor method getElementsDescriptors.

@Override
public XmlElementDescriptor[] getElementsDescriptors(final XmlTag context) {
    final DomElement domElement = myManager.getDomElement(context);
    if (domElement == null)
        return EMPTY_ARRAY;
    List<XmlElementDescriptor> xmlElementDescriptors = new ArrayList<>();
    for (DomCollectionChildDescription childrenDescription : domElement.getGenericInfo().getCollectionChildrenDescriptions()) {
        xmlElementDescriptors.add(new DomElementXmlDescriptor(childrenDescription, myManager));
    }
    for (DomFixedChildDescription childrenDescription : domElement.getGenericInfo().getFixedChildrenDescriptions()) {
        xmlElementDescriptors.add(new DomElementXmlDescriptor(childrenDescription, myManager));
    }
    final List<? extends CustomDomChildrenDescription> customs = domElement.getGenericInfo().getCustomNameChildrenDescription();
    for (final CustomDomChildrenDescription custom : customs) {
        final CustomDomChildrenDescription.TagNameDescriptor tagNameDescriptor = custom.getTagNameDescriptor();
        if (tagNameDescriptor == null)
            continue;
        final XmlTag xmlTag = domElement.getXmlTag();
        for (final EvaluatedXmlName name : tagNameDescriptor.getCompletionVariants(domElement)) {
            AbstractDomChildrenDescriptor descriptor = new AbstractDomChildrenDescriptor(myManager) {

                @Override
                public String getDefaultName() {
                    final String ns = xmlTag != null ? name.getNamespace(xmlTag, (XmlFile) xmlTag.getContainingFile()) : null;
                    if (ns != null) {
                        final String prefix = xmlTag.getPrefixByNamespace(ns);
                        if (prefix != null) {
                            return prefix + ":" + name.getXmlName().getLocalName();
                        }
                    }
                    return name.getXmlName().getLocalName();
                }

                @Override
                @Nullable
                public PsiElement getDeclaration() {
                    final PomTarget target = tagNameDescriptor.findDeclaration(domElement, name);
                    return target == null ? null : PomService.convertToPsi(context.getProject(), target);
                }
            };
            xmlElementDescriptors.add(descriptor);
        }
        xmlElementDescriptors.add(new AnyXmlElementDescriptor(this, getNSDescriptor()));
    }
    return xmlElementDescriptors.toArray(new XmlElementDescriptor[xmlElementDescriptors.size()]);
}
Also used : EvaluatedXmlName(com.intellij.util.xml.EvaluatedXmlName) AnyXmlElementDescriptor(com.intellij.xml.impl.schema.AnyXmlElementDescriptor) XmlFile(com.intellij.psi.xml.XmlFile) ArrayList(java.util.ArrayList) PomTarget(com.intellij.pom.PomTarget) DomElement(com.intellij.util.xml.DomElement) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) AnyXmlElementDescriptor(com.intellij.xml.impl.schema.AnyXmlElementDescriptor) XmlTag(com.intellij.psi.xml.XmlTag)

Aggregations

DomElement (com.intellij.util.xml.DomElement)97 XmlTag (com.intellij.psi.xml.XmlTag)34 PsiElement (com.intellij.psi.PsiElement)19 Nullable (org.jetbrains.annotations.Nullable)19 NotNull (org.jetbrains.annotations.NotNull)15 Project (com.intellij.openapi.project.Project)11 PsiFile (com.intellij.psi.PsiFile)11 XmlFile (com.intellij.psi.xml.XmlFile)11 XmlAttribute (com.intellij.psi.xml.XmlAttribute)10 XmlAttributeValue (com.intellij.psi.xml.XmlAttributeValue)9 ArrayList (java.util.ArrayList)8 LayoutViewElement (org.jetbrains.android.dom.layout.LayoutViewElement)7 ResourceElement (org.jetbrains.android.dom.resources.ResourceElement)6 DomManager (com.intellij.util.xml.DomManager)5 Style (org.jetbrains.android.dom.resources.Style)5 AntDomTarget (com.intellij.lang.ant.dom.AntDomTarget)4 XmlElement (com.intellij.psi.xml.XmlElement)4 DomElementProblemDescriptor (com.intellij.util.xml.highlighting.DomElementProblemDescriptor)4 LookupElement (com.intellij.codeInsight.lookup.LookupElement)3 TextRange (com.intellij.openapi.util.TextRange)3