<commit_before>package com.profiler.modifier;

import com.profiler.logging.Logger;

import javassist.*;

import java.net.URL;
import java.net.URLClassLoader;

public abstract class AbstractModifier implements Modifier {

	private static final Logger logger = Logger.getLogger(AbstractModifier.class);

	protected final ClassPool classPool;

	public AbstractModifier(ClassPool classPool) {
		this.classPool = classPool;
	}
	
	public byte[] addBeforeAfterLogics(String javassistClassName) {
		try {
			CtClass cc = classPool.get(javassistClassName);
			CtMethod[] methods = cc.getDeclaredMethods();

			for (CtMethod method : methods) {
				if (!method.isEmpty()) {
					String methodName = method.getName();
					CtClass[] params = method.getParameterTypes();
					StringBuilder sb = new StringBuilder();

					if (params.length != 0) {
						int paramsLength = params.length;

						for (int loop = paramsLength - 1; loop > 0; loop--) {
							sb.append(params[loop].getName()).append(",");
						}
						// sb.substring(0, sb.length()-2);
					}
					method.insertBefore("{System.out.println(\"*****" + javassistClassName + "." + methodName + "(" + sb + ") is started.\");}");
					method.insertAfter("{System.out.println(\"*****" + javassistClassName + "." + methodName + "(" + sb + ") is finished.\");}");
				} else {
					logger.warn(method.getLongName() + " is empty !!!!!");
				}
			}

			CtConstructor[] constructors = cc.getConstructors();

			for (CtConstructor constructor : constructors) {

				if (!constructor.isEmpty()) {
					CtClass[] params = constructor.getParameterTypes();
					StringBuilder sb = new StringBuilder();

					if (params.length != 0) {
						int paramsLength = params.length;
						for (int loop = paramsLength - 1; loop > 0; loop--) {
							sb.append(params[loop].getName()).append(",");
						}
						// sb.substring(0, sb.length()-2);
					}

					constructor.insertBefore("{System.out.println(\"*****" + javassistClassName + " Constructor:Param=(" + sb + ") is started.\");}");
					constructor.insertAfter("{System.out.println(\"*****" + javassistClassName + " Constructor:Param=(" + sb + ") is finished.\");}");
				} else {
					logger.warn(constructor.getLongName() + " is empty !!!!!");
				}
			}
			return cc.toBytecode();
		} catch (Exception e) {
			logger.error(e.getMessage());
			e.printStackTrace();
			return null;
		}
	}

	public void printClassConvertComplete(String javassistClassName) {
		logger.info("%s class is converted.", javassistClassName);
	}

	protected void checkLibrary(ClassLoader classLoader, String javassistClassName) {
		// TODO Util로 뽑을까?
		boolean findClass = findClass(javassistClassName);
		if (findClass) {
			return;
		}
		loadClassLoaderLibraries(classLoader);
	}

	public boolean findClass(String javassistClassName) {
		// TODO 원래는 get인데. find는 ctclas를 생성하지 않아 변경. 어차피 아래서 생성하기는 함. 유효성 여부 확인
		// 필요<commit_msg>[강운덕] [LUCYSUS-1744] HIPPO 의 로거를 JDK 로거로 변경함. maven에 junit포함.<commit_after>package com.profiler.modifier;


import javassist.*;

import java.net.URL;
import java.net.URLClassLoader;
import java.util.logging.Level;
import java.util.logging.Logger;

public abstract class AbstractModifier implements Modifier {

	private final Logger logger = Logger.getLogger(AbstractModifier.class.getName());

	protected final ClassPool classPool;

	public AbstractModifier(ClassPool classPool) {
		this.classPool = classPool;
	}
	
	public byte[] addBeforeAfterLogics(String javassistClassName) {
		try {
			CtClass cc = classPool.get(javassistClassName);
			CtMethod[] methods = cc.getDeclaredMethods();

			for (CtMethod method : methods) {
				if (!method.isEmpty()) {
					String methodName = method.getName();
					CtClass[] params = method.getParameterTypes();
					StringBuilder sb = new StringBuilder();

					if (params.length != 0) {
						int paramsLength = params.length;

						for (int loop = paramsLength - 1; loop > 0; loop--) {
							sb.append(params[loop].getName()).append(",");
						}
						// sb.substring(0, sb.length()-2);
					}
					method.insertBefore("{System.out.println(\"*****" + javassistClassName + "." + methodName + "(" + sb + ") is started.\");}");
					method.insertAfter("{System.out.println(\"*****" + javassistClassName + "." + methodName + "(" + sb + ") is finished.\");}");
				} else {
                    if (logger.isLoggable(Level.WARNING)) {
                        logger.warning(method.getLongName() + " is empty !!!!!");
                    }

                }
			}

			CtConstructor[] constructors = cc.getConstructors();

			for (CtConstructor constructor : constructors) {

				if (!constructor.isEmpty()) {
					CtClass[] params = constructor.getParameterTypes();
					StringBuilder sb = new StringBuilder();

					if (params.length != 0) {
						int paramsLength = params.length;
						for (int loop = paramsLength - 1; loop > 0; loop--) {
							sb.append(params[loop].getName()).append(",");
						}
						// sb.substring(0, sb.length()-2);
					}

					constructor.insertBefore("{System.out.println(\"*****" + javassistClassName + " Constructor:Param=(" + sb + ") is started.\");}");
					constructor.insertAfter("{System.out.println(\"*****" + javassistClassName + " Constructor:Param=(" + sb + ") is finished.\");}");
				} else {
                    if (logger.isLoggable(Level.WARNING)) {
                        logger.warning(constructor.getLongName() + " is empty !!!!!");
                    }

                }
			}
			return cc.toBytecode();
		} catch (Exception e) {
			if (logger.isLoggable(Level.WARNING)) {
			    logger.log(Level.WARNING, e.getMessage(), e);
            }
			return null;
		}
	}

	public void printClassConvertComplete(String javassistClassName) {
        if (logger.isLoggable(Level.INFO)) {
            logger.info(javassistClassName + " class is converted.");
        }

    }

	protected void checkLibrary(ClassLoader classLoader, String javassistClassName) {
		// TODO Util로 뽑을까?
		boolean findClass = findClass(javassistClassName);
		if (findClass) {
			return;
		}
		loadClassLoaderLibraries(classLoader);
	}

	public boolean findClass(String javassistClassName) {
		// TODO 원래는 get인데. find는 ctclas를 생성하지 않아 변경. 어차피 아래서 생성하기는 함. 유효성 여부 확인
		// 필요
{'fraction_non_alphanumeric': 0.15196787148594376, 'fraction_numerical': 0.0038554216867469878, 'mean_word_length': 3.1286472148541113, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '6886303', 'n_tokens_mistral': 2315, 'n_tokens_neox': 1993, 'n_words': 405}