Search in sources :

Example 1 with JspDirective

use of com.intellij.psi.impl.source.jsp.jspXml.JspDirective in project intellij-community by JetBrains.

the class UpdateJspFileCopyright method scanFile.

protected void scanFile() {
    logger.debug("updating " + getFile().getVirtualFile());
    XmlDocument doc = ((XmlFile) getFile()).getDocument();
    XmlTag root = doc.getRootTag();
    if (root == null) {
        return;
    }
    PsiElement elem = root.getFirstChild();
    PsiElement docTypeStart = null;
    PsiElement docTypeEnd = null;
    PsiElement firstTag = null;
    while (elem != null) {
        if (elem instanceof XmlToken) {
            if ("<!DOCTYPE".equals(elem.getText())) {
                docTypeStart = elem;
                while ((elem = getNextSibling(elem)) != null) {
                    if (elem instanceof PsiWhiteSpace)
                        continue;
                    if (elem instanceof XmlToken) {
                        if (elem.getText().endsWith(">")) {
                            elem = getNextSibling(elem);
                            docTypeEnd = elem;
                            break;
                        } else if (elem.getText().startsWith("<")) {
                            docTypeEnd = elem;
                            break;
                        }
                    } else {
                        break;
                    }
                }
                continue;
            } else {
                firstTag = elem;
                break;
            }
        } else if (elem instanceof XmlTag && !(elem instanceof JspDirective)) {
            firstTag = elem;
            break;
        }
        elem = getNextSibling(elem);
    }
    PsiElement first = root.getFirstChild();
    int location = getLanguageOptions().getFileLocation();
    if (docTypeStart != null) {
        checkComments(first, docTypeStart, location == XmlOptions.LOCATION_BEFORE_DOCTYPE);
        first = docTypeEnd;
    } else if (location == XmlOptions.LOCATION_BEFORE_DOCTYPE) {
        location = XmlOptions.LOCATION_BEFORE_ROOTTAG;
    }
    if (firstTag != null) {
        checkComments(first, firstTag, location == XmlOptions.LOCATION_BEFORE_ROOTTAG);
    } else if (location == XmlOptions.LOCATION_BEFORE_ROOTTAG) {
        // If we get here we have an empty file
        checkComments(first, first, true);
    }
}
Also used : JspDirective(com.intellij.psi.impl.source.jsp.jspXml.JspDirective) PsiElement(com.intellij.psi.PsiElement) PsiWhiteSpace(com.intellij.psi.PsiWhiteSpace)

Aggregations

PsiElement (com.intellij.psi.PsiElement)1 PsiWhiteSpace (com.intellij.psi.PsiWhiteSpace)1 JspDirective (com.intellij.psi.impl.source.jsp.jspXml.JspDirective)1