<commit_before>package tools.vitruv.dsls.reactions.formatting

import org.eclipse.emf.ecore.EObject
import org.eclipse.xtext.formatting2.IFormattableDocument
import tools.vitruv.dsls.mirbase.formatting.MirBaseFormatter
import tools.vitruv.dsls.mirbase.mirBase.MetaclassReference
import tools.vitruv.dsls.mirbase.mirBase.MirBaseFile
import tools.vitruv.dsls.reactions.reactionsLanguage.Action
import tools.vitruv.dsls.reactions.reactionsLanguage.ActionStatement
import tools.vitruv.dsls.reactions.reactionsLanguage.CreateModelElement
import tools.vitruv.dsls.reactions.reactionsLanguage.Matcher
import tools.vitruv.dsls.reactions.reactionsLanguage.ModelAttributeChange
import tools.vitruv.dsls.reactions.reactionsLanguage.ModelElementChange
import tools.vitruv.dsls.reactions.reactionsLanguage.Reaction
import tools.vitruv.dsls.reactions.reactionsLanguage.ReactionsFile
import tools.vitruv.dsls.reactions.reactionsLanguage.ReactionsSegment
import tools.vitruv.dsls.reactions.reactionsLanguage.Routine
import tools.vitruv.dsls.reactions.reactionsLanguage.Trigger
import tools.vitruv.dsls.reactions.reactionsLanguage.MatcherStatement
import tools.vitruv.dsls.reactions.reactionsLanguage.RoutineInput
import tools.vitruv.dsls.reactions.reactionsLanguage.RetrieveModelElement

class ReactionsLanguageFormatter extends MirBaseFormatter {

	def dispatch void format(ReactionsFile reactionsFile, extension IFormattableDocument document) {
		(reactionsFile as MirBaseFile).formatStatic(document)
		reactionsFile.formatStatic(document)
	}

	def formatStatic(ReactionsFile reactionsFile, extension IFormattableDocument document) {
		reactionsFile.reactionsSegments.forEach [formatStatic(document)]
		reactionsFile.reactionsSegments.head.prepend [newLines = 2]
		reactionsFile.reactionsSegments.tail.forEach [prepend [newLines = 4]]
	}

	def formatStatic(ReactionsSegment segment, extension IFormattableDocument document) {
		segment.regionFor.keyword('in reaction to changes in').prepend [newLine]
		segment.regionFor.keyword('execute actions in').prepend [newLine]
		segment.reactions.forEach [formatStatic(document)]
		segment.routines.forEach [formatStatic(document)]
	}

	def formatStatic(Reaction reaction, extension IFormattableDocument document) {
		reaction.prepend [newLines = 2]
		if (reaction.documentation !== null) {
			reaction.regionFor.keyword('reaction').prepend [newLine]
		}
		reaction.formatInteriorBlock(document)
		reaction.trigger.formatStatic(document)
		reaction.callRoutine.prepend [newLine]
		reaction.callRoutine.code.regionFor.keyword('(').prepend [noSpace].append [noSpace]
		reaction.callRoutine.code.regionFor.keyword(')').prepend [noSpace]
	}
	
	def formatStatic(Trigger trigger, extension IFormattableDocument document) {
		trigger.regionFor.keyword('with').prepend [newLine;indent]
		trigger.format(document)
	}
	
	def dispatch void format(ModelElementChange modelElementChange, extension IFormattableDocument document) {<commit_msg>Adapt formatter to changed execute actions in keyword<commit_after>package tools.vitruv.dsls.reactions.formatting

import org.eclipse.emf.ecore.EObject
import org.eclipse.xtext.formatting2.IFormattableDocument
import tools.vitruv.dsls.mirbase.formatting.MirBaseFormatter
import tools.vitruv.dsls.mirbase.mirBase.MetaclassReference
import tools.vitruv.dsls.mirbase.mirBase.MirBaseFile
import tools.vitruv.dsls.reactions.reactionsLanguage.Action
import tools.vitruv.dsls.reactions.reactionsLanguage.ActionStatement
import tools.vitruv.dsls.reactions.reactionsLanguage.CreateModelElement
import tools.vitruv.dsls.reactions.reactionsLanguage.Matcher
import tools.vitruv.dsls.reactions.reactionsLanguage.ModelAttributeChange
import tools.vitruv.dsls.reactions.reactionsLanguage.ModelElementChange
import tools.vitruv.dsls.reactions.reactionsLanguage.Reaction
import tools.vitruv.dsls.reactions.reactionsLanguage.ReactionsFile
import tools.vitruv.dsls.reactions.reactionsLanguage.ReactionsSegment
import tools.vitruv.dsls.reactions.reactionsLanguage.Routine
import tools.vitruv.dsls.reactions.reactionsLanguage.Trigger
import tools.vitruv.dsls.reactions.reactionsLanguage.MatcherStatement
import tools.vitruv.dsls.reactions.reactionsLanguage.RoutineInput
import tools.vitruv.dsls.reactions.reactionsLanguage.RetrieveModelElement

class ReactionsLanguageFormatter extends MirBaseFormatter {

	def dispatch void format(ReactionsFile reactionsFile, extension IFormattableDocument document) {
		(reactionsFile as MirBaseFile).formatStatic(document)
		reactionsFile.formatStatic(document)
	}

	def formatStatic(ReactionsFile reactionsFile, extension IFormattableDocument document) {
		reactionsFile.reactionsSegments.forEach [formatStatic(document)]
		reactionsFile.reactionsSegments.head.prepend [newLines = 2]
		reactionsFile.reactionsSegments.tail.forEach [prepend [newLines = 4]]
	}

	def formatStatic(ReactionsSegment segment, extension IFormattableDocument document) {
		segment.regionFor.keyword('in reaction to changes in').prepend [newLine]
		segment.regionFor.keyword('execute').prepend [newLine]
		segment.reactions.forEach [formatStatic(document)]
		segment.routines.forEach [formatStatic(document)]
	}

	def formatStatic(Reaction reaction, extension IFormattableDocument document) {
		reaction.prepend [newLines = 2]
		if (reaction.documentation !== null) {
			reaction.regionFor.keyword('reaction').prepend [newLine]
		}
		reaction.formatInteriorBlock(document)
		reaction.trigger.formatStatic(document)
		reaction.callRoutine.prepend [newLine]
		reaction.callRoutine.code.regionFor.keyword('(').prepend [noSpace].append [noSpace]
		reaction.callRoutine.code.regionFor.keyword(')').prepend [noSpace]
	}
	
	def formatStatic(Trigger trigger, extension IFormattableDocument document) {
		trigger.regionFor.keyword('with').prepend [newLine;indent]
		trigger.format(document)
	}
	
	def dispatch void format(ModelElementChange modelElementChange, extension IFormattableDocument document) {
{'fraction_non_alphanumeric': 0.08749789668517584, 'fraction_numerical': 0.0013461214874642437, 'mean_word_length': 7.371830985915493, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4746271', 'n_tokens_mistral': 1898, 'n_tokens_neox': 1739, 'n_words': 267}