<commit_before>package co.uk.niadel.napi.asm.transformers;

import co.uk.niadel.napi.asm.IASMTransformer;
import co.uk.niadel.napi.modhandler.NAPIModRegister;
import co.uk.niadel.napi.util.NAPILogHelper;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.*;

import java.io.IOException;

/**
 * Gets rid of calls to System.out.println and System.err.println to encourage the use of a logger, as loggers allow us to know what
 * mod is "saying" what. This makes debugging with multiple mods installed MUCH easier.
 *
 * @author Niadel
 */
public class NAPIASMDeSysOutTransformer implements IASMTransformer, Opcodes
{
	private static boolean shouldRun = Boolean.valueOf(NAPIModRegister.napiConfig.getConfigValue("removeSysOut", "false"));

	@Override
	public byte[] manipulateBytecodes(String className)
	{
		if (shouldRun)
		{
			//Could be way more optimised, but I'll save that for later.
			try
			{
				ClassReader classReader = new ClassReader(className);
				ClassNode classNode = new ClassNode();
				classReader.accept(classNode, 0);

				//Yup. I'm allowing it to catch my own uses of System.out.println.
				if (!className.contains("net.minecraft.") && !className.startsWith("java"))
				{
					for (MethodNode method : classNode.methods)
					{
						String allExceptionsThrown = method.exceptions == null ? "---" : "";

						if (method.exceptions != null)
						{<commit_msg>Fixed bug where N-API would not remove sysout calls by default.<commit_after>package co.uk.niadel.napi.asm.transformers;

import co.uk.niadel.napi.asm.IASMTransformer;
import co.uk.niadel.napi.modhandler.NAPIModRegister;
import co.uk.niadel.napi.util.NAPILogHelper;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.*;

import java.io.IOException;

/**
 * Gets rid of calls to System.out.println and System.err.println to encourage the use of a logger, as loggers allow us to know what
 * mod is "saying" what. This makes debugging with multiple mods installed MUCH easier.
 *
 * @author Niadel
 */
public class NAPIASMDeSysOutTransformer implements IASMTransformer, Opcodes
{
	private static boolean shouldRun = Boolean.valueOf(NAPIModRegister.napiConfig.getConfigValue("removeSysOut", "true"));

	@Override
	public byte[] manipulateBytecodes(String className)
	{
		if (shouldRun)
		{
			//Could be way more optimised, but I'll save that for later.
			try
			{
				ClassReader classReader = new ClassReader(className);
				ClassNode classNode = new ClassNode();
				classReader.accept(classNode, 0);

				//Yup. I'm allowing it to catch my own uses of System.out.println.
				if (!className.contains("net.minecraft.") && !className.startsWith("java"))
				{
					for (MethodNode method : classNode.methods)
					{
						String allExceptionsThrown = method.exceptions == null ? "---" : "";

						if (method.exceptions != null)
						{
{'fraction_non_alphanumeric': 0.10863045651449517, 'fraction_numerical': 0.0006664445184938354, 'mean_word_length': 4.045378151260504, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1695404', 'n_tokens_mistral': 1036, 'n_tokens_neox': 917, 'n_words': 252}