1 package org.ibex.classgen;
3 /** This class represents Method references. It is used as an argument to the
4 INVOKESTATIC, INVOKEVIRTUAL, INVOKESPEICAL, and INVOKEINTERFACE bytecodes
5 @see CGConst#INVOKESTATIC
6 @see CGConst#INVOKEVIRTUAL
7 @see CGConst#INVOKESPECIAL
8 @see CGConst#INVOKEINTERFACE
10 public class MethodRef extends ClassGen.FieldOrMethodRef {
11 /** Create a reference to method <i>name</i> of class <i>c</i> with the return type <i>ret</i> and the
12 arguments <i>args</i> */
13 public MethodRef(Type.Object c, String name, Type ret, Type[] args) {
14 super(c, name, getDescriptor(ret, args));
16 /** Equivalent to MethodRef(new Type.Object(s), ...)
17 @see #MethodRef(Type.Object, String, Type, Type[])
19 public MethodRef(String s, String name, Type ret, Type[] args) {
20 this(Type.fromDescriptor(s).asObject(), name, ret, args);
22 MethodRef(MethodRef i) { super(i); }
24 static String getDescriptor(Type ret, Type[] args) {
25 StringBuffer sb = new StringBuffer(args.length*4);
27 for(int i=0;i<args.length;i++) sb.append(args[i].getDescriptor());
29 sb.append(ret.getDescriptor());
33 /** MethodRef class used for the INVOKEINTERFACE bytecode. Although this contains the same
34 data as a normal MethodRef, these are treated differently in the byte code format. In general,
35 users don't need to be concerned with this though because MethodRef's are automatically converted
36 to MethodRef.I's when they are applied to an INVOKEINTERFACE bytecode */
37 public static class I extends MethodRef {
38 public I(Type.Object c, String name, Type ret, Type[] args) { super(c, name, ret, args); }
39 public I(String s, String name, Type ret, Type[] args) { super(s, name, ret, args); }
40 I(MethodRef m) { super(m); }