Skip to content

Commit

Permalink
Minor code cleanup. Closes #19
Browse files Browse the repository at this point in the history
  • Loading branch information
LexManos committed Mar 5, 2024
1 parent 7c842b2 commit efc54d0
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -88,7 +88,7 @@ public enum FinalState {
MAKEFINAL(i->i | Opcodes.ACC_FINAL),
REMOVEFINAL(i->i & ~Opcodes.ACC_FINAL),
CONFLICT(i->i);
private IntFunction<Integer> function;
private final IntFunction<Integer> function;

FinalState(final IntFunction<Integer> function) {
this.function = function;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

public abstract class Target<T> {
private final String className;
private Type type;
private final Type type;

public Target(String className) {
this.className = className.replace('.', '/');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Target<?>, AccessTransformer> accessTransformers = new HashMap<>();
private final Set<Type> 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());
Expand Down Expand Up @@ -99,11 +102,7 @@ public void load(Path path, String resourceName, List<String> 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));
}
Expand All @@ -120,6 +119,8 @@ public void load(Path path, String resourceName, List<String> 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);
}

Expand Down Expand Up @@ -185,7 +186,7 @@ public Map<String, List<AccessTransformer>> getAccessTransformers() {
}

public boolean containsClassTarget(Type type) {
return accessTransformers.keySet().stream().anyMatch(k->type.equals(k.getASMType()));
return this.validAtTypes.contains(type);
}

public Map<TargetType, Map<String, AccessTransformer>> getTransformersForTarget(Type type) {
Expand All @@ -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);
Expand Down

0 comments on commit efc54d0

Please sign in to comment.