Search in sources :

Example 6 with IntArrayList

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

the class LineWrapper method calcBreakOffsets.

public static IntArrayList calcBreakOffsets(char[] text, int startOffset, int endOffset, boolean lineStart, double x, double clipX, WidthProvider widthProvider) {
    IntArrayList breakOffsets = new IntArrayList();
    int nextOffset = startOffset;
    while (true) {
        int prevOffset = nextOffset;
        nextOffset = calcWordBreakOffset(text, nextOffset, endOffset, x, clipX, widthProvider);
        if (nextOffset == prevOffset && lineStart) {
            nextOffset = calcCharBreakOffset(text, nextOffset, endOffset, x, clipX, widthProvider);
            if (nextOffset == prevOffset) {
                // extremal case when even one character doesn't fit into clip width
                nextOffset++;
            }
        }
        if (nextOffset >= endOffset) {
            break;
        }
        breakOffsets.add(nextOffset);
        lineStart = true;
        x = 0;
    }
    return breakOffsets;
}
Also used : IntArrayList(com.intellij.util.containers.IntArrayList)

Example 7 with IntArrayList

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

the class CommentByBlockCommentHandler method commentNestedComments.

static void commentNestedComments(@NotNull Document document, TextRange range, Commenter commenter) {
    final int offset = range.getStartOffset();
    final IntArrayList toReplaceWithComments = new IntArrayList();
    final IntArrayList prefixes = new IntArrayList();
    final String text = document.getCharsSequence().subSequence(range.getStartOffset(), range.getEndOffset()).toString();
    final String commentedPrefix = commenter.getCommentedBlockCommentPrefix();
    final String commentedSuffix = commenter.getCommentedBlockCommentSuffix();
    final String commentPrefix = commenter.getBlockCommentPrefix();
    final String commentSuffix = commenter.getBlockCommentSuffix();
    int nearestSuffix = getNearest(text, commentedSuffix, 0);
    int nearestPrefix = getNearest(text, commentedPrefix, 0);
    int level = 0;
    int lastSuffix = -1;
    for (int i = Math.min(nearestPrefix, nearestSuffix); i < text.length(); i = Math.min(nearestPrefix, nearestSuffix)) {
        if (i > nearestPrefix) {
            nearestPrefix = getNearest(text, commentedPrefix, i);
            continue;
        }
        if (i > nearestSuffix) {
            nearestSuffix = getNearest(text, commentedSuffix, i);
            continue;
        }
        if (i == nearestPrefix) {
            if (level <= 0) {
                if (lastSuffix != -1) {
                    toReplaceWithComments.add(lastSuffix);
                }
                level = 1;
                lastSuffix = -1;
                toReplaceWithComments.add(i);
                prefixes.add(i);
            } else {
                level++;
            }
            nearestPrefix = getNearest(text, commentedPrefix, nearestPrefix + 1);
        } else {
            lastSuffix = i;
            level--;
            nearestSuffix = getNearest(text, commentedSuffix, nearestSuffix + 1);
        }
    }
    if (lastSuffix != -1) {
        toReplaceWithComments.add(lastSuffix);
    }
    int prefixIndex = prefixes.size() - 1;
    for (int i = toReplaceWithComments.size() - 1; i >= 0; i--) {
        int position = toReplaceWithComments.get(i);
        if (prefixIndex >= 0 && position == prefixes.get(prefixIndex)) {
            prefixIndex--;
            document.replaceString(offset + position, offset + position + commentedPrefix.length(), commentPrefix);
        } else {
            document.replaceString(offset + position, offset + position + commentedSuffix.length(), commentSuffix);
        }
    }
}
Also used : IntArrayList(com.intellij.util.containers.IntArrayList)

Example 8 with IntArrayList

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

the class SliceTestUtil method checkUsages.

public static void checkUsages(final SliceUsage usage, final TIntObjectHashMap<IntArrayList> flownOffsets) {
    final List<SliceUsage> children = new ArrayList<>();
    boolean b = ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> usage.processChildren(new CommonProcessors.CollectProcessor<>(children)), "Expanding", true, usage.getElement().getProject());
    assertTrue(b);
    int startOffset = usage.getElement().getTextOffset();
    IntArrayList list = flownOffsets.get(startOffset);
    int[] offsets = list == null ? new int[0] : list.toArray();
    Arrays.sort(offsets);
    int size = offsets.length;
    assertEquals(message(startOffset, usage), size, children.size());
    Collections.sort(children, (o1, o2) -> o1.compareTo(o2));
    for (int i = 0; i < children.size(); i++) {
        SliceUsage child = children.get(i);
        int offset = offsets[i];
        assertEquals(message(offset, child), offset, child.getUsageInfo().getElement().getTextOffset());
        checkUsages(child, flownOffsets);
    }
}
Also used : IntArrayList(com.intellij.util.containers.IntArrayList) IntArrayList(com.intellij.util.containers.IntArrayList)

Example 9 with IntArrayList

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

the class SliceTestUtil method fill.

private static void fill(Map<String, RangeMarker> sliceUsageName2Offset, String name, int offset, final TIntObjectHashMap<IntArrayList> flownOffsets) {
    for (int i = 1; i < 9; i++) {
        String newName = name + i;
        RangeMarker marker = sliceUsageName2Offset.get(newName);
        if (marker == null)
            break;
        IntArrayList offsets = flownOffsets.get(offset);
        if (offsets == null) {
            offsets = new IntArrayList();
            flownOffsets.put(offset, offsets);
        }
        int newStartOffset = marker.getStartOffset();
        offsets.add(newStartOffset);
        fill(sliceUsageName2Offset, newName, newStartOffset, flownOffsets);
    }
}
Also used : RangeMarker(com.intellij.openapi.editor.RangeMarker) IntArrayList(com.intellij.util.containers.IntArrayList)

Example 10 with IntArrayList

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

the class TemplateState method shortenReferences.

private void shortenReferences() {
    ApplicationManager.getApplication().runWriteAction(() -> {
        final PsiFile file = getPsiFile();
        if (file != null) {
            IntArrayList indices = initEmptyVariables();
            mySegments.setSegmentsGreedy(false);
            for (TemplateOptionalProcessor processor : Extensions.getExtensions(TemplateOptionalProcessor.EP_NAME)) {
                processor.processText(myProject, myTemplate, myDocument, myTemplateRange, myEditor);
            }
            mySegments.setSegmentsGreedy(true);
            restoreEmptyVariables(indices);
        }
    });
}
Also used : PsiFile(com.intellij.psi.PsiFile) 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