Skip to content

Commit 82ec51b

Browse files
committed
feat: consumer-based logMethod, drop log4j dependency
1 parent eab8035 commit 82ec51b

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

build.gradle

-1
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,4 @@ repositories {
1919
dependencies {
2020
implementation 'org.ow2.asm:asm-commons:9.7'
2121
implementation 'org.ow2.asm:asm-util:9.7'
22-
implementation 'org.apache.logging.log4j:log4j-api:2.20.0'
2322
}

src/main/java/ftbsc/lll/utils/debug/BytecodePrinter.java

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package ftbsc.lll.utils.debug;
22

3-
import org.apache.logging.log4j.Logger;
43
import org.objectweb.asm.tree.AbstractInsnNode;
54
import org.objectweb.asm.tree.MethodNode;
65
import org.objectweb.asm.util.Printer;
@@ -12,6 +11,7 @@
1211
import java.io.StringWriter;
1312
import java.nio.file.Files;
1413
import java.nio.file.Paths;
14+
import java.util.function.Consumer;
1515

1616
/**
1717
* A collection of static methods for debugging by printing the ASM bytecode.
@@ -30,33 +30,33 @@ public class BytecodePrinter {
3030
private static final TraceMethodVisitor MP = new TraceMethodVisitor(PRINTER);
3131

3232
/**
33-
* Prints the bytecode of a method using System.out.print().
33+
* Logs the bytecode of a method on System.out.
3434
* @param main the method to print
3535
*/
36-
public static void printMethod(final MethodNode main) {
37-
for (AbstractInsnNode i : main.instructions.toArray())
38-
System.out.print(insnToString(i));
36+
public static void logMethod(MethodNode main) {
37+
logMethod(main, System.out::println);
3938
}
4039

4140
/**
42-
* Logs the bytecode of a method using the ASM logger.
41+
* Logs the bytecode of a method into a given sink.
4342
* @param main the method to print
44-
* @param logger the Log4j {@link Logger} to print it with
43+
* @param logFn a consumer for the string, typically a logging function
44+
* @since 0.6.0
4545
*/
46-
public static void logMethod(final MethodNode main, final Logger logger) {
47-
for (AbstractInsnNode i : main.instructions.toArray())
48-
logger.debug(insnToString(i));
46+
public static void logMethod(MethodNode main, Consumer<String> logFn) {
47+
for(AbstractInsnNode i : main.instructions.toArray()) {
48+
logFn.accept(insnToString(i));
49+
}
4950
}
5051

5152
/**
5253
* Logs the bytecode of a method to a file.
5354
* @param main the method to print
5455
* @param path the file to log it to
5556
*/
56-
public static void logMethod(final MethodNode main, String path) {
57+
public static void logMethod(MethodNode main, String path) {
5758
StringBuilder out = new StringBuilder();
58-
for (AbstractInsnNode i : main.instructions.toArray())
59-
out.append(insnToString(i));
59+
logMethod(main, out::append);
6060
try {
6161
Files.write(Paths.get(path), out.toString().getBytes());
6262
} catch (IOException e) {

0 commit comments

Comments
 (0)