<commit_before>package ist.meic.pa;

import java.lang.reflect.Modifier;

import javassist.CannotCompileException;
import javassist.ClassPool;
import javassist.CtClass;
import javassist.CtMethod;
import javassist.NotFoundException;
import javassist.Translator;
import javassist.expr.ExprEditor;
import javassist.expr.MethodCall;

/**
 *Custom Translator class used to instrument the classes about to be profiled.
 */

public class CustomTranslator implements Translator {

	@Override
	public void start(ClassPool pool) throws NotFoundException, CannotCompileException {
	}
	
	/**
	 * The onLoad method checks if the function being loaded belongs to this project's
	 * package, or to Javassist's, and, if not, calls the InstrumentClass method on the class.
	 */

	@Override
	public void onLoad(ClassPool pool, String ctClass) throws NotFoundException, CannotCompileException {
		CtClass cc = pool.get(ctClass);
		cc.setModifiers(Modifier.PUBLIC);

		boolean javassist = ctClass.contains("javassist");
		boolean profiler = ctClass.contains("ist.meic.pa");

		if (!javassist && !profiler) {
			try {
				instrumentClass(cc);
			} catch (CannotCompileException e) {
				throw new CannotCompileException(e);
			}
		}
	}
	
	/**
	 * Method that checks the input class for boxing/unboxing operations and instruments
	 * it if such operations are found.
	 * If a call to the valueOf() or any of the *Value() methods is found, that call
	 * is replaced by a block of code containing that same call followed by a call
	 * to the updateAutoboxingCounter method, if the types are compatible.
	 * The compatibility is checked with the primitiveType method.
	 * 
	 * @param ctClass Class to be instrumented
	 * @throws CannotCompileException
	 */

	private void instrumentClass(final CtClass ctClass) throws CannotCompileException {
		for (final CtMethod method : ctClass.getDeclaredMethods()) {
			final String methodName = method.getLongName();
			method.instrument(new ExprEditor() {
				@Override
				public void edit(MethodCall methodCall) throws CannotCompileException {
					try {
						CtClass[] parameterTypes = methodCall.getMethod().getParameterTypes();
						
						String parameterClassName = "";
						String codeTemplate =
							"{" +
									"$_ = $proceed($$);" +
									"if (ist.meic.pa.Storage.primitiveType($_, $0)) {" +
										"ist.meic.pa.Storage.updateAutoboxingCounter(\"%s\");" +
									"}" +
							"}";
						String autoboxingMethodName = methodCall.getMethod().getLongName();
						
						String incompleteKey = methodName + Storage.SEPARATOR;
						String boxed = " boxed ";
						String unboxed = " unboxed ";
						<commit_msg>Added a last bit of missing documentation<commit_after>package ist.meic.pa;

import java.lang.reflect.Modifier;

import javassist.CannotCompileException;
import javassist.ClassPool;
import javassist.CtClass;
import javassist.CtMethod;
import javassist.NotFoundException;
import javassist.Translator;
import javassist.expr.ExprEditor;
import javassist.expr.MethodCall;

/**
 *Custom Translator class used to instrument the classes about to be profiled.
 */

public class CustomTranslator implements Translator {

	@Override
	public void start(ClassPool pool) throws NotFoundException, CannotCompileException {
	}
	
	/**
	 * The onLoad method checks if the function being loaded belongs to this project's
	 * package, or to Javassist's, and, if not, calls the InstrumentClass method on the class.
	 */

	@Override
	public void onLoad(ClassPool pool, String ctClass) throws NotFoundException, CannotCompileException {
		CtClass cc = pool.get(ctClass);
		cc.setModifiers(Modifier.PUBLIC);

		boolean javassist = ctClass.contains("javassist");
		boolean profiler = ctClass.contains("ist.meic.pa");

		if (!javassist && !profiler) {
			try {
				instrumentClass(cc);
			} catch (CannotCompileException e) {
				throw new CannotCompileException(e);
			}
		}
	}
	
	/**
	 * Method that checks the input class for boxing/unboxing operations and instruments
	 * it if such operations are found.
	 * If a call to the valueOf() or any of the *Value() methods is found, that call
	 * is replaced by a block of code containing that same call followed by a call
	 * to the updateAutoboxingCounter method, if the types are compatible.
	 * The compatibility is checked with the primitiveType method.
	 * This method also looks for the main() method of the instrumented class and
	 * adds the printOutput() method to it.
	 * 
	 * @param ctClass Class to be instrumented
	 * @throws CannotCompileException
	 */

	private void instrumentClass(final CtClass ctClass) throws CannotCompileException {
		for (final CtMethod method : ctClass.getDeclaredMethods()) {
			final String methodName = method.getLongName();
			method.instrument(new ExprEditor() {
				@Override
				public void edit(MethodCall methodCall) throws CannotCompileException {
					try {
						CtClass[] parameterTypes = methodCall.getMethod().getParameterTypes();
						
						String parameterClassName = "";
						String codeTemplate =
							"{" +
									"$_ = $proceed($$);" +
									"if (ist.meic.pa.Storage.primitiveType($_, $0)) {" +
										"ist.meic.pa.Storage.updateAutoboxingCounter(\"%s\");" +
									"}" +
							"}";
						String autoboxingMethodName = methodCall.getMethod().getLongName();
						
						String incompleteKey = methodName + Storage.SEPARATOR;
						String boxed = " boxed ";
						String unboxed = " unboxed ";
						
{'fraction_non_alphanumeric': 0.0926605504587156, 'fraction_numerical': 0.0003669724770642202, 'mean_word_length': 3.7606986899563317, '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': '3427026', 'n_tokens_mistral': 1893, 'n_tokens_neox': 1499, 'n_words': 479}