Skip to content

Commit

Permalink
Automatically fix inheritance problems and log errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Runemoro committed Jun 20, 2018
1 parent f991b30 commit 69e27a0
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/main/java/org/dimdev/javaremapper/SimpleRemapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,42 @@ public String map(String typeName) {
@Override
public String mapFieldName(String owner, String name, String desc) {
String newName = mapping.getField(owner, name, desc);
if (newName != null) return newName;

for (String superclass : inheritanceProvider.getAllSuperclasses(owner)) {
if (inheritanceProvider.getInheritableFields(superclass).contains(new MemberRef(name, desc))) {
newName = mapping.getField(superclass, name, desc);
if (newName != null) return newName;
String inheritedNewName = mapping.getField(superclass, name, desc);
if (inheritedNewName != null) {
if (newName != null && !inheritedNewName.equals(newName)) {
System.err.println("Field inheritance problem: " + owner + "." + name + " " + desc +
" inherits " + superclass + "." + name + " " + desc +
" but " + newName + " != " + inheritedNewName);
}
return inheritedNewName;
}
}
}
if (newName != null) return newName;
return name;
}

@Override
public String mapMethodName(String owner, String name, String desc) {
String newName = mapping.getMethod(owner, name, desc);
if (newName != null) return newName;

for (String superclass : inheritanceProvider.getAllSuperclasses(owner)) {
if (inheritanceProvider.getInheritableMethods(superclass).contains(new MemberRef(name, desc))) {
newName = mapping.getMethod(superclass, name, desc);
if (newName != null) return newName;
String inheritedNewName = mapping.getMethod(superclass, name, desc);
if (inheritedNewName != null) {
if (newName != null && !inheritedNewName.equals(newName)) {
System.err.println("Method inheritance problem: " + owner + "." + name + desc +
" inherits " + superclass + "." + name + desc +
" but " + newName + " != " + inheritedNewName);
}
return inheritedNewName;
}
}
}
if (newName != null) return newName;
return name;
}
}

0 comments on commit 69e27a0

Please sign in to comment.