Sébastien,
Geoff,
(Not sure why Geoff's reply doesn't show up in Google groups yet, but my comments refer to it).
A straightforward way to find out java.lang.* dependencies is the compiler option -Yno-imports
whose effect is "Compile without importing scala.*, java.lang.*, or Predef."
A few more details on that "-Yno-imports", it affects the following:
/** List of symbols to import from in a root context. Typically that
* is java.lang, scala, and scala.Predef, in that order. Exceptions:
*
* -- if -Yno-imports is given, nothing is imported
* -- if the unit is java defined, only java.lang is imported
* -- if -Yno-predef is given, if the unit has an import of Predef
* among its leading imports, or if the unit is scala.ScalaObject
* or scala.Predef, Predef is not imported.
*/
protected def rootImports(unit: CompilationUnit, tree: Tree): List[Symbol] = {
import definitions._
assert(isDefinitionsInitialized, "definitions uninitialized")
if (settings.noimports.value) Nil
else if (unit.isJava) List(JavaLangPackage)
else if (settings.nopredef.value || treeInfo.noPredefImportForUnit(unit.body)) List(JavaLangPackage, ScalaPackage)
else List(JavaLangPackage, ScalaPackage, PredefModule)
}
> 2. Design a idomatic Scala platform API. Split the API
> into parts that can be implemented portably and those
> that can't just as above.
>
> In this case even the JVM target would require additional code to
> implement the platform API on top of JRE classes.
I see. It's doable, it's for the common good, and so on.
> I'm not sure that I understand what you mean by
> whitelisting and book-keeping. By this do you mean generating
> a list of java classes which are allowable in the compiler
> and library and a process for enforcing the constraint?
What I had in mind is some automatic means to check whether platform dependencies had leaked into the codebase.
A tool to help with this need not be fancy, -Yno-imports helps somewhat but a dedicated compiler plugin can do a better job.
For example, to find out whether a callsite invokes JDK stuff one can test:
msym.owner.ownerChain contains JavaPackageClass
where
for(msym <- a.tpe.deferredMembers . . .
Other examples in
That plugin would report sometimes good news, e.g. that java.util.Properties is used but in fact it's already pretty much cordoned to
scala.sys.SystemProperties (thanks, Paul!)
/** A bidirectional map wrapping the java System properties.
* Changes to System properties will be immediately visible in the map,
* and modifications made to the map will be immediately applied to the
* System properties. If a security manager is in place which prevents
* the properties from being read or written, the AccessControlException
* will be caught and discarded.
*
* <at> author Paul Phillips
* <at> version 2.9
* <at> since 2.9
*/
class SystemProperties extends mutable.Map[String, String] {
Miguel