From 81a5bdf1b009cbd30a6c384bafb57de6d578cfb7 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Mon, 19 Feb 2024 12:22:40 +0100 Subject: [PATCH] cleanup - sort modifiers GitOrigin-RevId: dc2cc5e5cc2d1f474d6d26808a8862448bd8b742 --- .../com/intellij/diagnostic/ThreadDumper.java | 14 +++---- .../com/intellij/openapi/util/TextRange.java | 38 +++++++------------ .../openapi/util/text/LineTokenizer.java | 8 ++-- .../openapi/util/text/Pluralizer.java | 9 ++--- .../com/intellij/reference/SoftReference.java | 8 ++-- .../base/src/com/intellij/util/SmartList.java | 8 ++-- .../util/containers/ConcurrentRefHashMap.java | 14 +++---- .../ConcurrentSoftKeySoftValueHashMap.java | 9 ++--- .../ConcurrentSoftValueHashMap.java | 5 +-- .../containers/ConcurrentWeakHashMap.java | 4 +- .../ConcurrentWeakKeySoftValueHashMap.java | 34 +++++++---------- .../ConcurrentWeakKeyWeakValueHashMap.java | 12 +++--- .../ConcurrentWeakValueHashMap.java | 5 +-- .../com/intellij/util/containers/FList.java | 5 +-- .../containers/PeekableIteratorWrapper.java | 4 +- .../intellij/util/containers/RefHashMap.java | 16 +++----- .../containers/RefKeyRefValueHashMap.java | 14 +++---- .../util/containers/RefValueHashMapUtil.java | 8 ++-- .../intellij/util/containers/SoftHashMap.java | 5 +-- .../containers/SoftKeySoftValueHashMap.java | 11 ++---- .../containers/WeakKeySoftValueHashMap.java | 14 +++---- .../containers/WeakKeyWeakValueHashMap.java | 14 +++---- .../util/text/ByteArrayCharSequence.java | 8 ++-- .../util/text/CharArrayCharSequence.java | 8 ++-- .../com/intellij/util/text/CharArrayUtil.java | 18 ++++----- .../util/text/CharSequenceSubSequence.java | 8 ++-- .../util/text/ImmutableCharSequence.java | 24 +++++------- .../com/intellij/util/text/ImmutableText.java | 36 ++++++------------ .../src/com/intellij/util/text/SemVer.java | 8 ++-- .../intellij/util/text/StringSearcher.java | 5 +-- 30 files changed, 142 insertions(+), 232 deletions(-) diff --git a/platform/util/base/src/com/intellij/diagnostic/ThreadDumper.java b/platform/util/base/src/com/intellij/diagnostic/ThreadDumper.java index b5a2c9e21d5b..a0e1cb6da63c 100644 --- a/platform/util/base/src/com/intellij/diagnostic/ThreadDumper.java +++ b/platform/util/base/src/com/intellij/diagnostic/ThreadDumper.java @@ -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 threadDump = Arrays.asList(fullThreadDump.split("\n")); diff --git a/platform/util/base/src/com/intellij/openapi/util/TextRange.java b/platform/util/base/src/com/intellij/openapi/util/TextRange.java index d28769a02d7f..214cd94ef58b 100644 --- a/platform/util/base/src/com/intellij/openapi/util/TextRange.java +++ b/platform/util/base/src/com/intellij/openapi/util/TextRange.java @@ -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()); } diff --git a/platform/util/base/src/com/intellij/openapi/util/text/LineTokenizer.java b/platform/util/base/src/com/intellij/openapi/util/text/LineTokenizer.java index 504c6f46924f..a269bbd36724 100644 --- a/platform/util/base/src/com/intellij/openapi/util/text/LineTokenizer.java +++ b/platform/util/base/src/com/intellij/openapi/util/text/LineTokenizer.java @@ -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 tokenizeIntoList(CharSequence chars, final boolean includeSeparators) { + public static @NotNull List tokenizeIntoList(CharSequence chars, final boolean includeSeparators) { return tokenizeIntoList(chars, includeSeparators, true); } - @NotNull - public static List tokenizeIntoList(CharSequence chars, final boolean includeSeparators, final boolean skipLastEmptyLine) { + public static @NotNull List tokenizeIntoList(CharSequence chars, final boolean includeSeparators, final boolean skipLastEmptyLine) { if (chars == null || chars.length() == 0){ return Collections.emptyList(); } diff --git a/platform/util/base/src/com/intellij/openapi/util/text/Pluralizer.java b/platform/util/base/src/com/intellij/openapi/util/text/Pluralizer.java index 5056f1d28d2d..7fc223980bbc 100644 --- a/platform/util/base/src/com/intellij/openapi/util/text/Pluralizer.java +++ b/platform/util/base/src/com/intellij/openapi/util/text/Pluralizer.java @@ -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)); } diff --git a/platform/util/base/src/com/intellij/reference/SoftReference.java b/platform/util/base/src/com/intellij/reference/SoftReference.java index a90d43842ea1..602d1d38f806 100644 --- a/platform/util/base/src/com/intellij/reference/SoftReference.java +++ b/platform/util/base/src/com/intellij/reference/SoftReference.java @@ -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 extends java.lang.ref.SoftReference implements // return myReferent; //} - @Nullable - public static T dereference(@Nullable Reference ref) { + public static @Nullable T dereference(@Nullable Reference ref) { return ref == null ? null : ref.get(); } - @Nullable - public static T deref(@Nullable Supplier ref) { + public static @Nullable T deref(@Nullable Supplier ref) { return ref == null ? null : ref.get(); } } diff --git a/platform/util/base/src/com/intellij/util/SmartList.java b/platform/util/base/src/com/intellij/util/SmartList.java index c3492fb141a9..6b23d8c74b20 100644 --- a/platform/util/base/src/com/intellij/util/SmartList.java +++ b/platform/util/base/src/com/intellij/util/SmartList.java @@ -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 extends AbstractList 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 extends AbstractList implements RandomAccess { return oldValue; } - @NotNull @Override - public Iterator iterator() { + public @NotNull Iterator iterator() { return mySize == 0 ? Collections.emptyIterator() : super.iterator(); } diff --git a/platform/util/base/src/com/intellij/util/containers/ConcurrentRefHashMap.java b/platform/util/base/src/com/intellij/util/containers/ConcurrentRefHashMap.java index f824a6e85cf2..7213ccdff7e7 100644 --- a/platform/util/base/src/com/intellij/util/containers/ConcurrentRefHashMap.java +++ b/platform/util/base/src/com/intellij/util/containers/ConcurrentRefHashMap.java @@ -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 extends AbstractMap implements C abstract @NotNull KeyReference createKeyReference(@NotNull K key, @NotNull HashingStrategy hashingStrategy); - @NotNull - private KeyReference createKeyReference(@NotNull K key) { + private @NotNull KeyReference createKeyReference(@NotNull K key) { return createKeyReference(key, myHashingStrategy); } @@ -151,8 +150,7 @@ abstract class ConcurrentRefHashMap extends AbstractMap implements C } private static final ThreadLocal> HARD_KEY = ThreadLocal.withInitial(() -> new HardKey<>()); - @NotNull - private HardKey createHardKey(@NotNull Object o) { + private @NotNull HardKey createHardKey(@NotNull Object o) { //noinspection unchecked K key = (K)o; //noinspection unchecked @@ -244,9 +242,8 @@ abstract class ConcurrentRefHashMap extends AbstractMap implements C private final class EntrySet extends AbstractSet> { private final Set, V>> hashEntrySet = myMap.entrySet(); - @NotNull @Override - public Iterator> iterator() { + public @NotNull Iterator> iterator() { return new Iterator>() { private final Iterator, V>> hashIterator = hashEntrySet.iterator(); private RefEntry next; @@ -343,9 +340,8 @@ abstract class ConcurrentRefHashMap extends AbstractMap implements C private Set> entrySet; - @NotNull @Override - public Set> entrySet() { + public @NotNull Set> entrySet() { Set> es = entrySet; if (es == null) entrySet = es = new EntrySet(); return es; diff --git a/platform/util/base/src/com/intellij/util/containers/ConcurrentSoftKeySoftValueHashMap.java b/platform/util/base/src/com/intellij/util/containers/ConcurrentSoftKeySoftValueHashMap.java index ff018f9d752d..710314efc29f 100644 --- a/platform/util/base/src/com/intellij/util/containers/ConcurrentSoftKeySoftValueHashMap.java +++ b/platform/util/base/src/com/intellij/util/containers/ConcurrentSoftKeySoftValueHashMap.java @@ -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 extends ConcurrentWeakKeySof private static class SoftKey extends SoftReference implements KeyReference { private final int myHash; // Hash code of the key, stored here since the key may be tossed by the GC private final HashingStrategy myStrategy; - @NotNull private final ValueReference myValueReference; + private final @NotNull ValueReference myValueReference; SoftKey(@NotNull K k, @NotNull ValueReference valueReference, @@ -52,16 +52,15 @@ final class ConcurrentSoftKeySoftValueHashMap extends ConcurrentWeakKeySof return myHash; } - @NotNull @Override - public ValueReference getValueReference() { + public @NotNull ValueReference getValueReference() { return myValueReference; } } @Override @NotNull - KeyReference createKeyReference(@NotNull K k, @NotNull final V v) { + KeyReference createKeyReference(@NotNull K k, final @NotNull V v) { final ValueReference valueReference = createValueReference(v, myValueQueue); KeyReference keyReference = new SoftKey<>(k, valueReference, myHashingStrategy, myKeyQueue); if (valueReference instanceof SoftValue) { diff --git a/platform/util/base/src/com/intellij/util/containers/ConcurrentSoftValueHashMap.java b/platform/util/base/src/com/intellij/util/containers/ConcurrentSoftValueHashMap.java index f85386ff1ff7..042d936f47ab 100644 --- a/platform/util/base/src/com/intellij/util/containers/ConcurrentSoftValueHashMap.java +++ b/platform/util/base/src/com/intellij/util/containers/ConcurrentSoftValueHashMap.java @@ -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 extends ConcurrentRefValueHashMap extends ConcurrentRefHashMap { private static final class WeakKey extends WeakReference implements KeyReference { private final int myHash; /* Hashcode of key, stored here since the key may be tossed by the GC */ - @NotNull private final HashingStrategy myStrategy; + private final @NotNull HashingStrategy myStrategy; private WeakKey(@NotNull K k, int hash, diff --git a/platform/util/base/src/com/intellij/util/containers/ConcurrentWeakKeySoftValueHashMap.java b/platform/util/base/src/com/intellij/util/containers/ConcurrentWeakKeySoftValueHashMap.java index 63ad2b0d328f..789901a5bcd8 100644 --- a/platform/util/base/src/com/intellij/util/containers/ConcurrentWeakKeySoftValueHashMap.java +++ b/platform/util/base/src/com/intellij/util/containers/ConcurrentWeakKeySoftValueHashMap.java @@ -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 implements ConcurrentMap, ValueReference> myMap; final ReferenceQueue myKeyQueue = new ReferenceQueue<>(); final ReferenceQueue myValueQueue = new ReferenceQueue<>(); - @NotNull final HashingStrategy myHashingStrategy; + final @NotNull HashingStrategy myHashingStrategy; protected ConcurrentWeakKeySoftValueHashMap(int initialCapacity, float loadFactor, @@ -67,7 +67,7 @@ public class ConcurrentWeakKeySoftValueHashMap implements ConcurrentMap extends WeakReference implements KeyReference { private final int myHash; // Hash code of the key, stored here since the key may be tossed by the GC private final HashingStrategy myStrategy; - @NotNull private final ValueReference myValueReference; + private final @NotNull ValueReference myValueReference; WeakKey(@NotNull K k, @NotNull ValueReference valueReference, @@ -95,15 +95,14 @@ public class ConcurrentWeakKeySoftValueHashMap implements ConcurrentMap getValueReference() { + public @NotNull ValueReference getValueReference() { return myValueReference; } } static final class SoftValue extends SoftReference implements ValueReference { - @NotNull volatile KeyReference myKeyReference; // can't make it final because of circular dependency of KeyReference to ValueReference + volatile @NotNull KeyReference myKeyReference; // can't make it final because of circular dependency of KeyReference to ValueReference private SoftValue(@NotNull V value, @NotNull ReferenceQueue queue) { super(value, queue); } @@ -121,15 +120,14 @@ public class ConcurrentWeakKeySoftValueHashMap implements ConcurrentMap getKeyReference() { + public @NotNull KeyReference getKeyReference() { return myKeyReference; } } @NotNull - KeyReference createKeyReference(@NotNull K k, @NotNull final V v) { + KeyReference createKeyReference(@NotNull K k, final @NotNull V v) { final ValueReference valueReference = createValueReference(v, myValueQueue); KeyReference keyReference = new WeakKey<>(k, valueReference, myHashingStrategy, myKeyQueue); if (valueReference instanceof SoftValue) { @@ -139,8 +137,7 @@ public class ConcurrentWeakKeySoftValueHashMap implements ConcurrentMap createValueReference(@NotNull V value, @NotNull ReferenceQueue queue) { + protected @NotNull ValueReference createValueReference(@NotNull V value, @NotNull ReferenceQueue queue) { return new SoftValue<>(value, queue); } @@ -189,17 +186,15 @@ public class ConcurrentWeakKeySoftValueHashMap implements ConcurrentMap getValueReference() { + public @NotNull ValueReference getValueReference() { throw new UnsupportedOperationException(); } } private static final ThreadLocal> HARD_KEY = ThreadLocal.withInitial(() -> new HardKey<>()); - @NotNull - private HardKey createHardKey(@NotNull Object o) { + private @NotNull HardKey createHardKey(@NotNull Object o) { //noinspection unchecked K key = (K)o; //noinspection unchecked @@ -280,15 +275,13 @@ public class ConcurrentWeakKeySoftValueHashMap implements ConcurrentMap keySet() { + public @NotNull Set keySet() { throw new UnsupportedOperationException(); } - @NotNull @Override - public Collection values() { + public @NotNull Collection values() { List values = new ArrayList<>(); for (ValueReference valueReference : myMap.values()) { V v = valueReference == null ? null : valueReference.get(); @@ -299,9 +292,8 @@ public class ConcurrentWeakKeySoftValueHashMap implements ConcurrentMap> entrySet() { + public @NotNull Set> entrySet() { throw new UnsupportedOperationException(); } diff --git a/platform/util/base/src/com/intellij/util/containers/ConcurrentWeakKeyWeakValueHashMap.java b/platform/util/base/src/com/intellij/util/containers/ConcurrentWeakKeyWeakValueHashMap.java index 593981d4dbff..d5a9d68592b2 100644 --- a/platform/util/base/src/com/intellij/util/containers/ConcurrentWeakKeyWeakValueHashMap.java +++ b/platform/util/base/src/com/intellij/util/containers/ConcurrentWeakKeyWeakValueHashMap.java @@ -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 extends ConcurrentWeakKeySof } private static final class WeakValue extends WeakReference implements ValueReference { - @NotNull private volatile KeyReference myKeyReference; // can't make it final because of circular dependency of KeyReference to ValueReference + private volatile @NotNull KeyReference myKeyReference; // can't make it final because of circular dependency of KeyReference to ValueReference private WeakValue(@NotNull V value, @NotNull ReferenceQueue queue) { super(value, queue); } @@ -40,16 +40,15 @@ final class ConcurrentWeakKeyWeakValueHashMap extends ConcurrentWeakKeySof return v != null && v.equals(thatV); } - @NotNull @Override - public KeyReference getKeyReference() { + public @NotNull KeyReference getKeyReference() { return myKeyReference; } } @Override @NotNull - KeyReference createKeyReference(@NotNull K k, @NotNull final V v) { + KeyReference createKeyReference(@NotNull K k, final @NotNull V v) { ValueReference valueReference = createValueReference(v, myValueQueue); WeakKey keyReference = new WeakKey<>(k, valueReference, myHashingStrategy, myKeyQueue); if (valueReference instanceof WeakValue) { @@ -60,8 +59,7 @@ final class ConcurrentWeakKeyWeakValueHashMap extends ConcurrentWeakKeySof } @Override - @NotNull - protected ValueReference createValueReference(@NotNull V value, @NotNull ReferenceQueue queue) { + protected @NotNull ValueReference createValueReference(@NotNull V value, @NotNull ReferenceQueue queue) { return new WeakValue<>(value, queue); } } diff --git a/platform/util/base/src/com/intellij/util/containers/ConcurrentWeakValueHashMap.java b/platform/util/base/src/com/intellij/util/containers/ConcurrentWeakValueHashMap.java index e9a068f963b0..82198fde5ec6 100644 --- a/platform/util/base/src/com/intellij/util/containers/ConcurrentWeakValueHashMap.java +++ b/platform/util/base/src/com/intellij/util/containers/ConcurrentWeakValueHashMap.java @@ -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 extends ConcurrentRefValueHashMap extends AbstractList { return this; } - @NotNull @Override - public Iterator iterator() { + public @NotNull Iterator iterator() { return new Iterator() { private FList list = FList.this; diff --git a/platform/util/base/src/com/intellij/util/containers/PeekableIteratorWrapper.java b/platform/util/base/src/com/intellij/util/containers/PeekableIteratorWrapper.java index 77b64186ba6c..187fd2561124 100644 --- a/platform/util/base/src/com/intellij/util/containers/PeekableIteratorWrapper.java +++ b/platform/util/base/src/com/intellij/util/containers/PeekableIteratorWrapper.java @@ -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 implements PeekableIterator { - @NotNull private final Iterator myIterator; + private final @NotNull Iterator myIterator; private T myValue = null; private boolean myValidValue = false; diff --git a/platform/util/base/src/com/intellij/util/containers/RefHashMap.java b/platform/util/base/src/com/intellij/util/containers/RefHashMap.java index 87174a9a677b..35937c0e8a87 100644 --- a/platform/util/base/src/com/intellij/util/containers/RefHashMap.java +++ b/platform/util/base/src/com/intellij/util/containers/RefHashMap.java @@ -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 extends AbstractMap implements Map { private final MyMap myMap; private final ReferenceQueue myReferenceQueue = new ReferenceQueue<>(); private final HardKey myHardKeyInstance = new HardKey(); // "singleton" - @NotNull - private final HashingStrategy myStrategy; + private final @NotNull HashingStrategy myStrategy; private Set> entrySet; RefHashMap(int initialCapacity, float loadFactor, @NotNull HashingStrategy strategy) { @@ -98,8 +97,7 @@ abstract class RefHashMap extends AbstractMap implements Map { boolean equals(Object o); } - @NotNull - protected abstract Key createKey(@NotNull T k, @NotNull HashingStrategy strategy, @NotNull ReferenceQueue q); + protected abstract @NotNull Key createKey(@NotNull T k, @NotNull HashingStrategy strategy, @NotNull ReferenceQueue q); private class HardKey implements Key { private K myObject; @@ -232,7 +230,7 @@ abstract class RefHashMap extends AbstractMap implements Map { private final Entry 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 myStrategy; + private final @NotNull HashingStrategy myStrategy; private MyEntry(@NotNull Entry ent, @NotNull K key, int keyHashCode, @NotNull HashingStrategy strategy) { this.ent = ent; @@ -275,9 +273,8 @@ abstract class RefHashMap extends AbstractMap implements Map { private class EntrySet extends AbstractSet> { private final Set, V>> hashEntrySet = myMap.entrySet(); - @NotNull @Override - public Iterator> iterator() { + public @NotNull Iterator> iterator() { return new Iterator>() { private final Iterator, V>> hashIterator = hashEntrySet.iterator(); private MyEntry next; @@ -366,9 +363,8 @@ abstract class RefHashMap extends AbstractMap implements Map { } } - @NotNull @Override - public Set> entrySet() { + public @NotNull Set> entrySet() { Set> es = entrySet; if (es == null) { entrySet = es = new EntrySet(); diff --git a/platform/util/base/src/com/intellij/util/containers/RefKeyRefValueHashMap.java b/platform/util/base/src/com/intellij/util/containers/RefKeyRefValueHashMap.java index 3daa3b4d685e..b1734f37d2bd 100644 --- a/platform/util/base/src/com/intellij/util/containers/RefKeyRefValueHashMap.java +++ b/platform/util/base/src/com/intellij/util/containers/RefKeyRefValueHashMap.java @@ -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 implements Map{ return reference == null ? null : reference.get(); } - @NotNull - protected abstract ValueReference createValueReference(@NotNull RefHashMap.Key key, V referent, ReferenceQueue q); + protected abstract @NotNull ValueReference createValueReference(@NotNull RefHashMap.Key key, V referent, ReferenceQueue q); // returns true if some refs were tossed boolean processQueue() { @@ -94,15 +93,13 @@ abstract class RefKeyRefValueHashMap implements Map{ throw RefValueHashMapUtil.pointlessContainsValue(); } - @NotNull @Override - public Set keySet() { + public @NotNull Set keySet() { return myMap.keySet(); } - @NotNull @Override - public Collection values() { + public @NotNull Collection values() { List result = new ArrayList<>(); final Collection> refs = myMap.values(); for (ValueReference ref : refs) { @@ -114,9 +111,8 @@ abstract class RefKeyRefValueHashMap implements Map{ return result; } - @NotNull @Override - public Set> entrySet() { + public @NotNull Set> entrySet() { throw new UnsupportedOperationException(); } } diff --git a/platform/util/base/src/com/intellij/util/containers/RefValueHashMapUtil.java b/platform/util/base/src/com/intellij/util/containers/RefValueHashMapUtil.java index d828328a5ff5..2ee046cd8ee6 100644 --- a/platform/util/base/src/com/intellij/util/containers/RefValueHashMapUtil.java +++ b/platform/util/base/src/com/intellij/util/containers/RefValueHashMapUtil.java @@ -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"); } } diff --git a/platform/util/base/src/com/intellij/util/containers/SoftHashMap.java b/platform/util/base/src/com/intellij/util/containers/SoftHashMap.java index 195648f61ffc..73ca0c0a879f 100644 --- a/platform/util/base/src/com/intellij/util/containers/SoftHashMap.java +++ b/platform/util/base/src/com/intellij/util/containers/SoftHashMap.java @@ -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 extends RefHashMap { private static final class SoftKey extends SoftReference implements Key { private final int myHash; /* Hash code of key, stored here since the key may be tossed by the GC */ - @NotNull - private final HashingStrategy myStrategy; + private final @NotNull HashingStrategy myStrategy; private SoftKey(@NotNull T k, @NotNull HashingStrategy strategy, @NotNull ReferenceQueue q) { super(k, q); diff --git a/platform/util/base/src/com/intellij/util/containers/SoftKeySoftValueHashMap.java b/platform/util/base/src/com/intellij/util/containers/SoftKeySoftValueHashMap.java index 5d16114229b3..d591e9b4c108 100644 --- a/platform/util/base/src/com/intellij/util/containers/SoftKeySoftValueHashMap.java +++ b/platform/util/base/src/com/intellij/util/containers/SoftKeySoftValueHashMap.java @@ -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 implements Map{ throw RefValueHashMapUtil.pointlessContainsValue(); } - @NotNull @Override - public Set keySet() { + public @NotNull Set keySet() { return mySoftKeyMap.keySet(); } - @NotNull @Override - public Collection values() { + public @NotNull Collection values() { List result = new ArrayList<>(); Collection> refs = mySoftKeyMap.values(); for (ValueReference ref : refs) { @@ -110,9 +108,8 @@ final class SoftKeySoftValueHashMap implements Map{ return result; } - @NotNull @Override - public Set> entrySet() { + public @NotNull Set> entrySet() { throw new UnsupportedOperationException(); } } diff --git a/platform/util/base/src/com/intellij/util/containers/WeakKeySoftValueHashMap.java b/platform/util/base/src/com/intellij/util/containers/WeakKeySoftValueHashMap.java index 7aae75c0a399..9121ded0c5dd 100644 --- a/platform/util/base/src/com/intellij/util/containers/WeakKeySoftValueHashMap.java +++ b/platform/util/base/src/com/intellij/util/containers/WeakKeySoftValueHashMap.java @@ -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 extends RefKeyRefValueHashMap impl } private static final class SoftValueReference extends SoftReference implements ValueReference { - @NotNull private final RefHashMap.Key key; + private final @NotNull RefHashMap.Key key; private SoftValueReference(@NotNull RefHashMap.Key key, V referent, ReferenceQueue q) { super(referent, q); this.key = key; } - @NotNull @Override - public RefHashMap.Key getKey() { + public @NotNull RefHashMap.Key getKey() { return key; } } - @NotNull @Override - protected ValueReference createValueReference(@NotNull RefHashMap.Key key, - V referent, - ReferenceQueue q) { + protected @NotNull ValueReference createValueReference(@NotNull RefHashMap.Key key, + V referent, + ReferenceQueue q) { return new SoftValueReference<>(key, referent, q); } } diff --git a/platform/util/base/src/com/intellij/util/containers/WeakKeyWeakValueHashMap.java b/platform/util/base/src/com/intellij/util/containers/WeakKeyWeakValueHashMap.java index 81cf1ebf79b9..2aea0c42f088 100644 --- a/platform/util/base/src/com/intellij/util/containers/WeakKeyWeakValueHashMap.java +++ b/platform/util/base/src/com/intellij/util/containers/WeakKeyWeakValueHashMap.java @@ -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 extends RefKeyRefValueHashMap impl } private static final class WeakValueReference extends WeakReference implements ValueReference { - @NotNull private final RefHashMap.Key key; + private final @NotNull RefHashMap.Key key; private WeakValueReference(@NotNull RefHashMap.Key key, V referent, ReferenceQueue q) { super(referent, q); this.key = key; } - @NotNull @Override - public RefHashMap.Key getKey() { + public @NotNull RefHashMap.Key getKey() { return key; } } - @NotNull @Override - protected ValueReference createValueReference(@NotNull RefHashMap.Key key, - V referent, - ReferenceQueue q) { + protected @NotNull ValueReference createValueReference(@NotNull RefHashMap.Key key, + V referent, + ReferenceQueue q) { return new WeakValueReference<>(key, referent, q); } } diff --git a/platform/util/base/src/com/intellij/util/text/ByteArrayCharSequence.java b/platform/util/base/src/com/intellij/util/text/ByteArrayCharSequence.java index 88df7d318b8d..8839e9b792e5 100644 --- a/platform/util/base/src/com/intellij/util/text/ByteArrayCharSequence.java +++ b/platform/util/base/src/com/intellij/util/text/ByteArrayCharSequence.java @@ -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); } diff --git a/platform/util/base/src/com/intellij/util/text/CharArrayCharSequence.java b/platform/util/base/src/com/intellij/util/text/CharArrayCharSequence.java index a1a482cd75bb..6e97b3479c1f 100644 --- a/platform/util/base/src/com/intellij/util/text/CharArrayCharSequence.java +++ b/platform/util/base/src/com/intellij/util/text/CharArrayCharSequence.java @@ -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 } diff --git a/platform/util/base/src/com/intellij/util/text/CharArrayUtil.java b/platform/util/base/src/com/intellij/util/text/CharArrayUtil.java index 341d59fd3229..79f3887041e2 100644 --- a/platform/util/base/src/com/intellij/util/text/CharArrayUtil.java +++ b/platform/util/base/src/com/intellij/util/text/CharArrayUtil.java @@ -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); } } diff --git a/platform/util/base/src/com/intellij/util/text/CharSequenceSubSequence.java b/platform/util/base/src/com/intellij/util/text/CharSequenceSubSequence.java index 9ad2febe301f..6d332a7bca77 100644 --- a/platform/util/base/src/com/intellij/util/text/CharSequenceSubSequence.java +++ b/platform/util/base/src/com/intellij/util/text/CharSequenceSubSequence.java @@ -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)); } diff --git a/platform/util/base/src/com/intellij/util/text/ImmutableCharSequence.java b/platform/util/base/src/com/intellij/util/text/ImmutableCharSequence.java index 63386d964b9e..d28811f4372f 100644 --- a/platform/util/base/src/com/intellij/util/text/ImmutableCharSequence.java +++ b/platform/util/base/src/com/intellij/util/text/ImmutableCharSequence.java @@ -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(); } diff --git a/platform/util/base/src/com/intellij/util/text/ImmutableText.java b/platform/util/base/src/com/intellij/util/text/ImmutableText.java index 8c7825dd545d..875f96cfcc36 100644 --- a/platform/util/base/src/com/intellij/util/text/ImmutableText.java +++ b/platform/util/base/src/com/intellij/util/text/ImmutableText.java @@ -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); diff --git a/platform/util/base/src/com/intellij/util/text/SemVer.java b/platform/util/base/src/com/intellij/util/text/SemVer.java index d467cce8a494..5026ec2b1186 100644 --- a/platform/util/base/src/com/intellij/util/text/SemVer.java +++ b/platform/util/base/src/com/intellij/util/text/SemVer.java @@ -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 { 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 { 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) { diff --git a/platform/util/base/src/com/intellij/util/text/StringSearcher.java b/platform/util/base/src/com/intellij/util/text/StringSearcher.java index 1a635107bf4d..57d1b3d0fab9 100644 --- a/platform/util/base/src/com/intellij/util/text/StringSearcher.java +++ b/platform/util/base/src/com/intellij/util/text/StringSearcher.java @@ -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; }