use of com.intellij.psi.PsiWhiteSpace in project intellij-community by JetBrains.
the class XmlAttributeDeclImpl method findElementType.
private PsiElement findElementType() {
final PsiElement elementName = findElementByTokenType(XML_NAME);
final PsiElement nextSibling = (elementName != null) ? elementName.getNextSibling() : null;
final PsiElement elementType = (nextSibling instanceof PsiWhiteSpace) ? nextSibling.getNextSibling() : nextSibling;
return elementType;
}
use of com.intellij.psi.PsiWhiteSpace in project intellij-community by JetBrains.
the class XmlFormattingModel method replaceWithPsiInLeaf.
@Override
protected String replaceWithPsiInLeaf(final TextRange textRange, String whiteSpace, ASTNode leafElement) {
if (!myCanModifyAllWhiteSpaces) {
if (leafElement.getElementType() == TokenType.WHITE_SPACE)
return null;
LOG.assertTrue(leafElement.getPsi().isValid());
ASTNode prevNode = TreeUtil.prevLeaf(leafElement);
if (prevNode != null) {
IElementType type = prevNode.getElementType();
if (type == TokenType.WHITE_SPACE) {
final String text = prevNode.getText();
@NonNls final String cdataStartMarker = "<![CDATA[";
final int cdataPos = text.indexOf(cdataStartMarker);
if (cdataPos != -1 && whiteSpace.indexOf(cdataStartMarker) == -1) {
whiteSpace = mergeWsWithCdataMarker(whiteSpace, text, cdataPos);
if (whiteSpace == null)
return null;
}
prevNode = TreeUtil.prevLeaf(prevNode);
type = prevNode != null ? prevNode.getElementType() : null;
}
@NonNls final String cdataEndMarker = "]]>";
if (type == XmlTokenType.XML_CDATA_END && whiteSpace.indexOf(cdataEndMarker) == -1) {
final ASTNode at = findElementAt(prevNode.getStartOffset());
if (at != null && at.getPsi() instanceof PsiWhiteSpace) {
final String s = at.getText();
final int cdataEndPos = s.indexOf(cdataEndMarker);
whiteSpace = mergeWsWithCdataMarker(whiteSpace, s, cdataEndPos);
leafElement = at;
} else {
whiteSpace = null;
}
if (whiteSpace == null)
return null;
}
}
}
FormatterUtil.replaceWhiteSpace(whiteSpace, leafElement, TokenType.WHITE_SPACE, textRange);
return whiteSpace;
}
use of com.intellij.psi.PsiWhiteSpace in project intellij-community by JetBrains.
the class XmlBlock method createLeafBlocks.
private void createLeafBlocks(ASTNode node, List<Block> result) {
if (node instanceof OuterLanguageElement) {
processChild(result, node, null, null, null);
return;
}
ASTNode child = node.getFirstChildNode();
if (child == null && !(node instanceof PsiWhiteSpace) && node.getElementType() != TokenType.ERROR_ELEMENT && node.getTextLength() > 0) {
result.add(new ReadOnlyBlock(node));
return;
}
while (child != null) {
createLeafBlocks(child, result);
child = child.getTreeNext();
}
}
use of com.intellij.psi.PsiWhiteSpace in project intellij-community by JetBrains.
the class PyOverrideImplementUtil method getContextClass.
@Nullable
public static PyClass getContextClass(@NotNull final Editor editor, @NotNull final PsiFile file) {
int offset = editor.getCaretModel().getOffset();
PsiElement element = file.findElementAt(offset);
if (element == null) {
// are we in whitespace after last class? PY-440
final PsiElement lastChild = file.getLastChild();
if (lastChild != null && offset >= lastChild.getTextRange().getStartOffset() && offset <= lastChild.getTextRange().getEndOffset()) {
element = lastChild;
}
}
final PyClass pyClass = PsiTreeUtil.getParentOfType(element, PyClass.class, false);
if (pyClass == null && element instanceof PsiWhiteSpace && element.getPrevSibling() instanceof PyClass) {
return (PyClass) element.getPrevSibling();
}
return pyClass;
}
use of com.intellij.psi.PsiWhiteSpace in project intellij-community by JetBrains.
the class ConvertFormatOperatorToMethodIntention method collectWhitespace.
private static Pair<String, PsiElement> collectWhitespace(PsiElement start) {
StringBuilder sb = new StringBuilder();
PsiElement seeker = start;
while (seeker != null) {
seeker = seeker.getNextSibling();
if (seeker != null && seeker instanceof PsiWhiteSpace)
sb.append(seeker.getText());
else
break;
}
return Pair.create(sb.toString(), seeker);
}
Aggregations