KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jode > bytecode > Reference


1 /* Reference Copyright (C) 1999-2002 Jochen Hoenicke.
2  *
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU Lesser General Public License as published by
5  * the Free Software Foundation; either version 2, or (at your option)
6  * any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program; see the file COPYING.LESSER. If not, write to
15  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
16  *
17  * $Id: Reference.java.in,v 4.1.2.1 2002/05/28 17:34:01 hoenicke Exp $
18  */

19
20 package jode.bytecode;
21 import jode.util.UnifyHash;
22 import java.util.Iterator JavaDoc;
23
24 /**
25  * This class represents a field or method reference.
26  */

27 public class Reference {
28     /**
29      * A reference consists of a class name, a member name and a type.
30      */

31     private final String JavaDoc clazz, name, type;
32
33     private static final UnifyHash unifier = new UnifyHash();
34
35     public static Reference getReference(String JavaDoc className,
36                      String JavaDoc name, String JavaDoc type) {
37     int hash = className.hashCode() ^ name.hashCode() ^ type.hashCode();
38     Iterator JavaDoc iter = unifier.iterateHashCode(hash);
39     while (iter.hasNext()) {
40         Reference ref = (Reference) iter.next();
41         if (ref.clazz.equals(className)
42         && ref.name.equals(name)
43         && ref.type.equals(type))
44         return ref;
45     }
46     Reference ref = new Reference(className, name, type);
47     unifier.put(hash, ref);
48     return ref;
49     }
50
51     private Reference(String JavaDoc clazz, String JavaDoc name, String JavaDoc type) {
52     this.clazz = clazz;
53     this.name = name;
54     this.type = type;
55     }
56
57     public String JavaDoc getClazz() {
58     return clazz;
59     }
60
61     public String JavaDoc getName() {
62     return name;
63     }
64
65     public String JavaDoc getType() {
66     return type;
67     }
68     
69     public String JavaDoc toString() {
70     return clazz + " " + name + " " + type;
71     }
72 }
73
Popular Tags