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

Provide MappingTreeView -> IMappingProvider converter #128

Merged
Merged
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
31 changes: 23 additions & 8 deletions src/main/java/net/fabricmc/tinyremapper/TinyUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@

import net.fabricmc.mappingio.FlatMappingVisitor;
import net.fabricmc.mappingio.MappingReader;
import net.fabricmc.mappingio.MappingVisitor;
import net.fabricmc.mappingio.adapter.FlatAsRegularMappingVisitor;
import net.fabricmc.mappingio.adapter.MappingDstNsReorder;
import net.fabricmc.mappingio.adapter.MappingSourceNsSwitch;
import net.fabricmc.mappingio.tree.MappingTreeView;
import net.fabricmc.tinyremapper.IMappingProvider.MappingAcceptor;
import net.fabricmc.tinyremapper.IMappingProvider.Member;

Expand Down Expand Up @@ -74,15 +76,28 @@ public static IMappingProvider createTinyMappingProvider(final BufferedReader re
};
}

public static IMappingProvider createMappingProvider(MappingTreeView tree, String fromM, String toM) {
return out -> {
try {
tree.accept(createAdapter(fromM, toM, out));
} catch (IOException e) {
throw new RuntimeException(e);
}
};
}

private static void read(BufferedReader reader, String fromNs, String toNs, MappingAcceptor out) throws IOException {
MappingReader.read(reader,
// Ensure fromNs is on source and toNs is on destination side
new MappingSourceNsSwitch(
// Remove all dst namespaces we're not interested in
new MappingDstNsReorder(
new FlatAsRegularMappingVisitor(new MappingAdapter(out)),
toNs),
fromNs));
MappingReader.read(reader, createAdapter(fromNs, toNs, out));
}

private static MappingVisitor createAdapter(String fromNs, String toNs, MappingAcceptor out) throws IOException {
// Ensure fromNs is on source and toNs is on destination side
return new MappingSourceNsSwitch(
// Remove all dst namespaces we're not interested in
new MappingDstNsReorder(
new FlatAsRegularMappingVisitor(new MappingAdapter(out)),
toNs),
fromNs);
}

private static final class MappingAdapter implements FlatMappingVisitor {
Expand Down
Loading