Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xbase + Inferrer in Eclipse Editor
Xbase + Inferrer in Eclipse Editor [message #1123549] Wed, 02 October 2013 17:34 Go to next message
Roman Silencio is currently offline Roman SilencioFriend
Messages: 3
Registered: October 2013
Junior Member
Hello

I am trying a simple Xbase example, but it wont work in Eclipse.

First, i am creating a Xtext Project with Eclipse (4.3), removing the greeting example and using this grammar:
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.xbase.Xbase

generate myDsl "h__p://www.xtext.org/example/mydsl/MyDsl"

SomeModel :
   'test' ':' expressionValue = XExpression
;


After generating everything, i am adding the following code to the inferrer:
class MyDslJvmModelInferrer extends AbstractModelInferrer {

   @Inject extension JvmTypesBuilder

   def dispatch void infer(SomeModel element, IJvmDeclaredTypeAcceptor acceptor, boolean isPreIndexingPhase) {
      // assuming:  test: 1 + 1
      val returnType = element.newTypeRef(Integer.TYPE)
      acceptor.accept(element.toClass("ClassName")).initializeLater [
         documentation = element.documentation;
         members += element.toMethod("method", returnType) [
            body = element.expressionValue
         ]
      ]
   }
}


Finally, adding some UnitTest
@RunWith (XtextRunner)
@InjectWith (MyDslInjectorProvider)
class TestInferrer {

   @Inject extension ParseHelper<SomeModel>
   @Inject extension ValidationTestHelper
   @Inject extension CompilationTestHelper // deps:  org.eclipse.xtext.xbase.junit / org.eclipse.jdt.core


   @Test
   def void test() {''' test : 1 + 1'''.parse.assertNoErrors}

   @Test
   def javaGen() {
      '''test : 1 + 1'''
      .compile[
         print (generatedCode)
         compiledClass
      ]
   }
}


So far, everthing works as expected. The output from the print is also as expected:
{ClassName=@SuppressWarnings("all")
public class ClassName {
  public int method() {
    int _plus = (1 + 1);
    return _plus;
  }
}
}


Now i want to test the grammar in the Eclipse Editor, so starting Eclipse, creating a new file and adding the test code. But now i am getting this error:
The method +(int) is undefined

Well. Adding the xbase.jar to the project removes the error, but this cannot be the solution. Also jumping with F3 on the '+'-Sign works goining to the IntegerExtension. Cleaning out the Method body of the infer Method and the error also disappears.

I have no idea what could be wrong.
Maybe anybody has a hint.

Thanks in advance for any idea
Roman

Re: Xbase + Inferrer in Eclipse Editor [message #1123606 is a reply to message #1123549] Wed, 02 October 2013 18:58 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

it is intended that you have to put xbase.lib to the classpath of the model project.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xbase + Inferrer in Eclipse Editor [message #1123632 is a reply to message #1123606] Wed, 02 October 2013 19:32 Go to previous messageGo to next message
Roman Silencio is currently offline Roman SilencioFriend
Messages: 3
Registered: October 2013
Junior Member
Thanks for your fast reply.

Whats somehow strange to me is the reason, that the code works without any complaint as long as i dont use the + Operator.
for example
// works
test : 1
test : "string".toLowerCase.length
test : Integer.valueOf(1)
test : if (true) 1 else 2
// does not work
test : 1 + 1


So as long, as i am only using Methods its ok without the lib, even ifelse. The int + int Operation only works with the xbase lib around (same for Strings).
Re: Xbase + Inferrer in Eclipse Editor [message #1123636 is a reply to message #1123632] Wed, 02 October 2013 19:38 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
yes,

if you dont use any stuff from the lib you wont need it.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xbase + Inferrer in Eclipse Editor [message #1123658 is a reply to message #1123636] Wed, 02 October 2013 20:01 Go to previous messageGo to next message
Roman Silencio is currently offline Roman SilencioFriend
Messages: 3
Registered: October 2013
Junior Member
Thank you so far. That enought for me at the moment.

At the first glimpse, this involves xxxExtensions (String concat, Boolean Operations, etc..). I have to take a closer look at it some time. I thought things like (true || false) or ("asd" + "dsa") would not touch the xbase lib Extensions. So i was irritated that some Expressions worked and some others not.

Thanks again for your fast responses.
Re: Xbase + Inferrer in Eclipse Editor [message #1123664 is a reply to message #1123658] Wed, 02 October 2013 20:09 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

the clue is: Everything is api: even a simple + or ||


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Code Generator in java
Next Topic:Code generation error messages
Goto Forum:
  


Current Time: Wed Apr 24 14:21:43 GMT 2024

Powered by FUDForum. Page generated in 0.03177 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top