diff options
author | Paul Phillips <paulp@improving.org> | 2009-11-18 00:18:58 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2009-11-18 00:18:58 +0000 |
commit | ac3931a11d681a35fd4b96717aabe1258067edfc (patch) | |
tree | a173580a819208533a2810c055271a56bc7565f1 /src/library | |
parent | 32b04c2801b1eb24e28fe4deafe62c995472e957 (diff) | |
download | scala-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
Diffstat (limited to 'src/library')
-rw-r--r-- | src/library/scala/net/Utility.scala | 23 | ||||
-rw-r--r-- | src/library/scala/reflect/Invocation.scala | 134 | ||||
-rw-r--r-- | src/library/scala/reflect/RichClass.scala | 93 | ||||
-rw-r--r-- | src/library/scala/util/Hashable.scala | 62 | ||||
-rw-r--r-- | src/library/scala/util/ScalaClassLoader.scala | 92 | ||||
-rw-r--r-- | src/library/scala/xml/Attribute.scala | 1 | ||||
-rw-r--r-- | src/library/scala/xml/HasKeyValue.scala | 1 |
7 files changed, 1 insertions, 405 deletions
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/util/ScalaClassLoader.scala b/src/library/scala/util/ScalaClassLoader.scala deleted file mode 100644 index 3393f0413f..0000000000 --- a/src/library/scala/util/ScalaClassLoader.scala +++ /dev/null @@ -1,92 +0,0 @@ -/* NSC -- new Scala compiler - * Copyright 2005-2009 LAMP/EPFL - * @author Paul Phillips - */ - -package scala.util - -import java.lang.{ ClassLoader => JavaClassLoader } -import java.lang.reflect.{ Constructor, Modifier, Method } -import java.net.URL -import ScalaClassLoader._ -import scala.util.control.Exception.{ catching } - -trait ScalaClassLoader extends JavaClassLoader -{ - /** Executing an action with this classloader as context classloader */ - def asContext[T](action: => T): T = { - val oldLoader = getContextLoader - try { - setContextLoader(this) - action - } - finally setContextLoader(oldLoader) - } - def setAsContext() { setContextLoader(this) } - - /** Load and link a class with this classloader */ - def tryToLoadClass[T <: AnyRef](path: String): Option[Class[T]] = tryClass(path, false) - /** Load, link and initialize a class with this classloader */ - def tryToInitializeClass[T <: AnyRef](path: String): Option[Class[T]] = tryClass(path, true) - - private def tryClass[T <: AnyRef](path: String, initialize: Boolean): Option[Class[T]] = - catching(classOf[ClassNotFoundException], classOf[SecurityException]) opt - Class.forName(path, initialize, this).asInstanceOf[Class[T]] - - /** Create an instance of a class with this classloader */ - def create(path: String): AnyRef = { - tryToInitializeClass(path) match { - case Some(clazz) => clazz.newInstance() - case None => null - } - } - - /** Run the main method of a class to be loaded by this classloader */ - def run(objectName: String, arguments: Seq[String]) { - val clsToRun = tryToInitializeClass(objectName) getOrElse ( - throw new ClassNotFoundException(objectName) - ) - - val method = clsToRun.getMethod("main", classOf[Array[String]]) - if (!Modifier.isStatic(method.getModifiers)) - throw new NoSuchMethodException(objectName + ".main is not static") - - asContext(method.invoke(null, Array(arguments.toArray: AnyRef): _*)) // !!! : AnyRef shouldn't be necessary - } -} - -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 { - def setContextLoader(cl: JavaClassLoader) = Thread.currentThread.setContextClassLoader(cl) - def getContextLoader() = Thread.currentThread.getContextClassLoader() - def getSystemLoader() = JavaClassLoader.getSystemClassLoader() - def defaultParentClassLoader() = findExtClassLoader() - - def fromURLs(urls: Seq[URL]): URLClassLoader = - new URLClassLoader(urls.toList, defaultParentClassLoader()) - - /** True if supplied class exists in supplied path */ - def classExists(urls: Seq[URL], name: String): Boolean = - (fromURLs(urls) tryToLoadClass name).isDefined - - // we cannot use the app classloader here or we get what looks to - // be classloader deadlock, but if we pass null we bypass the extension - // classloader and our extensions, so we search the hierarchy to find - // the classloader whose parent is null. Resolves bug #857. - def findExtClassLoader(): JavaClassLoader = { - def search(cl: JavaClassLoader): JavaClassLoader = { - if (cl == null) null - else if (cl.getParent == null) cl - else search(cl.getParent) - } - - search(getContextLoader()) - } -} 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) } |