From 63172120a39a315e29bc38ea6634741797b3dcab Mon Sep 17 00:00:00 2001 From: jeff Date: Sat, 30 Aug 2014 14:14:54 -0400 Subject: finished class matching for now, need to work on class member matching --- src/cuchaz/enigma/convert/ClassIdentity.java | 40 ++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) (limited to 'src/cuchaz/enigma/convert/ClassIdentity.java') diff --git a/src/cuchaz/enigma/convert/ClassIdentity.java b/src/cuchaz/enigma/convert/ClassIdentity.java index 0a3a449..980f31f 100644 --- a/src/cuchaz/enigma/convert/ClassIdentity.java +++ b/src/cuchaz/enigma/convert/ClassIdentity.java @@ -60,6 +60,7 @@ import cuchaz.enigma.mapping.SignatureUpdater.ClassNameUpdater; public class ClassIdentity { private ClassEntry m_classEntry; + private String m_rawName; private SidedClassNamer m_namer; private Set m_fields; private Set m_methods; @@ -70,13 +71,18 @@ public class ClassIdentity private Set m_implementations; private Set m_references; - public ClassIdentity( CtClass c, SidedClassNamer namer, JarIndex index, boolean useReferences ) + public ClassIdentity( CtClass c, SidedClassNamer namer, JarIndex index, boolean useReferences, boolean useRawNames ) { m_namer = namer; // stuff from the bytecode m_classEntry = new ClassEntry( Descriptor.toJvmName( c.getName() ) ); + m_rawName = ""; + if( useRawNames ) + { + m_rawName = m_classEntry.getName(); + } m_fields = Sets.newHashSet(); for( CtField field : c.getDeclaredFields() ) { @@ -176,8 +182,16 @@ public class ClassIdentity { StringBuilder buf = new StringBuilder(); buf.append( "class: " ); + buf.append( m_classEntry.getName() ); + buf.append( " " ); buf.append( hashCode() ); buf.append( "\n" ); + if( m_rawName.length() > 0 ) + { + buf.append( "\traw name: " ); + buf.append( m_rawName ); + buf.append( "\n" ); + } for( String field : m_fields ) { buf.append( "\tfield " ); @@ -425,7 +439,8 @@ public class ClassIdentity public boolean equals( ClassIdentity other ) { - return m_fields.equals( other.m_fields ) + return m_rawName.equals( other.m_rawName ) + && m_fields.equals( other.m_fields ) && m_methods.equals( other.m_methods ) && m_constructors.equals( other.m_constructors ) && m_staticInitializer.equals( other.m_staticInitializer ) @@ -439,6 +454,7 @@ public class ClassIdentity public int hashCode( ) { List objs = Lists.newArrayList(); + objs.add( m_rawName ); objs.addAll( m_fields ); objs.addAll( m_methods ); objs.addAll( m_constructors ); @@ -449,4 +465,24 @@ public class ClassIdentity objs.addAll( m_references ); return Util.combineHashesOrdered( objs ); } + + public int getMatchScore( ClassIdentity other ) + { + return getNumMatches( m_fields, other.m_fields ) + + getNumMatches( m_methods, other.m_methods ) + + getNumMatches( m_constructors, other.m_constructors ); + } + + private int getNumMatches( Set a, Set b ) + { + int numMatches = 0; + for( String val : a ) + { + if( b.contains( val ) ) + { + numMatches++; + } + } + return numMatches; + } } -- cgit v1.2.3