Search in sources :

Example 26 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 27 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 28 with XmlDocument

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

the class UpdateJspxFileCopyright method scanFile.

protected void scanFile() {
    logger.debug("updating " + getFile().getVirtualFile());
    XmlDocument doc = ((XmlFile) getFile()).getDocument();
    XmlProlog xmlProlog = doc.getProlog();
    if (xmlProlog == null) {
        return;
    }
    PsiElement elem = xmlProlog.getFirstChild();
    PsiElement docTypeStart = null;
    while (elem != null) {
        if (elem instanceof XmlDoctype) {
            docTypeStart = elem;
            break;
        }
        elem = getNextSibling(elem);
    }
    PsiElement first = xmlProlog.getFirstChild();
    int location = getLanguageOptions().getFileLocation();
    if (docTypeStart != null) {
        final ArrayList<PsiComment> comments = new ArrayList<>();
        collectComments(doc.getFirstChild(), xmlProlog, comments);
        collectComments(first, docTypeStart, comments);
        checkComments(first, location == XmlOptions.LOCATION_BEFORE_DOCTYPE, comments);
        checkComments(docTypeStart, doc.getRootTag(), location == XmlOptions.LOCATION_BEFORE_ROOTTAG);
        return;
    } else if (location == XmlOptions.LOCATION_BEFORE_DOCTYPE) {
        location = XmlOptions.LOCATION_BEFORE_ROOTTAG;
    }
    final ArrayList<PsiComment> comments = new ArrayList<>();
    collectComments(doc.getFirstChild(), xmlProlog, comments);
    collectComments(first, doc.getRootTag(), comments);
    checkComments(doc.getRootTag(), location == XmlOptions.LOCATION_BEFORE_ROOTTAG, comments);
}
Also used : PsiComment(com.intellij.psi.PsiComment) XmlFile(com.intellij.psi.xml.XmlFile) XmlDoctype(com.intellij.psi.xml.XmlDoctype) ArrayList(java.util.ArrayList) XmlDocument(com.intellij.psi.xml.XmlDocument) XmlProlog(com.intellij.psi.xml.XmlProlog) PsiElement(com.intellij.psi.PsiElement)

Example 29 with XmlDocument

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

the class NamespaceCollector method collectInfo.

public static CollectedInfo collectInfo(final XmlFile psiFile) {
    final NamespaceCollector namespaceCollector = new NamespaceCollector();
    final XmlDocument document = psiFile.getDocument();
    if (document != null) {
        document.accept(namespaceCollector);
    }
    return new CollectedInfo(namespaceCollector.namespaces, namespaceCollector.elements, namespaceCollector.attributes);
}
Also used : XmlDocument(com.intellij.psi.xml.XmlDocument)

Example 30 with XmlDocument

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

the class JavaFxNamespaceDescriptor method init.

@Override
public void init(PsiElement element) {
    XmlDocument document = (XmlDocument) element;
    myFile = ((XmlFile) document.getContainingFile());
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) XmlDocument(com.intellij.psi.xml.XmlDocument)

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