Search in sources :

Example 1 with XmlDoctype

use of com.intellij.psi.xml.XmlDoctype 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)

Aggregations

PsiComment (com.intellij.psi.PsiComment)1 PsiElement (com.intellij.psi.PsiElement)1 XmlDoctype (com.intellij.psi.xml.XmlDoctype)1 XmlDocument (com.intellij.psi.xml.XmlDocument)1 XmlFile (com.intellij.psi.xml.XmlFile)1 XmlProlog (com.intellij.psi.xml.XmlProlog)1 ArrayList (java.util.ArrayList)1