@@ -11,22 +11,22 @@ import NullOpsDecorator._
1111 * as Scala types, which are explicitly nullable.
1212 *
1313 * The transformation is (conceptually) a function `n` that adheres to the following rules:
14- * (1) n(T) = T|JavaNull if T is a reference type
14+ * (1) n(T) = T|UncheckedNull if T is a reference type
1515 * (2) n(T) = T if T is a value type
16- * (3) n(C[T]) = C[T]|JavaNull if C is Java-defined
17- * (4) n(C[T]) = C[n(T)]|JavaNull if C is Scala-defined
18- * (5) n(A|B) = n(A)|n(B)|JavaNull
16+ * (3) n(C[T]) = C[T]|UncheckedNull if C is Java-defined
17+ * (4) n(C[T]) = C[n(T)]|UncheckedNull if C is Scala-defined
18+ * (5) n(A|B) = n(A)|n(B)|UncheckedNull
1919 * (6) n(A&B) = n(A) & n(B)
2020 * (7) n((A1, ..., Am)R) = (n(A1), ..., n(Am))n(R) for a method with arguments (A1, ..., Am) and return type R
2121 * (8) n(T) = T otherwise
2222 *
2323 * Treatment of generics (rules 3 and 4):
24- * - if `C` is Java-defined, then `n(C[T]) = C[T]|JavaNull `. That is, we don't recurse
25- * on the type argument, and only add JavaNull on the outside. This is because
24+ * - if `C` is Java-defined, then `n(C[T]) = C[T]|UncheckedNull `. That is, we don't recurse
25+ * on the type argument, and only add UncheckedNull on the outside. This is because
2626 * `C` itself will be nullified, and in particular so will be usages of `C`'s type argument within C's body.
2727 * e.g. calling `get` on a `java.util.List[String]` already returns `String|Null` and not `String`, so
2828 * we don't need to write `java.util.List[String|Null]`.
29- * - if `C` is Scala-defined, however, then we want `n(C[T]) = C[n(T)]|JavaNull `. This is because
29+ * - if `C` is Scala-defined, however, then we want `n(C[T]) = C[n(T)]|UncheckedNull `. This is because
3030 * `C` won't be nullified, so we need to indicate that its type argument is nullable.
3131 *
3232 * Notice that since the transformation is only applied to types attached to Java symbols, it doesn't need
@@ -43,9 +43,9 @@ object JavaNullInterop {
4343 *
4444 * After calling `nullifyMember`, Scala will see the method as
4545 *
46- * def foo(arg: String|JavaNull ): String|JavaNull
46+ * def foo(arg: String|UncheckedNull ): String|UncheckedNull
4747 *
48- * This nullability function uses `JavaNull ` instead of vanilla `Null`, for usability.
48+ * This nullability function uses `UncheckedNull ` instead of vanilla `Null`, for usability.
4949 * This means that we can select on the return of `foo`:
5050 *
5151 * val len = foo("hello").length
@@ -81,20 +81,20 @@ object JavaNullInterop {
8181 private def nullifyExceptReturnType (tp : Type )(implicit ctx : Context ): Type =
8282 new JavaNullMap (true )(ctx)(tp)
8383
84- /** Nullifies a Java type by adding `| JavaNull ` in the relevant places. */
84+ /** Nullifies a Java type by adding `| UncheckedNull ` in the relevant places. */
8585 private def nullifyType (tp : Type )(implicit ctx : Context ): Type =
8686 new JavaNullMap (false )(ctx)(tp)
8787
88- /** A type map that implements the nullification function on types. Given a Java-sourced type, this adds `| JavaNull `
88+ /** A type map that implements the nullification function on types. Given a Java-sourced type, this adds `| UncheckedNull `
8989 * in the right places to make the nulls explicit in Scala.
9090 *
9191 * @param outermostLevelAlreadyNullable whether this type is already nullable at the outermost level.
92- * For example, `Array[String]|JavaNull ` is already nullable at the
93- * outermost level, but `Array[String|JavaNull ]` isn't.
92+ * For example, `Array[String]|UncheckedNull ` is already nullable at the
93+ * outermost level, but `Array[String|UncheckedNull ]` isn't.
9494 * If this parameter is set to true, then the types of fields, and the return
9595 * types of methods will not be nullified.
9696 * This is useful for e.g. constructors, and also so that `A & B` is nullified
97- * to `(A & B) | JavaNull `, instead of `(A|JavaNull & B|JavaNull ) | JavaNull `.
97+ * to `(A & B) | UncheckedNull `, instead of `(A|UncheckedNull & B|UncheckedNull ) | UncheckedNull `.
9898 */
9999 private class JavaNullMap (var outermostLevelAlreadyNullable : Boolean )(implicit ctx : Context ) extends TypeMap {
100100 /** Should we nullify `tp` at the outermost level? */
@@ -107,15 +107,15 @@ object JavaNullInterop {
107107 ! tp.isRef(defn.AnyClass ) &&
108108 // We don't nullify Java varargs at the top level.
109109 // Example: if `setNames` is a Java method with signature `void setNames(String... names)`,
110- // then its Scala signature will be `def setNames(names: (String|JavaNull )*): Unit`.
110+ // then its Scala signature will be `def setNames(names: (String|UncheckedNull )*): Unit`.
111111 // This is because `setNames(null)` passes as argument a single-element array containing the value `null`,
112112 // and not a `null` array.
113113 ! tp.isRef(defn.RepeatedParamClass )
114114 case _ => true
115115 })
116116
117117 override def apply (tp : Type ): Type = tp match {
118- case tp : TypeRef if needsNull(tp) => OrJavaNull (tp)
118+ case tp : TypeRef if needsNull(tp) => OrUncheckedNull (tp)
119119 case appTp @ AppliedType (tycon, targs) =>
120120 val oldOutermostNullable = outermostLevelAlreadyNullable
121121 // We don't make the outmost levels of type arguements nullable if tycon is Java-defined.
@@ -125,7 +125,7 @@ object JavaNullInterop {
125125 val targs2 = targs map this
126126 outermostLevelAlreadyNullable = oldOutermostNullable
127127 val appTp2 = derivedAppliedType(appTp, tycon, targs2)
128- if (needsNull(tycon)) OrJavaNull (appTp2) else appTp2
128+ if (needsNull(tycon)) OrUncheckedNull (appTp2) else appTp2
129129 case ptp : PolyType =>
130130 derivedLambdaType(ptp)(ptp.paramInfos, this (ptp.resType))
131131 case mtp : MethodType =>
@@ -136,11 +136,11 @@ object JavaNullInterop {
136136 derivedLambdaType(mtp)(paramInfos2, this (mtp.resType))
137137 case tp : TypeAlias => mapOver(tp)
138138 case tp : AndType =>
139- // nullify(A & B) = (nullify(A) & nullify(B)) | JavaNull , but take care not to add
140- // duplicate `JavaNull `s at the outermost level inside `A` and `B`.
139+ // nullify(A & B) = (nullify(A) & nullify(B)) | UncheckedNull , but take care not to add
140+ // duplicate `UncheckedNull `s at the outermost level inside `A` and `B`.
141141 outermostLevelAlreadyNullable = true
142- OrJavaNull (derivedAndType(tp, this (tp.tp1), this (tp.tp2)))
143- case tp : TypeParamRef if needsNull(tp) => OrJavaNull (tp)
142+ OrUncheckedNull (derivedAndType(tp, this (tp.tp1), this (tp.tp2)))
143+ case tp : TypeParamRef if needsNull(tp) => OrUncheckedNull (tp)
144144 // In all other cases, return the type unchanged.
145145 // In particular, if the type is a ConstantType, then we don't nullify it because it is the
146146 // type of a final non-nullable field.
0 commit comments