Skip to content

Commit 249e26f

Browse files
bvennerscheeseng
authored andcommitted
Add missing @param/@tparam/@return Scaladoc tags in scala.util, scala.io, scala.ref (cleanup follow-up)
1 parent c101b01 commit 249e26f

25 files changed

Lines changed: 134 additions & 16 deletions

library-js/src/scala/util/DynamicVariable.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class DynamicVariable[T](init: T) {
6262
* @tparam S the result type of the thunk, also the return type of this method
6363
* @param newval The value to which to set the variable
6464
* @param thunk The code to evaluate under the new setting
65+
* @return the result of evaluating `thunk` with the variable temporarily bound to `newval`
6566
*/
6667
def withValue[S](newval: T)(thunk: => S): S = {
6768
val oldval = v

library/src/scala/io/BufferedSource.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ import scala.collection.mutable.StringBuilder
2222
* representation of a source file.
2323
*
2424
* @param inputStream the underlying input stream to read characters from
25-
* @param bufferSize the size of the internal buffer used for reading
25+
* @param bufferSize the size, in characters, of the internal buffer used for reading
26+
* @param codec the `Codec` used to decode bytes from the input stream into characters
2627
*/
2728
class BufferedSource(inputStream: InputStream, bufferSize: Int)(implicit val codec: Codec) extends Source {
2829
def this(inputStream: InputStream)(implicit codec: Codec) = this(inputStream, DefaultBufSize)(using codec)
@@ -96,8 +97,8 @@ class BufferedSource(inputStream: InputStream, bufferSize: Int)(implicit val cod
9697
* memory.
9798
*
9899
* @param sb the string builder to append to
99-
* @param start the string to prepend before the first character
100-
* @param sep the separator string inserted between elements
100+
* @param start the string to prepend before the first element
101+
* @param sep the separator string inserted between elements; passing an empty string enables the efficient bulk-read path
101102
* @param end the string to append after the last element
102103
* @return the string builder `sb` with all elements appended
103104
*/

library/src/scala/io/Position.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ private[scala] abstract class Position {
6868
*
6969
* @param line the 1-based line number, or 0 for undefined; values at or above `LINE_MASK` are clamped and the column is set to 0
7070
* @param column the 1-based column number, or 0 for undefined; clamped to `COLUMN_MASK`, ignored when `line` >= `LINE_MASK`
71+
* @return the encoded position as a non-negative integer that packs the line number in the high bits and the column number in the low bits, suitable for decoding with `line`, `column`, and `toString`
7172
*/
7273
final def encode(line: Int, column: Int): Int = {
7374
checkInput(line, column)
@@ -81,18 +82,21 @@ private[scala] abstract class Position {
8182
/** Returns the line number of the encoded position.
8283
*
8384
* @param pos the encoded position as returned by `encode`
85+
* @return the 1-based line number extracted from `pos`, or 0 if the line is undefined
8486
*/
8587
final def line(pos: Int): Int = (pos >> COLUMN_BITS) & LINE_MASK
8688

8789
/** Returns the column number of the encoded position.
8890
*
8991
* @param pos the encoded position as returned by `encode`
92+
* @return the 1-based column number extracted from `pos`, or 0 if the column is undefined
9093
*/
9194
final def column(pos: Int): Int = pos & COLUMN_MASK
9295

9396
/** Returns a string representation of the encoded position.
9497
*
9598
* @param pos the encoded position as returned by `encode`
99+
* @return a string in the form `"line:column"` using the decoded line and column numbers
96100
*/
97101
def toString(pos: Int): String = line(pos) + ":" + column(pos)
98102
}

library/src/scala/io/Source.scala

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,21 @@ object Source {
4141
/** Creates a Source instance from a single character.
4242
*
4343
* @param c the character to use as the source content
44+
* @return a `Source` that yields the single character `c`
4445
*/
4546
def fromChar(c: Char): Source = fromIterable(Array(c))
4647

4748
/** Creates Source from array of characters, with empty description.
4849
*
4950
* @param chars the array of characters to use as the source content
51+
* @return a `Source` that yields the characters from `chars`
5052
*/
5153
def fromChars(chars: Array[Char]): Source = fromIterable(chars)
5254

5355
/** Creates Source from a String, with no description.
5456
*
5557
* @param s the string to use as the source content
58+
* @return a `Source` that yields the characters of `s`
5659
*/
5760
def fromString(s: String): Source = fromIterable(s)
5861

@@ -61,6 +64,7 @@ object Source {
6164
*
6265
* @param name the name of the file to read
6366
* @param codec the implicit codec used for character encoding
67+
* @return a `BufferedSource` reading from the named file, described by its filename
6468
*/
6569
def fromFile(name: String)(implicit codec: Codec): BufferedSource =
6670
fromFile(new JFile(name))(using codec)
@@ -70,6 +74,7 @@ object Source {
7074
*
7175
* @param name the name of the file to read
7276
* @param enc the name of the character encoding to use
77+
* @return a `BufferedSource` reading from the named file with the given encoding
7378
*/
7479
def fromFile(name: String, enc: String): BufferedSource =
7580
fromFile(name)(using Codec(enc))
@@ -78,6 +83,7 @@ object Source {
7883
*
7984
* @param uri the file URI to read from
8085
* @param codec the implicit codec used for character encoding
86+
* @return a `BufferedSource` reading from the file referenced by `uri`
8187
*/
8288
def fromFile(uri: URI)(implicit codec: Codec): BufferedSource =
8389
fromFile(new JFile(uri))(using codec)
@@ -86,6 +92,7 @@ object Source {
8692
*
8793
* @param uri the file URI to read from
8894
* @param enc the name of the character encoding to use
95+
* @return a `BufferedSource` reading from the file referenced by `uri` with the given encoding
8996
*/
9097
def fromFile(uri: URI, enc: String): BufferedSource =
9198
fromFile(uri)(using Codec(enc))
@@ -95,6 +102,7 @@ object Source {
95102
*
96103
* @param file the file to read from
97104
* @param codec the implicit codec used for character encoding
105+
* @return a `BufferedSource` reading from `file` with the default buffer size
98106
*/
99107
def fromFile(file: JFile)(implicit codec: Codec): BufferedSource =
100108
fromFile(file, Source.DefaultBufSize)(using codec)
@@ -103,6 +111,7 @@ object Source {
103111
*
104112
* @param file the file to read from
105113
* @param enc the name of the character encoding to use
114+
* @return a `BufferedSource` reading from `file` with the given encoding
106115
*/
107116
def fromFile(file: JFile, enc: String): BufferedSource =
108117
fromFile(file)(using Codec(enc))
@@ -117,6 +126,7 @@ object Source {
117126
* @param file the file to read from
118127
* @param bufferSize the size of the input buffer, in characters
119128
* @param codec the implicit codec used for character encoding
129+
* @return a `BufferedSource` reading from `file` with the given buffer size, described by the file's absolute path
120130
*/
121131
def fromFile(file: JFile, bufferSize: Int)(implicit codec: Codec): BufferedSource = {
122132
val inputStream = new FileInputStream(file)
@@ -134,7 +144,7 @@ object Source {
134144
*
135145
* @param bytes the array of bytes to decode into characters
136146
* @param codec the implicit codec used for character encoding
137-
* @return the created `Source` instance.
147+
* @return a `Source` that yields the characters decoded from `bytes` using `codec`
138148
*/
139149
def fromBytes(bytes: Array[Byte])(implicit codec: Codec): Source =
140150
fromString(new String(bytes, codec.name))
@@ -153,6 +163,7 @@ object Source {
153163
*
154164
* @param uri the file URI to read from
155165
* @param codec the implicit codec used for character encoding
166+
* @return a `BufferedSource` reading from the file referenced by `uri`
156167
*/
157168
def fromURI(uri: URI)(implicit codec: Codec): BufferedSource =
158169
fromFile(new JFile(uri))(using codec)
@@ -161,6 +172,7 @@ object Source {
161172
*
162173
* @param s the URL string to read from
163174
* @param enc the name of the character encoding to use
175+
* @return a `BufferedSource` reading from the URL given by `s` with the given encoding
164176
*/
165177
def fromURL(s: String, enc: String): BufferedSource =
166178
fromURL(s)(using Codec(enc))
@@ -169,6 +181,7 @@ object Source {
169181
*
170182
* @param s the URL string to read from
171183
* @param codec the implicit codec used for character encoding
184+
* @return a `BufferedSource` reading from the URL given by `s`
172185
*/
173186
def fromURL(s: String)(implicit codec: Codec): BufferedSource =
174187
fromURL(new URI(s).toURL)(using codec)
@@ -177,6 +190,7 @@ object Source {
177190
*
178191
* @param url the URL to read from
179192
* @param enc the name of the character encoding to use
193+
* @return a `BufferedSource` reading from the stream opened on `url` with the given encoding
180194
*/
181195
def fromURL(url: URL, enc: String): BufferedSource =
182196
fromURL(url)(using Codec(enc))
@@ -185,6 +199,7 @@ object Source {
185199
*
186200
* @param url the URL to read from
187201
* @param codec the implicit codec used for character encoding
202+
* @return a `BufferedSource` reading from the stream opened on `url`
188203
*/
189204
def fromURL(url: URL)(implicit codec: Codec): BufferedSource =
190205
fromInputStream(url.openStream())(using codec)
@@ -197,7 +212,7 @@ object Source {
197212
* @param reset a () => Source which resets the stream (if unset, reset() will throw an Exception)
198213
* @param close a () => Unit method which closes the stream (if unset, close() will do nothing)
199214
* @param codec (implicit) a scala.io.Codec specifying behavior (defaults to Codec.default)
200-
* @return the buffered source
215+
* @return a `BufferedSource` reading from `inputStream` with the given buffer size
201216
*/
202217
def createBufferedSource(
203218
inputStream: InputStream,
@@ -221,6 +236,7 @@ object Source {
221236
*
222237
* @param resource name of the resource to load from the classpath
223238
* @param classLoader classloader to be used, or context classloader if not specified
239+
* @param codec the implicit codec used for character encoding
224240
* @return the buffered source
225241
*/
226242
def fromResource(resource: String, classLoader: ClassLoader = Thread.currentThread().getContextClassLoader())(implicit codec: Codec): BufferedSource =
@@ -406,6 +422,7 @@ abstract class Source extends Iterator[Char] with Closeable {
406422
/** Change or disable the positioner.
407423
*
408424
* @param on whether to enable (`true`) or disable (`false`) position tracking
425+
* @return this `Source`, to allow chained configuration calls
409426
*/
410427
def withPositioning(on: Boolean): this.type = {
411428
positioner = if (on) RelaxedPositioner else NoPositioner

library/src/scala/ref/SoftReference.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,17 @@ object SoftReference {
2626

2727
/** Creates a `SoftReference` pointing to `value`.
2828
*
29-
* @tparam T the type of the referenced object, must be a reference type
29+
* @tparam T the type of the referenced object; must be a subtype of `AnyRef`
3030
* @param value the object to be softly referenced; may be reclaimed by the garbage collector when memory is low
31+
* @return a new `SoftReference` wrapping `value`
3132
*/
3233
def apply[T <: AnyRef](value: T): SoftReference[T] = new SoftReference(value)
3334

3435
/** Optionally returns the referenced value, or `None` if that value no longer exists.
3536
*
36-
* @tparam T the type of the referenced object, must be a reference type
37+
* @tparam T the type of the referenced object; must be a subtype of `AnyRef`
3738
* @param sr the `SoftReference` to extract the value from
39+
* @return `Some(value)` if the referent has not been reclaimed, otherwise `None`
3840
*/
3941
def unapply[T <: AnyRef](sr: SoftReference[T]): Option[T] = Option(sr.underlying.get)
4042
}

library/src/scala/ref/WeakReference.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,15 @@ object WeakReference {
3535
*
3636
* @tparam T the type of the value to wrap in a weak reference
3737
* @param value the object to be weakly referenced
38+
* @return a new `WeakReference` wrapping `value`
3839
*/
3940
def apply[T <: AnyRef](value: T): WeakReference[T] = new WeakReference(value)
4041

4142
/** Optionally returns the referenced value, or `None` if that value no longer exists.
4243
*
4344
* @tparam T the type of the value to extract from the weak reference
4445
* @param wr the weak reference to extract a value from
46+
* @return `Some(value)` if the referent is still reachable, or `None` if it has been garbage collected
4547
*/
4648
def unapply[T <: AnyRef](wr: WeakReference[T]): Option[T] = Option(wr.underlying.get)
4749
}

library/src/scala/util/CommandLineParser.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ object CommandLineParser {
1717
* @param str the command line argument string to parse
1818
* @param n the zero-based index of the argument, used for error reporting
1919
* @param fs the type class instance (usually provided implicitly) that converts a string to type `T`
20+
* @return the value of type `T` parsed from `str`
2021
* @throws ParseError if argument cannot be converted to type `T`.
2122
*/
2223
def parseString[T](str: String, n: Int)(using fs: FromString[T]^): T = {
@@ -32,6 +33,7 @@ object CommandLineParser {
3233
* @param args the command line arguments array
3334
* @param n the zero-based index of the argument to parse
3435
* @param fs the type class instance that converts a string to type `T`
36+
* @return the value of type `T` parsed from the argument at index `n`
3537
* @throws ParseError if argument does not exist or cannot be converted to type `T`.
3638
*/
3739
def parseArgument[T](args: Array[String], n: Int)(using fs: FromString[T]^): T =
@@ -44,6 +46,7 @@ object CommandLineParser {
4446
* @param args the command line arguments array
4547
* @param n the zero-based index of the first remaining argument to parse
4648
* @param fs the type class instance that converts a string to type `T`
49+
* @return a list of values of type `T` parsed from arguments at indices `n` through the end, or an empty list if `n` is past the last argument
4750
* @throws ParseError if some of the arguments cannot be converted to type `T`.
4851
*/
4952
def parseRemainingArguments[T](args: Array[String], n: Int)(using fs: FromString[T]^): List[T] =
@@ -66,6 +69,7 @@ object CommandLineParser {
6669
/** Can throw java.lang.IllegalArgumentException.
6770
*
6871
* @param s the string to convert to type `T`
72+
* @return the value of type `T` parsed from `s`
6973
*/
7074
def fromString(s: String): T
7175

library/src/scala/util/DynamicVariable.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class DynamicVariable[T](init: T) {
5757
* @tparam S the result type of the thunk
5858
* @param newval the value to which to set the variable
5959
* @param thunk the code to evaluate under the new setting
60+
* @return the result of evaluating `thunk` with the variable bound to `newval`
6061
*/
6162
def withValue[S](newval: T)(thunk: => S): S = {
6263
val oldval = value

library/src/scala/util/Either.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ sealed abstract class Either[+A, +B] extends Product with Serializable {
422422
* @tparam A1 the supertype of `A` used to widen the left type
423423
* @tparam B1 the right type of the resulting `Either`
424424
* @param f the function to bind across `Right`
425+
* @return the result of applying `f` if this is a `Right`, otherwise the unchanged `Left`
425426
*/
426427
def flatMap[A1 >: A, B1](f: B => Either[A1, B1]): Either[A1, B1] = this match {
427428
case Right(b) => f(b)
@@ -563,6 +564,7 @@ final case class Left[+A, +B](value: A) extends Either[A, B] {
563564
* ```
564565
*
565566
* @tparam B1 the target right type to widen to
567+
* @return this `Left` typed as `Either[A, B1]`
566568
*/
567569
def withRight[B1 >: B]: Either[A, B1] = this
568570

@@ -585,6 +587,7 @@ final case class Right[+A, +B](value: B) extends Either[A, B] {
585587
* ```
586588
*
587589
* @tparam A1 the target left type to widen to
590+
* @return this `Right` typed as `Either[A1, B]`
588591
*/
589592
def withLeft[A1 >: A]: Either[A1, B] = this
590593

@@ -915,6 +918,7 @@ object Either {
915918
* @tparam A1 the supertype of `A` used to widen the left type
916919
* @tparam B1 the right type of the resulting `Either`
917920
* @param f the function to bind across `Right`
921+
* @return the result of applying `f` if this is a `Right`, otherwise the unchanged `Left`
918922
*/
919923
def flatMap[A1 >: A, B1](f: B => Either[A1, B1]): Either[A1, B1] = e match {
920924
case Right(b) => f(b)

library/src/scala/util/FromDigits.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ object FromDigits {
4141
*
4242
* @param digits the string representation of the numeric literal to convert
4343
* @param radix the base for the number system (e.g. 10 for decimal, 16 for hexadecimal)
44+
* @return the value of type `T` represented by the digit string interpreted in the given radix
4445
*/
4546
def fromDigits(digits: String, radix: Int): T
4647
}
@@ -95,6 +96,7 @@ object FromDigits {
9596
* @param digits the string representation of the numeric literal to convert
9697
* @param radix the base for the number system (e.g. 10 for decimal, 16 for hexadecimal)
9798
* @param limit the upper bound for positive values of the result type (e.g. `Int.MaxValue` or `Long.MaxValue`)
99+
* @return the integer value represented by the digit string, as a `Long`
98100
*/
99101
private def integerFromDigits(digits: String, radix: Int, limit: Long): Long = {
100102
var value: Long = 0
@@ -126,8 +128,10 @@ object FromDigits {
126128
}
127129

128130
/** Converts digit string to Int number.
131+
*
129132
* @param digits The string to convert
130133
* @param radix The radix
134+
* @return the `Int` value represented by the digit string in the given radix
131135
* @throws NumberTooLarge if number does not fit within Int range
132136
* @throws MalformedNumber if digits is not a legal digit string.
133137
* Legal strings consist only of digits conforming to radix,
@@ -137,8 +141,10 @@ object FromDigits {
137141
integerFromDigits(digits, radix, Int.MaxValue).toInt
138142

139143
/** Converts digit string to Long number.
144+
*
140145
* @param digits The string to convert
141146
* @param radix The radix
147+
* @return the `Long` value represented by the digit string in the given radix
142148
* @throws NumberTooLarge if the resulting number does not fit within Long range
143149
* @throws MalformedNumber if digits is not a legal digit string.
144150
* Legal strings consist only of digits conforming to radix,
@@ -150,7 +156,9 @@ object FromDigits {
150156
@sharable private val zeroFloat = raw"-?[0.]+(?:[eE][+-]?[0-9]+)?[fFdD]?".r
151157

152158
/** Converts digit string to Float number.
159+
*
153160
* @param digits The string to convert
161+
* @return the `Float` value represented by the digit string
154162
* @throws NumberTooLarge if the resulting number is infinite
155163
* @throws NumberTooSmall if the resulting number is 0.0f, yet the digits
156164
* string contains non-zero digits before the exponent.
@@ -168,7 +176,9 @@ object FromDigits {
168176
}
169177

170178
/** Converts digit string to Double number.
179+
*
171180
* @param digits The string to convert
181+
* @return the `Double` value represented by the digit string
172182
* @throws NumberTooLarge if the resulting number is infinite
173183
* @throws NumberTooSmall if the resulting number is 0.0d, yet the digits
174184
* string contains non-zero digits before the exponent.

0 commit comments

Comments
 (0)