Home » Modeling » TMF (Xtext) » Generating code from attributes in CSV
Generating code from attributes in CSV [message #1822231] |
Mon, 02 March 2020 08:46 |
Mohan Radhakrishnan Messages: 19 Registered: July 2009 |
Junior Member |
|
|
Hi,
I've looked at XText and XTend sample DSL's and executed in eclipse. Now I want to work with some CSV files that contain names of methods that generated code should use.
So, for example, this is the sample CSV.
Capital,,Capital,,,,,,,,,,,
Equity 1,,,equity1,,,,,,,,,,
Iinstruments,,,,capital,,,,,Currency,,,,
Premium,,,,premium,,,,,Currency,,,,
Earnings,,,,earnings,,,,,Currency,,,,
Can I create a DSL that generated code based on this ?
(e.g) Capital c = new Capital();
System.out.println( c.equity1().capital() );
System.out.println( c.equity1().premium() );
System.out.println( c.equity1().earnings() );
I can further enhance using using XTend if needed. I think. But XText is the part that deals with the DSL to handle this. Right ?
Thanks,
Mohan
|
|
| | | | | |
Re: Generating code from attributes in CSV [message #1822321 is a reply to message #1822308] |
Wed, 04 March 2020 02:45 |
Mohan Radhakrishnan Messages: 19 Registered: July 2009 |
Junior Member |
|
|
Hello Christian,
This was my original question.
So, for example, this is the sample CSV. I am led to believe that this doesn't need a DSL atleast at this time. These are the
steps I envisage. I am asking about Step 1 here. But if you have ideas about Step 2 you could share. I have the XTend domain
modeling book too.
Step 1 :
1. Create an XTend project.
2. Read CSV and use the tokens to create a template and generate code.
Step 2 :
1. If I need to really create a DSL from the CSV so that I can have some more semantics like
Hiberate validator code generated using XText and XTend I have to use both XText and XTend
Capital,,Capital,,,,,,,,,,,
Equity 1,,,equity1,,,,,,,,,,
Iinstruments,,,,capital,,,,,Currency,,,,
Premium,,,,premium,,,,,Currency,,,,
Earnings,,,,earnings,,,,,Currency,,,,
I want to generate code based on this.
(e.g) Capital c = new Capital();
System.out.println( c.equity1().capital() );
System.out.println( c.equity1().premium() );
System.out.println( c.equity1().earnings() );
|
|
| |
Re: Generating code from attributes in CSV [message #1822343 is a reply to message #1822326] |
Wed, 04 March 2020 13:56 |
Mohan Radhakrishnan Messages: 19 Registered: July 2009 |
Junior Member |
|
|
Capital,,Capital,,,,,,,,,,,
Equity 1,,,equity1,,,,,,,,,,
Iinstruments,,,,capital,,,,,Currency,,,,
Premium,,,,premium,,,,,Currency,,,,
Earnings,,,,earnings,,,,,Currency,,,,
The first line is the root POJO. Second line is the nested POJO. All other lines are 'getters' and 'setters'. Each such properly
returns a data type - int,long, double. Once I know how to use this I can add mocks and other testing techniques. That is what I think.
There is another CSV that contains the messages returned when a wrong data type is used. These two CSV's will be used.
I thought in the next step if I have a DSL based on this CSV I could work directly with it.
|
|
| | | | |
Goto Forum:
Current Time: Thu Sep 26 02:45:09 GMT 2024
Powered by FUDForum. Page generated in 0.05429 seconds
|