Class TextRange

java.lang.Object
com.intellij.openapi.util.TextRange
All Implemented Interfaces:
Segment, Serializable

public class TextRange extends Object implements Segment, Serializable
A text range defined by start and end (exclusive) offset.
See Also:
  • invalid reference
    ProperTextRange
  • invalid reference
    com.intellij.util.text.TextRangeUtil
  • Serialized Form
  • Field Details

    • EMPTY_RANGE

      public static final TextRange EMPTY_RANGE
    • EMPTY_ARRAY

      public static final TextRange[] EMPTY_ARRAY
  • Constructor Details

    • TextRange

      @Contract(pure=true) public TextRange(int startOffset, int endOffset)
      See Also:
    • TextRange

      protected TextRange(int startOffset, int endOffset, boolean checkForProperTextRange)
      Parameters:
      checkForProperTextRange - true if offsets should be checked by assertProperRange(int, int, Object)
      See Also:
      • invalid reference
        UnfairTextRange
  • Method Details

    • getStartOffset

      public final int getStartOffset()
      Specified by:
      getStartOffset in interface Segment
    • getEndOffset

      public final int getEndOffset()
      Specified by:
      getEndOffset in interface Segment
    • getLength

      public final int getLength()
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • contains

      @Contract(pure=true) public boolean contains(@NotNull @NotNull TextRange range)
      Checks if the specified text range is fully contained within this TextRange.
      Parameters:
      range - the text range to check for containment
      Returns:
      true if the specified text range is contained within this object, false otherwise
    • contains

      @Contract(pure=true) public boolean contains(@NotNull @NotNull Segment segment)
      Checks if the given segment is fully contained within this TextRange.
      Parameters:
      segment - the segment to be checked for containment
      Returns:
      true if the given range is contained within this segment, false otherwise
    • containsRange

      @Contract(pure=true) public boolean containsRange(int startOffset, int endOffset)
      Checks if the given range is fully contained within this TextRange.
      Parameters:
      startOffset - the start offset of the range to check
      endOffset - the end offset of the range to check
      Returns:
      true if the given range is contained within this TextRange, false otherwise
    • containsRange

      @Contract(pure=true) public static boolean containsRange(@NotNull @NotNull Segment outer, @NotNull @NotNull Segment inner)
    • containsOffset

      @Contract(pure=true) public boolean containsOffset(int offset)
      Checks if the given offset is contained within the range (unlike contains(int), offset at the end of the range is considered to be inside).
      Parameters:
      offset - the offset to check
      Returns:
      true if the given offset is within the range, false otherwise
      See Also:
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • contains

      @Contract(pure=true) public boolean contains(int offset)
      Checks if the given offset is contained within the range (unlike containsOffset(int), offset at the end of the range is considered to be outside).
      Parameters:
      offset - the offset to check
      Returns:
      true if the given offset is within the range, false otherwise
      See Also:
    • substring

      @Contract(pure=true) @NotNull public @NotNull String substring(@NotNull @NotNull String str)
      Returns a substring of the given string that is covered by this TextRange.
      Parameters:
      str - the string from which the substring will be extracted
      Returns:
      the substring
    • subSequence

      @Contract(pure=true) @NotNull public @NotNull CharSequence subSequence(@NotNull @NotNull CharSequence str)
    • cutOut

      @Contract(pure=true) @NotNull public @NotNull TextRange cutOut(@NotNull @NotNull TextRange subRange)
    • shiftRight

      @Contract(pure=true) @NotNull public @NotNull TextRange shiftRight(int delta)
    • shiftLeft

      @Contract(pure=true) @NotNull public @NotNull TextRange shiftLeft(int delta)
    • grown

      @Contract(pure=true) @NotNull public @NotNull TextRange grown(int lengthDelta)
    • from

      @Contract(pure=true) @NotNull public static @NotNull TextRange from(int offset, int length)
    • create

      @Contract(pure=true) @NotNull public static @NotNull TextRange create(int startOffset, int endOffset)
    • create

      @Contract(pure=true) @NotNull public static @NotNull TextRange create(@NotNull @NotNull Segment segment)
    • areSegmentsEqual

      @Contract(pure=true) public static boolean areSegmentsEqual(@NotNull @NotNull Segment segment1, @NotNull @NotNull Segment segment2)
    • replace

      @Contract(pure=true) @NotNull public @NotNull String replace(@NotNull @NotNull String original, @NotNull @NotNull String replacement)
    • intersects

      @Contract(pure=true) public boolean intersects(@NotNull @NotNull TextRange textRange)
    • intersects

      @Contract(pure=true) public boolean intersects(@NotNull @NotNull Segment textRange)
    • intersects

      @Contract(pure=true) public boolean intersects(int startOffset, int endOffset)
    • intersectsStrict

      @Contract(pure=true) public boolean intersectsStrict(@NotNull @NotNull TextRange textRange)
    • intersectsStrict

      @Contract(pure=true) public boolean intersectsStrict(int startOffset, int endOffset)
    • intersection

      @Contract(pure=true) public TextRange intersection(@NotNull @NotNull TextRange range)
    • isEmpty

      @Contract(pure=true) public boolean isEmpty()
    • union

      @Contract(pure=true) @NotNull public @NotNull TextRange union(@NotNull @NotNull TextRange textRange)
    • equalsToRange

      @Contract(pure=true) public boolean equalsToRange(int startOffset, int endOffset)
    • allOf

      @Contract(pure=true) @NotNull public static @NotNull TextRange allOf(@NotNull @NotNull String s)
    • assertProperRange

      public static void assertProperRange(@NotNull @NotNull Segment range) throws AssertionError
      Throws:
      AssertionError
    • assertProperRange

      public static void assertProperRange(@NotNull @NotNull Segment range, @NotNull @NotNull Object message) throws AssertionError
      Throws:
      AssertionError
    • assertProperRange

      public static void assertProperRange(int startOffset, int endOffset, @NotNull @NotNull Object message)
    • isProperRange

      public static boolean isProperRange(int startOffset, int endOffset)