diff options
author | Burak Emir <emir@epfl.ch> | 2006-11-05 02:53:14 +0000 |
---|---|---|
committer | Burak Emir <emir@epfl.ch> | 2006-11-05 02:53:14 +0000 |
commit | 1e23988361e85f275b44041207988ef9aa0099f2 (patch) | |
tree | 167c7224dfbec04561337d771226fd678a3d1ae0 | |
parent | 9d507e381c8c101a3edf16e0c065e9b8efd5feec (diff) | |
download | scala-1e23988361e85f275b44041207988ef9aa0099f2.tar.gz scala-1e23988361e85f275b44041207988ef9aa0099f2.tar.bz2 scala-1e23988361e85f275b44041207988ef9aa0099f2.zip |
caseclass->product
34 files changed, 552 insertions, 378 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala index aa75b710de..b43f5301f1 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala @@ -1818,13 +1818,14 @@ trait Parsers requires SyntaxAnalyzer { if (name != nme.ScalaObject.toTypeName) parents += scalaScalaObjectConstr if (mods.hasFlag(Flags.CASE)) { - parents += caseClassConstr + //parents += caseClassConstr if (!vparamss.isEmpty) { val argtypes: List[Tree] = vparamss.head map (.tpt.duplicate) //remove type annotation and you will get an interesting error message!!! val nargs = argtypes.length - if (0 < nargs && nargs <= definitions.MaxTupleArity) + if (nargs <= definitions.MaxTupleArity) parents += productConstr(argtypes) - } + } else + parents += productConstr(Nil) } val ps = parents.toList newLineOptWhenFollowedBy(LBRACE) diff --git a/src/compiler/scala/tools/nsc/symtab/StdNames.scala b/src/compiler/scala/tools/nsc/symtab/StdNames.scala index 951349e54f..90c54e3d4e 100644 --- a/src/compiler/scala/tools/nsc/symtab/StdNames.scala +++ b/src/compiler/scala/tools/nsc/symtab/StdNames.scala @@ -281,6 +281,7 @@ trait StdNames requires SymbolTable { val null_ = newTermName("null") val predef = newTermName("predef") val print = newTermName("print") + val productPrefix = newTermName("productPrefix") val readResolve = newTermName("readResolve") val receive = newTermName("receive") val report = newTermName("report") diff --git a/src/compiler/scala/tools/nsc/transform/LiftCode.scala b/src/compiler/scala/tools/nsc/transform/LiftCode.scala index fde24539a7..bc010f8236 100644 --- a/src/compiler/scala/tools/nsc/transform/LiftCode.scala +++ b/src/compiler/scala/tools/nsc/transform/LiftCode.scala @@ -224,14 +224,16 @@ abstract class LiftCode extends Transform { class Injector(env: InjectEnvironment, fresh: FreshNameCreator) { // todo replace className by caseName in CaseClass once we have switched to nsc. - def className(value: CaseClass): String = value match { + def className(value: AnyRef): String = value match { case _ :: _ => "scala.$colon$colon" case reflect.MethodType(_, _) => if (value.isInstanceOf[reflect.ImplicitMethodType]) "scala.reflect.ImplicitMethodType" else "scala.reflect.MethodType" - case x => + case x:Product => + "scala.reflect."+x.productPrefix //caseName + case x:CaseClass => "scala.reflect."+x.caseName //case _ => // bq:unreachable code // "" @@ -246,7 +248,20 @@ abstract class LiftCode extends Transform { case _ => "" } - def inject(value: Any): Tree = value match { + def inject(value: Any): Tree = { + def treatProduct(c:Product) = { + val name = objectName(c); + if (name.length() != 0) gen.mkAttributedRef(definitions.getModule(name)) + else { + val name = className(c); + if (name.length() == 0) throw new Error("don't know how to inject " + value); + val injectedArgs = new ListBuffer[Tree]; + for (val i <- 1 until c.arity+1 /*caseArity*/) + injectedArgs += inject(c.element(i)); + New(Ident(definitions.getClass(name)), List(injectedArgs.toList)) + } + } + value match { case FreeValue(tree) => New(Ident(definitions.getClass("scala.reflect.Literal")), List(List(tree))) case () => Literal(Constant(())) @@ -259,23 +274,17 @@ abstract class LiftCode extends Transform { case x: Long => Literal(Constant(x)) case x: Float => Literal(Constant(x)) case x: Double => Literal(Constant(x)) - case c: CaseClass => - val name = objectName(c); - if (name.length() != 0) gen.mkAttributedRef(definitions.getModule(name)) - else { - val name = className(c); - if (name.length() == 0) throw new Error("don't know how to inject " + value); - val injectedArgs = new ListBuffer[Tree]; - for (val i <- 0 until c.caseArity) - injectedArgs += inject(c.caseElement(i)); - New(Ident(definitions.getClass(name)), List(injectedArgs.toList)) - } + case c: Product => treatProduct(c) + case c: CaseClass => treatProduct(new Product { + override def productPrefix = c.caseName; + def element(i:Int) = c.caseElement(i) + def arity = c.caseArity }) case null => gen.mkAttributedRef(definitions.getModule("scala.reflect.NoType")) case _ => throw new Error("don't know how to inject " + value) } - + } } def reify(tree: Tree): reflect.Tree = diff --git a/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala b/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala index caf0573f3d..83d39bd031 100644 --- a/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala +++ b/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala @@ -47,6 +47,11 @@ trait SyntheticMethods requires Analyzer { !(ObjectClass isNonBottomSubClass sym.owner) && !(sym hasFlag DEFERRED))) } + def hasDirectImplementation(name: Name): Boolean = { + val sym = clazz.info.nonPrivateMember(name) + (sym.isTerm && sym.owner == clazz) + } + def syntheticMethod(name: Name, flags: Int, tpe: Type) = newSyntheticMethod(name, flags | OVERRIDE, tpe) @@ -89,6 +94,10 @@ trait SyntheticMethods requires Analyzer { val method = syntheticMethod(nme.caseName, FINAL, PolyType(List(), StringClass.tpe)) typed(DefDef(method, vparamss => Literal(Constant(clazz.name.decode)))) } + def productPrefixMethod: Tree = { + val method = syntheticMethod(nme.productPrefix, FINAL, PolyType(List(), StringClass.tpe)) + typed(DefDef(method, vparamss => Literal(Constant(clazz.name.decode)))) + } def moduleToStringMethod: Tree = { val method = syntheticMethod(nme.toString_, FINAL, MethodType(List(), StringClass.tpe)) @@ -217,10 +226,13 @@ trait SyntheticMethods requires Analyzer { if (!hasImplementation(nme.toString_)) ts += forwardingMethod(nme.toString_) if (!hasImplementation(nme.equals_)) ts += equalsMethod //forwardingMethod(nme.equals_) } - if (!hasImplementation(nme.caseElement)) ts += caseElementMethod - if (!hasImplementation(nme.caseArity)) ts += caseArityMethod - if (!hasImplementation(nme.caseName)) ts += caseNameMethod - + // remove, after updating starr + if(templ.parents.contains { x:Tree => x.tpe == definitions.getClass("scala.CaseClass") }) { + if (!hasImplementation(nme.caseElement)) ts += caseElementMethod + if (!hasImplementation(nme.caseArity)) ts += caseArityMethod + if (!hasImplementation(nme.caseName)) ts += caseNameMethod + } + if (!hasDirectImplementation(nme.productPrefix)) ts += productPrefixMethod val accessors = if(clazz hasFlag CASE) clazz.caseFieldAccessors else clazz.constrParamAccessors for (val i <- 0 until accessors.length) { val acc = accessors(i) diff --git a/src/library/scala/List.scala b/src/library/scala/List.scala index 1410068344..3d622bd68c 100644 --- a/src/library/scala/List.scala +++ b/src/library/scala/List.scala @@ -371,7 +371,7 @@ object List { * @author Martin Odersky and others * @version 1.0, 16/07/2003 */ -sealed abstract class List[+a] extends Seq[a] with CaseClass { +sealed abstract class List[+a] extends Seq[a] { /** Returns true if the list does not contain any elements. * @return true, iff the list is empty. @@ -1079,7 +1079,8 @@ sealed abstract class List[+a] extends Seq[a] with CaseClass { b.toList } - override protected def stringPrefix: String = "List" + protected override def stringPrefix: String = "List" + } /** The empty list. diff --git a/src/library/scala/Option.scala b/src/library/scala/Option.scala index 9d8e547c28..cb92cbd39d 100644 --- a/src/library/scala/Option.scala +++ b/src/library/scala/Option.scala @@ -22,7 +22,7 @@ import Predef._ * @author Matthias Zenger * @version 1.0, 16/07/2003 */ -sealed abstract class Option[+A] extends Iterable[A] with CaseClass { +sealed abstract class Option[+A] extends Iterable[A] { def isEmpty: Boolean = this match { case None => true @@ -80,8 +80,7 @@ sealed abstract class Option[+A] extends Iterable[A] with CaseClass { * @author Martin Odersky * @version 1.0, 16/07/2003 */ -final case class Some[+A](x: A) extends Option[A]; - +final case class Some[+A](x: A) extends Option[A] /** This case object represents non-existent values. * * @author Martin Odersky diff --git a/src/library/scala/Product.scala b/src/library/scala/Product.scala new file mode 100644 index 0000000000..07bc5b045c --- /dev/null +++ b/src/library/scala/Product.scala @@ -0,0 +1,42 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2002-2006, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id: CaseClass.scala 8756 2006-09-22 16:00:23Z michelou $ + + +package scala + +/** The trait <code>CaseClass</code> defines access functions for instances + * of case classes. + * + * @author Burak Emir + * @version 1.0 + */ +trait Product extends AnyRef { + + /** for a case class <code>A(x_1,...,x_k))</code>, returns <code>x_i</code> + * for <code>1 <= i < k</code> + * + * @param n the position of the n-th element + * @throws IndexOutOfBoundsException + * @return ... + */ + def element(n: Int): Any + + /** return k for a product <code>A(x_1,...,x_k))</code> + */ + def arity: Int + + /** + * By default the empty string. Implementations may override this + * method in order to prepend a string prefix to the result of the + * toString methods. + */ + def productPrefix = "" + +} diff --git a/src/library/scala/Product0.scala b/src/library/scala/Product0.scala new file mode 100644 index 0000000000..a78fdd8ffe --- /dev/null +++ b/src/library/scala/Product0.scala @@ -0,0 +1,35 @@ + +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2002-2006, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// generated on Sun Nov 05 03:50:36 CET 2006 +package scala + +import Predef._ + +/** Product0 is a cartesian product of 0 components + */ +trait Product0 extends Product { + + /** + * The arity of this product. + * @return 0 + */ + override def arity = 0 + + /** + * Returns the n-th projection of this product if 0<n<=arity, otherwise null + * @param n number of the projection to be returned + * @throws IndexOutOfBoundsException + */ + override def element(n: Int) = n match { + case _ => throw new IndexOutOfBoundsException(n.toString()) + } + + +} diff --git a/src/library/scala/Product1.scala b/src/library/scala/Product1.scala index 9f4860041c..944a49534b 100644 --- a/src/library/scala/Product1.scala +++ b/src/library/scala/Product1.scala @@ -7,12 +7,33 @@ ** |/ ** \* */ -// generated on Fri Oct 27 18:56:23 CEST 2006 +// generated on Sun Nov 05 03:50:36 CET 2006 package scala import Predef._ -trait Product1 [+T1] { +/** Product1 is a cartesian product of 1 components + */ +trait Product1 [+T1] extends Product { + + /** + * The arity of this product. + * @return 1 + */ + override def arity = 1 + + /** + * Returns the n-th projection of this product if 0<n<=arity, otherwise null + * @param n number of the projection to be returned + * @throws IndexOutOfBoundsException + */ + override def element(n: Int) = n match { + case 1 => _1 + case _ => throw new IndexOutOfBoundsException(n.toString()) + } + + /** projection of this product */ def _1:T1 + } diff --git a/src/library/scala/Product2.scala b/src/library/scala/Product2.scala index 822b2f798c..b23fe3bd01 100644 --- a/src/library/scala/Product2.scala +++ b/src/library/scala/Product2.scala @@ -7,13 +7,37 @@ ** |/ ** \* */ -// generated on Fri Oct 27 18:56:23 CEST 2006 +// generated on Sun Nov 05 03:50:36 CET 2006 package scala import Predef._ -trait Product2 [+T1, +T2] { +/** Product2 is a cartesian product of 2 components + */ +trait Product2 [+T1, +T2] extends Product { + + /** + * The arity of this product. + * @return 2 + */ + override def arity = 2 + + /** + * Returns the n-th projection of this product if 0<n<=arity, otherwise null + * @param n number of the projection to be returned + * @throws IndexOutOfBoundsException + */ + override def element(n: Int) = n match { + case 1 => _1 + case 2 => _2 + case _ => throw new IndexOutOfBoundsException(n.toString()) + } + + /** projection of this product */ def _1:T1 + + /** projection of this product */ def _2:T2 + } diff --git a/src/library/scala/Product3.scala b/src/library/scala/Product3.scala index 868d388ca2..ee17610110 100644 --- a/src/library/scala/Product3.scala +++ b/src/library/scala/Product3.scala @@ -7,14 +7,41 @@ ** |/ ** \* */ -// generated on Fri Oct 27 18:56:23 CEST 2006 +// generated on Sun Nov 05 03:50:36 CET 2006 package scala import Predef._ -trait Product3 [+T1, +T2, +T3] { +/** Product3 is a cartesian product of 3 components + */ +trait Product3 [+T1, +T2, +T3] extends Product { + + /** + * The arity of this product. + * @return 3 + */ + override def arity = 3 + + /** + * Returns the n-th projection of this product if 0<n<=arity, otherwise null + * @param n number of the projection to be returned + * @throws IndexOutOfBoundsException + */ + override def element(n: Int) = n match { + case 1 => _1 + case 2 => _2 + case 3 => _3 + case _ => throw new IndexOutOfBoundsException(n.toString()) + } + + /** projection of this product */ def _1:T1 + + /** projection of this product */ def _2:T2 + + /** projection of this product */ def _3:T3 + } diff --git a/src/library/scala/Product4.scala b/src/library/scala/Product4.scala index d6ed33e35e..5537c28ace 100644 --- a/src/library/scala/Product4.scala +++ b/src/library/scala/Product4.scala @@ -7,15 +7,45 @@ ** |/ ** \* */ -// generated on Fri Oct 27 18:56:23 CEST 2006 +// generated on Sun Nov 05 03:50:36 CET 2006 package scala import Predef._ -trait Product4 [+T1, +T2, +T3, +T4] { +/** Product4 is a cartesian product of 4 components + */ +trait Product4 [+T1, +T2, +T3, +T4] extends Product { + + /** + * The arity of this product. + * @return 4 + */ + override def arity = 4 + + /** + * Returns the n-th projection of this product if 0<n<=arity, otherwise null + * @param n number of the projection to be returned + * @throws IndexOutOfBoundsException + */ + override def element(n: Int) = n match { + case 1 => _1 + case 2 => _2 + case 3 => _3 + case 4 => _4 + case _ => throw new IndexOutOfBoundsException(n.toString()) + } + + /** projection of this product */ def _1:T1 + + /** projection of this product */ def _2:T2 + + /** projection of this product */ def _3:T3 + + /** projection of this product */ def _4:T4 + } diff --git a/src/library/scala/Product5.scala b/src/library/scala/Product5.scala index 0229c9f495..ffd29713d1 100644 --- a/src/library/scala/Product5.scala +++ b/src/library/scala/Product5.scala @@ -7,16 +7,49 @@ ** |/ ** \* */ -// generated on Fri Oct 27 18:56:23 CEST 2006 +// generated on Sun Nov 05 03:50:36 CET 2006 package scala import Predef._ -trait Product5 [+T1, +T2, +T3, +T4, +T5] { +/** Product5 is a cartesian product of 5 components + */ +trait Product5 [+T1, +T2, +T3, +T4, +T5] extends Product { + + /** + * The arity of this product. + * @return 5 + */ + override def arity = 5 + + /** + * Returns the n-th projection of this product if 0<n<=arity, otherwise null + * @param n number of the projection to be returned + * @throws IndexOutOfBoundsException + */ + override def element(n: Int) = n match { + case 1 => _1 + case 2 => _2 + case 3 => _3 + case 4 => _4 + case 5 => _5 + case _ => throw new IndexOutOfBoundsException(n.toString()) + } + + /** projection of this product */ def _1:T1 + + /** projection of this product */ def _2:T2 + + /** projection of this product */ def _3:T3 + + /** projection of this product */ def _4:T4 + + /** projection of this product */ def _5:T5 + } diff --git a/src/library/scala/Product6.scala b/src/library/scala/Product6.scala index 318b8a1524..4dd5140315 100644 --- a/src/library/scala/Product6.scala +++ b/src/library/scala/Product6.scala @@ -7,17 +7,53 @@ ** |/ ** \* */ -// generated on Fri Oct 27 18:56:23 CEST 2006 +// generated on Sun Nov 05 03:50:36 CET 2006 package scala import Predef._ -trait Product6 [+T1, +T2, +T3, +T4, +T5, +T6] { +/** Product6 is a cartesian product of 6 components + */ +trait Product6 [+T1, +T2, +T3, +T4, +T5, +T6] extends Product { + + /** + * The arity of this product. + * @return 6 + */ + override def arity = 6 + + /** + * Returns the n-th projection of this product if 0<n<=arity, otherwise null + * @param n number of the projection to be returned + * @throws IndexOutOfBoundsException + */ + override def element(n: Int) = n match { + case 1 => _1 + case 2 => _2 + case 3 => _3 + case 4 => _4 + case 5 => _5 + case 6 => _6 + case _ => throw new IndexOutOfBoundsException(n.toString()) + } + + /** projection of this product */ def _1:T1 + + /** projection of this product */ def _2:T2 + + /** projection of this product */ def _3:T3 + + /** projection of this product */ def _4:T4 + + /** projection of this product */ def _5:T5 + + /** projection of this product */ def _6:T6 + } diff --git a/src/library/scala/Product7.scala b/src/library/scala/Product7.scala index 523c7c6dc6..ce0ebfaac0 100644 --- a/src/library/scala/Product7.scala +++ b/src/library/scala/Product7.scala @@ -7,18 +7,57 @@ ** |/ ** \* */ -// generated on Fri Oct 27 18:56:23 CEST 2006 +// generated on Sun Nov 05 03:50:36 CET 2006 package scala import Predef._ -trait Product7 [+T1, +T2, +T3, +T4, +T5, +T6, +T7] { +/** Product7 is a cartesian product of 7 components + */ +trait Product7 [+T1, +T2, +T3, +T4, +T5, +T6, +T7] extends Product { + + /** + * The arity of this product. + * @return 7 + */ + override def arity = 7 + + /** + * Returns the n-th projection of this product if 0<n<=arity, otherwise null + * @param n number of the projection to be returned + * @throws IndexOutOfBoundsException + */ + override def element(n: Int) = n match { + case 1 => _1 + case 2 => _2 + case 3 => _3 + case 4 => _4 + case 5 => _5 + case 6 => _6 + case 7 => _7 + case _ => throw new IndexOutOfBoundsException(n.toString()) + } + + /** projection of this product */ def _1:T1 + + /** projection of this product */ def _2:T2 + + /** projection of this product */ def _3:T3 + + /** projection of this product */ def _4:T4 + + /** projection of this product */ def _5:T5 + + /** projection of this product */ def _6:T6 + + /** projection of this product */ def _7:T7 + } diff --git a/src/library/scala/Product8.scala b/src/library/scala/Product8.scala index 57ee647c69..bbe8275f6b 100644 --- a/src/library/scala/Product8.scala +++ b/src/library/scala/Product8.scala @@ -7,19 +7,61 @@ ** |/ ** \* */ -// generated on Fri Oct 27 18:56:23 CEST 2006 +// generated on Sun Nov 05 03:50:36 CET 2006 package scala import Predef._ -trait Product8 [+T1, +T2, +T3, +T4, +T5, +T6, +T7, +T8] { +/** Product8 is a cartesian product of 8 components + */ +trait Product8 [+T1, +T2, +T3, +T4, +T5, +T6, +T7, +T8] extends Product { + + /** + * The arity of this product. + * @return 8 + */ + override def arity = 8 + + /** + * Returns the n-th projection of this product if 0<n<=arity, otherwise null + * @param n number of the projection to be returned + * @throws IndexOutOfBoundsException + */ + override def element(n: Int) = n match { + case 1 => _1 + case 2 => _2 + case 3 => _3 + case 4 => _4 + case 5 => _5 + case 6 => _6 + case 7 => _7 + case 8 => _8 + case _ => throw new IndexOutOfBoundsException(n.toString()) + } + + /** projection of this product */ def _1:T1 + + /** projection of this product */ def _2:T2 + + /** projection of this product */ def _3:T3 + + /** projection of this product */ def _4:T4 + + /** projection of this product */ def _5:T5 + + /** projection of this product */ def _6:T6 + + /** projection of this product */ def _7:T7 + + /** projection of this product */ def _8:T8 + } diff --git a/src/library/scala/Product9.scala b/src/library/scala/Product9.scala index e7a7f73982..354d1d09ef 100644 --- a/src/library/scala/Product9.scala +++ b/src/library/scala/Product9.scala @@ -7,20 +7,65 @@ ** |/ ** \* */ -// generated on Fri Oct 27 18:56:23 CEST 2006 +// generated on Sun Nov 05 03:50:36 CET 2006 package scala import Predef._ -trait Product9 [+T1, +T2, +T3, +T4, +T5, +T6, +T7, +T8, +T9] { +/** Product9 is a cartesian product of 9 components + */ +trait Product9 [+T1, +T2, +T3, +T4, +T5, +T6, +T7, +T8, +T9] extends Product { + + /** + * The arity of this product. + * @return 9 + */ + override def arity = 9 + + /** + * Returns the n-th projection of this product if 0<n<=arity, otherwise null + * @param n number of the projection to be returned + * @throws IndexOutOfBoundsException + */ + override def element(n: Int) = n match { + case 1 => _1 + case 2 => _2 + case 3 => _3 + case 4 => _4 + case 5 => _5 + case 6 => _6 + case 7 => _7 + case 8 => _8 + case 9 => _9 + case _ => throw new IndexOutOfBoundsException(n.toString()) + } + + /** projection of this product */ def _1:T1 + + /** projection of this product */ def _2:T2 + + /** projection of this product */ def _3:T3 + + /** projection of this product */ def _4:T4 + + /** projection of this product */ def _5:T5 + + /** projection of this product */ def _6:T6 + + /** projection of this product */ def _7:T7 + + /** projection of this product */ def _8:T8 + + /** projection of this product */ def _9:T9 + } diff --git a/src/library/scala/runtime/ScalaRunTime.scala b/src/library/scala/runtime/ScalaRunTime.scala index 10d8683891..f32db05a23 100644 --- a/src/library/scala/runtime/ScalaRunTime.scala +++ b/src/library/scala/runtime/ScalaRunTime.scala @@ -75,23 +75,50 @@ object ScalaRunTime { else x.caseElement(from) :: fields(from + 1); fields(0) } - - def _toString(x: CaseClass): String = { + def caseFields(x: Product): List[Any] = { + val arity = x.arity; + def fields(from: Int): List[Any] = + if (from > arity) List() + else x.element(from) :: fields(from + 1); + fields(1) + } + def _toStringCaseClass(x: CaseClass): String = { caseFields(x).mkString(x.caseName + "(", ",", ")") } - - def _hashCode(x: CaseClass): Int = { + def _toStringProduct(x: Product): String = { + caseFields(x).mkString(x.productPrefix + "(", ",", ")") + } + /** only for bootstrapping 2.2.1 remove afterwards, keeping only _equalsProduct */ + def _toString(x: AnyRef): String = x match { + case xc: CaseClass => _toStringCaseClass(xc) + case xp: Product => _toStringProduct(xp) + } + def _hashCodeCaseClass(x: CaseClass): Int = { var code = x.getClass().hashCode(); - val arity = x.caseArity; + val arr = x.caseArity var i = 0; - while (i < arity) { + while (i < arr) { code = code * 41 + x.caseElement(i).hashCode(); i = i + 1 } code } - - def _equals(x: CaseClass, y: Any): Boolean = y match { + def _hashCodeProduct(x: Product): Int = { + var code = x.getClass().hashCode(); + val arr = x.arity + var i = 1; + while (i <= arr) { + code = code * 41 + x.element(i).hashCode(); + i = i + 1 + } + code + } + /** only for bootstrapping 2.2.1 remove afterwards, keeping only _equalsProduct */ + def _hashCode(x: AnyRef): Int = x match { + case xc: CaseClass => _hashCodeCaseClass(xc) + case xp: Product => _hashCodeProduct(xp) + } + def _equalsCaseClass(x: CaseClass, y: Any): Boolean = y match { case y1: CaseClass => /*(x.getClass() eq y1.getClass() &&*/ { val arity = x.caseArity; @@ -103,7 +130,23 @@ object ScalaRunTime { case _ => false } - + def _equalsProduct(x: Product, y: Any): Boolean = y match { + case y1: Product if x.arity == y1.arity => + /*(x.getClass() eq y1.getClass() &&*/ { + val arity = x.arity; + var i = 1; + while (i <= arity && x.element(i) == y1.element(i)) + i = i + 1; + i == arity + 1 + } + case _ => + false + } + /** only for bootstrapping 2.2.1 remove afterwards, keeping only _equalsProduct */ + def _equals(x: AnyRef, y: Any): Boolean = x match { + case xc: CaseClass => _equalsCaseClass(xc, y) + case xp: Product => _equalsProduct(xp, y) + } //def checkDefined[T >: Null](x: T): T = // if (x == null) throw new UndefinedException else x diff --git a/src/library/scala/runtime/matching/Address.scala b/src/library/scala/runtime/matching/Address.scala deleted file mode 100644 index e8f09d50c9..0000000000 --- a/src/library/scala/runtime/matching/Address.scala +++ /dev/null @@ -1,38 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2006, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - -// $Id$ - - -package scala.runtime.matching ; - - -object Address { - def empty = new Address(); -} - -//import List.list2ordered; - -/** Address holds the path in reverse Dewey notation -*/ -class Address( l:Int* ) extends Ordered[Address] { - - private val list:List[Int] = l.toList; - - def compare (y: Address): int = list.reverse.compare(y.list.reverse) - - def down: Address = new Address( ( 1 :: list ):_* ); - - /** precond: p is nonempty */ - def right: Address = list match { - case i :: rest => new Address( ((i+1) :: rest ):_* ) - } - - override def toString() = list.mkString("Address(",".",")"); - -} diff --git a/src/library/scala/runtime/matching/NonTerm.scala b/src/library/scala/runtime/matching/NonTerm.scala deleted file mode 100644 index d97e3e94b3..0000000000 --- a/src/library/scala/runtime/matching/NonTerm.scala +++ /dev/null @@ -1,58 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2006, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - -// $Id$ - - -package scala.runtime.matching ; - - -import scala.collection.immutable ; - -abstract class NonTerm { - - override def toString() = this match { - case TreeNT( i ) => "t"+i; - case h @ HedgeNT( i ) => "h"+i+{ if( h.nullable )"~" else "" }; - } - -} - -/** tree nonterminal. holds set of binding variable indices. - */ -case class TreeNT(i:int) extends NonTerm with Ordered[TreeNT] { - - var vset:immutable.Set[Int] = new immutable.TreeSet[Int]() ; - - /** vset should be sorted to allow fast lookup */ - def this( i:int, vset:immutable.Set[Int] ) = { - this( i ); - this.vset = new immutable.TreeSet[Int]() incl vset ; - } - - def compare (y: TreeNT): int = i compare y.i -} - -/** hedge nonterminals. holds nullable property. - */ -case class HedgeNT(i:int) extends NonTerm with Ordered[HedgeNT] { - - var nullable:boolean = false; - - def this( i:int, nullable:boolean ) = { - this( i ); - this.nullable = nullable; - } - - def compare (y: HedgeNT): int = i compare y.i -} - -//case object EMPTYHEDGE extends HedgeNT( 0, true ) ; -//case object ANYHEDGE extends HedgeNT( 1, true ) ; -object ANYTREE extends TreeNT( 1 ); - diff --git a/src/library/scala/runtime/matching/PatternTests.scala b/src/library/scala/runtime/matching/PatternTests.scala deleted file mode 100644 index 6fefc5e276..0000000000 --- a/src/library/scala/runtime/matching/PatternTests.scala +++ /dev/null @@ -1,17 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2006, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - -// $Id$ - - -package scala.runtime.matching ; - - -abstract class PatternTests extends Function2[Int,Any,Boolean]{ - def apply(i:Int, inp:Any): Boolean; -} diff --git a/src/library/scala/runtime/matching/Rule.scala b/src/library/scala/runtime/matching/Rule.scala deleted file mode 100644 index b9a14d6063..0000000000 --- a/src/library/scala/runtime/matching/Rule.scala +++ /dev/null @@ -1,112 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2006, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - -// $Id$ - - -package scala.runtime.matching ; - - -/* hedge grammar rules */ -abstract class Rule extends Ordered[Rule] { - - def compare (that: Rule): int = { - if( rule_smaller( this, that ) ) - -1 - else if( rule_eq( this, that ) ) - 0 - else - 1 - } - - final def rule_smaller( r1:Rule, r2:Rule ):boolean = r1 match { - case HedgeRule( h1, _, hh1 ) => r2 match { - case HedgeRule( h2, _, hh2 ) => - ((h1 == h2)&&( hh1.i < hh2.i )) || h1.i < h2.i; - case HedgeChainRule( h2, hh2 ) => - ((h1 == h2)&&( hh1.i < hh2.i )) || h1.i < h2.i; - case _ => false; - } - case HedgeChainRule( h1, hh1 ) => r2 match { - case HedgeRule( h2, _, hh2 ) => - ((h1 == h2)&&( hh1.i < hh2.i )) || h1.i < h2.i; - case HedgeChainRule( h2, hh2 ) => - ((h1 == h2)&&( hh1.i < hh2.i )) || h1.i < h2.i; - case _ => false; - } - case TreeRule( t1, _, hh1 ) => r2 match { - case TreeRule( t2, _, hh2 ) => - ((t1 == t2 )&&(hh1.i < hh2.i )) || t1.i < t2.i; - case AnyTreeRule( t2 ) => false; - case AnyNodeRule( t2, hh2 ) => - ((t1 == t2 )&&(hh1.i < hh2.i )) || t1.i < t2.i; - case _ => true; - } - case AnyTreeRule( t1 ) => r2 match { - case TreeRule( _, _ , _ ) => true; - case AnyTreeRule( t2 ) => t1.i < t2.i; - case AnyNodeRule( t2, _ ) => true - case _ => true; - } - case AnyNodeRule( t1, hh1 ) => r2 match { - case TreeRule( t2, _, hh2 ) => - ((t1 == t2 )&&(hh1.i < hh2.i )) || t1.i < t2.i; - case AnyTreeRule( t2 ) => false; - case AnyNodeRule( t2, hh2 ) => - ((t1 == t2 )&&(hh1.i < hh2.i )) || t1.i < t2.i; - case _ => true; - } - }; - final def rule_eq( r1:Rule, r2:Rule ):boolean = r1 == r2; - - - override def toString() = this match { - case HedgeChainRule( n, m ) => - n.toString()+" ::= "+m.toString(); - - case TreeRule( n, label, n2 ) => - (n.toString()+{ if( !n.vset.isEmpty ) n.vset.toString() else "" }+ - " ::= "+label+"( "+n2.toString()+{if( n2.nullable ) "~" else ""}+" )") - - case AnyTreeRule( n ) => - n.toString()+{ if( !n.vset.isEmpty ) n.vset.toString() else "" }+" ::= _ "; - - case AnyNodeRule( n, h ) => - n.toString()+{ if( !n.vset.isEmpty ) n.vset.toString() else "" }+" ::= _ ( "+h.toString()+" )"; - - case HedgeRule( n, t, h ) => - n.toString()+( - if( n.nullable ) "~" else " " - )+" ::= "+( - if( t == ANYTREE ) "_" else t.toString() - )+" "+h.toString(); - - } -} - -abstract class TRule extends Rule; -abstract class HRule extends Rule; -/* -a tree rule is of the from A -> s(B) -where A,B are TreeNTs and s is an identifier (string). - -If s is the empty string, then the node label is arbitrary -If HedgeNT is AnyHedgeNT, then the tree is arbitrary -*/ -case class HedgeChainRule( n: HedgeNT, rhs: HedgeNT ) extends HRule; -case class TreeRule( n:TreeNT, test:Int, h:HedgeNT ) extends TRule { - def this(i:Int, s:Int, n:Int ) = { - this( new TreeNT(i), s, new HedgeNT(n)); - } -}; -case class AnyTreeRule( n:TreeNT ) extends TRule { -} -case class AnyNodeRule( n:TreeNT, h:HedgeNT ) extends TRule { -} -case class HedgeRule( n:HedgeNT, t:TreeNT, h:HedgeNT ) extends HRule; - diff --git a/src/library/scala/runtime/matching/TestAlphabet.scala b/src/library/scala/runtime/matching/TestAlphabet.scala deleted file mode 100644 index 39237b4aa5..0000000000 --- a/src/library/scala/runtime/matching/TestAlphabet.scala +++ /dev/null @@ -1,21 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2006, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - -// $Id$ - - -package scala.runtime.matching ; - - -abstract class TestAlphabet; - -case class TestLabel(i: Int) extends TestAlphabet ; - -case object AnyNode extends TestAlphabet { - def view(x: Int): TestLabel = TestLabel(x); -} diff --git a/src/library/scala/xml/Comment.scala b/src/library/scala/xml/Comment.scala index 2f4ad96e9e..484d72def8 100644 --- a/src/library/scala/xml/Comment.scala +++ b/src/library/scala/xml/Comment.scala @@ -42,6 +42,6 @@ case class Comment(commentText: String) extends SpecialNode { override def text = "" /** appends "<!-- text -->" to this stringbuffer */ - def toString(sb: StringBuilder) = + override def toString(sb: StringBuilder) = sb.append("<!--").append(commentText).append("-->") } diff --git a/src/library/scala/xml/EntityRef.scala b/src/library/scala/xml/EntityRef.scala index a649ab4d5b..33cdef33e3 100644 --- a/src/library/scala/xml/EntityRef.scala +++ b/src/library/scala/xml/EntityRef.scala @@ -45,7 +45,7 @@ case class EntityRef(entityName: String) extends SpecialNode { } /** appends "& entityName;" to this stringbuffer */ - def toString(sb: StringBuilder) = + override def toString(sb: StringBuilder) = sb.append("&").append(entityName).append(";") } diff --git a/src/library/scala/xml/MetaData.scala b/src/library/scala/xml/MetaData.scala index 4e1d48f532..d06f2649f0 100644 --- a/src/library/scala/xml/MetaData.scala +++ b/src/library/scala/xml/MetaData.scala @@ -162,7 +162,7 @@ abstract class MetaData extends Iterable[MetaData] { sb.toString() } - def toString(sb: StringBuilder): Unit = { + def toString(sb: StringBuilder): StringBuilder = { sb.append(' ') toString1(sb) next.toString(sb) diff --git a/src/library/scala/xml/Null.scala b/src/library/scala/xml/Null.scala index e5a4290055..eedc208a2c 100644 --- a/src/library/scala/xml/Null.scala +++ b/src/library/scala/xml/Null.scala @@ -69,7 +69,7 @@ case object Null extends MetaData { override def toString(): String = "" - override def toString(sb: StringBuilder): Unit = {} + override def toString(sb: StringBuilder): StringBuilder = sb override def wellformed(scope: NamespaceBinding) = true diff --git a/src/library/scala/xml/ProcInstr.scala b/src/library/scala/xml/ProcInstr.scala index a355bb3eb4..1b3f78e01f 100644 --- a/src/library/scala/xml/ProcInstr.scala +++ b/src/library/scala/xml/ProcInstr.scala @@ -54,7 +54,7 @@ case class ProcInstr(target:String, proctext:String) extends SpecialNode { /** appends "<?" target (" "+text)?+"?>" * to this stringbuffer. */ - def toString(sb: StringBuilder) = { + override def toString(sb: StringBuilder) = { sb .append("<?") .append(target); diff --git a/src/library/scala/xml/SpecialNode.scala b/src/library/scala/xml/SpecialNode.scala index f68396250d..9fb23a64a3 100644 --- a/src/library/scala/xml/SpecialNode.scala +++ b/src/library/scala/xml/SpecialNode.scala @@ -29,9 +29,7 @@ abstract class SpecialNode extends Node with pull.XMLEvent { /** always empty */ final def child = Nil - final override def toString(): String = - toString(new StringBuilder()).toString() - + /** append string representation to the given stringbuffer */ def toString(sb: StringBuilder): StringBuilder } diff --git a/src/library/scala/xml/dtd/ContentModel.scala b/src/library/scala/xml/dtd/ContentModel.scala index 4ba9b8a51e..0f7eb6e8cb 100644 --- a/src/library/scala/xml/dtd/ContentModel.scala +++ b/src/library/scala/xml/dtd/ContentModel.scala @@ -134,13 +134,13 @@ sealed abstract class ContentModel { } case object PCDATA extends ContentModel { - def toString(sb:StringBuilder): StringBuilder = sb.append("(#PCDATA)"); + override def toString(sb:StringBuilder): StringBuilder = sb.append("(#PCDATA)"); } case object EMPTY extends ContentModel { - def toString(sb:StringBuilder): StringBuilder = sb.append("EMPTY"); + override def toString(sb:StringBuilder): StringBuilder = sb.append("EMPTY"); } case object ANY extends ContentModel { - def toString(sb:StringBuilder): StringBuilder = sb.append("ANY"); + override def toString(sb:StringBuilder): StringBuilder = sb.append("ANY"); } abstract class DFAContentModel extends ContentModel { import ContentModel.{ ElemName }; @@ -178,7 +178,7 @@ Console.println("ns = "+ns); } } */ - def toString(sb:StringBuilder): StringBuilder = { + override def toString(sb:StringBuilder): StringBuilder = { sb.append("(#PCDATA|"); //r match { // case Alt(Eps, rs@_*) => ContentModel.toString(Alt(rs:_*):RegExp, sb); @@ -207,6 +207,6 @@ case class ELEMENTS(r:ContentModel.RegExp) extends DFAContentModel { } } */ - def toString(sb:StringBuilder): StringBuilder = + override def toString(sb:StringBuilder): StringBuilder = ContentModel.toString(r, sb); } diff --git a/src/library/scala/xml/dtd/Decl.scala b/src/library/scala/xml/dtd/Decl.scala index 3a000baac5..3aec3b1c70 100644 --- a/src/library/scala/xml/dtd/Decl.scala +++ b/src/library/scala/xml/dtd/Decl.scala @@ -1,10 +1,10 @@ /* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2006, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ + ** ________ ___ / / ___ Scala API ** + ** / __/ __// _ | / / / _ | (c) 2003-2006, LAMP/EPFL ** + ** __\ \/ /__/ __ |/ /__/ __ | ** + ** /____/\___/_/ |_/____/_/ | | ** + ** |/ ** + \* */ // $Id$ @@ -17,13 +17,7 @@ import compat.StringBuilder abstract class Decl; abstract class MarkupDecl extends Decl { - - final override def toString(): String = { - toString(new StringBuilder()).toString(); - } - def toString(sb: StringBuilder): StringBuilder; - } /** an element declaration @@ -32,7 +26,7 @@ case class ElemDecl(name: String, contentModel: ContentModel) extends MarkupDecl //def mixed = ; // to do - def toString(sb: StringBuilder): StringBuilder = { + override def toString(sb: StringBuilder): StringBuilder = { sb .append("<!ELEMENT ") .append(name) @@ -46,7 +40,7 @@ case class ElemDecl(name: String, contentModel: ContentModel) extends MarkupDecl case class AttListDecl(name: String, attrs:List[AttrDecl]) extends MarkupDecl with DtdTypeSymbol { - def toString(sb: StringBuilder): StringBuilder = { + override def toString(sb: StringBuilder): StringBuilder = { sb .append("<!ATTLIST ") .append(name) @@ -61,10 +55,10 @@ case class AttListDecl(name: String, attrs:List[AttrDecl]) extends MarkupDecl wi */ case class AttrDecl( name:String, tpe:String, default:DefaultDecl ) { - final override def toString(): String = + override def toString(): String = toString(new StringBuilder()).toString(); - final def toString(sb: StringBuilder): StringBuilder = { + def toString(sb: StringBuilder): StringBuilder = { sb.append(" ").append( name ).append(' ').append( tpe ).append(' '); default.toString(sb) } @@ -77,7 +71,7 @@ abstract class EntityDecl extends MarkupDecl; /** a parsed general entity declaration */ case class ParsedEntityDecl( name:String, entdef:EntityDef ) extends EntityDecl { - final def toString(sb: StringBuilder): StringBuilder = { + override def toString(sb: StringBuilder): StringBuilder = { sb.append("<!ENTITY ").append( name ).append(' '); entdef.toString(sb).append('>'); } @@ -85,8 +79,7 @@ case class ParsedEntityDecl( name:String, entdef:EntityDef ) extends EntityDecl /** a parameter entity declaration */ case class ParameterEntityDecl(name: String, entdef: EntityDef) extends EntityDecl { - - final def toString(sb: StringBuilder): StringBuilder = { + override def toString(sb: StringBuilder): StringBuilder = { sb.append("<!ENTITY % ").append( name ).append(' '); entdef.toString(sb).append('>'); } @@ -94,23 +87,20 @@ case class ParameterEntityDecl(name: String, entdef: EntityDef) extends EntityDe /** an unparsed entity declaration */ case class UnparsedEntityDecl( name:String, extID:ExternalID, notation:String ) extends EntityDecl { - final def toString(sb: StringBuilder): StringBuilder = { + override def toString(sb: StringBuilder): StringBuilder = { sb.append("<!ENTITY ").append( name ).append(' '); extID.toString(sb).append(" NDATA ").append(notation).append('>'); } } /** a notation declaration */ case class NotationDecl( name:String, extID:ExternalID ) extends MarkupDecl { - final def toString(sb: StringBuilder): StringBuilder = { + override def toString(sb: StringBuilder): StringBuilder = { sb.append("<!NOTATION ").append( name ).append(' '); extID.toString(sb); } } abstract class EntityDef { - final override def toString(): String = - toString(new StringBuilder()).toString(); - def toString(sb: StringBuilder): StringBuilder; } @@ -135,13 +125,13 @@ case class IntDef(value:String) extends EntityDef { } validateValue(); - final def toString(sb: StringBuilder): StringBuilder = + override def toString(sb: StringBuilder): StringBuilder = Utility.appendQuoted(value, sb); } case class ExtDef(extID:ExternalID) extends EntityDef { - final def toString(sb: StringBuilder): StringBuilder = + override def toString(sb: StringBuilder): StringBuilder = extID.toString(sb); } @@ -152,7 +142,7 @@ case class PEReference(ent:String) extends MarkupDecl { if( !Utility.isName( ent )) throw new IllegalArgumentException("ent must be an XML Name"); - final def toString(sb: StringBuilder): StringBuilder = + override def toString(sb: StringBuilder): StringBuilder = sb.append('%').append(ent).append(';'); } @@ -165,20 +155,20 @@ abstract class DefaultDecl { } case object REQUIRED extends DefaultDecl { - final override def toString(): String = "#REQUIRED"; - final def toString(sb:StringBuilder) = sb.append("#REQUIRED"); + override def toString(): String = "#REQUIRED"; + override def toString(sb:StringBuilder) = sb.append("#REQUIRED"); } case object IMPLIED extends DefaultDecl { - final override def toString(): String = "#IMPLIED"; - final def toString(sb:StringBuilder) = sb.append("#IMPLIED"); + override def toString(): String = "#IMPLIED"; + override def toString(sb:StringBuilder) = sb.append("#IMPLIED"); } case class DEFAULT(fixed: Boolean, attValue:String) extends DefaultDecl { - final override def toString(): String = + override def toString(): String = toString(new StringBuilder()).toString(); - final def toString(sb:StringBuilder): StringBuilder = { + override def toString(sb:StringBuilder): StringBuilder = { if(fixed) sb.append("#FIXED "); Utility.appendEscapedQuoted( attValue, sb ); diff --git a/src/library/scala/xml/dtd/ExternalID.scala b/src/library/scala/xml/dtd/ExternalID.scala index 6fa5d4823d..304c8b01e0 100644 --- a/src/library/scala/xml/dtd/ExternalID.scala +++ b/src/library/scala/xml/dtd/ExternalID.scala @@ -9,7 +9,7 @@ // $Id$ -package scala.xml.dtd; +package scala.xml.dtd import compat.StringBuilder @@ -24,12 +24,12 @@ import compat.StringBuilder abstract class ExternalID { /** returns "PUBLIC "+publicLiteral+" SYSTEM "+systemLiteral */ - override def toString(): String; + override def toString(): String /** returns "PUBLIC "+publicLiteral+" SYSTEM "+systemLiteral */ - def toString(sb: StringBuilder): StringBuilder; + def toString(sb: StringBuilder): StringBuilder - def systemId: String; + def systemId: String } @@ -44,13 +44,13 @@ case class SystemID( systemId:String ) extends ExternalID with parsing.TokenTest if( !checkSysID( systemId ) ) throw new IllegalArgumentException( "can't use both \" and ' in systemLiteral" - ); + ) /** returns " SYSTEM "+systemLiteral */ - final override def toString() = - Utility.systemLiteralToString( systemId ); + override def toString() = + Utility.systemLiteralToString( systemId ) - final def toString(sb: StringBuilder): StringBuilder = - Utility.systemLiteralToString( sb, systemId ); + override def toString(sb: StringBuilder): StringBuilder = + Utility.systemLiteralToString( sb, systemId ) } @@ -61,38 +61,30 @@ case class SystemID( systemId:String ) extends ExternalID with parsing.TokenTest * @param systemLiteral (can be null for notation pubIDs) the system identifier literal **/ case class PublicID( publicId:String, systemId:String ) extends ExternalID with parsing.TokenTests{ - //Console.println("constructing PublicID \""+publicLiteral+"\" "+systemLiteral); - - //Console.println("util returns "+checkPubID( publicLiteral )); if( !checkPubID( publicId )) throw new IllegalArgumentException( "publicId must consist of PubidChars" - ); + ) if( systemId != null && !checkSysID( systemId ) ) throw new IllegalArgumentException( "can't use both \" and ' in systemId" - ); + ) /** the constant "#PI" */ - final def label = "#PI"; + def label = "#PI" /** always empty */ - final def attribute = Node.NoAttributes; + def attribute = Node.NoAttributes /** always empty */ - final def child = Nil; - - /** returns "PUBLIC "+publicId+" SYSTEM "+systemId */ - final override def toString(): String = { - toString(new StringBuilder()).toString(); - } + def child = Nil /** appends "PUBLIC "+publicId+" SYSTEM "+systemId to argument */ - final def toString(sb: StringBuilder): StringBuilder = { - Utility.publicLiteralToString( sb, publicId ).append(' '); + override def toString(sb: StringBuilder): StringBuilder = { + Utility.publicLiteralToString( sb, publicId ).append(' ') if(systemId!=null) - Utility.systemLiteralToString( sb, systemId ); + Utility.systemLiteralToString( sb, systemId ) else sb } diff --git a/test/files/run/caseclasses.scala b/test/files/run/caseclasses.scala index 7b9aa2e582..e064ba859f 100644 --- a/test/files/run/caseclasses.scala +++ b/test/files/run/caseclasses.scala @@ -12,14 +12,14 @@ object Test extends Application { } try { - Bar() caseElement 2 + Bar() element 3 throw new NullPointerException("duh") } catch { case x:IndexOutOfBoundsException => } try { - f(2) caseElement 2 + f(2) element 3 throw new NullPointerException("duh") } catch { case x:IndexOutOfBoundsException => diff --git a/test/files/run/misc.scala b/test/files/run/misc.scala index 7838328d4b..b705606342 100644 --- a/test/files/run/misc.scala +++ b/test/files/run/misc.scala @@ -222,12 +222,12 @@ Console.println; Console.println( true // Foo(3,'a',Bar()).caseElement( -1 ) == null // throws Exception now - && Foo(3,'a',Bar()).caseElement( 0 ) == 3 - && Foo(3,'a',Bar()).caseElement( 1 ) == 'a' - && Foo(3,'a',Bar()).caseElement( 2 ) == Bar() + && Foo(3,'a',Bar()).element( 1 ) == 3 + && Foo(3,'a',Bar()).element( 2 ) == 'a' + && Foo(3,'a',Bar()).element( 3 ) == Bar() && true // Foo(3,'a',Bar()).caseElement( 3 ) == null // throws Exception now - && Bar().caseArity == 0 - && Foo(3,'a',Bar()).caseArity == 3); + && Bar().arity == 0 + && Foo(3,'a',Bar()).arity == 3); //############################################################################ |