use of net.runelite.asm.ClassFile in project runelite by runelite.
the class UnusedClassTest method before.
@Before
public void before() throws IOException {
group = new ClassGroup();
load("EmptyInterface.class");
load("ClassA.class");
ClassFile emptyClass = load("EmptyClass.class");
emptyClass.removeMethod(emptyClass.findMethod("<init>"));
}
use of net.runelite.asm.ClassFile in project runelite by runelite.
the class UnusedClassTest method load.
private ClassFile load(String name) throws IOException {
InputStream in = UnusedClassTest.class.getResourceAsStream("unusedclass/" + name);
Assert.assertNotNull(in);
ClassFile cf = ClassUtil.loadClass(in);
group.addClass(cf);
return cf;
}
use of net.runelite.asm.ClassFile in project runelite by runelite.
the class RenameUniqueTest method checkRenamed.
private void checkRenamed() {
for (ClassFile cf : group.getClasses()) {
Assert.assertTrue(cf.getName().startsWith("class") || cf.getName().equals("client"));
for (Field f : cf.getFields()) {
// synthetic fields arent obfuscated
if (f.isSynthetic())
continue;
Assert.assertTrue(f.getName().startsWith("field"));
}
for (Method m : cf.getMethods()) {
Assert.assertTrue(m.getName().length() > 2);
checkCode(m.getCode());
}
}
}
use of net.runelite.asm.ClassFile in project runelite by runelite.
the class UnreachedCodeTest method testRun.
@Test
public void testRun() throws IOException {
UnreachedCode uc = new UnreachedCode();
uc.run(group);
ClassFile cf = group.getClasses().get(0);
Method method = cf.findMethod("entry");
Assert.assertFalse(method.getCode().getExceptions().getExceptions().isEmpty());
method = cf.findMethod("method1Unused");
Assert.assertNotNull(method);
Assert.assertFalse(method.getCode().getInstructions().getInstructions().stream().filter(i -> !(i instanceof Label)).findAny().isPresent());
Assert.assertTrue(method.getCode().getExceptions().getExceptions().isEmpty());
// Method is now invalid, remove so jar can be saved
cf.removeMethod(method);
// constructor now has no instructions
method = cf.findMethod("<init>");
Assert.assertNotNull(method);
Assert.assertFalse(method.getCode().getInstructions().getInstructions().stream().filter(i -> !(i instanceof Label)).findAny().isPresent());
// remove it too
cf.removeMethod(method);
}
use of net.runelite.asm.ClassFile in project runelite by runelite.
the class GetStatic method getMyField.
@Override
public net.runelite.asm.Field getMyField() {
Class clazz = field.getClazz();
ClassFile cf = this.getInstructions().getCode().getMethod().getClassFile().getGroup().findClass(clazz.getName());
if (cf == null) {
return null;
}
net.runelite.asm.Field f2 = cf.findFieldDeep(field.getName(), field.getType());
return f2;
}
Aggregations