@@ -22,19 +22,43 @@ trait ClassPath {
2222 import scala .tools .nsc .classpath ._
2323 def asURLs : Seq [URL ]
2424
25- /** Empty string represents root package */
25+ /*
26+ * These methods are mostly used in the ClassPath implementation to implement the `list` and
27+ * `findX` methods below.
28+ *
29+ * However, there are some other uses in the compiler, to implement `invalidateClassPathEntries`,
30+ * which is used by the repl's `:require` (and maybe the spark repl, https://github.com/scala/scala/pull/4051).
31+ * Using these methods directly is more efficient than calling `list`.
32+ *
33+ * The `inPackage` string is a full package name, e.g. "" or "scala.collection".
34+ */
35+
2636 private [nsc] def hasPackage (pkg : String ): Boolean
2737 private [nsc] def packages (inPackage : String ): Seq [PackageEntry ]
2838 private [nsc] def classes (inPackage : String ): Seq [ClassFileEntry ]
2939 private [nsc] def sources (inPackage : String ): Seq [SourceFileEntry ]
3040
31- /** Allows to get entries for packages and classes merged with sources possibly in one pass. */
41+ /**
42+ * Returns packages and classes (source or classfile) that are members of `inPackage` (not
43+ * recursively). The `inPackage` string is a full package name, e.g., "scala.collection".
44+ *
45+ * This is the main method uses to find classes, see class `PackageLoader`. The
46+ * `rootMirror.rootLoader` is created with `inPackage = ""`.
47+ */
3248 private [nsc] def list (inPackage : String ): ClassPathEntries
3349
3450 /**
35- * It returns both classes from class file and source files (as our base ClassRepresentation).
36- * So note that it's not so strictly related to findClassFile.
37- */
51+ * Returns the class file and / or source file for a given external name, e.g., "java.lang.String".
52+ * If there is both a class file and source file, the compiler can decide whether to read the
53+ * class file or compile the source file.
54+ *
55+ * Internally this seems to be used only by `ScriptRunner`, but only to call `.isDefined`. That
56+ * could probably be implemented differently.
57+ *
58+ * Externally, it is used by sbt's compiler interface:
59+ * https://github.com/sbt/sbt/blob/v0.13.15/compile/interface/src/main/scala/xsbt/CompilerInterface.scala#L249
60+ * Jason has some improvements for that in the works (https://github.com/scala/bug/issues/10289#issuecomment-310022699)
61+ */
3862 def findClass (className : String ): Option [ClassRepresentation ] = {
3963 // A default implementation which should be overridden, if we can create the more efficient
4064 // solution for a given type of ClassPath
@@ -45,6 +69,16 @@ trait ClassPath {
4569
4670 foundClassFromClassFiles orElse findClassInSources
4771 }
72+
73+ /**
74+ * Returns the classfile for an external name, e.g., "java.lang.String". This method does not
75+ * return source files.
76+ *
77+ * This method is used by the classfile parser. When parsing a Java class, its own inner classes
78+ * are entered with a `ClassfileLoader` that parses the classfile returned by this method.
79+ * It is also used in the backend, by the inliner, to obtain the bytecode when inlining from the
80+ * classpath. It's also used by scalap.
81+ */
4882 def findClassFile (className : String ): Option [AbstractFile ]
4983
5084 def asClassPathStrings : Seq [String ]
0 commit comments