@@ -1140,28 +1140,61 @@ class Definitions {
11401140 def isPredefClass (cls : Symbol ): Boolean =
11411141 (cls.owner eq ScalaPackageClass ) && predefClassNames.contains(cls.name)
11421142
1143- val StaticRootImportFns : List [RootRef ] = List [RootRef ](
1144- (() => JavaLangPackageVal .termRef, false ),
1145- (() => ScalaPackageVal .termRef, false )
1143+ private val JavaImportFns : List [RootRef ] = List (
1144+ RootRef (() => JavaLangPackageVal .termRef)
11461145 )
11471146
1148- val PredefImportFns : List [RootRef ] = List [RootRef ](
1149- (() => ScalaPredefModule .termRef, true ),
1150- (() => DottyPredefModule .termRef, false )
1147+ private val ScalaImportFns : List [RootRef ] =
1148+ JavaImportFns :+
1149+ RootRef (() => ScalaPackageVal .termRef)
1150+
1151+ private val PredefImportFns : List [RootRef ] = List (
1152+ RootRef (() => ScalaPredefModule .termRef, isPredef= true ),
1153+ RootRef (() => DottyPredefModule .termRef)
11511154 )
11521155
1153- @ tu lazy val RootImportFns : List [RootRef ] =
1154- if (ctx.settings.YnoImports .value) Nil
1155- else if (ctx.settings.YnoPredef .value) StaticRootImportFns
1156- else StaticRootImportFns ++ PredefImportFns
1156+ @ tu private lazy val JavaRootImportFns : List [RootRef ] =
1157+ if ctx.settings.YnoImports .value then Nil
1158+ else JavaImportFns
11571159
1158- @ tu lazy val ShadowableImportNames : Set [TermName ] = Set (" Predef" , " DottyPredef" ).map(_.toTermName)
1159- @ tu lazy val RootImportTypes : List [TermRef ] = RootImportFns .map(_._1())
1160+ @ tu private lazy val ScalaRootImportFns : List [RootRef ] =
1161+ if ctx.settings.YnoImports .value then Nil
1162+ else if ctx.settings.YnoPredef .value then ScalaImportFns
1163+ else ScalaImportFns ++ PredefImportFns
1164+
1165+ @ tu private lazy val JavaRootImportTypes : List [TermRef ] = JavaRootImportFns .map(_.refFn())
1166+ @ tu private lazy val ScalaRootImportTypes : List [TermRef ] = ScalaRootImportFns .map(_.refFn())
1167+ @ tu private lazy val JavaUnqualifiedOwnerTypes : Set [NamedType ] = unqualifiedTypes(JavaRootImportTypes )
1168+ @ tu private lazy val ScalaUnqualifiedOwnerTypes : Set [NamedType ] = unqualifiedTypes(ScalaRootImportTypes )
1169+
1170+ /** Are we compiling a java source file? */
1171+ private def isJavaContext (using Context ): Boolean =
1172+ val unit = ctx.compilationUnit
1173+ unit != null && unit.isJava
1174+
1175+ private def unqualifiedTypes (refs : List [TermRef ]) =
1176+ val types = refs.toSet[NamedType ]
1177+ types ++ types.map(_.symbol.moduleClass.typeRef)
1178+
1179+ /** Lazy references to the root imports */
1180+ def rootImportFns (using Context ): List [RootRef ] =
1181+ if isJavaContext then JavaRootImportFns
1182+ else ScalaRootImportFns
1183+
1184+ /** Root types imported by default */
1185+ def rootImportTypes (using Context ): List [TermRef ] =
1186+ if isJavaContext then JavaRootImportTypes
1187+ else ScalaRootImportTypes
11601188
11611189 /** Modules whose members are in the default namespace and their module classes */
1162- @ tu lazy val UnqualifiedOwnerTypes : Set [NamedType ] =
1163- RootImportTypes .toSet[NamedType ] ++ RootImportTypes .map(_.symbol.moduleClass.typeRef)
1190+ def unqualifiedOwnerTypes (using Context ): Set [NamedType ] =
1191+ if isJavaContext then JavaUnqualifiedOwnerTypes
1192+ else ScalaUnqualifiedOwnerTypes
1193+
1194+ /** Names of the root import symbols that can be hidden by other imports */
1195+ @ tu lazy val ShadowableImportNames : Set [TermName ] = Set (" Predef" , " DottyPredef" ).map(_.toTermName)
11641196
1197+ /** Class symbols for which no class exist at runtime */
11651198 @ tu lazy val NotRuntimeClasses : Set [Symbol ] = Set (AnyClass , AnyValClass , NullClass , NothingClass )
11661199
11671200 /** Classes that are known not to have an initializer irrespective of
0 commit comments