// pass 1: look for any classes that got moved to inner classes
Map<String,String> renames = Maps.newHashMap();
for( ClassMapping classMapping : val.classes() )
{
// make sure we strip the packages off of obfuscated inner classes
String innerClassName = new ClassEntry( classMapping.getObfName() ).getSimpleName();
String outerClassName = m_jarIndex.getOuterClass( innerClassName );
if( outerClassName != null )
{
// build the composite class name
String newName = outerClassName + "$" + innerClassName;
// add a rename
renames.put( classMapping.getObfName(), newName );
System.out.println( String.format( "Converted class mapping %s to %s", classMapping.getObfName(), newName ) );
}
}
for( Map.Entry<String,String> entry : renames.entrySet() )
{
val.renameObfClass( entry.getKey(), entry.getValue() );
}
// pass 2: look for fields/methods that are actually declared in superclasses
MappingsRenamer renamer = new MappingsRenamer( m_jarIndex, val );
for( ClassMapping classMapping : val.classes() )
{
ClassEntry obfClassEntry = new ClassEntry( classMapping.getObfName() );
// fields
for( FieldMapping fieldMapping : Lists.newArrayList( classMapping.fields() ) )
{
FieldEntry fieldEntry = new FieldEntry( obfClassEntry, fieldMapping.getObfName() );
ClassEntry resolvedObfClassEntry = m_jarIndex.resolveEntryClass( fieldEntry );
if( resolvedObfClassEntry != null && !resolvedObfClassEntry.equals( fieldEntry.getClassEntry() ) )
{
boolean wasMoved = renamer.moveFieldToObfClass( classMapping, fieldMapping, resolvedObfClassEntry );
if( wasMoved )
{
System.out.println( String.format( "Moved field %s to class %s", fieldEntry, resolvedObfClassEntry ) );
}
else
{
System.err.println( String.format( "WARNING: Would move field %s to class %s but the field was already there. Dropping instead.", fieldEntry, resolvedObfClassEntry ) );
}
}
}
// methods
for( MethodMapping methodMapping : Lists.newArrayList( classMapping.methods() ) )
{
// skip constructors
if( methodMapping.isConstructor() )
{
continue;
}
MethodEntry methodEntry = new MethodEntry( obfClassEntry, methodMapping.getObfName(), methodMapping.getObfSignature() );
ClassEntry resolvedObfClassEntry = m_jarIndex.resolveEntryClass( methodEntry );
if( resolvedObfClassEntry != null && !resolvedObfClassEntry.equals( methodEntry.getClassEntry() ) )
{
boolean wasMoved = renamer.moveMethodToObfClass( classMapping, methodMapping, resolvedObfClassEntry );
if( wasMoved )
{
System.out.println( String.format( "Moved method %s to class %s", methodEntry, resolvedObfClassEntry ) );