KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > compiler > base > bcg > pool > Constant


1 /* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2  *
3  * This file is part of the compiler and core tools for the AspectJ(tm)
4  * programming language; see http://aspectj.org
5  *
6  * The contents of this file are subject to the Mozilla Public License
7  * Version 1.1 (the "License"); you may not use this file except in
8  * compliance with the License. You may obtain a copy of the License at
9  * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/.
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the
14  * License.
15  *
16  * The Original Code is AspectJ.
17  *
18  * The Initial Developer of the Original Code is Xerox Corporation. Portions
19  * created by Xerox Corporation are Copyright (C) 1999-2002 Xerox Corporation.
20  * All Rights Reserved.
21  *
22  * Contributor(s):
23  */

24
25 package org.aspectj.compiler.base.bcg.pool;
26
27 import org.aspectj.compiler.base.bcg.*;
28
29 import java.io.*;
30 import java.util.*;
31
32 import org.aspectj.compiler.base.ast.ArrayType;
33 import org.aspectj.compiler.base.ast.NameType;
34 import org.aspectj.compiler.base.ast.RefType;
35
36 public abstract class Constant implements Comparable JavaDoc {
37
38     static final byte UTF_TAG = 1;
39     static final byte INT_TAG = 3;
40     static final byte FLOAT_TAG = 4;
41     static final byte LONG_TAG = 5;
42     static final byte DOUBLE_TAG = 6;
43     static final byte CLASS_TAG = 7;
44     static final byte STRING_TAG = 8;
45     static final byte FIELD_REF_TAG = 9;
46     static final byte METHOD_REF_TAG = 10;
47     static final byte INTERFACE_METHOD_REF_TAG = 11;
48     static final byte NAME_AND_TYPE_TAG = 12;
49
50     private int index = 0;
51     private int popularity = 0;
52     public void makePopular() { popularity++; }
53
54     void setIndex(int index) { this.index = index; }
55     public short getIndex() { return (short)index; }
56     public void writeIndex(DataOutputStream stream) throws IOException {
57         stream.writeShort((short)index);
58     }
59     public void writeBriefIndex(DataOutputStream stream) throws IOException {
60         stream.writeByte((byte)index);
61     }
62     abstract void writeTo(DataOutputStream stream) throws IOException;
63     abstract void readFrom(DataInputStream stream, ConstantPool pool) throws IOException;
64     public int compareTo(Object JavaDoc o) {
65         // sorting most popular first
66
int other = ((Constant)o).popularity;
67         
68         return (popularity > other) ? +1 : (popularity == other) ? 0 : -1;
69     }
70     boolean isBig() { return false; } // overridden in Long and Double
71
public void display(int indent, boolean inline) {
72         System.err.print(this);
73     }
74
75     static String JavaDoc rep(int index, String JavaDoc x) {
76         return x + ":" + Integer.toHexString(index);
77     }
78 }
79
Popular Tags