From 0cb0658f619a29c7d16fac6207b56f7dce4856f5 Mon Sep 17 00:00:00 2001 From: Graham Date: Sat, 19 Oct 2019 17:22:01 +0100 Subject: [PATCH] Add shorthand MemberDesc constructors --- .../main/java/dev/openrs2/asm/MemberDesc.java | 25 +++++++++++++++++++ .../asm/classpath/AsmClassMetadata.java | 4 +-- .../dev/openrs2/deob/remap/TypedRemapper.java | 2 +- .../deob/transform/FieldOrderTransformer.java | 6 ++--- 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/asm/src/main/java/dev/openrs2/asm/MemberDesc.java b/asm/src/main/java/dev/openrs2/asm/MemberDesc.java index 82c641fa11..2a282bbe89 100644 --- a/asm/src/main/java/dev/openrs2/asm/MemberDesc.java +++ b/asm/src/main/java/dev/openrs2/asm/MemberDesc.java @@ -2,9 +2,34 @@ package dev.openrs2.asm; 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 { 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) { this.name = name; this.desc = desc; diff --git a/asm/src/main/java/dev/openrs2/asm/classpath/AsmClassMetadata.java b/asm/src/main/java/dev/openrs2/asm/classpath/AsmClassMetadata.java index 92ad831e76..5f3a15a95d 100644 --- a/asm/src/main/java/dev/openrs2/asm/classpath/AsmClassMetadata.java +++ b/asm/src/main/java/dev/openrs2/asm/classpath/AsmClassMetadata.java @@ -49,14 +49,14 @@ public final class AsmClassMetadata extends ClassMetadata { @Override public ImmutableList getFields() { return clazz.fields.stream() - .map(f -> new MemberDesc(f.name, f.desc)) + .map(MemberDesc::new) .collect(ImmutableList.toImmutableList()); } @Override public ImmutableList getMethods() { return clazz.methods.stream() - .map(m -> new MemberDesc(m.name, m.desc)) + .map(MemberDesc::new) .collect(ImmutableList.toImmutableList()); } diff --git a/deob/src/main/java/dev/openrs2/deob/remap/TypedRemapper.java b/deob/src/main/java/dev/openrs2/deob/remap/TypedRemapper.java index bf70058e4a..e6e206c516 100644 --- a/deob/src/main/java/dev/openrs2/deob/remap/TypedRemapper.java +++ b/deob/src/main/java/dev/openrs2/deob/remap/TypedRemapper.java @@ -188,7 +188,7 @@ public final class TypedRemapper extends Remapper { return true; } - if (clazz.isNative(new MemberDesc(method.getName(), method.getDesc()))) { + if (clazz.isNative(new MemberDesc(method))) { return true; } } diff --git a/deob/src/main/java/dev/openrs2/deob/transform/FieldOrderTransformer.java b/deob/src/main/java/dev/openrs2/deob/transform/FieldOrderTransformer.java index 7edf61075c..9e1d08fc5c 100644 --- a/deob/src/main/java/dev/openrs2/deob/transform/FieldOrderTransformer.java +++ b/deob/src/main/java/dev/openrs2/deob/transform/FieldOrderTransformer.java @@ -33,15 +33,15 @@ public final class FieldOrderTransformer extends Transformer { continue; } - var desc = new MemberDesc(putfield.name, putfield.desc); + var desc = new MemberDesc(putfield); if (!fields.containsKey(desc)) { fields.put(desc, index++); } } clazz.fields.sort((a, b) -> { - var indexA = fields.getOrDefault(new MemberDesc(a.name, a.desc), -1); - var indexB = fields.getOrDefault(new MemberDesc(b.name, b.desc), -1); + var indexA = fields.getOrDefault(new MemberDesc(a), -1); + var indexB = fields.getOrDefault(new MemberDesc(b), -1); return Integer.compare(indexA, indexB); }); });