KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > classfile > CPMethodInfo


1 /*
2  * CPMethodInfo.java
3  *
4  * The contents of this file are subject to the terms of the Common Development
5  * and Distribution License (the License). You may not use this file except in
6  * compliance with the License.
7  *
8  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
9  * or http://www.netbeans.org/cddl.txt.
10  *
11  * When distributing Covered Code, include this CDDL Header Notice in each file
12  * and include the License file at http://www.netbeans.org/cddl.txt.
13  * If applicable, add the following below the CDDL Header, with the fields
14  * enclosed by brackets [] replaced by your own identifying information:
15  * "Portions Copyrighted [year] [name of copyright owner]"
16  *
17  * The Original Software is NetBeans. The Initial Developer of the Original
18  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
19  * Microsystems, Inc. All Rights Reserved.
20  *
21  * Contributor(s): Thomas Ball
22  *
23  * Version: $Revision: 1.5 $
24  */

25
26 package org.netbeans.modules.classfile;
27
28
29 /**
30  * A class representing the CONSTANT_Methodref constant pool type.
31  *
32  * @author Thomas Ball
33  */

34 public class CPMethodInfo extends CPFieldMethodInfo {
35     CPMethodInfo(ConstantPool pool,int iClass,int iNameAndType) {
36         super(pool, iClass, iNameAndType);
37     }
38
39     public final String JavaDoc getMethodName() {
40     return getFieldName();
41     }
42
43     /**
44      * Get method name and signature, such as "void setBar(Bar)".
45      */

46     public final String JavaDoc getFullMethodName() {
47         return getFullMethodName(getMethodName(), getDescriptor());
48     }
49     
50     static String JavaDoc getFullMethodName(String JavaDoc name, String JavaDoc signature) {
51         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
52         int index = signature.indexOf(')');
53         String JavaDoc params = signature.substring(1, index);
54         
55         if (!"<init>".equals(name) && !"<clinit>".equals(name)) {
56             String JavaDoc ret = signature.substring(index + 1);
57             ret = CPFieldMethodInfo.getSignature(ret, false);
58             if (ret.length() > 0) {
59                 sb.append(ret);
60                 sb.append(' ');
61             }
62         }
63         sb.append(name);
64         sb.append('(');
65         index = 0;
66         int paramsLength = params.length();
67         while (index < paramsLength) {
68             StringBuffer JavaDoc p = new StringBuffer JavaDoc();
69             char ch = params.charAt(index++);
70             while (ch == '[') {
71                 p.append(ch);
72                 ch = params.charAt(index++);
73             }
74             p.append(ch);
75             if (ch == 'L')
76                 do {
77                     ch = params.charAt(index++);
78                     p.append(ch);
79                 } while (ch != ';');
80             sb.append(CPFieldMethodInfo.getSignature(p.toString(), false));
81             if (index < paramsLength)
82                 sb.append(',');
83         }
84         sb.append(')');
85         return sb.toString();
86     }
87
88     public int getTag() {
89     return ConstantPool.CONSTANT_MethodRef;
90     }
91 }
92
Popular Tags