diff options
author | Martin Odersky <odersky@gmail.com> | 2014-01-19 12:09:23 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2014-01-19 12:09:23 +0100 |
commit | d4204733c669ce4b198d9078f84d6617633c6d4f (patch) | |
tree | 7235b09b900df0b008c9569454038419d3e99321 /tests | |
parent | f11dea6fc2eed56bee3eb1999c3890aae958e897 (diff) | |
download | dotty-d4204733c669ce4b198d9078f84d6617633c6d4f.tar.gz dotty-d4204733c669ce4b198d9078f84d6617633c6d4f.tar.bz2 dotty-d4204733c669ce4b198d9078f84d6617633c6d4f.zip |
Refinement of fully-defined accumulator.
It needs to follow type aliases in order not to give false indications what variables are contained in a type.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/pos/dotctest.scala | 178 | ||||
-rw-r--r-- | tests/pos/test.scala | 13 |
2 files changed, 24 insertions, 167 deletions
diff --git a/tests/pos/dotctest.scala b/tests/pos/dotctest.scala index 42efc7e06..0fcb13307 100644 --- a/tests/pos/dotctest.scala +++ b/tests/pos/dotctest.scala @@ -1,172 +1,34 @@ /* NSC -- new Scala compiler * Copyright 2005-2012 LAMP/EPFL - * @author Paul Phillips + * @author Paul Phillips */ - package dotty.tools package io -import java.io.{ InputStream, OutputStream, IOException, FileNotFoundException, FileInputStream, DataOutputStream } -import java.util.jar._ -import scala.collection.JavaConverters._ -import Attributes.Name -import scala.language.{postfixOps, implicitConversions} - -// Attributes.Name instances: -// -// static Attributes.Name CLASS_PATH -// static Attributes.Name CONTENT_TYPE -// static Attributes.Name EXTENSION_INSTALLATION -// static Attributes.Name EXTENSION_LIST -// static Attributes.Name EXTENSION_NAME -// static Attributes.Name IMPLEMENTATION_TITLE -// static Attributes.Name IMPLEMENTATION_URL -// static Attributes.Name IMPLEMENTATION_VENDOR -// static Attributes.Name IMPLEMENTATION_VENDOR_ID -// static Attributes.Name IMPLEMENTATION_VERSION -// static Attributes.Name MAIN_CLASS -// static Attributes.Name MANIFEST_VERSION -// static Attributes.Name SEALED -// static Attributes.Name SIGNATURE_VERSION -// static Attributes.Name SPECIFICATION_TITLE -// static Attributes.Name SPECIFICATION_VENDOR -// static Attributes.Name SPECIFICATION_VERSION - -class Jar(file: File) extends Iterable[JarEntry] { - def this(jfile: JFile) = this(File(jfile)) - def this(path: String) = this(File(path)) - - protected def errorFn(msg: String): Unit = Console println msg - - lazy val jarFile = new JarFile(file.jfile) - lazy val manifest = withJarInput(s => Option(s.getManifest)) - - def mainClass = manifest map (f => f(Name.MAIN_CLASS)) - /** The manifest-defined classpath String if available. */ - def classPathString: Option[String] = - for (m <- manifest ; cp <- m.attrs get Name.CLASS_PATH) yield cp - def classPathElements: List[String] = classPathString match { - case Some(s) => s split "\\s+" toList - case _ => Nil - } - - def withJarInput[T](f: JarInputStream => T): T = { - val in = new JarInputStream(file.inputStream()) - try f(in) - finally in.close() - } - def jarWriter(mainAttrs: (Attributes.Name, String)*) = { - new JarWriter(file, Jar.WManifest(mainAttrs: _*).underlying) - } - - override def foreach[U](f: JarEntry => U): Unit = withJarInput { in => - Iterator continually in.getNextJarEntry() takeWhile (_ != null) foreach f - } - override def iterator: Iterator[JarEntry] = this.toList.iterator - def fileishIterator: Iterator[Fileish] = jarFile.entries.asScala map (x => Fileish(x, () => getEntryStream(x))) - - private def getEntryStream(entry: JarEntry) = jarFile getInputStream entry match { - case null => errorFn("No such entry: " + entry) ; null - case x => x - } - override def toString = "" + file -} - -class JarWriter(val file: File, val manifest: Manifest) { - private lazy val out = new JarOutputStream(file.outputStream(), manifest) +import java.io.{ InputStream } +import java.util.jar.JarEntry +import language.postfixOps - /** Adds a jar entry for the given path and returns an output - * stream to which the data should immediately be written. - * This unusual interface exists to work with fjbg. - */ - def newOutputStream(path: String): DataOutputStream = { - val entry = new JarEntry(path) - out putNextEntry entry - new DataOutputStream(out) - } +/** A common interface for File-based things and Stream-based things. + * (In particular, io.File and JarEntry.) + */ +class Fileish(val path: Path, val input: () => InputStream) extends Streamable.Chars { + def inputStream() = input() - def writeAllFrom(dir: Directory): Unit = { - try dir.list foreach (x => addEntry(x, "")) - finally out.close() - } - def addStream(entry: JarEntry, in: InputStream): Unit = { - out putNextEntry entry - try transfer(in, out) - finally out.closeEntry() - } - def addFile(file: File, prefix: String): Unit = { - val entry = new JarEntry(prefix + file.name) - addStream(entry, file.inputStream()) - } - def addEntry(entry: Path, prefix: String): Unit = { - if (entry.isFile) addFile(entry.toFile, prefix) - else addDirectory(entry.toDirectory, prefix + entry.name + "/") - } - def addDirectory(entry: Directory, prefix: String): Unit = { - entry.list foreach (p => addEntry(p, prefix)) - } + def parent = path.parent + def name = path.name + def isSourceFile = path.hasExtension("java", "scala") - private def transfer(in: InputStream, out: OutputStream) = { - val buf = new Array[Byte](10240) - def loop(): Unit = in.read(buf, 0, buf.length) match { - case -1 => in.close() - case n => out.write(buf, 0, n) ; loop - } - loop - } + private lazy val pkgLines = lines() collect { case x if x startsWith "package " => x stripPrefix "package" trim } + lazy val pkgFromPath = parent.path.replaceAll("""[/\\]""", ".") + lazy val pkgFromSource = pkgLines map (_ stripSuffix ";") mkString "." - def close() = out.close() + override def toString = path.path } -object Jar { - type AttributeMap = java.util.Map[Attributes.Name, String] - - object WManifest { - def apply(mainAttrs: (Attributes.Name, String)*): WManifest = { - val m = WManifest(new JManifest) - for ((k, v) <- mainAttrs) - m(k) = v - - m - } - def apply(manifest: JManifest): WManifest = new WManifest(manifest) - implicit def unenrichManifest(x: WManifest): JManifest = x.underlying - } - class WManifest(manifest: JManifest) { - for ((k, v) <- initialMainAttrs) - this(k) = v - - def underlying = manifest - def attrs = manifest.getMainAttributes().asInstanceOf[AttributeMap].asScala withDefaultValue null - def initialMainAttrs: Map[Attributes.Name, String] = { - import scala.util.Properties._ - Map( - Name.MANIFEST_VERSION -> "1.0", - ScalaCompilerVersion -> versionNumberString - ) - } - - def apply(name: Attributes.Name): String = attrs(name) - def apply(name: String): String = apply(new Attributes.Name(name)) - def update(key: Attributes.Name, value: String) = attrs.put(key, value) - def update(key: String, value: String) = attrs.put(new Attributes.Name(key), value) - - def mainClass: String = apply(Name.MAIN_CLASS) - def mainClass_=(value: String) = update(Name.MAIN_CLASS, value) - } - - // See http://download.java.net/jdk7/docs/api/java/nio/file/Path.html - // for some ideas. - private val ZipMagicNumber = List[Byte](80, 75, 3, 4) - private def magicNumberIsZip(f: Path) = f.isFile && (f.toFile.bytes().take(4).toList == ZipMagicNumber) - - def isJarOrZip(f: Path): Boolean = isJarOrZip(f, true) - def isJarOrZip(f: Path, examineFile: Boolean): Boolean = - f.hasExtension("zip", "jar") || (examineFile && magicNumberIsZip(f)) - - def create(file: File, sourceDir: Directory, mainClass: String): Unit = { - val writer = new Jar(file).jarWriter(Name.MAIN_CLASS -> mainClass) - writer writeAllFrom sourceDir - } +object Fileish { + def apply(f: File): Fileish = new Fileish(f, () => f.inputStream()) + def apply(f: JarEntry, in: () => InputStream): Fileish = new Fileish(Path(f.getName), in) + def apply(path: String, in: () => InputStream): Fileish = new Fileish(Path(path), in) } diff --git a/tests/pos/test.scala b/tests/pos/test.scala index 403ea9704..b614afa70 100644 --- a/tests/pos/test.scala +++ b/tests/pos/test.scala @@ -1,12 +1,7 @@ object test { - - val x = 2 - val y: Int = math.abs(x) - - val xs = List((1, "a"), (2, "b")) - - def write(x: String) = ??? - def write(xs: (Int, String)*) = ??? - write(xs: _*) + object foo extends scala.reflect.io.Streamable.Chars { + val lns = lines() + val pkgLines = lns collect { case x if x startsWith "package " => x stripPrefix "package" trim } + } }
\ No newline at end of file |