Skip to content

Commit

Permalink
Some small fixes to the modlauncher codebase (#116)
Browse files Browse the repository at this point in the history
* Target is a record. let's make it one.

Signed-off-by: cpw <cpw+github@weeksfamily.ca>

* Lambda is spelt lambda not lamdba.

Signed-off-by: cpw <cpw+github@weeksfamily.ca>

---------

Signed-off-by: cpw <cpw+github@weeksfamily.ca>
  • Loading branch information
cpw authored Sep 24, 2023
1 parent a032080 commit c8fa420
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import java.util.List;
import java.util.Map;

import static cpw.mods.modlauncher.api.LamdbaExceptionUtils.uncheck;
import static cpw.mods.modlauncher.api.LambdaExceptionUtils.uncheck;

@State(Scope.Benchmark)
public class TransformBenchmark {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public final class TransformTargetLabel {
private final TargetType<?> labelType;

TransformTargetLabel(ITransformer.Target<?> target) {
this(target.getClassName(), target.getElementName(), target.getElementDescriptor(), target.getTargetType());
this(target.className(), target.elementName(), target.elementDescriptor(), target.targetType());
}
private TransformTargetLabel(String className, String elementName, String elementDescriptor, TargetType<?> labelType) {
this.className = Type.getObjectType(className.replace('.', '/'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@
import cpw.mods.modlauncher.api.ITransformingClassLoaderBuilder;

import java.net.URL;
import java.net.URLConnection;
import java.nio.file.Path;
import java.util.*;
import java.util.function.Function;
import java.util.jar.Manifest;

import static cpw.mods.modlauncher.api.LamdbaExceptionUtils.rethrowFunction;
import static cpw.mods.modlauncher.api.LambdaExceptionUtils.rethrowFunction;

class TransformingClassLoaderBuilder implements ITransformingClassLoaderBuilder {
private final List<Path> transformationPaths = new ArrayList<>();
Expand Down
67 changes: 7 additions & 60 deletions src/main/java/cpw/mods/modlauncher/api/ITransformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,39 +94,14 @@ default String[] labels() {

/**
* Simple data holder indicating where the {@link ITransformer} can target.
* @param className The name of the class being targetted
* @param elementName The name of the element being targetted. This is the field name for a field,
* the method name for a method. Empty string for other types
* @param elementDescriptor The method's descriptor. Empty string for other types
* @param targetType The {@link TargetType} for this target - it should match the ITransformer
* type variable T
*/
@SuppressWarnings("SameParameterValue")
final class Target<T> {
private final String className;
private final String elementName;
private final String elementDescriptor;
private final TargetType<T> targetType;

/**
* Build a new target. Ensure that the targetType matches the T type for the ITransformer
* supplying the target.
* <p>
* In an obfuscated environment, this will be the obfuscated "notch" naming, in a
* deobfuscated environment this will be the searge naming.
*
* @param className The name of the class being targetted
* @param elementName The name of the element being targetted. This is the field name for a field,
* the method name for a method. Empty string for other types
* @param elementDescriptor The method's descriptor. Empty string for other types
* @param targetType The {@link TargetType} for this target - it should match the ITransformer
* type variable T
*/
Target(String className, String elementName, String elementDescriptor, TargetType<T> targetType) {
Objects.requireNonNull(className, "Class Name cannot be null");
Objects.requireNonNull(elementName, "Element Name cannot be null");
Objects.requireNonNull(elementDescriptor, "Element Descriptor cannot be null");
Objects.requireNonNull(targetType, "Target Type cannot be null");
this.className = className;
this.elementName = elementName;
this.elementDescriptor = elementDescriptor;
this.targetType = targetType;
}

record Target<T>(String className, String elementName, String elementDescriptor, TargetType<T> targetType) {
/**
* Convenience method returning a {@link Target} for a class
*
Expand Down Expand Up @@ -172,33 +147,5 @@ public static Target<MethodNode> targetMethod(String className, String methodNam
public static Target<FieldNode> targetField(String className, String fieldName) {
return new Target<>(className, fieldName, "", TargetType.FIELD);
}

/**
* @return The class name for this target
*/
public String getClassName() {
return className;
}

/**
* @return The element name for this target, either the field name or the method name
*/
public String getElementName() {
return elementName;
}

/**
* @return The element's descriptor. Usually the method descriptor
*/
public String getElementDescriptor() {
return elementDescriptor;
}

/**
* @return The target type of this target
*/
public TargetType<T> getTargetType() {
return targetType;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
/**
* From stackoverflow: https://stackoverflow.com/a/27644392
*/
public class LamdbaExceptionUtils {
public class LambdaExceptionUtils {

/**
* .forEach(rethrowConsumer(name -> System.out.println(Class.forName(name)))); or .forEach(rethrowConsumer(ClassNameUtil::println));
Expand Down

0 comments on commit c8fa420

Please sign in to comment.