diff options
author | michelou <michelou@epfl.ch> | 2011-04-29 19:41:12 +0000 |
---|---|---|
committer | michelou <michelou@epfl.ch> | 2011-04-29 19:41:12 +0000 |
commit | 80bb9cfb7b2c05a48eb43852b252c36136697835 (patch) | |
tree | 0f1db7dd77ed01a536a370035c5a3f6dd5936f3b | |
parent | f335e447254c391726d52c0a380b61183571b25b (diff) | |
download | scala-80bb9cfb7b2c05a48eb43852b252c36136697835.tar.gz scala-80bb9cfb7b2c05a48eb43852b252c36136697835.tar.bz2 scala-80bb9cfb7b2c05a48eb43852b252c36136697835.zip |
removed legacy library code (package scala.mobile)
-rw-r--r-- | docs/examples/mobile/sort.scala | 17 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/parser/Parsers.scala | 6 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala | 11 | ||||
-rw-r--r-- | src/library/scala/mobile/Code.scala | 234 | ||||
-rw-r--r-- | src/library/scala/mobile/Location.scala | 72 |
5 files changed, 9 insertions, 331 deletions
diff --git a/docs/examples/mobile/sort.scala b/docs/examples/mobile/sort.scala deleted file mode 100644 index b0bfe43a54..0000000000 --- a/docs/examples/mobile/sort.scala +++ /dev/null @@ -1,17 +0,0 @@ -package examples.mobile - -import java.net._ -import scala.mobile._ - - -object sort extends Application { - val url = new URL("http://scala.epfl.ch/classes/examples.jar") - - val location = new Location(url) - val obj = location create "examples.sort" - val ar = Array(6, 2, 8, 5, 1) - obj[Array[Int], Unit]("println")(ar) - obj[Array[Int], Unit]("sort")(ar) - obj[Array[Int], Unit]("println")(ar) - Console.println -} diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala index 38392e5dd6..84959d04ac 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala @@ -2188,12 +2188,12 @@ self => } /** Def ::= val PatDef - * | var VarDef + * | var PatDef * | def FunDef * | type [nl] TypeDef * | TmplDef - * Dcl ::= val ValDcl - * | var ValDcl + * Dcl ::= val PatDcl + * | var PatDcl * | def FunDcl * | type [nl] TypeDcl */ diff --git a/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala b/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala index d1214d8fe4..810d3e7497 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala @@ -67,8 +67,8 @@ abstract class TreeBuilder { } /** Traverse pattern and collect all variable names with their types in buffer - * The variables keep their positions; whereas the pattern is converted to be synthetic - * for all nodes that contain a variable position. + * The variables keep their positions; whereas the pattern is converted to be + * synthetic for all nodes that contain a variable position. */ class GetVarTraverser extends Traverser { val buf = new ListBuffer[(Name, Tree, Position)] @@ -149,7 +149,8 @@ abstract class TreeBuilder { case _ => t } - def makeAnnotated(t: Tree, annot: Tree): Tree = atPos(annot.pos union t.pos)(Annotated(annot, t)) + def makeAnnotated(t: Tree, annot: Tree): Tree = + atPos(annot.pos union t.pos)(Annotated(annot, t)) def makeSelfDef(name: TermName, tpt: Tree): ValDef = ValDef(Modifiers(PRIVATE), name, tpt, EmptyTree) @@ -261,7 +262,7 @@ abstract class TreeBuilder { /** Create tree for for-comprehension generator <val pat0 <- rhs0> */ def makeGenerator(pos: Position, pat: Tree, valeq: Boolean, rhs: Tree): Enumerator = { - val pat1 = patvarTransformer.transform(pat); + val pat1 = patvarTransformer.transform(pat) val rhs1 = if (valeq) rhs else matchVarPattern(pat1) match { @@ -582,7 +583,7 @@ abstract class TreeBuilder { } var cnt = 0 val restDefs = for ((vname, tpt, pos) <- vars) yield atPos(pos) { - cnt = cnt + 1 + cnt += 1 ValDef(mods, vname.toTermName, tpt, Select(Ident(tmp), newTermName("_" + cnt))) } firstDef :: restDefs diff --git a/src/library/scala/mobile/Code.scala b/src/library/scala/mobile/Code.scala deleted file mode 100644 index b25a36a04f..0000000000 --- a/src/library/scala/mobile/Code.scala +++ /dev/null @@ -1,234 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2002-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.mobile - - -import java.lang.reflect.{Constructor, Method, Modifier} -import java.lang.NoSuchMethodException - -/** The class <code>Code</code> provides <code>apply</code> methods - * with different arities (actually up to 9 parameters) to invoke - * a function simply by specifying its name and argument types.<p/> - * - * Example:<pre> - * <b>val</b> url = <b>new</b> URL("http://scala-lang.org/classes/examples.jar"); - * <b>val</b> obj = <b>new</b> Location(url) create "examples.sort"; - * <b>val</b> ar = Array(6, 2, 8, 5, 1); - * obj[Array[Int], Unit]("println")(ar); - * obj[Array[Int], Unit]("sort")(ar); - * obj[Array[Int], Unit]("println")(ar);</pre> - * - * @see <a href="Location.html">Location</a> - * - * @author Stephane Micheloud - * @version 1.0, 04/05/2004 - */ -class Code(clazz: java.lang.Class[_]) { - - private type JObject = java.lang.Object - - private var instance: JObject = _ - - ///////////////////////////// apply methods /////////////////////////////// - - type AnyClass = Class[T] forSome { type T } - - def apply[R](funName: String) = - () => { - val args = Array[JObject]() - val types = Array[AnyClass]() - applyFun(funName, args, types).asInstanceOf[R] - } - - def apply[A0, R](funName: String) = - (_0: A0) => { - val p = boxValue(_0) - val args = Array(p._1) - val types = Array[AnyClass](p._2) - applyFun(funName, args, types).asInstanceOf[R] - } - - def apply[A0, A1, R](funName: String) = - (_0: A0, _1: A1) => { - val p0 = boxValue(_0) - val p1 = boxValue(_1) - val args = Array(p0._1, p1._1) - val types = Array[AnyClass](p0._2, p1._2) - applyFun(funName, args, types).asInstanceOf[R] - } - - def apply[A0, A1, A2, R](funName: String) = - (_0: A0, _1: A1, _2: A2) => { - val p0 = boxValue(_0) - val p1 = boxValue(_1) - val p2 = boxValue(_2) - val args = Array(p0._1, p1._1, p2._1) - val types = Array[AnyClass](p0._2, p1._2, p2._2) - applyFun(funName, args, types).asInstanceOf[R] - } - - def apply[A0, A1, A2, A3, R](funName: String) = - (_0: A0, _1: A1, _2: A2, _3: A3) => { - val p0 = boxValue(_0) - val p1 = boxValue(_1) - val p2 = boxValue(_2) - val p3 = boxValue(_3) - val args = Array(p0._1, p1._1, p2._1, p3._1) - val types = Array[AnyClass](p0._2, p1._2, p2._2, p3._2) - applyFun(funName, args, types).asInstanceOf[R] - } - - def apply[A0, A1, A2, A3, A4, R](funName: String) = - (_0: A0, _1: A1, _2: A2, _3: A3, _4: A4) => { - val p0 = boxValue(_0) - val p1 = boxValue(_1) - val p2 = boxValue(_2) - val p3 = boxValue(_3) - val p4 = boxValue(_4) - val args = Array(p0._1, p1._1, p2._1, p3._1, p4._1) - val types = Array[AnyClass](p0._2, p1._2, p2._2, p3._2, p4._2) - applyFun(funName, args, types).asInstanceOf[R] - } - - def apply[A0, A1, A2, A3, A4, A5, R](funName: String) = - (_0: A0, _1: A1, _2: A2, _3: A3, _4: A4, _5: A5) => { - val p0 = boxValue(_0) - val p1 = boxValue(_1) - val p2 = boxValue(_2) - val p3 = boxValue(_3) - val p4 = boxValue(_4) - val p5 = boxValue(_5) - val args = Array(p0._1, p1._1, p2._1, p3._1, p4._1, p5._1) - val types = Array[AnyClass](p0._2, p1._2, p2._2, p3._2, p4._2, p5._2) - applyFun(funName, args, types).asInstanceOf[R] - } - - def apply[A0, A1, A2, A3, A4, A5, A6, R](funName: String) = - (_0: A0, _1: A1, _2: A2, _3: A3, _4: A4, _5: A5, _6: A6) => { - val p0 = boxValue(_0) - val p1 = boxValue(_1) - val p2 = boxValue(_2) - val p3 = boxValue(_3) - val p4 = boxValue(_4) - val p5 = boxValue(_5) - val p6 = boxValue(_6) - val args = Array(p0._1, p1._1, p2._1, p3._1, p4._1, p5._1, p6._1) - val types = Array[AnyClass](p0._2, p1._2, p2._2, p3._2, p4._2, p5._2, p6._2) - applyFun(funName, args, types).asInstanceOf[R] - } - - def apply[A0, A1, A2, A3, A4, A5, A6, A7, R](funName: String) = - (_0: A0, _1: A1, _2: A2, _3: A3, _4: A4, _5: A5, _6: A6, _7: A7) => { - val p0 = boxValue(_0) - val p1 = boxValue(_1) - val p2 = boxValue(_2) - val p3 = boxValue(_3) - val p4 = boxValue(_4) - val p5 = boxValue(_5) - val p6 = boxValue(_6) - val p7 = boxValue(_7) - val args = Array(p0._1, p1._1, p2._1, p3._1, p4._1, p5._1, p6._1, p7._1) - val types = Array[AnyClass](p0._2, p1._2, p2._2, p3._2, p4._2, p5._2, p6._2, p7._2) - applyFun(funName, args, types).asInstanceOf[R] - } - - def apply[A0, A1, A2, A3, A4, A5, A6, A7, A8, R](funName: String) = - (_0: A0, _1: A1, _2: A2, _3: A3, _4: A4, _5: A5, _6: A6, _7: A7, _8: A8) => { - val p0 = boxValue(_0) - val p1 = boxValue(_1) - val p2 = boxValue(_2) - val p3 = boxValue(_3) - val p4 = boxValue(_4) - val p5 = boxValue(_5) - val p6 = boxValue(_6) - val p7 = boxValue(_7) - val p8 = boxValue(_8) - val args = Array(p0._1, p1._1, p2._1, p3._1, p4._1, p5._1, p6._1, p7._1, p8._1) - val types = Array[AnyClass](p0._2, p1._2, p2._2, p3._2, p4._2, p5._2, p6._2, p7._2, p8._2) - applyFun(funName, args, types).asInstanceOf[R] - } - - ////////////////////// private functions /////////////////////// - - private def boxValue(value: Any) = value match { - case x: Byte => (java.lang.Byte.valueOf(x), java.lang.Byte.TYPE) - case x: Boolean => (java.lang.Boolean.valueOf(x), java.lang.Boolean.TYPE) - case x: Char => (java.lang.Character.valueOf(x), java.lang.Character.TYPE) - case x: Short => (java.lang.Short.valueOf(x), java.lang.Short.TYPE) - case x: Int => (java.lang.Integer.valueOf(x), java.lang.Integer.TYPE) - case x: Long => (java.lang.Long.valueOf(x), java.lang.Long.TYPE) - case x: Float => (java.lang.Float.valueOf(x), java.lang.Float.TYPE) - case x: Double => (java.lang.Double.valueOf(x), java.lang.Double.TYPE) - case _ => - val x = value.asInstanceOf[JObject] - (x, x.getClass()) - } - - private def isConstructorName(methName: String) = { - var className = clazz.getName() - val classInx = className.lastIndexOf(".") - val methInx = methName.lastIndexOf(".") - if (classInx > 0 && methInx < 0) - className = className.substring(classInx + 1, className.length()) - methName.equals(className) - } - - private def applyFun(methName: String, args: Array[JObject], - argTypes: Array[Class[T] forSome { type T }]): JObject = { - try { - val method = clazz.getMethod(methName, argTypes : _*) - var obj: JObject = null - if (! Modifier.isStatic(method.getModifiers())) { - if (instance eq null) { - instance = try { - clazz.newInstance().asInstanceOf[AnyRef] - } catch { case _ => - val cs = clazz.getConstructors() -//Console.println("cs.length=" + cs.length); - if (cs.length > 0) { - cs(0).newInstance("").asInstanceOf[AnyRef] - } else { - sys.error("class " + clazz.getName() + " has no public constructor") - } - } - } - obj = instance - } - val result = method.invoke(obj, args : _*) - if (result eq null) ().asInstanceOf[JObject] else result - } - catch { - case me: NoSuchMethodException => - if (isConstructorName(methName)) { - try { - val cstr = clazz.getConstructor(argTypes : _*) - instance = cstr.newInstance(args : _*).asInstanceOf[AnyRef] - instance - } - catch { - case e: Exception => - Console.println(e.getMessage()) - e.printStackTrace() - } - } - else { - Console.println(me.getMessage()) - me.printStackTrace() - } - null - case e: Exception => - Console.println(e.getMessage()) - e.printStackTrace() - null - } - } - -} diff --git a/src/library/scala/mobile/Location.scala b/src/library/scala/mobile/Location.scala deleted file mode 100644 index 159bf11141..0000000000 --- a/src/library/scala/mobile/Location.scala +++ /dev/null @@ -1,72 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2002-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - -package scala.mobile - -import java.net._ -import scala.collection.mutable - -/** The class <code>Location</code> provides a <code>create</code> - * method to instantiate objects from a network location by - * specifying the URL address of the jar/class file.<p/> - * - * An update of the jar/class file should not break your code as far - * as the used class names and method signatures are the same.<p/> - * - * Example:<pre> - * <b>val</b> url = <b>new</b> URL("http://scala-lang.org/classes/examples.jar"); - * <b>val</b> obj = <b>new</b> Location(url) create "examples.sort";</pre> - * - * @see <a href="Code.html">Code</a> - * - * @author Stephane Micheloud - * @version 1.0, 04/05/2004 - */ -class Location(url: URL) { - /** A cache containing all class loaders of this location. - */ - private val lcache = new mutable.HashMap[URL, ClassLoader] - - /** The class loader associated with this location. - */ - private val loader = - if (url eq null) ClassLoader.getSystemClassLoader() - else lcache.getOrElseUpdate(url, new URLClassLoader(Array(url))) - - /** A cache containing all classes of this location. - */ - private val ccache = new mutable.HashMap[String, java.lang.Class[_]] - - /** Return the code description for the string <code>className</code> - * at this location. - * - * @param classname the name of the class - * @return the code description corresponding to `className`. - */ - def create(className: String) = new Code( - ccache.getOrElseUpdate(className, { - // source 'class A { ... }' becomes in bytecode: interface A.class + class A$class.class - // source 'object A { ... }' becomes in bytecode: interface A.class + class A$.class - val append = if (loader.loadClass(className).isInterface) "$class" else "$" - loader loadClass (className + append) - }) - ) -} - -/** The object <code>Location</code> can be used to instantiate - * objects on the same Java VM. It is just provided to illustrate - * the special case where resources are available locally.<p/> - * - * Example:<pre> - * <b>val</b> obj = Location.create("xcode.Math"); - * <b>val</b> x = obj[Int, Int]("square")(5);</pre> - * - * @author Stephane Micheloud - * @version 1.0, 04/05/2004 - */ -object Location extends Location(null) |