mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-14 18:05:27 +07:00
cleanup - sort modifiers
GitOrigin-RevId: dc2cc5e5cc2d1f474d6d26808a8862448bd8b742
This commit is contained in:
committed by
intellij-monorepo-bot
parent
138cf5f4dc
commit
81a5bdf1b0
@@ -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;
|
||||
|
||||
import com.intellij.openapi.util.text.StringUtilRt;
|
||||
@@ -26,15 +26,13 @@ public final class ThreadDumper {
|
||||
private ThreadDumper() {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String dumpThreadsToString() {
|
||||
public static @NotNull String dumpThreadsToString() {
|
||||
StringWriter writer = new StringWriter();
|
||||
dumpThreadInfos(getThreadInfos(), writer);
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String dumpEdtStackTrace(ThreadInfo @NotNull [] threadInfos) {
|
||||
public static @NotNull String dumpEdtStackTrace(ThreadInfo @NotNull [] threadInfos) {
|
||||
StringWriter writer = new StringWriter();
|
||||
if (threadInfos.length > 0) {
|
||||
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.
|
||||
* Enabling this flag should significantly reduce coroutine dump size.
|
||||
*/
|
||||
@NotNull
|
||||
public static ThreadDump getThreadDumpInfo(ThreadInfo @NotNull [] threadInfos, boolean stripCoroutineDump) {
|
||||
public static @NotNull ThreadDump getThreadDumpInfo(ThreadInfo @NotNull [] threadInfos, boolean stripCoroutineDump) {
|
||||
sort(threadInfos);
|
||||
StringWriter writer = new StringWriter();
|
||||
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[])}
|
||||
*/
|
||||
@Nullable
|
||||
public static String getEdtStackForCrash(@NotNull String fullThreadDump, @NotNull String exceptionType) {
|
||||
public static @Nullable 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
|
||||
// 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"));
|
||||
|
||||
@@ -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;
|
||||
|
||||
import org.jetbrains.annotations.Contract;
|
||||
@@ -104,21 +104,18 @@ public class TextRange implements Segment, Serializable {
|
||||
return myStartOffset <= offset && offset < myEndOffset;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Contract(pure = true)
|
||||
public String substring(@NotNull String str) {
|
||||
public @NotNull String substring(@NotNull String str) {
|
||||
return str.substring(myStartOffset, myEndOffset);
|
||||
}
|
||||
|
||||
@Contract(pure = true)
|
||||
@NotNull
|
||||
public CharSequence subSequence(@NotNull CharSequence str) {
|
||||
public @NotNull CharSequence subSequence(@NotNull CharSequence str) {
|
||||
return str.subSequence(myStartOffset, myEndOffset);
|
||||
}
|
||||
|
||||
@Contract(pure = true)
|
||||
@NotNull
|
||||
public TextRange cutOut(@NotNull TextRange subRange) {
|
||||
public @NotNull TextRange cutOut(@NotNull TextRange subRange) {
|
||||
if (subRange.getStartOffset() > getLength()) {
|
||||
throw new IllegalArgumentException("SubRange: " + subRange + "; this=" + this);
|
||||
}
|
||||
@@ -131,22 +128,19 @@ public class TextRange implements Segment, Serializable {
|
||||
}
|
||||
|
||||
@Contract(pure = true)
|
||||
@NotNull
|
||||
public TextRange shiftRight(int delta) {
|
||||
public @NotNull TextRange shiftRight(int delta) {
|
||||
if (delta == 0) return this;
|
||||
return new TextRange(myStartOffset + delta, myEndOffset + delta);
|
||||
}
|
||||
|
||||
@Contract(pure = true)
|
||||
@NotNull
|
||||
public TextRange shiftLeft(int delta) {
|
||||
public @NotNull TextRange shiftLeft(int delta) {
|
||||
if (delta == 0) return this;
|
||||
return new TextRange(myStartOffset - delta, myEndOffset - delta);
|
||||
}
|
||||
|
||||
@Contract(pure = true)
|
||||
@NotNull
|
||||
public TextRange grown(int lengthDelta) {
|
||||
public @NotNull TextRange grown(int lengthDelta) {
|
||||
if (lengthDelta == 0) {
|
||||
return this;
|
||||
}
|
||||
@@ -154,20 +148,17 @@ public class TextRange implements Segment, Serializable {
|
||||
}
|
||||
|
||||
@Contract(pure = true)
|
||||
@NotNull
|
||||
public static TextRange from(int offset, int length) {
|
||||
public static @NotNull TextRange from(int offset, int length) {
|
||||
return create(offset, offset + length);
|
||||
}
|
||||
|
||||
@Contract(pure = true)
|
||||
@NotNull
|
||||
public static TextRange create(int startOffset, int endOffset) {
|
||||
public static @NotNull TextRange create(int startOffset, int endOffset) {
|
||||
return new TextRange(startOffset, endOffset);
|
||||
}
|
||||
|
||||
@Contract(pure = true)
|
||||
@NotNull
|
||||
public static TextRange create(@NotNull Segment segment) {
|
||||
public static @NotNull TextRange create(@NotNull Segment segment) {
|
||||
return create(segment.getStartOffset(), segment.getEndOffset());
|
||||
}
|
||||
|
||||
@@ -178,8 +169,7 @@ public class TextRange implements Segment, Serializable {
|
||||
}
|
||||
|
||||
@Contract(pure = true)
|
||||
@NotNull
|
||||
public String replace(@NotNull String original, @NotNull String replacement) {
|
||||
public @NotNull String replace(@NotNull String original, @NotNull String replacement) {
|
||||
String beginning = original.substring(0, getStartOffset());
|
||||
String ending = original.substring(getEndOffset());
|
||||
return beginning + replacement + ending;
|
||||
@@ -226,8 +216,7 @@ public class TextRange implements Segment, Serializable {
|
||||
}
|
||||
|
||||
@Contract(pure = true)
|
||||
@NotNull
|
||||
public TextRange union(@NotNull TextRange textRange) {
|
||||
public @NotNull TextRange union(@NotNull TextRange textRange) {
|
||||
if (equals(textRange)) {
|
||||
return this;
|
||||
}
|
||||
@@ -240,8 +229,7 @@ public class TextRange implements Segment, Serializable {
|
||||
}
|
||||
|
||||
@Contract(pure = true)
|
||||
@NotNull
|
||||
public static TextRange allOf(@NotNull String s) {
|
||||
public static @NotNull TextRange allOf(@NotNull String s) {
|
||||
return new TextRange(0, s.length());
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
import com.intellij.util.ArrayUtilRt;
|
||||
@@ -25,13 +25,11 @@ public final class LineTokenizer {
|
||||
return strings.isEmpty() ? ArrayUtilRt.EMPTY_STRING_ARRAY : ArrayUtilRt.toStringArray(strings);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<String> tokenizeIntoList(CharSequence chars, final boolean includeSeparators) {
|
||||
public static @NotNull List<String> tokenizeIntoList(CharSequence chars, final boolean includeSeparators) {
|
||||
return tokenizeIntoList(chars, includeSeparators, true);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<String> tokenizeIntoList(CharSequence chars, final boolean includeSeparators, final boolean skipLastEmptyLine) {
|
||||
public static @NotNull List<String> tokenizeIntoList(CharSequence chars, final boolean includeSeparators, final boolean skipLastEmptyLine) {
|
||||
if (chars == null || chars.length() == 0){
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@@ -132,20 +132,17 @@ public final class Pluralizer {
|
||||
/**
|
||||
* Pluralize or singularize a word based on the passed in count.
|
||||
*/
|
||||
@NotNull
|
||||
public String pluralize(@NotNull String word, int count, boolean inclusive) {
|
||||
public @NotNull String pluralize(@NotNull String word, int count, boolean inclusive) {
|
||||
String pluralized = count == 1 ? singular(word) : plural(word);
|
||||
|
||||
return (inclusive ? count + " " : "") + Strings.notNullize(pluralized, word);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String plural(@Nullable String word) {
|
||||
public @Nullable String plural(@Nullable String word) {
|
||||
return restoreCase(word, replaceWord(word, irregularSingles, irregularPlurals, pluralRules));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String singular(@Nullable String word) {
|
||||
public @Nullable String singular(@Nullable String word) {
|
||||
return restoreCase(word, replaceWord(word, irregularPlurals, irregularSingles, singularRules));
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
@@ -41,13 +41,11 @@ public class SoftReference<T> extends java.lang.ref.SoftReference<T> implements
|
||||
// return myReferent;
|
||||
//}
|
||||
|
||||
@Nullable
|
||||
public static <T> T dereference(@Nullable Reference<T> ref) {
|
||||
public static @Nullable <T> T dereference(@Nullable Reference<T> ref) {
|
||||
return ref == null ? null : ref.get();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static <T> T deref(@Nullable Supplier<T> ref) {
|
||||
public static @Nullable <T> T deref(@Nullable Supplier<T> ref) {
|
||||
return ref == null ? null : ref.get();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
import com.intellij.ReviseWhenPortedToJDK;
|
||||
@@ -84,8 +84,7 @@ public class SmartList<E> extends AbstractList<E> implements RandomAccess {
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String outOfBoundsMessage(int index, int size) {
|
||||
private static @NotNull String outOfBoundsMessage(int index, int size) {
|
||||
return "Index: " + index + ", Size: " + size;
|
||||
}
|
||||
|
||||
@@ -237,9 +236,8 @@ public class SmartList<E> extends AbstractList<E> implements RandomAccess {
|
||||
return oldValue;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Iterator<E> iterator() {
|
||||
public @NotNull Iterator<E> iterator() {
|
||||
return mySize == 0 ? Collections.emptyIterator() : super.iterator();
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
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);
|
||||
|
||||
@NotNull
|
||||
private KeyReference<K> createKeyReference(@NotNull K key) {
|
||||
private @NotNull KeyReference<K> createKeyReference(@NotNull K key) {
|
||||
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<>());
|
||||
|
||||
@NotNull
|
||||
private HardKey<K> createHardKey(@NotNull Object o) {
|
||||
private @NotNull HardKey<K> createHardKey(@NotNull Object o) {
|
||||
//noinspection unchecked
|
||||
K key = (K)o;
|
||||
//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 Set<Map.Entry<KeyReference<K>, V>> hashEntrySet = myMap.entrySet();
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Iterator<Map.Entry<K, V>> iterator() {
|
||||
public @NotNull Iterator<Map.Entry<K, V>> iterator() {
|
||||
return new Iterator<Map.Entry<K, V>>() {
|
||||
private final Iterator<Map.Entry<KeyReference<K>, V>> hashIterator = hashEntrySet.iterator();
|
||||
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;
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<Map.Entry<K, V>> entrySet() {
|
||||
public @NotNull Set<Map.Entry<K, V>> entrySet() {
|
||||
Set<Entry<K, V>> es = entrySet;
|
||||
if (es == null) entrySet = es = new EntrySet();
|
||||
return es;
|
||||
|
||||
@@ -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;
|
||||
|
||||
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 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;
|
||||
@NotNull private final ValueReference<K, V> myValueReference;
|
||||
private final @NotNull ValueReference<K, V> myValueReference;
|
||||
|
||||
SoftKey(@NotNull K k,
|
||||
@NotNull ValueReference<K, V> valueReference,
|
||||
@@ -52,16 +52,15 @@ final class ConcurrentSoftKeySoftValueHashMap<K, V> extends ConcurrentWeakKeySof
|
||||
return myHash;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ValueReference<K, V> getValueReference() {
|
||||
public @NotNull ValueReference<K, V> getValueReference() {
|
||||
return myValueReference;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@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);
|
||||
KeyReference<K,V> keyReference = new SoftKey<>(k, valueReference, myHashingStrategy, myKeyQueue);
|
||||
if (valueReference instanceof SoftValue) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -27,9 +27,8 @@ final class ConcurrentSoftValueHashMap<K,V> extends ConcurrentRefValueHashMap<K,
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public K getKey() {
|
||||
public @NotNull K getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
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 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,
|
||||
int hash,
|
||||
|
||||
@@ -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;
|
||||
|
||||
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;
|
||||
final ReferenceQueue<K> myKeyQueue = new ReferenceQueue<>();
|
||||
final ReferenceQueue<V> myValueQueue = new ReferenceQueue<>();
|
||||
@NotNull final HashingStrategy<? super K> myHashingStrategy;
|
||||
final @NotNull HashingStrategy<? super K> myHashingStrategy;
|
||||
|
||||
protected ConcurrentWeakKeySoftValueHashMap(int initialCapacity,
|
||||
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> {
|
||||
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;
|
||||
@NotNull private final ValueReference<K, V> myValueReference;
|
||||
private final @NotNull ValueReference<K, V> myValueReference;
|
||||
|
||||
WeakKey(@NotNull K k,
|
||||
@NotNull ValueReference<K, V> valueReference,
|
||||
@@ -95,15 +95,14 @@ public class ConcurrentWeakKeySoftValueHashMap<K, V> implements ConcurrentMap<K,
|
||||
return myHash;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ValueReference<K, V> getValueReference() {
|
||||
public @NotNull ValueReference<K, V> getValueReference() {
|
||||
return myValueReference;
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
super(value, queue);
|
||||
}
|
||||
@@ -121,15 +120,14 @@ public class ConcurrentWeakKeySoftValueHashMap<K, V> implements ConcurrentMap<K,
|
||||
return v != null && v.equals(thatV);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public KeyReference<K, V> getKeyReference() {
|
||||
public @NotNull KeyReference<K, V> getKeyReference() {
|
||||
return myKeyReference;
|
||||
}
|
||||
}
|
||||
|
||||
@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);
|
||||
KeyReference<K,V> keyReference = new WeakKey<>(k, valueReference, myHashingStrategy, myKeyQueue);
|
||||
if (valueReference instanceof SoftValue) {
|
||||
@@ -139,8 +137,7 @@ public class ConcurrentWeakKeySoftValueHashMap<K, V> implements ConcurrentMap<K,
|
||||
return keyReference;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected ValueReference<K, V> createValueReference(@NotNull V value, @NotNull ReferenceQueue<? super V> queue) {
|
||||
protected @NotNull ValueReference<K, V> createValueReference(@NotNull V value, @NotNull ReferenceQueue<? super V> queue) {
|
||||
return new SoftValue<>(value, queue);
|
||||
}
|
||||
|
||||
@@ -189,17 +186,15 @@ public class ConcurrentWeakKeySoftValueHashMap<K, V> implements ConcurrentMap<K,
|
||||
return myHash;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ValueReference<K, V> getValueReference() {
|
||||
public @NotNull ValueReference<K, V> getValueReference() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
private static final ThreadLocal<HardKey<?,?>> HARD_KEY = ThreadLocal.withInitial(() -> new HardKey<>());
|
||||
|
||||
@NotNull
|
||||
private HardKey<K,V> createHardKey(@NotNull Object o) {
|
||||
private @NotNull HardKey<K,V> createHardKey(@NotNull Object o) {
|
||||
//noinspection unchecked
|
||||
K key = (K)o;
|
||||
//noinspection unchecked
|
||||
@@ -280,15 +275,13 @@ public class ConcurrentWeakKeySoftValueHashMap<K, V> implements ConcurrentMap<K,
|
||||
return removed;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<K> keySet() {
|
||||
public @NotNull Set<K> keySet() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<V> values() {
|
||||
public @NotNull Collection<V> values() {
|
||||
List<V> values = new ArrayList<>();
|
||||
for (ValueReference<K, V> valueReference : myMap.values()) {
|
||||
V v = valueReference == null ? null : valueReference.get();
|
||||
@@ -299,9 +292,8 @@ public class ConcurrentWeakKeySoftValueHashMap<K, V> implements ConcurrentMap<K,
|
||||
return values;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<Entry<K, V>> entrySet() {
|
||||
public @NotNull Set<Entry<K, V>> entrySet() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
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> {
|
||||
@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) {
|
||||
super(value, queue);
|
||||
}
|
||||
@@ -40,16 +40,15 @@ final class ConcurrentWeakKeyWeakValueHashMap<K, V> extends ConcurrentWeakKeySof
|
||||
return v != null && v.equals(thatV);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public KeyReference<K, V> getKeyReference() {
|
||||
public @NotNull KeyReference<K, V> getKeyReference() {
|
||||
return myKeyReference;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@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);
|
||||
WeakKey<K, V> keyReference = new WeakKey<>(k, valueReference, myHashingStrategy, myKeyQueue);
|
||||
if (valueReference instanceof WeakValue) {
|
||||
@@ -60,8 +59,7 @@ final class ConcurrentWeakKeyWeakValueHashMap<K, V> extends ConcurrentWeakKeySof
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected ValueReference<K, V> createValueReference(@NotNull V value, @NotNull ReferenceQueue<? super V> queue) {
|
||||
protected @NotNull ValueReference<K, V> createValueReference(@NotNull V value, @NotNull ReferenceQueue<? super V> queue) {
|
||||
return new WeakValue<>(value, queue);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -28,9 +28,8 @@ final class ConcurrentWeakValueHashMap<K,V> extends ConcurrentRefValueHashMap<K,
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public K getKey() {
|
||||
public @NotNull K getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
@@ -65,9 +65,8 @@ public final class FList<E> extends AbstractList<E> {
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Iterator<E> iterator() {
|
||||
public @NotNull Iterator<E> iterator() {
|
||||
return new Iterator<E>() {
|
||||
|
||||
private FList<E> list = FList.this;
|
||||
|
||||
@@ -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;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -10,7 +10,7 @@ import java.util.NoSuchElementException;
|
||||
* Consider using {@link com.google.common.collect.Iterators#peekingIterator(Iterator)} instead.
|
||||
*/
|
||||
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 boolean myValidValue = false;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
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 ReferenceQueue<K> myReferenceQueue = new ReferenceQueue<>();
|
||||
private final HardKey myHardKeyInstance = new HardKey(); // "singleton"
|
||||
@NotNull
|
||||
private final HashingStrategy<? super K> myStrategy;
|
||||
private final @NotNull HashingStrategy<? super K> myStrategy;
|
||||
private Set<Entry<K, V>> entrySet;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected abstract <T> Key<T> createKey(@NotNull T k, @NotNull HashingStrategy<? super T> strategy, @NotNull ReferenceQueue<? super T> q);
|
||||
protected abstract @NotNull <T> Key<T> createKey(@NotNull T k, @NotNull HashingStrategy<? super T> strategy, @NotNull ReferenceQueue<? super T> q);
|
||||
|
||||
private class HardKey implements Key<K> {
|
||||
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 K key; // Strong reference to key, so that the GC will leave it alone as long as this Entry exists
|
||||
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) {
|
||||
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 final Set<Entry<Key<K>, V>> hashEntrySet = myMap.entrySet();
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Iterator<Entry<K, V>> iterator() {
|
||||
public @NotNull Iterator<Entry<K, V>> iterator() {
|
||||
return new Iterator<Entry<K, V>>() {
|
||||
private final Iterator<Entry<Key<K>, V>> hashIterator = hashEntrySet.iterator();
|
||||
private MyEntry<K, V> next;
|
||||
@@ -366,9 +363,8 @@ abstract class RefHashMap<K, V> extends AbstractMap<K, V> implements Map<K, V> {
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<Entry<K, V>> entrySet() {
|
||||
public @NotNull Set<Entry<K, V>> entrySet() {
|
||||
Set<Entry<K, V>> es = entrySet;
|
||||
if (es == null) {
|
||||
entrySet = es = new EntrySet();
|
||||
|
||||
@@ -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;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -24,8 +24,7 @@ abstract class RefKeyRefValueHashMap<K,V> implements Map<K,V>{
|
||||
return reference == null ? null : reference.get();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected abstract ValueReference<K,V> createValueReference(@NotNull RefHashMap.Key<K> key, V referent, ReferenceQueue<? super V> q);
|
||||
protected abstract @NotNull ValueReference<K,V> createValueReference(@NotNull RefHashMap.Key<K> key, V referent, ReferenceQueue<? super V> q);
|
||||
|
||||
// returns true if some refs were tossed
|
||||
boolean processQueue() {
|
||||
@@ -94,15 +93,13 @@ abstract class RefKeyRefValueHashMap<K,V> implements Map<K,V>{
|
||||
throw RefValueHashMapUtil.pointlessContainsValue();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<K> keySet() {
|
||||
public @NotNull Set<K> keySet() {
|
||||
return myMap.keySet();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<V> values() {
|
||||
public @NotNull Collection<V> values() {
|
||||
List<V> result = new ArrayList<>();
|
||||
final Collection<ValueReference<K, V>> refs = myMap.values();
|
||||
for (ValueReference<K, V> ref : refs) {
|
||||
@@ -114,9 +111,8 @@ abstract class RefKeyRefValueHashMap<K,V> implements Map<K,V>{
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<Entry<K, V>> entrySet() {
|
||||
public @NotNull Set<Entry<K, V>> entrySet() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public final class RefValueHashMapUtil {
|
||||
@NotNull
|
||||
public static IncorrectOperationException pointlessContainsKey() {
|
||||
public static @NotNull IncorrectOperationException pointlessContainsKey() {
|
||||
return new IncorrectOperationException("containsKey() makes no sense for weak/soft map because GC can clear the value any moment now");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static IncorrectOperationException pointlessContainsValue() {
|
||||
public static @NotNull IncorrectOperationException pointlessContainsValue() {
|
||||
return new IncorrectOperationException("containsValue() makes no sense for weak/soft map because GC can clear the key any moment now");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
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 final int myHash; /* Hash code of key, stored here since the key may be tossed by the GC */
|
||||
@NotNull
|
||||
private final HashingStrategy<? super T> myStrategy;
|
||||
private final @NotNull HashingStrategy<? super T> myStrategy;
|
||||
|
||||
private SoftKey(@NotNull T k, @NotNull HashingStrategy<? super T> strategy, @NotNull ReferenceQueue<? super T> q) {
|
||||
super(k, q);
|
||||
|
||||
@@ -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;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -90,15 +90,13 @@ final class SoftKeySoftValueHashMap<K,V> implements Map<K,V>{
|
||||
throw RefValueHashMapUtil.pointlessContainsValue();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<K> keySet() {
|
||||
public @NotNull Set<K> keySet() {
|
||||
return mySoftKeyMap.keySet();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<V> values() {
|
||||
public @NotNull Collection<V> values() {
|
||||
List<V> result = new ArrayList<>();
|
||||
Collection<ValueReference<K, V>> refs = mySoftKeyMap.values();
|
||||
for (ValueReference<K, V> ref : refs) {
|
||||
@@ -110,9 +108,8 @@ final class SoftKeySoftValueHashMap<K,V> implements Map<K,V>{
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<Entry<K, V>> entrySet() {
|
||||
public @NotNull Set<Entry<K, V>> entrySet() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
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> {
|
||||
@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) {
|
||||
super(referent, q);
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public RefHashMap.Key<K> getKey() {
|
||||
public @NotNull RefHashMap.Key<K> getKey() {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected ValueReference<K, V> createValueReference(@NotNull RefHashMap.Key<K> key,
|
||||
V referent,
|
||||
ReferenceQueue<? super V> q) {
|
||||
protected @NotNull ValueReference<K, V> createValueReference(@NotNull RefHashMap.Key<K> key,
|
||||
V referent,
|
||||
ReferenceQueue<? super V> q) {
|
||||
return new SoftValueReference<>(key, referent, q);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
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> {
|
||||
@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) {
|
||||
super(referent, q);
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public RefHashMap.Key<K> getKey() {
|
||||
public @NotNull RefHashMap.Key<K> getKey() {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected ValueReference<K, V> createValueReference(@NotNull RefHashMap.Key<K> key,
|
||||
V referent,
|
||||
ReferenceQueue<? super V> q) {
|
||||
protected @NotNull ValueReference<K, V> createValueReference(@NotNull RefHashMap.Key<K> key,
|
||||
V referent,
|
||||
ReferenceQueue<? super V> q) {
|
||||
return new WeakValueReference<>(key, referent, q);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
import com.intellij.ReviseWhenPortedToJDK;
|
||||
@@ -46,15 +46,13 @@ public final class ByteArrayCharSequence implements CharSequenceWithStringHash {
|
||||
return (char)(myChars[index + myStart] & 0xff);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@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);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String toString() {
|
||||
public @NotNull String toString() {
|
||||
return new String(myChars, myStart, length(), StandardCharsets.ISO_8859_1);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
import com.intellij.openapi.util.text.CharSequenceWithStringHash;
|
||||
@@ -33,15 +33,13 @@ public class CharArrayCharSequence implements CharSequenceBackedByArray, CharSeq
|
||||
return myChars[index + myStart];
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@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);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String toString() {
|
||||
public @NotNull String toString() {
|
||||
return new String(myChars, myStart, myEnd - myStart); //TODO StringFactory
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
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 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) {
|
||||
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 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 start start offset within the given text to check (inclusive)
|
||||
* @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) {
|
||||
for (int i = start; i < end; i++) {
|
||||
@@ -518,15 +518,13 @@ public final class CharArrayUtil {
|
||||
return true;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Reader readerFromCharSequence(@NotNull CharSequence text) {
|
||||
public static @NotNull Reader readerFromCharSequence(@NotNull CharSequence text) {
|
||||
char[] chars = fromSequenceWithoutCopying(text);
|
||||
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
|
||||
public static ImmutableCharSequence createImmutableCharSequence(@NotNull CharSequence sequence) {
|
||||
public static @NotNull ImmutableCharSequence createImmutableCharSequence(@NotNull CharSequence sequence) {
|
||||
return ImmutableText.valueOf(sequence);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -49,16 +49,14 @@ public class CharSequenceSubSequence implements CharSequence, CharArrayExternali
|
||||
return myChars.charAt(index + myStart);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public CharSequence subSequence(int start, int end) {
|
||||
public @NotNull CharSequence subSequence(int start, int end) {
|
||||
if (start == myStart && end == myEnd) return this;
|
||||
return new CharSequenceSubSequence(myChars, myStart + start, myStart + end);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String toString() {
|
||||
public @NotNull String toString() {
|
||||
if (myChars instanceof String) return ((String)myChars).substring(myStart, myEnd);
|
||||
return new String(CharArrayUtil.fromSequence(myChars, myStart, myEnd));
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
import org.jetbrains.annotations.Contract;
|
||||
@@ -7,38 +7,32 @@ import org.jetbrains.annotations.NotNull;
|
||||
public abstract class ImmutableCharSequence implements CharSequence {
|
||||
|
||||
@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();
|
||||
}
|
||||
|
||||
private static boolean isImmutable(@NotNull final CharSequence cs) {
|
||||
private static boolean isImmutable(final @NotNull CharSequence cs) {
|
||||
return cs instanceof ImmutableCharSequence ||
|
||||
cs instanceof CharSequenceSubSequence && isImmutable(((CharSequenceSubSequence)cs).getBaseSequence());
|
||||
}
|
||||
|
||||
@Contract(pure = true)
|
||||
@NotNull
|
||||
public abstract ImmutableCharSequence concat(@NotNull CharSequence sequence);
|
||||
public abstract @NotNull ImmutableCharSequence concat(@NotNull CharSequence sequence);
|
||||
|
||||
@Contract(pure = true)
|
||||
@NotNull
|
||||
public abstract ImmutableCharSequence insert(int index, @NotNull CharSequence seq);
|
||||
public abstract @NotNull ImmutableCharSequence insert(int index, @NotNull CharSequence seq);
|
||||
|
||||
@Contract(pure = true)
|
||||
@NotNull
|
||||
public abstract ImmutableCharSequence delete(int start, int end);
|
||||
public abstract @NotNull ImmutableCharSequence delete(int start, int end);
|
||||
|
||||
@Contract(pure = true)
|
||||
@NotNull
|
||||
public abstract ImmutableCharSequence subtext(int start, int end);
|
||||
public abstract @NotNull ImmutableCharSequence subtext(int start, int end);
|
||||
|
||||
@Contract(pure = true)
|
||||
@NotNull
|
||||
public ImmutableCharSequence replace(int start, int end, @NotNull CharSequence seq) {
|
||||
public @NotNull ImmutableCharSequence replace(int start, int end, @NotNull CharSequence seq) {
|
||||
return delete(start, end).insert(start, seq);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public abstract String toString();
|
||||
public abstract @NotNull String toString();
|
||||
}
|
||||
|
||||
@@ -65,8 +65,7 @@ final class ImmutableText extends ImmutableCharSequence implements CharArrayExte
|
||||
|
||||
// visible for tests
|
||||
// Here (String | CompositeNode | ByteArrayCharSequence) is stored
|
||||
@NotNull
|
||||
final CharSequence myNode;
|
||||
final @NotNull CharSequence myNode;
|
||||
|
||||
private ImmutableText(@NotNull CharSequence node) {
|
||||
myNode = node;
|
||||
@@ -78,15 +77,13 @@ final class ImmutableText extends ImmutableCharSequence implements CharArrayExte
|
||||
* @param obj the object to represent as text.
|
||||
* @return the textual representation of the specified object.
|
||||
*/
|
||||
@NotNull
|
||||
static ImmutableText valueOf(@NotNull Object obj) {
|
||||
static @NotNull ImmutableText valueOf(@NotNull Object obj) {
|
||||
if (obj instanceof ImmutableText) return (ImmutableText)obj;
|
||||
if (obj instanceof CharSequence) return valueOf((CharSequence)obj);
|
||||
return valueOf(String.valueOf(obj));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static ImmutableText valueOf(@NotNull CharSequence str) {
|
||||
private static @NotNull ImmutableText valueOf(@NotNull CharSequence str) {
|
||||
if (str instanceof ByteArrayCharSequence) {
|
||||
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
|
||||
*/
|
||||
@NotNull
|
||||
private CharSequence ensureChunked() {
|
||||
private @NotNull CharSequence ensureChunked() {
|
||||
if (length() > BLOCK_SIZE && !(myNode instanceof CompositeNode)) {
|
||||
return nodeOf(myNode, 0, length());
|
||||
}
|
||||
return myNode;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static CharSequence nodeOf(@NotNull CharSequence node, int offset, int length) {
|
||||
private static @NotNull CharSequence nodeOf(@NotNull CharSequence node, int offset, int length) {
|
||||
if (length <= BLOCK_SIZE) {
|
||||
// Use toString to avoid referencing the original byte[] array in case if node is ByteArrayCharSequence
|
||||
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.
|
||||
* @return {@code this + that}
|
||||
*/
|
||||
@NotNull
|
||||
private ImmutableText concat(@NotNull ImmutableText that) {
|
||||
private @NotNull ImmutableText concat(@NotNull ImmutableText that) {
|
||||
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
|
||||
@NotNull
|
||||
public CharSequence subSequence(final int start, final int end) {
|
||||
public @NotNull CharSequence subSequence(final int start, final int end) {
|
||||
if (start == 0 && end == length()) return this;
|
||||
return new CharSequenceSubSequence(this, start, end);
|
||||
}
|
||||
@@ -242,8 +235,7 @@ final class ImmutableText extends ImmutableCharSequence implements CharArrayExte
|
||||
}
|
||||
private InnerLeaf myLastLeaf;
|
||||
|
||||
@NotNull
|
||||
private InnerLeaf findLeaf(int index) {
|
||||
private @NotNull InnerLeaf findLeaf(int index) {
|
||||
if (index < 0) throw outOfRange(index);
|
||||
|
||||
CharSequence node = myNode;
|
||||
@@ -347,13 +339,11 @@ final class ImmutableText extends ImmutableCharSequence implements CharArrayExte
|
||||
* @return the {@code java.lang.String} for this text.
|
||||
*/
|
||||
@Override
|
||||
@NotNull
|
||||
public String toString() {
|
||||
public @NotNull String toString() {
|
||||
return myNode.toString();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static CharSequence concatNodes(@NotNull CharSequence node1, @NotNull CharSequence node2) {
|
||||
private static @NotNull CharSequence concatNodes(@NotNull CharSequence node1, @NotNull CharSequence node2) {
|
||||
// All Text instances are maintained balanced:
|
||||
// (head < tail * 2) & (tail < head * 2)
|
||||
final int length = node1.length() + node2.length();
|
||||
@@ -464,8 +454,7 @@ final class ImmutableText extends ImmutableCharSequence implements CharArrayExte
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public CharSequence subSequence(int start, int end) {
|
||||
public @NotNull CharSequence subSequence(int start, int end) {
|
||||
int cesure = head.length();
|
||||
if (end <= cesure) {
|
||||
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));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toString() {
|
||||
public @NotNull String toString() {
|
||||
int len = length();
|
||||
char[] data = new char[len];
|
||||
getChars(0, len, data, 0);
|
||||
|
||||
@@ -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;
|
||||
|
||||
import com.intellij.openapi.util.NlsSafe;
|
||||
@@ -18,8 +18,7 @@ public final class SemVer implements Comparable<SemVer> {
|
||||
private final int myMajor;
|
||||
private final int myMinor;
|
||||
private final int myPatch;
|
||||
@Nullable
|
||||
private final String myPreRelease;
|
||||
private final @Nullable String myPreRelease;
|
||||
|
||||
public SemVer(@NotNull String rawVersion, int major, int minor, int patch) {
|
||||
this(rawVersion, major, minor, patch, null);
|
||||
@@ -170,8 +169,7 @@ public final class SemVer implements Comparable<SemVer> {
|
||||
return diff;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static SemVer parseFromText(@Nullable String text) {
|
||||
public static @Nullable SemVer parseFromText(@Nullable String text) {
|
||||
if (text != null) {
|
||||
int majorEndIdx = text.indexOf('.');
|
||||
if (majorEndIdx >= 0) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
import com.intellij.openapi.util.text.Strings;
|
||||
@@ -58,8 +58,7 @@ public final class StringSearcher {
|
||||
Character.isJavaIdentifierPart(pattern.charAt(pattern.length() - 1));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getPattern(){
|
||||
public @NotNull String getPattern(){
|
||||
return myPattern;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user