View Javadoc

1   /*
2    * Copyright 2005 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at 
7    * 
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software 
11   * distributed under the License is distributed on an "AS IS" BASIS, 
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
13   * See the License for the specific language governing permissions and 
14   * limitations under the License.
15   */
16  
17  
18  package org.apache.jdo.impl.enhancer.classfile;
19  
20  import java.io.*;
21  import java.util.Stack;
22  
23  /***
24   * Abstract base class of the types which represent entries in
25   * the class constant pool.
26   */
27  abstract public class ConstBasic implements VMConstants {
28      /* The index of the constant entry in the constant pool */
29      protected int index = 0;
30  
31      /* public accessors */
32  
33      /* Get the index of this constant entry */
34      public int getIndex() { return index; }
35  
36      /* Return the type of the constant entry - see VMConstants */
37      public abstract int tag();
38  
39      /* package local methods *//package-summary/html">class="comment"> package local methods *//package-summary.html">/* package local methods *//package-summary.html">class="comment"> package local methods */
40  
41      /***
42       * Sets the index of this constant with its containing constant pool
43       */
44      void setIndex(int ind) { index = ind; }
45  
46      /***
47       * Write this Constant pool entry to the output stream
48       */
49      abstract void formatData(DataOutputStream b) throws IOException;
50  
51      /***
52       * Resolve integer index references to the actual constant pool
53       * entries that they represent.  This is used during class file 
54       * reading because a constant pool entry could have a forward
55       * reference to a higher numbered constant.
56       */
57      abstract void resolve(ConstantPool p);
58  
59      /***
60       * Return the index of this constant in the constant pool as
61       * a decimal formatted String.
62       */
63      String indexAsString() { return Integer.toString(index); }
64  
65      /***
66       * The constructor for subtypes
67       */
68      ConstBasic() {}
69  
70      /***
71       * Compares this instance with another for structural equality.
72       */
73      //@olsen: added method
74      public boolean isEqual(Stack msg, Object obj) {
75          if (!(obj instanceof ConstBasic)) {
76              msg.push("obj/obj.getClass() = "
77                       + (obj == null ? null : obj.getClass()));
78              msg.push("this.getClass() = "
79                       + this.getClass());
80              return false;
81          }
82          ConstBasic other = (ConstBasic)obj;
83  
84          return true;
85      }
86  }