View Javadoc

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