Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice')
-rw-r--r--plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/Initialization.xtend27
-rw-r--r--plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/JavaExtensions.xtend28
2 files changed, 34 insertions, 21 deletions
diff --git a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/Initialization.xtend b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/Initialization.xtend
index 17af4439e..f3484e9cb 100644
--- a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/Initialization.xtend
+++ b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/Initialization.xtend
@@ -49,8 +49,7 @@ class Initialization {
«IF tmp.length==0»«defaultInit(a, useClassDefaultsOnly)»«ENDIF»
«ENDFOR»
'''
- }
-
+ }
def private dataConfigurationInit(EObject roomClass, List<Attribute> path){
var a = path.last
var aType = a.refType.type
@@ -66,21 +65,21 @@ class Initialization {
''''''
}
- def private valueInit(List<Attribute> path, String value){
- if(value == null) return ''''''
+ def private valueInit(List<Attribute> path, String literalValue){
+ if(literalValue == null) return ''''''
var a = path.last
var aType = a.refType.type
var getter = if(path.size > 1)procedureHelpers.invokeGetters(path.take(path.size-1), null)+"." else ""
'''
«IF a.size == 0 || aType.characterType»
- «getter»«procedureHelpers.invokeSetter(a.name,null,value)»;
- «ELSEIF value.startsWith("{")»
- «getter»«procedureHelpers.invokeSetter(a.name,null, '''new «aType.typeName»[] «value»''')»;
+ «getter»«procedureHelpers.invokeSetter(a.name,null,literalValue)»;
+ «ELSEIF literalValue.startsWith("{")»
+ «getter»«procedureHelpers.invokeSetter(a.name,null, '''new «aType.typeName»[] «literalValue»''')»;
«ELSE»
{
«aType.typeName»[] _«a.name» = new «aType.typeName»[«a.size»];
for (int i=0;i<«a.size»;i++){
- _«a.name»[i] = «value»;
+ _«a.name»[i] = «literalValue»;
}
«getter»«procedureHelpers.invokeSetter(a.name,null,"_"+a.name)»;
}
@@ -109,8 +108,9 @@ class Initialization {
'''
}
- def private getRoomDefaulValue(Attribute a){
- a.defaultValueLiteral
+ def String getRoomDefaulValue(Attribute a){
+ if(a.refType.type.primitive && a.defaultValueLiteral != null)
+ languageExt.toValueLiteral(a.refType.type as PrimitiveType, a.defaultValueLiteral)
}
def private String getDataConfigValue(EObject roomClass, List<Attribute> path){
@@ -125,11 +125,8 @@ class Initialization {
dataConfigExt.getAttrClassConfigValue(pc, pc.regular.equals(roomClass), path)
}
}
- return if(result != null)
- if(a.size > 0 && !aType.characterType)
- '''{ «FOR e : result.split(',') SEPARATOR ", "»«languageExt.toValueLiteral(aType, e)»«ENDFOR»}'''
- else
- languageExt.toValueLiteral(aType, result)
+ if(result != null)
+ return languageExt.toValueLiteral(aType, result)
}
}
diff --git a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/JavaExtensions.xtend b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/JavaExtensions.xtend
index e461a45fd..d76f23f5a 100644
--- a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/JavaExtensions.xtend
+++ b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/JavaExtensions.xtend
@@ -100,13 +100,27 @@ class JavaExtensions implements ILanguageExtension {
override String destructorReturnType() {
"void"
}
- override String toCharArrayExpr(String s){
- "\"" + s + "\".toCharArray()"
- }
+
override String superCall(String baseClassName, String method, String args) {
"super."+method+"("+args+");"
}
- override String toValueLiteral(PrimitiveType type, String value){
+
+ override toValueLiteral(PrimitiveType type, String value) {
+ switch(type.targetName){
+ case "char":
+ castValue(type, value)
+ case "string":
+ castValue(type, value)
+ case value.contains(','):{
+ var singleValues = value.replace('{', '').replace('}', '').trim.split(',')
+ '''{ «FOR v: singleValues SEPARATOR ', '»«castValue(type, v.trim)»«ENDFOR» }'''.toString
+ }
+ default:
+ castValue(type, value)
+ }
+ }
+
+ def private castValue(PrimitiveType type, String value){
switch(type.targetName){
case "boolean":
return value
@@ -126,10 +140,10 @@ class JavaExtensions implements ILanguageExtension {
if(value.length == 1)
return "'"+value+"'"
else
- return value.toCharArrayExpr
+ return "\""+value.replace("\\", "\\\\").replace("\"", "\\\"")+"\".toCharArray()"
}
case "String":
- return "\""+value+"\""
+ return "\""+value.replace("\\", "\\\\").replace("\"", "\\\"")+"\""
}
throw new UnsupportedOperationException(type.targetName)
@@ -183,4 +197,6 @@ class JavaExtensions implements ILanguageExtension {
return newArrayList(dataArg, typedData, typedArgList);
}
+
+
}

Back to the top