2929package gr .gousiosg .javacg .stat ;
3030
3131import org .apache .bcel .classfile .JavaClass ;
32- import org .apache .bcel .generic .ConstantPoolGen ;
33- import org .apache .bcel .generic .ConstantPushInstruction ;
34- import org .apache .bcel .generic .EmptyVisitor ;
35- import org .apache .bcel .generic .INVOKEINTERFACE ;
36- import org .apache .bcel .generic .INVOKESPECIAL ;
37- import org .apache .bcel .generic .INVOKESTATIC ;
38- import org .apache .bcel .generic .INVOKEVIRTUAL ;
39- import org .apache .bcel .generic .Instruction ;
40- import org .apache .bcel .generic .InstructionConstants ;
41- import org .apache .bcel .generic .InstructionHandle ;
42- import org .apache .bcel .generic .MethodGen ;
43- import org .apache .bcel .generic .ReturnInstruction ;
32+ import org .apache .bcel .generic .*;
4433
4534/**
4635 * The simplest of method visitors, prints any invoked method
@@ -59,8 +48,19 @@ public MethodVisitor(MethodGen m, JavaClass jc) {
5948 visitedClass = jc ;
6049 mg = m ;
6150 cp = mg .getConstantPool ();
62- format = "M:" + visitedClass .getClassName () + ":" + mg .getName ()
63- + " " + "(%s)%s:%s" ;
51+ format = "M:" + visitedClass .getClassName () + ":" + mg .getName () + "(" + argumentList (mg .getArgumentTypes ()) + ")"
52+ + " " + "(%s)%s:%s(%s)" ;
53+ }
54+
55+ private String argumentList (Type [] arguments ) {
56+ StringBuilder sb = new StringBuilder ();
57+ for (int i = 0 ; i < arguments .length ; i ++) {
58+ if (i != 0 ) {
59+ sb .append ("," );
60+ }
61+ sb .append (arguments [i ].toString ());
62+ }
63+ return sb .toString ();
6464 }
6565
6666 public void start () {
@@ -85,21 +85,21 @@ private boolean visitInstruction(Instruction i) {
8585
8686 @ Override
8787 public void visitINVOKEVIRTUAL (INVOKEVIRTUAL i ) {
88- System .out .println (String .format (format ,"M" ,i .getReferenceType (cp ),i .getMethodName (cp )));
88+ System .out .println (String .format (format ,"M" ,i .getReferenceType (cp ),i .getMethodName (cp ), argumentList ( i . getArgumentTypes ( cp )) ));
8989 }
9090
9191 @ Override
9292 public void visitINVOKEINTERFACE (INVOKEINTERFACE i ) {
93- System .out .println (String .format (format ,"I" ,i .getReferenceType (cp ),i .getMethodName (cp )));
93+ System .out .println (String .format (format ,"I" ,i .getReferenceType (cp ),i .getMethodName (cp ), argumentList ( i . getArgumentTypes ( cp )) ));
9494 }
9595
9696 @ Override
9797 public void visitINVOKESPECIAL (INVOKESPECIAL i ) {
98- System .out .println (String .format (format ,"O" ,i .getReferenceType (cp ),i .getMethodName (cp )));
98+ System .out .println (String .format (format ,"O" ,i .getReferenceType (cp ),i .getMethodName (cp ), argumentList ( i . getArgumentTypes ( cp )) ));
9999 }
100100
101101 @ Override
102102 public void visitINVOKESTATIC (INVOKESTATIC i ) {
103- System .out .println (String .format (format ,"S" ,i .getReferenceType (cp ),i .getMethodName (cp )));
103+ System .out .println (String .format (format ,"S" ,i .getReferenceType (cp ),i .getMethodName (cp ), argumentList ( i . getArgumentTypes ( cp )) ));
104104 }
105105}
0 commit comments