Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Trouble emitting template code after splitting Generator Xtend into two pieces(Noob)
Trouble emitting template code after splitting Generator Xtend into two pieces [message #1219896] Fri, 06 December 2013 14:44 Go to next message
Gary Worsham is currently offline Gary WorshamFriend
Messages: 176
Registered: September 2013
Senior Member
My code generator emits 3 different files. So of course I need 3 code generation methods. The generator Xtend was getting a little large so as usual I wanted to break it into smaller pieces. I succeeded in taking out one of the classes to a separate file, and when I use the debugger, it is actually executing those lines, but nothing is coming out except the comment which I emit in the primary generator class.

Here's the main generator class section where the three different generators get called. toTestCode() creates a new class of the separated code and calls the specific methods.

	override void doGenerate(Resource resource, IFileSystemAccess fsa) {
		var pkage = "\\com\\holycityaudio\\SpinCAD\\CADBlocks\\"
		fsa.generateFile(pkage + resource.className+"CADBlock.java", toCADBlockCode(resource.contents.head as Program))
		pkage = "\\com\\holycityaudio\\SpinCAD\\ControlPanel\\"
		fsa.generateFile(pkage + resource.className+"ControlPanel.java", toControlPanelCode(resource.contents.head as Program))
		pkage = "\\com\\holycityaudio\\SpinCAD\\test\\"
		fsa.generateFile(pkage + resource.className+"Test.java", toTestCode(resource.contents.head as Program))
	}
	
	def className(Resource res) {
		var name = res.URI.lastSegment
		// println(name)
		return name.substring(0, name.indexOf('.'))
	}
	
	def toTestCode(Program pr) { 
		val blockName = pr.eResource.className
		var boop = new SpinCADTestGenerator
		boop.genTestHeader(blockName)
		boop.testNoConnections(blockName)
		boop.testAllConnections(blockName, pr)
		boop.genTestCloser()
	'''
	// do something
	'''
	}


and here's an example of two of the called methods:

class SpinCADTestGenerator {
 
def genTestHeader(String blockName) { 
	'''
package com.holycityaudio.SpinCAD.test;

import javax.swing.SwingUtilities;

import com.holycityaudio.SpinCAD.SpinCADFrame;
import com.holycityaudio.SpinCAD.SpinCADPanel;
import com.holycityaudio.SpinCAD.SpinCADPin;
import com.holycityaudio.SpinCAD.CADBlocks.*;
import com.holycityaudio.SpinCAD.ControlBlocks.*;

public class «blockName+"Test"» {
	public «blockName+"Test"»(SpinCADFrame f) {
		System.out.println("Start of «blockName»CADBlock unit test..." + "\n");

		SpinCADPanel p = new SpinCADPanel(f);
		InputCADBlock i = new InputCADBlock(225, 10);
		OutputCADBlock o = new OutputCADBlock(225, 290);
'''
}

def genTestCloser() {
	'''
	// end of test code
	}
	'''
}


The only thing that is getting generated is the line:

	// do something


No errors or warnings, and like I said, the debugger does trace through the SpinCADTestGenerator methods. Just nothing is coming out. The generator code that is still in the first file works fine.

?????

Thanks!!!!

GW
Re: Trouble emitting template code after splitting Generator Xtend into two pieces [message #1219898 is a reply to message #1219896] Fri, 06 December 2013 14:48 Go to previous messageGo to next message
Gary Worsham is currently offline Gary WorshamFriend
Messages: 176
Registered: September 2013
Senior Member
In what seems to be a recurring pattern, I have solved the problem immediately after posting this notice. The answer is:

	def toTestCode(Program pr) { 
		val blockName = pr.eResource.className
		var boop = new SpinCADTestGenerator
	'''
		«boop.genTestHeader(blockName)»
		«boop.testNoConnections(blockName)»
		«boop.testAllConnections(blockName, pr)»
		«boop.genTestCloser()»

	// do something
	'''
	}

[Updated on: Fri, 06 December 2013 14:49]

Report message to a moderator

Re: Trouble emitting template code after splitting Generator Xtend into two pieces [message #1219904 is a reply to message #1219896] Fri, 06 December 2013 15:10 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13661
Registered: July 2009
Senior Member
If you call a method and throw its result to /dev/null/ ...

Maybe what you actually want to do is
'''
//somecomment
<<someMethod>>
<<someOtherMethods>>
''''

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:How to use Xtext 2.5 new Full Maven Support in own code generator shipped as maven plugin?
Next Topic:Resolving proxies
Goto Forum:
  


Current Time: Thu Nov 26 10:07:43 GMT 2020

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

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

Back to the top