Skip to content

Commit

Permalink
Refactored: removed ClassHierarchyAnalyzer.superclasses
Browse files Browse the repository at this point in the history
  • Loading branch information
luontola committed Mar 23, 2015
1 parent 43fea24 commit 82f9e8b
Showing 1 changed file with 9 additions and 12 deletions.
Expand Up @@ -19,8 +19,6 @@ public class ClassHierarchyAnalyzer implements MethodRelocations {


private final Map<Type, ClassInfo> classes = new HashMap<>(); private final Map<Type, ClassInfo> classes = new HashMap<>();
@Deprecated @Deprecated
private final Map<Type, Type> superclasses = new HashMap<>();
@Deprecated
private final Map<Type, List<MethodRef>> methodsByInterface = new HashMap<>(); private final Map<Type, List<MethodRef>> methodsByInterface = new HashMap<>();
@Deprecated @Deprecated
private final Map<Type, List<MethodRef>> methodsByClass = new HashMap<>(); private final Map<Type, List<MethodRef>> methodsByClass = new HashMap<>();
Expand All @@ -34,8 +32,6 @@ public void analyze(byte[] bytecode) {
ClassInfo c = new ClassInfo(cr); ClassInfo c = new ClassInfo(cr);
classes.put(c.type, c); classes.put(c.type, c);


superclasses.put(c.type, classNameToType(cr.getSuperName()));

if (Flags.hasFlag(cr.getAccess(), ACC_INTERFACE)) { if (Flags.hasFlag(cr.getAccess(), ACC_INTERFACE)) {
analyzeInterface(cr); analyzeInterface(cr);
} else { } else {
Expand Down Expand Up @@ -168,22 +164,23 @@ public MethodRef getMethodDefaultImplementation(MethodRef interfaceMethod) {
} }


@Override @Override
public List<MethodRef> getInterfaceMethods(Type interfaceName) { public List<MethodRef> getInterfaceMethods(Type type) {
Set<MethodRef> results = new LinkedHashSet<>(); Set<MethodRef> results = new LinkedHashSet<>();
results.addAll(methodsByInterface.getOrDefault(interfaceName, Collections.emptyList())); results.addAll(methodsByInterface.getOrDefault(type, Collections.emptyList()));
for (Type parent : getInterfacesOf(interfaceName)) { for (Type parent : getInterfacesOf(type)) {
for (MethodRef parentMethod : getInterfaceMethods(parent)) { for (MethodRef parentMethod : getInterfaceMethods(parent)) {
results.add(parentMethod.withOwner(interfaceName.getInternalName())); results.add(parentMethod.withOwner(type.getInternalName()));
} }
} }
return new ArrayList<>(results); return new ArrayList<>(results);
} }


public List<MethodRef> getSuperclassMethods(Type className) { public List<MethodRef> getSuperclassMethods(Type type) {
Set<MethodRef> results = new LinkedHashSet<>(); Set<MethodRef> results = new LinkedHashSet<>();
while (superclasses.containsKey(className)) { while (classes.containsKey(type)) {
className = superclasses.get(className); ClassInfo c = classes.get(type);
results.addAll(methodsByClass.getOrDefault(className, Collections.emptyList())); type = c.superclass;
results.addAll(methodsByClass.getOrDefault(type, Collections.emptyList()));
} }
return new ArrayList<>(results); return new ArrayList<>(results);
} }
Expand Down

0 comments on commit 82f9e8b

Please sign in to comment.