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  package org.apache.commons.compress.harmony.unpack200.bytecode;
18  
19  import java.io.DataOutputStream;
20  import java.io.IOException;
21  
22  /**
23   * Abstract superclass for constant pool entries
24   */
25  public abstract class ConstantPoolEntry extends ClassFileEntry {
26  
27      public static final byte CP_Class = 7;
28  
29      public static final byte CP_Double = 6;
30  
31      public static final byte CP_Fieldref = 9;
32  
33      public static final byte CP_Float = 4;
34  
35      public static final byte CP_Integer = 3;
36  
37      /*
38       * class MemberRef extends ConstantPoolEntry { private int index; Class(String name) { super(CP_Class); index = pool.indexOf(name); } void
39       * writeBody(DataOutputStream dos) throws IOException { dos.writeShort(index); } }
40       */
41  
42      public static final byte CP_InterfaceMethodref = 11;
43  
44      public static final byte CP_Long = 5;
45  
46      public static final byte CP_Methodref = 10;
47  
48      public static final byte CP_NameAndType = 12;
49  
50      public static final byte CP_String = 8;
51  
52      public static final byte CP_UTF8 = 1;
53  
54      byte tag;
55  
56      protected int globalIndex;
57  
58      ConstantPoolEntry(final byte tag, final int globalIndex) {
59          this.tag = tag;
60          this.globalIndex = globalIndex;
61      }
62  
63      @Override
64      public void doWrite(final DataOutputStream dos) throws IOException {
65          dos.writeByte(tag);
66          writeBody(dos);
67      }
68  
69      @Override
70      public abstract boolean equals(Object obj);
71  
72      public int getGlobalIndex() {
73          return globalIndex;
74      }
75  
76      public byte getTag() {
77          return tag;
78      }
79  
80      @Override
81      public abstract int hashCode();
82  
83      protected abstract void writeBody(DataOutputStream dos) throws IOException;
84  }