@@ -3,9 +3,10 @@ package scala.tools.partest
33import scala .tools .nsc .util .JavaClassPath
44import scala .collection .JavaConverters ._
55import scala .tools .asm
6- import asm .ClassReader
6+ import asm .{ ClassReader }
77import asm .tree .{ClassNode , MethodNode , InsnList }
88import java .io .InputStream
9+ import AsmNode ._
910
1011/**
1112 * Provides utilities for inspecting bytecode using ASM library.
@@ -29,21 +30,47 @@ import java.io.InputStream
2930 *
3031 */
3132abstract class BytecodeTest extends ASMConverters {
33+ import instructions ._
3234
3335 /** produce the output to be compared against a checkfile */
3436 protected def show (): Unit
3537
3638 def main (args : Array [String ]): Unit = show
3739
38- // asserts
40+ // asserts
3941 def sameBytecode (methA : MethodNode , methB : MethodNode ) = {
4042 val isa = instructions.fromMethod(methA)
4143 val isb = instructions.fromMethod(methB)
4244 if (isa == isb) println(" bytecode identical" )
4345 else diffInstructions(isa, isb)
4446 }
4547
46- import instructions ._
48+ // Do these classes have all the same methods, with the same names, access,
49+ // descriptors and generic signatures? Method bodies are not considered, and
50+ // the names of the classes containing the methods are substituted so they do
51+ // not appear as differences.
52+ def sameMethodAndFieldSignatures (clazzA : ClassNode , clazzB : ClassNode ): Boolean = {
53+ val ms1 = clazzA.fieldsAndMethods.toIndexedSeq
54+ val ms2 = clazzB.fieldsAndMethods.toIndexedSeq
55+ val name1 = clazzA.name
56+ val name2 = clazzB.name
57+
58+ if (ms1.length != ms2.length) {
59+ println(" Different member counts in $name1 and $name2" )
60+ false
61+ }
62+ else (ms1, ms2).zipped forall { (m1, m2) =>
63+ val c1 = m1.characteristics
64+ val c2 = m2.characteristics.replaceAllLiterally(name2, name1)
65+ if (c1 == c2)
66+ println(s " [ok] $m1" )
67+ else
68+ println(s " [fail] \n in $name1: $c1\n in $name2: $c2" )
69+
70+ c1 == c2
71+ }
72+ }
73+
4774 // bytecode is equal modulo local variable numbering
4875 def equalsModuloVar (a : Instruction , b : Instruction ) = (a, b) match {
4976 case _ if a == b => true
0 commit comments