Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Xpand] Dynamic position of generated text
[Xpand] Dynamic position of generated text [message #843658] Fri, 13 April 2012 08:46 Go to next message
Hai Le is currently offline Hai LeFriend
Messages: 9
Registered: April 2012
Location: Vietnam
Junior Member
Hi all,

Please take a look at my problem. Let's consider that we have 3 very simple templates in Xpand: class, variable and method.

«DEFINE class FOR X»
public class MyClass {
	«EXPAND variableDec»
	«EXPAND method»
}
«ENDDEFINE»

«DEFINE variable FOR X»
	int a = 0;
	int b = 0;
	int c = 0;
«ENDDEFINE»

«DEFINE method FOR X»
	public static String methodA() {
		«EXPAND variable»
	}
«ENDDEFINE»


The output shall be:

public class MyClass {
	int a = 0;
	int b = 0;
	int c = 0;
	
	public static String methodA() {
	int a = 0;
	int b = 0;
	int c = 0;
	}
}


So I wonder that do we have any way to make the text generated right at the place where EXPAND statement is placed. Specifically, if we update the template variable as:

«DEFINE variable FOR X»
int a = 0;
int b = 0;
int c = 0;
«ENDDEFINE»


And the calling of variable template in other templates:

«DEFINE class FOR X»
public class MyClass {
	«EXPAND variableDec»
	«EXPAND method»
}
«ENDDEFINE»

«DEFINE method FOR X»
public static String methodA() {
	«EXPAND variable»
}
«ENDDEFINE»


Then the expected text is generated as:

public class MyClass {
	int a = 0;
	int b = 0;
	int c = 0;
	
	public static String methodA() {
		int a = 0;
		int b = 0;
		int c = 0;
	}
}


Hope that everyone could understand my situation. Thanks for any help!
Re: [Xpand] Dynamic position of generated text [message #843704 is a reply to message #843658] Fri, 13 April 2012 09:31 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6485
Registered: July 2009
Senior Member
Hi actually do not understand the problem can you make clear what is
NOT working
Re: [Xpand] Dynamic position of generated text [message #843730 is a reply to message #843704] Fri, 13 April 2012 10:07 Go to previous messageGo to next message
Hai Le is currently offline Hai LeFriend
Messages: 9
Registered: April 2012
Location: Vietnam
Junior Member
Hi Christian,

Of course it is always working. The point here is that I have a "common" template just like the above sample:

«DEFINE variable FOR X»
	int a = 0;
	int b = 0;
	int c = 0;
«ENDDEFINE»


This template shall be called from the others such as:

«DEFINE class FOR X»
public class MyClass {
	«EXPAND variable»	
}
«ENDDEFINE»


--> The output here is OK:
public class MyClass {
	int a = 0;
	int b = 0;
	int c = 0;	
}


However, due to this template is common, so there is another usecase like this:

«DEFINE class FOR X»
public class MyClass {
	
	public static String methodA() {
		«EXPAND variable»
	}
}
«ENDDEFINE»


The code is actually generated as:
public class MyClass {
	
	public static String methodA() {
	int a = 0;
	int b = 0;
	int c = 0;
	}
}


But expected as:
public class MyClass {
	int a = 0;
	int b = 0;
	int c = 0;
	
	public static String methodA() {
		int a = 0;
		int b = 0;
		int c = 0;
	}
}


How do you think?

[Updated on: Fri, 13 April 2012 10:08]

Report message to a moderator

Re: [Xpand] Dynamic position of generated text [message #843749 is a reply to message #843730] Fri, 13 April 2012 10:27 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6485
Registered: July 2009
Senior Member
Still confusing what you mean. Are you talking about the indention?
Re: [Xpand] Dynamic position of generated text [message #843753 is a reply to message #843749] Fri, 13 April 2012 10:34 Go to previous messageGo to next message
Hai Le is currently offline Hai LeFriend
Messages: 9
Registered: April 2012
Location: Vietnam
Junior Member
Yes, that is it. About the indention.
How to dynamically change it?
Re: [Xpand] Dynamic position of generated text [message #843759 is a reply to message #843753] Fri, 13 April 2012 10:38 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6485
Registered: July 2009
Senior Member
Use a post processor/ beautifier
Re: [Xpand] Dynamic position of generated text [message #843763 is a reply to message #843759] Fri, 13 April 2012 10:46 Go to previous messageGo to next message
Hai Le is currently offline Hai LeFriend
Messages: 9
Registered: April 2012
Location: Vietnam
Junior Member
I already got a beautifer (to remove some empty lines, replace some characters...), but could you please be more precise on this usecase?
Re: [Xpand] Dynamic position of generated text [message #843767 is a reply to message #843763] Fri, 13 April 2012 10:49 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6485
Registered: July 2009
Senior Member
Did you read the docs?
Re: [Xpand] Dynamic position of generated text [message #843768 is a reply to message #843767] Fri, 13 April 2012 10:52 Go to previous message
Hai Le is currently offline Hai LeFriend
Messages: 9
Registered: April 2012
Location: Vietnam
Junior Member
Ah thanks Christian, I got an idea and try to implement in my current beautifer.
Previous Topic:Acceleo xmi to java
Next Topic:[Acceleo] Class not found in invoke()
Goto Forum:
  


Current Time: Sun Nov 23 11:14:11 GMT 2014

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

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