diff options
author | Paul Phillips <paulp@improving.org> | 2011-12-09 11:52:56 -0800 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2011-12-09 11:52:56 -0800 |
commit | 04d13e6071b5daa0106d80c146048a148d7fad13 (patch) | |
tree | 88ab73a21bdb1516ac68eb1395ad6ba0de52c7c2 /test/disabled/properties | |
parent | a8c98041482f44750cad023dc13f43a26bd0d64a (diff) | |
download | scala-04d13e6071b5daa0106d80c146048a148d7fad13.tar.gz scala-04d13e6071b5daa0106d80c146048a148d7fad13.tar.bz2 scala-04d13e6071b5daa0106d80c146048a148d7fad13.zip |
Disabled another presentation compiler test.
It foiled me right on the cusp of a successful windows nightly.
https://scala-webapps.epfl.ch/jenkins/job/scala-nightly-windows/1170/consoleText
Diffstat (limited to 'test/disabled/properties')
-rw-r--r-- | test/disabled/properties/Runner.scala | 3 | ||||
-rw-r--r-- | test/disabled/properties/src/properties.scala | 54 |
2 files changed, 57 insertions, 0 deletions
diff --git a/test/disabled/properties/Runner.scala b/test/disabled/properties/Runner.scala new file mode 100644 index 0000000000..1ef3cf9025 --- /dev/null +++ b/test/disabled/properties/Runner.scala @@ -0,0 +1,3 @@ +import scala.tools.nsc.interactive.tests._ + +object Test extends InteractiveTest
\ No newline at end of file diff --git a/test/disabled/properties/src/properties.scala b/test/disabled/properties/src/properties.scala new file mode 100644 index 0000000000..35b6a92221 --- /dev/null +++ b/test/disabled/properties/src/properties.scala @@ -0,0 +1,54 @@ +/** Illustrate the use of custom 'apply/update' methods. */ +object properties { + + /** A mutable property whose getter and setter may be customized. */ + case class Property[T](init: T) { + private var value: T = init + + /** The getter function, defaults to identity. */ + private var setter: T => T = identity[T] + + /** The setter function, defaults to identity. */ + private var getter: T => T = identity[T] + + /** Retrive the value held in this property. */ + def apply(): T = getter(value) + + /** Update the value held in this property, through the setter. */ + def update(newValue: T) /*?*/ = value = setter(newValue) + + /** Change the getter. */ + def get(newGetter: T => T) /*?*/ = { getter = newGetter; this } + + /** Change the setter */ + def set(newSetter: T => T) = { setter = newSetter; this } + } + + class User { + // Create a property with custom getter and setter + val firstname = Property("")./*!*/get { v => v.toUpperCase() }./*!*/set { v => "Mr. " + v } + val lastname = Property("<noname>") + + /** Scala provides syntactic sugar for calling 'apply'. Simply + * adding a list of arguments between parenthesis (in this case, + * an empty list) is translated to a call to 'apply' with those + * arguments. + */ + override def toString() = firstname() + " " + lastname() + } + + def main(args: Array[String]) { + val user1 = new User + + // Syntactic sugar for 'update': an assignment is translated to a + // call to method 'update' + user1./*!*/firstname() = "Robert" + + val user2 = new User + user2.firstname() = "bob" + user2.lastname() = "KUZ" + + println("user1: " + user1) + println("user2: " + user2) + } +}
\ No newline at end of file |