Search in sources :

Example 6 with XmlElement

use of com.intellij.psi.xml.XmlElement in project intellij-community by JetBrains.

the class DomAnchorImpl method diagnoseNegativeIndex2.

private static <T extends DomElement> void diagnoseNegativeIndex2(T t, DomElement parent, AbstractDomChildrenDescription description, List<? extends DomElement> values) {
    final XmlTag parentTag = parent.getXmlTag();
    StringBuilder diag = new StringBuilder("Index<0: description=" + description + "\nparent=" + parent + "\nt=" + t + "\nvalues=" + values + "\n");
    for (int i = 0, size = values.size(); i < size; i++) {
        DomElement value = values.get(i);
        if (value.toString().equals(t.toString())) {
            final XmlElement tElement = t.getXmlElement();
            final XmlElement valElement = value.getXmlElement();
            diag.append(" hasSame, i=" + i + "; same=" + (value == t) + ", equal=" + value.equals(t) + ", equal2=" + t.equals(value) + ", t.physical=" + (tElement == null ? "null" : String.valueOf(tElement.isPhysical())) + ", value.physical=" + (valElement == null ? "null" : String.valueOf(valElement.isPhysical())) + ", sameElements=" + (tElement == value.getXmlElement()) + "\n");
            if (tElement != null && valElement != null) {
                diag.append("  sameFile=" + (tElement.getContainingFile() == valElement.getContainingFile()) + ", sameParent=" + (tElement.getParent() == valElement.getParent()) + "\n");
            }
        }
    }
    if (parentTag != null) {
        diag.append("Parent tag: ").append(parentTag.getName()).append("\n");
        if (t instanceof GenericAttributeValue) {
            for (XmlAttribute attribute : parentTag.getAttributes()) {
                diag.append(", attr: ").append(attribute.getName());
            }
            diag.append("\n");
        } else {
            for (XmlTag tag : parentTag.getSubTags()) {
                diag.append("\n subtag: ").append(tag.getName());
            }
            diag.append("\n");
        }
    }
    diag.append("Child name: ").append(t.getXmlElementName()).append(";").append(t.getXmlElementNamespaceKey());
    LOG.error(diag);
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlElement(com.intellij.psi.xml.XmlElement) XmlTag(com.intellij.psi.xml.XmlTag)

Example 7 with XmlElement

use of com.intellij.psi.xml.XmlElement in project intellij-community by JetBrains.

the class DomElementAnnotationHolderImpl method createAnnotation.

@Override
@NotNull
public Annotation createAnnotation(@NotNull DomElement element, HighlightSeverity severity, @Nullable String message) {
    final XmlElement xmlElement = element.getXmlElement();
    LOG.assertTrue(xmlElement != null, "No XML element for " + element);
    final TextRange range = xmlElement.getTextRange();
    final int startOffset = range.getStartOffset();
    final int endOffset = message == null ? startOffset : range.getEndOffset();
    final Annotation annotation = new Annotation(startOffset, endOffset, severity, message, null);
    myAnnotations.add(annotation);
    return annotation;
}
Also used : XmlElement(com.intellij.psi.xml.XmlElement) TextRange(com.intellij.openapi.util.TextRange) Annotation(com.intellij.lang.annotation.Annotation) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with XmlElement

use of com.intellij.psi.xml.XmlElement in project intellij-community by JetBrains.

the class GoToSymbolProvider method createNavigationItem.

@Nullable
protected static NavigationItem createNavigationItem(final DomElement domElement) {
    final GenericDomValue name = domElement.getGenericInfo().getNameDomElement(domElement);
    assert name != null;
    final XmlElement psiElement = name.getXmlElement();
    final String value = name.getStringValue();
    if (psiElement == null || value == null) {
        return null;
    }
    final Icon icon = ElementPresentationManager.getIcon(domElement);
    return createNavigationItem(psiElement, value, icon);
}
Also used : XmlElement(com.intellij.psi.xml.XmlElement) GenericDomValue(com.intellij.util.xml.GenericDomValue) Nullable(org.jetbrains.annotations.Nullable)

Example 9 with XmlElement

use of com.intellij.psi.xml.XmlElement in project intellij-community by JetBrains.

the class DomInvocationHandler method getXmlElementNamespace.

@Override
@NotNull
public String getXmlElementNamespace() {
    final DomInvocationHandler parent = getParentHandler();
    assert parent != null : "this operation should be performed on the DOM having a physical parent, your DOM may be not very fresh";
    final XmlElement element = parent.getXmlElement();
    assert element != null;
    return getXmlName().getNamespace(element, getFile());
}
Also used : XmlElement(com.intellij.psi.xml.XmlElement) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with XmlElement

use of com.intellij.psi.xml.XmlElement in project intellij-community by JetBrains.

the class DomInvocationHandler method checkValidity.

@Nullable
protected String checkValidity() {
    ProgressManager.checkCanceled();
    final DomParentStrategy parentStrategy = getParentStrategy();
    String error = parentStrategy.checkValidity();
    if (error != null) {
        return "Strategy: " + error;
    }
    final long modCount = myManager.getPsiModificationCount();
    if (myLastModCount == modCount) {
        return null;
    }
    final XmlElement xmlElement = parentStrategy.getXmlElement();
    if (xmlElement != null) {
        final DomInvocationHandler actual = myManager.getDomHandler(xmlElement);
        if (!equals(actual)) {
            return "element changed: " + this.toStringEx() + "!=" + (actual == null ? null : actual.toStringEx());
        }
        myLastModCount = modCount;
        return null;
    }
    final DomInvocationHandler parent = getParentHandler();
    if (parent == null) {
        return "no parent: " + getDomElementType();
    }
    error = parent.checkValidity();
    if (error != null) {
        return "parent: " + error;
    }
    myLastModCount = modCount;
    return null;
}
Also used : XmlElement(com.intellij.psi.xml.XmlElement) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

XmlElement (com.intellij.psi.xml.XmlElement)69 PsiElement (com.intellij.psi.PsiElement)16 NotNull (org.jetbrains.annotations.NotNull)16 Nullable (org.jetbrains.annotations.Nullable)11 XmlTag (com.intellij.psi.xml.XmlTag)10 PsiFile (com.intellij.psi.PsiFile)7 PsiReference (com.intellij.psi.PsiReference)6 XmlAttribute (com.intellij.psi.xml.XmlAttribute)6 XmlFile (com.intellij.psi.xml.XmlFile)6 Manifest (org.jetbrains.android.dom.manifest.Manifest)5 Module (com.intellij.openapi.module.Module)4 Project (com.intellij.openapi.project.Project)4 DomElement (com.intellij.util.xml.DomElement)4 ArrayList (java.util.ArrayList)4 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)3 CompositePsiElement (com.intellij.psi.impl.source.tree.CompositePsiElement)3 SmartList (com.intellij.util.SmartList)3 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)3 ResourceType (com.android.resources.ResourceType)2 Result (com.intellij.openapi.application.Result)2