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 JsonSmartEnterProcessor method terminatedOnCurrentLine.
private static boolean terminatedOnCurrentLine(@NotNull Editor editor, @NotNull PsiElement element) {
final Document document = editor.getDocument();
final int caretOffset = editor.getCaretModel().getCurrentCaret().getOffset();
final int elementEndOffset = element.getTextRange().getEndOffset();
if (document.getLineNumber(elementEndOffset) != document.getLineNumber(caretOffset)) {
return false;
}
// Skip empty PsiError elements if comma is missing
PsiElement nextLeaf = PsiTreeUtil.nextLeaf(element, true);
return nextLeaf == null || (nextLeaf instanceof PsiWhiteSpace && nextLeaf.getText().contains("\n"));
}
use of com.intellij.psi.PsiWhiteSpace in project intellij-community by JetBrains.
the class JsonSurroundDescriptor method getElementsToSurround.
@NotNull
@Override
public PsiElement[] getElementsToSurround(PsiFile file, int startOffset, int endOffset) {
PsiElement firstElement = file.findElementAt(startOffset);
PsiElement lastElement = file.findElementAt(endOffset - 1);
// Extend selection beyond possible delimiters
while (firstElement != null && (firstElement instanceof PsiWhiteSpace || firstElement.getNode().getElementType() == JsonElementTypes.COMMA)) {
firstElement = firstElement.getNextSibling();
}
while (lastElement != null && (lastElement instanceof PsiWhiteSpace || lastElement.getNode().getElementType() == JsonElementTypes.COMMA)) {
lastElement = lastElement.getPrevSibling();
}
if (firstElement != null) {
startOffset = firstElement.getTextRange().getStartOffset();
}
if (lastElement != null) {
endOffset = lastElement.getTextRange().getEndOffset();
}
final JsonElement property = PsiTreeUtil.findElementOfClassAtRange(file, startOffset, endOffset, JsonProperty.class);
if (property != null) {
final List<JsonElement> properties = ContainerUtil.newArrayList(property);
PsiElement nextSibling = property.getNextSibling();
while (nextSibling != null && nextSibling.getTextRange().getEndOffset() <= endOffset) {
if (nextSibling instanceof JsonProperty) {
properties.add((JsonProperty) nextSibling);
}
nextSibling = nextSibling.getNextSibling();
}
return properties.toArray(new PsiElement[properties.size()]);
}
final JsonValue value = PsiTreeUtil.findElementOfClassAtRange(file, startOffset, endOffset, JsonValue.class);
if (value != null) {
return new PsiElement[] { value };
}
return PsiElement.EMPTY_ARRAY;
}
Aggregations