Home » Modeling » TMF (Xtext) » [XBase] Corss-referencing function definitions
| |
Re: [XBase] Corss-referencing function definitions [message #1396290 is a reply to message #1395957] |
Tue, 08 July 2014 01:14   |
Eclipse User |
|
|
|
Hi Lorenzo,
Thanks for responding. In the function below, the call to "getBooksInLibrary(library)" doesn't seem to work. Similar to getBook, getBooksInLibrary is a function definition.
In the model inferrer [2], I have mapped to a Java class, and the function is mapped to a Java function. This allows me to do something like new getBooksInLibrary().getBooksInLibrary(library), however, this is not what I need.
In short, the method getBooksInLibrary() should show up when I perform content-assist in the method getBook.
function getBook (Library library, String bookName) : Book {
for(Book book : getBooksInLibrary(library)) { // Cross-referencing getBooksInLibrary()
if (book.name.equals(bookName)) {
return book;
}
}
return null
}
[Updated on: Tue, 08 July 2014 01:29] by Moderator
|
|
|
Re: [XBase] Corss-referencing function definitions [message #1396378 is a reply to message #1396290] |
Tue, 08 July 2014 04:08   |
Eclipse User |
|
|
|
On 08/07/2014 07:14, Neeraj Bhusare wrote:
> Hi Lorenzo,
>
> Thanks for responding. In the function below, the call to
> "getBooksInLibrary(library)" doesn't seem to work. Similar to getBook,
> getBooksInLibrary is a function definition.
> In the model inferrer [2], I have mapped to a Java class, and the
> function is mapped to a Java function. I believe I have done it correctly.
>
> function getBook (Library library, String bookName) : Book {
> for(Book book : getBooksInLibrary(library)) { // Cross-referencing
> getBooksInLibrary() if (book.name.equals(bookName)) {
> return book; } } return null }
mh... but are Library and Book types visible in your test program? Are
they imported?
--
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
|
|
| |
Re: [XBase] Corss-referencing function definitions [message #1397774 is a reply to message #1396290] |
Thu, 10 July 2014 02:28  |
Eclipse User |
|
|
|
On 08/07/2014 07:14, Neeraj Bhusare wrote:
> Hi Lorenzo,
>
> Thanks for responding. In the function below, the call to
> "getBooksInLibrary(library)" doesn't seem to work. Similar to getBook,
> getBooksInLibrary is a function definition.
> In the model inferrer [2], I have mapped to a Java class, and the
> function is mapped to a Java function. I believe I have done it correctly.
>
> function getBook (Library library, String bookName) : Book {
> for(Book book : getBooksInLibrary(library)) { // Cross-referencing
> getBooksInLibrary() if (book.name.equals(bookName)) {
> return book; } } return null }
Hi
I've just noted that in your function dsl
https://github.com/nbhusare/XBase-test/blob/master/org.xtext.example.function/src/org/xtext/example/function/FunctionDsl.xtext
you can define a single function in a FunctionModel
each function is inferred as a method inside an inferred class, thus
from a function you can't simply access another function (because that
corresponds to a method in another class); you should create an instance
of the inferred class...
so you probably need to customize the scoping...
you might also have to rethink your design... first of all, since these
functions should be callable without an object you might want to infer
them as static methods. After that it could probably be enough to make
all the inferred classes available as implicit imports.
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
|
|
|
Goto Forum:
Current Time: Wed Jul 23 13:42:53 EDT 2025
Powered by FUDForum. Page generated in 0.03718 seconds
|