use of com.intellij.psi.PsiWhiteSpace in project intellij-community by JetBrains.
the class WhiteSpace method coveredByBlock.
/**
* Allows to check if {@code 'myInitial'} property value stands for continuous white space text.
* <p/>
* The text is considered to be continuous {@code 'white space'} at following cases:
* <ul>
* <li>{@code 'myInitial'} is empty string or string that contains white spaces only;</li>
* <li>{@code 'myInitial'} is a {@code CDATA} string which content is empty or consists from white spaces only;</li>
* <li>{@code 'myInitial'} string belongs to the same {@link PsiWhiteSpace} element;</li>
* </ul>
*
* @param model formatting model that is used to provide access to the {@code PSI API} if necessary
* @return {@code true} if {@code 'myInitial'} property value stands for white space;
* {@code false} otherwise
*/
private boolean coveredByBlock(final FormattingDocumentModel model) {
if (myInitial == null)
return true;
if (model.containsWhiteSpaceSymbolsOnly(myStart, myEnd))
return true;
if (!(model instanceof FormattingDocumentModelImpl))
return false;
PsiFile psiFile = ((FormattingDocumentModelImpl) model).getFile();
if (psiFile == null)
return false;
PsiElement start = psiFile.findElementAt(myStart);
PsiElement end = psiFile.findElementAt(myEnd - 1);
// there maybe non-white text inside CDATA-encoded injected elements
return start == end && start instanceof PsiWhiteSpace;
}
use of com.intellij.psi.PsiWhiteSpace in project intellij-community by JetBrains.
the class PyForPartImpl method followsNodeOfType.
/**
* Checks that given node actually follows a node of given type, skipping whitespace.
* @param node node to check.
* @param eltType type of a node that must precede the node we're checking.
* @return true if node is really a next sibling to a node of eltType type.
*/
protected static boolean followsNodeOfType(ASTNode node, PyElementType eltType) {
if (node != null) {
PsiElement checker = node.getPsi();
// step from the source node
checker = checker.getPrevSibling();
while (checker != null) {
ASTNode ch_node = checker.getNode();
if (ch_node == null)
return false;
else {
if (ch_node.getElementType() == eltType) {
return true;
} else if (!(checker instanceof PsiWhiteSpace)) {
return false;
}
}
checker = checker.getPrevSibling();
}
}
return false;
}
use of com.intellij.psi.PsiWhiteSpace in project intellij-community by JetBrains.
the class PySmartEnterProcessor method getStatementAtCaret.
@Nullable
protected PsiElement getStatementAtCaret(Editor editor, PsiFile psiFile) {
PsiElement statementAtCaret = super.getStatementAtCaret(editor, psiFile);
if (statementAtCaret instanceof PsiWhiteSpace) {
return null;
}
if (statementAtCaret == null) {
return null;
}
final PyStatementList statementList = PsiTreeUtil.getParentOfType(statementAtCaret, PyStatementList.class, false);
if (statementList != null) {
for (PyStatement statement : statementList.getStatements()) {
if (PsiTreeUtil.isAncestor(statement, statementAtCaret, true)) {
return statement;
}
}
} else {
final PyFile file = PsiTreeUtil.getParentOfType(statementAtCaret, PyFile.class, false);
if (file != null) {
for (PyStatement statement : file.getStatements()) {
if (PsiTreeUtil.isAncestor(statement, statementAtCaret, true)) {
return statement;
}
}
}
}
return null;
}
use of com.intellij.psi.PsiWhiteSpace in project intellij-community by JetBrains.
the class PyBreakContinueGotoProvider method getGotoDeclarationTarget.
@Override
public PsiElement getGotoDeclarationTarget(@Nullable PsiElement source, Editor editor) {
if (source != null && source.getLanguage() instanceof PythonLanguage) {
final PyLoopStatement loop = PsiTreeUtil.getParentOfType(source, PyLoopStatement.class, false, PyFunction.class, PyClass.class);
if (loop != null) {
ASTNode node = source.getNode();
if (node != null) {
IElementType node_type = node.getElementType();
if (node_type == PyTokenTypes.CONTINUE_KEYWORD) {
return loop;
}
if (node_type == PyTokenTypes.BREAK_KEYWORD) {
PsiElement outer_element = loop;
PsiElement after_cycle;
while (true) {
after_cycle = outer_element.getNextSibling();
if (after_cycle != null) {
if (after_cycle instanceof PsiWhiteSpace) {
after_cycle = after_cycle.getNextSibling();
}
if (after_cycle instanceof PyStatement)
return after_cycle;
}
outer_element = outer_element.getParent();
if (PyUtil.instanceOf(outer_element, PsiFile.class, PyFunction.class, PyClass.class)) {
break;
}
}
// cycle is the last statement in the flow of execution. its last element is our best bet.
return PsiTreeUtil.getDeepestLast(loop);
}
}
}
}
return null;
}
use of com.intellij.psi.PsiWhiteSpace in project intellij-community by JetBrains.
the class StatementEffectFunctionCallQuickFix method getNextElement.
private static PsiElement getNextElement(@NotNull final PsiElement expression) {
final PsiElement whiteSpace = expression.getContainingFile().findElementAt(expression.getTextOffset() + expression.getTextLength());
PsiElement next = null;
if (whiteSpace instanceof PsiWhiteSpace) {
final String whiteSpaceText = whiteSpace.getText();
if (!whiteSpaceText.contains("\n")) {
next = whiteSpace.getNextSibling();
while (next instanceof PsiWhiteSpace && whiteSpaceText.contains("\\")) {
next = next.getNextSibling();
}
}
} else
next = whiteSpace;
RemoveUnnecessaryBackslashQuickFix.removeBackSlash(next);
if (whiteSpace != null)
whiteSpace.delete();
return next;
}
Aggregations