JvmModelInferrer and InferredTypes [message #1022422] |
Thu, 21 March 2013 21:01 |
|
Hi,
i a playing around with xbase' new typesystem.
here is my grammar
Model:
elements+=Element*;
Element:
"field" name=ID "=" init=XExpression;
I want to create a javabean out of this. here is my inferrer
class MyDslJvmModelInferrer extends AbstractModelInferrer {
@Inject extension JvmTypesBuilder
@Inject extension TypeReferences
def dispatch void infer(Model model, IJvmDeclaredTypeAcceptor acceptor, boolean isPreIndexingPhase) {
acceptor.accept(model.toClass("my.company.greeting.MyGreetings"))
.initializeLater([
for (e : model.elements.filter(x|x.name != null && x.init != null)) {
val f = e.toField(e.name, inferredType) [
initializer = e.init
]
members += f
members += e.toGetter(e.name, inferredType(e.init))
members += e.toSetter(e.name, inferredType(e.init))
}
])
}
}
somehow the inferring is not working
field xxxx = "aaaa"
@SuppressWarnings("all")
public class MyGreetings {
private String xxxx = "aaaa";
public Object getXxxx() {
return this.xxxx;
}
public void setXxxx(final String xxxx) {
this.xxxx = xxxx;
}
}
what am i missing?
another question is: can i use an inferred type without
actually reusing the xexpression the inferrer
(e.g. leave out initializer = e.init)
val f = e.toField(e.name, inferredType(e.init)) []
members += f
members += e.toGetter(e.name, inferredType(e.init))
members += e.toSetter(e.name, inferredType(e.init))
this gives me
Cannot infer type from recursive usage. Type 'Object' is used.
or should i use a "typeprovider" diectly in this case. if so what would be the replacement for the deprecated old one.
Thanks
Christian
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
Re: JvmModelInferrer and InferredTypes [message #1022776 is a reply to message #1022422] |
Fri, 22 March 2013 13:54 |
Sebastian Zarnekow Messages: 3118 Registered: July 2009 |
Senior Member |
|
|
Hi Christian,
there is no API for that purpose available yet, but you could try to use
the type of the field itself, e.g. this inferrer works for me:
@Inject extension JvmTypesBuilder
def dispatch void infer(Model model, IJvmDeclaredTypeAcceptor acceptor,
boolean isPreIndexingPhase) {
acceptor.accept(model.toClass("my.company.greeting.MyGreetings")).initializeLater(
[
for (e : model.elements.filter(x|x.name != null && x.init != null)) {
val f = e.toField(e.name, inferredType(e.init)) [
initializer = e.init
]
members += f
members += e.toGetter(e.name, f.type)
members += e.toSetter(e.name, f.type)
}
])
}
Regarding your second question: No, currently it's not easily possible
to have an inferred type without an associated expression, though we
definitely want to support that. The API as is is still rough and not
yet settled though your feedback is very valuable to use. Could you
collect that in a bugzilla ticket? We want to improve on that for all
Xbase clients until the bundles are sealed for the Kepler release.
Best regards,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Go visit: http://xtext.itemis.com
Am 21.03.13 22:01, schrieb Christian Dietrich:
> Hi,
>
> i a playing around with xbase' new typesystem.
>
> here is my grammar
>
>
> Model:
> elements+=Element*;
>
> Element:
> "field" name=ID "=" init=XExpression;
>
> I want to create a javabean out of this. here is my inferrer
>
>
> class MyDslJvmModelInferrer extends AbstractModelInferrer {
>
> @Inject extension JvmTypesBuilder
> @Inject extension TypeReferences
>
>
>
> def dispatch void infer(Model model, IJvmDeclaredTypeAcceptor
> acceptor, boolean isPreIndexingPhase) {
>
> acceptor.accept(model.toClass("my.company.greeting.MyGreetings"))
> .initializeLater([
> for (e : model.elements.filter(x|x.name != null &&
> x.init != null)) {
> val f = e.toField(e.name, inferredType) [
> initializer = e.init
> ]
> members += f
> members += e.toGetter(e.name, inferredType(e.init))
> members += e.toSetter(e.name, inferredType(e.init))
>
>
> }
> ])
> }
> }
>
>
>
> somehow the inferring is not working
>
> field xxxx = "aaaa"
>
> @SuppressWarnings("all")
> public class MyGreetings {
> private String xxxx = "aaaa";
>
> public Object getXxxx() {
> return this.xxxx;
> }
>
> public void setXxxx(final String xxxx) {
> this.xxxx = xxxx;
> }
> }
>
>
> what am i missing?
>
> another question is: can i use an inferred type without actually reusing
> the xexpression the inferrer
> (e.g. leave out initializer = e.init)
>
> val f = e.toField(e.name, inferredType(e.init)) []
> members += f
> members += e.toGetter(e.name, inferredType(e.init))
> members += e.toSetter(e.name, inferredType(e.init))
> this gives me
>
> Cannot infer type from recursive usage. Type 'Object' is used.
> or should i use a "typeprovider" diectly in this case. if so what would
> be the replacement for the deprecated old one.
>
> Thanks
> Christian
>
|
|
|
Powered by
FUDForum. Page generated in 0.03066 seconds