<commit_before>/*
 * Copyright (c) 2010 University of Tartu
 */
package org.jpmml.xjc;

import java.util.Collection;
import java.util.Map;

import com.sun.codemodel.JCodeModel;
import com.sun.codemodel.JDefinedClass;
import com.sun.codemodel.JExpr;
import com.sun.codemodel.JFieldVar;
import com.sun.codemodel.JMethod;
import com.sun.codemodel.JMod;
import com.sun.codemodel.JMods;
import com.sun.codemodel.JVar;
import com.sun.tools.xjc.Options;
import com.sun.tools.xjc.model.CAttributePropertyInfo;
import com.sun.tools.xjc.model.CElementPropertyInfo;
import com.sun.tools.xjc.model.CPropertyInfo;
import com.sun.tools.xjc.model.CValuePropertyInfo;
import com.sun.tools.xjc.outline.ClassOutline;
import com.sun.tools.xjc.outline.FieldOutline;
import com.sun.tools.xjc.outline.Outline;
import org.jvnet.jaxb2_commons.plugin.AbstractParameterizablePlugin;
import org.xml.sax.ErrorHandler;

public class ValueConstructorPlugin extends AbstractParameterizablePlugin {

	private boolean ignoreAttributes = false;

	private boolean ignoreElements = false;

	private boolean ignoreValues = false;


	@Override
	public String getOptionName(){
		return "XvalueConstructor";
	}

	@Override
	public String getUsage(){
		return null;
	}

	@Override
	@SuppressWarnings (
		value = {"unused"}
	)
	public boolean run(Outline outline, Options options, ErrorHandler errorHandler){
		JCodeModel codeModel = outline.getCodeModel();

		Collection<? extends ClassOutline> clazzes = outline.getClasses();
		for(ClassOutline clazz : clazzes){
			JDefinedClass beanClazz = clazz.implClass;

			FieldOutline[] fields = clazz.getDeclaredFields();

			final
			Map<String, JFieldVar> fieldVars = beanClazz.fields();

			FieldFilter filter = new FieldFilter(){

				@Override
				public boolean accept(FieldOutline field){
					CPropertyInfo propertyInfo = field.getPropertyInfo();

					JFieldVar fieldVar = fieldVars.get(propertyInfo.getName(false));

					JMods modifiers = fieldVar.mods();
					if((modifiers.getValue() & JMod.STATIC) == JMod.STATIC){
						return false;
					} // End if

					if(propertyInfo instanceof CAttributePropertyInfo){
						CAttributePropertyInfo attributePropertyInfo = (CAttributePropertyInfo)propertyInfo;

						return !getIgnoreAttributes() && attributePropertyInfo.isRequired();
					} else

					if(propertyInfo instanceof CElementPropertyInfo && !getIgnoreElements()){
						CElementPropertyInfo elementPropertyInfo = (CElementPropertyInfo)propertyInfo;

						return !getIgnoreElements() && elementPropertyInfo.isRequired();
					} else

					if(propertyInfo instanceof CValuePropertyInfo){
						CValuePropertyInfo valuePropertyInfo = (CValuePropertyInfo)propertyInfo;

						return !getIgnoreValues();
					} else

					{
						return false;
					}
				}
			};

			fields = CodeModelUtil.filterFields(fields, filter);
			if(fields.length == 0){
				continue;
			}

			JMethod defaultConstructor = beanClazz.constructor(JMod.PUBLIC);
			JMethod valueConstructor = beanClazz.constructor(JMod.PUBLIC);

			for(FieldOutline field : fields){
				CPropertyInfo propertyInfo = field.getPropertyInfo();

				JFieldVar fieldVar = fieldVars.get(propertyInfo.getName(false));

				JVar param = valueConstructor.param(fieldVar.type(), fieldVar.name());

				valueConstructor.body().assign(JExpr.refthis(fieldVar.name()), param);
			}
		}

		return true;
	}

	public boolean getIgnoreAttributes(){
		return this.ignoreAttributes;
	}

	public void setIgnoreAttributes(boolean ignoreAttributes){
		this.ignoreAttributes = ignoreAttributes;
	}

	public boolean getIgnoreElements(){
		return this.ignoreElements;
	}

	public void setIgnoreElements(boolean ignoreElements){
		this.ignoreElements = ignoreElements;
	}

	public boolean getIgnoreValues(){
		return this.ignoreValues;
	}

	public void setIgnoreValues(boolean ignoreValues){
		this.ignoreValues = ignoreValues;
	}
}<commit_msg>Generated value constructor parameters for XSD mixed content fields<commit_after>/*
 * Copyright (c) 2010 University of Tartu
 */
package org.jpmml.xjc;

import java.util.Collection;
import java.util.Map;

import com.sun.codemodel.JCodeModel;
import com.sun.codemodel.JDefinedClass;
import com.sun.codemodel.JExpr;
import com.sun.codemodel.JFieldVar;
import com.sun.codemodel.JMethod;
import com.sun.codemodel.JMod;
import com.sun.codemodel.JMods;
import com.sun.codemodel.JVar;
import com.sun.tools.xjc.Options;
import com.sun.tools.xjc.model.CAttributePropertyInfo;
import com.sun.tools.xjc.model.CElementPropertyInfo;
import com.sun.tools.xjc.model.CPropertyInfo;
import com.sun.tools.xjc.model.CReferencePropertyInfo;
import com.sun.tools.xjc.model.CValuePropertyInfo;
import com.sun.tools.xjc.outline.ClassOutline;
import com.sun.tools.xjc.outline.FieldOutline;
import com.sun.tools.xjc.outline.Outline;
import org.jvnet.jaxb2_commons.plugin.AbstractParameterizablePlugin;
import org.xml.sax.ErrorHandler;

public class ValueConstructorPlugin extends AbstractParameterizablePlugin {

	private boolean ignoreAttributes = false;

	private boolean ignoreElements = false;

	private boolean ignoreReferences = false;

	private boolean ignoreValues = false;


	@Override
	public String getOptionName(){
		return "XvalueConstructor";
	}

	@Override
	public String getUsage(){
		return null;
	}

	@Override
	@SuppressWarnings (
		value = {"unused"}
	)
	public boolean run(Outline outline, Options options, ErrorHandler errorHandler){
		JCodeModel codeModel = outline.getCodeModel();

		Collection<? extends ClassOutline> clazzes = outline.getClasses();
		for(ClassOutline clazz : clazzes){
			JDefinedClass beanClazz = clazz.implClass;

			FieldOutline[] fields = clazz.getDeclaredFields();

			final
			Map<String, JFieldVar> fieldVars = beanClazz.fields();

			FieldFilter filter = new FieldFilter(){

				@Override
				public boolean accept(FieldOutline field){
					CPropertyInfo propertyInfo = field.getPropertyInfo();

					JFieldVar fieldVar = fieldVars.get(propertyInfo.getName(false));

					JMods modifiers = fieldVar.mods();
					if((modifiers.getValue() & JMod.STATIC) == JMod.STATIC){
						return false;
					} // End if

					if(propertyInfo instanceof CAttributePropertyInfo){
						CAttributePropertyInfo attributePropertyInfo = (CAttributePropertyInfo)propertyInfo;

						return !getIgnoreAttributes() && attributePropertyInfo.isRequired();
					} else

					if(propertyInfo instanceof CElementPropertyInfo && !getIgnoreElements()){
						CElementPropertyInfo elementPropertyInfo = (CElementPropertyInfo)propertyInfo;

						return !getIgnoreElements() && elementPropertyInfo.isRequired();
					} else

					if(propertyInfo instanceof CReferencePropertyInfo){
						CReferencePropertyInfo referencePropertyInfo = (CReferencePropertyInfo)propertyInfo;

						return !getIgnoreReferences() && referencePropertyInfo.isRequired();
					} else

					if(propertyInfo instanceof CValuePropertyInfo){
						CValuePropertyInfo valuePropertyInfo = (CValuePropertyInfo)propertyInfo;

						return !getIgnoreValues();
					} else

					{
						throw new IllegalArgumentException();
					}
				}
			};

			fields = CodeModelUtil.filterFields(fields, filter);
			if(fields.length == 0){
				continue;
			}

			JMethod defaultConstructor = beanClazz.constructor(JMod.PUBLIC);
			JMethod valueConstructor = beanClazz.constructor(JMod.PUBLIC);

			for(FieldOutline field : fields){
				CPropertyInfo propertyInfo = field.getPropertyInfo();

				JFieldVar fieldVar = fieldVars.get(propertyInfo.getName(false));

				JVar param = valueConstructor.param(fieldVar.type(), fieldVar.name());

				valueConstructor.body().assign(JExpr.refthis(fieldVar.name()), param);
			}
		}

		return true;
	}

	public boolean getIgnoreAttributes(){
		return this.ignoreAttributes;
	}

	public void setIgnoreAttributes(boolean ignoreAttributes){
		this.ignoreAttributes = ignoreAttributes;
	}

	public boolean getIgnoreElements(){
		return this.ignoreElements;
	}

	public void setIgnoreElements(boolean ignoreElements){
		this.ignoreElements = ignoreElements;
	}

	public boolean getIgnoreReferences(){
		return this.ignoreReferences;
	}

	public void setIgnoreReferences(boolean ignoreReferences){
		this.ignoreReferences = ignoreReferences;
	}

	public boolean getIgnoreValues(){
		return this.ignoreValues;
	}

	public void setIgnoreValues(boolean ignoreValues){
		this.ignoreValues = ignoreValues;
	}
}
{'fraction_non_alphanumeric': 0.09788707174406112, 'fraction_numerical': 0.001432493732839919, 'mean_word_length': 4.762035763411279, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '2369418', 'n_tokens_mistral': 2856, 'n_tokens_neox': 2422, 'n_words': 498}