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 05:14 |
Neeraj Bhusare Messages: 177 Registered: July 2009 Location: Canada |
Senior Member |
|
|
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
}
Twitter : @NeerajBhusare
Blog : https://nbhusare.github.io/
Best regards, Neeraj
[Updated on: Tue, 08 July 2014 05:29] Report message to a moderator
|
|
|
Re: [XBase] Corss-referencing function definitions [message #1396378 is a reply to message #1396290] |
Tue, 08 July 2014 08:08 |
|
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
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
|
|
| |
Re: [XBase] Corss-referencing function definitions [message #1397774 is a reply to message #1396290] |
Thu, 10 July 2014 06:28 |
|
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
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
|
|
|
Goto Forum:
Current Time: Thu Apr 18 09:35:20 GMT 2024
Powered by FUDForum. Page generated in 0.02434 seconds
|