@@ -1155,28 +1155,61 @@ class Definitions {
11551155 def isPredefClass (cls : Symbol ): Boolean =
11561156 (cls.owner eq ScalaPackageClass ) && predefClassNames.contains(cls.name)
11571157
1158- val StaticRootImportFns : List [RootRef ] = List [RootRef ](
1159- (() => JavaLangPackageVal .termRef, false ),
1160- (() => ScalaPackageVal .termRef, false )
1158+ private val JavaImportFns : List [RootRef ] = List (
1159+ RootRef (() => JavaLangPackageVal .termRef)
11611160 )
11621161
1163- val PredefImportFns : List [RootRef ] = List [RootRef ](
1164- (() => ScalaPredefModule .termRef, true ),
1165- (() => DottyPredefModule .termRef, false )
1162+ private val ScalaImportFns : List [RootRef ] =
1163+ JavaImportFns :+
1164+ RootRef (() => ScalaPackageVal .termRef)
1165+
1166+ private val PredefImportFns : List [RootRef ] = List (
1167+ RootRef (() => ScalaPredefModule .termRef, isPredef= true ),
1168+ RootRef (() => DottyPredefModule .termRef)
11661169 )
11671170
1168- @ tu lazy val RootImportFns : List [RootRef ] =
1169- if (ctx.settings.YnoImports .value) Nil
1170- else if (ctx.settings.YnoPredef .value) StaticRootImportFns
1171- else StaticRootImportFns ++ PredefImportFns
1171+ @ tu private lazy val JavaRootImportFns : List [RootRef ] =
1172+ if ctx.settings.YnoImports .value then Nil
1173+ else JavaImportFns
11721174
1173- @ tu lazy val ShadowableImportNames : Set [TermName ] = Set (" Predef" , " DottyPredef" ).map(_.toTermName)
1174- @ tu lazy val RootImportTypes : List [TermRef ] = RootImportFns .map(_._1())
1175+ @ tu private lazy val ScalaRootImportFns : List [RootRef ] =
1176+ if ctx.settings.YnoImports .value then Nil
1177+ else if ctx.settings.YnoPredef .value then ScalaImportFns
1178+ else ScalaImportFns ++ PredefImportFns
1179+
1180+ @ tu private lazy val JavaRootImportTypes : List [TermRef ] = JavaRootImportFns .map(_.refFn())
1181+ @ tu private lazy val ScalaRootImportTypes : List [TermRef ] = ScalaRootImportFns .map(_.refFn())
1182+ @ tu private lazy val JavaUnqualifiedOwnerTypes : Set [NamedType ] = unqualifiedTypes(JavaRootImportTypes )
1183+ @ tu private lazy val ScalaUnqualifiedOwnerTypes : Set [NamedType ] = unqualifiedTypes(ScalaRootImportTypes )
1184+
1185+ /** Are we compiling a java source file? */
1186+ private def isJavaContext (using Context ): Boolean =
1187+ val unit = ctx.compilationUnit
1188+ unit != null && unit.isJava
1189+
1190+ private def unqualifiedTypes (refs : List [TermRef ]) =
1191+ val types = refs.toSet[NamedType ]
1192+ types ++ types.map(_.symbol.moduleClass.typeRef)
1193+
1194+ /** Lazy references to the root imports */
1195+ def rootImportFns (using Context ): List [RootRef ] =
1196+ if isJavaContext then JavaRootImportFns
1197+ else ScalaRootImportFns
1198+
1199+ /** Root types imported by default */
1200+ def rootImportTypes (using Context ): List [TermRef ] =
1201+ if isJavaContext then JavaRootImportTypes
1202+ else ScalaRootImportTypes
11751203
11761204 /** Modules whose members are in the default namespace and their module classes */
1177- @ tu lazy val UnqualifiedOwnerTypes : Set [NamedType ] =
1178- RootImportTypes .toSet[NamedType ] ++ RootImportTypes .map(_.symbol.moduleClass.typeRef)
1205+ def unqualifiedOwnerTypes (using Context ): Set [NamedType ] =
1206+ if isJavaContext then JavaUnqualifiedOwnerTypes
1207+ else ScalaUnqualifiedOwnerTypes
1208+
1209+ /** Names of the root import symbols that can be hidden by other imports */
1210+ @ tu lazy val ShadowableImportNames : Set [TermName ] = Set (" Predef" , " DottyPredef" ).map(_.toTermName)
11791211
1212+ /** Class symbols for which no class exist at runtime */
11801213 @ tu lazy val NotRuntimeClasses : Set [Symbol ] = Set (AnyClass , AnyValClass , NullClass , NothingClass )
11811214
11821215 @ tu lazy val SpecialClassTagClasses : Set [Symbol ] = Set (UnitClass , AnyClass , AnyValClass )
0 commit comments