KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > innig > macker > structure > Reference


1 /*______________________________________________________________________________
2  *
3  * Macker http://innig.net/macker/
4  *
5  * Copyright 2002-2003 Paul Cantrell
6  *
7  * This program is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License version 2, as published by the
9  * Free Software Foundation. See the file LICENSE.html for more information.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE. See the license for more details.
14  *
15  * You should have received a copy of the GNU General Public License along with
16  * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
17  * Place, Suite 330 / Boston, MA 02111-1307 / USA.
18  *______________________________________________________________________________
19  */

20  
21 package net.innig.macker.structure;
22
23 /**
24     A reference from one class to another.
25 */

26 public final class Reference
27     {
28     public Reference(
29             ClassInfo from,
30             ClassInfo to,
31             ReferenceType type,
32             String JavaDoc memberName,
33             AccessModifier memberAccess)
34         {
35         if(from == null)
36             throw new IllegalArgumentException JavaDoc("from is null");
37         if(to == null)
38             throw new IllegalArgumentException JavaDoc("to is null");
39         if(type == null)
40             throw new IllegalArgumentException JavaDoc("type is null");
41         if((memberName == null) != (memberAccess == null))
42             throw new IllegalArgumentException JavaDoc("memberName and memberAccess must both be present or both be absent");
43         this.from = from;
44         this.to = to;
45         this.type = type;
46         this.memberName = memberName;
47         this.memberAccess = memberAccess;
48         }
49     
50     public ClassInfo getFrom() { return from; }
51     public ClassInfo getTo() { return to; }
52     public ReferenceType getType() { return type; }
53     
54     public String JavaDoc getMemberName() { return memberName; }
55     public AccessModifier getMemberAccess() { return memberAccess; }
56     
57     //public String getFileName() { }
58
//public int getLine()
59

60     public boolean equals(Object JavaDoc that)
61         {
62         if(this == that)
63             return true;
64         if(that == null)
65             return false;
66         if(this.getClass() != that.getClass())
67             return false;
68         Reference thatRef = (Reference) that;
69         if(this.memberName == null && thatRef.memberName != null)
70             return false;
71         if(this.memberAccess == null && thatRef.memberAccess != null)
72             return false;
73         return this.from.equals(thatRef.from)
74             && this.to .equals(thatRef.to)
75             && this.type.equals(thatRef.type);
76         }
77     
78     public int hashCode()
79         {
80         return from.hashCode()
81              ^ to.hashCode() * 17
82              ^ type.hashCode() * 103
83              ^ (memberName == null ? 0 : memberName.hashCode() * 23)
84              ^ (memberAccess == null ? 0 : memberAccess.hashCode() * 5);
85         }
86     
87     public String JavaDoc toString()
88         {
89         return "Ref(" + from + " -> " + to + ", " + type
90             + (memberAccess == null ? "" : ": " + memberAccess + " " + memberName) + ')';
91         }
92     
93     private final ClassInfo from, to;
94     private final ReferenceType type;
95     private final String JavaDoc memberName;
96     private final AccessModifier memberAccess;
97     }
98
99
Popular Tags