Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Tracing, StringConcatenationClient and String
Tracing, StringConcatenationClient and String [message #1776915] Wed, 22 November 2017 18:41 Go to next message
Steve Hostettler is currently offline Steve HostettlerFriend
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 #1776916 is a reply to message #1776915] Wed, 22 November 2017 18:44 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12243
Registered: July 2009
Senior Member
if you define the type of the method to StringConcatenationClient explictely it will be compiled as a such.
the StringConcatenationClient allows the framework to intercept the stuff you put between the <<>>


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Tracing, StringConcatenationClient and String [message #1776921 is a reply to message #1776916] Wed, 22 November 2017 19:52 Go to previous messageGo to next message
Steve Hostettler is currently offline Steve HostettlerFriend
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.
Re: Tracing, StringConcatenationClient and String [message #1776924 is a reply to message #1776921] Wed, 22 November 2017 20:10 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12243
Registered: July 2009
Senior Member
because that is the way how rich strings are compiled to a StringConcatentationClient.
the string part is compiled differently (have a look at the generated files in each case)

whatabout moving the vars to the catenation?

e.g.

def static StringConcatenationClient yyy() '''
«var x = 1»
«var y = 2»
xxx«x» «y»
'''


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Tracing, StringConcatenationClient and String [message #1776948 is a reply to message #1776924] Thu, 23 November 2017 07:26 Go to previous message
Steve Hostettler is currently offline Steve HostettlerFriend
Messages: 81
Registered: June 2016
Member
Hello thanks for your reply. Does work. Thanks again
Previous Topic:How to retrieve all visible entities from the global index?
Next Topic:Traces are not generated
Goto Forum:
  


Current Time: Tue Sep 25 20:34:10 GMT 2018

Powered by FUDForum. Page generated in 0.01696 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top