mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 15:19:59 +07:00
cleanup, reduce dependencies on ImmutableCharsequence (part of IJPL-234343)
GitOrigin-RevId: 45553e01cea8983f629cc134995986dc9b89d10d
This commit is contained in:
committed by
intellij-monorepo-bot
parent
387c92bcb0
commit
25efcf366f
@@ -13,6 +13,7 @@ import it.unimi.dsi.fastutil.bytes.ByteList;
|
||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||
import it.unimi.dsi.fastutil.ints.IntList;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.VisibleForTesting;
|
||||
|
||||
@@ -29,23 +30,25 @@ public final class LineSet {
|
||||
private static final int MODIFIED_MASK = 0x4;
|
||||
private static final int SEPARATOR_MASK = 0x3;
|
||||
|
||||
private final int[] myStarts;
|
||||
private final byte[] myFlags; // MODIFIED_MASK bit is for is/setModified(line); SEPARATOR_MASK 2 bits stores line separator length: 0..2
|
||||
private final int @NotNull [] myStarts;
|
||||
private final byte @NotNull [] myFlags; // MODIFIED_MASK bit is for is/setModified(line); SEPARATOR_MASK 2 bits stores line separator length: 0..2
|
||||
private final int myLength;
|
||||
|
||||
private LineSet(int[] starts, byte[] flags, int length) {
|
||||
private LineSet(int @NotNull [] starts, byte @NotNull [] flags, int length) {
|
||||
myStarts = starts;
|
||||
myFlags = flags;
|
||||
myLength = length;
|
||||
}
|
||||
|
||||
public static LineSet createLineSet(CharSequence text) {
|
||||
@Contract("_ -> new")
|
||||
public static @NotNull LineSet createLineSet(@NotNull CharSequence text) {
|
||||
return createLineSet(text, false);
|
||||
}
|
||||
|
||||
private static @NotNull LineSet createLineSet(@NotNull CharSequence text, boolean markModified) {
|
||||
IntList starts = new IntArrayList();
|
||||
ByteList flags = new ByteArrayList();
|
||||
int approxLineCount = text.length() / 20;
|
||||
IntList starts = new IntArrayList(approxLineCount);
|
||||
ByteList flags = new ByteArrayList(approxLineCount);
|
||||
|
||||
LineTokenizer lineTokenizer = new LineTokenizer(text);
|
||||
while (!lineTokenizer.atEnd()) {
|
||||
@@ -105,7 +108,8 @@ public final class LineSet {
|
||||
return new LineSet(starts, flags, myLength + lengthDelta);
|
||||
}
|
||||
|
||||
private LineSet genericUpdate(int startOffset, int endOffset, CharSequence replacement) {
|
||||
@Contract("_, _, _ -> new")
|
||||
private @NotNull LineSet genericUpdate(int startOffset, int endOffset, @NotNull CharSequence replacement) {
|
||||
int startLine = findLineIndex(startOffset);
|
||||
int endLine = findLineIndex(endOffset);
|
||||
|
||||
@@ -152,7 +156,7 @@ public final class LineSet {
|
||||
return new LineSet(starts, flags, myLength + lengthShift);
|
||||
}
|
||||
|
||||
private int shiftData(int[] dstStarts, byte[] dstFlags, int srcOffset, int dstOffset, int count, int offsetDelta) {
|
||||
private int shiftData(int @NotNull [] dstStarts, byte @NotNull [] dstFlags, int srcOffset, int dstOffset, int count, int offsetDelta) {
|
||||
if (count < 0) return dstOffset;
|
||||
|
||||
System.arraycopy(myFlags, srcOffset, dstFlags, dstOffset, count);
|
||||
|
||||
@@ -39,8 +39,14 @@ public class MarkupModelImpl extends UserDataHolderBase implements MarkupModelEx
|
||||
|
||||
private volatile RangeHighlighter[] myCachedHighlighters;
|
||||
private final List<MarkupModelListener> myListeners = ContainerUtil.createLockFreeCopyOnWriteList();
|
||||
private final RangeHighlighterTree myHighlighterTree; // this tree holds regular highlighters with target = HighlighterTargetArea.EXACT_RANGE
|
||||
private final RangeHighlighterTree myHighlighterTreeForLines; // this tree holds line range highlighters with target = HighlighterTargetArea.LINES_IN_RANGE
|
||||
/**
|
||||
* this tree holds line range highlighters with {@link RangeHighlighter#getTargetArea()} = {@link HighlighterTargetArea#EXACT_RANGE}
|
||||
*/
|
||||
private final RangeHighlighterTree myHighlighterTree;
|
||||
/**
|
||||
* this tree holds line range highlighters with {@link RangeHighlighter#getTargetArea()} = {@link HighlighterTargetArea#LINES_IN_RANGE}
|
||||
*/
|
||||
private final RangeHighlighterTree myHighlighterTreeForLines;
|
||||
|
||||
@ApiStatus.Internal
|
||||
protected MarkupModelImpl(@NotNull DocumentEx document) {
|
||||
@@ -176,7 +182,7 @@ public class MarkupModelImpl extends UserDataHolderBase implements MarkupModelEx
|
||||
}
|
||||
|
||||
@NotNull
|
||||
RangeHighlighterTree treeFor(@NotNull RangeHighlighter highlighter) {
|
||||
private RangeHighlighterTree treeFor(@NotNull RangeHighlighter highlighter) {
|
||||
return highlighter.getTargetArea() == HighlighterTargetArea.EXACT_RANGE ? myHighlighterTree : myHighlighterTreeForLines;
|
||||
}
|
||||
|
||||
|
||||
@@ -46,6 +46,7 @@ import it.unimi.dsi.fastutil.ints.Int2IntMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntRBTreeMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntSortedMap;
|
||||
import it.unimi.dsi.fastutil.ints.IntComparators;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -121,7 +122,10 @@ public abstract class FindManagerBase extends FindManager {
|
||||
return findStringLoop(text, offset, model, file, getFindContextPredicate(model, file, text));
|
||||
}
|
||||
|
||||
private FindResult findStringLoop(CharSequence text, int offset, FindModel model, VirtualFile file,
|
||||
private FindResult findStringLoop(@NotNull CharSequence text,
|
||||
int offset,
|
||||
@NotNull FindModel model,
|
||||
@Nullable VirtualFile file,
|
||||
@Nullable Predicate<? super FindResult> filter) {
|
||||
final char[] textArray = CharArrayUtil.fromSequenceWithoutCopying(text);
|
||||
while(true) {
|
||||
@@ -561,10 +565,11 @@ public abstract class FindManagerBase extends FindManager {
|
||||
@NotNull FindModel myFindModel,
|
||||
@NotNull CharSequence myText,
|
||||
@NotNull Int2IntSortedMap mySkipRangesSet) implements Predicate<FindResult> {
|
||||
static FindExceptCommentsOrLiteralsData create(@NotNull VirtualFile file,
|
||||
@NotNull FindModel model,
|
||||
@NotNull CharSequence text,
|
||||
@NotNull FindManagerBase manager) {
|
||||
@Contract("_, _, _, _ -> new")
|
||||
static @NotNull FindExceptCommentsOrLiteralsData create(@NotNull VirtualFile file,
|
||||
@NotNull FindModel model,
|
||||
@NotNull CharSequence text,
|
||||
@NotNull FindManagerBase manager) {
|
||||
Int2IntSortedMap skipRangesSet = new Int2IntRBTreeMap(IntComparators.OPPOSITE_COMPARATOR);
|
||||
|
||||
if (model.isExceptComments() || model.isExceptCommentsAndStringLiterals()) {
|
||||
@@ -578,12 +583,12 @@ public abstract class FindManagerBase extends FindManager {
|
||||
return new FindExceptCommentsOrLiteralsData(file, model.clone(), ImmutableCharSequence.asImmutable(text), skipRangesSet);
|
||||
}
|
||||
|
||||
private static void addRanges(VirtualFile file,
|
||||
FindModel model,
|
||||
CharSequence text,
|
||||
private static void addRanges(@NotNull VirtualFile file,
|
||||
@NotNull FindModel model,
|
||||
@NotNull CharSequence text,
|
||||
@NotNull Int2IntSortedMap result,
|
||||
FindModel.SearchContext searchContext,
|
||||
FindManagerBase manager) {
|
||||
@NotNull FindModel.SearchContext searchContext,
|
||||
@NotNull FindManagerBase manager) {
|
||||
FindModel clonedModel = model.clone();
|
||||
clonedModel.setSearchContext(searchContext);
|
||||
clonedModel.setForward(true);
|
||||
@@ -598,7 +603,7 @@ public abstract class FindManagerBase extends FindManager {
|
||||
}
|
||||
}
|
||||
|
||||
boolean isAcceptableFor(FindModel model, VirtualFile file, CharSequence text) {
|
||||
boolean isAcceptableFor(@NotNull FindModel model, @NotNull VirtualFile file, @NotNull CharSequence text) {
|
||||
return Comparing.equal(myFile, file) &&
|
||||
myFindModel.equals(model) &&
|
||||
myText.length() == text.length()
|
||||
|
||||
@@ -2098,7 +2098,7 @@ c:com.intellij.openapi.editor.RawText
|
||||
- s:getDataFlavor():java.awt.datatransfer.DataFlavor
|
||||
com.intellij.openapi.editor.actionSystem.ActionPlan
|
||||
- a:getCaretOffset():I
|
||||
- a:getText():com.intellij.util.text.ImmutableCharSequence
|
||||
- a:getText():java.lang.CharSequence
|
||||
- a:replace(I,I,java.lang.String):V
|
||||
- a:setCaretOffset(I):V
|
||||
a:com.intellij.openapi.editor.actionSystem.EditorAction
|
||||
|
||||
@@ -19,7 +19,6 @@ import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.editor.CaretModel;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.util.text.ImmutableCharSequence;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
@@ -39,7 +38,7 @@ public interface ActionPlan {
|
||||
* @return text content.
|
||||
*/
|
||||
@NotNull
|
||||
ImmutableCharSequence getText();
|
||||
CharSequence getText();
|
||||
|
||||
/**
|
||||
* Replaces the specified range of text with the specified string.
|
||||
|
||||
@@ -5,7 +5,9 @@ import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.actionSystem.ActionPlan;
|
||||
import com.intellij.util.text.CharArrayUtil;
|
||||
import com.intellij.util.text.ImmutableCharSequence;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.UnmodifiableView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -25,7 +27,7 @@ final class EditorActionPlan implements ActionPlan {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ImmutableCharSequence getText() {
|
||||
public @NotNull CharSequence getText() {
|
||||
return myText;
|
||||
}
|
||||
|
||||
@@ -48,7 +50,8 @@ final class EditorActionPlan implements ActionPlan {
|
||||
myCaretOffset = offset;
|
||||
}
|
||||
|
||||
public List<Replacement> getReplacements() {
|
||||
@Contract(pure = true)
|
||||
public @NotNull @UnmodifiableView List<Replacement> getReplacements() {
|
||||
return Collections.unmodifiableList(myReplacements);
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ public class ExporterToTextFile implements com.intellij.ide.ExporterToTextFile {
|
||||
childIndent = indent;
|
||||
}
|
||||
|
||||
Enumeration enumeration = node.children();
|
||||
Enumeration<?> enumeration = node.children();
|
||||
while (enumeration.hasMoreElements()) {
|
||||
DefaultMutableTreeNode child = (DefaultMutableTreeNode)enumeration.nextElement();
|
||||
appendNode(buf, child, lineSeparator, childIndent);
|
||||
|
||||
@@ -364,7 +364,7 @@ public class UsageViewImpl implements UsageViewEx {
|
||||
synchronized (parentNode) {
|
||||
otherNodes = ContainerUtil.filter(parentNode.getChildren(), n -> n.isExcluded() != almostAllChildrenExcluded);
|
||||
}
|
||||
if (otherNodes.size() == 1 && otherNodes.get(0) == node) {
|
||||
if (otherNodes.size() == 1 && otherNodes.getFirst() == node) {
|
||||
nodes.add(parentNode);
|
||||
collectParentNodes(parentNode, almostAllChildrenExcluded, nodes);
|
||||
}
|
||||
@@ -1851,7 +1851,7 @@ public class UsageViewImpl implements UsageViewEx {
|
||||
WriteIntentReadAction.run(runnable);
|
||||
}
|
||||
};
|
||||
action.putValue(DUMB_AWARE_KEY, Boolean.valueOf(dumbAware));
|
||||
action.putValue(DUMB_AWARE_KEY, dumbAware);
|
||||
addButtonToLowerPane(action);
|
||||
}
|
||||
|
||||
@@ -1997,7 +1997,7 @@ public class UsageViewImpl implements UsageViewEx {
|
||||
: ContainerUtil.mapNotNull(selectionPaths, p -> ObjectUtils.tryCast(p.getLastPathComponent(), TreeNode.class));
|
||||
}
|
||||
|
||||
private @NotNull JBIterable<TreeNode> traverseNodesRecursively(@NotNull List<? extends TreeNode> roots) {
|
||||
private static @NotNull JBIterable<TreeNode> traverseNodesRecursively(@NotNull List<? extends TreeNode> roots) {
|
||||
return TreeUtil.treeNodeTraverser(null).withRoots(roots).traverse();
|
||||
}
|
||||
|
||||
|
||||
@@ -70,8 +70,8 @@ class LineTokenizer(private val myText: CharSequence) {
|
||||
@JvmStatic
|
||||
@JvmOverloads
|
||||
fun tokenizeIntoList(chars: CharSequence?, includeSeparators: Boolean, skipLastEmptyLine: Boolean = true): List<String> {
|
||||
if (chars == null || chars.isEmpty()) {
|
||||
return mutableListOf()
|
||||
if (chars.isNullOrEmpty()) {
|
||||
return listOf()
|
||||
}
|
||||
|
||||
val tokenizer = LineTokenizer(chars)
|
||||
|
||||
Reference in New Issue
Block a user