<commit_before>package jce.generators

import java.io.File
import java.util.List
import jce.properties.EcorificationProperties
import org.eclipse.core.resources.IProject

/**
 * Generator class for the generation of Ecore factory implementation classes.
 * @author <NAME>
 */
class EFactoryImplementationGenerator extends ClassGenerator {

	/**
	 * Basic constructor, sets the properties.
	 */
	new(EcorificationProperties properties) {
		super(properties)
	}

	/**
	 * Creates a Ecore Factory in a package path with a specific name. 
	 */
	def public void create(String path, List<String> packageTypes, IProject project) {
		val currentPackage = path.replace(File.separatorChar, '.') // path to package declaration
		val interfacePackage = packageUtil.cutLastSegment(currentPackage)
		val packageName = packageUtil.getLastSegment(interfacePackage).toFirstUpper
		val content = createFactoryContent(currentPackage, packageName, interfacePackage, packageTypes)
		createClass(path, '''«packageName»FactoryImpl.java''', content, project)
		monitor.subTask(''' Created «packageName»FactoryImpl.java''') // detailed logging
	}

	/**
	 * Creates the content of an Ecore factory.
	 */
	def private String createFactoryContent(String currentPackage, String packageName, String interfacePackage,
		List<String> packageTypes) '''
		package «currentPackage»;
		
		import org.eclipse.emf.ecore.EClass;
		import org.eclipse.emf.ecore.EObject;
		import org.eclipse.emf.ecore.EPackage;
		import org.eclipse.emf.ecore.impl.EFactoryImpl;
		import org.eclipse.emf.ecore.plugin.EcorePlugin;
		
		import «interfacePackage».«packageName»Factory;
		import «interfacePackage».«packageName»Package;
		«FOR type : packageTypes»
			import «packageUtil.cutFirstSegment(interfacePackage)».«type»;
		«ENDFOR»
		
		/**
		 * An implementation of the model <b>Factory</b>.
		 * @generated
		 */
		public class «packageName»FactoryImpl extends EFactoryImpl implements «packageName»Factory {
		    /**
		     * Creates the default factory implementation.
		     * <!-- begin-user-doc -->
		     * <!-- end-user-doc -->
		     * @generated
		     */
		    public static «packageName»Factory init() {
		        try {
		            «packageName»Factory the«packageName»Factory = («packageName»Factory)EPackage.Registry.INSTANCE.getEFactory(«packageName»Package.eNS_URI);
		            if (the«packageName»Factory != null) {
		                return the«packageName»Factory;
		            }
		        }
		        catch (Exception exception) {
		            EcorePlugin.INSTANCE.log(exception);
		        }
		        return new «packageName»FactoryImpl();
		    }
		
		    /**
		     * Creates an instance of the factory.
		     * @generated
		     */
		    public «packageName»FactoryImpl2() {
		        super();
		    }
		
		    /**
		     * @generated
		     */
		    @Override
		    public EObject create(EClass eClass) {
		        switch (eClass.getClassifierID()) {
		            «FOR type : packageTypes»
		            	case «packageName»Package.«constantName(type)»: return create«type»();
		            «ENDFOR»
		            default:
		                throw new IllegalArgumentException("The class '" + eClass.getName() + "' is not a valid classifier");
		        }<commit_msg>FIX: Fixed constructor of the factory implementation template.<commit_after>package jce.generators

import java.io.File
import java.util.List
import jce.properties.EcorificationProperties
import org.eclipse.core.resources.IProject

/**
 * Generator class for the generation of Ecore factory implementation classes.
 * @author <NAME>
 */
class EFactoryImplementationGenerator extends ClassGenerator {

	/**
	 * Basic constructor, sets the properties.
	 */
	new(EcorificationProperties properties) {
		super(properties)
	}

	/**
	 * Creates a Ecore Factory in a package path with a specific name. 
	 */
	def public void create(String path, List<String> packageTypes, IProject project) {
		val currentPackage = path.replace(File.separatorChar, '.') // path to package declaration
		val interfacePackage = packageUtil.cutLastSegment(currentPackage)
		val packageName = packageUtil.getLastSegment(interfacePackage).toFirstUpper
		val content = createFactoryContent(currentPackage, packageName, interfacePackage, packageTypes)
		createClass(path, '''«packageName»FactoryImpl.java''', content, project)
		monitor.subTask(''' Created «packageName»FactoryImpl.java''') // detailed logging
	}

	/**
	 * Creates the content of an Ecore factory.
	 */
	def private String createFactoryContent(String currentPackage, String packageName, String interfacePackage,
		List<String> packageTypes) '''
		package «currentPackage»;
		
		import org.eclipse.emf.ecore.EClass;
		import org.eclipse.emf.ecore.EObject;
		import org.eclipse.emf.ecore.EPackage;
		import org.eclipse.emf.ecore.impl.EFactoryImpl;
		import org.eclipse.emf.ecore.plugin.EcorePlugin;
		
		import «interfacePackage».«packageName»Factory;
		import «interfacePackage».«packageName»Package;
		«FOR type : packageTypes»
			import «packageUtil.cutFirstSegment(interfacePackage)».«type»;
		«ENDFOR»
		
		/**
		 * An implementation of the model <b>Factory</b>.
		 * @generated
		 */
		public class «packageName»FactoryImpl extends EFactoryImpl implements «packageName»Factory {
		    /**
		     * Creates the default factory implementation.
		     * <!-- begin-user-doc -->
		     * <!-- end-user-doc -->
		     * @generated
		     */
		    public static «packageName»Factory init() {
		        try {
		            «packageName»Factory the«packageName»Factory = («packageName»Factory)EPackage.Registry.INSTANCE.getEFactory(«packageName»Package.eNS_URI);
		            if (the«packageName»Factory != null) {
		                return the«packageName»Factory;
		            }
		        }
		        catch (Exception exception) {
		            EcorePlugin.INSTANCE.log(exception);
		        }
		        return new «packageName»FactoryImpl();
		    }
		
		    /**
		     * Creates an instance of the factory.
		     * @generated
		     */
		    public «packageName»FactoryImpl() {
		        super();
		    }
		
		    /**
		     * @generated
		     */
		    @Override
		    public EObject create(EClass eClass) {
		        switch (eClass.getClassifierID()) {
		            «FOR type : packageTypes»
		            	case «packageName»Package.«constantName(type)»: return create«type»();
		            «ENDFOR»
		            default:
		                throw new IllegalArgumentException("The class '" + eClass.getName() + "' is not a valid classifier");
		        }
{'fraction_non_alphanumeric': 0.10727383863080685, 'fraction_numerical': 0.0001528117359413203, 'mean_word_length': 2.998167379352474, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '5451860', 'n_tokens_mistral': 1975, 'n_tokens_neox': 1724, 'n_words': 569}