01: /* Reference Copyright (C) 1999-2002 Jochen Hoenicke.
02: *
03: * This program is free software; you can redistribute it and/or modify
04: * it under the terms of the GNU Lesser General Public License as published by
05: * the Free Software Foundation; either version 2, or (at your option)
06: * any later version.
07: *
08: * This program is distributed in the hope that it will be useful,
09: * 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:
22: import jode.util.UnifyHash;
23: import java.util.Iterator;
24:
25: /**
26: * This class represents a field or method reference.
27: */
28: public class Reference {
29: /**
30: * A reference consists of a class name, a member name and a type.
31: */
32: private final String clazz, name, type;
33:
34: private static final UnifyHash unifier = new UnifyHash();
35:
36: public static Reference getReference(String className, String name,
37: String type) {
38: int hash = className.hashCode() ^ name.hashCode()
39: ^ type.hashCode();
40: Iterator iter = unifier.iterateHashCode(hash);
41: while (iter.hasNext()) {
42: Reference ref = (Reference) iter.next();
43: if (ref.clazz.equals(className) && ref.name.equals(name)
44: && ref.type.equals(type))
45: return ref;
46: }
47: Reference ref = new Reference(className, name, type);
48: unifier.put(hash, ref);
49: return ref;
50: }
51:
52: private Reference(String clazz, String name, String type) {
53: this .clazz = clazz;
54: this .name = name;
55: this .type = type;
56: }
57:
58: public String getClazz() {
59: return clazz;
60: }
61:
62: public String getName() {
63: return name;
64: }
65:
66: public String getType() {
67: return type;
68: }
69:
70: public String toString() {
71: return clazz + " " + name + " " + type;
72: }
73: }
|