Search in sources :

Example 36 with PsiWhiteSpace

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);
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PsiDocToken(com.intellij.psi.javadoc.PsiDocToken) TextRange(com.intellij.openapi.util.TextRange) PsiElement(com.intellij.psi.PsiElement) PsiWhiteSpace(com.intellij.psi.PsiWhiteSpace)

Example 37 with PsiWhiteSpace

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);
    }
}
Also used : IncorrectOperationException(com.intellij.util.IncorrectOperationException) Document(com.intellij.openapi.editor.Document) HbPath(com.dmarcotte.handlebars.psi.HbPath) TextRange(com.intellij.openapi.util.TextRange) Editor(com.intellij.openapi.editor.Editor) HbBundle(com.dmarcotte.handlebars.HbBundle) HbBlockMustache(com.dmarcotte.handlebars.psi.HbBlockMustache) PsiTreeUtil(com.intellij.psi.util.PsiTreeUtil) PsiElement(com.intellij.psi.PsiElement) PsiWhiteSpace(com.intellij.psi.PsiWhiteSpace) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) NotNull(org.jetbrains.annotations.NotNull) HbOpenBlockMustache(com.dmarcotte.handlebars.psi.HbOpenBlockMustache) PsiDocumentManager(com.intellij.psi.PsiDocumentManager) HbOpenBlockMustache(com.dmarcotte.handlebars.psi.HbOpenBlockMustache) HbPath(com.dmarcotte.handlebars.psi.HbPath) HbBlockMustache(com.dmarcotte.handlebars.psi.HbBlockMustache) TextRange(com.intellij.openapi.util.TextRange) Document(com.intellij.openapi.editor.Document) PsiElement(com.intellij.psi.PsiElement) PsiWhiteSpace(com.intellij.psi.PsiWhiteSpace)

Example 38 with PsiWhiteSpace

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;
    }
}
Also used : PsiElement(com.intellij.psi.PsiElement) PsiWhiteSpace(com.intellij.psi.PsiWhiteSpace)

Example 39 with PsiWhiteSpace

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();
    }
}
Also used : GherkinTableCell(org.jetbrains.plugins.cucumber.psi.GherkinTableCell) PsiElement(com.intellij.psi.PsiElement) PsiWhiteSpace(com.intellij.psi.PsiWhiteSpace)

Example 40 with PsiWhiteSpace

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));
            }
        }
    }
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PsiComment(com.intellij.psi.PsiComment) FoldingDescriptor(com.intellij.lang.folding.FoldingDescriptor) TextRange(com.intellij.openapi.util.TextRange) UnfairTextRange(com.intellij.openapi.util.UnfairTextRange) PsiElement(com.intellij.psi.PsiElement) PsiWhiteSpace(com.intellij.psi.PsiWhiteSpace)

Aggregations

PsiWhiteSpace (com.intellij.psi.PsiWhiteSpace)90 PsiElement (com.intellij.psi.PsiElement)82 TextRange (com.intellij.openapi.util.TextRange)23 ASTNode (com.intellij.lang.ASTNode)15 PsiFile (com.intellij.psi.PsiFile)15 NotNull (org.jetbrains.annotations.NotNull)15 Nullable (org.jetbrains.annotations.Nullable)14 PsiComment (com.intellij.psi.PsiComment)13 IElementType (com.intellij.psi.tree.IElementType)13 Document (com.intellij.openapi.editor.Document)12 Project (com.intellij.openapi.project.Project)7 ArrayList (java.util.ArrayList)6 FoldingDescriptor (com.intellij.lang.folding.FoldingDescriptor)5 Editor (com.intellij.openapi.editor.Editor)5 Language (com.intellij.lang.Language)4 UnfairTextRange (com.intellij.openapi.util.UnfairTextRange)4 XmlTag (com.intellij.psi.xml.XmlTag)4 XMLLanguage (com.intellij.lang.xml.XMLLanguage)3 PsiDocumentManager (com.intellij.psi.PsiDocumentManager)3 XmlFile (com.intellij.psi.xml.XmlFile)3