Search in sources :

Example 26 with IntArrayList

use of com.intellij.util.containers.IntArrayList in project intellij-community by JetBrains.

the class TemplateState method initEmptyVariables.

private IntArrayList initEmptyVariables() {
    int endSegmentNumber = myTemplate.getEndSegmentNumber();
    int selStart = myTemplate.getSelectionStartSegmentNumber();
    int selEnd = myTemplate.getSelectionEndSegmentNumber();
    IntArrayList indices = new IntArrayList();
    List<TemplateDocumentChange> changes = ContainerUtil.newArrayList();
    for (int i = 0; i < myTemplate.getSegmentsCount(); i++) {
        int length = mySegments.getSegmentEnd(i) - mySegments.getSegmentStart(i);
        if (length != 0)
            continue;
        if (i == endSegmentNumber || i == selStart || i == selEnd)
            continue;
        String name = myTemplate.getSegmentName(i);
        for (int j = 0; j < myTemplate.getVariableCount(); j++) {
            if (myTemplate.getVariableNameAt(j).equals(name)) {
                Expression e = myTemplate.getExpressionAt(j);
                String marker = "a";
                if (e instanceof MacroCallNode) {
                    marker = ((MacroCallNode) e).getMacro().getDefaultValue();
                }
                changes.add(new TemplateDocumentChange(marker, mySegments.getSegmentStart(i), mySegments.getSegmentEnd(i), i));
                indices.add(i);
                break;
            }
        }
    }
    executeChanges(changes);
    return indices;
}
Also used : IntArrayList(com.intellij.util.containers.IntArrayList)

Example 27 with IntArrayList

use of com.intellij.util.containers.IntArrayList in project intellij-community by JetBrains.

the class HighlightExitPointsHandler method highlightExitPoints.

private void highlightExitPoints(final PsiStatement parent, final PsiCodeBlock body) throws AnalysisCanceledException {
    final Project project = myTarget.getProject();
    ControlFlow flow = ControlFlowFactory.getInstance(project).getControlFlow(body, LocalsOrMyInstanceFieldsControlFlowPolicy.getInstance(), false);
    Collection<PsiStatement> exitStatements = ControlFlowUtil.findExitPointsAndStatements(flow, 0, flow.getSize(), new IntArrayList(), PsiReturnStatement.class, PsiBreakStatement.class, PsiContinueStatement.class, PsiThrowStatement.class);
    if (!exitStatements.contains(parent))
        return;
    PsiElement originalTarget = getExitTarget(parent);
    final Iterator<PsiStatement> it = exitStatements.iterator();
    while (it.hasNext()) {
        PsiStatement psiStatement = it.next();
        if (getExitTarget(psiStatement) != originalTarget) {
            it.remove();
        }
    }
    for (PsiElement e : exitStatements) {
        addOccurrence(e);
    }
    myStatusText = CodeInsightBundle.message("status.bar.exit.points.highlighted.message", exitStatements.size(), HighlightUsagesHandler.getShortcutText());
}
Also used : Project(com.intellij.openapi.project.Project) IntArrayList(com.intellij.util.containers.IntArrayList)

Example 28 with IntArrayList

use of com.intellij.util.containers.IntArrayList in project intellij-community by JetBrains.

the class DocumentImpl method clearLineModificationFlagsExcept.

void clearLineModificationFlagsExcept(@NotNull int[] caretLines) {
    IntArrayList modifiedLines = new IntArrayList(caretLines.length);
    LineSet lineSet = getLineSet();
    for (int line : caretLines) {
        if (line >= 0 && line < lineSet.getLineCount() && lineSet.isModified(line)) {
            modifiedLines.add(line);
        }
    }
    lineSet = lineSet.clearModificationFlags();
    for (int i = 0; i < modifiedLines.size(); i++) {
        lineSet = lineSet.setModified(modifiedLines.get(i));
    }
    myLineSet = lineSet;
    myFrozen = null;
}
Also used : IntArrayList(com.intellij.util.containers.IntArrayList)

Example 29 with IntArrayList

use of com.intellij.util.containers.IntArrayList in project intellij-community by JetBrains.

the class CommentByBlockCommentHandler method insertNestedComments.

private TextRange insertNestedComments(int startOffset, int endOffset, String commentPrefix, String commentSuffix, Commenter commenter) {
    if (commenter instanceof SelfManagingCommenter) {
        final SelfManagingCommenter selfManagingCommenter = (SelfManagingCommenter) commenter;
        return selfManagingCommenter.insertBlockComment(startOffset, endOffset, myDocument, mySelfManagedCommenterData);
    }
    String normalizedPrefix = commentPrefix.trim();
    String normalizedSuffix = commentSuffix.trim();
    IntArrayList nestedCommentPrefixes = new IntArrayList();
    IntArrayList nestedCommentSuffixes = new IntArrayList();
    String commentedPrefix = commenter.getCommentedBlockCommentPrefix();
    String commentedSuffix = commenter.getCommentedBlockCommentSuffix();
    CharSequence chars = myDocument.getCharsSequence();
    for (int i = startOffset; i < endOffset; ++i) {
        if (CharArrayUtil.regionMatches(chars, i, normalizedPrefix)) {
            nestedCommentPrefixes.add(i);
        } else {
            if (CharArrayUtil.regionMatches(chars, i, normalizedSuffix)) {
                nestedCommentSuffixes.add(i);
            }
        }
    }
    int shift = 0;
    if (!(commentedSuffix == null && !nestedCommentSuffixes.isEmpty() && nestedCommentSuffixes.get(nestedCommentSuffixes.size() - 1) + commentSuffix.length() == endOffset)) {
        myDocument.insertString(endOffset, commentSuffix);
        shift += commentSuffix.length();
    }
    // process nested comments in back order
    int i = nestedCommentPrefixes.size() - 1;
    int j = nestedCommentSuffixes.size() - 1;
    final TextRange selection = new TextRange(startOffset, endOffset);
    while (i >= 0 && j >= 0) {
        final int prefixIndex = nestedCommentPrefixes.get(i);
        final int suffixIndex = nestedCommentSuffixes.get(j);
        if (prefixIndex > suffixIndex) {
            shift += doBoundCommentingAndGetShift(prefixIndex, commentedPrefix, normalizedPrefix.length(), commentSuffix, false, selection);
            --i;
        } else {
            //if (insertPos < myDocument.getTextLength() && Character.isWhitespace(myDocument.getCharsSequence().charAt(insertPos))) {
            //  insertPos = suffixIndex + commentSuffix.length();
            //}
            shift += doBoundCommentingAndGetShift(suffixIndex, commentedSuffix, normalizedSuffix.length(), commentPrefix, true, selection);
            --j;
        }
    }
    while (i >= 0) {
        final int prefixIndex = nestedCommentPrefixes.get(i);
        shift += doBoundCommentingAndGetShift(prefixIndex, commentedPrefix, normalizedPrefix.length(), commentSuffix, false, selection);
        --i;
    }
    while (j >= 0) {
        final int suffixIndex = nestedCommentSuffixes.get(j);
        shift += doBoundCommentingAndGetShift(suffixIndex, commentedSuffix, normalizedSuffix.length(), commentPrefix, true, selection);
        --j;
    }
    if (!(commentedPrefix == null && !nestedCommentPrefixes.isEmpty() && nestedCommentPrefixes.get(0) == startOffset)) {
        myDocument.insertString(startOffset, commentPrefix);
        shift += commentPrefix.length();
    }
    RangeMarker marker = myDocument.createRangeMarker(startOffset, endOffset + shift);
    try {
        return processDocument(myDocument, marker, commenter, true);
    } finally {
        marker.dispose();
    }
}
Also used : TextRange(com.intellij.openapi.util.TextRange) IntArrayList(com.intellij.util.containers.IntArrayList)

Example 30 with IntArrayList

use of com.intellij.util.containers.IntArrayList in project intellij-community by JetBrains.

the class CommentByLineCommentHandler method doUncommentLine.

private static boolean doUncommentLine(int line, Document document, Commenter commenter, int startOffset, int endOffset, boolean removeSpace) {
    String prefix = commenter.getLineCommentPrefix();
    if (prefix != null) {
        if (removeSpace)
            prefix += ' ';
        CharSequence chars = document.getCharsSequence();
        if (commenter instanceof CommenterWithLineSuffix) {
            CommenterWithLineSuffix commenterWithLineSuffix = (CommenterWithLineSuffix) commenter;
            String suffix = commenterWithLineSuffix.getLineCommentSuffix();
            int theEnd = endOffset > 0 ? endOffset : document.getLineEndOffset(line);
            while (theEnd > startOffset && Character.isWhitespace(chars.charAt(theEnd - 1))) {
                theEnd--;
            }
            String lineText = document.getText(new TextRange(startOffset, theEnd));
            if (lineText.indexOf(suffix) != -1) {
                int start = startOffset + lineText.indexOf(suffix);
                document.deleteString(start, start + suffix.length());
            }
        }
        boolean matchesTrimmed = false;
        boolean commented = CharArrayUtil.regionMatches(chars, startOffset, prefix) || (matchesTrimmed = prefix.endsWith(" ") && CharArrayUtil.regionMatches(chars, startOffset, prefix.trim()));
        assert commented;
        int charsToDelete = matchesTrimmed ? prefix.trim().length() : prefix.length();
        document.deleteString(startOffset, startOffset + charsToDelete);
        // delete whitespace on line if that's all that left after uncommenting
        int lineStartOffset = document.getLineStartOffset(line);
        int lineEndOffset = document.getLineEndOffset(line);
        if (CharArrayUtil.isEmptyOrSpaces(chars, lineStartOffset, lineEndOffset))
            document.deleteString(lineStartOffset, lineEndOffset);
        return true;
    }
    String text = document.getCharsSequence().subSequence(startOffset, endOffset).toString();
    prefix = commenter.getBlockCommentPrefix();
    final String suffix = commenter.getBlockCommentSuffix();
    if (prefix == null || suffix == null) {
        return true;
    }
    IntArrayList prefixes = new IntArrayList();
    IntArrayList suffixes = new IntArrayList();
    for (int position = 0; position < text.length(); ) {
        int prefixPos = text.indexOf(prefix, position);
        if (prefixPos == -1) {
            break;
        }
        prefixes.add(prefixPos);
        position = prefixPos + prefix.length();
        int suffixPos = text.indexOf(suffix, position);
        if (suffixPos == -1) {
            suffixPos = text.length() - suffix.length();
        }
        suffixes.add(suffixPos);
        position = suffixPos + suffix.length();
    }
    assert prefixes.size() == suffixes.size();
    for (int i = prefixes.size() - 1; i >= 0; i--) {
        uncommentRange(document, startOffset + prefixes.get(i), Math.min(startOffset + suffixes.get(i) + suffix.length(), endOffset), commenter);
    }
    return false;
}
Also used : TextRange(com.intellij.openapi.util.TextRange) IntArrayList(com.intellij.util.containers.IntArrayList)

Aggregations

IntArrayList (com.intellij.util.containers.IntArrayList)31 ArrayList (java.util.ArrayList)5 PsiFile (com.intellij.psi.PsiFile)3 NotNull (org.jetbrains.annotations.NotNull)3 TextRange (com.intellij.openapi.util.TextRange)2 Nullable (org.jetbrains.annotations.Nullable)2 ExceptionUtil (com.intellij.codeInsight.ExceptionUtil)1 RadComponent (com.intellij.designer.model.RadComponent)1 LighterASTNode (com.intellij.lang.LighterASTNode)1 Logger (com.intellij.openapi.diagnostic.Logger)1 RangeMarker (com.intellij.openapi.editor.RangeMarker)1 Project (com.intellij.openapi.project.Project)1 com.intellij.psi (com.intellij.psi)1 PsiCodeBlock (com.intellij.psi.PsiCodeBlock)1 PsiElement (com.intellij.psi.PsiElement)1 PsiJavaFile (com.intellij.psi.PsiJavaFile)1 DummyHolder (com.intellij.psi.impl.source.DummyHolder)1 MethodSignature (com.intellij.psi.util.MethodSignature)1 PsiTreeUtil (com.intellij.psi.util.PsiTreeUtil)1 PsiUtil (com.intellij.psi.util.PsiUtil)1