Search in sources :

Example 61 with XmlFile

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

the class TreeIncrementalUpdateTest method testRemoveAttributeParent.

public void testRemoveAttributeParent() throws Throwable {
    final XmlFile file = (XmlFile) createFile("file.xml", "<?xml version='1.0' encoding='UTF-8'?>\n" + "<!DOCTYPE ejb-jar PUBLIC \"-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN\" \"http://java.sun.com/dtd/ejb-jar_2_0.dtd\">\n" + "<a>\n" + " <child-element xxx=\"239\"/>\n" + "</a>");
    final DomFileElementImpl<MyElement> fileElement = getDomManager().getFileElement(file, MyElement.class, "a");
    myCallRegistry.clear();
    final MyElement rootElement = fileElement.getRootElement();
    final MyElement oldLeaf = rootElement.getChildElements().get(0);
    final GenericAttributeValue<String> xxx = oldLeaf.getXxx();
    final XmlTag oldLeafTag = oldLeaf.getXmlTag();
    new WriteCommandAction(getProject()) {

        @Override
        protected void run(@NotNull Result result) throws Throwable {
            oldLeafTag.delete();
        }
    }.execute();
    assertFalse(oldLeaf.isValid());
    assertFalse(xxx.isValid());
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) XmlFile(com.intellij.psi.xml.XmlFile) XmlTag(com.intellij.psi.xml.XmlTag) Result(com.intellij.openapi.application.Result)

Example 62 with XmlFile

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

the class TreeIncrementalUpdateTest method testTypeBeforeRootTag.

public void testTypeBeforeRootTag() throws Throwable {
    getDomManager().registerFileDescription(new DomFileDescription<>(MyElement.class, "a"), getTestRootDisposable());
    final XmlFile file = (XmlFile) createFile("file.xml", "<?xml version='1.0' encoding='UTF-8'?>\n" + "<a/>");
    assertTrue(getDomManager().isDomFile(file));
    final DomFileElementImpl<MyElement> fileElement = getDomManager().getFileElement(file, MyElement.class);
    assertTrue(fileElement.isValid());
    myCallRegistry.clear();
    putExpected(new DomEvent(fileElement, false));
    new WriteCommandAction(getProject()) {

        @Override
        protected void run(@NotNull Result result) throws Throwable {
            final Document document = getDocument(file);
            final int i = document.getText().indexOf("<a");
            document.insertString(i, "a");
            commitDocument(document);
        }
    }.execute();
    assertFalse(getDomManager().isDomFile(file));
    assertFalse(fileElement.isValid());
    assertResultsAndClear();
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) XmlFile(com.intellij.psi.xml.XmlFile) Document(com.intellij.openapi.editor.Document) DomEvent(com.intellij.util.xml.events.DomEvent) Result(com.intellij.openapi.application.Result)

Example 63 with XmlFile

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

the class TypeOrElementOrAttributeReference method getVariants.

public static Object[] getVariants(XmlTag tag, ReferenceType type, String prefix) {
    String[] tagNames = null;
    switch(type) {
        case GroupReference:
            tagNames = new String[] { SchemaReferencesProvider.GROUP_TAG_NAME };
            break;
        case AttributeGroupReference:
            tagNames = new String[] { SchemaReferencesProvider.ATTRIBUTE_GROUP_TAG_NAME };
            break;
        case AttributeReference:
            tagNames = new String[] { SchemaReferencesProvider.ATTRIBUTE_TAG_NAME };
            break;
        case ElementReference:
            tagNames = new String[] { SchemaReferencesProvider.ELEMENT_TAG_NAME };
            break;
        case TypeReference:
            tagNames = new String[] { SchemaReferencesProvider.SIMPLE_TYPE_TAG_NAME, SchemaReferencesProvider.COMPLEX_TYPE_TAG_NAME };
            break;
    }
    final XmlDocument document = ((XmlFile) tag.getContainingFile()).getDocument();
    if (document == null) {
        return ArrayUtil.EMPTY_OBJECT_ARRAY;
    }
    final XmlTag rootTag = document.getRootTag();
    String ourNamespace = rootTag != null ? rootTag.getAttributeValue(TARGET_NAMESPACE) : "";
    if (ourNamespace == null)
        ourNamespace = "";
    CompletionProcessor processor = new CompletionProcessor(tag, prefix);
    for (String namespace : tag.knownNamespaces()) {
        if (ourNamespace.equals(namespace))
            continue;
        final XmlNSDescriptor nsDescriptor = tag.getNSDescriptor(namespace, true);
        if (nsDescriptor instanceof XmlNSDescriptorImpl) {
            processNamespace(namespace, processor, (XmlNSDescriptorImpl) nsDescriptor, tagNames);
        }
    }
    XmlNSDescriptor nsDescriptor = (XmlNSDescriptor) document.getMetaData();
    if (nsDescriptor instanceof XmlNSDescriptorImpl) {
        processNamespace(ourNamespace, processor, (XmlNSDescriptorImpl) nsDescriptor, tagNames);
    }
    return ArrayUtil.toStringArray(processor.myElements);
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) XmlNSDescriptor(com.intellij.xml.XmlNSDescriptor) XmlDocument(com.intellij.psi.xml.XmlDocument) XmlNSDescriptorImpl(com.intellij.xml.impl.schema.XmlNSDescriptorImpl) XmlTag(com.intellij.psi.xml.XmlTag)

Example 64 with XmlFile

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

the class TypeOrElementOrAttributeReference method getNamespace.

private static String getNamespace(final XmlTag tag, final String text) {
    final String namespacePrefix = XmlUtil.findPrefixByQualifiedName(text);
    final String namespaceByPrefix = tag.getNamespaceByPrefix(namespacePrefix);
    if (!namespaceByPrefix.isEmpty())
        return namespaceByPrefix;
    final XmlTag rootTag = ((XmlFile) tag.getContainingFile()).getRootTag();
    if (rootTag != null && "schema".equals(rootTag.getLocalName()) && XmlUtil.ourSchemaUrisList.indexOf(rootTag.getNamespace()) != -1) {
        final String targetNS = rootTag.getAttributeValue(TARGET_NAMESPACE);
        if (targetNS != null) {
            final String targetNsPrefix = rootTag.getPrefixByNamespace(targetNS);
            if (namespacePrefix.equals(targetNsPrefix) || (namespaceByPrefix.isEmpty() && targetNsPrefix == null)) {
                return targetNS;
            }
        }
    }
    return namespaceByPrefix;
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) XmlTag(com.intellij.psi.xml.XmlTag)

Example 65 with XmlFile

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

the class XmlDuplicatedIdInspection method buildVisitor.

@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
    return new XmlElementVisitor() {

        @Override
        public void visitXmlAttributeValue(final XmlAttributeValue value) {
            if (value.getTextRange().isEmpty()) {
                return;
            }
            final PsiFile file = value.getContainingFile();
            if (!(file instanceof XmlFile)) {
                return;
            }
            PsiFile baseFile = PsiUtilCore.getTemplateLanguageFile(file);
            if (baseFile != file && !(baseFile instanceof XmlFile)) {
                return;
            }
            final XmlRefCountHolder refHolder = XmlRefCountHolder.getRefCountHolder((XmlFile) file);
            if (refHolder == null)
                return;
            final PsiElement parent = value.getParent();
            if (!(parent instanceof XmlAttribute))
                return;
            final XmlTag tag = (XmlTag) parent.getParent();
            if (tag == null)
                return;
            checkValue(value, (XmlFile) file, refHolder, tag, holder);
        }
    };
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlFile(com.intellij.psi.xml.XmlFile) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) XmlTag(com.intellij.psi.xml.XmlTag) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

XmlFile (com.intellij.psi.xml.XmlFile)409 XmlTag (com.intellij.psi.xml.XmlTag)155 PsiFile (com.intellij.psi.PsiFile)121 VirtualFile (com.intellij.openapi.vfs.VirtualFile)102 Nullable (org.jetbrains.annotations.Nullable)74 Project (com.intellij.openapi.project.Project)69 NotNull (org.jetbrains.annotations.NotNull)66 PsiElement (com.intellij.psi.PsiElement)64 XmlAttribute (com.intellij.psi.xml.XmlAttribute)39 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)34 Module (com.intellij.openapi.module.Module)34 XmlDocument (com.intellij.psi.xml.XmlDocument)32 Result (com.intellij.openapi.application.Result)28 XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)23 XmlAttributeValue (com.intellij.psi.xml.XmlAttributeValue)22 XmlNSDescriptor (com.intellij.xml.XmlNSDescriptor)21 ArrayList (java.util.ArrayList)20 Document (com.intellij.openapi.editor.Document)19 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)18 Editor (com.intellij.openapi.editor.Editor)15