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;
}
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);
}
}
}
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);
}
}
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);
}
}
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);
}
});
}
Aggregations