@@ -7,6 +7,7 @@ import rx.util.functions._
7
7
import scala .collection .SortedSet
8
8
import scala .collection .SortedMap
9
9
import org .junit .Ignore
10
+ import java .lang .reflect .Modifier
10
11
11
12
class CompletenessTest extends JUnitSuite {
12
13
@@ -65,22 +66,50 @@ class CompletenessTest extends JUnitSuite {
65
66
// declarations: => only those declared in Observable
66
67
// members => also those of superclasses
67
68
methodMembersToMethodStrings(tp.declarations.filter(m => m.isMethod && m.isPublic))
69
+ // TODO how can we filter out instance methods which were put into companion because
70
+ // of extends AnyVal in a way which does not depend on implementation-chosen name '$extension'?
71
+ .filter(! _.contains(" $extension" ))
68
72
}
69
73
70
- def getStaticMethods (tp : Type ): Iterable [String ] = {
71
- ???
72
- }
74
+ def getStaticJavaMethods (className : String ): Iterable [String ] = {
75
+ val c = Class .forName(className)
76
+ for (method <- c.getMethods() if Modifier .isStatic(method.getModifiers)) yield {
77
+ method.getName + method.getParameterTypes().map(_.getSimpleName()).mkString(" (" , " , " , " )" )
78
+ }
79
+ }
80
+
81
+ def getObservableCompanionMethods : Iterable [String ] = {
82
+ val tp = typeOf[rx.lang.scala.Observable .type ]
83
+ getPublicInstanceMethods(tp.typeSymbol.companionSymbol.typeSignature)
84
+ // TODO how can we filter out instance methods which were put into companion because
85
+ // of extends AnyVal in a way which does not depend on implementation-chosen name '$extension'?
86
+ .filter(! _.contains(" $extension" ))
87
+ }
88
+
89
+ def printMethodSet (title : String , tp : Type ) {
90
+ println(" \n " + title)
91
+ println(title.map(_ => '-' ) + " \n " )
92
+ getPublicInstanceMethods(tp).toList.sorted.foreach(println(_))
93
+ }
73
94
74
95
@ Test def printJavaInstanceMethods : Unit = {
75
- println(" \n Instance methods of rx.Observable" )
76
- println( " ---------------------------------\n " )
77
- getPublicInstanceMethods(typeOf[rx.Observable [_]]).toList.sorted.foreach(println(_))
96
+ printMethodSet(" Instance methods of rx.Observable" ,
97
+ typeOf[rx.Observable [_]])
78
98
}
79
99
80
100
@ Test def printScalaInstanceMethods : Unit = {
81
- println(" \n Instance methods of rx.lang.scala.Observable" )
82
- println( " --------------------------------------------\n " )
83
- getPublicInstanceMethods(typeOf[rx.lang.scala.Observable [_]]).toList.sorted.foreach(s => println(s))
101
+ printMethodSet(" Instance methods of rx.lang.scala.Observable" ,
102
+ typeOf[rx.lang.scala.Observable [_]])
103
+ }
104
+
105
+ @ Test def printJavaStaticMethods : Unit = {
106
+ printMethodSet(" Static methods of rx.Observable" ,
107
+ typeOf[rx.Observable [_]].typeSymbol.companionSymbol.typeSignature)
108
+ }
109
+
110
+ @ Test def printScalaCompanionMethods : Unit = {
111
+ printMethodSet(" Companion methods of rx.lang.scala.Observable" ,
112
+ typeOf[rx.lang.scala.Observable .type ])
84
113
}
85
114
86
115
def javaMethodSignatureToScala (s : String ): String = {
@@ -113,13 +142,6 @@ class CompletenessTest extends JUnitSuite {
113
142
}
114
143
}
115
144
116
- @ Ignore // Does not yet work
117
- @ Test def printJavaStaticMethods : Unit = {
118
- println(" \n Static methods of rx.Observable" )
119
- println( " -------------------------------\n " )
120
- getStaticMethods(typeOf[rx.Observable [_]]).toList.sorted.foreach(println(_))
121
- }
122
-
123
145
def checkMethodPresence (expectedMethods : Iterable [String ], tp : Type ): Unit = {
124
146
val actualMethods = getPublicInstanceMethods(tp).toSet
125
147
val expMethodsSorted = expectedMethods.toList.sorted
0 commit comments