summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2009-05-19 12:39:00 +0000
committerPaul Phillips <paulp@improving.org>2009-05-19 12:39:00 +0000
commitaf9090a32aeb2a6db80767ae3ef10c484c63617d (patch)
treee1f1cf1fafc4bb92e0a6833a9cce627324c40f67 /test
parent54384172fe0a5a926a133f46aed0653bb59b054d (diff)
downloadscala-af9090a32aeb2a6db80767ae3ef10c484c63617d.tar.gz
scala-af9090a32aeb2a6db80767ae3ef10c484c63617d.tar.bz2
scala-af9090a32aeb2a6db80767ae3ef10c484c63617d.zip
Test case for #715.
Diffstat (limited to 'test')
-rw-r--r--test/files/pos/bug715/meredith_1.scala98
-rw-r--r--test/files/pos/bug715/runner_2.scala3
2 files changed, 101 insertions, 0 deletions
diff --git a/test/files/pos/bug715/meredith_1.scala b/test/files/pos/bug715/meredith_1.scala
new file mode 100644
index 0000000000..1443180fe9
--- /dev/null
+++ b/test/files/pos/bug715/meredith_1.scala
@@ -0,0 +1,98 @@
+package com.sap.dspace.model.othello;
+
+import scala.xml._
+
+trait XMLRenderer {
+ type T <: {def getClass() : java.lang.Class[_]}
+ val valueTypes =
+ List(
+ classOf[java.lang.Boolean],
+ classOf[java.lang.Integer],
+ classOf[java.lang.Float],
+ classOf[java.lang.String]
+ // more to come
+ )
+
+ def value2XML(
+ value : Object,
+ field : java.lang.reflect.Field,
+ pojo : T
+ ) : Node = {
+ value match {
+ case null => Text( "null" )
+ case vUnmatched =>
+ if (value.isInstanceOf[java.lang.Boolean])
+ Text( value.asInstanceOf[java.lang.Boolean].toString )
+ else if (value.isInstanceOf[java.lang.Integer])
+ Text( value.asInstanceOf[java.lang.Integer].toString )
+ else if (value.isInstanceOf[java.lang.Float])
+ Text( value.asInstanceOf[java.lang.Float].toString )
+ // else if (value.isInstanceOf[T])
+ // pojo2XML( value.asInstanceOf[T] )
+ else
+ <unmatchedType>
+ <theType>
+ {vUnmatched.getClass.toString}
+ </theType>
+ <theValue>
+ {vUnmatched.toString}
+ </theValue>
+ </unmatchedType>
+ }
+ }
+
+ def field2XML(
+ field : java.lang.reflect.Field,
+ pojo : T
+ ) : Elem = {
+
+ val accessible = field.isAccessible;
+ field.setAccessible( true );
+ // BUGBUG lgm need to disambiguate on type and possibly make
+ // recursive call to pojo2XML
+ val fldValXML = value2XML( field.get( pojo ), field, pojo );
+ field.setAccessible( accessible );
+
+ Elem(
+ null,
+ field.getName,
+ null,
+ TopScope,
+ fldValXML
+ )
+ }
+
+ def pojo2XML( pojo : T ) : Elem = {
+ val progeny =
+ for (field <- pojo.getClass.getDeclaredFields)
+ yield field2XML( field, pojo );
+
+ Elem(
+ null,
+ pojo.getClass.getName,
+ null,
+ TopScope,
+ progeny : _*
+ )
+ }
+}
+
+case class POJO2XMLRenderer( recurse : Boolean )
+ extends XMLRenderer {
+ type T = java.io.Serializable
+ override def value2XML(
+ value : Object,
+ field : java.lang.reflect.Field,
+ pojo : java.io.Serializable
+ ) : Node = {
+ if (recurse) super.value2XML( value, field, pojo )
+ else Text( value + "" )
+ }
+}
+
+object thePOJO2XMLRenderer extends POJO2XMLRenderer( true ) {
+}
+
+object Test extends Application {
+ println(com.sap.dspace.model.othello.thePOJO2XMLRenderer)
+} \ No newline at end of file
diff --git a/test/files/pos/bug715/runner_2.scala b/test/files/pos/bug715/runner_2.scala
new file mode 100644
index 0000000000..233b1bddb9
--- /dev/null
+++ b/test/files/pos/bug715/runner_2.scala
@@ -0,0 +1,3 @@
+object Test extends Application {
+ println(com.sap.dspace.model.othello.thePOJO2XMLRenderer)
+} \ No newline at end of file