<commit_before>/**
  Copyright (c) 2012 committers of YAKINDU and others.
  All rights reserved. This program and the accompanying materials
  are made available under the terms of the Eclipse Public License v1.0
  which accompanies this distribution, and is available at
  http://www.eclipse.org/legal/epl-v10.html
  Contributors:
  	<NAME> - Initial contribution and API
*/
package org.yakindu.sct.generator.java

import com.google.inject.Inject
import org.eclipse.xtext.generator.IFileSystemAccess
import org.yakindu.base.types.Direction
import org.yakindu.base.types.Parameter
import org.yakindu.base.types.typesystem.GenericTypeSystem
import org.yakindu.base.types.typesystem.ITypeSystem
import org.yakindu.sct.generator.core.types.ICodegenTypeSystemAccess
import org.yakindu.sct.model.sexec.ExecutionFlow
import org.yakindu.sct.model.sgen.GeneratorEntry
import org.yakindu.sct.model.sgraph.Scope
import org.yakindu.sct.model.stext.stext.InterfaceScope
import org.yakindu.sct.model.stext.stext.InternalScope
import org.yakindu.sct.model.stext.stext.OperationDefinition
import org.yakindu.sct.model.stext.stext.VariableDefinition

class StatemachineInterface {

	@Inject extension Naming
	@Inject extension GenmodelEntries
	@Inject extension Navigation
	@Inject extension ITypeSystem
	@Inject extension ICodegenTypeSystemAccess
	@Inject extension ExpressionCode
	@Inject Beautifier beautifier

	def generateStatemachineInterface(ExecutionFlow flow, GeneratorEntry entry, IFileSystemAccess fsa) {
		var filename = flow.getImplementationPackagePath(entry) + '/' + flow.statemachineInterfaceName.java
		var content = beautifier.format(filename, content(flow, entry))
		fsa.generateFile(filename, content)
	}

	def private content(ExecutionFlow flow, GeneratorEntry entry) {
		'''
			«entry.licenseText»
			package «flow.getImplementationPackageName(entry)»;
			«IF entry.createInterfaceObserver && flow.hasOutgoingEvents»
				import java.util.List;
			«ENDIF»
			import «entry.basePackageName».«iStatemachine»;
			«IF flow.timed»
				import «entry.basePackageName».«iTimerCallback»;
			«ENDIF»
			
			public interface «flow.statemachineInterfaceName» extends «flow.statemachineInterfaceExtensions» {
			
				«FOR scope : flow.scopes»
					«scope.createScope(entry)»
				«ENDFOR»
			}
		'''
	}
	
	
	
	def private constantFieldDeclaration(VariableDefinition variable){
		'''public static final «variable.type.targetLanguageName» «variable.symbol» = «variable.initialValue.code»;'''
	}

	def private createScope(Scope scope, GeneratorEntry entry) {
		switch scope {
			InterfaceScope: scope.createScope(entry)
			InternalScope: scope.createScope
		}
	}

	def private createScope(InterfaceScope scope, GeneratorEntry entry) {
		'''
			«scope.createInterface(entry)»
			«scope.createListenerInterface(entry)»
			«scope.createOperationCallbackInterface»
			
			public «scope.interfaceName» get«scope.interfaceName»();
			<commit_msg>Added constant support for java code generator<commit_after>/**
  Copyright (c) 2012 committers of YAKINDU and others.
  All rights reserved. This program and the accompanying materials
  are made available under the terms of the Eclipse Public License v1.0
  which accompanies this distribution, and is available at
  http://www.eclipse.org/legal/epl-v10.html
  Contributors:
  	<NAME> - Initial contribution and API
*/
package org.yakindu.sct.generator.java

import com.google.inject.Inject
import org.eclipse.xtext.generator.IFileSystemAccess
import org.yakindu.base.types.Direction
import org.yakindu.base.types.Parameter
import org.yakindu.base.types.typesystem.GenericTypeSystem
import org.yakindu.base.types.typesystem.ITypeSystem
import org.yakindu.sct.generator.core.types.ICodegenTypeSystemAccess
import org.yakindu.sct.model.sexec.ExecutionFlow
import org.yakindu.sct.model.sgen.GeneratorEntry
import org.yakindu.sct.model.sgraph.Scope
import org.yakindu.sct.model.stext.stext.InterfaceScope
import org.yakindu.sct.model.stext.stext.InternalScope
import org.yakindu.sct.model.stext.stext.OperationDefinition
import org.yakindu.sct.model.stext.stext.VariableDefinition

class StatemachineInterface {

	@Inject extension Naming
	@Inject extension GenmodelEntries
	@Inject extension Navigation
	@Inject extension ITypeSystem
	@Inject extension ICodegenTypeSystemAccess
	@Inject extension ExpressionCode
	@Inject Beautifier beautifier

	def generateStatemachineInterface(ExecutionFlow flow, GeneratorEntry entry, IFileSystemAccess fsa) {
		var filename = flow.getImplementationPackagePath(entry) + '/' + flow.statemachineInterfaceName.java
		var content = beautifier.format(filename, content(flow, entry))
		fsa.generateFile(filename, content)
	}

	def private content(ExecutionFlow flow, GeneratorEntry entry) {
		'''
			«entry.licenseText»
			package «flow.getImplementationPackageName(entry)»;
			«IF entry.createInterfaceObserver && flow.hasOutgoingEvents»
				import java.util.List;
			«ENDIF»
			import «entry.basePackageName».«iStatemachine»;
			«IF flow.timed»
				import «entry.basePackageName».«iTimerCallback»;
			«ENDIF»
			
			public interface «flow.statemachineInterfaceName» extends «flow.statemachineInterfaceExtensions» {
				«IF flow.internalScope != null»
				
				«var constants = flow.internalScope.declarations.filter(VariableDefinition).filter[const]»
				«FOR constant : constants»
					«constant.constantFieldDeclaration()»
				«ENDFOR»
				«ENDIF»
				«FOR scope : flow.scopes»
					«scope.createScope(entry)»
				«ENDFOR»
			}
		'''
	}
	
	
	
	def private constantFieldDeclaration(VariableDefinition variable){
		'''public static final «variable.type.targetLanguageName» «variable.symbol» = «variable.initialValue.code»;'''
	}

	def private createScope(Scope scope, GeneratorEntry entry) {
		switch scope {
			InterfaceScope: scope.createScope(entry)
			InternalScope: scope.createScope
		}
	}

	def private createScope(InterfaceScope scope, GeneratorEntry entry) {
		'''
			«scope.createInterface(entry)»
			«scope.createListenerInterface(entry)»
			«scope.createOperationCallbackInterface»
			
			public «scope.interfaceName» get«scope.interfaceName»();
			
{'fraction_non_alphanumeric': 0.0934640522875817, 'fraction_numerical': 0.00261437908496732, 'mean_word_length': 5.1332665330661325, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '23260', 'n_tokens_mistral': 2028, 'n_tokens_neox': 1851, 'n_words': 492}