Browse Source

Use 'long' instead of 'int' for 'integer' values in generated Java code

markus.muehlbrandt@gmail.com 11 years ago
parent
commit
95f0e57b03

+ 4 - 0
plugins/org.yakindu.sct.generator.java/library/FeatureTypeLibrary.xmi

@@ -28,5 +28,9 @@
         name="TimerService"
         optional="true"
         parameterType="BOOLEAN"/>
+    <parameters
+        name="UseJavaIntForInteger"
+        optional="true"
+        parameterType="BOOLEAN"/>
   </types>
 </sgen:FeatureTypeLibrary>

+ 12 - 1
plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/GenmodelEntries.xtend

@@ -56,6 +56,10 @@ class GenmodelEntries {
 		generalFeatures?.getParameterValue(IJavaFeatureConstants::INTERFACE_OBSERVER_SUPPORT)
 	}
 	
+	def private FeatureParameterValue getUseJavaIntForInteger(GeneratorEntry it) {
+		generalFeatures?.getParameterValue(IJavaFeatureConstants::USE_JAVA_INT_FOR_INTEGER)
+	}
+	
 	def getLicenseText(GeneratorEntry it) {
 		if (licenseTextParameter != null) {
 			return "/**"+licenseTextParameter.stringValue+"*/"
@@ -110,5 +114,12 @@ class GenmodelEntries {
 			return interfaceObserverSupportParameter.booleanValue
 		}
 		return false
-	} 
+	}
+	
+	def useJavaInt(GeneratorEntry it) {
+		if (useJavaIntForInteger != null) {
+			return useJavaIntForInteger.booleanValue
+		}
+		return false
+	}
 }

+ 12 - 5
plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/JavaCodeGenerator.java

@@ -14,6 +14,7 @@ import static org.yakindu.sct.generator.core.util.GeneratorUtils.isDumpSexec;
 import org.yakindu.sct.generator.core.impl.GenericJavaBasedGenerator;
 import org.yakindu.sct.generator.core.types.ICodegenTypeSystemAccess;
 import org.yakindu.sct.generator.java.types.JavaTypeSystemAccess;
+import org.yakindu.sct.generator.java.types.OldJavaTypeSystemAccess;
 import org.yakindu.sct.model.sexec.ExecutionFlow;
 import org.yakindu.sct.model.sgen.GeneratorEntry;
 import org.yakindu.sct.model.sgraph.Statechart;
@@ -23,12 +24,12 @@ import com.google.inject.Module;
 import com.google.inject.util.Modules;
 
 public class JavaCodeGenerator extends GenericJavaBasedGenerator {
-
+	
 	@Override
 	public void runGenerator(Statechart statechart, GeneratorEntry entry) {
 		JavaGenerator delegate = getInjector(entry).getInstance(
 				JavaGenerator.class);
-
+		
 		ExecutionFlow flow = createExecutionFlow(statechart, entry);
 
 		if (isDumpSexec(entry)) {
@@ -39,12 +40,18 @@ public class JavaCodeGenerator extends GenericJavaBasedGenerator {
 	}
 
 	@Override
-	protected Module createModule(GeneratorEntry entry) {
+	protected Module createModule(final GeneratorEntry entry) {
 		Module module = super.createModule(entry);
+		final GenmodelEntries entries = new GenmodelEntries();
 		return Modules.override(module).with(new Module() {
 			public void configure(Binder binder) {
-				binder.bind(ICodegenTypeSystemAccess.class).to(
-						JavaTypeSystemAccess.class);
+				if (entries.useJavaInt(entry)) {
+					binder.bind(ICodegenTypeSystemAccess.class).to(
+							OldJavaTypeSystemAccess.class);
+				} else {
+					binder.bind(ICodegenTypeSystemAccess.class).to(
+							JavaTypeSystemAccess.class);
+				}
 			}
 		});
 	}

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

@@ -39,6 +39,8 @@ public interface IJavaFeatureConstants {
 	
 	public static final String STATEMACHINE_FACTORY_SUPPORT = "StatemachineFactorySupport";
 	
+	public static final String USE_JAVA_INT_FOR_INTEGER = "UseJavaIntForInteger";
+	
 	public static final String[] JAVA_KEYWORDS = { "abstract", "assert",
 		"boolean", "break", "byte", "case", "catch", "char", "class",
 		"const", "continue", "default", "do", "double", "else", "enum",

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

@@ -65,4 +65,8 @@ public final class JavaFeatureConstants implements IJavaFeatureConstants {
 	public static final String getStatemachineFactorySupport() {
 		return STATEMACHINE_FACTORY_SUPPORT;
 	}
+	
+	public static final String getUseJavaIntForInteger() {
+		return USE_JAVA_INT_FOR_INTEGER;
+	}
 }

+ 1 - 1
plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/types/JavaTypeSystemAccess.xtend

@@ -28,7 +28,7 @@ class JavaTypeSystemAccess implements ICodegenTypeSystemAccess {
 		switch (type) {
 			case type == null || isVoidType(type): "void"
 			case isRealType(type) : "double"
-			case isIntegerType(type) : "int"
+			case isIntegerType(type) : "long"
 			case isBooleanType(type) : "boolean"
 			case isStringType(type) : "String"
 			default : "//"+this

+ 37 - 0
plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/types/OldJavaTypeSystemAccess.xtend

@@ -0,0 +1,37 @@
+/**
+ * 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:
+ *     committers of YAKINDU - initial API and implementation
+ */
+package org.yakindu.sct.generator.java.types
+
+import com.google.inject.Inject
+import org.yakindu.base.types.Type
+import org.yakindu.sct.generator.core.types.ICodegenTypeSystemAccess
+import org.yakindu.sct.model.stext.types.ISTextTypeSystem
+
+/**
+ * @author andreas muelder
+ * @author Alexander Nyßen - Adopted to type system changes
+ */
+class OldJavaTypeSystemAccess implements ICodegenTypeSystemAccess {
+	
+	@Inject
+	private extension ISTextTypeSystem ts
+	
+	override String getTargetLanguageName(Type type) {
+		switch (type) {
+			case type == null || isVoidType(type): "void"
+			case isRealType(type) : "double"
+			case isIntegerType(type) : "int"
+			case isBooleanType(type) : "boolean"
+			case isStringType(type) : "String"
+			default : "//"+this
+		};
+	}
+}