Cross Reference handling in Inferrer [message #1753339] |
Sat, 04 February 2017 06:27 |
Akira Tanaka Messages: 98 Registered: March 2010 |
Member |
|
|
Hello again,
I have created a sample dsl for my question. I created two types of Property, one using cross-reference and the other using JvmTypeReference.
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.xbase.Xbase
generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"
Model:
objects += Object*;
Object:
EntityObject | StringObject;
EntityObject:
'entity' name=ValidID '{'
properties += Property*
'}';
Property:
PropertyTypeA | PropertyTypeB;
PropertyTypeA:
'property_a' name=ValidID ':' type=[Object|ValidID];
PropertyTypeB:
'property_b' name=ValidID ':' type=JvmTypeReference;
StringObject:
'string' name=ValidID body=XBlockExpression;
In the standard Domainmodel example, most of the types are specified as JvmTypeReference. IJvmModelInferrer may be simple or standard. However, when it comes to content-assist in the generated editor, it provides too many choices (see TypeB attached).
We would rather prefer to use TypeA Property so that we can get better content-assist in the generated editor (see TypeA, attached). However, I was not successful to make this work with IJvmModelInferrer.
Code for mapping EntityObject follows.
def dispatch void infer(EntityObject element, IJvmDeclaredTypeAcceptor acceptor, boolean isPreIndexingPhase) {
acceptor.accept(element.toClass(element.name)) [
for (property : element.properties) {
if (property instanceof PropertyTypeB)
members += property.toField(property.name, property.type)
else
members += property.toField(property.name, /* what code should come here? */)
}
]
}
I tried to find a discussion similar to mine and found the following (I am not looking for ProposalProvider route).
[url= https://www.eclipse.org/forums/index.php/t/268675/]
It seems no resolution was made at that time. I tried several approaches but did not work as expected. I would appreciate any advice on this.
Akira
|
|
|
|
|
Re: Cross Reference handling in Inferrer [message #1753343 is a reply to message #1753342] |
Sat, 04 February 2017 08:59 |
|
e.g.
def dispatch void infer(EntityObject element, IJvmDeclaredTypeAcceptor acceptor, boolean isPreIndexingPhase) {
acceptor.accept(element.toClass(element.name)) [
for (property : element.properties) {
if (property instanceof PropertyTypeB)
members += property.toField(property.name, property.type)
else if (property instanceof PropertyTypeA){
val String name = property.type?.name
if (name !== null) {
members += property.toField(property.name, name.typeRef)
}
}
}
]
}
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
Powered by
FUDForum. Page generated in 0.03492 seconds