<commit_before>package com.abstratt.mdd.frontend.textuml.renderer;

import com.abstratt.mdd.target.base.IBasicBehaviorGenerator
import java.util.List
import org.eclipse.uml2.uml.Action
import org.eclipse.uml2.uml.Activity
import org.eclipse.uml2.uml.AddStructuralFeatureValueAction
import org.eclipse.uml2.uml.AddVariableValueAction
import org.eclipse.uml2.uml.CallOperationAction
import org.eclipse.uml2.uml.Clause
import org.eclipse.uml2.uml.ConditionalNode
import org.eclipse.uml2.uml.CreateLinkAction
import org.eclipse.uml2.uml.CreateObjectAction
import org.eclipse.uml2.uml.DataType
import org.eclipse.uml2.uml.DestroyObjectAction
import org.eclipse.uml2.uml.Feature
import org.eclipse.uml2.uml.InputPin
import org.eclipse.uml2.uml.Operation
import org.eclipse.uml2.uml.Parameter
import org.eclipse.uml2.uml.ReadSelfAction
import org.eclipse.uml2.uml.ReadStructuralFeatureAction
import org.eclipse.uml2.uml.ReadVariableAction
import org.eclipse.uml2.uml.StructuredActivityNode
import org.eclipse.uml2.uml.TestIdentityAction
import org.eclipse.uml2.uml.Type
import org.eclipse.uml2.uml.ValueSpecification
import org.eclipse.uml2.uml.ValueSpecificationAction
import static extension com.abstratt.mdd.core.util.MDDExtensionUtils.*
import static extension com.abstratt.mdd.core.util.ActivityUtils.*
import static extension com.abstratt.mdd.core.util.FeatureUtils.*
import static extension com.abstratt.mdd.target.base.GeneratorUtils.*
import org.eclipse.uml2.uml.SendSignalAction
import com.abstratt.mdd.core.util.MDDExtensionUtils

class ActivityGenerator implements IBasicBehaviorGenerator {
    
    override generateActivity(Activity activity) {
    	if (activity.isClosure) {
    		if (!activity.outputParameters.isEmpty) {
    			val singleStatement = activity.rootAction.findStatements.size == 1
    			if (singleStatement) {
					return activity.rootAction.findSingleStatement.inputs.get(0).sourceAction.generateAction
    			}
			}
		}
        val generated = activity.rootAction.generateAction
        return generated
    }
    
    override generateActivityAsExpression(Activity toGenerate, boolean asClosure, List<Parameter> parameters) {
        val singleStatement = toGenerate.rootAction.findSingleStatement
		val sourceAction = singleStatement.sourceAction
		return sourceAction.generateAction
    }
    
    override generateAction(Action action, boolean delegate) {
        generateProperAction(action)
    }
    
    def dispatch generateProperAction(Action action) {
        '''/* TBD: «action.eClass.name» */'''
    }
    
    def dispatch generateProperAction(StructuredActivityNode action) {
        val statements = action.findStatements
        val isRoot = action.rootAction
        val isCast = MDDExtensionUtils.isCast(action)
        if (isCast)
        	'''(«action.inputs.get(0).sourceAction.generateAction» as «action.outputs.get(0).type.name»)'''
        else if (isRoot) 
            statements.map[generateStatement].join('\n')
        else
        '''
        begin<commit_msg>rendering of activities as expressions<commit_after>package com.abstratt.mdd.frontend.textuml.renderer;

import com.abstratt.mdd.target.base.IBasicBehaviorGenerator
import java.util.List
import org.eclipse.uml2.uml.Action
import org.eclipse.uml2.uml.Activity
import org.eclipse.uml2.uml.AddStructuralFeatureValueAction
import org.eclipse.uml2.uml.AddVariableValueAction
import org.eclipse.uml2.uml.CallOperationAction
import org.eclipse.uml2.uml.Clause
import org.eclipse.uml2.uml.ConditionalNode
import org.eclipse.uml2.uml.CreateLinkAction
import org.eclipse.uml2.uml.CreateObjectAction
import org.eclipse.uml2.uml.DataType
import org.eclipse.uml2.uml.DestroyObjectAction
import org.eclipse.uml2.uml.Feature
import org.eclipse.uml2.uml.InputPin
import org.eclipse.uml2.uml.Operation
import org.eclipse.uml2.uml.Parameter
import org.eclipse.uml2.uml.ReadSelfAction
import org.eclipse.uml2.uml.ReadStructuralFeatureAction
import org.eclipse.uml2.uml.ReadVariableAction
import org.eclipse.uml2.uml.StructuredActivityNode
import org.eclipse.uml2.uml.TestIdentityAction
import org.eclipse.uml2.uml.Type
import org.eclipse.uml2.uml.ValueSpecification
import org.eclipse.uml2.uml.ValueSpecificationAction
import static extension com.abstratt.mdd.core.util.MDDExtensionUtils.*
import static extension com.abstratt.mdd.core.util.ActivityUtils.*
import static extension com.abstratt.mdd.core.util.FeatureUtils.*
import static extension com.abstratt.mdd.target.base.GeneratorUtils.*
import org.eclipse.uml2.uml.SendSignalAction
import com.abstratt.mdd.core.util.MDDExtensionUtils

class ActivityGenerator implements IBasicBehaviorGenerator {
    
    override generateActivity(Activity activity) {
    	if (activity.isClosure) {
    		if (!activity.outputParameters.isEmpty) {
    			val singleStatement = activity.rootAction.findStatements.size == 1
    			if (singleStatement) {
					return activity.rootAction.findSingleStatement.inputs.get(0).sourceAction.generateAction
    			}
			}
		}
        val generated = activity.rootAction.generateAction
        return generated
    }
    
    def CharSequence generateActivityAsExpressionIfPossible(Activity toGenerate) {
        val statements = toGenerate.rootAction.findStatements
        return if (statements.size == 1 && statements.get(0).inputs.size == 1)
        	generateActivityAsExpression(toGenerate)
    	else
    	    generateActivity(toGenerate)
    }
    
    override generateActivityAsExpression(Activity toGenerate, boolean asClosure, List<Parameter> parameters) {
        val singleStatement = toGenerate.rootAction.findSingleStatement
		val sourceAction = singleStatement.sourceAction
		return sourceAction.generateAction
    }
    
    override generateAction(Action action, boolean delegate) {
        generateProperAction(action)
    }
    
    def dispatch generateProperAction(Action action) {
        '''/* TBD: «action.eClass.name» */'''
    }
    
    def dispatch generateProperAction(StructuredActivityNode action) {
        val statements = action.findStatements
        val isRoot = action.rootAction
        val isCast = MDDExtensionUtils.isCast(action)
        if (isCast)
        	'''(«action.inputs.get(0).sourceAction.generateAction» as «action.outputs.get(0).type.name»)'''
        else if (isRoot) 
            statements.map[generateStatement].join('\n')
        else
        '''
        begin
{'fraction_non_alphanumeric': 0.08967136150234742, 'fraction_numerical': 0.009233176838810642, 'mean_word_length': 4.125100240577385, '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': '1380139', 'n_tokens_mistral': 1963, 'n_tokens_neox': 1932, 'n_words': 325}