use of com.intellij.psi.PsiWhiteSpace in project intellij-community by JetBrains.
the class PsiTreeDebugBuilder method psiToBuffer.
private void psiToBuffer(PsiElement root, int indent, boolean showRanges, boolean showChildrenRanges) {
if (!myShowWhiteSpaces && root instanceof PsiWhiteSpace)
return;
if (!myShowErrorElements && root instanceof PsiErrorElement)
return;
for (int i = 0; i < indent; i++) {
myBuffer.append(' ');
}
final String rootStr = root.toString();
myBuffer.append(rootStr);
PsiElement child = root.getFirstChild();
if (child == null) {
String text = root.getText();
assert text != null : "text is null for <" + root + ">";
text = StringUtil.replace(text, "\n", "\\n");
text = StringUtil.replace(text, "\r", "\\r");
text = StringUtil.replace(text, "\t", "\\t");
myBuffer.append("('");
myBuffer.append(text);
myBuffer.append("')");
}
if (showRanges)
myBuffer.append(root.getTextRange());
myBuffer.append("\n");
while (child != null) {
psiToBuffer(child, indent + 2, showChildrenRanges, showChildrenRanges);
child = child.getNextSibling();
}
}
use of com.intellij.psi.PsiWhiteSpace in project intellij-community by JetBrains.
the class UpdateJavaScriptFileCopyright method scanFile.
protected void scanFile() {
PsiElement first = getFile().getFirstChild();
if (first != null) {
final PsiElement child = first.getFirstChild();
if (child instanceof PsiComment) {
first = child;
}
}
PsiElement last = first;
PsiElement next = first;
while (next != null) {
if (next instanceof PsiComment || next instanceof PsiWhiteSpace) {
next = getNextSibling(next);
} else {
break;
}
last = next;
}
if (first != null) {
checkComments(first, last, true);
} else {
checkComments(null, null, true);
}
}
use of com.intellij.psi.PsiWhiteSpace 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);
}
}
use of com.intellij.psi.PsiWhiteSpace in project intellij-community by JetBrains.
the class InspectionUtil method isSuppressedAt.
private static boolean isSuppressedAt(PsiElement anchor, LocalInspectionTool tool) {
if (anchor == null)
return false;
PsiElement prevSibling;
if (!(anchor instanceof XmlComment)) {
prevSibling = anchor.getPrevSibling();
while (prevSibling instanceof PsiWhiteSpace || prevSibling instanceof XmlText) {
prevSibling = prevSibling.getPrevSibling();
}
} else {
prevSibling = anchor;
}
if (prevSibling instanceof XmlProlog) {
if (prevSibling.getTextLength() > 0 && !"\n".equals(prevSibling.getText())) {
return isSuppressedAt(prevSibling.getLastChild(), tool);
} else {
return isSuppressedAt(prevSibling, tool);
}
}
if (prevSibling instanceof XmlComment) {
final XmlComment comment = (XmlComment) prevSibling;
final String text = XmlUtil.getCommentText(comment);
if (text != null) {
final Matcher matcher = SUPPRESSION_PATTERN.matcher(text);
if (matcher.matches()) {
final String[] strings = matcher.group(1).split(",");
final String toolId = tool.getID();
for (String s : strings) {
if (s.trim().equals(toolId) || ALL_ID.equals(s.trim()))
return true;
}
}
}
}
return false;
}
use of com.intellij.psi.PsiWhiteSpace in project intellij-community by JetBrains.
the class SuppressInspectionAction method invoke.
public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException {
final XmlTag anchor = getAnchor(element);
if (anchor == null)
return;
PsiElement prevSibling = anchor.getPrevSibling();
while (prevSibling instanceof PsiWhiteSpace || prevSibling instanceof XmlText) {
prevSibling = prevSibling.getPrevSibling();
}
if (prevSibling instanceof XmlProlog) {
prevSibling = prevSibling.getLastChild();
if (prevSibling != null && !(prevSibling instanceof XmlComment)) {
prevSibling = PsiTreeUtil.getPrevSiblingOfType(prevSibling, XmlComment.class);
}
}
if (prevSibling instanceof XmlComment) {
final XmlComment comment = (XmlComment) prevSibling;
final String text = XmlUtil.getCommentText(comment);
if (text != null && InspectionUtil.SUPPRESSION_PATTERN.matcher(text).matches()) {
final String s = text.trim() + ", " + myToolId;
final XmlComment newComment = createComment(project, s);
CodeStyleManager.getInstance(PsiManager.getInstance(project).getProject()).reformat(comment.replace(newComment));
} else {
addNoinspectionComment(project, anchor);
}
} else {
addNoinspectionComment(project, anchor);
}
}
Aggregations