399195ccb54aeef9eafb8becc09c38cd753b8b3c
[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 MemberRef {
11     
12     final Type[] argTypes;
13     final Type   returnType;
14
15     /** Create a reference to method <i>name</i> of class <i>c</i> with the return type <i>ret</i> and the
16         arguments <i>args</i> */
17     public MethodRef(Type.Class c, String name, Type returnType, Type[] argTypes) {
18         super(c, name);
19         this.argTypes = argTypes;
20         this.returnType = returnType;
21     }
22     
23     public String getDescriptor() {
24         StringBuffer sb = new StringBuffer(argTypes.length*4);
25         sb.append("(");
26         for(int i=0;i<argTypes.length;i++) sb.append(argTypes[i].getDescriptor());
27         sb.append(")");
28         sb.append(returnType.getDescriptor());
29         return sb.toString();
30     }
31     
32     /** MethodRef class used for the INVOKEINTERFACE bytecode. Although this contains the same
33         data as a normal MethodRef, these are treated differently in the byte code format. In general,
34         users don't need to be concerned with this though because MethodRef's are automatically converted
35         to MethodRef.I's when they are applied to an INVOKEINTERFACE bytecode */
36     public static class I extends MethodRef {
37         public I(Type.Class c, String name, Type ret, Type[] args) { super(c, name, ret, args); }
38     }
39 }