From efc54d0c5d970c87d61ba93d508610eab6b7736a Mon Sep 17 00:00:00 2001 From: LexManos Date: Mon, 4 Mar 2024 18:15:20 -0800 Subject: [PATCH] Minor code cleanup. Closes #19 --- .../accesstransformer/AccessTransformer.java | 4 ++-- .../AccessTransformerEngine.java | 2 +- .../minecraftforge/accesstransformer/Target.java | 2 +- .../parser/AccessTransformerList.java | 15 ++++++++------- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/main/java/net/minecraftforge/accesstransformer/AccessTransformer.java b/src/main/java/net/minecraftforge/accesstransformer/AccessTransformer.java index 48ee221..83ad531 100644 --- a/src/main/java/net/minecraftforge/accesstransformer/AccessTransformer.java +++ b/src/main/java/net/minecraftforge/accesstransformer/AccessTransformer.java @@ -26,7 +26,7 @@ public AccessTransformer(final Target target, final Modifier modifier, final this.memberTarget = target; this.targetAccess = modifier; this.targetFinalState = finalState; - this.origins.add(origin+":"+lineNumber); + this.origins.add(origin + ':' + lineNumber); } @SuppressWarnings("unchecked") @@ -88,7 +88,7 @@ public enum FinalState { MAKEFINAL(i->i | Opcodes.ACC_FINAL), REMOVEFINAL(i->i & ~Opcodes.ACC_FINAL), CONFLICT(i->i); - private IntFunction function; + private final IntFunction function; FinalState(final IntFunction function) { this.function = function; diff --git a/src/main/java/net/minecraftforge/accesstransformer/AccessTransformerEngine.java b/src/main/java/net/minecraftforge/accesstransformer/AccessTransformerEngine.java index 97db812..e5bbcda 100644 --- a/src/main/java/net/minecraftforge/accesstransformer/AccessTransformerEngine.java +++ b/src/main/java/net/minecraftforge/accesstransformer/AccessTransformerEngine.java @@ -17,7 +17,7 @@ public enum AccessTransformerEngine { INSTANCE; - private AccessTransformerList masterList = new AccessTransformerList(); + private final AccessTransformerList masterList = new AccessTransformerList(); public boolean transform(ClassNode clazzNode, final Type classType) { // this should never happen but safety first diff --git a/src/main/java/net/minecraftforge/accesstransformer/Target.java b/src/main/java/net/minecraftforge/accesstransformer/Target.java index d22dd8c..7069bce 100644 --- a/src/main/java/net/minecraftforge/accesstransformer/Target.java +++ b/src/main/java/net/minecraftforge/accesstransformer/Target.java @@ -10,7 +10,7 @@ public abstract class Target { private final String className; - private Type type; + private final Type type; public Target(String className) { this.className = className.replace('.', '/'); diff --git a/src/main/java/net/minecraftforge/accesstransformer/parser/AccessTransformerList.java b/src/main/java/net/minecraftforge/accesstransformer/parser/AccessTransformerList.java index 75bdfa7..d573c70 100644 --- a/src/main/java/net/minecraftforge/accesstransformer/parser/AccessTransformerList.java +++ b/src/main/java/net/minecraftforge/accesstransformer/parser/AccessTransformerList.java @@ -32,15 +32,18 @@ import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; public class AccessTransformerList { private static final Logger LOGGER = LogManager.getLogger("AXFORM"); private static final Marker AXFORM_MARKER = MarkerManager.getMarker("AXFORM"); private final Map, AccessTransformer> accessTransformers = new HashMap<>(); + private final Set validAtTypes = new HashSet<>(); + private final Renamer renamer = new Renamer(); private INameHandler nameHandler = new IdentityNameHandler(); - private Renamer renamer = new Renamer(); public void loadFromResource(String resourceName) throws URISyntaxException, IOException { final Path path = Paths.get(getClass().getClassLoader().getResource(resourceName).toURI()); @@ -99,11 +102,7 @@ public void load(Path path, String resourceName, List lines) { int idx = name.indexOf('('); String desc = name.substring(idx).replace('.', '/'); name = name.substring(0, idx); - try { target = new MethodTarget(renamer.map(cls), renamer.mapMethodName(cls, name, desc), renamer.mapMethodDesc(desc)); - } catch (Throwable t) { - throw t; - } } ats.add(new AccessTransformer(target, mod, fmod, resourceName, lineIndex)); } @@ -120,6 +119,8 @@ public void load(Path path, String resourceName, List lines) { } this.accessTransformers.clear(); this.accessTransformers.putAll(localATCopy); + for (AccessTransformer newAT : ats) + this.validAtTypes.add(newAT.getTarget().getASMType()); LOGGER.debug(AXFORM_MARKER,"Loaded access transformer {} from path {}", resourceName, path); } @@ -185,7 +186,7 @@ public Map> getAccessTransformers() { } public boolean containsClassTarget(Type type) { - return accessTransformers.keySet().stream().anyMatch(k->type.equals(k.getASMType())); + return this.validAtTypes.contains(type); } public Map> getTransformersForTarget(Type type) { @@ -204,7 +205,7 @@ public void setNameHandler(final INameHandler nameHandler) { LOGGER.debug(AXFORM_MARKER, "Set name handler {}", nameHandler); } - private class Renamer extends Remapper { + private final class Renamer extends Remapper { @Override public String map(String internalName) { return AccessTransformerList.this.nameHandler.translateClassName(internalName);