<commit_before>package hu.eltesoft.modelexecution.m2t.java.templates

import hu.eltesoft.modelexecution.m2m.metamodel.region.RgInitialPseudostate
import hu.eltesoft.modelexecution.m2m.metamodel.region.RgRegion
import hu.eltesoft.modelexecution.m2m.metamodel.region.RgState
import hu.eltesoft.modelexecution.m2m.metamodel.region.RgTransition
import hu.eltesoft.modelexecution.m2t.java.StateQualifiers.Entry
import hu.eltesoft.modelexecution.m2t.java.StateQualifiers.Exit
import hu.eltesoft.modelexecution.m2t.java.Template
import hu.eltesoft.modelexecution.m2t.smap.xtend.SourceMappedTemplate
import hu.eltesoft.modelexecution.runtime.base.Event

import static hu.eltesoft.modelexecution.m2t.java.Languages.*
import hu.eltesoft.modelexecution.runtime.base.StateMachineRegion

@SourceMappedTemplate(stratumName=XUML_RT)
class RegionTemplate extends Template {

	val RgRegion region;
	val RgInitialPseudostate initState;
	val RgTransition initTransition;
	val RgState firstState;

	new(RgRegion region) {
		super(region)
		this.region = region
		initState = region.initialPseudostate
		initTransition = initState.initialTransition
		firstState = initTransition.target
	}

	override generate() '''
		«generatedHeader(region.name)»
		public class «region.name» extends «StateMachineRegion.canonicalName» {
		
			private enum States {
				«initState.name», «FOR state : region.states SEPARATOR ', '»«state.name»«ENDFOR»
			}
		
			private «region.containerClass.name» owner;
			private States currentState = States.«initState.name»;
		
			public «region.name»(«region.containerClass.name» owner) {
				this.owner = owner;
			}
		
			@Override
			public void doInitialTransition() {
				// Initial state exit «trace(initState.reference, Exit)»
				owner.getRuntime().logExitState("«initState.name»");
		
				// Initial transition effect «trace(initTransition.reference)»
				owner.getRuntime().logTransition("<init transition>", "«initState.name»", "«firstState.name»");
				«IF null != initTransition.effect»
					new «initTransition.effect.name»(owner).execute();
				«ENDIF»
		
				// First state entry «trace(firstState.reference, Entry)»
				owner.getRuntime().logEnterState("«firstState.name»");
				«IF null != firstState.entry»
					new «firstState.entry.name»(owner).execute();
				«ENDIF»
		
				currentState = States.«firstState.name»;
			}
		
			@Override
			public void step(«Event.canonicalName» event) {
				owner.getRuntime().logEventDispatched(owner, event);
				switch (currentState) {
				«FOR state : region.states»
					case «state.name»:
						«FOR transition : state.transitions SEPARATOR ' else '»
							if («transition.event.name».eventMatches(event))
							{
								// State exit «trace(state.reference, Exit)»
								owner.getRuntime().logExitState("«state.name»");
								«IF null != state.exit»
									new «state.exit.name»(owner).execute();
								«ENDIF»
							
								// Transition effect «trace(transition.reference)»
								owner.getRuntime().logTransition("«transition.event.name»", "«state.name»", "«transition.target.name»");<commit_msg>Fixing model compilation warning caused by incomplete state machine switch<commit_after>package hu.eltesoft.modelexecution.m2t.java.templates

import hu.eltesoft.modelexecution.m2m.metamodel.region.RgInitialPseudostate
import hu.eltesoft.modelexecution.m2m.metamodel.region.RgRegion
import hu.eltesoft.modelexecution.m2m.metamodel.region.RgState
import hu.eltesoft.modelexecution.m2m.metamodel.region.RgTransition
import hu.eltesoft.modelexecution.m2t.java.StateQualifiers.Entry
import hu.eltesoft.modelexecution.m2t.java.StateQualifiers.Exit
import hu.eltesoft.modelexecution.m2t.java.Template
import hu.eltesoft.modelexecution.m2t.smap.xtend.SourceMappedTemplate
import hu.eltesoft.modelexecution.runtime.base.Event

import static hu.eltesoft.modelexecution.m2t.java.Languages.*
import hu.eltesoft.modelexecution.runtime.base.StateMachineRegion

@SourceMappedTemplate(stratumName=XUML_RT)
class RegionTemplate extends Template {

	val RgRegion region;
	val RgInitialPseudostate initState;
	val RgTransition initTransition;
	val RgState firstState;

	new(RgRegion region) {
		super(region)
		this.region = region
		initState = region.initialPseudostate
		initTransition = initState.initialTransition
		firstState = initTransition.target
	}

	override generate() '''
		«generatedHeader(region.name)»
		public class «region.name» extends «StateMachineRegion.canonicalName» {
		
			private enum States {
				«initState.name», «FOR state : region.states SEPARATOR ', '»«state.name»«ENDFOR»
			}
		
			private «region.containerClass.name» owner;
			private States currentState = States.«initState.name»;
		
			public «region.name»(«region.containerClass.name» owner) {
				this.owner = owner;
			}
		
			@Override
			public void doInitialTransition() {
				// Initial state exit «trace(initState.reference, Exit)»
				owner.getRuntime().logExitState("«initState.name»");
		
				// Initial transition effect «trace(initTransition.reference)»
				owner.getRuntime().logTransition("<init transition>", "«initState.name»", "«firstState.name»");
				«IF null != initTransition.effect»
					new «initTransition.effect.name»(owner).execute();
				«ENDIF»
		
				// First state entry «trace(firstState.reference, Entry)»
				owner.getRuntime().logEnterState("«firstState.name»");
				«IF null != firstState.entry»
					new «firstState.entry.name»(owner).execute();
				«ENDIF»
		
				currentState = States.«firstState.name»;
			}
		
			@Override
			public void step(«Event.canonicalName» event) {
				owner.getRuntime().logEventDispatched(owner, event);
				switch (currentState) {
				case «initState.name»:
					break;
				«FOR state : region.states»
					case «state.name»:
						«FOR transition : state.transitions SEPARATOR ' else '»
							if («transition.event.name».eventMatches(event))
							{
								// State exit «trace(state.reference, Exit)»
								owner.getRuntime().logExitState("«state.name»");
								«IF null != state.exit»
									new «state.exit.name»(owner).execute();
								«ENDIF»
							
								// Transition effect «trace(transition.reference)»
								owner.getRuntime().logTransition("«transition.event.name»", "«state.name»", "«transition.target.name»");
{'fraction_non_alphanumeric': 0.12292199488491048, 'fraction_numerical': 0.00319693094629156, 'mean_word_length': 4.253568429890848, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1379613', 'n_tokens_mistral': 2401, 'n_tokens_neox': 1974, 'n_words': 512}