Enumerate interface members using cached metadata, references #24

This commit is contained in:
Mumfrey committed 2015-03-23 22:18:31 +00:00
1 parent 34c6e62c8f
commit 14f110c06e
2 files changed
+20 -21

No files matched your search

@@ -486,7 +486,7 @@ class ClassInfo extends TreeInfo {
/**
* Class targets
*/
protected List<ClassInfo> targets() {
protected List<ClassInfo> getTargets() {
if (this.mixin != null) {
List<ClassInfo> targets = new ArrayList<ClassInfo>();
targets.add(this);
@@ -497,6 +497,15 @@ class ClassInfo extends TreeInfo {
return ImmutableList.<ClassInfo>of(this);
}
/**
* Get class/interface methods
*
* @return read-only view of class methods
*/
public Set<Method> getMethods() {
return Collections.unmodifiableSet(this.methods);
}
/**
* Test whether this class has the specified superclass in its hierarchy
*
@@ -573,7 +582,7 @@ class ClassInfo extends TreeInfo {
public ClassInfo findSuperClass(String superClass, Traversal traversal) {
ClassInfo superClassInfo = this.getSuperClass();
if (superClassInfo != null) {
List<ClassInfo> targets = superClassInfo.targets();
List<ClassInfo> targets = superClassInfo.getTargets();
for (ClassInfo superTarget : targets) {
if (superClass.equals(superTarget.getName())) {
return superClassInfo;
@@ -756,7 +765,7 @@ class ClassInfo extends TreeInfo {
ClassInfo superClassInfo = this.getSuperClass();
if (superClassInfo != null) {
for (ClassInfo superTarget : superClassInfo.targets()) {
for (ClassInfo superTarget : superClassInfo.getTargets()) {
Method method = superTarget.findMethodInHierarchy(name, desc, true, traversal.next());
if (method != null) {
return method;
@@ -27,12 +27,10 @@ package org.spongepowered.asm.mixin.transformer;
import java.util.HashSet;
import java.util.Set;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.AnnotationNode;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodNode;
import org.spongepowered.asm.mixin.Implements;
import org.spongepowered.asm.mixin.transformer.ClassInfo.Method;
import org.spongepowered.asm.util.ASMHelper;
@@ -85,7 +83,7 @@ public class InterfaceInfo extends TreeInfo {
*/
private void initMethods() {
this.methods = new HashSet<String>();
this.readInterface(this.iface.getClassName());
this.readInterface(this.iface.getInternalName());
}
/**
@@ -95,22 +93,14 @@ public class InterfaceInfo extends TreeInfo {
* @param ifaceName Name of the interface to read
*/
private void readInterface(String ifaceName) {
ClassNode ifaceNode = new ClassNode();
try {
ClassReader classReader = new ClassReader(TreeInfo.loadClass(ifaceName, true));
classReader.accept(ifaceNode, 0);
} catch (Exception ex) {
throw new InvalidMixinException(this.mixin, "An error was encountered parsing the interface " + this.iface.toString());
ClassInfo interfaceInfo = ClassInfo.forName(ifaceName);
for (Method ifaceMethod : interfaceInfo.getMethods()) {
this.methods.add(ifaceMethod.toString());
}
for (MethodNode ifaceMethod : ifaceNode.methods) {
String signature = ifaceMethod.name + ifaceMethod.desc;
this.methods.add(signature);
}
for (String superIface : ifaceNode.interfaces) {
String sif = superIface.replace('/', '.');
this.readInterface(sif);
for (String superIface : interfaceInfo.getInterfaces()) {
this.readInterface(superIface);
}
}