Skip to content

Commit

Permalink
Fix inheritance map
Browse files Browse the repository at this point in the history
  • Loading branch information
Runemoro committed Jun 18, 2018
1 parent 22ee873 commit 44df6be
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/main/java/org/dimdev/javaremapper/InheritanceMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ public InheritanceMapper() {
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
super.visit(version, access, name, signature, superName, interfaces);

Set<String> inheritanceSet = inheritanceMap.computeIfAbsent(name, k -> new HashSet<>());
inheritanceMap.put(name, new HashSet<>());
inheritableFields.put(name, new HashSet<>());
inheritableMethods.put(name, new HashSet<>());

Set<String> inheritanceSet = inheritanceMap.get(name);
if (superName != null) inheritanceSet.add(superName); // java/lang/Object has a null superclass
inheritanceSet.addAll(Arrays.asList(interfaces));
if ((access & Opcodes.ACC_ENUM) != 0) inheritanceSet.add("java/lang/Enum");
Expand Down Expand Up @@ -50,9 +54,6 @@ public MethodVisitor visitMethod(int access, String name, String descriptor, Str
public Set<String> getSuperclasses(String name) {
Set<String> result = inheritanceMap.get(name);
if (result == null) {
inheritanceMap.put(name, new HashSet<>());
inheritableFields.put(name, new HashSet<>());
inheritableMethods.put(name, new HashSet<>());
visitClasspathClass(name);
result = inheritanceMap.get(name);
}
Expand Down Expand Up @@ -81,9 +82,6 @@ public Set<String> getAllSuperclasses(String name) {
public Set<MemberRef> getInheritableFields(String name) {
Set<MemberRef> result = inheritableFields.get(name);
if (result == null) {
inheritanceMap.put(name, new HashSet<>());
inheritableFields.put(name, new HashSet<>());
inheritableMethods.put(name, new HashSet<>());
visitClasspathClass(name);
result = inheritableFields.get(name);
}
Expand All @@ -94,16 +92,17 @@ public Set<MemberRef> getInheritableFields(String name) {
public Set<MemberRef> getInheritableMethods(String name) {
Set<MemberRef> result = inheritableMethods.get(name);
if (result == null) {
inheritanceMap.put(name, new HashSet<>());
inheritableFields.put(name, new HashSet<>());
inheritableMethods.put(name, new HashSet<>());
visitClasspathClass(name);
result = inheritableMethods.get(name);
}
return result;
}

private void visitClasspathClass(String name) {
inheritanceMap.put(name, new HashSet<>());
inheritableFields.put(name, new HashSet<>());
inheritableMethods.put(name, new HashSet<>());

try (InputStream inputStream = InheritanceMapper.class.getClassLoader().getResourceAsStream(name + ".class")) {
if (inputStream == null) return;
ClassReader reader = new ClassReader(inputStream);
Expand Down

0 comments on commit 44df6be

Please sign in to comment.