cleanup - sort modifiers

GitOrigin-RevId: dc2cc5e5cc2d1f474d6d26808a8862448bd8b742
This commit is contained in:
Vladimir Krivosheev
2024-02-19 12:22:40 +01:00
committed by intellij-monorepo-bot
parent 138cf5f4dc
commit 81a5bdf1b0
30 changed files with 142 additions and 232 deletions

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. // Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.diagnostic; package com.intellij.diagnostic;
import com.intellij.openapi.util.text.StringUtilRt; import com.intellij.openapi.util.text.StringUtilRt;
@@ -26,15 +26,13 @@ public final class ThreadDumper {
private ThreadDumper() { private ThreadDumper() {
} }
@NotNull public static @NotNull String dumpThreadsToString() {
public static String dumpThreadsToString() {
StringWriter writer = new StringWriter(); StringWriter writer = new StringWriter();
dumpThreadInfos(getThreadInfos(), writer); dumpThreadInfos(getThreadInfos(), writer);
return writer.toString(); return writer.toString();
} }
@NotNull public static @NotNull String dumpEdtStackTrace(ThreadInfo @NotNull [] threadInfos) {
public static String dumpEdtStackTrace(ThreadInfo @NotNull [] threadInfos) {
StringWriter writer = new StringWriter(); StringWriter writer = new StringWriter();
if (threadInfos.length > 0) { if (threadInfos.length > 0) {
StackTraceElement[] trace = threadInfos[0].getStackTrace(); StackTraceElement[] trace = threadInfos[0].getStackTrace();
@@ -51,8 +49,7 @@ public final class ThreadDumper {
* @param stripCoroutineDump whether to remove stackframes from coroutine dump that have no useful debug information. * @param stripCoroutineDump whether to remove stackframes from coroutine dump that have no useful debug information.
* Enabling this flag should significantly reduce coroutine dump size. * Enabling this flag should significantly reduce coroutine dump size.
*/ */
@NotNull public static @NotNull ThreadDump getThreadDumpInfo(ThreadInfo @NotNull [] threadInfos, boolean stripCoroutineDump) {
public static ThreadDump getThreadDumpInfo(ThreadInfo @NotNull [] threadInfos, boolean stripCoroutineDump) {
sort(threadInfos); sort(threadInfos);
StringWriter writer = new StringWriter(); StringWriter writer = new StringWriter();
StackTraceElement[] edtStack = dumpThreadInfos(threadInfos, writer); StackTraceElement[] edtStack = dumpThreadInfos(threadInfos, writer);
@@ -188,8 +185,7 @@ public final class ThreadDumper {
* *
* @param fullThreadDump lines comprising a thread dump as formatted by {@link #dumpCallStack(ThreadInfo, Writer, StackTraceElement[])} * @param fullThreadDump lines comprising a thread dump as formatted by {@link #dumpCallStack(ThreadInfo, Writer, StackTraceElement[])}
*/ */
@Nullable public static @Nullable String getEdtStackForCrash(@NotNull String fullThreadDump, @NotNull String exceptionType) {
public static String getEdtStackForCrash(@NotNull String fullThreadDump, @NotNull String exceptionType) {
// We know that the AWT-EventQueue-* thread is dumped out first (see #sort above), and for each thread, there are at the very least // We know that the AWT-EventQueue-* thread is dumped out first (see #sort above), and for each thread, there are at the very least
// 3 lines printed out before the stack trace. If we don't see any of this, then return early // 3 lines printed out before the stack trace. If we don't see any of this, then return early
List<String> threadDump = Arrays.asList(fullThreadDump.split("\n")); List<String> threadDump = Arrays.asList(fullThreadDump.split("\n"));

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. // Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.openapi.util; package com.intellij.openapi.util;
import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.Contract;
@@ -104,21 +104,18 @@ public class TextRange implements Segment, Serializable {
return myStartOffset <= offset && offset < myEndOffset; return myStartOffset <= offset && offset < myEndOffset;
} }
@NotNull
@Contract(pure = true) @Contract(pure = true)
public String substring(@NotNull String str) { public @NotNull String substring(@NotNull String str) {
return str.substring(myStartOffset, myEndOffset); return str.substring(myStartOffset, myEndOffset);
} }
@Contract(pure = true) @Contract(pure = true)
@NotNull public @NotNull CharSequence subSequence(@NotNull CharSequence str) {
public CharSequence subSequence(@NotNull CharSequence str) {
return str.subSequence(myStartOffset, myEndOffset); return str.subSequence(myStartOffset, myEndOffset);
} }
@Contract(pure = true) @Contract(pure = true)
@NotNull public @NotNull TextRange cutOut(@NotNull TextRange subRange) {
public TextRange cutOut(@NotNull TextRange subRange) {
if (subRange.getStartOffset() > getLength()) { if (subRange.getStartOffset() > getLength()) {
throw new IllegalArgumentException("SubRange: " + subRange + "; this=" + this); throw new IllegalArgumentException("SubRange: " + subRange + "; this=" + this);
} }
@@ -131,22 +128,19 @@ public class TextRange implements Segment, Serializable {
} }
@Contract(pure = true) @Contract(pure = true)
@NotNull public @NotNull TextRange shiftRight(int delta) {
public TextRange shiftRight(int delta) {
if (delta == 0) return this; if (delta == 0) return this;
return new TextRange(myStartOffset + delta, myEndOffset + delta); return new TextRange(myStartOffset + delta, myEndOffset + delta);
} }
@Contract(pure = true) @Contract(pure = true)
@NotNull public @NotNull TextRange shiftLeft(int delta) {
public TextRange shiftLeft(int delta) {
if (delta == 0) return this; if (delta == 0) return this;
return new TextRange(myStartOffset - delta, myEndOffset - delta); return new TextRange(myStartOffset - delta, myEndOffset - delta);
} }
@Contract(pure = true) @Contract(pure = true)
@NotNull public @NotNull TextRange grown(int lengthDelta) {
public TextRange grown(int lengthDelta) {
if (lengthDelta == 0) { if (lengthDelta == 0) {
return this; return this;
} }
@@ -154,20 +148,17 @@ public class TextRange implements Segment, Serializable {
} }
@Contract(pure = true) @Contract(pure = true)
@NotNull public static @NotNull TextRange from(int offset, int length) {
public static TextRange from(int offset, int length) {
return create(offset, offset + length); return create(offset, offset + length);
} }
@Contract(pure = true) @Contract(pure = true)
@NotNull public static @NotNull TextRange create(int startOffset, int endOffset) {
public static TextRange create(int startOffset, int endOffset) {
return new TextRange(startOffset, endOffset); return new TextRange(startOffset, endOffset);
} }
@Contract(pure = true) @Contract(pure = true)
@NotNull public static @NotNull TextRange create(@NotNull Segment segment) {
public static TextRange create(@NotNull Segment segment) {
return create(segment.getStartOffset(), segment.getEndOffset()); return create(segment.getStartOffset(), segment.getEndOffset());
} }
@@ -178,8 +169,7 @@ public class TextRange implements Segment, Serializable {
} }
@Contract(pure = true) @Contract(pure = true)
@NotNull public @NotNull String replace(@NotNull String original, @NotNull String replacement) {
public String replace(@NotNull String original, @NotNull String replacement) {
String beginning = original.substring(0, getStartOffset()); String beginning = original.substring(0, getStartOffset());
String ending = original.substring(getEndOffset()); String ending = original.substring(getEndOffset());
return beginning + replacement + ending; return beginning + replacement + ending;
@@ -226,8 +216,7 @@ public class TextRange implements Segment, Serializable {
} }
@Contract(pure = true) @Contract(pure = true)
@NotNull public @NotNull TextRange union(@NotNull TextRange textRange) {
public TextRange union(@NotNull TextRange textRange) {
if (equals(textRange)) { if (equals(textRange)) {
return this; return this;
} }
@@ -240,8 +229,7 @@ public class TextRange implements Segment, Serializable {
} }
@Contract(pure = true) @Contract(pure = true)
@NotNull public static @NotNull TextRange allOf(@NotNull String s) {
public static TextRange allOf(@NotNull String s) {
return new TextRange(0, s.length()); return new TextRange(0, s.length());
} }

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. // Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.openapi.util.text; package com.intellij.openapi.util.text;
import com.intellij.util.ArrayUtilRt; import com.intellij.util.ArrayUtilRt;
@@ -25,13 +25,11 @@ public final class LineTokenizer {
return strings.isEmpty() ? ArrayUtilRt.EMPTY_STRING_ARRAY : ArrayUtilRt.toStringArray(strings); return strings.isEmpty() ? ArrayUtilRt.EMPTY_STRING_ARRAY : ArrayUtilRt.toStringArray(strings);
} }
@NotNull public static @NotNull List<String> tokenizeIntoList(CharSequence chars, final boolean includeSeparators) {
public static List<String> tokenizeIntoList(CharSequence chars, final boolean includeSeparators) {
return tokenizeIntoList(chars, includeSeparators, true); return tokenizeIntoList(chars, includeSeparators, true);
} }
@NotNull public static @NotNull List<String> tokenizeIntoList(CharSequence chars, final boolean includeSeparators, final boolean skipLastEmptyLine) {
public static List<String> tokenizeIntoList(CharSequence chars, final boolean includeSeparators, final boolean skipLastEmptyLine) {
if (chars == null || chars.length() == 0){ if (chars == null || chars.length() == 0){
return Collections.emptyList(); return Collections.emptyList();
} }

View File

@@ -132,20 +132,17 @@ public final class Pluralizer {
/** /**
* Pluralize or singularize a word based on the passed in count. * Pluralize or singularize a word based on the passed in count.
*/ */
@NotNull public @NotNull String pluralize(@NotNull String word, int count, boolean inclusive) {
public String pluralize(@NotNull String word, int count, boolean inclusive) {
String pluralized = count == 1 ? singular(word) : plural(word); String pluralized = count == 1 ? singular(word) : plural(word);
return (inclusive ? count + " " : "") + Strings.notNullize(pluralized, word); return (inclusive ? count + " " : "") + Strings.notNullize(pluralized, word);
} }
@Nullable public @Nullable String plural(@Nullable String word) {
public String plural(@Nullable String word) {
return restoreCase(word, replaceWord(word, irregularSingles, irregularPlurals, pluralRules)); return restoreCase(word, replaceWord(word, irregularSingles, irregularPlurals, pluralRules));
} }
@Nullable public @Nullable String singular(@Nullable String word) {
public String singular(@Nullable String word) {
return restoreCase(word, replaceWord(word, irregularPlurals, irregularSingles, singularRules)); return restoreCase(word, replaceWord(word, irregularPlurals, irregularSingles, singularRules));
} }

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. // Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.reference; package com.intellij.reference;
import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.ApiStatus;
@@ -41,13 +41,11 @@ public class SoftReference<T> extends java.lang.ref.SoftReference<T> implements
// return myReferent; // return myReferent;
//} //}
@Nullable public static @Nullable <T> T dereference(@Nullable Reference<T> ref) {
public static <T> T dereference(@Nullable Reference<T> ref) {
return ref == null ? null : ref.get(); return ref == null ? null : ref.get();
} }
@Nullable public static @Nullable <T> T deref(@Nullable Supplier<T> ref) {
public static <T> T deref(@Nullable Supplier<T> ref) {
return ref == null ? null : ref.get(); return ref == null ? null : ref.get();
} }
} }

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. // Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.util; package com.intellij.util;
import com.intellij.ReviseWhenPortedToJDK; import com.intellij.ReviseWhenPortedToJDK;
@@ -84,8 +84,7 @@ public class SmartList<E> extends AbstractList<E> implements RandomAccess {
} }
} }
@NotNull private static @NotNull String outOfBoundsMessage(int index, int size) {
private static String outOfBoundsMessage(int index, int size) {
return "Index: " + index + ", Size: " + size; return "Index: " + index + ", Size: " + size;
} }
@@ -237,9 +236,8 @@ public class SmartList<E> extends AbstractList<E> implements RandomAccess {
return oldValue; return oldValue;
} }
@NotNull
@Override @Override
public Iterator<E> iterator() { public @NotNull Iterator<E> iterator() {
return mySize == 0 ? Collections.emptyIterator() : super.iterator(); return mySize == 0 ? Collections.emptyIterator() : super.iterator();
} }

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. // Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.util.containers; package com.intellij.util.containers;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@@ -37,8 +37,7 @@ abstract class ConcurrentRefHashMap<K, V> extends AbstractMap<K, V> implements C
abstract @NotNull KeyReference<K> createKeyReference(@NotNull K key, @NotNull HashingStrategy<? super K> hashingStrategy); abstract @NotNull KeyReference<K> createKeyReference(@NotNull K key, @NotNull HashingStrategy<? super K> hashingStrategy);
@NotNull private @NotNull KeyReference<K> createKeyReference(@NotNull K key) {
private KeyReference<K> createKeyReference(@NotNull K key) {
return createKeyReference(key, myHashingStrategy); return createKeyReference(key, myHashingStrategy);
} }
@@ -151,8 +150,7 @@ abstract class ConcurrentRefHashMap<K, V> extends AbstractMap<K, V> implements C
} }
private static final ThreadLocal<HardKey<?>> HARD_KEY = ThreadLocal.withInitial(() -> new HardKey<>()); private static final ThreadLocal<HardKey<?>> HARD_KEY = ThreadLocal.withInitial(() -> new HardKey<>());
@NotNull private @NotNull HardKey<K> createHardKey(@NotNull Object o) {
private HardKey<K> createHardKey(@NotNull Object o) {
//noinspection unchecked //noinspection unchecked
K key = (K)o; K key = (K)o;
//noinspection unchecked //noinspection unchecked
@@ -244,9 +242,8 @@ abstract class ConcurrentRefHashMap<K, V> extends AbstractMap<K, V> implements C
private final class EntrySet extends AbstractSet<Map.Entry<K, V>> { private final class EntrySet extends AbstractSet<Map.Entry<K, V>> {
private final Set<Map.Entry<KeyReference<K>, V>> hashEntrySet = myMap.entrySet(); private final Set<Map.Entry<KeyReference<K>, V>> hashEntrySet = myMap.entrySet();
@NotNull
@Override @Override
public Iterator<Map.Entry<K, V>> iterator() { public @NotNull Iterator<Map.Entry<K, V>> iterator() {
return new Iterator<Map.Entry<K, V>>() { return new Iterator<Map.Entry<K, V>>() {
private final Iterator<Map.Entry<KeyReference<K>, V>> hashIterator = hashEntrySet.iterator(); private final Iterator<Map.Entry<KeyReference<K>, V>> hashIterator = hashEntrySet.iterator();
private RefEntry<K, V> next; private RefEntry<K, V> next;
@@ -343,9 +340,8 @@ abstract class ConcurrentRefHashMap<K, V> extends AbstractMap<K, V> implements C
private Set<Map.Entry<K, V>> entrySet; private Set<Map.Entry<K, V>> entrySet;
@NotNull
@Override @Override
public Set<Map.Entry<K, V>> entrySet() { public @NotNull Set<Map.Entry<K, V>> entrySet() {
Set<Entry<K, V>> es = entrySet; Set<Entry<K, V>> es = entrySet;
if (es == null) entrySet = es = new EntrySet(); if (es == null) entrySet = es = new EntrySet();
return es; return es;

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. // Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.util.containers; package com.intellij.util.containers;
import com.intellij.util.ObjectUtilsRt; import com.intellij.util.ObjectUtilsRt;
@@ -24,7 +24,7 @@ final class ConcurrentSoftKeySoftValueHashMap<K, V> extends ConcurrentWeakKeySof
private static class SoftKey<K, V> extends SoftReference<K> implements KeyReference<K, V> { private static class SoftKey<K, V> extends SoftReference<K> implements KeyReference<K, V> {
private final int myHash; // Hash code of the key, stored here since the key may be tossed by the GC private final int myHash; // Hash code of the key, stored here since the key may be tossed by the GC
private final HashingStrategy<? super K> myStrategy; private final HashingStrategy<? super K> myStrategy;
@NotNull private final ValueReference<K, V> myValueReference; private final @NotNull ValueReference<K, V> myValueReference;
SoftKey(@NotNull K k, SoftKey(@NotNull K k,
@NotNull ValueReference<K, V> valueReference, @NotNull ValueReference<K, V> valueReference,
@@ -52,16 +52,15 @@ final class ConcurrentSoftKeySoftValueHashMap<K, V> extends ConcurrentWeakKeySof
return myHash; return myHash;
} }
@NotNull
@Override @Override
public ValueReference<K, V> getValueReference() { public @NotNull ValueReference<K, V> getValueReference() {
return myValueReference; return myValueReference;
} }
} }
@Override @Override
@NotNull @NotNull
KeyReference<K,V> createKeyReference(@NotNull K k, @NotNull final V v) { KeyReference<K,V> createKeyReference(@NotNull K k, final @NotNull V v) {
final ValueReference<K, V> valueReference = createValueReference(v, myValueQueue); final ValueReference<K, V> valueReference = createValueReference(v, myValueQueue);
KeyReference<K,V> keyReference = new SoftKey<>(k, valueReference, myHashingStrategy, myKeyQueue); KeyReference<K,V> keyReference = new SoftKey<>(k, valueReference, myHashingStrategy, myKeyQueue);
if (valueReference instanceof SoftValue) { if (valueReference instanceof SoftValue) {

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. // Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.util.containers; package com.intellij.util.containers;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@@ -27,9 +27,8 @@ final class ConcurrentSoftValueHashMap<K,V> extends ConcurrentRefValueHashMap<K,
this.key = key; this.key = key;
} }
@NotNull
@Override @Override
public K getKey() { public @NotNull K getKey() {
return key; return key;
} }

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. // Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.util.containers; package com.intellij.util.containers;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@@ -29,7 +29,7 @@ final class ConcurrentWeakHashMap<K, V> extends ConcurrentRefHashMap<K, V> {
private static final class WeakKey<K> extends WeakReference<K> implements KeyReference<K> { private static final class WeakKey<K> extends WeakReference<K> implements KeyReference<K> {
private final int myHash; /* Hashcode of key, stored here since the key may be tossed by the GC */ private final int myHash; /* Hashcode of key, stored here since the key may be tossed by the GC */
@NotNull private final HashingStrategy<? super K> myStrategy; private final @NotNull HashingStrategy<? super K> myStrategy;
private WeakKey(@NotNull K k, private WeakKey(@NotNull K k,
int hash, int hash,

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. // Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.util.containers; package com.intellij.util.containers;
import com.intellij.util.ObjectUtilsRt; import com.intellij.util.ObjectUtilsRt;
@@ -25,7 +25,7 @@ public class ConcurrentWeakKeySoftValueHashMap<K, V> implements ConcurrentMap<K,
private final ConcurrentMap<KeyReference<K,V>, ValueReference<K,V>> myMap; private final ConcurrentMap<KeyReference<K,V>, ValueReference<K,V>> myMap;
final ReferenceQueue<K> myKeyQueue = new ReferenceQueue<>(); final ReferenceQueue<K> myKeyQueue = new ReferenceQueue<>();
final ReferenceQueue<V> myValueQueue = new ReferenceQueue<>(); final ReferenceQueue<V> myValueQueue = new ReferenceQueue<>();
@NotNull final HashingStrategy<? super K> myHashingStrategy; final @NotNull HashingStrategy<? super K> myHashingStrategy;
protected ConcurrentWeakKeySoftValueHashMap(int initialCapacity, protected ConcurrentWeakKeySoftValueHashMap(int initialCapacity,
float loadFactor, float loadFactor,
@@ -67,7 +67,7 @@ public class ConcurrentWeakKeySoftValueHashMap<K, V> implements ConcurrentMap<K,
static final class WeakKey<K, V> extends WeakReference<K> implements KeyReference<K, V> { static final class WeakKey<K, V> extends WeakReference<K> implements KeyReference<K, V> {
private final int myHash; // Hash code of the key, stored here since the key may be tossed by the GC private final int myHash; // Hash code of the key, stored here since the key may be tossed by the GC
private final HashingStrategy<? super K> myStrategy; private final HashingStrategy<? super K> myStrategy;
@NotNull private final ValueReference<K, V> myValueReference; private final @NotNull ValueReference<K, V> myValueReference;
WeakKey(@NotNull K k, WeakKey(@NotNull K k,
@NotNull ValueReference<K, V> valueReference, @NotNull ValueReference<K, V> valueReference,
@@ -95,15 +95,14 @@ public class ConcurrentWeakKeySoftValueHashMap<K, V> implements ConcurrentMap<K,
return myHash; return myHash;
} }
@NotNull
@Override @Override
public ValueReference<K, V> getValueReference() { public @NotNull ValueReference<K, V> getValueReference() {
return myValueReference; return myValueReference;
} }
} }
static final class SoftValue<K, V> extends SoftReference<V> implements ValueReference<K,V> { static final class SoftValue<K, V> extends SoftReference<V> implements ValueReference<K,V> {
@NotNull volatile KeyReference<K, V> myKeyReference; // can't make it final because of circular dependency of KeyReference to ValueReference volatile @NotNull KeyReference<K, V> myKeyReference; // can't make it final because of circular dependency of KeyReference to ValueReference
private SoftValue(@NotNull V value, @NotNull ReferenceQueue<? super V> queue) { private SoftValue(@NotNull V value, @NotNull ReferenceQueue<? super V> queue) {
super(value, queue); super(value, queue);
} }
@@ -121,15 +120,14 @@ public class ConcurrentWeakKeySoftValueHashMap<K, V> implements ConcurrentMap<K,
return v != null && v.equals(thatV); return v != null && v.equals(thatV);
} }
@NotNull
@Override @Override
public KeyReference<K, V> getKeyReference() { public @NotNull KeyReference<K, V> getKeyReference() {
return myKeyReference; return myKeyReference;
} }
} }
@NotNull @NotNull
KeyReference<K,V> createKeyReference(@NotNull K k, @NotNull final V v) { KeyReference<K,V> createKeyReference(@NotNull K k, final @NotNull V v) {
final ValueReference<K, V> valueReference = createValueReference(v, myValueQueue); final ValueReference<K, V> valueReference = createValueReference(v, myValueQueue);
KeyReference<K,V> keyReference = new WeakKey<>(k, valueReference, myHashingStrategy, myKeyQueue); KeyReference<K,V> keyReference = new WeakKey<>(k, valueReference, myHashingStrategy, myKeyQueue);
if (valueReference instanceof SoftValue) { if (valueReference instanceof SoftValue) {
@@ -139,8 +137,7 @@ public class ConcurrentWeakKeySoftValueHashMap<K, V> implements ConcurrentMap<K,
return keyReference; return keyReference;
} }
@NotNull protected @NotNull ValueReference<K, V> createValueReference(@NotNull V value, @NotNull ReferenceQueue<? super V> queue) {
protected ValueReference<K, V> createValueReference(@NotNull V value, @NotNull ReferenceQueue<? super V> queue) {
return new SoftValue<>(value, queue); return new SoftValue<>(value, queue);
} }
@@ -189,17 +186,15 @@ public class ConcurrentWeakKeySoftValueHashMap<K, V> implements ConcurrentMap<K,
return myHash; return myHash;
} }
@NotNull
@Override @Override
public ValueReference<K, V> getValueReference() { public @NotNull ValueReference<K, V> getValueReference() {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
} }
private static final ThreadLocal<HardKey<?,?>> HARD_KEY = ThreadLocal.withInitial(() -> new HardKey<>()); private static final ThreadLocal<HardKey<?,?>> HARD_KEY = ThreadLocal.withInitial(() -> new HardKey<>());
@NotNull private @NotNull HardKey<K,V> createHardKey(@NotNull Object o) {
private HardKey<K,V> createHardKey(@NotNull Object o) {
//noinspection unchecked //noinspection unchecked
K key = (K)o; K key = (K)o;
//noinspection unchecked //noinspection unchecked
@@ -280,15 +275,13 @@ public class ConcurrentWeakKeySoftValueHashMap<K, V> implements ConcurrentMap<K,
return removed; return removed;
} }
@NotNull
@Override @Override
public Set<K> keySet() { public @NotNull Set<K> keySet() {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@NotNull
@Override @Override
public Collection<V> values() { public @NotNull Collection<V> values() {
List<V> values = new ArrayList<>(); List<V> values = new ArrayList<>();
for (ValueReference<K, V> valueReference : myMap.values()) { for (ValueReference<K, V> valueReference : myMap.values()) {
V v = valueReference == null ? null : valueReference.get(); V v = valueReference == null ? null : valueReference.get();
@@ -299,9 +292,8 @@ public class ConcurrentWeakKeySoftValueHashMap<K, V> implements ConcurrentMap<K,
return values; return values;
} }
@NotNull
@Override @Override
public Set<Entry<K, V>> entrySet() { public @NotNull Set<Entry<K, V>> entrySet() {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. // Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.util.containers; package com.intellij.util.containers;
import com.intellij.util.ObjectUtilsRt; import com.intellij.util.ObjectUtilsRt;
@@ -22,7 +22,7 @@ final class ConcurrentWeakKeyWeakValueHashMap<K, V> extends ConcurrentWeakKeySof
} }
private static final class WeakValue<K, V> extends WeakReference<V> implements ValueReference<K,V> { private static final class WeakValue<K, V> extends WeakReference<V> implements ValueReference<K,V> {
@NotNull private volatile KeyReference<K, V> myKeyReference; // can't make it final because of circular dependency of KeyReference to ValueReference private volatile @NotNull KeyReference<K, V> myKeyReference; // can't make it final because of circular dependency of KeyReference to ValueReference
private WeakValue(@NotNull V value, @NotNull ReferenceQueue<? super V> queue) { private WeakValue(@NotNull V value, @NotNull ReferenceQueue<? super V> queue) {
super(value, queue); super(value, queue);
} }
@@ -40,16 +40,15 @@ final class ConcurrentWeakKeyWeakValueHashMap<K, V> extends ConcurrentWeakKeySof
return v != null && v.equals(thatV); return v != null && v.equals(thatV);
} }
@NotNull
@Override @Override
public KeyReference<K, V> getKeyReference() { public @NotNull KeyReference<K, V> getKeyReference() {
return myKeyReference; return myKeyReference;
} }
} }
@Override @Override
@NotNull @NotNull
KeyReference<K,V> createKeyReference(@NotNull K k, @NotNull final V v) { KeyReference<K,V> createKeyReference(@NotNull K k, final @NotNull V v) {
ValueReference<K, V> valueReference = createValueReference(v, myValueQueue); ValueReference<K, V> valueReference = createValueReference(v, myValueQueue);
WeakKey<K, V> keyReference = new WeakKey<>(k, valueReference, myHashingStrategy, myKeyQueue); WeakKey<K, V> keyReference = new WeakKey<>(k, valueReference, myHashingStrategy, myKeyQueue);
if (valueReference instanceof WeakValue) { if (valueReference instanceof WeakValue) {
@@ -60,8 +59,7 @@ final class ConcurrentWeakKeyWeakValueHashMap<K, V> extends ConcurrentWeakKeySof
} }
@Override @Override
@NotNull protected @NotNull ValueReference<K, V> createValueReference(@NotNull V value, @NotNull ReferenceQueue<? super V> queue) {
protected ValueReference<K, V> createValueReference(@NotNull V value, @NotNull ReferenceQueue<? super V> queue) {
return new WeakValue<>(value, queue); return new WeakValue<>(value, queue);
} }
} }

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. // Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.util.containers; package com.intellij.util.containers;
@@ -28,9 +28,8 @@ final class ConcurrentWeakValueHashMap<K,V> extends ConcurrentRefValueHashMap<K,
this.key = key; this.key = key;
} }
@NotNull
@Override @Override
public K getKey() { public @NotNull K getKey() {
return key; return key;
} }

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. // Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.util.containers; package com.intellij.util.containers;
import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.Comparing;
@@ -65,9 +65,8 @@ public final class FList<E> extends AbstractList<E> {
return this; return this;
} }
@NotNull
@Override @Override
public Iterator<E> iterator() { public @NotNull Iterator<E> iterator() {
return new Iterator<E>() { return new Iterator<E>() {
private FList<E> list = FList.this; private FList<E> list = FList.this;

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. // Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.util.containers; package com.intellij.util.containers;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@@ -10,7 +10,7 @@ import java.util.NoSuchElementException;
* Consider using {@link com.google.common.collect.Iterators#peekingIterator(Iterator)} instead. * Consider using {@link com.google.common.collect.Iterators#peekingIterator(Iterator)} instead.
*/ */
public class PeekableIteratorWrapper<T> implements PeekableIterator<T> { public class PeekableIteratorWrapper<T> implements PeekableIterator<T> {
@NotNull private final Iterator<? extends T> myIterator; private final @NotNull Iterator<? extends T> myIterator;
private T myValue = null; private T myValue = null;
private boolean myValidValue = false; private boolean myValidValue = false;

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. // Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.util.containers; package com.intellij.util.containers;
import com.intellij.util.ObjectUtilsRt; import com.intellij.util.ObjectUtilsRt;
@@ -18,8 +18,7 @@ abstract class RefHashMap<K, V> extends AbstractMap<K, V> implements Map<K, V> {
private final MyMap myMap; private final MyMap myMap;
private final ReferenceQueue<K> myReferenceQueue = new ReferenceQueue<>(); private final ReferenceQueue<K> myReferenceQueue = new ReferenceQueue<>();
private final HardKey myHardKeyInstance = new HardKey(); // "singleton" private final HardKey myHardKeyInstance = new HardKey(); // "singleton"
@NotNull private final @NotNull HashingStrategy<? super K> myStrategy;
private final HashingStrategy<? super K> myStrategy;
private Set<Entry<K, V>> entrySet; private Set<Entry<K, V>> entrySet;
RefHashMap(int initialCapacity, float loadFactor, @NotNull HashingStrategy<? super K> strategy) { RefHashMap(int initialCapacity, float loadFactor, @NotNull HashingStrategy<? super K> strategy) {
@@ -98,8 +97,7 @@ abstract class RefHashMap<K, V> extends AbstractMap<K, V> implements Map<K, V> {
boolean equals(Object o); boolean equals(Object o);
} }
@NotNull protected abstract @NotNull <T> Key<T> createKey(@NotNull T k, @NotNull HashingStrategy<? super T> strategy, @NotNull ReferenceQueue<? super T> q);
protected abstract <T> Key<T> createKey(@NotNull T k, @NotNull HashingStrategy<? super T> strategy, @NotNull ReferenceQueue<? super T> q);
private class HardKey implements Key<K> { private class HardKey implements Key<K> {
private K myObject; private K myObject;
@@ -232,7 +230,7 @@ abstract class RefHashMap<K, V> extends AbstractMap<K, V> implements Map<K, V> {
private final Entry<?, V> ent; private final Entry<?, V> ent;
private final K key; // Strong reference to key, so that the GC will leave it alone as long as this Entry exists private final K key; // Strong reference to key, so that the GC will leave it alone as long as this Entry exists
private final int myKeyHashCode; private final int myKeyHashCode;
@NotNull private final HashingStrategy<? super K> myStrategy; private final @NotNull HashingStrategy<? super K> myStrategy;
private MyEntry(@NotNull Entry<?, V> ent, @NotNull K key, int keyHashCode, @NotNull HashingStrategy<? super K> strategy) { private MyEntry(@NotNull Entry<?, V> ent, @NotNull K key, int keyHashCode, @NotNull HashingStrategy<? super K> strategy) {
this.ent = ent; this.ent = ent;
@@ -275,9 +273,8 @@ abstract class RefHashMap<K, V> extends AbstractMap<K, V> implements Map<K, V> {
private class EntrySet extends AbstractSet<Entry<K, V>> { private class EntrySet extends AbstractSet<Entry<K, V>> {
private final Set<Entry<Key<K>, V>> hashEntrySet = myMap.entrySet(); private final Set<Entry<Key<K>, V>> hashEntrySet = myMap.entrySet();
@NotNull
@Override @Override
public Iterator<Entry<K, V>> iterator() { public @NotNull Iterator<Entry<K, V>> iterator() {
return new Iterator<Entry<K, V>>() { return new Iterator<Entry<K, V>>() {
private final Iterator<Entry<Key<K>, V>> hashIterator = hashEntrySet.iterator(); private final Iterator<Entry<Key<K>, V>> hashIterator = hashEntrySet.iterator();
private MyEntry<K, V> next; private MyEntry<K, V> next;
@@ -366,9 +363,8 @@ abstract class RefHashMap<K, V> extends AbstractMap<K, V> implements Map<K, V> {
} }
} }
@NotNull
@Override @Override
public Set<Entry<K, V>> entrySet() { public @NotNull Set<Entry<K, V>> entrySet() {
Set<Entry<K, V>> es = entrySet; Set<Entry<K, V>> es = entrySet;
if (es == null) { if (es == null) {
entrySet = es = new EntrySet(); entrySet = es = new EntrySet();

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. // Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.util.containers; package com.intellij.util.containers;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@@ -24,8 +24,7 @@ abstract class RefKeyRefValueHashMap<K,V> implements Map<K,V>{
return reference == null ? null : reference.get(); return reference == null ? null : reference.get();
} }
@NotNull protected abstract @NotNull ValueReference<K,V> createValueReference(@NotNull RefHashMap.Key<K> key, V referent, ReferenceQueue<? super V> q);
protected abstract ValueReference<K,V> createValueReference(@NotNull RefHashMap.Key<K> key, V referent, ReferenceQueue<? super V> q);
// returns true if some refs were tossed // returns true if some refs were tossed
boolean processQueue() { boolean processQueue() {
@@ -94,15 +93,13 @@ abstract class RefKeyRefValueHashMap<K,V> implements Map<K,V>{
throw RefValueHashMapUtil.pointlessContainsValue(); throw RefValueHashMapUtil.pointlessContainsValue();
} }
@NotNull
@Override @Override
public Set<K> keySet() { public @NotNull Set<K> keySet() {
return myMap.keySet(); return myMap.keySet();
} }
@NotNull
@Override @Override
public Collection<V> values() { public @NotNull Collection<V> values() {
List<V> result = new ArrayList<>(); List<V> result = new ArrayList<>();
final Collection<ValueReference<K, V>> refs = myMap.values(); final Collection<ValueReference<K, V>> refs = myMap.values();
for (ValueReference<K, V> ref : refs) { for (ValueReference<K, V> ref : refs) {
@@ -114,9 +111,8 @@ abstract class RefKeyRefValueHashMap<K,V> implements Map<K,V>{
return result; return result;
} }
@NotNull
@Override @Override
public Set<Entry<K, V>> entrySet() { public @NotNull Set<Entry<K, V>> entrySet() {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
} }

View File

@@ -1,17 +1,15 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. // Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.util.containers; package com.intellij.util.containers;
import com.intellij.util.IncorrectOperationException; import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
public final class RefValueHashMapUtil { public final class RefValueHashMapUtil {
@NotNull public static @NotNull IncorrectOperationException pointlessContainsKey() {
public static IncorrectOperationException pointlessContainsKey() {
return new IncorrectOperationException("containsKey() makes no sense for weak/soft map because GC can clear the value any moment now"); return new IncorrectOperationException("containsKey() makes no sense for weak/soft map because GC can clear the value any moment now");
} }
@NotNull public static @NotNull IncorrectOperationException pointlessContainsValue() {
public static IncorrectOperationException pointlessContainsValue() {
return new IncorrectOperationException("containsValue() makes no sense for weak/soft map because GC can clear the key any moment now"); return new IncorrectOperationException("containsValue() makes no sense for weak/soft map because GC can clear the key any moment now");
} }
} }

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. // Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.util.containers; package com.intellij.util.containers;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@@ -27,8 +27,7 @@ final class SoftHashMap<K,V> extends RefHashMap<K,V> {
private static final class SoftKey<T> extends SoftReference<T> implements Key<T> { private static final class SoftKey<T> extends SoftReference<T> implements Key<T> {
private final int myHash; /* Hash code of key, stored here since the key may be tossed by the GC */ private final int myHash; /* Hash code of key, stored here since the key may be tossed by the GC */
@NotNull private final @NotNull HashingStrategy<? super T> myStrategy;
private final HashingStrategy<? super T> myStrategy;
private SoftKey(@NotNull T k, @NotNull HashingStrategy<? super T> strategy, @NotNull ReferenceQueue<? super T> q) { private SoftKey(@NotNull T k, @NotNull HashingStrategy<? super T> strategy, @NotNull ReferenceQueue<? super T> q) {
super(k, q); super(k, q);

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. // Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.util.containers; package com.intellij.util.containers;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@@ -90,15 +90,13 @@ final class SoftKeySoftValueHashMap<K,V> implements Map<K,V>{
throw RefValueHashMapUtil.pointlessContainsValue(); throw RefValueHashMapUtil.pointlessContainsValue();
} }
@NotNull
@Override @Override
public Set<K> keySet() { public @NotNull Set<K> keySet() {
return mySoftKeyMap.keySet(); return mySoftKeyMap.keySet();
} }
@NotNull
@Override @Override
public Collection<V> values() { public @NotNull Collection<V> values() {
List<V> result = new ArrayList<>(); List<V> result = new ArrayList<>();
Collection<ValueReference<K, V>> refs = mySoftKeyMap.values(); Collection<ValueReference<K, V>> refs = mySoftKeyMap.values();
for (ValueReference<K, V> ref : refs) { for (ValueReference<K, V> ref : refs) {
@@ -110,9 +108,8 @@ final class SoftKeySoftValueHashMap<K,V> implements Map<K,V>{
return result; return result;
} }
@NotNull
@Override @Override
public Set<Entry<K, V>> entrySet() { public @NotNull Set<Entry<K, V>> entrySet() {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
} }

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. // Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.util.containers; package com.intellij.util.containers;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@@ -13,25 +13,23 @@ final class WeakKeySoftValueHashMap<K,V> extends RefKeyRefValueHashMap<K,V> impl
} }
private static final class SoftValueReference<K,V> extends SoftReference<V> implements ValueReference<K,V> { private static final class SoftValueReference<K,V> extends SoftReference<V> implements ValueReference<K,V> {
@NotNull private final RefHashMap.Key<K> key; private final @NotNull RefHashMap.Key<K> key;
private SoftValueReference(@NotNull RefHashMap.Key<K> key, V referent, ReferenceQueue<? super V> q) { private SoftValueReference(@NotNull RefHashMap.Key<K> key, V referent, ReferenceQueue<? super V> q) {
super(referent, q); super(referent, q);
this.key = key; this.key = key;
} }
@NotNull
@Override @Override
public RefHashMap.Key<K> getKey() { public @NotNull RefHashMap.Key<K> getKey() {
return key; return key;
} }
} }
@NotNull
@Override @Override
protected ValueReference<K, V> createValueReference(@NotNull RefHashMap.Key<K> key, protected @NotNull ValueReference<K, V> createValueReference(@NotNull RefHashMap.Key<K> key,
V referent, V referent,
ReferenceQueue<? super V> q) { ReferenceQueue<? super V> q) {
return new SoftValueReference<>(key, referent, q); return new SoftValueReference<>(key, referent, q);
} }
} }

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. // Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.util.containers; package com.intellij.util.containers;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@@ -13,25 +13,23 @@ final class WeakKeyWeakValueHashMap<K,V> extends RefKeyRefValueHashMap<K,V> impl
} }
private static final class WeakValueReference<K,V> extends WeakReference<V> implements ValueReference<K,V> { private static final class WeakValueReference<K,V> extends WeakReference<V> implements ValueReference<K,V> {
@NotNull private final RefHashMap.Key<K> key; private final @NotNull RefHashMap.Key<K> key;
private WeakValueReference(@NotNull RefHashMap.Key<K> key, V referent, ReferenceQueue<? super V> q) { private WeakValueReference(@NotNull RefHashMap.Key<K> key, V referent, ReferenceQueue<? super V> q) {
super(referent, q); super(referent, q);
this.key = key; this.key = key;
} }
@NotNull
@Override @Override
public RefHashMap.Key<K> getKey() { public @NotNull RefHashMap.Key<K> getKey() {
return key; return key;
} }
} }
@NotNull
@Override @Override
protected ValueReference<K, V> createValueReference(@NotNull RefHashMap.Key<K> key, protected @NotNull ValueReference<K, V> createValueReference(@NotNull RefHashMap.Key<K> key,
V referent, V referent,
ReferenceQueue<? super V> q) { ReferenceQueue<? super V> q) {
return new WeakValueReference<>(key, referent, q); return new WeakValueReference<>(key, referent, q);
} }
} }

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. // Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.util.text; package com.intellij.util.text;
import com.intellij.ReviseWhenPortedToJDK; import com.intellij.ReviseWhenPortedToJDK;
@@ -46,15 +46,13 @@ public final class ByteArrayCharSequence implements CharSequenceWithStringHash {
return (char)(myChars[index + myStart] & 0xff); return (char)(myChars[index + myStart] & 0xff);
} }
@NotNull
@Override @Override
public CharSequence subSequence(int start, int end) { public @NotNull CharSequence subSequence(int start, int end) {
return start == 0 && end == length() ? this : new ByteArrayCharSequence(myChars, myStart + start, myStart + end); return start == 0 && end == length() ? this : new ByteArrayCharSequence(myChars, myStart + start, myStart + end);
} }
@Override @Override
@NotNull public @NotNull String toString() {
public String toString() {
return new String(myChars, myStart, length(), StandardCharsets.ISO_8859_1); return new String(myChars, myStart, length(), StandardCharsets.ISO_8859_1);
} }

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. // Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.util.text; package com.intellij.util.text;
import com.intellij.openapi.util.text.CharSequenceWithStringHash; import com.intellij.openapi.util.text.CharSequenceWithStringHash;
@@ -33,15 +33,13 @@ public class CharArrayCharSequence implements CharSequenceBackedByArray, CharSeq
return myChars[index + myStart]; return myChars[index + myStart];
} }
@NotNull
@Override @Override
public CharSequence subSequence(int start, int end) { public @NotNull CharSequence subSequence(int start, int end) {
return start == 0 && end == length() ? this : new CharArrayCharSequence(myChars, myStart + start, myStart + end); return start == 0 && end == length() ? this : new CharArrayCharSequence(myChars, myStart + start, myStart + end);
} }
@Override @Override
@NotNull public @NotNull String toString() {
public String toString() {
return new String(myChars, myStart, myEnd - myStart); //TODO StringFactory return new String(myChars, myStart, myEnd - myStart); //TODO StringFactory
} }

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. // Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.util.text; package com.intellij.util.text;
import com.intellij.openapi.util.TextRange; import com.intellij.openapi.util.TextRange;
@@ -41,7 +41,7 @@ public final class CharArrayUtil {
} }
/** /**
* Copies necessary number of symbols from the given char sequence to the given array. * Copies the necessary number of symbols from the given char sequence to the given array.
* *
* @param src source data holder * @param src source data holder
* @param dst output data buffer * @param dst output data buffer
@@ -111,7 +111,7 @@ public final class CharArrayUtil {
} }
/** /**
* @return a new char array containing the sub-sequence's chars * @return a new char array containing the subsequence's chars
*/ */
public static char @NotNull [] fromSequence(@NotNull CharSequence seq, int start, int end) { public static char @NotNull [] fromSequence(@NotNull CharSequence seq, int start, int end) {
char[] result = new char[end - start]; char[] result = new char[end - start];
@@ -346,7 +346,7 @@ public final class CharArrayUtil {
} }
/** /**
* Tries to find index of given pattern at the given buffer. * Tries to find index of a given pattern at the given buffer.
* *
* @param buffer characters buffer which contents should be checked for the given pattern * @param buffer characters buffer which contents should be checked for the given pattern
* @param pattern target characters sequence to find at the given buffer * @param pattern target characters sequence to find at the given buffer
@@ -501,12 +501,12 @@ public final class CharArrayUtil {
} }
/** /**
* Allows to answer if target region of the given text contains only white space symbols (tabulations, white spaces and line feeds). * Allows answering if a target region of the given text contains only white space symbols (tabulations, white spaces, and line feeds).
* *
* @param text text to check * @param text text to check
* @param start start offset within the given text to check (inclusive) * @param start start offset within the given text to check (inclusive)
* @param end end offset within the given text to check (exclusive) * @param end end offset within the given text to check (exclusive)
* @return {@code true} if target region of the given text contains white space symbols only; {@code false} otherwise * @return {@code true} if a target region of the given text contains white space symbols only; {@code false} otherwise
*/ */
public static boolean isEmptyOrSpaces(@NotNull CharSequence text, int start, int end) { public static boolean isEmptyOrSpaces(@NotNull CharSequence text, int start, int end) {
for (int i = start; i < end; i++) { for (int i = start; i < end; i++) {
@@ -518,15 +518,13 @@ public final class CharArrayUtil {
return true; return true;
} }
@NotNull public static @NotNull Reader readerFromCharSequence(@NotNull CharSequence text) {
public static Reader readerFromCharSequence(@NotNull CharSequence text) {
char[] chars = fromSequenceWithoutCopying(text); char[] chars = fromSequenceWithoutCopying(text);
return chars == null ? new CharSequenceReader(text) : new UnsyncCharArrayReader(chars, 0, text.length()); return chars == null ? new CharSequenceReader(text) : new UnsyncCharArrayReader(chars, 0, text.length());
} }
@NotNull
//TODO: move to a better place or inline, because it creates excessive dependencies //TODO: move to a better place or inline, because it creates excessive dependencies
public static ImmutableCharSequence createImmutableCharSequence(@NotNull CharSequence sequence) { public static @NotNull ImmutableCharSequence createImmutableCharSequence(@NotNull CharSequence sequence) {
return ImmutableText.valueOf(sequence); return ImmutableText.valueOf(sequence);
} }
} }

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. // Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.util.text; package com.intellij.util.text;
@@ -49,16 +49,14 @@ public class CharSequenceSubSequence implements CharSequence, CharArrayExternali
return myChars.charAt(index + myStart); return myChars.charAt(index + myStart);
} }
@NotNull
@Override @Override
public CharSequence subSequence(int start, int end) { public @NotNull CharSequence subSequence(int start, int end) {
if (start == myStart && end == myEnd) return this; if (start == myStart && end == myEnd) return this;
return new CharSequenceSubSequence(myChars, myStart + start, myStart + end); return new CharSequenceSubSequence(myChars, myStart + start, myStart + end);
} }
@Override @Override
@NotNull public @NotNull String toString() {
public String toString() {
if (myChars instanceof String) return ((String)myChars).substring(myStart, myEnd); if (myChars instanceof String) return ((String)myChars).substring(myStart, myEnd);
return new String(CharArrayUtil.fromSequence(myChars, myStart, myEnd)); return new String(CharArrayUtil.fromSequence(myChars, myStart, myEnd));
} }

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. // Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.util.text; package com.intellij.util.text;
import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.Contract;
@@ -7,38 +7,32 @@ import org.jetbrains.annotations.NotNull;
public abstract class ImmutableCharSequence implements CharSequence { public abstract class ImmutableCharSequence implements CharSequence {
@Contract(pure = true) @Contract(pure = true)
public static CharSequence asImmutable(@NotNull final CharSequence cs) { public static CharSequence asImmutable(final @NotNull CharSequence cs) {
return isImmutable(cs) ? cs : cs.toString(); return isImmutable(cs) ? cs : cs.toString();
} }
private static boolean isImmutable(@NotNull final CharSequence cs) { private static boolean isImmutable(final @NotNull CharSequence cs) {
return cs instanceof ImmutableCharSequence || return cs instanceof ImmutableCharSequence ||
cs instanceof CharSequenceSubSequence && isImmutable(((CharSequenceSubSequence)cs).getBaseSequence()); cs instanceof CharSequenceSubSequence && isImmutable(((CharSequenceSubSequence)cs).getBaseSequence());
} }
@Contract(pure = true) @Contract(pure = true)
@NotNull public abstract @NotNull ImmutableCharSequence concat(@NotNull CharSequence sequence);
public abstract ImmutableCharSequence concat(@NotNull CharSequence sequence);
@Contract(pure = true) @Contract(pure = true)
@NotNull public abstract @NotNull ImmutableCharSequence insert(int index, @NotNull CharSequence seq);
public abstract ImmutableCharSequence insert(int index, @NotNull CharSequence seq);
@Contract(pure = true) @Contract(pure = true)
@NotNull public abstract @NotNull ImmutableCharSequence delete(int start, int end);
public abstract ImmutableCharSequence delete(int start, int end);
@Contract(pure = true) @Contract(pure = true)
@NotNull public abstract @NotNull ImmutableCharSequence subtext(int start, int end);
public abstract ImmutableCharSequence subtext(int start, int end);
@Contract(pure = true) @Contract(pure = true)
@NotNull public @NotNull ImmutableCharSequence replace(int start, int end, @NotNull CharSequence seq) {
public ImmutableCharSequence replace(int start, int end, @NotNull CharSequence seq) {
return delete(start, end).insert(start, seq); return delete(start, end).insert(start, seq);
} }
@NotNull
@Override @Override
public abstract String toString(); public abstract @NotNull String toString();
} }

View File

@@ -65,8 +65,7 @@ final class ImmutableText extends ImmutableCharSequence implements CharArrayExte
// visible for tests // visible for tests
// Here (String | CompositeNode | ByteArrayCharSequence) is stored // Here (String | CompositeNode | ByteArrayCharSequence) is stored
@NotNull final @NotNull CharSequence myNode;
final CharSequence myNode;
private ImmutableText(@NotNull CharSequence node) { private ImmutableText(@NotNull CharSequence node) {
myNode = node; myNode = node;
@@ -78,15 +77,13 @@ final class ImmutableText extends ImmutableCharSequence implements CharArrayExte
* @param obj the object to represent as text. * @param obj the object to represent as text.
* @return the textual representation of the specified object. * @return the textual representation of the specified object.
*/ */
@NotNull static @NotNull ImmutableText valueOf(@NotNull Object obj) {
static ImmutableText valueOf(@NotNull Object obj) {
if (obj instanceof ImmutableText) return (ImmutableText)obj; if (obj instanceof ImmutableText) return (ImmutableText)obj;
if (obj instanceof CharSequence) return valueOf((CharSequence)obj); if (obj instanceof CharSequence) return valueOf((CharSequence)obj);
return valueOf(String.valueOf(obj)); return valueOf(String.valueOf(obj));
} }
@NotNull private static @NotNull ImmutableText valueOf(@NotNull CharSequence str) {
private static ImmutableText valueOf(@NotNull CharSequence str) {
if (str instanceof ByteArrayCharSequence) { if (str instanceof ByteArrayCharSequence) {
return new ImmutableText(str); return new ImmutableText(str);
} }
@@ -103,16 +100,14 @@ final class ImmutableText extends ImmutableCharSequence implements CharArrayExte
* *
* @return a copy of the myNode better prepared for small modifications to fully enable structure-sharing capabilities * @return a copy of the myNode better prepared for small modifications to fully enable structure-sharing capabilities
*/ */
@NotNull private @NotNull CharSequence ensureChunked() {
private CharSequence ensureChunked() {
if (length() > BLOCK_SIZE && !(myNode instanceof CompositeNode)) { if (length() > BLOCK_SIZE && !(myNode instanceof CompositeNode)) {
return nodeOf(myNode, 0, length()); return nodeOf(myNode, 0, length());
} }
return myNode; return myNode;
} }
@NotNull private static @NotNull CharSequence nodeOf(@NotNull CharSequence node, int offset, int length) {
private static CharSequence nodeOf(@NotNull CharSequence node, int offset, int length) {
if (length <= BLOCK_SIZE) { if (length <= BLOCK_SIZE) {
// Use toString to avoid referencing the original byte[] array in case if node is ByteArrayCharSequence // Use toString to avoid referencing the original byte[] array in case if node is ByteArrayCharSequence
return node.subSequence(offset, offset + length).toString(); return node.subSequence(offset, offset + length).toString();
@@ -143,8 +138,7 @@ final class ImmutableText extends ImmutableCharSequence implements CharArrayExte
* @param that the text that is concatenated. * @param that the text that is concatenated.
* @return {@code this + that} * @return {@code this + that}
*/ */
@NotNull private @NotNull ImmutableText concat(@NotNull ImmutableText that) {
private ImmutableText concat(@NotNull ImmutableText that) {
return that.length() == 0 ? this : length() == 0 ? that : new ImmutableText(concatNodes(ensureChunked(), that.ensureChunked())); return that.length() == 0 ? this : length() == 0 ? that : new ImmutableText(concatNodes(ensureChunked(), that.ensureChunked()));
} }
@@ -200,8 +194,7 @@ final class ImmutableText extends ImmutableCharSequence implements CharArrayExte
} }
@Override @Override
@NotNull public @NotNull CharSequence subSequence(final int start, final int end) {
public CharSequence subSequence(final int start, final int end) {
if (start == 0 && end == length()) return this; if (start == 0 && end == length()) return this;
return new CharSequenceSubSequence(this, start, end); return new CharSequenceSubSequence(this, start, end);
} }
@@ -242,8 +235,7 @@ final class ImmutableText extends ImmutableCharSequence implements CharArrayExte
} }
private InnerLeaf myLastLeaf; private InnerLeaf myLastLeaf;
@NotNull private @NotNull InnerLeaf findLeaf(int index) {
private InnerLeaf findLeaf(int index) {
if (index < 0) throw outOfRange(index); if (index < 0) throw outOfRange(index);
CharSequence node = myNode; CharSequence node = myNode;
@@ -347,13 +339,11 @@ final class ImmutableText extends ImmutableCharSequence implements CharArrayExte
* @return the {@code java.lang.String} for this text. * @return the {@code java.lang.String} for this text.
*/ */
@Override @Override
@NotNull public @NotNull String toString() {
public String toString() {
return myNode.toString(); return myNode.toString();
} }
@NotNull private static @NotNull CharSequence concatNodes(@NotNull CharSequence node1, @NotNull CharSequence node2) {
private static CharSequence concatNodes(@NotNull CharSequence node1, @NotNull CharSequence node2) {
// All Text instances are maintained balanced: // All Text instances are maintained balanced:
// (head < tail * 2) & (tail < head * 2) // (head < tail * 2) & (tail < head * 2)
final int length = node1.length() + node2.length(); final int length = node1.length() + node2.length();
@@ -464,8 +454,7 @@ final class ImmutableText extends ImmutableCharSequence implements CharArrayExte
} }
@Override @Override
@NotNull public @NotNull CharSequence subSequence(int start, int end) {
public CharSequence subSequence(int start, int end) {
int cesure = head.length(); int cesure = head.length();
if (end <= cesure) { if (end <= cesure) {
return head.subSequence(start, end); return head.subSequence(start, end);
@@ -486,9 +475,8 @@ final class ImmutableText extends ImmutableCharSequence implements CharArrayExte
return concatNodes(head.subSequence(start, cesure), tail.subSequence(0, end - cesure)); return concatNodes(head.subSequence(start, cesure), tail.subSequence(0, end - cesure));
} }
@NotNull
@Override @Override
public String toString() { public @NotNull String toString() {
int len = length(); int len = length();
char[] data = new char[len]; char[] data = new char[len];
getChars(0, len, data, 0); getChars(0, len, data, 0);

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. // Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.util.text; package com.intellij.util.text;
import com.intellij.openapi.util.NlsSafe; import com.intellij.openapi.util.NlsSafe;
@@ -18,8 +18,7 @@ public final class SemVer implements Comparable<SemVer> {
private final int myMajor; private final int myMajor;
private final int myMinor; private final int myMinor;
private final int myPatch; private final int myPatch;
@Nullable private final @Nullable String myPreRelease;
private final String myPreRelease;
public SemVer(@NotNull String rawVersion, int major, int minor, int patch) { public SemVer(@NotNull String rawVersion, int major, int minor, int patch) {
this(rawVersion, major, minor, patch, null); this(rawVersion, major, minor, patch, null);
@@ -170,8 +169,7 @@ public final class SemVer implements Comparable<SemVer> {
return diff; return diff;
} }
@Nullable public static @Nullable SemVer parseFromText(@Nullable String text) {
public static SemVer parseFromText(@Nullable String text) {
if (text != null) { if (text != null) {
int majorEndIdx = text.indexOf('.'); int majorEndIdx = text.indexOf('.');
if (majorEndIdx >= 0) { if (majorEndIdx >= 0) {

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. // Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.util.text; package com.intellij.util.text;
import com.intellij.openapi.util.text.Strings; import com.intellij.openapi.util.text.Strings;
@@ -58,8 +58,7 @@ public final class StringSearcher {
Character.isJavaIdentifierPart(pattern.charAt(pattern.length() - 1)); Character.isJavaIdentifierPart(pattern.charAt(pattern.length() - 1));
} }
@NotNull public @NotNull String getPattern(){
public String getPattern(){
return myPattern; return myPattern;
} }