<commit_before>package com.jorgediaz.util.model;

import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.servlet.PluginContextListener;
import com.liferay.portal.kernel.servlet.ServletContextPool;
import com.liferay.portal.kernel.util.AggregateClassLoader;
import com.liferay.portal.kernel.util.PortalClassLoaderUtil;
import com.liferay.portal.model.ClassName;
import com.liferay.portal.model.ClassedModel;

import java.lang.reflect.Field;

import java.sql.Types;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletContext;
public class ModelUtil {

	public static ClassLoader getClassLoader() {

		ClassLoader portalClassLoader = PortalClassLoaderUtil.getClassLoader();

		AggregateClassLoader aggregateClassLoader = new AggregateClassLoader(
			portalClassLoader);

		if (_log.isDebugEnabled()) {
			_log.debug("Adding " + portalClassLoader);
		}

		aggregateClassLoader.addClassLoader(portalClassLoader);

		for (String servletContextName : ServletContextPool.keySet()) {
			try {
				ServletContext servletContext = ServletContextPool.get(
					servletContextName);

				ClassLoader classLoader =
					(ClassLoader)servletContext.getAttribute(
						PluginContextListener.PLUGIN_CLASS_LOADER);

				_log.debug(
					"Adding " + classLoader + " for " + servletContextName);

				aggregateClassLoader.addClassLoader(classLoader);
			}
			catch (Exception e) {
				if (_log.isWarnEnabled()) {
					_log.warn(
						"Error adding classLoader for " + servletContextName +
						": " + e.getMessage(), e);
				}
			}
		}

		return aggregateClassLoader;
	}

	public static List<String> getClassNameValues(
			Collection<ClassName> classNames) {

		List<String> classNameStr = new ArrayList<String>();

		for (ClassName className : classNames) {
			classNameStr.add(className.getValue());
		}

		return classNameStr;
	}

	public static Class<?> getJavaClass(
		Map<String, Class<?>> javaClassesCache, ClassLoader classloader,
		String className) throws ClassNotFoundException {

		Class<?> clazz = javaClassesCache.get(className);

		if (clazz != null) {
			return clazz;
		}

		clazz = classloader.loadClass(className);

		if (_log.isDebugEnabled()) {
			_log.debug("loaded class: " + clazz);
		}

		javaClassesCache.put(className, clazz);
		return clazz;
	}

	public static Map<Integer, String> getJdbcTypeNames() {

		if (jdbcTypeNames == null) {
			Map<Integer, String> aux = new HashMap<Integer, String>();

			for (Field field : Types.class.getFields()) {
				try {
					aux.put((Integer)field.get(null), field.getName());
				}
				catch (IllegalArgumentException e) {
				}
				catch (IllegalAccessException e) {
				}
			}

			jdbcTypeNames = aux;
		}

		return jdbcTypeNames;
	}

	public static String getLiferayLocalServiceUtilClassName(
		Class<? extends ClassedModel> clazz) {

		Package pkg = clazz.getPackage();

		String packageName = pkg.getName();
		int pos = packageName.lastIndexOf(".model");

		if (pos > 0) {
			packageName = packageName.substring(0, pos);
		}

		String className =
			packageName + ".service." + clazz.getSimpleName() +
				"LocalServiceUtil";

		if (_log.isDebugEnabled()) {
			_log.debug(
				"LocalServiceUtil of " + clazz.getName() + ": " + className);
		}

		return className;
	}

	public static String getLiferayModelImplClassName(
		Class<? extends ClassedModel> clazz) {

		Package pkg = clazz.getPackage();

		String className =
			pkg.getName() + ".impl." + clazz.getSimpleName() + "ModelImpl";

		if (_log.isDebugEnabled()) {
			_log.debug("ModelImpl of " + clazz.getName() + ": " + className);
		}

		return className;
	}

	public static Object getLiferayModelImplField(
		Class<?> classLiferayModelImpl, String liferayModelImplField) {

		Object data = null;
		try {
			Field field = classLiferayModelImpl.getDeclaredField(
				liferayModelImplField);
			data = field.get(null);
		}
		catch (Exception e) {
			throw new RuntimeException(
				"Error accessing to " +
				classLiferayModelImpl.getName() + "#" +
				liferayModelImplField, e);
		}

		return data;
	}

	private static Log _log = LogFactoryUtil.getLog(ModelUtil.class);

	private static Map<Integer, String> jdbcTypeNames = null;

}<commit_msg>New ModelUtil.makeFieldModifiable y ModelUtil.setFieldValue methods<commit_after>package com.jorgediaz.util.model;

import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.servlet.PluginContextListener;
import com.liferay.portal.kernel.servlet.ServletContextPool;
import com.liferay.portal.kernel.util.AggregateClassLoader;
import com.liferay.portal.kernel.util.PortalClassLoaderUtil;
import com.liferay.portal.model.ClassName;
import com.liferay.portal.model.ClassedModel;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

import java.sql.Types;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletContext;
public class ModelUtil {

	public static ClassLoader getClassLoader() {

		ClassLoader portalClassLoader = PortalClassLoaderUtil.getClassLoader();

		AggregateClassLoader aggregateClassLoader = new AggregateClassLoader(
			portalClassLoader);

		if (_log.isDebugEnabled()) {
			_log.debug("Adding " + portalClassLoader);
		}

		aggregateClassLoader.addClassLoader(portalClassLoader);

		for (String servletContextName : ServletContextPool.keySet()) {
			try {
				ServletContext servletContext = ServletContextPool.get(
					servletContextName);

				ClassLoader classLoader =
					(ClassLoader)servletContext.getAttribute(
						PluginContextListener.PLUGIN_CLASS_LOADER);

				_log.debug(
					"Adding " + classLoader + " for " + servletContextName);

				aggregateClassLoader.addClassLoader(classLoader);
			}
			catch (Exception e) {
				if (_log.isWarnEnabled()) {
					_log.warn(
						"Error adding classLoader for " + servletContextName +
						": " + e.getMessage(), e);
				}
			}
		}

		return aggregateClassLoader;
	}

	public static List<String> getClassNameValues(
			Collection<ClassName> classNames) {

		List<String> classNameStr = new ArrayList<String>();

		for (ClassName className : classNames) {
			classNameStr.add(className.getValue());
		}

		return classNameStr;
	}

	public static Class<?> getJavaClass(
		Map<String, Class<?>> javaClassesCache, ClassLoader classloader,
		String className) throws ClassNotFoundException {

		Class<?> clazz = javaClassesCache.get(className);

		if (clazz != null) {
			return clazz;
		}

		clazz = classloader.loadClass(className);

		if (_log.isDebugEnabled()) {
			_log.debug("loaded class: " + clazz);
		}

		javaClassesCache.put(className, clazz);
		return clazz;
	}

	public static Map<Integer, String> getJdbcTypeNames() {

		if (jdbcTypeNames == null) {
			Map<Integer, String> aux = new HashMap<Integer, String>();

			for (Field field : Types.class.getFields()) {
				try {
					aux.put((Integer)field.get(null), field.getName());
				}
				catch (IllegalArgumentException e) {
				}
				catch (IllegalAccessException e) {
				}
			}

			jdbcTypeNames = aux;
		}

		return jdbcTypeNames;
	}

	public static String getLiferayLocalServiceUtilClassName(
		Class<? extends ClassedModel> clazz) {

		Package pkg = clazz.getPackage();

		String packageName = pkg.getName();
		int pos = packageName.lastIndexOf(".model");

		if (pos > 0) {
			packageName = packageName.substring(0, pos);
		}

		String className =
			packageName + ".service." + clazz.getSimpleName() +
				"LocalServiceUtil";

		if (_log.isDebugEnabled()) {
			_log.debug(
				"LocalServiceUtil of " + clazz.getName() + ": " + className);
		}

		return className;
	}

	public static String getLiferayModelImplClassName(
		Class<? extends ClassedModel> clazz) {

		Package pkg = clazz.getPackage();

		String className =
			pkg.getName() + ".impl." + clazz.getSimpleName() + "ModelImpl";

		if (_log.isDebugEnabled()) {
			_log.debug("ModelImpl of " + clazz.getName() + ": " + className);
		}

		return className;
	}

	public static Object getLiferayModelImplField(
		Class<?> classLiferayModelImpl, String liferayModelImplField) {

		Object data = null;
		try {
			Field field = classLiferayModelImpl.getDeclaredField(
				liferayModelImplField);
			data = field.get(null);
		}
		catch (Exception e) {
			throw new RuntimeException(
				"Error accessing to " +
				classLiferayModelImpl.getName() + "#" +
				liferayModelImplField, e);
		}

		return data;
	}

	public static void makeFieldModifiable(Field nameField)
		throws NoSuchFieldException, SecurityException,
			IllegalArgumentException, IllegalAccessException {

		nameField.setAccessible(true);
		int modifiers = nameField.getModifiers();
		Field modifierField =
			nameField.getClass().getDeclaredField("modifiers");
		modifiers = modifiers & ~Modifier.FINAL;
		modifierField.setAccessible(true);
		modifierField.setInt(nameField, modifiers);
	}

	public static void setFieldValue(Object owner, Field field, Object value)
		throws IllegalArgumentException, IllegalAccessException,
			NoSuchFieldException, SecurityException {

		makeFieldModifiable(field);
		field.set(owner, value);
	}

	private static Log _log = LogFactoryUtil.getLog(ModelUtil.class);

	private static Map<Integer, String> jdbcTypeNames = null;

}
{'fraction_non_alphanumeric': 0.11208721422523285, 'fraction_numerical': 0.0004233700254022015, 'mean_word_length': 4.299495232753785, 'pattern_counts': {'":': 6, '<': 33, '<?xml version=': 0, '>': 35, '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': '359559', 'n_tokens_mistral': 3302, 'n_tokens_neox': 2891, 'n_words': 594}