summaryrefslogtreecommitdiff
path: root/src/cuchaz/enigma/analysis/EntryReference.java
diff options
context:
space:
mode:
authorGravatar jeff2015-01-13 23:25:04 -0500
committerGravatar jeff2015-01-13 23:25:04 -0500
commit959cb5fd4f9586ec3bd265b452fe25fe1db82e3f (patch)
treebdd8a2c52c2fe053ba3460614bde8542e5378dbe /src/cuchaz/enigma/analysis/EntryReference.java
parentgot rid of gradle in favor of ivy+ssjb (diff)
downloadenigma-fork-959cb5fd4f9586ec3bd265b452fe25fe1db82e3f.tar.gz
enigma-fork-959cb5fd4f9586ec3bd265b452fe25fe1db82e3f.tar.xz
enigma-fork-959cb5fd4f9586ec3bd265b452fe25fe1db82e3f.zip
source format change
don't hate me too much if you were planning a big merge. =P
Diffstat (limited to 'src/cuchaz/enigma/analysis/EntryReference.java')
-rw-r--r--src/cuchaz/enigma/analysis/EntryReference.java94
1 files changed, 35 insertions, 59 deletions
diff --git a/src/cuchaz/enigma/analysis/EntryReference.java b/src/cuchaz/enigma/analysis/EntryReference.java
index 0cde875..bb611df 100644
--- a/src/cuchaz/enigma/analysis/EntryReference.java
+++ b/src/cuchaz/enigma/analysis/EntryReference.java
@@ -18,74 +18,61 @@ import cuchaz.enigma.mapping.ClassEntry;
18import cuchaz.enigma.mapping.ConstructorEntry; 18import cuchaz.enigma.mapping.ConstructorEntry;
19import cuchaz.enigma.mapping.Entry; 19import cuchaz.enigma.mapping.Entry;
20 20
21public class EntryReference<E extends Entry, C extends Entry> 21public class EntryReference<E extends Entry,C extends Entry> {
22{ 22
23 private static final List<String> ConstructorNonNames = Arrays.asList( "this", "super", "static" ); 23 private static final List<String> ConstructorNonNames = Arrays.asList("this", "super", "static");
24 public E entry; 24 public E entry;
25 public C context; 25 public C context;
26 26
27 private boolean m_isNamed; 27 private boolean m_isNamed;
28 28
29 public EntryReference( E entry, String sourceName ) 29 public EntryReference(E entry, String sourceName) {
30 { 30 this(entry, sourceName, null);
31 this( entry, sourceName, null );
32 } 31 }
33 32
34 public EntryReference( E entry, String sourceName, C context ) 33 public EntryReference(E entry, String sourceName, C context) {
35 { 34 if (entry == null) {
36 if( entry == null ) 35 throw new IllegalArgumentException("Entry cannot be null!");
37 {
38 throw new IllegalArgumentException( "Entry cannot be null!" );
39 } 36 }
40 37
41 this.entry = entry; 38 this.entry = entry;
42 this.context = context; 39 this.context = context;
43 40
44 m_isNamed = sourceName != null && sourceName.length() > 0; 41 m_isNamed = sourceName != null && sourceName.length() > 0;
45 if( entry instanceof ConstructorEntry && ConstructorNonNames.contains( sourceName ) ) 42 if (entry instanceof ConstructorEntry && ConstructorNonNames.contains(sourceName)) {
46 {
47 m_isNamed = false; 43 m_isNamed = false;
48 } 44 }
49 } 45 }
50 46
51 public EntryReference( E entry, C context, EntryReference<E,C> other ) 47 public EntryReference(E entry, C context, EntryReference<E,C> other) {
52 {
53 this.entry = entry; 48 this.entry = entry;
54 this.context = context; 49 this.context = context;
55 m_isNamed = other.m_isNamed; 50 m_isNamed = other.m_isNamed;
56 } 51 }
57 52
58 public ClassEntry getLocationClassEntry( ) 53 public ClassEntry getLocationClassEntry() {
59 { 54 if (context != null) {
60 if( context != null )
61 {
62 return context.getClassEntry(); 55 return context.getClassEntry();
63 } 56 }
64 return entry.getClassEntry(); 57 return entry.getClassEntry();
65 } 58 }
66 59
67 public boolean isNamed( ) 60 public boolean isNamed() {
68 {
69 return m_isNamed; 61 return m_isNamed;
70 } 62 }
71 63
72 public Entry getNameableEntry( ) 64 public Entry getNameableEntry() {
73 { 65 if (entry instanceof ConstructorEntry) {
74 if( entry instanceof ConstructorEntry )
75 {
76 // renaming a constructor really means renaming the class 66 // renaming a constructor really means renaming the class
77 return entry.getClassEntry(); 67 return entry.getClassEntry();
78 } 68 }
79 return entry; 69 return entry;
80 } 70 }
81 71
82 public String getNamableName( ) 72 public String getNamableName() {
83 { 73 if (getNameableEntry() instanceof ClassEntry) {
84 if( getNameableEntry() instanceof ClassEntry )
85 {
86 ClassEntry classEntry = (ClassEntry)getNameableEntry(); 74 ClassEntry classEntry = (ClassEntry)getNameableEntry();
87 if( classEntry.isInnerClass() ) 75 if (classEntry.isInnerClass()) {
88 {
89 // make sure we only rename the inner class name 76 // make sure we only rename the inner class name
90 return classEntry.getInnerClassName(); 77 return classEntry.getInnerClassName();
91 } 78 }
@@ -95,55 +82,44 @@ public class EntryReference<E extends Entry, C extends Entry>
95 } 82 }
96 83
97 @Override 84 @Override
98 public int hashCode( ) 85 public int hashCode() {
99 { 86 if (context != null) {
100 if( context != null ) 87 return Util.combineHashesOrdered(entry.hashCode(), context.hashCode());
101 {
102 return Util.combineHashesOrdered( entry.hashCode(), context.hashCode() );
103 } 88 }
104 return entry.hashCode(); 89 return entry.hashCode();
105 } 90 }
106 91
107 @Override 92 @Override
108 public boolean equals( Object other ) 93 public boolean equals(Object other) {
109 { 94 if (other instanceof EntryReference) {
110 if( other instanceof EntryReference ) 95 return equals((EntryReference<?,?>)other);
111 {
112 return equals( (EntryReference<?,?>)other );
113 } 96 }
114 return false; 97 return false;
115 } 98 }
116 99
117 public boolean equals( EntryReference<?,?> other ) 100 public boolean equals(EntryReference<?,?> other) {
118 {
119 // check entry first 101 // check entry first
120 boolean isEntrySame = entry.equals( other.entry ); 102 boolean isEntrySame = entry.equals(other.entry);
121 if( !isEntrySame ) 103 if (!isEntrySame) {
122 {
123 return false; 104 return false;
124 } 105 }
125 106
126 // check caller 107 // check caller
127 if( context == null && other.context == null ) 108 if (context == null && other.context == null) {
128 {
129 return true; 109 return true;
130 } 110 } else if (context != null && other.context != null) {
131 else if( context != null && other.context != null ) 111 return context.equals(other.context);
132 {
133 return context.equals( other.context );
134 } 112 }
135 return false; 113 return false;
136 } 114 }
137 115
138 @Override 116 @Override
139 public String toString( ) 117 public String toString() {
140 {
141 StringBuilder buf = new StringBuilder(); 118 StringBuilder buf = new StringBuilder();
142 buf.append( entry ); 119 buf.append(entry);
143 if( context != null ) 120 if (context != null) {
144 { 121 buf.append(" called from ");
145 buf.append( " called from " ); 122 buf.append(context);
146 buf.append( context );
147 } 123 }
148 return buf.toString(); 124 return buf.toString();
149 } 125 }