Jelajahi Sumber

#867: Using IGenArtifactConfigurations to generate relative include paths.

Thomas Kutz 9 tahun lalu
induk
melakukan
f6ed26272e

+ 17 - 1
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/CppCodeGenerator.java

@@ -36,13 +36,26 @@ public class CppCodeGenerator extends GenericJavaBasedGenerator {
 	@Inject
 	private CppGenerator delegate;
 	
+	@Inject
+	private IGenArtifactConfigurations artifactConfigs;
+	
+	@Override
+	protected void prepareGenerator(GeneratorEntry entry) {
+		super.prepareGenerator(entry);
+		initGenArtifactConfigurations();
+	}
+	
+	protected void initGenArtifactConfigurations() {
+		artifactConfigs.setFileSystemAccess(sctFsa);
+	}
+	
 	@Override
 	public void runGenerator(Statechart statechart, GeneratorEntry entry) {
 		ExecutionFlow flow = createExecutionFlow(statechart, entry);
 		if (debugFeatureHelper.isDumpSexec(entry)) {
 			dumpSexec(entry, flow);
 		}
-		delegate.generate(flow, entry, sctFsa.getIFileSystemAccess());
+		delegate.generate(flow, entry, sctFsa.getIFileSystemAccess(), artifactConfigs);
 	}
 
 	@Override
@@ -53,6 +66,9 @@ public class CppCodeGenerator extends GenericJavaBasedGenerator {
 				binder.bind(ICodegenTypeSystemAccess.class).to(CTypeSystemAccess.class);
 				binder.bind(INamingService.class).to(CppNamingService.class);
 				binder.bind(GeneratorEntry.class).toInstance(entry);
+				
+				binder.bind(IGenArtifactConfigurations.class).to(GenArtifactConfigurations.class);
+				// default binding to ensure consistency of already used API
 				binder.bind(IGenArtifactConfigurations.class)
 						.annotatedWith(Names.named(IGenArtifactConfigurations.DEFAULT))
 						.toInstance(GenArtifactConfigurations.DEFAULT);

+ 51 - 15
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/CppGenerator.xtend

@@ -11,11 +11,14 @@
 package org.yakindu.sct.generator.cpp
 
 import com.google.inject.Inject
+import com.google.inject.name.Named
 import org.eclipse.xtext.generator.IFileSystemAccess
+import org.yakindu.sct.generator.c.GenArtifactConfigurations.GenArtifactConfiguration
+import org.yakindu.sct.generator.c.IGenArtifactConfigurations
 import org.yakindu.sct.generator.core.impl.IExecutionFlowGenerator
+import org.yakindu.sct.generator.core.library.IOutletFeatureHelper
 import org.yakindu.sct.model.sexec.ExecutionFlow
 import org.yakindu.sct.model.sgen.GeneratorEntry
-import org.yakindu.sct.model.sgraph.Statechart
 
 /**
  * This is the CPP code generators main class. 
@@ -24,27 +27,60 @@ import org.yakindu.sct.model.sgraph.Statechart
  */
 class CppGenerator implements IExecutionFlowGenerator {
 	 
-	@Inject extension Types
-	@Inject extension TimedStatemachineInterface
-	@Inject extension TimerInterface
-	@Inject extension StatemachineInterface
-	@Inject extension StatemachineHeader
-	@Inject extension StatemachineImplementation
-
+	@Inject extension Types typesContent
+	@Inject extension TimedStatemachineInterface timedStatemachineInterfaceContent
+	@Inject extension TimerInterface timerInterfaceContent
+	@Inject extension StatemachineInterface statemachineInterfaceContent
+	@Inject extension StatemachineHeader statemachineHeaderContent
+	@Inject extension StatemachineImplementation statemachineSourceContent
 	@Inject extension Navigation
+	@Inject extension Naming
+	
+	@Inject IOutletFeatureHelper outletFeatureHelper
 	
+	@Inject @Named(IGenArtifactConfigurations.DEFAULT)
+	IGenArtifactConfigurations defaultConfigs
+	
+	/**
+	 * @Deprecated use {@link #generate(ExecutionFlow, GeneratorEntry, IFileSystemAccess, ArtifactLocationProvider)} instead
+	 */
+	@Deprecated
 	override generate(ExecutionFlow flow, GeneratorEntry entry, IFileSystemAccess fsa) {
-
-		flow.generateTypesHpp(flow.sourceElement as Statechart, fsa, entry)
+		generate(flow, entry, fsa, defaultConfigs)
+	}
+	
+	def generate(ExecutionFlow flow, GeneratorEntry entry, IFileSystemAccess fsa, IGenArtifactConfigurations locations) {
+		initGenerationArtifacts(flow, entry, locations)
+		generateArtifacts(flow, entry, fsa, locations);
+	}
+	
+	def generateArtifacts(ExecutionFlow flow, GeneratorEntry entry, IFileSystemAccess fsa, IGenArtifactConfigurations locations) {
+		for (GenArtifactConfiguration a : locations.configurations) {
+			fsa.generateFile(a.getName, a.getOutputName, a.getContentTemplate.content(flow, entry, locations))
+		}
+	}
+	
+	def initGenerationArtifacts(ExecutionFlow flow, GeneratorEntry entry, IGenArtifactConfigurations locations) {
+		if (outletFeatureHelper.getLibraryTargetFolderValue(entry) != null) {
+			locations.configure(flow.typesModule.h, IExecutionFlowGenerator.LIBRARY_TARGET_FOLDER_OUTPUT, typesContent)
+		} else {
+			locations.configure(flow.typesModule.h, IExecutionFlowGenerator.TARGET_FOLDER_OUTPUT, typesContent)
+		}
 		
-		flow.generateIStatemachine(entry, fsa);
+		locations.configure(statemachineInterface.h, IExecutionFlowGenerator.TARGET_FOLDER_OUTPUT, statemachineInterfaceContent)
 		
 		if (flow.timed) {
-			flow.generateITimedStatemachine(entry, fsa);
-			flow.generateITimerService(entry, fsa);
+			if (outletFeatureHelper.getLibraryTargetFolderValue(entry) != null) {
+				locations.configure(timedStatemachineInterface.h, IExecutionFlowGenerator.LIBRARY_TARGET_FOLDER_OUTPUT, timedStatemachineInterfaceContent)
+				locations.configure(timerInterface.h, IExecutionFlowGenerator.LIBRARY_TARGET_FOLDER_OUTPUT, timerInterfaceContent)
+			} else {
+				locations.configure(timedStatemachineInterface.h, IExecutionFlowGenerator.TARGET_FOLDER_OUTPUT, timedStatemachineInterfaceContent)
+				locations.configure(timerInterface.h, IExecutionFlowGenerator.TARGET_FOLDER_OUTPUT, timerInterfaceContent)
+			}
 		}
 		
-		flow.generateStatemachineHeader(flow.sourceElement as Statechart, fsa, entry)
-		flow.generateStatemachineImplemenation(flow.sourceElement as Statechart, fsa, entry)
+		locations.configure(flow.module.h, IExecutionFlowGenerator.TARGET_FOLDER_OUTPUT, statemachineHeaderContent)
+		locations.configure(flow.module.cpp, IExecutionFlowGenerator.TARGET_FOLDER_OUTPUT, statemachineSourceContent)
 	}
+	
 }

+ 6 - 9
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/StatemachineHeader.xtend

@@ -13,8 +13,8 @@ package org.yakindu.sct.generator.cpp
 import com.google.inject.Inject
 import java.util.List
 import org.eclipse.xtend2.lib.StringConcatenation
-import org.eclipse.xtext.generator.IFileSystemAccess
 import org.yakindu.base.types.Direction
+import org.yakindu.sct.generator.c.IGenArtifactConfigurations
 import org.yakindu.sct.generator.core.types.ICodegenTypeSystemAccess
 import org.yakindu.sct.generator.cpp.features.GenmodelEntriesExtension
 import org.yakindu.sct.model.sexec.Check
@@ -23,7 +23,6 @@ import org.yakindu.sct.model.sexec.Step
 import org.yakindu.sct.model.sexec.naming.INamingService
 import org.yakindu.sct.model.sgen.GeneratorEntry
 import org.yakindu.sct.model.sgraph.Scope
-import org.yakindu.sct.model.sgraph.Statechart
 import org.yakindu.sct.model.stext.stext.EventDefinition
 import org.yakindu.sct.model.stext.stext.InterfaceScope
 import org.yakindu.sct.model.stext.stext.InternalScope
@@ -40,21 +39,18 @@ class StatemachineHeader extends org.yakindu.sct.generator.c.StatemachineHeader
 
 	protected GeneratorEntry entry
 
-	def generateStatemachineHeader(ExecutionFlow flow, Statechart sc, IFileSystemAccess fsa, GeneratorEntry entry) {
+	override content(ExecutionFlow it, GeneratorEntry entry, extension IGenArtifactConfigurations artifactConfigs) {
 		this.entry = entry
-		fsa.generateFile(flow.module().h, flow.generateStatemachineHeaderContents(entry))
-	}
-
-	def generateStatemachineHeaderContents(ExecutionFlow it, GeneratorEntry entry) '''
+	'''
 		«entry.licenseText»
 		
 		#ifndef «module().define»_H_
 		#define «module().define»_H_
 		
-		#include "«typesModule.h»"
+		#include "«(typesModule.h).relativeTo(module.h)»"
 		#include "«statemachineInterface.h»"
 		«IF timed»
-			#include "«timedStatemachineInterface.h»"
+			#include "«(timedStatemachineInterface.h).relativeTo(module.h)»"
 		«ENDIF»
 		
 		/*! \file Header of the state machine '«name»'.
@@ -91,6 +87,7 @@ class StatemachineHeader extends org.yakindu.sct.generator.c.StatemachineHeader
 		«ENDIF»
 		#endif /* «module().define»_H_ */
 	'''
+	}
 
 	def protected getInterfaceExtensions(ExecutionFlow flow) {
 

+ 7 - 8
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/StatemachineImplementation.xtend

@@ -12,7 +12,8 @@ package org.yakindu.sct.generator.cpp
 
 import com.google.inject.Inject
 import java.util.List
-import org.eclipse.xtext.generator.IFileSystemAccess
+import org.yakindu.sct.generator.c.IContentTemplate
+import org.yakindu.sct.generator.c.IGenArtifactConfigurations
 import org.yakindu.sct.generator.core.types.ICodegenTypeSystemAccess
 import org.yakindu.sct.generator.cpp.features.GenmodelEntriesExtension
 import org.yakindu.sct.model.sexec.Check
@@ -21,13 +22,13 @@ import org.yakindu.sct.model.sexec.Step
 import org.yakindu.sct.model.sexec.extensions.StateVectorExtensions
 import org.yakindu.sct.model.sexec.naming.INamingService
 import org.yakindu.sct.model.sgen.GeneratorEntry
-import org.yakindu.sct.model.sgraph.Statechart
 import org.yakindu.sct.model.stext.stext.InterfaceScope
 import org.yakindu.sct.model.stext.stext.StatechartScope
 import org.yakindu.sct.model.stext.stext.VariableDefinition
+
 import static org.eclipse.xtext.util.Strings.*
 
-class StatemachineImplementation {
+class StatemachineImplementation implements IContentTemplate {
 	
 	@Inject extension Naming
 	@Inject extension Navigation
@@ -40,12 +41,9 @@ class StatemachineImplementation {
 	
 	protected GeneratorEntry entry
 	
-	def generateStatemachineImplemenation(ExecutionFlow flow, Statechart sc, IFileSystemAccess fsa, GeneratorEntry entry) {
+	override content(ExecutionFlow it, GeneratorEntry entry, IGenArtifactConfigurations artifactConfigs) {
 		this.entry = entry
-		fsa.generateFile(flow.module.cpp, flow.statemachineContent)
-	}
-	
-	def statemachineContent(ExecutionFlow it) '''
+	'''	
 		«entry.licenseText»
 		
 		#include "«module.h»"
@@ -83,6 +81,7 @@ class StatemachineImplementation {
 		
 		«functionImplementations»
 	'''
+	}
 	
 	def constructorDefinition(ExecutionFlow it) '''
 		«module»::«module»()

+ 6 - 9
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/StatemachineInterface.xtend

@@ -9,13 +9,14 @@
  */
 package org.yakindu.sct.generator.cpp
 
-import org.yakindu.sct.model.sexec.ExecutionFlow
-import org.yakindu.sct.model.sgen.GeneratorEntry
-import org.eclipse.xtext.generator.IFileSystemAccess
 import com.google.inject.Inject
 import org.yakindu.sct.generator.c.GenmodelEntries
+import org.yakindu.sct.generator.c.IContentTemplate
+import org.yakindu.sct.generator.c.IGenArtifactConfigurations
+import org.yakindu.sct.model.sexec.ExecutionFlow
+import org.yakindu.sct.model.sgen.GeneratorEntry
 
-class StatemachineInterface {
+class StatemachineInterface implements IContentTemplate {
 	
 	@Inject
 	extension Naming
@@ -23,11 +24,7 @@ class StatemachineInterface {
 	@Inject
 	extension GenmodelEntries
 	
-	def generateIStatemachine(ExecutionFlow flow, GeneratorEntry entry, IFileSystemAccess fsa) {
-		fsa.generateFile(statemachineInterface.h, flow.content(entry) )
-	}
-	
-	def private content(ExecutionFlow it, GeneratorEntry entry) {
+	override content(ExecutionFlow it, GeneratorEntry entry, IGenArtifactConfigurations locations) {
 		'''
 		«entry.licenseText»
 		

+ 6 - 18
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/TimedStatemachineInterface.xtend

@@ -9,15 +9,14 @@
  */
 package org.yakindu.sct.generator.cpp
 
-import org.yakindu.sct.model.sexec.ExecutionFlow
-import org.yakindu.sct.model.sgen.GeneratorEntry
-import org.eclipse.xtext.generator.IFileSystemAccess
 import com.google.inject.Inject
 import org.yakindu.sct.generator.c.GenmodelEntries
-import org.yakindu.sct.generator.core.library.IOutletFeatureHelper
-import org.yakindu.sct.generator.core.impl.IExecutionFlowGenerator
+import org.yakindu.sct.generator.c.IContentTemplate
+import org.yakindu.sct.generator.c.IGenArtifactConfigurations
+import org.yakindu.sct.model.sexec.ExecutionFlow
+import org.yakindu.sct.model.sgen.GeneratorEntry
 
-class TimedStatemachineInterface {
+class TimedStatemachineInterface implements IContentTemplate {
 	
 	@Inject
 	extension Naming
@@ -25,18 +24,7 @@ class TimedStatemachineInterface {
 	@Inject
 	extension GenmodelEntries
 	
-	@Inject
-	protected IOutletFeatureHelper outletFeatureHelper;
-	
-	def generateITimedStatemachine(ExecutionFlow flow, GeneratorEntry entry, IFileSystemAccess fsa) {
-		if (outletFeatureHelper.getLibraryTargetFolderValue(entry) != null)
-			fsa.generateFile(timedStatemachineInterface.h, IExecutionFlowGenerator.LIBRARY_TARGET_FOLDER_OUTPUT,
-				flow.content(entry))
-		else
-			fsa.generateFile(timedStatemachineInterface.h, flow.content(entry))
-	}
-	
-	def protected content(ExecutionFlow it, GeneratorEntry entry) {
+	override content(ExecutionFlow it, GeneratorEntry entry, IGenArtifactConfigurations locations) {
 		'''
 		«entry.licenseText»
 		

+ 6 - 18
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/TimerInterface.xtend

@@ -9,15 +9,14 @@
  */
 package org.yakindu.sct.generator.cpp
 
-import org.yakindu.sct.model.sexec.ExecutionFlow
-import org.yakindu.sct.model.sgen.GeneratorEntry
-import org.eclipse.xtext.generator.IFileSystemAccess
 import com.google.inject.Inject
 import org.yakindu.sct.generator.c.GenmodelEntries
-import org.yakindu.sct.generator.core.library.IOutletFeatureHelper
-import org.yakindu.sct.generator.core.impl.IExecutionFlowGenerator
+import org.yakindu.sct.generator.c.IContentTemplate
+import org.yakindu.sct.generator.c.IGenArtifactConfigurations
+import org.yakindu.sct.model.sexec.ExecutionFlow
+import org.yakindu.sct.model.sgen.GeneratorEntry
 
-class TimerInterface {
+class TimerInterface implements IContentTemplate {
 	
 	@Inject
 	extension Naming
@@ -25,18 +24,7 @@ class TimerInterface {
 	@Inject
 	extension GenmodelEntries
 	
-	@Inject
-	protected IOutletFeatureHelper outletFeatureHelper;
-	
-	def generateITimerService(ExecutionFlow flow, GeneratorEntry entry, IFileSystemAccess fsa) {
-		if (outletFeatureHelper.getLibraryTargetFolderValue(entry) != null)
-			fsa.generateFile(timerInterface.h, IExecutionFlowGenerator.LIBRARY_TARGET_FOLDER_OUTPUT,
-				flow.content(entry))
-		else
-			fsa.generateFile(timerInterface.h, flow.content(entry))
-	}
-	
-	def protected content(ExecutionFlow it, GeneratorEntry entry) {
+	override content(ExecutionFlow it, GeneratorEntry entry, IGenArtifactConfigurations locations) {
 		'''
 		«entry.licenseText»
 		

+ 7 - 20
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/Types.xtend

@@ -10,33 +10,19 @@
  */
 package org.yakindu.sct.generator.cpp
 
-import org.yakindu.sct.model.sexec.ExecutionFlow
-import org.yakindu.sct.model.sgraph.Statechart
-import org.eclipse.xtext.generator.IFileSystemAccess
 import com.google.inject.Inject
-import org.yakindu.sct.model.sgen.GeneratorEntry
 import org.yakindu.sct.generator.c.GenmodelEntries
-import org.yakindu.sct.generator.core.impl.IExecutionFlowGenerator
-import org.yakindu.sct.generator.core.library.IOutletFeatureHelper
+import org.yakindu.sct.generator.c.IContentTemplate
+import org.yakindu.sct.generator.c.IGenArtifactConfigurations
+import org.yakindu.sct.model.sexec.ExecutionFlow
+import org.yakindu.sct.model.sgen.GeneratorEntry
 
-class Types {
+class Types implements IContentTemplate {
 
 	@Inject extension Naming
 	@Inject extension GenmodelEntries
 
-	@Inject
-	protected IOutletFeatureHelper outletFeatureHelper;
-
-	def generateTypesHpp(ExecutionFlow flow, Statechart sc, IFileSystemAccess fsa, GeneratorEntry entry) {
-		if (outletFeatureHelper.getLibraryTargetFolderValue(entry) != null)
-			fsa.generateFile(flow.typesModule.h, IExecutionFlowGenerator.LIBRARY_TARGET_FOLDER_OUTPUT,
-				flow.typesHContent(entry))
-		else
-			fsa.generateFile(flow.typesModule.h, flow.typesHContent(entry))
-
-	}
-
-	def typesHContent(ExecutionFlow it, GeneratorEntry entry) '''
+	override content(ExecutionFlow it, GeneratorEntry entry, IGenArtifactConfigurations locations) '''
 		«entry.licenseText»
 		
 		#ifndef «typesModule.define»_H_
@@ -57,4 +43,5 @@ class Types {
 		
 		#endif /* «typesModule.define»_H_ */
 	'''
+	
 }