diff options
author | Guillaume Martres <smarter@ubuntu.com> | 2017-04-05 00:10:30 +0200 |
---|---|---|
committer | Guillaume Martres <smarter@ubuntu.com> | 2017-04-11 16:04:31 +0200 |
commit | 2b04d2a96100fad5fc88b78b6b4094ae6ae25a37 (patch) | |
tree | ba9741bab0d92d9bf92853385d5d0c207e01f16e /compiler/src/dotty/tools/dotc/classpath/ClassPath.scala | |
parent | 92a9d05fd64ac97140aa0f01214c4738526383c3 (diff) | |
download | dotty-2b04d2a96100fad5fc88b78b6b4094ae6ae25a37.tar.gz dotty-2b04d2a96100fad5fc88b78b6b4094ae6ae25a37.tar.bz2 dotty-2b04d2a96100fad5fc88b78b6b4094ae6ae25a37.zip |
Fix #2186: Synchronize classpath handling with Scala 2.12
This commit is a very crude port of the classpath handling as it exists
in the 2.12.x branch of scalac (hash: 232d95a198c94da0c6c8393624e83e9b9ac84e81),
this replaces the existing Classpath code that was adapted from scalac
years ago.
This code was written by Grzegorz Kossakowski, MichaĆ Pociecha, Lukas
Rytz, Jason Zaugg and other scalac contributors, many thanks to them!
For more information on this implementation, see the description of the
PR that originally added it to scalac: https://github.com/scala/scala/pull/4060
Changes made to the copied code to get it to compile with dotty:
- Rename scala.tools.nsc.util.ClassPath to dotty.tools.io.ClassPath
- Rename scala.tools.nsc.classpath.* to dotty.tools.dotc.classpath.*
- Replace "private[nsc]" by "private[dotty]"
- Changed `isClass` methods in FileUtils to skip Scala 2.11
implementation classes (needed until we stop being retro-compatible with
Scala 2.11)
I also copied PlainFile.scala from scalac to get access to
`PlainNioFile`.
Diffstat (limited to 'compiler/src/dotty/tools/dotc/classpath/ClassPath.scala')
-rw-r--r-- | compiler/src/dotty/tools/dotc/classpath/ClassPath.scala | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/compiler/src/dotty/tools/dotc/classpath/ClassPath.scala b/compiler/src/dotty/tools/dotc/classpath/ClassPath.scala new file mode 100644 index 000000000..129c6b9fe --- /dev/null +++ b/compiler/src/dotty/tools/dotc/classpath/ClassPath.scala @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2014 Contributor. All rights reserved. + */ +package dotty.tools.dotc.classpath + +import scala.reflect.io.AbstractFile +import dotty.tools.io.ClassRepresentation + +case class ClassPathEntries(packages: Seq[PackageEntry], classesAndSources: Seq[ClassRepresentation]) + +object ClassPathEntries { + import scala.language.implicitConversions + // to have working unzip method + implicit def entry2Tuple(entry: ClassPathEntries): (Seq[PackageEntry], Seq[ClassRepresentation]) = (entry.packages, entry.classesAndSources) +} + +trait ClassFileEntry extends ClassRepresentation { + def file: AbstractFile +} + +trait SourceFileEntry extends ClassRepresentation { + def file: AbstractFile +} + +trait PackageEntry { + def name: String +} + +private[dotty] case class ClassFileEntryImpl(file: AbstractFile) extends ClassFileEntry { + override def name = FileUtils.stripClassExtension(file.name) // class name + + override def binary: Option[AbstractFile] = Some(file) + override def source: Option[AbstractFile] = None +} + +private[dotty] case class SourceFileEntryImpl(file: AbstractFile) extends SourceFileEntry { + override def name = FileUtils.stripSourceExtension(file.name) + + override def binary: Option[AbstractFile] = None + override def source: Option[AbstractFile] = Some(file) +} + +private[dotty] case class ClassAndSourceFilesEntry(classFile: AbstractFile, srcFile: AbstractFile) extends ClassRepresentation { + override def name = FileUtils.stripClassExtension(classFile.name) + + override def binary: Option[AbstractFile] = Some(classFile) + override def source: Option[AbstractFile] = Some(srcFile) +} + +private[dotty] case class PackageEntryImpl(name: String) extends PackageEntry + +private[dotty] trait NoSourcePaths { + def asSourcePathString: String = "" + private[dotty] def sources(inPackage: String): Seq[SourceFileEntry] = Seq.empty +} + +private[dotty] trait NoClassPaths { + def findClassFile(className: String): Option[AbstractFile] = None + private[dotty] def classes(inPackage: String): Seq[ClassFileEntry] = Seq.empty +} |