Skip to content
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
12 changes: 8 additions & 4 deletions hypo-asm/src/main/java/dev/denwav/hypo/asm/AsmOutputWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.function.ToIntFunction;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
Expand All @@ -43,22 +44,25 @@
public final class AsmOutputWriter implements HypoOutputWriter {

private final @NotNull Path outputFile;
private final @NotNull ToIntFunction<ClassNode> writerFlags;

private AsmOutputWriter(final @NotNull Path outputFile) {
private AsmOutputWriter(final @NotNull Path outputFile, final @NotNull ToIntFunction<ClassNode> writerFlags) {
this.outputFile = outputFile;
this.writerFlags = writerFlags;
}

/**
* Create a new instance of a {@link AsmOutputWriter} which writes to the given file as a jar file.
*
* @param output The jar file to write to. Must not already exist.
* @param writerFlags Function which provides writer flags for a given {@link ClassNode}.
* @return The new {@link AsmOutputWriter}.
*/
public static @NotNull AsmOutputWriter to(final @NotNull Path output) {
public static @NotNull AsmOutputWriter to(final @NotNull Path output, final @NotNull ToIntFunction<ClassNode> writerFlags) {
if (Files.exists(output)) {
throw new IllegalArgumentException("Cannot write to jar file, as it already exists: " + output);
}
return new AsmOutputWriter(output);
return new AsmOutputWriter(output, writerFlags);
}

@Override
Expand Down Expand Up @@ -120,7 +124,7 @@ private void writeFile(
}

final ClassNode node = ((AsmClassData) data).getNode();
final ClassWriter writer = new ClassWriter(0);
final ClassWriter writer = new ClassWriter(this.writerFlags.applyAsInt(node));
node.accept(writer);

final byte[] classBytes = writer.toByteArray();
Expand Down
Loading