|
Re: Adding a Fake Resource (like Object in Java) [message #1106104 is a reply to message #1105940] |
Tue, 10 September 2013 17:53 |
|
On 10/09/2013 15:18, kamo cuvao wrote:
> Hello again!
>
> Recently I managed to add inheritance to my language, but I still have a
> problem:
>
> I need a "default" class from which all classes, which don't inherit
> other classes, are inherited (basically an Object class like in Java).
>
> I think I need two Parts to make this work:
> (1) Create a resource (with the Object class) and add it to a ResourceSet?
> (2) I need a "default reference" to the Object in any class, where no
> "extends" is present.
>
>
> To achieve (1) I tried to enhance my XtextResourceSet, but that didn't
> work:
>
> public class MyResourceSet extends XtextResourceSet {
> public MyResourceSet(){
> Resource resource =
> this.createResource(URI.createURI("fakepath://Object.tts"));
> Content cont = MyDslFactory.eINSTANCE.createContent();
> cont.setName("Object");
> resource.getContents().add(cont);
> this.getResources().add(resource);
> }
> }
>
>
> with
>
> public Class<? extends XtextResourceSet> bindXtextResourceSet() {
> return MyResourceSet.class;
> }
>
>
> To solve (2) I really have no clue how to do this.
>
> Thanks for your answers,
> Martin
>
Hi
I used to do that in one of my first Xtext experiments (FJ,
http://fj-eclipse.sourceforge.net/ ), you may want to see the sources
(though they were developed for Xtext 2.0).
In general though, it is not a good idea to do like that; it is much
better to provide a library for your DSL
(http://zarnekow.blogspot.de/2012/11/xtext-corner-8-libraries-are-key.html),
e.g., including Object.
In one of the examples (SmallJava) of my new book I deal with
inheritance and a library including Object (and how to consider a class
without any 'extends' as an implicit subclass of Object); the code of
the examples is available at
https://github.com/LorenzoBettini/packtpub-xtext-book-examples
hope this helps
cheers
Lorenzo
--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
Xtext Book:
http://www.packtpub.com/implementing-domain-specific-languages-with-xtext-and-xtend/book
HOME: http://www.lorenzobettini.it
TDD Book: https://leanpub.com/tdd-buildautomation-ci
Xtext Book: https://www.packtpub.com/application-development/implementing-domain-specific-languages-xtext-and-xtend-second-edition
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03364 seconds