Search in sources :

Example 16 with XmlDocument

use of com.intellij.psi.xml.XmlDocument 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 17 with XmlDocument

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

the class ExternalAnnotationsManagerImpl method sortItems.

private static void sortItems(@NotNull XmlFile xmlFile) {
    XmlDocument document = xmlFile.getDocument();
    if (document == null) {
        return;
    }
    XmlTag rootTag = document.getRootTag();
    if (rootTag == null) {
        return;
    }
    List<XmlTag> itemTags = new ArrayList<>();
    for (XmlTag item : rootTag.getSubTags()) {
        if (item.getAttributeValue("name") != null) {
            itemTags.add(item);
        } else {
            item.delete();
        }
    }
    List<XmlTag> sorted = new ArrayList<>(itemTags);
    Collections.sort(sorted, (item1, item2) -> {
        String externalName1 = item1.getAttributeValue("name");
        String externalName2 = item2.getAttributeValue("name");
        // null names were not added
        assert externalName1 != null && externalName2 != null;
        return externalName1.compareTo(externalName2);
    });
    if (!sorted.equals(itemTags)) {
        for (XmlTag item : sorted) {
            rootTag.addAfter(item, null);
            item.delete();
        }
    }
}
Also used : ArrayList(java.util.ArrayList) XmlDocument(com.intellij.psi.xml.XmlDocument) XmlTag(com.intellij.psi.xml.XmlTag)

Example 18 with XmlDocument

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

the class XmlStructuralSearchProfile method createPatternTree.

@NotNull
@Override
public PsiElement[] createPatternTree(@NotNull String text, @NotNull PatternTreeContext context, @NotNull FileType fileType, @Nullable Language language, String contextName, @Nullable String extension, @NotNull Project project, boolean physical) {
    final String ext = extension != null ? extension : fileType.getDefaultExtension();
    String text1 = context == PatternTreeContext.File ? text : "<QQQ>" + text + "</QQQ>";
    final PsiFile fileFromText = PsiFileFactory.getInstance(project).createFileFromText("dummy." + ext, fileType, text1, LocalTimeCounter.currentTime(), physical, true);
    final XmlDocument document = HtmlUtil.getRealXmlDocument(((XmlFile) fileFromText).getDocument());
    if (context == PatternTreeContext.File) {
        return new PsiElement[] { document };
    }
    return document.getRootTag().getValue().getChildren();
}
Also used : XmlDocument(com.intellij.psi.xml.XmlDocument) NotNull(org.jetbrains.annotations.NotNull)

Example 19 with XmlDocument

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

the class AddAntBuildFile method update.

public void update(@NotNull AnActionEvent e) {
    final Presentation presentation = e.getPresentation();
    final Project project = e.getProject();
    if (project != null) {
        final VirtualFile[] files = e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
        if (files != null && files.length > 0) {
            for (VirtualFile file : files) {
                final PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
                if (!(psiFile instanceof XmlFile)) {
                    continue;
                }
                final XmlFile xmlFile = (XmlFile) psiFile;
                final XmlDocument document = xmlFile.getDocument();
                if (document == null) {
                    continue;
                }
                final XmlTag rootTag = document.getRootTag();
                if (rootTag == null) {
                    continue;
                }
                if (!"project".equals(rootTag.getName())) {
                    continue;
                }
                if (AntConfigurationBase.getInstance(project).getAntBuildFile(psiFile) != null) {
                    continue;
                }
                // found at least one candidate file
                enable(presentation);
                return;
            }
        }
    }
    disable(presentation);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) XmlFile(com.intellij.psi.xml.XmlFile) PsiFile(com.intellij.psi.PsiFile) XmlDocument(com.intellij.psi.xml.XmlDocument) Presentation(com.intellij.openapi.actionSystem.Presentation) XmlTag(com.intellij.psi.xml.XmlTag)

Example 20 with XmlDocument

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

the class FlexUtils method processMetaAttributesForClass.

public static void processMetaAttributesForClass(@NotNull PsiElement jsClass, @NotNull final ActionScriptResolveUtil.MetaDataProcessor processor) {
    ActionScriptResolveUtil.processMetaAttributesForClass(jsClass, processor);
    if (jsClass instanceof XmlBackedJSClassImpl) {
        PsiElement parent = jsClass.getParent();
        if (parent != null) {
            PsiFile file = parent.getContainingFile();
            if (file instanceof XmlFile) {
                XmlDocument document = ((XmlFile) file).getDocument();
                if (document != null) {
                    XmlTag rootTag = document.getRootTag();
                    if (rootTag != null) {
                        JSResolveUtil.JSInjectedFilesVisitor visitor = new JSResolveUtil.JSInjectedFilesVisitor() {

                            @Override
                            protected void process(JSFile file) {
                                if (file != null) {
                                    ActionScriptResolveUtil.processMetaAttributesForClass(file, processor);
                                }
                            }
                        };
                        processMxmlTags(rootTag, true, visitor);
                    }
                }
            }
        }
    }
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) PsiFile(com.intellij.psi.PsiFile) XmlDocument(com.intellij.psi.xml.XmlDocument) JSFile(com.intellij.lang.javascript.psi.JSFile) JSResolveUtil(com.intellij.lang.javascript.psi.resolve.JSResolveUtil) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag)

Aggregations

XmlDocument (com.intellij.psi.xml.XmlDocument)57 XmlTag (com.intellij.psi.xml.XmlTag)39 XmlFile (com.intellij.psi.xml.XmlFile)32 PsiElement (com.intellij.psi.PsiElement)13 Nullable (org.jetbrains.annotations.Nullable)11 XmlNSDescriptor (com.intellij.xml.XmlNSDescriptor)9 PsiFile (com.intellij.psi.PsiFile)8 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 ArrayList (java.util.ArrayList)6 XmlAttribute (com.intellij.psi.xml.XmlAttribute)5 PsiMetaData (com.intellij.psi.meta.PsiMetaData)4 IncorrectOperationException (com.intellij.util.IncorrectOperationException)4 NotNull (org.jetbrains.annotations.NotNull)4 Project (com.intellij.openapi.project.Project)3 XmlText (com.intellij.psi.xml.XmlText)3 XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)3 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)2 Editor (com.intellij.openapi.editor.Editor)2 PsiErrorElement (com.intellij.psi.PsiErrorElement)2 FilterElementProcessor (com.intellij.psi.scope.processor.FilterElementProcessor)2