Skip to content
This repository has been archived by the owner on Jan 23, 2025. It is now read-only.

Commit

Permalink
CommandReorderTiny: always output ordered mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
asiekierka committed Jun 28, 2019
1 parent ea16f28 commit 36a7433
Showing 1 changed file with 46 additions and 22 deletions.
68 changes: 46 additions & 22 deletions src/main/java/net/fabricmc/stitch/commands/CommandReorderTiny.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Comparator;
import java.util.Locale;

public class CommandReorderTiny extends Command {
Expand All @@ -50,6 +51,17 @@ public boolean isArgumentCountValid(int count) {
return count >= 4;
}

private int compareTriples(EntryTriple a, EntryTriple b) {
int c = a.getOwner().compareTo(b.getOwner());
if (c == 0) {
c = a.getDesc().compareTo(b.getDesc());
if (c == 0) {
c = a.getName().compareTo(b.getName());
}
}
return c;
}

@Override
public void run(String[] args) throws Exception {
File fileOld = new File(args[0]);
Expand All @@ -75,31 +87,43 @@ public void run(String[] args) throws Exception {
firstLineBuilder.append('\t').append(name);
}
writer.write(firstLineBuilder.append('\n').toString());
for (ClassEntry entry : input.getClassEntries()) {
StringBuilder s = new StringBuilder("CLASS");
for (String name : names) {
s.append('\t').append(entry.get(name));
input.getClassEntries().stream().sorted(Comparator.comparing((a) -> a.get(names[0]))).forEach((entry) -> {
try {
StringBuilder s = new StringBuilder("CLASS");
for (String name : names) {
s.append('\t').append(entry.get(name));
}
writer.write(s.append('\n').toString());
} catch (IOException e) {
throw new RuntimeException(e);
}
writer.write(s.append('\n').toString());
}
for (FieldEntry entry : input.getFieldEntries()) {
StringBuilder s = new StringBuilder("FIELD");
EntryTriple first = entry.get(names[0]);
s.append('\t').append(first.getOwner()).append('\t').append(first.getDesc());
for (String name : names) {
s.append('\t').append(entry.get(name).getName());
});
input.getFieldEntries().stream().sorted((a, b) -> compareTriples(a.get(names[0]), b.get(names[0]))).forEach((entry) -> {
try {
StringBuilder s = new StringBuilder("FIELD");
EntryTriple first = entry.get(names[0]);
s.append('\t').append(first.getOwner()).append('\t').append(first.getDesc());
for (String name : names) {
s.append('\t').append(entry.get(name).getName());
}
writer.write(s.append('\n').toString());
} catch (IOException e) {
throw new RuntimeException(e);
}
writer.write(s.append('\n').toString());
}
for (MethodEntry entry : input.getMethodEntries()) {
StringBuilder s = new StringBuilder("METHOD");
EntryTriple first = entry.get(names[0]);
s.append('\t').append(first.getOwner()).append('\t').append(first.getDesc());
for (String name : names) {
s.append('\t').append(entry.get(name).getName());
});
input.getMethodEntries().stream().sorted((a, b) -> compareTriples(a.get(names[0]), b.get(names[0]))).forEach((entry) -> {
try {
StringBuilder s = new StringBuilder("METHOD");
EntryTriple first = entry.get(names[0]);
s.append('\t').append(first.getOwner()).append('\t').append(first.getDesc());
for (String name : names) {
s.append('\t').append(entry.get(name).getName());
}
writer.write(s.append('\n').toString());
} catch (IOException e) {
throw new RuntimeException(e);
}
writer.write(s.append('\n').toString());
}
});
}

System.err.println("Done!");
Expand Down

0 comments on commit 36a7433

Please sign in to comment.