use of com.intellij.psi.PsiWhiteSpace in project intellij-community by JetBrains.
the class DocTagSelectioner method getDocTagRange.
public static TextRange getDocTagRange(PsiDocTag e, CharSequence documentText, int minOffset) {
TextRange range = e.getTextRange();
int endOffset = range.getEndOffset();
int startOffset = range.getStartOffset();
PsiElement[] children = e.getChildren();
for (int i = children.length - 1; i >= 0; i--) {
PsiElement child = children[i];
int childStartOffset = child.getTextRange().getStartOffset();
if (childStartOffset <= minOffset) {
break;
}
if (child instanceof PsiDocToken) {
PsiDocToken token = (PsiDocToken) child;
IElementType type = token.getTokenType();
char[] chars = token.textToCharArray();
int shift = CharArrayUtil.shiftForward(chars, 0, " \t\n\r");
if (shift != chars.length && type != JavaDocTokenType.DOC_COMMENT_LEADING_ASTERISKS) {
break;
}
} else if (!(child instanceof PsiWhiteSpace)) {
break;
}
endOffset = Math.min(childStartOffset, endOffset);
}
startOffset = CharArrayUtil.shiftBackward(documentText, startOffset - 1, "* \t") + 1;
return new TextRange(startOffset, endOffset);
}
use of com.intellij.psi.PsiWhiteSpace in project intellij-plugins by JetBrains.
the class HbBlockMismatchFix method invoke.
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
final int offset = editor.getCaretModel().getOffset();
PsiElement psiElement = file.findElementAt(offset);
if (psiElement == null)
return;
if (psiElement instanceof PsiWhiteSpace)
psiElement = PsiTreeUtil.prevLeaf(psiElement);
HbBlockMustache blockMustache = (HbBlockMustache) PsiTreeUtil.findFirstParent(psiElement, true, psiElement1 -> psiElement1 instanceof HbBlockMustache);
if (blockMustache == null) {
return;
}
HbBlockMustache targetBlockMustache = blockMustache;
// ensure we update the open or close mustache for this block appropriately
if (myUpdateOpenMustache != (targetBlockMustache instanceof HbOpenBlockMustache)) {
targetBlockMustache = blockMustache.getPairedElement();
}
HbPath path = PsiTreeUtil.findChildOfType(targetBlockMustache, HbPath.class);
final Document document = PsiDocumentManager.getInstance(project).getDocument(file);
if (path != null && document != null) {
final TextRange textRange = path.getTextRange();
document.replaceString(textRange.getStartOffset(), textRange.getEndOffset(), myCorrectedName);
}
}
use of com.intellij.psi.PsiWhiteSpace in project intellij-plugins by JetBrains.
the class BaseCreateMethodsFix method evalAnchor.
protected void evalAnchor(@Nullable Editor editor, PsiElement context) {
if (editor == null)
return;
final int caretOffset = editor.getCaretModel().getOffset();
final PsiElement body = DartResolveUtil.getBody(myDartClass);
assert body != null;
for (PsiElement child : body.getChildren()) {
if (child.getTextRange().getStartOffset() > caretOffset)
break;
anchor = child;
}
PsiElement next = anchor == null ? null : anchor.getNextSibling();
while (next != null && (next instanceof PsiWhiteSpace || ";".equals(next.getText()))) {
anchor = next;
next = anchor.getNextSibling();
}
if (anchor == null) {
anchor = body;
}
}
use of com.intellij.psi.PsiWhiteSpace in project intellij-plugins by JetBrains.
the class GherkinTableRowImpl method deleteCell.
public void deleteCell(int columnIndex) {
final List<GherkinTableCell> cells = getPsiCells();
if (columnIndex < cells.size()) {
PsiElement cell = cells.get(columnIndex);
PsiElement nextPipe = cell.getNextSibling();
if (nextPipe instanceof PsiWhiteSpace) {
nextPipe = nextPipe.getNextSibling();
}
if (nextPipe != null && nextPipe.getNode().getElementType() == GherkinTokenTypes.PIPE) {
nextPipe.delete();
}
cell.delete();
}
}
use of com.intellij.psi.PsiWhiteSpace in project intellij-plugins by JetBrains.
the class DartFoldingBuilder method foldComments.
private static void foldComments(@NotNull final List<FoldingDescriptor> descriptors, @NotNull final Collection<PsiElement> psiElements, @Nullable final TextRange fileHeaderRange) {
PsiElement psiElement;
for (Iterator<PsiElement> iter = psiElements.iterator(); iter.hasNext(); ) {
psiElement = iter.next();
if (!(psiElement instanceof PsiComment)) {
continue;
}
if (fileHeaderRange != null && fileHeaderRange.intersects(psiElement.getTextRange())) {
continue;
}
final IElementType elementType = psiElement.getNode().getElementType();
if ((elementType == DartTokenTypesSets.MULTI_LINE_DOC_COMMENT || elementType == DartTokenTypesSets.MULTI_LINE_COMMENT) && !isCustomRegionElement(psiElement)) {
descriptors.add(new FoldingDescriptor(psiElement, psiElement.getTextRange()));
} else if (elementType == DartTokenTypesSets.SINGLE_LINE_DOC_COMMENT || elementType == DartTokenTypesSets.SINGLE_LINE_COMMENT) {
final PsiElement firstCommentInSequence = psiElement;
PsiElement lastCommentInSequence = firstCommentInSequence;
PsiElement nextElement = firstCommentInSequence;
boolean containsCustomRegionMarker = isCustomRegionElement(nextElement);
while (iter.hasNext() && (nextElement = nextElement.getNextSibling()) != null && (nextElement instanceof PsiWhiteSpace || nextElement.getNode().getElementType() == elementType)) {
if (nextElement.getNode().getElementType() == elementType) {
// advance iterator to skip processed comments sequence
iter.next();
lastCommentInSequence = nextElement;
containsCustomRegionMarker |= isCustomRegionElement(nextElement);
}
}
if (lastCommentInSequence != firstCommentInSequence && !containsCustomRegionMarker) {
final TextRange range = TextRange.create(firstCommentInSequence.getTextRange().getStartOffset(), lastCommentInSequence.getTextRange().getEndOffset());
descriptors.add(new FoldingDescriptor(firstCommentInSequence, range));
}
}
}
}
Aggregations