1 20 21 package net.innig.macker.structure; 22 23 26 public final class Reference 27 { 28 public Reference( 29 ClassInfo from, 30 ClassInfo to, 31 ReferenceType type, 32 String memberName, 33 AccessModifier memberAccess) 34 { 35 if(from == null) 36 throw new IllegalArgumentException ("from is null"); 37 if(to == null) 38 throw new IllegalArgumentException ("to is null"); 39 if(type == null) 40 throw new IllegalArgumentException ("type is null"); 41 if((memberName == null) != (memberAccess == null)) 42 throw new IllegalArgumentException ("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 getMemberName() { return memberName; } 55 public AccessModifier getMemberAccess() { return memberAccess; } 56 57 60 public boolean equals(Object 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 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 memberName; 96 private final AccessModifier memberAccess; 97 } 98 99 | Popular Tags |