summaryrefslogtreecommitdiff
path: root/src/partest/scala/tools/partest/AsmNode.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2013-02-08 13:52:58 -0800
committerPaul Phillips <paulp@improving.org>2013-02-08 17:41:23 -0800
commit22341e7ab9722cf212c01e9830014648849f8e70 (patch)
tree18cab6ae1c9bd6ecf429723a4c726c3491a22577 /src/partest/scala/tools/partest/AsmNode.scala
parent6537d79e47def868e028815db6f70e2dc7d49bac (diff)
downloadscala-22341e7ab9722cf212c01e9830014648849f8e70.tar.gz
scala-22341e7ab9722cf212c01e9830014648849f8e70.tar.bz2
scala-22341e7ab9722cf212c01e9830014648849f8e70.zip
Expanded bytecode testing code.
def sameMethodAndFieldSignatures compares two classes to verify they have all the same methods and fields, and no others.
Diffstat (limited to 'src/partest/scala/tools/partest/AsmNode.scala')
-rw-r--r--src/partest/scala/tools/partest/AsmNode.scala60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/partest/scala/tools/partest/AsmNode.scala b/src/partest/scala/tools/partest/AsmNode.scala
new file mode 100644
index 0000000000..d181436676
--- /dev/null
+++ b/src/partest/scala/tools/partest/AsmNode.scala
@@ -0,0 +1,60 @@
+package scala.tools.partest
+
+import scala.collection.JavaConverters._
+import scala.tools.asm
+import asm._
+import asm.tree._
+import java.lang.reflect.Modifier
+
+sealed trait AsmNode[+T] {
+ def node: T
+ def access: Int
+ def desc: String
+ def name: String
+ def signature: String
+ def attrs: List[Attribute]
+ def visibleAnnotations: List[AnnotationNode]
+ def invisibleAnnotations: List[AnnotationNode]
+ def characteristics = f"$name%15s $desc%-30s$accessString$sigString"
+
+ private def accessString = if (access == 0) "" else " " + Modifier.toString(access)
+ private def sigString = if (signature == null) "" else " " + signature
+ override def toString = characteristics
+}
+
+object AsmNode {
+ type AsmMethod = AsmNode[MethodNode]
+ type AsmField = AsmNode[FieldNode]
+ type AsmMember = AsmNode[_]
+
+ implicit class ClassNodeOps(val node: ClassNode) {
+ def fieldsAndMethods: List[AsmMember] = {
+ val xs: List[AsmMember] = (
+ node.methods.asScala.toList.map(x => (x: AsmMethod))
+ ++ node.fields.asScala.toList.map(x => (x: AsmField))
+ )
+ xs sortBy (_.characteristics)
+ }
+ }
+ implicit class AsmMethodNode(val node: MethodNode) extends AsmNode[MethodNode] {
+ def access: Int = node.access
+ def desc: String = node.desc
+ def name: String = node.name
+ def signature: String = node.signature
+ def attrs: List[Attribute] = node.attrs.asScala.toList
+ def visibleAnnotations: List[AnnotationNode] = node.visibleAnnotations.asScala.toList
+ def invisibleAnnotations: List[AnnotationNode] = node.invisibleAnnotations.asScala.toList
+ }
+ implicit class AsmFieldNode(val node: FieldNode) extends AsmNode[FieldNode] {
+ def access: Int = node.access
+ def desc: String = node.desc
+ def name: String = node.name
+ def signature: String = node.signature
+ def attrs: List[Attribute] = node.attrs.asScala.toList
+ def visibleAnnotations: List[AnnotationNode] = node.visibleAnnotations.asScala.toList
+ def invisibleAnnotations: List[AnnotationNode] = node.invisibleAnnotations.asScala.toList
+ }
+
+ def apply(node: MethodNode): AsmMethodNode = new AsmMethodNode(node)
+ def apply(node: FieldNode): AsmFieldNode = new AsmFieldNode(node)
+}