Tracing, StringConcatenationClient and String [message #1776915] |
Wed, 22 November 2017 18:41 |
Steve Hostettler Messages: 81 Registered: June 2016 |
Member |
|
|
Helllo,
I am very confused with the StringConcatenationClient class and its relation to String. I am trying to add tracing to my DSL but when I use fsa.generateTracedFile the last parameter is a StringConcatenationClient instead of String.
At development time I can do a cast but at runtime I get a ClassCastException.
Not sure how to handle this, could someone point me in the right direction with the following code:
def generate(Activity activity, IFileSystemAccess2 fsa, GeneratorContext context) {
fsa.generateTracedFile(activity.toClassFileName, activity, activity.generateBody(context) as StringConcatenationClient)
}
def generateBody(Activity activity, GeneratorContext context) {
if (activity.consume) {
context.requireInputDao(activity.parameter.regularType.type)
}
val body = '''
«FOR statement : activity.statements»
«statement.generate(context)»
«ENDFOR»
'''
val activityFQN = activity.fullyQualifiedName(activity.name)
val dependencies = context.generalContext.getDependenciesByFQN(activityFQN)
val activityTables = dependencies.tables
val fieldContext = dependencies.fieldContext
'''
package «activity.toPackageName»;
...
«context.generate(dependencies)»
«activity.generateConstructorActivity(context, activityTables)»
}
'''
/*
*/
}
|
|
|
|
Re: Tracing, StringConcatenationClient and String [message #1776921 is a reply to message #1776916] |
Wed, 22 November 2017 19:52 |
Steve Hostettler Messages: 81 Registered: June 2016 |
Member |
|
|
Hello thanks for the reply.
I get that bug then why is
def String getDecisionTableBody (DecisionTableFunction function, List<String> inputTypesList, DecisionTable table) {
var argIndex = 0
var argIndexError = 0
'''
package «function.toPackageName»;
public class «function.toSimpleClassName» {
public «table.decisions.head.output.class.name» decide(«FOR inputType : inputTypesList SEPARATOR ', '»«inputType» $«argIndex++»«ENDFOR»){
«FOR decision : table.decisions »
if («FOR input : decision.inputs SEPARATOR ' && '»«IF input === null || input == ""»true /* for $«argIndex++ % decision.inputs.size» */«ELSE»(«generateCondition(argIndex++ % decision.inputs.size, String.valueOf(input), inputTypesList)»)«ENDIF»«ENDFOR»){
return «IF decision.output === null»null«ELSE»«generateValue(decision.output)»«ENDIF»;
} «ENDFOR»«IF table.defaultDecision !== null» else {
return «IF table.defaultDecision.output === null»null«ELSE»«generateValue(table.defaultDecision.output)»«ENDIF»;
}«ELSE»throw new IllegalArgumentException("Decision table called with unexpected arguments: " + « FOR input : table.decisions.head.inputs SEPARATOR' + " and " +'» $«argIndexError++» «ENDFOR» ); «ENDIF»
}
}'''
}
fine whereas
def StringConcatenationClient getDecisionTableBody (DecisionTableFunction function, List<String> inputTypesList, DecisionTable table) {
var argIndex = 0
var argIndexError = 0
'''
package «function.toPackageName»;
public class «function.toSimpleClassName» {
public «table.decisions.head.output.class.name» decide(«FOR inputType : inputTypesList SEPARATOR ', '»«inputType» $«argIndex++»«ENDFOR»){
«FOR decision : table.decisions »
if («FOR input : decision.inputs SEPARATOR ' && '»«IF input === null || input == ""»true /* for $«argIndex++ % decision.inputs.size» */«ELSE»(«generateCondition(argIndex++ % decision.inputs.size, String.valueOf(input), inputTypesList)»)«ENDIF»«ENDFOR»){
return «IF decision.output === null»null«ELSE»«generateValue(decision.output)»«ENDIF»;
} «ENDFOR»«IF table.defaultDecision !== null» else {
return «IF table.defaultDecision.output === null»null«ELSE»«generateValue(table.defaultDecision.output)»«ENDIF»;
}«ELSE»throw new IllegalArgumentException("Decision table called with unexpected arguments: " + « FOR input : table.decisions.head.inputs SEPARATOR' + " and " +'» $«argIndexError++» «ENDFOR» ); «ENDIF»
}
}'''
}
raises a compilation error:
Resource Description Path Location Type
d Cannot refer to the non-final variable argIndex inside this template.
This template compiles to an anonymous subclass of StringConcatenationClient because of its target type.
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04053 seconds