Add shorthand MemberDesc constructors

bzip2
Graham 5 years ago
parent 0a5901cde4
commit 0cb0658f61
  1. 25
      asm/src/main/java/dev/openrs2/asm/MemberDesc.java
  2. 4
      asm/src/main/java/dev/openrs2/asm/classpath/AsmClassMetadata.java
  3. 2
      deob/src/main/java/dev/openrs2/deob/remap/TypedRemapper.java
  4. 6
      deob/src/main/java/dev/openrs2/deob/transform/FieldOrderTransformer.java

@ -2,9 +2,34 @@ package dev.openrs2.asm;
import java.util.Objects; import java.util.Objects;
import org.objectweb.asm.tree.FieldInsnNode;
import org.objectweb.asm.tree.FieldNode;
import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode;
public final class MemberDesc { public final class MemberDesc {
private final String name, desc; private final String name, desc;
public MemberDesc(FieldNode field) {
this(field.name, field.desc);
}
public MemberDesc(MethodNode method) {
this(method.name, method.desc);
}
public MemberDesc(FieldInsnNode fieldInsn) {
this(fieldInsn.name, fieldInsn.desc);
}
public MemberDesc(MethodInsnNode methodInsn) {
this(methodInsn.name, methodInsn.desc);
}
public MemberDesc(MemberRef memberRef) {
this(memberRef.getName(), memberRef.getDesc());
}
public MemberDesc(String name, String desc) { public MemberDesc(String name, String desc) {
this.name = name; this.name = name;
this.desc = desc; this.desc = desc;

@ -49,14 +49,14 @@ public final class AsmClassMetadata extends ClassMetadata {
@Override @Override
public ImmutableList<MemberDesc> getFields() { public ImmutableList<MemberDesc> getFields() {
return clazz.fields.stream() return clazz.fields.stream()
.map(f -> new MemberDesc(f.name, f.desc)) .map(MemberDesc::new)
.collect(ImmutableList.toImmutableList()); .collect(ImmutableList.toImmutableList());
} }
@Override @Override
public ImmutableList<MemberDesc> getMethods() { public ImmutableList<MemberDesc> getMethods() {
return clazz.methods.stream() return clazz.methods.stream()
.map(m -> new MemberDesc(m.name, m.desc)) .map(MemberDesc::new)
.collect(ImmutableList.toImmutableList()); .collect(ImmutableList.toImmutableList());
} }

@ -188,7 +188,7 @@ public final class TypedRemapper extends Remapper {
return true; return true;
} }
if (clazz.isNative(new MemberDesc(method.getName(), method.getDesc()))) { if (clazz.isNative(new MemberDesc(method))) {
return true; return true;
} }
} }

@ -33,15 +33,15 @@ public final class FieldOrderTransformer extends Transformer {
continue; continue;
} }
var desc = new MemberDesc(putfield.name, putfield.desc); var desc = new MemberDesc(putfield);
if (!fields.containsKey(desc)) { if (!fields.containsKey(desc)) {
fields.put(desc, index++); fields.put(desc, index++);
} }
} }
clazz.fields.sort((a, b) -> { clazz.fields.sort((a, b) -> {
var indexA = fields.getOrDefault(new MemberDesc(a.name, a.desc), -1); var indexA = fields.getOrDefault(new MemberDesc(a), -1);
var indexB = fields.getOrDefault(new MemberDesc(b.name, b.desc), -1); var indexB = fields.getOrDefault(new MemberDesc(b), -1);
return Integer.compare(indexA, indexB); return Integer.compare(indexA, indexB);
}); });
}); });

Loading…
Cancel
Save