1    
2    /*
3    
4      The author of this software is Ian Kaplan
5      Bear Products International
6      www.bearcave.com
7      iank@bearcave.com
8    
9      Copyright (c) Ian Kaplan, 1999, 2000
10   
11     See copyright file for usage and licensing
12   
13   */
14   
15   package jconst;
16   
17   import java.io.*;
18   import util.*;
19   
20   /** 
21   
22      The constRef object represents CONSTANT_FieldRef,
23      CONSTANT_MethodRef and CONSTANT_InterfaceMethodRef.
24      The format is
25   <pre>
26        CONSTANT_<>ref_info {
27          u1 tag;
28          u2 index;
29          u2 name_and_type_index
30        }
31   </pre>
32   <p>
33        index must be a an index in the constant table for a
34        constClass_or_String object.
35   <p>
36        The name_and_type_index must be an index in the constant
37        table for a constName_and_type_info object.
38    <p>
39        Note that this class is not derived from the constClass_or_String
40        since the reference pointers do not point to constUtf8 classes.
41   
42   
43    */
44   public class constRef extends constBase {
45     int index;
46     int name_and_type_index;
47     constClass_or_String class_ref;
48     constName_and_Type_info name_ref;
49   
50     public void read( DataInputStream dStream ) {
51       index = readU2( dStream );
52       name_and_type_index = readU2( dStream );
53     }
54   
55     public void set_ref(constBase objAry[] ) {
56       constBase tmp = objAry[ index ];
57   
58       if (tmp instanceof constClass_or_String) {
59         class_ref = (constClass_or_String)tmp;
60       }
61       else {
62         System.out.println("object at const. pool index " + index + 
63   			 " is not a constClass_or_String");
64       }
65   
66       tmp = objAry[ name_and_type_index ];
67       if (tmp instanceof constName_and_Type_info) {
68         name_ref = (constName_and_Type_info)tmp;
69       }
70       else {
71         System.out.println("object at const. pool index " + index + 
72   			 " is not a constName_and_Type_info");
73       }
74     } // set_ref    
75   
76   
77     public String getString() {
78       StringBuffer str = new StringBuffer();
79   
80       str.append( super.getString() );
81       str.append(": ");
82       if (class_ref != null) {
83         str.append( class_ref.getString() );
84       }
85       else
86         str.append("null ref");
87   
88       str.append(", ");
89   
90       if (name_ref != null) {
91         str.append( name_ref.getString() );
92       }
93       else
94         str.append("null ref");
95       return str.toString();
96     } // getString
97   
98   
99     public void pr() {
100      System.out.print( getString() );
101    } // pr
102  
103  } // constRef
104