renamed Type.fromDescriptor() to Type.instance()
[org.ibex.classgen.git] / src / org / ibex / classgen / MethodRef.java
1 package org.ibex.classgen;
2
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
9 */
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.Class c, String name, Type ret, Type[] args) {
14         super(c, name, getDescriptor(ret, args));
15     }
16     /** Equivalent to MethodRef(new Type.Class(s), ...)
17         @see #MethodRef(Type.Class, String, Type, Type[])
18     */
19     public MethodRef(String s, String name, Type ret, Type[] args) {
20         this(Type.instance(s).asClass(), name, ret, args);
21     }
22     MethodRef(MethodRef i) { super(i); }
23     
24     static String getDescriptor(Type ret, Type[] args) {
25         StringBuffer sb = new StringBuffer(args.length*4);
26         sb.append("(");
27         for(int i=0;i<args.length;i++) sb.append(args[i].getDescriptor());
28         sb.append(")");
29         sb.append(ret.getDescriptor());
30         return sb.toString();
31     }
32     
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.Class 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); }
41     }
42 }