<commit_before>package code.elix_x.excomms.asm.transform.specific;

import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;

import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.InsnList;
import org.objectweb.asm.tree.MethodNode;

import code.elix_x.excomms.asm.transform.OpcodeGroups;

public class SpecificMethodNodeTransformer extends SpecificNodeTransformer<MethodNode> {

	public static SpecificMethodNodeTransformer instructionsTransformer(String target, int priority, Function<InsnList, InsnList> insnOld2new){
		return new SpecificMethodNodeTransformer(priority, target, node -> node.instructions = insnOld2new.apply(node.instructions));
	}

	public static SpecificMethodNodeTransformer instructionsTransformer(int priority, String target, Consumer<InsnList> insnConsumer){
		return new SpecificMethodNodeTransformer(priority, target, node -> insnConsumer.accept(node.instructions));
	}

	public static SpecificMethodNodeTransformer instructionsBegginningInserter(String target, int priority, InsnList insn){
		return instructionsTransformer(priority, target, instructions -> instructions.insertBefore(instructions.getFirst(), insn));
	}

	public static SpecificMethodNodeTransformer instructionsInserter(String target, int priority, Function<InsnList, AbstractInsnNode> where, InsnList insn, boolean before){
		return instructionsTransformer(priority, target, instructions -> {
			if(before) instructions.insertBefore(where.apply(instructions), insn);
			else instructions.insert(where.apply(instructions), insn);
		});
	}

	public static SpecificMethodNodeTransformer instructionsInserter(String target, int priority, Function<AbstractInsnNode, Pair<InsnList, Boolean>> inserter){
		return instructionsTransformer(priority, target, instructions -> {
			for(AbstractInsnNode node : instructions.toArray()){
				Pair<InsnList, Boolean> pair = inserter.apply(node);
				if(pair != null) if(pair.getRight()) instructions.insertBefore(node, pair.getLeft());
				else instructions.insert(node, pair.getLeft());
			}
		});
	}

	public static SpecificMethodNodeTransformer instructionsInserterBeforeReturn(String target, int priority, Supplier<InsnList> insn){
		return instructionsInserter(target, priority, node -> OpcodeGroups.RETURN.contains(node.getOpcode()) ? new ImmutablePair<>(insn.get(), true) : null);
	}

	private final String target;

	public SpecificMethodNodeTransformer(String target, int priority, Function<MethodNode, MethodNode> transform){
		super(MethodNode.class, priority, transform);
		this.target = target;
	}

	public SpecificMethodNodeTransformer(int priority, String target, Consumer<MethodNode> transform){
		super(priority, MethodNode.class, transform);
		this.target = target;
	}

	@Override
	public boolean accepts(MethodNode target){
		return this.target.equals(target.name);
	}

}<commit_msg>Forgot specific method trans description check<commit_after>package code.elix_x.excomms.asm.transform.specific;

import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;

import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.InsnList;
import org.objectweb.asm.tree.MethodNode;

import code.elix_x.excomms.asm.transform.OpcodeGroups;

public class SpecificMethodNodeTransformer extends SpecificNodeTransformer<MethodNode> {

	public static SpecificMethodNodeTransformer instructionsTransformer(String target, int priority, Function<InsnList, InsnList> insnOld2new){
		return new SpecificMethodNodeTransformer(priority, target, node -> node.instructions = insnOld2new.apply(node.instructions));
	}

	public static SpecificMethodNodeTransformer instructionsTransformer(int priority, String target, Consumer<InsnList> insnConsumer){
		return new SpecificMethodNodeTransformer(priority, target, node -> insnConsumer.accept(node.instructions));
	}

	public static SpecificMethodNodeTransformer instructionsBegginningInserter(String target, int priority, InsnList insn){
		return instructionsTransformer(priority, target, instructions -> instructions.insertBefore(instructions.getFirst(), insn));
	}

	public static SpecificMethodNodeTransformer instructionsInserter(String target, int priority, Function<InsnList, AbstractInsnNode> where, InsnList insn, boolean before){
		return instructionsTransformer(priority, target, instructions -> {
			if(before) instructions.insertBefore(where.apply(instructions), insn);
			else instructions.insert(where.apply(instructions), insn);
		});
	}

	public static SpecificMethodNodeTransformer instructionsInserter(String target, int priority, Function<AbstractInsnNode, Pair<InsnList, Boolean>> inserter){
		return instructionsTransformer(priority, target, instructions -> {
			for(AbstractInsnNode node : instructions.toArray()){
				Pair<InsnList, Boolean> pair = inserter.apply(node);
				if(pair != null) if(pair.getRight()) instructions.insertBefore(node, pair.getLeft());
				else instructions.insert(node, pair.getLeft());
			}
		});
	}

	public static SpecificMethodNodeTransformer instructionsInserterBeforeReturn(String target, int priority, Supplier<InsnList> insn){
		return instructionsInserter(target, priority, node -> OpcodeGroups.RETURN.contains(node.getOpcode()) ? new ImmutablePair<>(insn.get(), true) : null);
	}

	private final String target;

	public SpecificMethodNodeTransformer(String target, int priority, Function<MethodNode, MethodNode> transform){
		super(MethodNode.class, priority, transform);
		this.target = target;
	}

	public SpecificMethodNodeTransformer(int priority, String target, Consumer<MethodNode> transform){
		super(priority, MethodNode.class, transform);
		this.target = target;
	}

	@Override
	public boolean accepts(MethodNode target){
		return this.target.contains("(") ? this.target.equals(target.name + target.desc) : this.target.equals(target.name);
	}

}
{'fraction_non_alphanumeric': 0.10011451006052674, 'fraction_numerical': 0.0013086864060199575, 'mean_word_length': 7.065963060686016, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 37, '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': '7492351', 'n_tokens_mistral': 1754, 'n_tokens_neox': 1673, 'n_words': 368}