| [Xpand] Dynamic position of generated text [message #843658] |
Fri, 13 April 2012 04:46  |
Hai Le 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 #843730 is a reply to message #843704] |
Fri, 13 April 2012 06:07   |
Hai Le 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 06:08] Report message to a moderator
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.09116 seconds