Search in sources :

Example 31 with XmlDocument

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

the class FxDefinitionBackedDescriptor method getDeclarationByFxDefinitionTag.

@Nullable
private static XmlAttributeValue getDeclarationByFxDefinitionTag(@NotNull final XmlTag xmlTag) {
    if (!xmlTag.isValid() || xmlTag.getParent() instanceof XmlDocument) {
        return null;
    }
    XmlTag rootTag = xmlTag;
    XmlTag parent;
    while ((parent = rootTag.getParentTag()) != null) {
        rootTag = parent;
    }
    final XmlTag[] subTags = rootTag.getSubTags();
    final XmlTag libraryTag = subTags.length > 0 && FlexPredefinedTagNames.LIBRARY.equals(subTags[0].getLocalName()) && JavaScriptSupportLoader.MXML_URI3.equals(subTags[0].getNamespace()) ? subTags[0] : null;
    final XmlTag[] definitionTags = libraryTag == null ? XmlTag.EMPTY : libraryTag.findSubTags(CodeContext.DEFINITION_TAG_NAME, JavaScriptSupportLoader.MXML_URI3);
    final String localName = xmlTag.getLocalName();
    for (final XmlTag definitionTag : definitionTags) {
        final XmlAttribute nameAttribute = definitionTag.getAttribute(MxmlLanguageTagsUtil.NAME_ATTRIBUTE);
        final XmlAttributeValue attributeValue = nameAttribute == null ? null : nameAttribute.getValueElement();
        if (attributeValue != null && localName.equals(attributeValue.getValue())) {
            return attributeValue;
        }
    }
    return null;
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlDocument(com.intellij.psi.xml.XmlDocument) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) XmlTag(com.intellij.psi.xml.XmlTag) Nullable(org.jetbrains.annotations.Nullable)

Example 32 with XmlDocument

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

the class AntDomFileDescription method isAntFile.

public static boolean isAntFile(final XmlFile xmlFile) {
    final XmlDocument document = xmlFile.getDocument();
    if (document != null) {
        final XmlTag tag = document.getRootTag();
        final VirtualFile vFile = xmlFile.getOriginalFile().getVirtualFile();
        if (tag != null && ROOT_TAG_NAME.equals(tag.getName()) && tag.getContext() instanceof XmlDocument) {
            if (tag.getAttributeValue("name") != null && tag.getAttributeValue("default") != null && vFile != null && ForcedAntFileAttribute.mayBeAntFile(vFile)) {
                return true;
            }
        }
        if (vFile != null && ForcedAntFileAttribute.isAntFile(vFile)) {
            return true;
        }
    }
    return false;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) XmlDocument(com.intellij.psi.xml.XmlDocument) XmlTag(com.intellij.psi.xml.XmlTag)

Example 33 with XmlDocument

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

the class DomGenPanel method createUIComponents.

private void createUIComponents() {
    mySchemaLocation = new TextFieldWithBrowseButton();
    final String title = "Choose XSD or DTD schema";
    mySchemaLocation.addBrowseFolderListener(title, "Make sure there are only necessary schemes in directory where your XSD or DTD schema is located", myProject, new FileTypeDescriptor(title, "xsd", "dtd"));
    mySchemaLocation.getTextField().setEditable(false);
    mySchemaLocation.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            final File file = new File(mySchemaLocation.getText());
            if (file.exists() && file.getName().toLowerCase().endsWith(".xsd")) {
                final VirtualFile vf = LocalFileSystem.getInstance().findFileByIoFile(file);
                if (vf != null) {
                    final PsiFile psiFile = PsiManager.getInstance(myProject).findFile(vf);
                    if (psiFile instanceof XmlFile) {
                        final XmlDocument xml = ((XmlFile) psiFile).getDocument();
                        if (xml != null) {
                            final XmlTag rootTag = xml.getRootTag();
                            if (rootTag != null) {
                                String target = null;
                                ArrayList<String> ns = new ArrayList<>();
                                for (XmlAttribute attr : rootTag.getAttributes()) {
                                    if ("targetNamespace".equals(attr.getName())) {
                                        target = attr.getValue();
                                    } else if (attr.getName().startsWith("xmlns")) {
                                        ns.add(attr.getValue());
                                    }
                                }
                                ns.remove(target);
                                if (target != null) {
                                    myNamespace.setText(target);
                                }
                                mySkipSchemas.setText(StringUtil.join(ArrayUtil.toStringArray(ns), "\n"));
                            }
                        }
                    }
                }
            }
        }
    });
    myOutputDir = new TextFieldWithBrowseButton();
    FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
    myOutputDir.addBrowseFolderListener("Select Output Directory For Generated Files", "", myProject, descriptor);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlFile(com.intellij.psi.xml.XmlFile) ActionEvent(java.awt.event.ActionEvent) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) ArrayList(java.util.ArrayList) XmlDocument(com.intellij.psi.xml.XmlDocument) FileTypeDescriptor(com.intellij.openapi.fileChooser.FileTypeDescriptor) TextFieldWithBrowseButton(com.intellij.openapi.ui.TextFieldWithBrowseButton) ActionListener(java.awt.event.ActionListener) PsiFile(com.intellij.psi.PsiFile) XmlFile(com.intellij.psi.xml.XmlFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) PsiFile(com.intellij.psi.PsiFile) XmlTag(com.intellij.psi.xml.XmlTag)

Example 34 with XmlDocument

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

the class RegistrationCheckerUtil method processPluginXml.

private static void processPluginXml(XmlFile xmlFile, RegistrationTypeFinder finder, boolean includeActions) {
    final XmlDocument document = xmlFile.getDocument();
    if (document == null)
        return;
    final XmlTag rootTag = document.getRootTag();
    if (rootTag == null)
        return;
    DescriptorUtil.processComponents(rootTag, finder);
    if (includeActions) {
        DescriptorUtil.processActions(rootTag, finder);
    }
}
Also used : XmlDocument(com.intellij.psi.xml.XmlDocument) XmlTag(com.intellij.psi.xml.XmlTag)

Example 35 with XmlDocument

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

the class ExternalAnnotationsManagerImpl method annotateExternally.

private void annotateExternally(@NotNull final PsiModifierListOwner listOwner, @NotNull final String annotationFQName, @Nullable final XmlFile xmlFile, @NotNull final PsiFile codeUsageFile, @Nullable final PsiNameValuePair[] values) {
    if (xmlFile == null) {
        notifyAfterAnnotationChanging(listOwner, annotationFQName, false);
        return;
    }
    try {
        final XmlDocument document = xmlFile.getDocument();
        if (document != null) {
            final XmlTag rootTag = document.getRootTag();
            final String externalName = getExternalName(listOwner, false);
            if (externalName == null) {
                LOG.info("member without external name: " + listOwner);
            }
            if (rootTag != null && externalName != null) {
                XmlTag anchor = null;
                for (XmlTag item : rootTag.getSubTags()) {
                    int compare = Comparing.compare(externalName, StringUtil.unescapeXml(item.getAttributeValue("name")));
                    if (compare == 0) {
                        anchor = null;
                        for (XmlTag annotation : item.getSubTags()) {
                            compare = Comparing.compare(annotationFQName, annotation.getAttributeValue("name"));
                            if (compare == 0) {
                                annotation.delete();
                                break;
                            }
                            anchor = annotation;
                        }
                        XmlTag newTag = XmlElementFactory.getInstance(myPsiManager.getProject()).createTagFromText(createAnnotationTag(annotationFQName, values));
                        item.addAfter(newTag, anchor);
                        commitChanges(xmlFile);
                        notifyAfterAnnotationChanging(listOwner, annotationFQName, true);
                        return;
                    }
                    if (compare < 0)
                        break;
                    anchor = item;
                }
                @NonNls String text = "<item name=\'" + StringUtil.escapeXml(externalName) + "\'>\n";
                text += createAnnotationTag(annotationFQName, values);
                text += "</item>";
                rootTag.addAfter(XmlElementFactory.getInstance(myPsiManager.getProject()).createTagFromText(text), anchor);
                commitChanges(xmlFile);
                notifyAfterAnnotationChanging(listOwner, annotationFQName, true);
                return;
            }
        }
        notifyAfterAnnotationChanging(listOwner, annotationFQName, false);
    } catch (IncorrectOperationException e) {
        LOG.error(e);
        notifyAfterAnnotationChanging(listOwner, annotationFQName, false);
    } finally {
        dropCache();
        if (codeUsageFile.getVirtualFile().isInLocalFileSystem()) {
            UndoUtil.markPsiFileForUndo(codeUsageFile);
        }
    }
}
Also used : NonNls(org.jetbrains.annotations.NonNls) XmlDocument(com.intellij.psi.xml.XmlDocument) IncorrectOperationException(com.intellij.util.IncorrectOperationException) 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