From a85529d1ce6ec533809575ec84572de855464b36 Mon Sep 17 00:00:00 2001 From: jeff Date: Wed, 20 Aug 2014 01:21:52 -0400 Subject: finished reference navigation system. Still need to debug and polish it, but the basic idea seems to work. =) --- src/cuchaz/enigma/analysis/EntryReference.java | 89 ++++++++++++++++++++++++-- 1 file changed, 83 insertions(+), 6 deletions(-) (limited to 'src/cuchaz/enigma/analysis/EntryReference.java') diff --git a/src/cuchaz/enigma/analysis/EntryReference.java b/src/cuchaz/enigma/analysis/EntryReference.java index f462210..869e08c 100644 --- a/src/cuchaz/enigma/analysis/EntryReference.java +++ b/src/cuchaz/enigma/analysis/EntryReference.java @@ -10,19 +10,96 @@ ******************************************************************************/ package cuchaz.enigma.analysis; -import cuchaz.enigma.mapping.BehaviorEntry; +import cuchaz.enigma.Util; +import cuchaz.enigma.mapping.ClassEntry; import cuchaz.enigma.mapping.Entry; -public class EntryReference +public class EntryReference { - public T entry; - public BehaviorEntry caller; + public E entry; + public C context; public int pos; - public EntryReference( T entry, BehaviorEntry caller, int pos ) + public EntryReference( E entry ) { + this( entry, null, -1 ); + } + + public EntryReference( E entry, C context, int pos ) + { + if( entry == null ) + { + throw new IllegalArgumentException( "Entry cannot be null!" ); + } + this.entry = entry; - this.caller = caller; + this.context = context; this.pos = pos; } + + public ClassEntry getClassEntry( ) + { + if( context != null ) + { + return context.getClassEntry(); + } + return entry.getClassEntry(); + } + + @Override + public int hashCode( ) + { + if( context != null ) + { + return Util.combineHashesOrdered( entry.hashCode(), context.hashCode(), Integer.valueOf( pos ).hashCode() ); + } + return entry.hashCode(); + } + + @Override + public boolean equals( Object other ) + { + if( other instanceof EntryReference ) + { + return equals( (EntryReference)other ); + } + return false; + } + + public boolean equals( EntryReference other ) + { + // check entry first + boolean isEntrySame = entry.equals( other.entry ); + if( !isEntrySame ) + { + return false; + } + + // check caller + if( context == null && other.context == null ) + { + return true; + } + else if( context != null && other.context != null ) + { + return context.equals( other.context ) && pos == other.pos; + } + return false; + } + + @Override + public String toString( ) + { + StringBuilder buf = new StringBuilder(); + buf.append( entry ); + if( context != null ) + { + buf.append( " called from " ); + buf.append( context ); + buf.append( " (" ); + buf.append( pos ); + buf.append( ")" ); + } + return buf.toString(); + } } -- cgit v1.2.3