summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2009-11-18 00:18:58 +0000
committerPaul Phillips <paulp@improving.org>2009-11-18 00:18:58 +0000
commitac3931a11d681a35fd4b96717aabe1258067edfc (patch)
treea173580a819208533a2810c055271a56bc7565f1
parent32b04c2801b1eb24e28fe4deafe62c995472e957 (diff)
downloadscala-ac3931a11d681a35fd4b96717aabe1258067edfc.tar.gz
scala-ac3931a11d681a35fd4b96717aabe1258067edfc.tar.bz2
scala-ac3931a11d681a35fd4b96717aabe1258067edfc.zip
Removing bits from the library which shouldn't ...
Removing bits from the library which shouldn't make the 2.8 cut. Removed outright: util.Hashable: unused and I have a better plan for this net.Utility: class created to accomodate expansion which never materialized reflect.Invocation: doesn't go far enough, needs love it won't find right now reflect.RichClass: same as Invocation Moved into compiler: util.ScalaClassLoader: too useful to lose, not done enough to ship
-rw-r--r--src/compiler/scala/tools/ant/sabbus/Compiler.scala2
-rw-r--r--src/compiler/scala/tools/nsc/Interpreter.scala10
-rw-r--r--src/compiler/scala/tools/nsc/MainGenericRunner.scala3
-rw-r--r--src/compiler/scala/tools/nsc/ObjectRunner.scala2
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/AbstractFileClassLoader.scala2
-rw-r--r--src/compiler/scala/tools/nsc/util/ScalaClassLoader.scala (renamed from src/library/scala/util/ScalaClassLoader.scala)17
-rw-r--r--src/library/scala/net/Utility.scala23
-rw-r--r--src/library/scala/reflect/Invocation.scala134
-rw-r--r--src/library/scala/reflect/RichClass.scala93
-rw-r--r--src/library/scala/util/Hashable.scala62
-rw-r--r--src/library/scala/xml/Attribute.scala1
-rw-r--r--src/library/scala/xml/HasKeyValue.scala1
12 files changed, 21 insertions, 329 deletions
diff --git a/src/compiler/scala/tools/ant/sabbus/Compiler.scala b/src/compiler/scala/tools/ant/sabbus/Compiler.scala
index 787c6af870..f6372f741a 100644
--- a/src/compiler/scala/tools/ant/sabbus/Compiler.scala
+++ b/src/compiler/scala/tools/ant/sabbus/Compiler.scala
@@ -13,7 +13,7 @@ package scala.tools.ant.sabbus
import java.io.File
import java.net.URL
import java.lang.reflect.InvocationTargetException
-import scala.util.ScalaClassLoader
+import scala.tools.nsc.util.ScalaClassLoader
class Compiler(classpath: Array[URL], val settings: Settings)
{
diff --git a/src/compiler/scala/tools/nsc/Interpreter.scala b/src/compiler/scala/tools/nsc/Interpreter.scala
index 489ab1a3e0..77436fe55f 100644
--- a/src/compiler/scala/tools/nsc/Interpreter.scala
+++ b/src/compiler/scala/tools/nsc/Interpreter.scala
@@ -15,7 +15,8 @@ import reflect.InvocationTargetException
import scala.collection.immutable.ListSet
import scala.collection.mutable
import scala.collection.mutable.{ ListBuffer, HashSet, ArrayBuffer }
-import scala.util.{ ScalaClassLoader, URLClassLoader }
+import scala.tools.nsc.util.ScalaClassLoader
+import ScalaClassLoader.URLClassLoader
import scala.util.control.Exception.{ Catcher, catching, ultimately, unwrapping }
import io.{ PlainFile, VirtualDirectory }
@@ -119,11 +120,14 @@ class Interpreter(val settings: Settings, out: PrintWriter)
/** the compiler's classpath, as URL's */
val compilerClasspath: List[URL] = {
- import scala.net.Utility.parseURL
+ def parseURL(s: String): Option[URL] =
+ catching(classOf[MalformedURLException]) opt new URL(s)
+
val classpathPart =
ClassPath.expandPath(compiler.settings.classpath.value).map(s => new File(s).toURL)
+ val codebasePart =
+ (compiler.settings.Xcodebase.value.split(" ")).toList flatMap parseURL
- val codebasePart = (compiler.settings.Xcodebase.value.split(" ")).toList flatMap parseURL
classpathPart ::: codebasePart
}
diff --git a/src/compiler/scala/tools/nsc/MainGenericRunner.scala b/src/compiler/scala/tools/nsc/MainGenericRunner.scala
index 9cd9cdbd43..0365f28dc3 100644
--- a/src/compiler/scala/tools/nsc/MainGenericRunner.scala
+++ b/src/compiler/scala/tools/nsc/MainGenericRunner.scala
@@ -11,9 +11,8 @@ import java.io.{ File, IOException }
import java.lang.{ClassNotFoundException, NoSuchMethodException}
import java.lang.reflect.InvocationTargetException
import java.net.{ URL, MalformedURLException }
-import scala.util.ScalaClassLoader
-import util.ClassPath
+import util.{ ClassPath, ScalaClassLoader }
import File.pathSeparator
import Properties.{ versionString, copyrightString }
diff --git a/src/compiler/scala/tools/nsc/ObjectRunner.scala b/src/compiler/scala/tools/nsc/ObjectRunner.scala
index e4e0826d32..282cff4987 100644
--- a/src/compiler/scala/tools/nsc/ObjectRunner.scala
+++ b/src/compiler/scala/tools/nsc/ObjectRunner.scala
@@ -8,7 +8,7 @@
package scala.tools.nsc
import java.net.URL
-import scala.util.ScalaClassLoader
+import util.ScalaClassLoader
/** An object that runs another object specified by name.
*
diff --git a/src/compiler/scala/tools/nsc/interpreter/AbstractFileClassLoader.scala b/src/compiler/scala/tools/nsc/interpreter/AbstractFileClassLoader.scala
index cf41852652..02df1d7318 100644
--- a/src/compiler/scala/tools/nsc/interpreter/AbstractFileClassLoader.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/AbstractFileClassLoader.scala
@@ -7,7 +7,7 @@ package scala.tools.nsc
package interpreter
import scala.tools.nsc.io.AbstractFile
-import scala.util.ScalaClassLoader
+import util.ScalaClassLoader
/**
* A class loader that loads files from a {@link scala.tools.nsc.io.AbstractFile}.
diff --git a/src/library/scala/util/ScalaClassLoader.scala b/src/compiler/scala/tools/nsc/util/ScalaClassLoader.scala
index 3393f0413f..fa1227a859 100644
--- a/src/library/scala/util/ScalaClassLoader.scala
+++ b/src/compiler/scala/tools/nsc/util/ScalaClassLoader.scala
@@ -3,7 +3,8 @@
* @author Paul Phillips
*/
-package scala.util
+package scala.tools.nsc
+package util
import java.lang.{ ClassLoader => JavaClassLoader }
import java.lang.reflect.{ Constructor, Modifier, Method }
@@ -55,15 +56,15 @@ trait ScalaClassLoader extends JavaClassLoader
}
}
-class URLClassLoader(urls: Seq[URL], parent: JavaClassLoader)
- extends java.net.URLClassLoader(urls.toArray, parent)
- with ScalaClassLoader
-{
- /** Override to widen to public */
- override def addURL(url: URL) = super.addURL(url)
-}
object ScalaClassLoader {
+ class URLClassLoader(urls: Seq[URL], parent: JavaClassLoader)
+ extends java.net.URLClassLoader(urls.toArray, parent)
+ with ScalaClassLoader {
+ /** Override to widen to public */
+ override def addURL(url: URL) = super.addURL(url)
+ }
+
def setContextLoader(cl: JavaClassLoader) = Thread.currentThread.setContextClassLoader(cl)
def getContextLoader() = Thread.currentThread.getContextClassLoader()
def getSystemLoader() = JavaClassLoader.getSystemClassLoader()
diff --git a/src/library/scala/net/Utility.scala b/src/library/scala/net/Utility.scala
deleted file mode 100644
index 59ce1c0ceb..0000000000
--- a/src/library/scala/net/Utility.scala
+++ /dev/null
@@ -1,23 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-package scala.net
-
-import java.net.{ URL, MalformedURLException }
-import scala.util.control.Exception._
-
-/**
- * Skeleton in anticipation of more convenience methods.
- *
- * @since 2.8
- */
-object Utility
-{
- def parseURL(s: String): Option[URL] =
- catching(classOf[MalformedURLException]) opt new URL(s)
-}
diff --git a/src/library/scala/reflect/Invocation.scala b/src/library/scala/reflect/Invocation.scala
deleted file mode 100644
index 795c74fef4..0000000000
--- a/src/library/scala/reflect/Invocation.scala
+++ /dev/null
@@ -1,134 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2002-2009, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-// $Id$
-
-
-package scala.reflect
-
-import scala.annotation.experimental
-import scala.util.control.Exception.catching
-import java.lang.{ Class => JClass }
-import java.lang.reflect.{ Method => JMethod }
-import scala.{ Symbol => ScalaSymbol }
-
-/** <p>
- * A more convenient syntax for reflective invocation.<br/>
- * Example usage:
- * </p><pre>
- * <b>class</b> Obj { <b>private def</b> foo(x: Int, y: String): Long = x + y.length }</pre>
- * <p>
- * You can call it reflectively one of two ways:
- * </p><pre>
- * <b>import</b> scala.reflect.Invocation._
- * (<b>new</b> Obj) o 'foo(5, "abc") // the 'o' method returns Any
- * <b>val</b> x: Long = (<b>new</b> Obj) oo 'foo(5, "abc") // the 'oo' method casts to expected type.</pre>
- * <p>
- * If you call the <code>oo</code> method and do not give the type inferencer
- * enough help, it will most likely infer <code>Nothing</code>, which will
- * result in a <code>ClassCastException</code>.
- * </p>
- *
- * @author Paul Phillips
- */
-@experimental
-object Invocation
-{
- /** <p>
- * In order to encapsulate anything to do with reflection, we must
- * overcome an issue with the boxing of primitives. If we declare a
- * method which takes arguments of type <code>Any</code>, by the time the
- * method parameters can be examined, the primitives have already been boxed.
- * The reflective call will then fail because <code>classOf[java.lang.Integer]</code>
- * is not the same thing as <code>classOf[scala.Int].</code>
- * </p>
- * <p>
- * Any useful workaround will require examining the arguments before
- * the method is called. The approach here is to define two implicits,
- * one for <code>AnyRef</code>'s and one for <code>AnyVal</code>'s, and
- * box them in a container which preserves their original class identity.
- * </p>
- */
- trait PrimitivePreserver[T] {
- val value: T
- val clazz: JClass[_]
- }
- case class PreservedAnyVal[T <: AnyVal](value: T) extends PrimitivePreserver[T] {
- val clazz = getAnyValClass(value)
- }
- case class PreservedAnyRef[T <: AnyRef](value: T) extends PrimitivePreserver[T] {
- val clazz = value.getClass
- }
- implicit def makePreservedAnyRef[T <: AnyRef](x: T) = PreservedAnyRef(x)
- implicit def makePreservedAnyVal[T <: AnyVal](x: T) = PreservedAnyVal(x)
-
- /** We also require an implicit on scala.Symbol so they appear to contain
- * an apply method, which packages the method arguments. The type parameter
- * is the method's expected result type.
- */
- class SymbolWithArguments(val sym: ScalaSymbol, val args: PrimitivePreserver[_]*) {
- def getArgs = args map (_.value.asInstanceOf[AnyRef])
- def getArgTypes = args.toList map (_.clazz)
- def argsMatch(m: JMethod) =
- List.map2(m.getParameterTypes.toList, getArgTypes)(_ isAssignableFrom _) forall (_ == true)
-
- // only called if getMethod() fails - searches private methods too.
- def getDeclaredMethodsOn(x: AnyRef) =
- (x.getClass.getDeclaredMethods filter (_.getName == sym.name) find argsMatch) match {
- case Some(m) => m setAccessible true ; m
- case None => throw new NoSuchMethodException(sym.name)
- }
-
- def getMethodOn(x: AnyRef) =
- catching(classOf[NoSuchMethodException]) .
- opt (x.getClass.getMethod(sym.name, getArgTypes: _*)) .
- getOrElse (getDeclaredMethodsOn(x))
-
- }
- class RichSymbol(sym: ScalaSymbol) {
- def apply(args: PrimitivePreserver[_]*): SymbolWithArguments =
- new SymbolWithArguments(sym, args: _*)
- }
- implicit def makeRichSymbol(sym: ScalaSymbol): RichSymbol = new RichSymbol(sym)
-
- /** An implicit on AnyRef provides it with the 'o' method, which is supposed
- * to look like a giant '.' and present the feel of method invocation.
- */
- class ReflectionOperators[T <: AnyRef](self: T) {
- val clazz = self.getClass.asInstanceOf[JClass[T]]
-
- /** Issue call without touching result - returns Any.
- */
- def o(sym: ScalaSymbol): Any = oo(new SymbolWithArguments(sym))
- def o(symApp: SymbolWithArguments): Any = oo(symApp)
-
- /** Issue call expecting return type R - casts result to R.
- */
- def oo[R](sym: ScalaSymbol): R = oo[R](new SymbolWithArguments(sym))
- def oo[R](symApp: SymbolWithArguments): R = {
- def method = symApp getMethodOn self
- method.invoke(self, symApp.getArgs: _*).asInstanceOf[R]
- }
- }
- implicit def makeReflectionOperators[T <: AnyRef](x: T): ReflectionOperators[T] =
- new ReflectionOperators(x)
-
- /** Obtain the class object for an <code>AnyVal</code>.
- */
- def getAnyValClass(x: AnyVal): JClass[_] = x match {
- case _: Byte => classOf[Byte]
- case _: Short => classOf[Short]
- case _: Int => classOf[Int]
- case _: Long => classOf[Long]
- case _: Float => classOf[Float]
- case _: Double => classOf[Double]
- case _: Char => classOf[Char]
- case _: Boolean => classOf[Boolean]
- case _: Unit => classOf[Unit]
- }
-}
diff --git a/src/library/scala/reflect/RichClass.scala b/src/library/scala/reflect/RichClass.scala
deleted file mode 100644
index 7d690f360d..0000000000
--- a/src/library/scala/reflect/RichClass.scala
+++ /dev/null
@@ -1,93 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2002-2009, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-// $Id$
-
-package scala.reflect
-
-import scala.annotation.experimental
-import scala.util.control.Exception._
-import scala.util.ScalaClassLoader._
-import java.lang.{ Class => JClass }
-import java.lang.reflect. { Constructor => JConstructor }
-
-object RichClass
-{
- // We can't put this in Predef at the moment because everything referenced
- // from Predef has to be buildable at the first bootstraping phase.
- implicit def classWrapper[T](x: JClass[T]): RichClass[T] = new RichClass(x)
-}
-
-@experimental
-final class RichClass[T](val self: JClass[T]) extends Proxy
-{
- // The getConstructors and getDeclaredConstructors methods on java.lang.Class[T]
- // return "raw type" Constructors rather than Constructor[T]s as one would want.
- // The "why" from http://java.sun.com/javase/6/docs/api/java/lang/Class.html is:
- //
- // Note that while this method returns an array of Constructor<T> objects (that is an array
- // of constructors from this class), the return type of this method is Constructor<?>[] and
- // not Constructor<T>[] as might be expected. This less informative return type is necessary
- // since after being returned from this method, the array could be modified to hold Constructor
- // objects for different classes, which would violate the type guarantees of Constructor<T>[]
- //
- // Since this reasoning is invalid in scala due to its abandonment of Array covariance,
- // these methods exist to correct the return types.
- //
- // In addition, at this writing because of ticket #1560 the compiler crashes on the
- // untyped constructors but not on these.
-
- def getConstructorsTyped(): Array[JConstructor[T]] =
- self.getConstructors() map (_.asInstanceOf[JConstructor[T]])
-
- def getDeclaredConstructorsTyped(): Array[JConstructor[T]] =
- self.getDeclaredConstructors() map (_.asInstanceOf[JConstructor[T]])
-
- private lazy val classLoader = self.getClassLoader match {
- case null => getSystemLoader
- case x => x
- }
- private val exceptions = List(
- classOf[ClassNotFoundException],
- classOf[NoSuchMethodException],
- classOf[SecurityException],
- classOf[NullPointerException],
- classOf[ClassCastException]
- )
-
- // Experimental!
- // scala> classOf[String].reflectiveCall[Array[String]]("ababab", "split")("b")
- // res0: Array[String] = Array(a, a, a)
-
- /** A class representing a reflective method call. It is a function object
- * and will make the call with whatever args are given via apply, or it will
- * throw an exception at that point if there was an error in creation.
- */
- class ReflectiveCall[+U](obj: T, name: String) {
- def methodForArgs(args: AnyRef*) = self.getMethod(name, args map (_.getClass) : _*)
- def isErroneous = false
- def apply(args: Any*): U = {
- val ps = args map (_.asInstanceOf[AnyRef])
- val m = methodForArgs(ps: _*)
- m.invoke(obj, ps: _*).asInstanceOf[U]
- }
- }
-
- class FailedReflectiveCall[+U](ex: Throwable) extends ReflectiveCall[U](null.asInstanceOf[T], null) {
- override def isErroneous = true
- override def apply(args: Any*) = throw ex
- }
-
- def reflectiveCall[U](obj: T, method: String): ReflectiveCall[U] = {
- (catching(exceptions: _*) either (new ReflectiveCall[U](obj, method))) match {
- case Left(x) => new FailedReflectiveCall[U](x)
- case Right(x) => x
- }
- }
-}
-
diff --git a/src/library/scala/util/Hashable.scala b/src/library/scala/util/Hashable.scala
deleted file mode 100644
index 117d749316..0000000000
--- a/src/library/scala/util/Hashable.scala
+++ /dev/null
@@ -1,62 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-// $Id$
-
-
-package scala.util
-
-/** <p>
- * A convenience trait for simplifying hashCode creation.
- * Mix this into a class and define <code>val hashValues = Seq(x1, x2, ...)</code>
- * and your <code>hashCode</code> will be derived from those values.
- * If you define <code>equals</code> in terms of <code>equalHashValues</code>
- * then your <code>hashCode</code> and <code>equals</code> methods will
- * never be out of sync. Something like:
- * </p><pre>
- * <b>override def</b> equals(other: Any) = other <b>match</b> {
- * <b>case</b> x: YourClass => <b>this</b> equalHashValues x
- * <b>case</b> _ => <b>false</b>
- * }</pre>
- *
- * @author Paul Phillips
- */
-abstract trait Hashable extends AnyRef
-{
- import Hashable._
- protected def hashValues: Seq[Any] // in an ideal universe this would be more like Seq[Hashable]
- protected def hashSeed: Int = 1
-
- override def hashCode: Int =
- (hashValues map calculateHashCode).foldLeft(hashSeed)((x, y) => x * 41 + y)
-
- protected def equalHashValues(other: Any) = other match {
- case x: Hashable => hashValues sameElements x.hashValues
- case _ => false
- }
-}
-abstract trait StrictHashable extends Hashable
-{
- protected def hashValues: Seq[Hashable]
-}
-
-object Hashable
-{
- /** This implicit is for StrictHashable's benefit, so your hashValues Seq
- * can contain both explicitly Hashable classes and value types.
- */
- implicit def anyVal2Hashable(x: AnyVal): Hashable =
- new Hashable { protected def hashValues = Seq(x) }
-
- private def calculateHashCode(x: Any) = x match {
- case null => 0
- case x: AnyRef => x.hashCode
- case x => x.asInstanceOf[AnyRef].hashCode
- }
-}
-
diff --git a/src/library/scala/xml/Attribute.scala b/src/library/scala/xml/Attribute.scala
index 222642fe47..2f3856ed89 100644
--- a/src/library/scala/xml/Attribute.scala
+++ b/src/library/scala/xml/Attribute.scala
@@ -13,7 +13,6 @@ package scala.xml
import collection.Seq
import collection.mutable.StringBuilder
-
/** Attribute defines the interface shared by both
* PrefixedAttribute and UnprefixedAttribute
*/
diff --git a/src/library/scala/xml/HasKeyValue.scala b/src/library/scala/xml/HasKeyValue.scala
index 0522924270..6f98d0ed3b 100644
--- a/src/library/scala/xml/HasKeyValue.scala
+++ b/src/library/scala/xml/HasKeyValue.scala
@@ -20,6 +20,7 @@ package scala.xml
*
* @author Burak Emir
*/
+@deprecated("Use UnprefixedAttribute's extractor")
class HasKeyValue(key: String) {
def unapplySeq(x: MetaData): Option[Seq[Node]] = x.get(key)
}