From 6664fb1e36a5cea98e26a9127a83be73702af4d3 Mon Sep 17 00:00:00 2001 From: Lanse505 Date: Sun, 25 Jun 2023 12:10:55 +0200 Subject: [PATCH 1/3] Started work on some documentation --- .../lodestone/asm/CodeCleaner.java | 57 +++++++++++++++++++ .../parchmentmc/lodestone/asm/CodeTree.java | 24 ++++++++ .../lodestone/asm/MutableBouncerInfo.java | 12 ++++ .../lodestone/asm/MutableClassInfo.java | 5 ++ 4 files changed, 98 insertions(+) diff --git a/src/main/java/org/parchmentmc/lodestone/asm/CodeCleaner.java b/src/main/java/org/parchmentmc/lodestone/asm/CodeCleaner.java index 5cb38db..f0c3a18 100644 --- a/src/main/java/org/parchmentmc/lodestone/asm/CodeCleaner.java +++ b/src/main/java/org/parchmentmc/lodestone/asm/CodeCleaner.java @@ -14,18 +14,36 @@ public class CodeCleaner { + /** + * The CodeTree which holds the various classes and their mutable metadata representations. + */ private final CodeTree codeTree; + /** + * Main Constructor for CodeCleaner + * + * @param codeTree The CodeTree object being read. + */ public CodeCleaner(final CodeTree codeTree) { this.codeTree = codeTree; } + /** + * Grabs the name of the class to be cleaned from the mutable metadata, and passes it to the other implementation. + * + * @param classMetadata The mutable class metadata being passed in. + */ public void cleanClass(final MutableClassInfo classMetadata) { doCleanClass( classMetadata.getName() ); } + /** + * METHOD EXPLAINATION GOES HERE + * + * @param className The name of the class being cleaned. + */ private void doCleanClass(final String className) { MutableClassInfo info = codeTree.getClassMetadataFor(className); if (info == null || info.isResolved()) @@ -64,6 +82,13 @@ private void doCleanClass(final String className) { info.setResolved(true); } + /** + * METHOD EXPLAINATION GOES HERE + * + * @param methodMetadata The mutable method metadata. + * @param className The name of the class that pertains to the method. + * @return Returns a mutable method reference metadata. + */ private MutableMethodReferenceInfo doWalkBouncers(final MutableMethodInfo methodMetadata, String className) { final MutableClassInfo classMetadata = codeTree.getClassMetadataFor(className); if (!classMetadata.getMethods().isEmpty()) { @@ -136,10 +161,25 @@ private MutableMethodReferenceInfo doWalkBouncers(final MutableMethodInfo method return null; } + /** + * METHOD EXPLAINATION GOES HERE + * + * @param methodMetadata The mutable method metadata. + * @param ownerName The name of the owning class. + * @return Returns a Set of method references of overrides. + */ private Set findOverrides(MutableMethodInfo methodMetadata, String ownerName) { return doFindOverrides(methodMetadata, ownerName, new LinkedHashSet<>()); } + /** + * METHOD EXPLAINATION GOES HERE + * + * @param methodMetadata The mutable method metadata. + * @param className The name of the class that the method exists in. + * @param overrides A Set of override method references. + * @return Returns a Set of method references of overrides. + */ private Set doFindOverrides(MutableMethodInfo methodMetadata, String className, Set overrides) { if (methodMetadata.isStatic() || methodMetadata.isPrivate() || methodMetadata.getMethod().getName().startsWith("<")) { return overrides; @@ -191,6 +231,13 @@ private Set doFindOverrides(MutableMethodInfo method return overrides; } + /** + * METHOD EXPLAINATION GOES HERE + * + * @param mtd The method metadata. + * @param owner The owning class string identifier. + * @return Returns the first found method override reference. + */ private MutableMethodReferenceInfo doFindFirstOverride(MutableMethodInfo mtd, String owner) { if (mtd.isStatic() || mtd.isPrivate() || mtd.getMethod().getName().startsWith("<")) return null; @@ -238,6 +285,11 @@ private MutableMethodReferenceInfo doFindFirstOverride(MutableMethodInfo mtd, St return null; } + /** + * METHOD EXPLAINATION GOES HERE + * + * @param cls The class metadata for trying to resolve the abstract root class. + */ private void resolveAbstract(MutableClassInfo cls) { Map abs = new HashMap<>(); Set known = new TreeSet<>(); @@ -308,6 +360,11 @@ private void resolveAbstract(MutableClassInfo cls) { } } + /** + * METHOD EXPLAINATION GOES HERE + * + * @param mutableClassInfo The class metadata for trying to resolve the root record class. + */ private void resolveRecord(MutableClassInfo mutableClassInfo) { if (!mutableClassInfo.isRecord() || mutableClassInfo.getRecords().isEmpty() || mutableClassInfo.getFields().isEmpty()) return; diff --git a/src/main/java/org/parchmentmc/lodestone/asm/CodeTree.java b/src/main/java/org/parchmentmc/lodestone/asm/CodeTree.java index f3e1c78..7f10cf5 100644 --- a/src/main/java/org/parchmentmc/lodestone/asm/CodeTree.java +++ b/src/main/java/org/parchmentmc/lodestone/asm/CodeTree.java @@ -13,15 +13,26 @@ import java.util.zip.ZipInputStream; public class CodeTree { + private final Set noneLibraryClasses = new LinkedHashSet<>(); private final Map sources = new HashMap<>(); + /** + * A map consisting of the class string identifier as the key and the Mutable class metadata as the value. + */ private final Map parsedClasses = new HashMap<>(); public Set getNoneLibraryClasses() { return noneLibraryClasses; } + /** + * METHOD EXPLAINATION GOES HERE + * + * @param path The file path to the file being loaded. + * @param library If the loaded file is a library or not. + * @throws IOException Throws an IOException if it couldn't read the file using the ZipInputStream. + */ public final void load(final Path path, final boolean library) throws IOException { try (ZipInputStream zipInputStream = new ZipInputStream(Files.newInputStream(path))) { ZipEntry entry; @@ -41,6 +52,12 @@ public final void load(final Path path, final boolean library) throws IOExceptio } } + /** + * METHOD EXPLAINATION GOES HERE + * + * @param cls The class identifier name. + * @return Returns the mutable metadata for the class. + */ public MutableClassInfo getClassMetadataFor(String cls) { MutableClassInfo classMetadata = parsedClasses.get(cls); if (classMetadata == null) { @@ -67,6 +84,13 @@ private MutableClassInfo buildClass(final ClassNode classNode) { return new MutableClassInfo(classNode); } + /** + * METHOD EXPLAINATION GOES HERE + * + * @param is The input stream thats being read. + * @return Returns the read file in the form of a byte array of data. + * @throws IOException Throws an IOException if the data cannot be read. + */ private static byte[] readStreamFully(InputStream is) throws IOException { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(Math.max(8192, is.available())); byte[] buffer = new byte[8192]; diff --git a/src/main/java/org/parchmentmc/lodestone/asm/MutableBouncerInfo.java b/src/main/java/org/parchmentmc/lodestone/asm/MutableBouncerInfo.java index 2a726e2..d5facd1 100644 --- a/src/main/java/org/parchmentmc/lodestone/asm/MutableBouncerInfo.java +++ b/src/main/java/org/parchmentmc/lodestone/asm/MutableBouncerInfo.java @@ -1,9 +1,21 @@ package org.parchmentmc.lodestone.asm; public class MutableBouncerInfo { + /** + * The target method reference. + */ private final MutableMethodReferenceInfo target; + + /** + * The method super reference. + */ private MutableMethodReferenceInfo owner; + /** + * Main Constructor + * + * @param target The target method reference. + */ public MutableBouncerInfo(MutableMethodReferenceInfo target) { this.target = target; } diff --git a/src/main/java/org/parchmentmc/lodestone/asm/MutableClassInfo.java b/src/main/java/org/parchmentmc/lodestone/asm/MutableClassInfo.java index 127c00a..565d6ef 100644 --- a/src/main/java/org/parchmentmc/lodestone/asm/MutableClassInfo.java +++ b/src/main/java/org/parchmentmc/lodestone/asm/MutableClassInfo.java @@ -32,6 +32,11 @@ public class MutableClassInfo implements MutableSecuredObjectInfo { private final boolean isRecord; private boolean resolved = false; + /** + * Main Constructor + * + * @param node The class node being parsed into metadata. + */ MutableClassInfo(ClassNode node) { this.name = node.name; this.superName = "java/lang/Object".equals(node.superName) ? null : node.superName; From 469f2fa8c918e8ac2d6f504becf1234435501a83 Mon Sep 17 00:00:00 2001 From: Lanse Date: Tue, 27 Jun 2023 21:39:04 +0200 Subject: [PATCH 2/3] Push JavaDocs --- .../lodestone/asm/CodeCleaner.java | 22 +++++++++++-------- .../parchmentmc/lodestone/asm/CodeTree.java | 6 ++--- .../lodestone/asm/MutableBouncerInfo.java | 16 +++----------- .../lodestone/asm/MutableClassInfo.java | 7 ++++++ .../converter/BouncingTargetConverter.java | 8 +++++++ .../lodestone/converter/ClassConverter.java | 7 ++++++ .../lodestone/converter/FieldConverter.java | 8 +++++++ .../lodestone/converter/MethodConverter.java | 9 ++++++++ .../lodestone/converter/RecordConverter.java | 15 +++++++++++++ .../converter/ReferenceConverter.java | 7 ++++++ 10 files changed, 80 insertions(+), 25 deletions(-) diff --git a/src/main/java/org/parchmentmc/lodestone/asm/CodeCleaner.java b/src/main/java/org/parchmentmc/lodestone/asm/CodeCleaner.java index f0c3a18..7466d7a 100644 --- a/src/main/java/org/parchmentmc/lodestone/asm/CodeCleaner.java +++ b/src/main/java/org/parchmentmc/lodestone/asm/CodeCleaner.java @@ -40,7 +40,9 @@ public void cleanClass(final MutableClassInfo classMetadata) { } /** - * METHOD EXPLAINATION GOES HERE + * Cleans up the metadata for a class. + * The method does this by resolving bouncer methods and resolving abstract methods. + * This method also resolves record classes. * * @param className The name of the class being cleaned. */ @@ -83,7 +85,7 @@ private void doCleanClass(final String className) { } /** - * METHOD EXPLAINATION GOES HERE + * Recursively walks up the class hierarchy to find the final implementation of a method by following bouncer methods. * * @param methodMetadata The mutable method metadata. * @param className The name of the class that pertains to the method. @@ -162,7 +164,8 @@ private MutableMethodReferenceInfo doWalkBouncers(final MutableMethodInfo method } /** - * METHOD EXPLAINATION GOES HERE + * Used to find the all methods that override the given method within the class hierarchy. + * Providing an empty set of method references. * * @param methodMetadata The mutable method metadata. * @param ownerName The name of the owning class. @@ -173,7 +176,7 @@ private Set findOverrides(MutableMethodInfo methodMe } /** - * METHOD EXPLAINATION GOES HERE + * Used to find the all methods that override the given method within the class hierarchy. * * @param methodMetadata The mutable method metadata. * @param className The name of the class that the method exists in. @@ -232,10 +235,10 @@ private Set doFindOverrides(MutableMethodInfo method } /** - * METHOD EXPLAINATION GOES HERE + * Finds the first concrete implementation of the given method within the class hierarchy. * * @param mtd The method metadata. - * @param owner The owning class string identifier. + * @param owner The name of the class that potentially overrides the method as its arguments * @return Returns the first found method override reference. */ private MutableMethodReferenceInfo doFindFirstOverride(MutableMethodInfo mtd, String owner) { @@ -286,7 +289,8 @@ private MutableMethodReferenceInfo doFindFirstOverride(MutableMethodInfo mtd, St } /** - * METHOD EXPLAINATION GOES HERE + * Resolves abstract methods in the class hierarchy, it does this by identifying the abstract methods + * concrete implementations and creating appropriate method references. * * @param cls The class metadata for trying to resolve the abstract root class. */ @@ -361,9 +365,9 @@ private void resolveAbstract(MutableClassInfo cls) { } /** - * METHOD EXPLAINATION GOES HERE + * Copies over the record getters to the record info. * - * @param mutableClassInfo The class metadata for trying to resolve the root record class. + * @param mutableClassInfo The class metadata for trying to copy over the record getters. */ private void resolveRecord(MutableClassInfo mutableClassInfo) { if (!mutableClassInfo.isRecord() || mutableClassInfo.getRecords().isEmpty() || mutableClassInfo.getFields().isEmpty()) diff --git a/src/main/java/org/parchmentmc/lodestone/asm/CodeTree.java b/src/main/java/org/parchmentmc/lodestone/asm/CodeTree.java index 7f10cf5..0f0e1ef 100644 --- a/src/main/java/org/parchmentmc/lodestone/asm/CodeTree.java +++ b/src/main/java/org/parchmentmc/lodestone/asm/CodeTree.java @@ -27,7 +27,7 @@ public Set getNoneLibraryClasses() { } /** - * METHOD EXPLAINATION GOES HERE + * Loads all class files for a given file path and stores them in the 'sources' map as byte arrays. * * @param path The file path to the file being loaded. * @param library If the loaded file is a library or not. @@ -53,7 +53,7 @@ public final void load(final Path path, final boolean library) throws IOExceptio } /** - * METHOD EXPLAINATION GOES HERE + * Retrieves the metadata for a given class name, creating it if necessary, and returns a MutableClassInfo object. * * @param cls The class identifier name. * @return Returns the mutable metadata for the class. @@ -85,7 +85,7 @@ private MutableClassInfo buildClass(final ClassNode classNode) { } /** - * METHOD EXPLAINATION GOES HERE + * Reads an InputStream fully and returns the data as a byte array. * * @param is The input stream thats being read. * @return Returns the read file in the form of a byte array of data. diff --git a/src/main/java/org/parchmentmc/lodestone/asm/MutableBouncerInfo.java b/src/main/java/org/parchmentmc/lodestone/asm/MutableBouncerInfo.java index d5facd1..ba711a9 100644 --- a/src/main/java/org/parchmentmc/lodestone/asm/MutableBouncerInfo.java +++ b/src/main/java/org/parchmentmc/lodestone/asm/MutableBouncerInfo.java @@ -1,21 +1,11 @@ package org.parchmentmc.lodestone.asm; public class MutableBouncerInfo { - /** - * The target method reference. - */ + private final MutableMethodReferenceInfo target; - - /** - * The method super reference. - */ - private MutableMethodReferenceInfo owner; - /** - * Main Constructor - * - * @param target The target method reference. - */ + private MutableMethodReferenceInfo owner; + public MutableBouncerInfo(MutableMethodReferenceInfo target) { this.target = target; } diff --git a/src/main/java/org/parchmentmc/lodestone/asm/MutableClassInfo.java b/src/main/java/org/parchmentmc/lodestone/asm/MutableClassInfo.java index 565d6ef..acd53ed 100644 --- a/src/main/java/org/parchmentmc/lodestone/asm/MutableClassInfo.java +++ b/src/main/java/org/parchmentmc/lodestone/asm/MutableClassInfo.java @@ -77,6 +77,13 @@ public class MutableClassInfo implements MutableSecuredObjectInfo { } } + /** + * Returns the target method handle of the lambda expression represented by the given InvokeDynamicInsnNode. + * + * @param idn the InvokeDynamicInsnNode representing the lambda expression + * @return the target method handle of the lambda expression, or null if the given InvokeDynamicInsnNode does not represent a lambda expression + * @throws NullPointerException if the given InvokeDynamicInsnNode is null + */ private Handle getLambdaTarget(InvokeDynamicInsnNode idn) { if (LAMBDA_METAFACTORY.equals(idn.bsm) && idn.bsmArgs != null && idn.bsmArgs.length == 3 && idn.bsmArgs[1] instanceof Handle) { return ((Handle) idn.bsmArgs[1]); diff --git a/src/main/java/org/parchmentmc/lodestone/converter/BouncingTargetConverter.java b/src/main/java/org/parchmentmc/lodestone/converter/BouncingTargetConverter.java index dcb8485..167f159 100644 --- a/src/main/java/org/parchmentmc/lodestone/converter/BouncingTargetConverter.java +++ b/src/main/java/org/parchmentmc/lodestone/converter/BouncingTargetConverter.java @@ -5,6 +5,14 @@ import org.parchmentmc.lodestone.asm.MutableBouncerInfo; public class BouncingTargetConverter { + + /** + * Converts the given MutableBouncerInfo object into a BouncingTargetMetadata object. + * + * @param bouncerInfo the MutableBouncerInfo object to convert + * @return a BouncingTargetMetadata object representing the converted MutableBouncerInfo object, or null if the input is null + * @throws ReferenceConversionException if an error occurs while converting a method reference in the MutableBouncerInfo object + */ public BouncingTargetMetadata convert(final MutableBouncerInfo bouncerInfo) { final ReferenceConverter methodReferenceConverter = new ReferenceConverter(); diff --git a/src/main/java/org/parchmentmc/lodestone/converter/ClassConverter.java b/src/main/java/org/parchmentmc/lodestone/converter/ClassConverter.java index b5e36d3..133f2ab 100644 --- a/src/main/java/org/parchmentmc/lodestone/converter/ClassConverter.java +++ b/src/main/java/org/parchmentmc/lodestone/converter/ClassConverter.java @@ -8,6 +8,13 @@ public class ClassConverter { + /** + * Converts the given MutableClassInfo object into a ClassMetadata object. + * + * @param classInfo the MutableClassInfo object to convert + * @return a ClassMetadata object representing the converted MutableClassInfo object + * @throws ReferenceConversionException if an error occurs while converting a reference in the MutableClassInfo object + */ public ClassMetadata convert(final MutableClassInfo classInfo) { final MethodConverter methodConverter = new MethodConverter(); final FieldConverter fieldConverter = new FieldConverter(); diff --git a/src/main/java/org/parchmentmc/lodestone/converter/FieldConverter.java b/src/main/java/org/parchmentmc/lodestone/converter/FieldConverter.java index 3812058..62e9de0 100644 --- a/src/main/java/org/parchmentmc/lodestone/converter/FieldConverter.java +++ b/src/main/java/org/parchmentmc/lodestone/converter/FieldConverter.java @@ -7,6 +7,14 @@ import org.parchmentmc.lodestone.asm.MutableFieldInfo; public class FieldConverter { + + /** + * Converts the given MutableFieldInfo object into a FieldMetadata object for the specified class. + * + * @param classInfo the MutableClassInfo object representing the class that the field belongs to + * @param fieldInfo the MutableFieldInfo object to convert + * @return a FieldMetadata object representing the converted MutableFieldInfo object + */ public FieldMetadata convert(final MutableClassInfo classInfo, final MutableFieldInfo fieldInfo) { return FieldMetadataBuilder.create() .withName(NamedBuilder.create().withObfuscated(fieldInfo.getName()).build()) diff --git a/src/main/java/org/parchmentmc/lodestone/converter/MethodConverter.java b/src/main/java/org/parchmentmc/lodestone/converter/MethodConverter.java index ba354be..a376ae2 100644 --- a/src/main/java/org/parchmentmc/lodestone/converter/MethodConverter.java +++ b/src/main/java/org/parchmentmc/lodestone/converter/MethodConverter.java @@ -8,6 +8,15 @@ import org.parchmentmc.lodestone.asm.MutableMethodInfo; public class MethodConverter { + + /** + * Converts the given MutableMethodInfo object into a MethodMetadata object for the specified class. + * + * @param classInfo the MutableClassInfo object representing the class that the method belongs to + * @param mutableMethodInfo the MutableMethodInfo object to convert + * @return a MethodMetadata object representing the converted MutableMethodInfo object + * @throws ReferenceConversionException if an error occurs while converting a reference in the MutableMethodInfo object + */ public MethodMetadata convert(final MutableClassInfo classInfo, final MutableMethodInfo mutableMethodInfo) { final ReferenceConverter methodReferenceConverter = new ReferenceConverter(); final BouncingTargetConverter bouncingTargetConverter = new BouncingTargetConverter(); diff --git a/src/main/java/org/parchmentmc/lodestone/converter/RecordConverter.java b/src/main/java/org/parchmentmc/lodestone/converter/RecordConverter.java index a5da5b2..740271c 100644 --- a/src/main/java/org/parchmentmc/lodestone/converter/RecordConverter.java +++ b/src/main/java/org/parchmentmc/lodestone/converter/RecordConverter.java @@ -13,6 +13,15 @@ import java.util.Iterator; public class RecordConverter { + + /** + * Converts the given MutableRecordInfo object into a RecordMetadata object for the specified class. + * + * @param classInfo the MutableClassInfo object representing the class that the record belongs to + * @param recordInfo the MutableRecordInfo object to convert + * @return a RecordMetadata object representing the converted MutableRecordInfo object + * @throws ReferenceConversionException if an error occurs while converting a reference in the MutableRecordInfo object + */ public RecordMetadata convert(final MutableClassInfo classInfo, final MutableRecordInfo recordInfo) { final ReferenceConverter referenceConverter = new ReferenceConverter(); @@ -35,6 +44,12 @@ public RecordMetadata convert(final MutableClassInfo classInfo, final MutableRec .build(); } + /** + * Returns the MutableMethodReferenceInfo object representing the getter for the given MutableFieldInfo object. + * + * @param fieldInfo the MutableFieldInfo object to get the getter for + * @return the MutableMethodReferenceInfo object representing the getter for the given MutableFieldInfo object, or null if no getter is found + */ private static MutableMethodReferenceInfo getGetter(MutableFieldInfo fieldInfo) { final Iterator iterator = fieldInfo.getGetters().iterator(); MutableMethodReferenceInfo result = null; diff --git a/src/main/java/org/parchmentmc/lodestone/converter/ReferenceConverter.java b/src/main/java/org/parchmentmc/lodestone/converter/ReferenceConverter.java index 190c7f0..e5f1f2f 100644 --- a/src/main/java/org/parchmentmc/lodestone/converter/ReferenceConverter.java +++ b/src/main/java/org/parchmentmc/lodestone/converter/ReferenceConverter.java @@ -6,6 +6,13 @@ import org.parchmentmc.lodestone.asm.MutableMethodReferenceInfo; public class ReferenceConverter { + + /** + * Converts the given MutableMethodReferenceInfo object into a Reference object. + * + * @param refInfo the MutableMethodReferenceInfo object to convert + * @return a Reference object representing the converted MutableMethodReferenceInfo object, or null if the input is null + */ public Reference convert(final MutableMethodReferenceInfo refInfo) { if (refInfo == null) return null; From 12072c39c649d3b6f440c20bf3e1ca55d6691c31 Mon Sep 17 00:00:00 2001 From: Lanse Date: Tue, 27 Jun 2023 22:04:42 +0200 Subject: [PATCH 3/3] Final push --- .../lodestone/LodestoneExtension.java | 21 +++ .../lodestone/LodestonePlugin.java | 11 ++ .../tasks/DownloadLauncherMetadata.java | 23 ++++ .../lodestone/tasks/DownloadVersion.java | 24 ++++ .../tasks/DownloadVersionMetadata.java | 34 +++++ .../tasks/ExtractMetadataFromJarFiles.java | 34 +++++ .../ExtractMetadataFromProguardFile.java | 15 +++ .../lodestone/tasks/ExtractMetadataTask.java | 32 +++++ .../lodestone/tasks/MergeMetadata.java | 121 ++++++++++++++++++ .../lodestone/tasks/MinecraftVersionTask.java | 11 ++ .../lodestone/util/ASMRemapper.java | 24 ++++ 11 files changed, 350 insertions(+) diff --git a/src/main/java/org/parchmentmc/lodestone/LodestoneExtension.java b/src/main/java/org/parchmentmc/lodestone/LodestoneExtension.java index 27bb494..590a3fc 100644 --- a/src/main/java/org/parchmentmc/lodestone/LodestoneExtension.java +++ b/src/main/java/org/parchmentmc/lodestone/LodestoneExtension.java @@ -15,10 +15,20 @@ import java.io.InputStreamReader; import java.net.URL; +/** + * LodestoneExtension is a class that represents the extension configuration for the Lodestone plugin. + * It provides properties and methods to configure and retrieve Minecraft versions. + */ public class LodestoneExtension { private final Project project; private final Property mcVersion; + /** + * Constructs a new LodestoneExtension with the specified project and object factory. + * + * @param project The Gradle project associated with the extension. + * @param factory The object factory used to create properties. + */ @Inject public LodestoneExtension(Project project, ObjectFactory factory) { this.project = project; @@ -26,12 +36,23 @@ public LodestoneExtension(Project project, ObjectFactory factory) { this.mcVersion = factory.property(String.class).convention("latest"); } + /** + * Returns the property representing the Minecraft version. + * + * @return The property containing the Minecraft version. + */ public Property getMcVersion() { return mcVersion; } private String resolvedMcVersion; + /** + * Returns a provider for the resolved Minecraft version. + * The provider lazily resolves and provides the Minecraft version based on the configured Minecraft version property. + * + * @return The provider for the resolved Minecraft version. + */ public Provider getResolvedMcVersion() { return mcVersion.map(mc -> { if (resolvedMcVersion != null) diff --git a/src/main/java/org/parchmentmc/lodestone/LodestonePlugin.java b/src/main/java/org/parchmentmc/lodestone/LodestonePlugin.java index ccb9327..f8c7aac 100644 --- a/src/main/java/org/parchmentmc/lodestone/LodestonePlugin.java +++ b/src/main/java/org/parchmentmc/lodestone/LodestonePlugin.java @@ -6,7 +6,18 @@ import org.gradle.api.Plugin; import org.gradle.api.Project; +/** + * LodestonePlugin is a Gradle plugin that applies the Lodestone functionality to a project. + * It implements the Plugin interface to define the plugin behavior when applied to a project. + */ public class LodestonePlugin implements Plugin { + + /** + * Applies the Lodestone plugin functionality to the specified Gradle project. + * It creates and configures a LodestoneExtension for the project. + * + * @param project The Gradle project to apply the plugin to. + */ public void apply(Project project) { LodestoneExtension extension = project.getExtensions().create("lodestone", LodestoneExtension.class, project); } diff --git a/src/main/java/org/parchmentmc/lodestone/tasks/DownloadLauncherMetadata.java b/src/main/java/org/parchmentmc/lodestone/tasks/DownloadLauncherMetadata.java index 8a667ce..5364452 100644 --- a/src/main/java/org/parchmentmc/lodestone/tasks/DownloadLauncherMetadata.java +++ b/src/main/java/org/parchmentmc/lodestone/tasks/DownloadLauncherMetadata.java @@ -22,12 +22,25 @@ import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING; import static java.nio.file.StandardOpenOption.WRITE; +/** + * The DownloadLauncherMetadata task downloads the launcher metadata from the Mojang server and saves it to a file. + * The task is executed during the build process and can be configured to output the metadata file to a specific location. + */ @SuppressWarnings("UnstableApiUsage") public abstract class DownloadLauncherMetadata extends DefaultTask { + + /** + * Constructs a new DownloadLauncherMetadata task and sets the default output location for the metadata file. + */ public DownloadLauncherMetadata() { this.getOutput().convention(getProject().getLayout().getBuildDirectory().dir(getName()).map(d -> d.file("launcher.json"))); } + /** + * Downloads the launcher metadata from the Mojang server and saves it to a file. + * + * @throws IOException if an error occurs while downloading or saving the metadata file + */ @SuppressWarnings("ResultOfMethodCallIgnored") @TaskAction void download() throws IOException { @@ -46,9 +59,19 @@ void download() throws IOException { } } + /** + * Returns the output file property for the launcher metadata file. + * + * @return the output file property for the launcher metadata file + */ @OutputFile public abstract RegularFileProperty getOutput(); + /** + * Returns a Gson instance configured to deserialize the Mojang launcher metadata format. + * + * @return a Gson instance configured to deserialize the Mojang launcher metadata format + */ public static Gson getLauncherManifestGson() { return new GsonBuilder().registerTypeAdapter(OffsetDateTime.class, new OffsetDateTimeAdapter()).disableHtmlEscaping().create(); } diff --git a/src/main/java/org/parchmentmc/lodestone/tasks/DownloadVersion.java b/src/main/java/org/parchmentmc/lodestone/tasks/DownloadVersion.java index 277ee3b..c015bca 100644 --- a/src/main/java/org/parchmentmc/lodestone/tasks/DownloadVersion.java +++ b/src/main/java/org/parchmentmc/lodestone/tasks/DownloadVersion.java @@ -22,12 +22,26 @@ import static java.nio.file.StandardOpenOption.*; +/** + * The DownloadVersion task downloads the necessary files for a Minecraft version to be run, including the Minecraft + * client jar, the server jar, and any libraries required by those jars. + */ public abstract class DownloadVersion extends MinecraftVersionTask { + + /** + * Constructs a new DownloadVersion task and sets the default input and output locations for the downloaded files. + */ public DownloadVersion() { this.getInput().convention(getProject().getLayout().getBuildDirectory().dir(getName()).flatMap(d -> d.file(this.getMcVersion().map(s -> s + ".json")))); this.getOutput().convention(getProject().getLayout().getBuildDirectory().dir(getName()).flatMap(s -> s.dir(this.getMcVersion()))); } + /** + * Downloads the necessary files for the Minecraft version to be run, including the Minecraft client jar, the + * server jar, and any libraries required by those jars. + * + * @throws IOException if an error occurs while downloading or saving the files + */ @SuppressWarnings("ResultOfMethodCallIgnored") @TaskAction void download() throws IOException { @@ -75,9 +89,19 @@ void download() throws IOException { } } + /** + * Returns the input file property for the version manifest JSON file. + * + * @return the input file property for the version manifest JSON file + */ @InputFile public abstract RegularFileProperty getInput(); + /** + * Returns the output directory property for the downloaded files. + * + * @return the output directory property for the downloaded files + */ @OutputDirectory public abstract DirectoryProperty getOutput(); } diff --git a/src/main/java/org/parchmentmc/lodestone/tasks/DownloadVersionMetadata.java b/src/main/java/org/parchmentmc/lodestone/tasks/DownloadVersionMetadata.java index 956b3a2..a739cbd 100644 --- a/src/main/java/org/parchmentmc/lodestone/tasks/DownloadVersionMetadata.java +++ b/src/main/java/org/parchmentmc/lodestone/tasks/DownloadVersionMetadata.java @@ -18,12 +18,28 @@ import static java.nio.file.StandardOpenOption.*; +/** + * The DownloadVersionMetadata task downloads the version metadata for a given Minecraft version, + * including the JSON file that contains information about the version's client jar, server jar, + * and any required libraries. + */ public abstract class DownloadVersionMetadata extends MinecraftVersionTask { + + /** + * Constructs a new DownloadVersionMetadata task and sets the default input and output locations for the downloaded + * version metadata files. + */ public DownloadVersionMetadata() { this.getInput().convention(getProject().getLayout().getBuildDirectory().dir(getName()).map(d -> d.file("launcher.json"))); this.getOutput().convention(getProject().getLayout().getBuildDirectory().dir(getName()).flatMap(d -> d.file(this.getMcVersion().map(s -> s + ".json")))); } + /** + * Downloads the version metadata for the given Minecraft version, including the JSON file that contains + * information about the version's client jar, server jar, and any required libraries. + * + * @throws IOException if an error occurs while downloading or saving the version metadata files + */ @SuppressWarnings("ResultOfMethodCallIgnored") @TaskAction void download() throws IOException { @@ -56,6 +72,14 @@ void download() throws IOException { } } + /** + * Resolves the Minecraft version to download based on the provided Minecraft version string and the launcher + * manifest. + * + * @param mcVersion the Minecraft version string to resolve + * @param launcherManifest the launcher manifest containing the available Minecraft versions + * @return the resolved Minecraft version string + */ public static String resolveMinecraftVersion(String mcVersion, LauncherManifest launcherManifest) { switch (mcVersion) { case "latest_snapshot": @@ -82,9 +106,19 @@ public static String resolveMinecraftVersion(String mcVersion, LauncherManifest return mcVersion; } + /** + * Returns the input file property for the launcher manifest JSON file. + * + * @return the input file property for the launcher manifest JSON file + */ @InputFile public abstract RegularFileProperty getInput(); + /** + * Returns the output file property for the downloaded version metadata file. + * + * @return the output file property for the downloaded version metadata file + */ @OutputFile public abstract RegularFileProperty getOutput(); } diff --git a/src/main/java/org/parchmentmc/lodestone/tasks/ExtractMetadataFromJarFiles.java b/src/main/java/org/parchmentmc/lodestone/tasks/ExtractMetadataFromJarFiles.java index 8cf8084..e198f17 100644 --- a/src/main/java/org/parchmentmc/lodestone/tasks/ExtractMetadataFromJarFiles.java +++ b/src/main/java/org/parchmentmc/lodestone/tasks/ExtractMetadataFromJarFiles.java @@ -23,11 +23,27 @@ import java.util.function.Function; import java.util.stream.Stream; +/** + * The ExtractMetadataFromJarFiles task extracts metadata from a Minecraft client jar file and any required library + * jar files, and outputs the metadata as a JSON file. + */ public abstract class ExtractMetadataFromJarFiles extends ExtractMetadataTask { + + /** + * Constructs a new ExtractMetadataFromJarFiles task and sets the default output location for the metadata JSON file. + */ public ExtractMetadataFromJarFiles() { this.getOutput().convention(getProject().getLayout().getBuildDirectory().dir(getName()).map(d -> d.file("metadata.json"))); } + /** + * Extracts metadata from the given Minecraft client jar file and any required library jar files, and returns + * a SourceMetadata object that represents the metadata for the client jar and its contents. + * + * @param clientJarFile the Minecraft client jar file to extract metadata from + * @return a SourceMetadata object that represents the metadata for the client jar and its contents + * @throws IOException if an error occurs while reading or parsing the jar files + */ @Override protected SourceMetadata extractMetadata(File clientJarFile) throws IOException { final File librariesDirectory = this.getLibraries().getAsFile().get(); @@ -68,10 +84,23 @@ protected SourceMetadata extractMetadata(File clientJarFile) throws IOException return adaptClassTypes(baseDataSet); } + /** + * Adapts the class types in the given SourceMetadata object to be compatible with the Minecraft data model. + * + * @param sourceMetadata the SourceMetadata object to adapt + * @return the adapted SourceMetadata object + */ private static SourceMetadata adaptClassTypes(final SourceMetadata sourceMetadata) { return adaptInnerOuterClassList(sourceMetadata); } + /** + * Adapts the inner and outer class lists in the given SourceMetadata object to be compatible with the Minecraft + * data model. + * + * @param sourceMetadata the SourceMetadata object to adapt + * @return the adapted SourceMetadata object + */ private static SourceMetadata adaptInnerOuterClassList(final SourceMetadata sourceMetadata) { final Map namedClassMetadataMap = sourceMetadata.getClasses() .stream() @@ -100,6 +129,11 @@ private static SourceMetadata adaptInnerOuterClassList(final SourceMetadata sour .build(); } + /** + * Returns the input directory containing the required library jar files for the task. + * + * @return the input directory containing the required library jar files for the task + */ @InputDirectory public abstract DirectoryProperty getLibraries(); } diff --git a/src/main/java/org/parchmentmc/lodestone/tasks/ExtractMetadataFromProguardFile.java b/src/main/java/org/parchmentmc/lodestone/tasks/ExtractMetadataFromProguardFile.java index 44dbd36..7496c8a 100644 --- a/src/main/java/org/parchmentmc/lodestone/tasks/ExtractMetadataFromProguardFile.java +++ b/src/main/java/org/parchmentmc/lodestone/tasks/ExtractMetadataFromProguardFile.java @@ -5,11 +5,26 @@ import java.io.File; +/** + * The ExtractMetadataFromProguardFile task extracts metadata from a Proguard mapping file and outputs the metadata + * as a JSON file. + */ public abstract class ExtractMetadataFromProguardFile extends ExtractMetadataTask { + + /** + * Constructs a new ExtractMetadataFromProguardFile task and sets the default output location for the metadata JSON file. + */ public ExtractMetadataFromProguardFile() { this.getOutput().convention(getProject().getLayout().getBuildDirectory().dir(getName()).map(d -> d.file("proguard.json"))); } + /** + * Extracts metadata from the given Proguard mapping file and returns a SourceMetadata object that represents the + * metadata for the obfuscated code. + * + * @param source the Proguard mapping file to extract metadata from + * @return a SourceMetadata object that represents the metadata for the obfuscated code + */ @Override protected SourceMetadata extractMetadata(File source) { return MetadataProguardParser.fromFile(source); diff --git a/src/main/java/org/parchmentmc/lodestone/tasks/ExtractMetadataTask.java b/src/main/java/org/parchmentmc/lodestone/tasks/ExtractMetadataTask.java index c03847a..383e9bb 100644 --- a/src/main/java/org/parchmentmc/lodestone/tasks/ExtractMetadataTask.java +++ b/src/main/java/org/parchmentmc/lodestone/tasks/ExtractMetadataTask.java @@ -15,7 +15,17 @@ import java.io.FileWriter; import java.io.IOException; +/** + * The ExtractMetadataTask is an abstract base class for tasks that extract metadata from Minecraft code in various formats + * and output the metadata as a JSON file. + */ public abstract class ExtractMetadataTask extends MinecraftVersionTask { + + /** + * Executes the task by extracting metadata from the input file and writing it to the output file. + * + * @throws IOException if an error occurs while reading or writing the files + */ @SuppressWarnings("ResultOfMethodCallIgnored") @TaskAction private void execute() throws IOException { @@ -35,6 +45,11 @@ private void execute() throws IOException { fileWriter.close(); } + /** + * Creates a Gson instance with the necessary type adapters for serializing metadata to JSON. + * + * @return a Gson instance with the necessary type adapters for serializing metadata to JSON + */ protected static Gson createMetadataGson() { return new GsonBuilder() .registerTypeAdapter(SimpleVersion.class, new SimpleVersionAdapter()) @@ -44,11 +59,28 @@ protected static Gson createMetadataGson() { .create(); } + /** + * Extracts metadata from the given input file and returns a SourceMetadata object that represents the metadata. + * + * @param inputFile the input file to extract metadata from + * @return a SourceMetadata object that represents the metadata from the input file + * @throws IOException if an error occurs while reading or parsing the input file + */ protected abstract SourceMetadata extractMetadata(File inputFile) throws IOException; + /** + * Returns the input file for the task. + * + * @return the input file for the task + */ @InputFile public abstract RegularFileProperty getInput(); + /** + * Returns the output file for the task. + * + * @return the output file for the task + */ @OutputFile public abstract RegularFileProperty getOutput(); } diff --git a/src/main/java/org/parchmentmc/lodestone/tasks/MergeMetadata.java b/src/main/java/org/parchmentmc/lodestone/tasks/MergeMetadata.java index 80e5621..92b35a0 100644 --- a/src/main/java/org/parchmentmc/lodestone/tasks/MergeMetadata.java +++ b/src/main/java/org/parchmentmc/lodestone/tasks/MergeMetadata.java @@ -21,15 +21,33 @@ import java.util.Map; import java.util.stream.Collectors; +/** + * It provides methods for merging metadata in Minecraft versions. + */ public abstract class MergeMetadata extends MinecraftVersionTask { + /** + * Constructs a new {@code MergeMetadata} object. + * It sets the default output file for merged metadata. + */ public MergeMetadata() { this.getOutput().convention(getProject().getLayout().getBuildDirectory().dir(getName()).map(d -> d.file("merged.json"))); } + /** + * Returns the output file property for the merged metadata. + * + * @return the output file property + */ @OutputFile public abstract RegularFileProperty getOutput(); + /** + * Adapts the types of the source metadata by mapping obfuscated names to Mojang names. + * + * @param sourceMetadata the source metadata to adapt + * @return the adapted source metadata + */ private static SourceMetadata adaptTypes(final SourceMetadata sourceMetadata) { final Map obfToMojClassNameMap = new LinkedHashMap<>(); final Map obfKeyToMojMethodNameMap = new LinkedHashMap<>(); @@ -109,6 +127,14 @@ private static SourceMetadata adaptTypes(final SourceMetadata sourceMetadata) { return bouncerRemappedDataBuilder.build(); } + /** + * Adapts the signatures of a class metadata by mapping obfuscated names to Mojang names. + * + * @param classMetadata the class metadata to adapt + * @param obfToMojNameMap the map of obfuscated names to Mojang names + * @param remapper the ASMRemapper used for remapping + * @return the adapted class metadata + */ private static ClassMetadata adaptSignatures( final ClassMetadata classMetadata, final Map obfToMojNameMap, @@ -273,6 +299,15 @@ private static ClassMetadata adaptSignatures( return classMetadataBuilder.build(); } + /** + * Adapts the references of a class metadata by mapping obfuscated names to Mojang names. + * + * @param classMetadata the class metadata to adapt + * @param obfKeyToMojMethodNameMap the map of obfuscated method names to Mojang method names + * @param obfKeyToMojFieldNameMap the map of obfuscated field names to Mojang field names + * @param remapper the ASMRemapper used for remapping + * @return the adapted class metadata + */ private static ClassMetadata adaptReferences( final ClassMetadata classMetadata, final Map obfKeyToMojMethodNameMap, @@ -385,6 +420,14 @@ private static ClassMetadata adaptReferences( return classMetadataBuilder.build(); } + /** + * Creates a remapped reference using the given ASMRemapper and method metadata. + * + * @param remapper The ASMRemapper used for remapping the signature. + * @param methodMetadata The method metadata containing information about the method. + * @return A ReferenceBuilder representing the remapped reference. + * @throws IllegalStateException if the obfuscated name is missing in the method signature. + */ private static ReferenceBuilder createRemappedReference(final ASMRemapper remapper, final BaseReference methodMetadata) { final ReferenceBuilder targetBuilder = ReferenceBuilder.create() .withOwner(methodMetadata.getOwner()) @@ -410,6 +453,13 @@ private static ReferenceBuilder createRemappedReference(final ASMRemapper remapp return targetBuilder; } + /** + * Collects the obfuscated class names and their corresponding Mojang names recursively + * from the given class metadata and stores them in the provided map. + * + * @param classMetadata the class metadata to collect names from + * @param obfToMojMap the map to store the collected names + */ private static void collectClassNames(final ClassMetadata classMetadata, final Map obfToMojMap) { obfToMojMap.put( classMetadata.getName().getObfuscatedName().orElseThrow(() -> new IllegalStateException("Missing obfuscated name.")), @@ -419,6 +469,12 @@ private static void collectClassNames(final ClassMetadata classMetadata, final M classMetadata.getInnerClasses().forEach(innerClassMetadata -> collectClassNames(innerClassMetadata, obfToMojMap)); } + /** + * Recursively collects the method names from the given ClassMetadata and populates them into the objKeyToMojNameMap. + * + * @param classMetadata The ClassMetadata to collect method names from. + * @param objKeyToMojNameMap The map to store the method names, where the keys are method keys and the values are MethodMetadata objects. + */ private static void collectMethodNames(final ClassMetadata classMetadata, final Map objKeyToMojNameMap) { classMetadata.getMethods().forEach(methodMetadata -> objKeyToMojNameMap.put( buildMethodKey(methodMetadata), @@ -428,6 +484,12 @@ private static void collectMethodNames(final ClassMetadata classMetadata, final classMetadata.getInnerClasses().forEach(innerClassMetadata -> collectMethodNames(innerClassMetadata, objKeyToMojNameMap)); } + /** + * Recursively collects the field names from the given ClassMetadata and populates them into the objKeyToMojNameMap. + * + * @param classMetadata The ClassMetadata to collect field names from. + * @param objKeyToMojNameMap The map to store the field names, where the keys are field keys and the values are FieldMetadata objects. + */ private static void collectFieldNames(final ClassMetadata classMetadata, final Map objKeyToMojNameMap) { classMetadata.getFields().forEach(fieldMetadata -> objKeyToMojNameMap.put( buildFieldKey(fieldMetadata), @@ -437,6 +499,13 @@ private static void collectFieldNames(final ClassMetadata classMetadata, final M classMetadata.getInnerClasses().forEach(innerClassMetadata -> collectFieldNames(innerClassMetadata, objKeyToMojNameMap)); } + /** + * Builds a method key based on the given MethodMetadata. + * + * @param methodMetadata The MethodMetadata object containing the necessary information. + * @return A string representing the method key in the format "className/methodNamemethodDesc". + * @throws IllegalStateException if any obfuscated name in the MethodMetadata is missing. + */ private static String buildMethodKey(final MethodMetadata methodMetadata) { return buildMethodKey( methodMetadata.getOwner().getObfuscatedName().orElseThrow(() -> new IllegalStateException("Missing obfuscated owner name.")), @@ -445,6 +514,13 @@ private static String buildMethodKey(final MethodMetadata methodMetadata) { ); } + /** + * Builds a method key based on the given Reference object. + * + * @param reference The Reference object containing the necessary information. + * @return A string representing the method key in the format "className/methodNamemethodDesc". + * @throws IllegalStateException if any obfuscated name in the Reference is missing. + */ private static String buildMethodKey(final Reference Reference) { return buildMethodKey( Reference.getOwner().getObfuscatedName().orElseThrow(() -> new IllegalStateException("Missing obfuscated owner name.")), @@ -453,6 +529,14 @@ private static String buildMethodKey(final Reference Reference) { ); } + /** + * Builds a method key based on the given class name, method name, and method descriptor. + * + * @param className The obfuscated class name. + * @param methodName The obfuscated method name. + * @param methodDesc The obfuscated method descriptor. + * @return A string representing the method key in the format "className/methodNamemethodDesc". + */ private static String buildMethodKey(final String className, final String methodName, final String methodDesc) { return String.format("%s/%s%s", className, @@ -460,6 +544,13 @@ private static String buildMethodKey(final String className, final String method methodDesc); } + /** + * Builds a field key based on the given FieldMetadata. + * + * @param fieldMetadata The FieldMetadata object containing the necessary information. + * @return A string representing the field key in the format "className/fieldNamefieldDesc". + * @throws IllegalStateException if any obfuscated name in the FieldMetadata is missing. + */ private static String buildFieldKey(final FieldMetadata fieldMetadata) { return buildFieldKey( fieldMetadata.getOwner().getObfuscatedName().orElseThrow(() -> new IllegalStateException("Missing obfuscated owner name.")), @@ -468,6 +559,13 @@ private static String buildFieldKey(final FieldMetadata fieldMetadata) { ); } + /** + * Builds a field key based on the given Reference object. + * + * @param reference The Reference object containing the necessary information. + * @return A string representing the field key in the format "className/fieldNamefieldDesc". + * @throws IllegalStateException if any obfuscated name in the Reference is missing. + */ private static String buildFieldKey(final Reference fieldMetadata) { return buildFieldKey( fieldMetadata.getOwner().getObfuscatedName().orElseThrow(() -> new IllegalStateException("Missing obfuscated owner name.")), @@ -476,6 +574,14 @@ private static String buildFieldKey(final Reference fieldMetadata) { ); } + /** + * Builds a field key based on the given class name, field name, and field descriptor. + * + * @param className The obfuscated class name. + * @param fieldName The obfuscated field name. + * @param fieldDesc The obfuscated field descriptor. + * @return A string representing the field key in the format "className/fieldNamefieldDesc". + */ private static String buildFieldKey(final String className, final String fieldName, final String fieldDesc) { return String.format("%s/%s%s", className, @@ -483,6 +589,11 @@ private static String buildFieldKey(final String className, final String fieldNa fieldDesc); } + /** + * Executes the task to merge source metadata from the left and right sources, adapt the types, and write the merged metadata to the output file. + * + * @throws IOException if an I/O error occurs during file operations. + */ @SuppressWarnings("ResultOfMethodCallIgnored") @TaskAction void execute() throws IOException { @@ -508,9 +619,19 @@ void execute() throws IOException { fileWriter.close(); } + /** + * Returns the property representing the left source file for merging. + * + * @return The property representing the left source file. + */ @InputFile public abstract RegularFileProperty getLeftSource(); + /** + * Returns the property representing the right source file for merging. + * + * @return The property representing the right source file. + */ @InputFile public abstract RegularFileProperty getRightSource(); } diff --git a/src/main/java/org/parchmentmc/lodestone/tasks/MinecraftVersionTask.java b/src/main/java/org/parchmentmc/lodestone/tasks/MinecraftVersionTask.java index 431aa6e..d2060f3 100644 --- a/src/main/java/org/parchmentmc/lodestone/tasks/MinecraftVersionTask.java +++ b/src/main/java/org/parchmentmc/lodestone/tasks/MinecraftVersionTask.java @@ -10,9 +10,20 @@ * Extending this class provides a Minecraft version property and default convention value for it. */ public abstract class MinecraftVersionTask extends DefaultTask { + + /** + * Returns the property representing the Minecraft version. + * + * @return The property representing the Minecraft version. + */ @Input public abstract Property getMcVersion(); + /** + * Constructs a new instance of the {@code MinecraftVersionTask} class. + * Sets the default Minecraft version based on the {@code LodestoneExtension} if available. + * If the extension is not found, the default version is set to "latest". + */ protected MinecraftVersionTask() { LodestoneExtension extension = getProject().getExtensions().findByType(LodestoneExtension.class); if (extension == null) { diff --git a/src/main/java/org/parchmentmc/lodestone/util/ASMRemapper.java b/src/main/java/org/parchmentmc/lodestone/util/ASMRemapper.java index df1b2e1..4d8d3d5 100644 --- a/src/main/java/org/parchmentmc/lodestone/util/ASMRemapper.java +++ b/src/main/java/org/parchmentmc/lodestone/util/ASMRemapper.java @@ -4,16 +4,34 @@ import java.util.Map; +/** + * ASMRemapper provides mapping functionality for class and method names. + * It allows renaming classes and methods based on the provided mappings. + */ public class ASMRemapper extends Remapper { private final Map classRenames; private final Map methodRenames; + /** + * Constructs a new ASMRemapper with the specified class and method rename mappings. + * + * @param classRenames A map of class rename mappings. + * @param methodRenames A map of method rename mappings. + */ public ASMRemapper(final Map classRenames, final Map methodRenames) { this.classRenames = classRenames; this.methodRenames = methodRenames; } + /** + * Maps the given method name based on the owner, name, and descriptor. + * + * @param owner The internal name of the owning class. + * @param name The original name of the method. + * @param descriptor The method descriptor. + * @return The mapped method name, or the original name if no mapping is found. + */ @Override public String mapMethodName(final String owner, final String name, final String descriptor) { final String methodKey = String.format("%s/%s%s", @@ -24,6 +42,12 @@ public String mapMethodName(final String owner, final String name, final String return methodRenames.getOrDefault(methodKey, name); } + /** + * Maps the given key, which can be a class name or any other identifier. + * + * @param key The key to be mapped. + * @return The mapped key, or the original key if no mapping is found. + */ @Override public String map(final String key) { return classRenames.getOrDefault(key, key);