Merge branch 'master' of github.com:Parabot/Parabot

This commit is contained in:
JKetelaar
2014-12-25 13:47:14 +01:00
2 changed files with 31 additions and 10 deletions
@@ -1,5 +1,7 @@
package org.parabot.core.asm; package org.parabot.core.asm;
import java.lang.reflect.Modifier;
import org.objectweb.asm.Opcodes; import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.FieldNode; import org.objectweb.asm.tree.FieldNode;
@@ -115,4 +117,28 @@ public class ASMUtils implements Opcodes {
throw new RuntimeException("eek " + c); throw new RuntimeException("eek " + c);
} }
public static void makePublic(ClassNode node) {
if (!Modifier.isPublic(node.access)) {
if (Modifier.isPrivate(node.access)) {
node.access = node.access & (~Opcodes.ACC_PRIVATE);
}
if (Modifier.isProtected(node.access)) {
node.access = node.access & (~Opcodes.ACC_PROTECTED);
}
node.access = node.access | Opcodes.ACC_PUBLIC;
}
}
public static void makePublic(MethodNode node) {
if (!Modifier.isPublic(node.access)) {
if (Modifier.isPrivate(node.access)) {
node.access = node.access & (~Opcodes.ACC_PRIVATE);
}
if (Modifier.isProtected(node.access)) {
node.access = node.access & (~Opcodes.ACC_PROTECTED);
}
node.access = node.access | Opcodes.ACC_PUBLIC;
}
}
} }
@@ -1,9 +1,7 @@
package org.parabot.core.asm.adapters; package org.parabot.core.asm.adapters;
import java.lang.reflect.Modifier;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodNode;
import org.parabot.core.Core; import org.parabot.core.Core;
import org.parabot.core.asm.ASMUtils; import org.parabot.core.asm.ASMUtils;
import org.parabot.core.asm.interfaces.Injectable; import org.parabot.core.asm.interfaces.Injectable;
@@ -46,14 +44,11 @@ public class AddInterfaceAdapter implements Injectable {
} }
protected static void addInterface(ClassNode node, String i) { protected static void addInterface(ClassNode node, String i) {
if (!Modifier.isPublic(node.access)) { ASMUtils.makePublic(node);
if (Modifier.isPrivate(node.access)) { for(MethodNode mn : node.methods) {
node.access = node.access & (~Opcodes.ACC_PRIVATE); if(mn.desc.startsWith("<init")) {
ASMUtils.makePublic(mn);
} }
if (Modifier.isProtected(node.access)) {
node.access = node.access & (~Opcodes.ACC_PROTECTED);
}
node.access = node.access | Opcodes.ACC_PUBLIC;
} }
node.interfaces.add(i); node.interfaces.add(i);
} }