Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate from mappings-io over to srgutils #2

Merged
merged 1 commit into from
Dec 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion parchment/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ plugins {
dependencies {
implementation project(":api")
implementation 'org.parchmentmc.feather:io-gson:1.1.0'
implementation 'net.fabricmc:mapping-io:0.5.1'
implementation 'net.neoforged:srgutils:1.0.0'
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package net.neoforged.jst.parchment.namesanddocs;

import net.fabricmc.mappingio.MappingReader;
import net.fabricmc.mappingio.format.MappingFormat;
import net.fabricmc.mappingio.tree.MemoryMappingTree;
import net.neoforged.jst.parchment.namesanddocs.mappingio.TreeData;
import net.neoforged.jst.parchment.namesanddocs.srgutils.MappingFileDatabase;
import net.neoforged.jst.parchment.namesanddocs.parchment.ParchmentDatabase;
import net.neoforged.srgutils.INamedMappingFile;
import org.jetbrains.annotations.Nullable;

import java.io.IOException;
Expand All @@ -26,12 +24,7 @@ public static NamesAndDocsDatabase load(Path path, @Nullable NameAndDocsFormat f
return switch (format) {
case PARCHMENT_ZIP -> ParchmentDatabase.loadZip(path);
case PARCHMENT_JSON -> ParchmentDatabase.loadJson(path);
case TSRG2 -> {
var tree = new MemoryMappingTree(true);
MappingReader.read(path, MappingFormat.TSRG_2_FILE, tree);

yield new TreeData(tree);
}
case TSRG2 -> MappingFileDatabase.load(path);
};
}

Expand All @@ -48,5 +41,3 @@ private static NameAndDocsFormat guessFormat(Path path) {
}

}


This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package net.neoforged.jst.parchment.namesanddocs.mappingio;
package net.neoforged.jst.parchment.namesanddocs.srgutils;

import net.fabricmc.mappingio.tree.MappingTree;
import net.neoforged.jst.parchment.namesanddocs.NamesAndDocsForClass;
import net.neoforged.jst.parchment.namesanddocs.NamesAndDocsForField;
import net.neoforged.jst.parchment.namesanddocs.NamesAndDocsForMethod;
import net.neoforged.srgutils.IMappingFile;

import java.util.List;

class TreeClassData implements NamesAndDocsForClass {
private final MappingTree.ClassMapping classData;
class MappingFileClassData implements NamesAndDocsForClass {
private final IMappingFile.IClass classData;

public TreeClassData(MappingTree.ClassMapping classData) {
public MappingFileClassData(IMappingFile.IClass classData) {

this.classData = classData;
}
Expand All @@ -27,7 +27,7 @@ public NamesAndDocsForField getField(String name) {

@Override
public NamesAndDocsForMethod getMethod(String name, String methodSignature) {
var methodData = classData.getMethod(name, methodSignature, 0);
return methodData != null ? new TreeMethodData(methodData) : null;
var methodData = classData.getMethod(name, methodSignature);
return methodData != null ? new MappingFileMethodData(methodData) : null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package net.neoforged.jst.parchment.namesanddocs.srgutils;

import net.neoforged.jst.parchment.namesanddocs.NamesAndDocsDatabase;
import net.neoforged.jst.parchment.namesanddocs.NamesAndDocsForClass;
import net.neoforged.srgutils.IMappingFile;
import net.neoforged.srgutils.INamedMappingFile;

import java.io.IOException;
import java.nio.file.Path;

public class MappingFileDatabase implements NamesAndDocsDatabase {
private final IMappingFile tree;

public MappingFileDatabase(INamedMappingFile tree) {
this.tree = tree.getMap("right", "right");
}

public static MappingFileDatabase load(Path path) throws IOException {
var mappingFile = INamedMappingFile.load(path.toFile());
return new MappingFileDatabase(mappingFile);
}

@Override
public NamesAndDocsForClass getClass(String className) {
var classData = tree.getClass(className);
return classData != null ? new MappingFileClassData(classData) : null;
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package net.neoforged.jst.parchment.namesanddocs.mappingio;
package net.neoforged.jst.parchment.namesanddocs.srgutils;

import net.fabricmc.mappingio.tree.MappingTree;
import net.neoforged.jst.parchment.namesanddocs.NamesAndDocsForMethod;
import net.neoforged.jst.parchment.namesanddocs.NamesAndDocsForParameter;
import net.neoforged.srgutils.IMappingFile;
import org.jetbrains.annotations.Nullable;

import java.util.List;

public class TreeMethodData implements NamesAndDocsForMethod {
private final MappingTree.MethodMapping methodData;
public class MappingFileMethodData implements NamesAndDocsForMethod {
private final IMappingFile.IMethod methodData;

public TreeMethodData(MappingTree.MethodMapping methodData) {
public MappingFileMethodData(IMappingFile.IMethod methodData) {
this.methodData = methodData;
}

Expand All @@ -21,14 +21,14 @@ public List<String> getJavadoc() {

@Override
public NamesAndDocsForParameter getParameter(int index) {
var paramData = methodData.getArg(0, index, null);
if (paramData == null || paramData.getName(0) == null) {
var paramData = methodData.getParameter(index);
if (paramData == null || paramData.getMapped() == null) {
return null;
}
return new NamesAndDocsForParameter() {
@Override
public @Nullable String getName() {
return paramData.getName(0);
return paramData.getOriginal();
}

@Override
Expand Down
3 changes: 3 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ dependencyResolutionManagement {
maven {
url "https://maven.parchmentmc.org/"
}
maven {
url "https://maven.neoforged.net/releases/"
}
}
}

Expand Down
8 changes: 8 additions & 0 deletions tests/data/tsrg_file/expected/pkg/TestClass.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package pkg;

import java.util.*;

public class TestClass {
public void m(String p_254545_, List<String> p_254546_) {
}
}
5 changes: 5 additions & 0 deletions tests/data/tsrg_file/merged.tsrg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
tsrg2 left right
obfuscated_c pkg/TestClass
obfuscated_m (Ljava/lang/String;Ljava/util/List;)V m
1 o p_254545_
2 o p_254546_
8 changes: 8 additions & 0 deletions tests/data/tsrg_file/source/pkg/TestClass.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package pkg;

import java.util.*;

public class TestClass {
public void m(String a1, List<String> a2) {
}
}
19 changes: 12 additions & 7 deletions tests/src/test/java/net/neoforged/jst/tests/EmbeddedTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,27 +186,32 @@ void archiveOutput() throws Exception {

@Test
void testInnerAndLocalClasses() throws Exception {
runTest("nested");
runTest("nested", "parchment.json");
}

@Test
void testExternalReferences() throws Exception {
runTest("external_refs");
runTest("external_refs", "parchment.json");
}

@Test
void testParamIndices() throws Exception {
runTest("param_indices");
runTest("param_indices", "parchment.json");
}

@Test
void testJavadoc() throws Exception {
runTest("javadoc");
runTest("javadoc", "parchment.json");
}

protected final void runTest(String testDirName) throws Exception {
@Test
void testTsrgMappings() throws Exception {
runTest("tsrg_file", "merged.tsrg");
}

protected final void runTest(String testDirName, String mappingsFilename) throws Exception {
var testDir = testDataRoot.resolve(testDirName);
var parchmentFile = testDir.resolve("parchment.json");
var mappingsFile = testDir.resolve(mappingsFilename);
var sourceDir = testDir.resolve("source");
var expectedDir = testDir.resolve("expected");

Expand All @@ -227,7 +232,7 @@ protected final void runTest(String testDirName) throws Exception {
librariesFile.toString(),
"--enable-parchment",
"--parchment-mappings",
parchmentFile.toString(),
mappingsFile.toString(),
inputFile.toString(),
outputFile.toString()
);
Expand Down