Close issue #3 - static and private inheritance

This commit is contained in:
md_5 2013-07-01 10:39:19 +10:00
parent 9a0c971c5d
commit 33d8d24d7e
5 changed files with 30 additions and 18 deletions

View File

@ -73,7 +73,7 @@ public class JarComparer extends ClassVisitor {
@Override @Override
public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) { public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) {
Ownable field = new Ownable(NodeType.FIELD, myName, name, desc); Ownable field = new Ownable(NodeType.FIELD, myName, name, desc, access);
fields.add(field); fields.add(field);
return null; // No need to get more info about a field! return null; // No need to get more info about a field!
} }
@ -82,7 +82,7 @@ public class JarComparer extends ClassVisitor {
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
// Check for initializers // Check for initializers
if (!name.equals("<init>") && !name.equals("<clinit>")) { if (!name.equals("<init>") && !name.equals("<clinit>")) {
Ownable method = new Ownable(NodeType.METHOD, myName, name, desc); Ownable method = new Ownable(NodeType.METHOD, myName, name, desc, access);
methods.add(method); methods.add(method);
} }
// FIXME: Scan return types too! // FIXME: Scan return types too!

View File

@ -39,14 +39,15 @@ import net.md_5.specialsource.transformer.MethodDescriptor;
import net.md_5.specialsource.transformer.ChainingTransformer; import net.md_5.specialsource.transformer.ChainingTransformer;
import net.md_5.specialsource.transformer.MappingTransformer; import net.md_5.specialsource.transformer.MappingTransformer;
import java.io.*; import java.io.*;
import java.lang.reflect.Modifier;
import java.util.*; import java.util.*;
public class JarMapping { public class JarMapping {
public final LinkedHashMap<String, String> packages = new LinkedHashMap<String, String>(); public final LinkedHashMap<String, String> packages = new LinkedHashMap<String, String>();
public final Map<String, String> classes = new HashMap<String, String>(); public final Map<String, String> classes = new HashMap<String, String>();
public final Map<String, String> fields = new HashMap<String, String>(); public final Map<String, Ownable> fields = new HashMap<String, Ownable>();
public final Map<String, String> methods = new HashMap<String, String>(); public final Map<String, Ownable> methods = new HashMap<String, Ownable>();
private InheritanceMap inheritanceMap = new InheritanceMap(); private InheritanceMap inheritanceMap = new InheritanceMap();
private InheritanceProvider fallbackInheritanceProvider = null; private InheritanceProvider fallbackInheritanceProvider = null;
private Set<String> excludedPackages = new HashSet<String>(); private Set<String> excludedPackages = new HashSet<String>();
@ -90,10 +91,14 @@ public class JarMapping {
return false; return false;
} }
public String tryClimb(Map<String, String> map, NodeType type, String owner, String name) { public Ownable tryClimb(Map<String, Ownable> map, NodeType type, String owner, String name) {
String key = owner + "/" + name; String key = owner + "/" + name;
String mapped = map.get(key); Ownable mapped = map.get(key);
if (mapped != null && (Modifier.isPrivate(mapped.getAccess()) || Modifier.isStatic(mapped.getAccess()))) {
return null;
}
if (mapped == null) { if (mapped == null) {
Collection<String> parents = null; Collection<String> parents = null;
@ -295,13 +300,13 @@ public class JarMapping {
String oldClassName = inputTransformer.transformClassName(tokens[0]); String oldClassName = inputTransformer.transformClassName(tokens[0]);
String oldFieldName = inputTransformer.transformFieldName(tokens[0], tokens[1]); String oldFieldName = inputTransformer.transformFieldName(tokens[0], tokens[1]);
String newFieldName = outputTransformer.transformFieldName(tokens[0], tokens[2]); String newFieldName = outputTransformer.transformFieldName(tokens[0], tokens[2]);
fields.put(oldClassName + "/" + oldFieldName, newFieldName); fields.put(oldClassName + "/" + oldFieldName, new Ownable(NodeType.FIELD, newFieldName));
} else if (tokens.length == 4) { } else if (tokens.length == 4) {
String oldClassName = inputTransformer.transformClassName(tokens[0]); String oldClassName = inputTransformer.transformClassName(tokens[0]);
String oldMethodName = inputTransformer.transformMethodName(tokens[0], tokens[1], tokens[2]); String oldMethodName = inputTransformer.transformMethodName(tokens[0], tokens[1], tokens[2]);
String oldMethodDescriptor = inputTransformer.transformMethodDescriptor(tokens[2]); String oldMethodDescriptor = inputTransformer.transformMethodDescriptor(tokens[2]);
String newMethodName = outputTransformer.transformMethodName(tokens[0], tokens[3], tokens[2]); String newMethodName = outputTransformer.transformMethodName(tokens[0], tokens[3], tokens[2]);
methods.put(oldClassName + "/" + oldMethodName + " " + oldMethodDescriptor, newMethodName); methods.put(oldClassName + "/" + oldMethodName + " " + oldMethodDescriptor, new Ownable(NodeType.METHOD, newMethodName));
} else { } else {
throw new IOException("Invalid csrg file line, token count " + tokens.length + " unexpected in " + line); throw new IOException("Invalid csrg file line, token count " + tokens.length + " unexpected in " + line);
} }
@ -404,7 +409,7 @@ public class JarMapping {
return; return;
} }
fields.put(oldClassName + "/" + oldFieldName, newFieldName); fields.put(oldClassName + "/" + oldFieldName, new Ownable(NodeType.FIELD, newFieldName));
} else if (kind.equals("MD:")) { } else if (kind.equals("MD:")) {
String oldFull = tokens[1]; String oldFull = tokens[1];
String newFull = tokens[3]; String newFull = tokens[3];
@ -439,7 +444,7 @@ public class JarMapping {
return; return;
} }
methods.put(oldClassName + "/" + oldMethodName + " " + oldMethodDescriptor, newMethodName); methods.put(oldClassName + "/" + oldMethodName + " " + oldMethodDescriptor, new Ownable(NodeType.METHOD, newMethodName));
} else { } else {
throw new IllegalArgumentException("Unable to parse srg file, unrecognized mapping type in line=" + line); throw new IllegalArgumentException("Unable to parse srg file, unrecognized mapping type in line=" + line);
} }
@ -482,7 +487,7 @@ public class JarMapping {
Ownable oldField = oldJar.fields.get(i); Ownable oldField = oldJar.fields.get(i);
Ownable newField = newJar.fields.get(i); Ownable newField = newJar.fields.get(i);
String key = oldField.owner + "/" + oldField.name; String key = oldField.owner + "/" + oldField.name;
fields.put(key, newField.name); fields.put(key, newField);
if (full || !oldField.name.equals(newField.name)) { if (full || !oldField.name.equals(newField.name)) {
srgWriter.addFieldMap(oldField, newField); srgWriter.addFieldMap(oldField, newField);
@ -492,7 +497,7 @@ public class JarMapping {
Ownable oldMethod = oldJar.methods.get(i); Ownable oldMethod = oldJar.methods.get(i);
Ownable newMethod = newJar.methods.get(i); Ownable newMethod = newJar.methods.get(i);
String key = oldMethod.owner + "/" + oldMethod.name + " " + oldMethod.descriptor; String key = oldMethod.owner + "/" + oldMethod.name + " " + oldMethod.descriptor;
methods.put(key, newMethod.name); methods.put(key, newMethod);
MethodDescriptor methodDescriptorTransformer = new MethodDescriptor(null, classes); MethodDescriptor methodDescriptorTransformer = new MethodDescriptor(null, classes);
String oldDescriptor = methodDescriptorTransformer.transform(oldMethod.descriptor); String oldDescriptor = methodDescriptorTransformer.transform(oldMethod.descriptor);

View File

@ -150,14 +150,14 @@ public class JarRemapper extends Remapper {
@Override @Override
public String mapFieldName(String owner, String name, String desc) { public String mapFieldName(String owner, String name, String desc) {
String mapped = jarMapping.tryClimb(jarMapping.fields, NodeType.FIELD, owner, name); Ownable mapped = jarMapping.tryClimb(jarMapping.fields, NodeType.FIELD, owner, name);
return mapped == null ? name : mapped; return mapped == null ? name : mapped.name;
} }
@Override @Override
public String mapMethodName(String owner, String name, String desc) { public String mapMethodName(String owner, String name, String desc) {
String mapped = jarMapping.tryClimb(jarMapping.methods, NodeType.METHOD, owner, name + " " + desc); Ownable mapped = jarMapping.tryClimb(jarMapping.methods, NodeType.METHOD, owner, name + " " + desc);
return mapped == null ? name : mapped; return mapped == null ? name : mapped.name;
} }
/** /**

View File

@ -29,16 +29,23 @@
package net.md_5.specialsource; package net.md_5.specialsource;
import lombok.Data; import lombok.Data;
import lombok.RequiredArgsConstructor;
/** /**
* A class which can be used to represent a field, method, or anything else * A class which can be used to represent a field, method, or anything else
* which has an owner, a name and a descriptor. * which has an owner, a name and a descriptor.
*/ */
@Data @Data
@RequiredArgsConstructor
public class Ownable { public class Ownable {
public final NodeType type; public final NodeType type;
public final String owner; public final String owner;
public final String name; public final String name;
public final String descriptor; public final String descriptor;
public final int access;
public Ownable(NodeType type, String name) {
this(type, null, name, null, -1);
}
} }

View File

@ -227,12 +227,12 @@ public class RemapperPreprocessor {
} }
String className = ((Type) ldcClass.cst).getInternalName(); String className = ((Type) ldcClass.cst).getInternalName();
String newName = jarMapping.tryClimb(jarMapping.fields, NodeType.FIELD, className, fieldName); Ownable newName = jarMapping.tryClimb(jarMapping.fields, NodeType.FIELD, className, fieldName);
logR("Remapping " + className + "/" + fieldName + " -> " + newName); logR("Remapping " + className + "/" + fieldName + " -> " + newName);
if (newName != null) { if (newName != null) {
// Change the string literal to the correct name // Change the string literal to the correct name
ldcField.cst = newName; ldcField.cst = newName.name;
//ldcClass.cst = className; // not remapped here - taken care of by JarRemapper //ldcClass.cst = className; // not remapped here - taken care of by JarRemapper
} }
} }