浏览代码

Add generator feature 'Includes' with option 'useRelativePaths' (#1245)

* Add generator feature 'Includes' with option 'useRelativePaths' to specifiy if include statements should be relative paths or simple names (#1206)

* Fix dupliate paragraph id
Thomas Kutz 8 年之前
父节点
当前提交
130246cccb

+ 28 - 0
plugins/org.yakindu.sct.doc.user/src/user-guide/generating_code.textile

@@ -249,7 +249,21 @@ bc. feature Tracing {
 
 ==<!-- End sgen_feature_tracing -->==
 
+==<!-- Start sgen_feature_includes -->==
 
+h3(#c-includes-feature). Includes feature
+
+The *Includes* feature allows to change how include statements are generated:
+
+# _useRelativePaths_ (Boolean, optional): If this parameter is set to _true_, relative paths are calculated for include statements, otherwise simple includes are used. Default value is _true_.
+
+bq.. *Example:*
+
+bc. feature Includes {
+    useRelativePaths = false
+}
+
+==<!-- End sgen_feature_includes -->==
 
 h2(#c-specification-of-c-code). Specification of C code
 
@@ -765,7 +779,21 @@ bc. feature GeneratorOptions {
 
 ==<!-- End sgen_feature_generatoroptions -->==
 
+==<!-- Start sgen_feature_includes -->==
+
+h3(#cpp-includes-feature). Includes feature
+
+The *Includes* feature allows to change how include statements are generated:
+
+# _useRelativePaths_ (Boolean, optional): If this parameter is set to _true_, relative paths are calculated for include statements, otherwise simple includes are used. Default value is _true_.
+
+bq.. *Example:*
+
+bc. feature Includes {
+    useRelativePaths = false
+}
 
+==<!-- End sgen_feature_includes -->==
 
 h2(#cpp-specification-of-cpp-code). Specification of C++ code
 

+ 8 - 0
plugins/org.yakindu.sct.generator.c/library/FeatureTypeLibrary.xmi

@@ -35,4 +35,12 @@
         comment="Whether to generate a callback that is used when a state is entered."
         parameterType="BOOLEAN"/>
   </types>
+  <types name="Includes"
+      optional="true">
+    <parameters
+        name="useRelativePaths"
+        comment="If set to 'true' relative paths are calculated for include statements, otherwise simple includes are used."
+        optional="true"
+        parameterType="BOOLEAN"/>
+  </types>
 </sgen:FeatureTypeLibrary>

+ 17 - 1
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/CCodeGeneratorModule.java

@@ -11,8 +11,10 @@
 package org.yakindu.sct.generator.c;
 
 import static org.yakindu.sct.generator.c.features.ICFeatureConstants.FEATURE_TRACING;
+import static org.yakindu.sct.generator.c.features.ICFeatureConstants.FEATURE_INCLUDES;
 import static org.yakindu.sct.generator.c.features.ICFeatureConstants.PARAMETER_TRACING_ENTER_STATE;
 import static org.yakindu.sct.generator.c.features.ICFeatureConstants.PARAMETER_TRACING_EXIT_STATE;
+import static org.yakindu.sct.generator.c.features.ICFeatureConstants.PARAMETER_INCLUDES_USE_RELATIVE_PATHS;
 import static org.yakindu.sct.model.sexec.transformation.IModelSequencer.ADD_TRACES;
 
 import org.yakindu.sct.generator.c.types.CTypeSystemAccess;
@@ -38,7 +40,11 @@ public class CCodeGeneratorModule implements GeneratorModule {
 		binder.bind(IExecutionFlowGenerator.class).to(CGenerator.class);
 		binder.bind(INamingService.class).to(CNamingService.class);
 		binder.bind(ICodegenTypeSystemAccess.class).to(CTypeSystemAccess.class);
-		binder.bind(IGenArtifactConfigurations.class).to(DefaultGenArtifactConfigurations.class);
+		bindIGenArtifactConfigurations(entry, binder);
+		bindTracingProperty(entry, binder);
+	}
+
+	protected void bindTracingProperty(GeneratorEntry entry, Binder binder) {
 		FeatureParameterValue traceEnterFeature = entry.getFeatureParameterValue(FEATURE_TRACING,
 				PARAMETER_TRACING_ENTER_STATE);
 		FeatureParameterValue traceExitFeature = entry.getFeatureParameterValue(FEATURE_TRACING,
@@ -46,7 +52,17 @@ public class CCodeGeneratorModule implements GeneratorModule {
 		boolean traceEnter = traceEnterFeature != null ? traceEnterFeature.getBooleanValue() : false;
 		boolean traceExit = traceExitFeature != null ? traceEnterFeature.getBooleanValue() : false;
 		binder.bind(Boolean.class).annotatedWith(Names.named(ADD_TRACES)).toInstance(traceEnter || traceExit);
+	}
 
+	protected void bindIGenArtifactConfigurations(GeneratorEntry entry, Binder binder) {
+		FeatureParameterValue useRelativePathParam = entry.getFeatureParameterValue(FEATURE_INCLUDES,
+				PARAMETER_INCLUDES_USE_RELATIVE_PATHS);
+		boolean useRelativePath = useRelativePathParam != null ? useRelativePathParam.getBooleanValue() : true;
+		if (useRelativePath) {
+			binder.bind(IGenArtifactConfigurations.class).to(DefaultGenArtifactConfigurations.class);
+		} else {
+			binder.bind(IGenArtifactConfigurations.class).to(SimpleGenArtifactConfigurations.class);
+		}
 	}
 
 }

+ 29 - 0
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/SimpleGenArtifactConfigurations.java

@@ -0,0 +1,29 @@
+/**
+ * Copyright (c) 2017 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:
+ * 	committers of YAKINDU - initial API and implementation
+ * 
+ */
+package org.yakindu.sct.generator.c;
+
+import org.eclipse.core.runtime.Path;
+
+/**
+ * 
+ * Circumvents relative path computation by just returning the target artifact's simple name.
+ * 
+ * @author thomas kutz
+ *
+ */
+public class SimpleGenArtifactConfigurations extends DefaultGenArtifactConfigurations {
+
+	
+	@Override
+	public String relativeTo(String target, String fromArtifact) {
+		return new Path(target).lastSegment();
+	}
+}

+ 2 - 0
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/features/CDefaultFeatureValueProvider.java

@@ -61,6 +61,8 @@ public class CDefaultFeatureValueProvider extends AbstractDefaultFeatureValuePro
 			parameterValue.setValue(true);
 		} else if (ICFeatureConstants.PARAMETER_TRACING_EXIT_STATE.equals(parameterName)) {
 			parameterValue.setValue(true);
+		} else if (ICFeatureConstants.PARAMETER_INCLUDES_USE_RELATIVE_PATHS.equals(parameterName)) {
+			parameterValue.setValue(true);
 		} else {
 			throw new IllegalArgumentException("Unsupported parameter '" + parameterName + "'.");
 		}

+ 4 - 0
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/features/ICFeatureConstants.java

@@ -42,4 +42,8 @@ public interface ICFeatureConstants {
 	public static final String PARAMETER_TRACING_ENTER_STATE = "enterState";
 	
 	public static final String PARAMETER_TRACING_EXIT_STATE = "exitState";
+	
+	public static final String FEATURE_INCLUDES = "Includes";
+	
+	public static final String PARAMETER_INCLUDES_USE_RELATIVE_PATHS = "useRelativePaths";
 }

+ 8 - 0
plugins/org.yakindu.sct.generator.cpp/library/FeatureTypeLibrary.xmi

@@ -32,4 +32,12 @@
         optional="true"
         parameterType="BOOLEAN"/>
   </types>
+  <types name="Includes"
+      optional="true">
+    <parameters
+        name="useRelativePaths"
+        comment="If set to 'true' relative paths are calculated for include statements, otherwise simple includes are used."
+        optional="true"
+        parameterType="BOOLEAN"/>
+  </types>
 </sgen:FeatureTypeLibrary>

+ 19 - 0
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/CppCodeGeneratorModule.java

@@ -10,12 +10,19 @@
  */
 package org.yakindu.sct.generator.cpp;
 
+import static org.yakindu.sct.generator.cpp.features.CPPFeatureConstants.FEATURE_INCLUDES;
+import static org.yakindu.sct.generator.cpp.features.CPPFeatureConstants.PARAMETER_INCLUDES_USE_RELATIVE_PATHS;
+
 import org.yakindu.base.types.inferrer.ITypeSystemInferrer;
+import org.yakindu.sct.generator.c.DefaultGenArtifactConfigurations;
+import org.yakindu.sct.generator.c.IGenArtifactConfigurations;
+import org.yakindu.sct.generator.c.SimpleGenArtifactConfigurations;
 import org.yakindu.sct.generator.c.types.CTypeSystemAccess;
 import org.yakindu.sct.generator.core.GeneratorModule;
 import org.yakindu.sct.generator.core.IExecutionFlowGenerator;
 import org.yakindu.sct.generator.core.types.ICodegenTypeSystemAccess;
 import org.yakindu.sct.model.sexec.naming.INamingService;
+import org.yakindu.sct.model.sgen.FeatureParameterValue;
 import org.yakindu.sct.model.sgen.GeneratorEntry;
 import org.yakindu.sct.model.stext.inferrer.STextTypeInferrer;
 
@@ -35,6 +42,18 @@ public class CppCodeGeneratorModule implements GeneratorModule {
 		binder.bind(ICodegenTypeSystemAccess.class).to(CTypeSystemAccess.class);
 		binder.bind(INamingService.class).to(CppNamingService.class);
 		binder.bind(ITypeSystemInferrer.class).to(STextTypeInferrer.class);
+		bindIGenArtifactConfigurations(entry, binder);
+	}
+	
+	protected void bindIGenArtifactConfigurations(GeneratorEntry entry, Binder binder) {
+		FeatureParameterValue useRelativePathParam = entry.getFeatureParameterValue(FEATURE_INCLUDES,
+				PARAMETER_INCLUDES_USE_RELATIVE_PATHS);
+		boolean useRelativePath = useRelativePathParam != null ? useRelativePathParam.getBooleanValue() : true;
+		if (useRelativePath) {
+			binder.bind(IGenArtifactConfigurations.class).to(DefaultGenArtifactConfigurations.class);
+		} else {
+			binder.bind(IGenArtifactConfigurations.class).to(SimpleGenArtifactConfigurations.class);
+		}
 	}
 
 }

+ 2 - 0
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/features/CPPDefaultFeatureValueProvider.java

@@ -60,6 +60,8 @@ public class CPPDefaultFeatureValueProvider extends AbstractDefaultFeatureValueP
 			parameterValue.setValue(Visibility.PRIVATE.toString().toLowerCase());
 		} else if (parameterValue.getParameter().getName().equals(CPPFeatureConstants.PARAMETER_STATIC_OPC)) {
 			parameterValue.setValue(false);
+		} else if (parameterValue.getParameter().getName().equals(CPPFeatureConstants.PARAMETER_INCLUDES_USE_RELATIVE_PATHS)) {
+			parameterValue.setValue(true);
 		}
 	}
 

+ 4 - 0
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/features/CPPFeatureConstants.java

@@ -29,4 +29,8 @@ public interface CPPFeatureConstants {
 	public static final String PARAMETER_INNER_FUNCTION_VISIBILITY = "innerFunctionVisibility";
 	
 	public static final String PARAMETER_STATIC_OPC = "staticOperationCallback";
+	
+	public static final String FEATURE_INCLUDES = "Includes";
+	
+	public static final String PARAMETER_INCLUDES_USE_RELATIVE_PATHS = "useRelativePaths";
 }