Xbase + Inferrer in Eclipse Editor [message #1123549] |
Wed, 02 October 2013 17:34 |
Roman Silencio 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
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03177 seconds