Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Domain model example: Proposal with entity attributes
Domain model example: Proposal with entity attributes [message #482723] Thu, 27 August 2009 12:49 Go to next message
Eclipse UserFriend
Hi,

I am using the domain model example (which is delivered with TMF Xtext):


Model :
(elements+=AbstractElement)*;

AbstractElement : PackageDeclaration | Type | Import;

Type :
Entity | DataType;

DataType :
'datatype' name=ID;

Entity :
'entity' name=ID ('extends' superType=[Entity|QualifiedName])? '{'
(features+=Feature)*
'}';

Feature :
StructuralFeature | Operation;

StructuralFeature :
Attribute | Reference;

Attribute :
'attr' name=ID ':' type=TypeRef;


I am trying to define some references to entity attributes in another
Xtext grammar:

DataColumn:
'datacolumn' header=STRING dataColumn=[entityDsl::Attribute];

The generated editor doesn't show proposals for entity attributes
(dataColumn). It should list all attributes of existing entities.

Any ideas?
Thanks
ILyas
Re: Domain model example: Proposal with entity attributes [message #482800 is a reply to message #482723] Fri, 28 August 2009 00:35 Go to previous messageGo to next message
Eclipse UserFriend
In your referencing grammar. Do you import the model whose attributes are to be proposed? If not, how should the editor know where to look for possible proposals?
Re: Domain model example: Proposal with entity attributes [message #482821 is a reply to message #482800] Fri, 28 August 2009 04:58 Go to previous messageGo to next message
Eclipse UserFriend
My grammar imports the referencing grammar:

import 'http://www..../.../.../DomainModel' as entityDsl


I created a model with my entities and import this model in my concrete
referencing model to define references:

import
" platform:/resource/...entitydsl.generator/src/model/MyModel. entitydsl "


---


The grammar of the DomainModel looks like this Xtext example:
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.tmf/org .eclipse.xtext/examples/org.eclipse.xtext.example.domainmode l/src/org/eclipse/xtext/example/Domainmodel.xtext?root=Model ing_Project&view=markup

If I define references to PackageDeclarations proposals are shown. But
for attribute references proposals are not available! If you look at the
domain model grammar attributes are embedded in entities
(Model->AbstractElement->Type->Entity->Feature->StructuralFeature- >Attribute)
and PackageDeclarations can be defined directly
(Model->AbstractElement->PackageDeclaration). Can this be reason for not
shown attribute proposals?

Thanks
ILyas


Alexander Nittka schrieb:
> In your referencing grammar. Do you import the model whose attributes
> are to be proposed? If not, how should the editor know where to look for
> possible proposals?
Re: Domain model example: Proposal with entity attributes [message #483103 is a reply to message #482821] Mon, 31 August 2009 03:08 Go to previous messageGo to next message
Eclipse UserFriend
Hi Ilyas,

this cannot (or at least should not) be the cause for your problem. Please attach two sample models. If the proposals are not visible, your objects are most likely not contained in the scope for this cross reference.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com


Ilyas Keser wrote on Fri, 28 August 2009 04:58
My grammar imports the referencing grammar:

import 'http://www..../.../.../DomainModel' as entityDsl


I created a model with my entities and import this model in my concrete
referencing model to define references:

import
" platform:/resource/...entitydsl.generator/src/model/MyModel. entitydsl "


---


The grammar of the DomainModel looks like this Xtext example:
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.tmf/org .eclipse.xtext/examples/org.eclipse.xtext.example.domainmode l/src/org/eclipse/xtext/example/Domainmodel.xtext?root=Model ing_Project&view=markup

If I define references to PackageDeclarations proposals are shown. But
for attribute references proposals are not available! If you look at the
domain model grammar attributes are embedded in entities
(Model->AbstractElement->Type->Entity->Feature->StructuralFeature- >Attribute)
and PackageDeclarations can be defined directly
(Model->AbstractElement->PackageDeclaration). Can this be reason for not
shown attribute proposals?

Thanks
ILyas


Alexander Nittka schrieb:
> In your referencing grammar. Do you import the model whose attributes
> are to be proposed? If not, how should the editor know where to look for
> possible proposals?

Re: Domain model example: Proposal with entity attributes [message #483222 is a reply to message #483103] Mon, 31 August 2009 12:10 Go to previous messageGo to next message
Eclipse UserFriend
Hi Sebastian,

I think the problem is that my model contains two entities with same
attributes. So it is not possible for Xtext to create and show the
proposals for the attributes:

package test{
entity Customer {
attr name : java.lang.String
...
}

entity Contract {
attr name:java.lang.String
...
}
}

How can I create proposals like "test.Customer.name"? I tried to
override complete.._..() method in ..ProposalProvider. But, how can I
get the package and entity name of an attribute?

Thanks
ILyas


Sebastian Zarnekow schrieb:
> Hi Ilyas,
>
> this cannot (or at least should not) be the cause for your problem.
> Please attach two sample models. If the proposals are not visible, your
> objects are most likely not contained in the scope for this cross
> reference.
>
> Regards,
> Sebastian
Re: Domain model example: Proposal with entity attributes [message #483247 is a reply to message #483222] Mon, 31 August 2009 13:54 Go to previous messageGo to next message
Eclipse UserFriend
Hi Ilyas,

most likely you want to compute the name of scoped elements instead of
completion proposals. There is a utility class 'Scopes' that provides a
hook to customize the name of an EObject as it is available in a scope.

To navigate from an attribute to an entity and to the containing
package, you should try to use eContainer() and downcast the result.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Ilyas Keser schrieb:
> Hi Sebastian,
>
> I think the problem is that my model contains two entities with same
> attributes. So it is not possible for Xtext to create and show the
> proposals for the attributes:
>
> package test{
> entity Customer {
> attr name : java.lang.String
> ...
> }
>
> entity Contract {
> attr name:java.lang.String
> ...
> }
> }
>
> How can I create proposals like "test.Customer.name"? I tried to
> override complete.._..() method in ..ProposalProvider. But, how can I
> get the package and entity name of an attribute?
>
> Thanks
> ILyas
>
>
> Sebastian Zarnekow schrieb:
>> Hi Ilyas,
>>
>> this cannot (or at least should not) be the cause for your problem.
>> Please attach two sample models. If the proposals are not visible,
>> your objects are most likely not contained in the scope for this cross
>> reference.
>>
>> Regards,
>> Sebastian
Re: Domain model example: Proposal with entity attributes [message #483357 is a reply to message #483247] Tue, 01 September 2009 06:13 Go to previous messageGo to next message
Eclipse UserFriend
Hi Sebastian,

does it mean that I need to do following steps:

- implement own SimpleAttributeResolver

- use Google Guice to register this new class

Thanks
ILyas

Sebastian Zarnekow schrieb:
> Hi Ilyas,
>
> most likely you want to compute the name of scoped elements instead of
> completion proposals. There is a utility class 'Scopes' that provides a
> hook to customize the name of an EObject as it is available in a scope.
>
> To navigate from an attribute to an entity and to the containing
> package, you should try to use eContainer() and downcast the result.
>
> Regards,
> Sebastian
Re: Domain model example: Proposal with entity attributes [message #483386 is a reply to message #483357] Tue, 01 September 2009 08:27 Go to previous messageGo to next message
Eclipse UserFriend
Hi Ilyas,

you should implement a ScopeProvider and use your own algorithm to
compute the name of a scoped element if the type of the reference is
your eClass 'Attribute'. The class Scopes with #scopedElementsFor may be
useful.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Ilyas Keser schrieb:
> Hi Sebastian,
>
> does it mean that I need to do following steps:
>
> - implement own SimpleAttributeResolver
>
> - use Google Guice to register this new class
>
> Thanks
> ILyas
>
> Sebastian Zarnekow schrieb:
>> Hi Ilyas,
>>
>> most likely you want to compute the name of scoped elements instead of
>> completion proposals. There is a utility class 'Scopes' that provides
>> a hook to customize the name of an EObject as it is available in a scope.
>>
>> To navigate from an attribute to an entity and to the containing
>> package, you should try to use eContainer() and downcast the result.
>>
>> Regards,
>> Sebastian
Re: Domain model example: Proposal with entity attributes [message #483602 is a reply to message #483386] Wed, 02 September 2009 05:56 Go to previous messageGo to next message
Eclipse UserFriend
Hi Sebastian,

thanks for your answers. I am not sure about the steps which are requied
to solve my problem. In oAW Xtext it was for me simple with Xtend to
compute the name of the proposals. I read the section about the Scopes
in TMF Xtext User Guide again and tried to implement a ScopeProvider. In
my ScopeProvider I have following method:


public IScope getScope(EObject context, EReference reference) {

if (reference.getEType() == EntityDslPackage.eINSTANCE.getAttribute()) {
// TODO1: get all entity attributes
// TODO2: create a ScopedElement for every attribute

return IScope.NULLSCOPE;
}
return super.getScope(context, reference);
}

Is it OK if I get all entity attributes and create a scoped element for
every attribute? At this point, how can I get all entity attributes of
my imported entity model file?

---

To compute the name of a scoped element do I need to override
scopedElementsFor() of the class Scopes.

Sorry for asking so many questions.
Thanks
ILyas


Sebastian Zarnekow schrieb:
> Hi Ilyas,
>
> you should implement a ScopeProvider and use your own algorithm to
> compute the name of a scoped element if the type of the reference is
> your eClass 'Attribute'. The class Scopes with #scopedElementsFor may be
> useful.
>
> Regards,
> Sebastian
Re: Domain model example: Proposal with entity attributes [message #483641 is a reply to message #483602] Wed, 02 September 2009 08:32 Go to previous messageGo to next message
Eclipse UserFriend
Hi Ilyas,

please have a detailled look at the class Scopes. The method that you
are refering to is static and therefore could never be overridden. But
you may pass a function to it that will compute the name for your EObject.

Why did you choose to not use the declarative API of the ScopeProvider?

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Ilyas Keser schrieb:
> Hi Sebastian,
>
> thanks for your answers. I am not sure about the steps which are requied
> to solve my problem. In oAW Xtext it was for me simple with Xtend to
> compute the name of the proposals. I read the section about the Scopes
> in TMF Xtext User Guide again and tried to implement a ScopeProvider. In
> my ScopeProvider I have following method:
>
>
> public IScope getScope(EObject context, EReference reference) {
>
> if (reference.getEType() == EntityDslPackage.eINSTANCE.getAttribute()) {
> // TODO1: get all entity attributes
> // TODO2: create a ScopedElement for every attribute
>
> return IScope.NULLSCOPE;
> }
> return super.getScope(context, reference);
> }
>
> Is it OK if I get all entity attributes and create a scoped element for
> every attribute? At this point, how can I get all entity attributes of
> my imported entity model file?
>
> ---
>
> To compute the name of a scoped element do I need to override
> scopedElementsFor() of the class Scopes.
>
> Sorry for asking so many questions.
> Thanks
> ILyas
>
>
> Sebastian Zarnekow schrieb:
>> Hi Ilyas,
>>
>> you should implement a ScopeProvider and use your own algorithm to
>> compute the name of a scoped element if the type of the reference is
>> your eClass 'Attribute'. The class Scopes with #scopedElementsFor may
>> be useful.
>>
>> Regards,
>> Sebastian
Re: Domain model example: Proposal with entity attributes [message #483878 is a reply to message #483641] Thu, 03 September 2009 09:03 Go to previous messageGo to next message
Eclipse UserFriend
Thanks for your help.

Below is the snippet where I use the declarative API and the class "Scopes". But I don't know how to get all the entity attributes which are imported from my entity model. I tried to use the context to get the attributes but without success?

public class GUIDSLScopeProvider extends AbstractDeclarativeScopeProvider {

public IScope scope_DataColumn_entityAttribute(DataColumn context, EReference reference){

if(reference.getEType() == EntityDslPackage.eINSTANCE.getAttribute()){

// TODO: get all entity attributes (declared in imported entity model)
Iterable<Attribute> attributes = null; // ???

Iterable<IScopedElement> scopedElements = Scopes.scopedElementsFor(attributes, new Function<EObject, String>() {
public String apply(EObject attr) {

//...
}
});

return new SimpleScope(IScope.NULLSCOPE, scopedElements);
}

return super.getScope(context, reference);
}
}


ILyas


Sebastian Zarnekow schrieb:
> Hi Ilyas,
>
> please have a detailled look at the class Scopes. The method that you
> are refering to is static and therefore could never be overridden. But
> you may pass a function to it that will compute the name for your EObject.
>
> Why did you choose to not use the declarative API of the ScopeProvider?
>
> Regards,
> Sebastian
Re: Domain model example: Proposal with entity attributes [message #484138 is a reply to message #483878] Fri, 04 September 2009 08:25 Go to previous messageGo to next message
Eclipse UserFriend
Hi Ilyas,

there is no utility function that directly does what you describe.
However, please search this newsgroup for ImportUri and ImportUriUtil
and you'll find some pointers that will help to achieve what you describe.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Ilyas Keser schrieb:
> Thanks for your help.
>
> Below is the snippet where I use the declarative API and the class
> "Scopes". But I don't know how to get all the entity attributes which
> are imported from my entity model. I tried to use the context to get the
> attributes but without success?
>
> public class GUIDSLScopeProvider extends AbstractDeclarativeScopeProvider {
>
> public IScope scope_DataColumn_entityAttribute(DataColumn context,
> EReference reference){
>
> if(reference.getEType() == EntityDslPackage.eINSTANCE.getAttribute()){
>
> // TODO: get all entity attributes (declared in imported entity
> model)
> Iterable<Attribute> attributes = null; // ???
>
> Iterable<IScopedElement> scopedElements =
> Scopes.scopedElementsFor(attributes, new Function<EObject, String>() {
> public String apply(EObject attr) {
>
> //...
> }
> });
>
> return new SimpleScope(IScope.NULLSCOPE, scopedElements);
> }
>
> return super.getScope(context, reference);
> }
> }
>
>
> ILyas
>
>
> Sebastian Zarnekow schrieb:
>> Hi Ilyas,
>>
>> please have a detailled look at the class Scopes. The method that you
>> are refering to is static and therefore could never be overridden. But
>> you may pass a function to it that will compute the name for your
>> EObject.
>>
>> Why did you choose to not use the declarative API of the ScopeProvider?
>>
>> Regards,
>> Sebastian
>
>
Re: Domain model example: Proposal with entity attributes [message #484406 is a reply to message #484138] Mon, 07 September 2009 08:09 Go to previous messageGo to next message
Eclipse UserFriend
Hi Sebastian,

thanks for your help.
It works with ImportUriUtil.getResource().

Regards,
ILyas

Sebastian Zarnekow schrieb:
> Hi Ilyas,
>
> there is no utility function that directly does what you describe.
> However, please search this newsgroup for ImportUri and ImportUriUtil
> and you'll find some pointers that will help to achieve what you describe.
>
> Regards,
> Sebastian
Re: Domain model example: Proposal with entity attributes [message #485101 is a reply to message #484406] Thu, 10 September 2009 10:26 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

currently Scoping works :) and I can use QualifiedNames to define references to attributes of an entity, for example:

de.example.xtext.Customer.name

But if I try to run the code generator (MyDSLGenerator.mwe) the references to attributes can't be resolved:

ERROR eclipse.emf.mwe.core.WorkflowRunner .. "Couldn't resolve reference to Attribute".

In the template file (MyDSLTemplate.xpt), I can use the references for code generation without any problem.

Any ideas?
ILyas

Ilyas Keser schrieb:
> Hi Sebastian,
>
> thanks for your help.
> It works with ImportUriUtil.getResource().
>
> Regards,
> ILyas
>
> Sebastian Zarnekow schrieb:
>> Hi Ilyas,
>>
>> there is no utility function that directly does what you describe.
>> However, please search this newsgroup for ImportUri and ImportUriUtil
>> and you'll find some pointers that will help to achieve what you
>> describe.
>>
>> Regards,
>> Sebastian
Re: Domain model example: Proposal with entity attributes [message #485121 is a reply to message #485101] Thu, 10 September 2009 10:49 Go to previous messageGo to next message
Eclipse UserFriend
Hi Ilyas,

did you register every meta model in the standalonesetup bean of your
workflow? Did you refer the other genmodels in the workflow of your
language generator? Maybe you ended up with duplicate classes for one or
another Ecore model?

Hope that helps,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Ilyas Keser schrieb:
> Hi,
>
> currently Scoping works :) and I can use QualifiedNames to define
> references to attributes of an entity, for example:
>
> de.example.xtext.Customer.name
>
> But if I try to run the code generator (MyDSLGenerator.mwe) the
> references to attributes can't be resolved:
>
> ERROR eclipse.emf.mwe.core.WorkflowRunner .. "Couldn't resolve
> reference to Attribute".
>
> In the template file (MyDSLTemplate.xpt), I can use the references for
> code generation without any problem.
>
> Any ideas?
> ILyas
>
> Ilyas Keser schrieb:
>> Hi Sebastian,
>>
>> thanks for your help.
>> It works with ImportUriUtil.getResource().
>>
>> Regards,
>> ILyas
>>
>> Sebastian Zarnekow schrieb:
>>> Hi Ilyas,
>>>
>>> there is no utility function that directly does what you describe.
>>> However, please search this newsgroup for ImportUri and ImportUriUtil
>>> and you'll find some pointers that will help to achieve what you
>>> describe.
>>>
>>> Regards,
>>> Sebastian
Re: Domain model example: Proposal with entity attributes [message #485137 is a reply to message #485121] Thu, 10 September 2009 11:15 Go to previous messageGo to next message
Eclipse UserFriend
Hi Sebastian,

do I need to register every metamodel in the StandaloneSetup and refer other genmodels in my workflow if I use resource URIs to import existing EPackages?

My configuration of the workflow files is as follows:
- In my GUIDSL grammar I am using resource URIs and not namespace URIs to import existing metamodels: (I understand the documentation so that the registeration of metamodels in StandaloneSetup is only needed if you use namespace URIs?, http://www.eclipse.org/Xtext/documentation/0_7_2/xtext.html# UsingresourceURIstoimportexistingEPackages)
- GenerateGUIDSL.mwe: EPackages are not registered and EcoreGeneratorFragment refers to genmodels.
- GUIDSLGenerator.mwe: EPackages are not registered.

Thanks,
ILyas


Sebastian Zarnekow schrieb:
> Hi Ilyas,
>
> did you register every meta model in the standalonesetup bean of your
> workflow? Did you refer the other genmodels in the workflow of your
> language generator? Maybe you ended up with duplicate classes for one or
> another Ecore model?
>
> Hope that helps,
> Sebastian
Re: Domain model example: Proposal with entity attributes [message #485276 is a reply to message #485137] Fri, 11 September 2009 03:22 Go to previous messageGo to next message
Eclipse UserFriend
Hi Ilyas,

basically you'll have to register every references ecore metamodel in
the standalone setup. The type of your uris in your grammar has nothing
to do with the runtime or the fact that you have to register metamodels
in the standalone setup.
Please refer the EMF book to get used to the various EMF concepts.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Ilyas Keser schrieb:
> Hi Sebastian,
>
> do I need to register every metamodel in the StandaloneSetup and refer
> other genmodels in my workflow if I use resource URIs to import existing
> EPackages?
>
> My configuration of the workflow files is as follows:
> - In my GUIDSL grammar I am using resource URIs and not namespace
> URIs to import existing metamodels: (I understand the documentation so
> that the registeration of metamodels in StandaloneSetup is only needed
> if you use namespace URIs?,
> http://www.eclipse.org/Xtext/documentation/0_7_2/xtext.html# UsingresourceURIstoimportexistingEPackages)
>
> - GenerateGUIDSL.mwe: EPackages are not registered and
> EcoreGeneratorFragment refers to genmodels.
> - GUIDSLGenerator.mwe: EPackages are not registered.
>
> Thanks,
> ILyas
>
>
> Sebastian Zarnekow schrieb:
>> Hi Ilyas,
>>
>> did you register every meta model in the standalonesetup bean of your
>> workflow? Did you refer the other genmodels in the workflow of your
>> language generator? Maybe you ended up with duplicate classes for one
>> or another Ecore model?
>>
>> Hope that helps,
>> Sebastian
Re: Domain model example: Proposal with entity attributes [message #485834 is a reply to message #485276] Tue, 15 September 2009 05:06 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

in all workflows the standalone setup registers all used ecore metamodels. Additionally in workflows for language generation the EcoreGeneratorFragment refers to required genmodels. And language generation works for my all DSLs... But, if I try to run the MyDslGenerator.mwe the references to "Attributes" can't be resolved:

ERROR eclipse.emf.mwe.core.WorkflowRunner .. "Couldn't resolve reference to Attribute".

I am using a custom scoping to get a modified content assist for Attributes (for example: org.my.package.MyClass.myAttribute instead of myAttribute). Can this error be related with my custom scoping? Or do I need to modify the linking mechanism of Xtext. I don't really understand (out of the documentation) when a custom linking mechanism is needed.

Thanks,
ILyas



Sebastian Zarnekow schrieb:
> Hi Ilyas,
>
> basically you'll have to register every references ecore metamodel in
> the standalone setup. The type of your uris in your grammar has nothing
> to do with the runtime or the fact that you have to register metamodels
> in the standalone setup.
> Please refer the EMF book to get used to the various EMF concepts.
>
> Regards,
> Sebastian
Re: Domain model example: Proposal with entity attributes [message #486280 is a reply to message #485834] Thu, 17 September 2009 03:02 Go to previous messageGo to next message
Eclipse UserFriend
Hi Ilyas,

Indeed it looks like a reference in your model cannot be linked. Thus there is
probably a problem with your scope provider. Please provide more details
(grammar, scope provider implementation, and example) so we can help you
resolve the problem.

Regards,

--knut

Ilyas Keser wrote:
> Hi,
>
> in all workflows the standalone setup registers all used ecore
> metamodels. Additionally in workflows for language generation the
> EcoreGeneratorFragment refers to required genmodels. And language
> generation works for my all DSLs... But, if I try to run the
> MyDslGenerator.mwe the references to "Attributes" can't be resolved:
>
> ERROR eclipse.emf.mwe.core.WorkflowRunner .. "Couldn't resolve
> reference to Attribute".
> I am using a custom scoping to get a modified content assist for
> Attributes (for example: org.my.package.MyClass.myAttribute instead of
> myAttribute). Can this error be related with my custom scoping? Or do I
> need to modify the linking mechanism of Xtext. I don't really understand
> (out of the documentation) when a custom linking mechanism is needed.
> Thanks,
> ILyas
>
>
>
> Sebastian Zarnekow schrieb:
>> Hi Ilyas,
>>
>> basically you'll have to register every references ecore metamodel in
>> the standalone setup. The type of your uris in your grammar has
>> nothing to do with the runtime or the fact that you have to register
>> metamodels in the standalone setup.
>> Please refer the EMF book to get used to the various EMF concepts.
>>
>> Regards,
>> Sebastian
Re: Domain model example: Proposal with entity attributes [message #486323 is a reply to message #486280] Thu, 17 September 2009 05:21 Go to previous messageGo to next message
Eclipse UserFriend
Hi Knut,

thanks for your answer. In following I will try to provide more details:

The grammar GUIDSL defines references to EntityDsl. For example:

DataTable:
'datatable' name=ID value=[entityDsl::Attribute|QualifiedName] '{'
(dataColumns+=DataColumn)+
'}';

DataColumn:
'datacolumn' header=STRING value=[entityDsl::Attribute|QualifiedName];


---------------


Both EntityDsl and GUIDSL use a third grammar named Base(Grammar Mixing). For example QualifiedName is defined in Base:

QualifiedName :
ID ('.' ID)*;


---------------


Part of EntityDsl:

Package:
'package' name=QualifiedName '{'
(elements+=Package | elements+=Entity)*
'}';

Attribute:
'attr' (static?='static')? name=ID ':' type=TypeRef;

Operation:
'op' (visibility=Visibility)? name=ID'(' (parameters+=Parameter (',' parameters+=Parameter)*)? ')' ':' returnType=TypeRef;

Entity :
'entity' name=ID ('extends' superType=[Entity|QualifiedName])? '{'
(attributes+=Attribute)*
(operations+=Operation)*
'}';



-------------


And here is my ScopeProvider:

public class GUIDSLScopeProvider extends AbstractDeclarativeScopeProvider {

public IScope scope_DataColumn_value(DataColumn context, EReference reference){
return getEntityAttributesScope(context, reference);
}


public IScope getEntityAttributesScope(EObject context, EReference reference){

if(reference.getEType() == EntityDslPackage.eINSTANCE.getAttribute()){

// get imported entity model
Model model = (Model)EcoreUtil.getRootContainer(context);
Import imp = (Import)model.getImports().get(0);
Resource importedResource = ImportUriUtil.getResource(imp.eResource(), imp.getImportURI());
de.example.xtext.entityDsl.Model importedEntityModel = (de.example.xtext.entityDsl.Model)importedResource.getConten ts().get(0);

// get all attributes
Collection<Object> allElements = GUIDSLScopeProvider.iteratorToCollection(
EcoreUtil.getAllContents(importedEntityModel.getElements())) ;
Collection<Attribute> attributes = EcoreUtil.getObjectsByType(
allElements, EntityDslPackage.eINSTANCE.getAttribute());

// compute attribute names and create scoped elements
Iterable<IScopedElement> scopedElements = Scopes.scopedElementsFor(attributes, new Function<EObject, String>() {
public String apply(EObject from) {
Attribute attribute = (Attribute)from;
Entity entity = (Entity)attribute.eContainer();

// return "my.package.EntityName.attributeName" if the entity in a package
if(entity.eContainer() != null && entity.eContainer().eClass() == EntityDslPackage.eINSTANCE.getPackage()){
Package pack = (Package)entity.eContainer();
return (pack.getName() + "." + entity.getName() + "." + attribute.getName());
}
// return "EntityName.attributeName"
return (entity.getName() + "." + attribute.getName());
}
});

return new SimpleScope(IScope.NULLSCOPE, scopedElements);
}

return super.getScope(context, reference);
}

...
}


Thanks,
ILyas


Knut Wannheden schrieb:
> Hi Ilyas,
>
> Indeed it looks like a reference in your model cannot be linked. Thus
> there is probably a problem with your scope provider. Please provide
> more details (grammar, scope provider implementation, and example) so we
> can help you resolve the problem.
>
> Regards,
>
> --knut
>
> Ilyas Keser wrote:
>> Hi,
>>
>> in all workflows the standalone setup registers all used ecore
>> metamodels. Additionally in workflows for language generation the
>> EcoreGeneratorFragment refers to required genmodels. And language
>> generation works for my all DSLs... But, if I try to run the
>> MyDslGenerator.mwe the references to "Attributes" can't be resolved:
>>
>> ERROR eclipse.emf.mwe.core.WorkflowRunner .. "Couldn't resolve
>> reference to Attribute".
>> I am using a custom scoping to get a modified content assist for
>> Attributes (for example: org.my.package.MyClass.myAttribute instead of
>> myAttribute). Can this error be related with my custom scoping? Or do
>> I need to modify the linking mechanism of Xtext. I don't really
>> understand (out of the documentation) when a custom linking mechanism
>> is needed. Thanks,
>> ILyas
>>
>>
>>
>> Sebastian Zarnekow schrieb:
>>> Hi Ilyas,
>>>
>>> basically you'll have to register every references ecore metamodel in
>>> the standalone setup. The type of your uris in your grammar has
>>> nothing to do with the runtime or the fact that you have to register
>>> metamodels in the standalone setup.
>>> Please refer the EMF book to get used to the various EMF concepts.
>>>
>>> Regards,
>>> Sebastian
Re: Domain model example: Proposal with entity attributes [message #486359 is a reply to message #486323] Thu, 17 September 2009 08:23 Go to previous message
Eclipse UserFriend
Hi Ilyas,

Provided that your scope provider implementation declares an import for your
"Package" interface (otherwise java.lang.Package would be used which would
throw a ClassCastException!) and it also declares a method
scope_DataTable_value with the same implementation, I think this looks fine.

If you still have problems I suggest you report a Bugzilla issue and attach
all the grammars, scope providers, and examples required to reproduce the
problem.

Hope that helps,

--knut

Ilyas Keser wrote:
> Hi Knut,
>
> thanks for your answer. In following I will try to provide more details:
>
> The grammar GUIDSL defines references to EntityDsl. For example:
>
> DataTable:
> 'datatable' name=ID value=[entityDsl::Attribute|QualifiedName] '{'
> (dataColumns+=DataColumn)+ '}';
> DataColumn:
> 'datacolumn' header=STRING value=[entityDsl::Attribute|QualifiedName];
>
>
> ---------------
>
>
> Both EntityDsl and GUIDSL use a third grammar named Base(Grammar
> Mixing). For example QualifiedName is defined in Base:
>
> QualifiedName :
> ID ('.' ID)*;
>
>
> ---------------
>
>
> Part of EntityDsl:
>
> Package:
> 'package' name=QualifiedName '{'
> (elements+=Package | elements+=Entity)*
> '}';
>
> Attribute:
> 'attr' (static?='static')? name=ID ':' type=TypeRef;
>
> Operation:
> 'op' (visibility=Visibility)? name=ID'(' (parameters+=Parameter (','
> parameters+=Parameter)*)? ')' ':' returnType=TypeRef;
>
> Entity :
> 'entity' name=ID ('extends' superType=[Entity|QualifiedName])? '{'
> (attributes+=Attribute)*
> (operations+=Operation)*
> '}';
>
>
>
> -------------
>
>
> And here is my ScopeProvider:
>
> public class GUIDSLScopeProvider extends AbstractDeclarativeScopeProvider {
>
> public IScope scope_DataColumn_value(DataColumn context, EReference
> reference){
> return getEntityAttributesScope(context, reference);
> }
>
>
> public IScope getEntityAttributesScope(EObject context, EReference
> reference){
>
> if(reference.getEType() ==
> EntityDslPackage.eINSTANCE.getAttribute()){
>
> // get imported entity model
> Model model = (Model)EcoreUtil.getRootContainer(context);
> Import imp = (Import)model.getImports().get(0);
> Resource importedResource =
> ImportUriUtil.getResource(imp.eResource(), imp.getImportURI());
> de.example.xtext.entityDsl.Model importedEntityModel =
> (de.example.xtext.entityDsl.Model)importedResource.getConten ts().get(0);
>
> // get all attributes
> Collection<Object> allElements =
> GUIDSLScopeProvider.iteratorToCollection(
>
> EcoreUtil.getAllContents(importedEntityModel.getElements())) ;
> Collection<Attribute> attributes = EcoreUtil.getObjectsByType(
> allElements,
> EntityDslPackage.eINSTANCE.getAttribute());
>
> // compute attribute names and create scoped elements
> Iterable<IScopedElement> scopedElements =
> Scopes.scopedElementsFor(attributes, new Function<EObject, String>() {
> public String apply(EObject from) {
> Attribute attribute = (Attribute)from;
> Entity entity = (Entity)attribute.eContainer();
>
> // return "my.package.EntityName.attributeName" if
> the entity in a package
> if(entity.eContainer() != null &&
> entity.eContainer().eClass() == EntityDslPackage.eINSTANCE.getPackage()){
> Package pack = (Package)entity.eContainer();
> return (pack.getName() + "." + entity.getName()
> + "." + attribute.getName());
> }
> // return "EntityName.attributeName"
> return (entity.getName() + "." + attribute.getName());
> }
> });
>
> return new SimpleScope(IScope.NULLSCOPE, scopedElements);
> }
>
> return super.getScope(context, reference);
> }
>
> ...
> }
>
>
> Thanks,
> ILyas
>
>
> Knut Wannheden schrieb:
>> Hi Ilyas,
>>
>> Indeed it looks like a reference in your model cannot be linked. Thus
>> there is probably a problem with your scope provider. Please provide
>> more details (grammar, scope provider implementation, and example) so
>> we can help you resolve the problem.
>>
>> Regards,
>>
>> --knut
>>
>> Ilyas Keser wrote:
>>> Hi,
>>>
>>> in all workflows the standalone setup registers all used ecore
>>> metamodels. Additionally in workflows for language generation the
>>> EcoreGeneratorFragment refers to required genmodels. And language
>>> generation works for my all DSLs... But, if I try to run the
>>> MyDslGenerator.mwe the references to "Attributes" can't be resolved:
>>>
>>> ERROR eclipse.emf.mwe.core.WorkflowRunner .. "Couldn't resolve
>>> reference to Attribute".
>>> I am using a custom scoping to get a modified content assist for
>>> Attributes (for example: org.my.package.MyClass.myAttribute instead
>>> of myAttribute). Can this error be related with my custom scoping? Or
>>> do I need to modify the linking mechanism of Xtext. I don't really
>>> understand (out of the documentation) when a custom linking mechanism
>>> is needed. Thanks,
>>> ILyas
>>>
>>>
>>>
>>> Sebastian Zarnekow schrieb:
>>>> Hi Ilyas,
>>>>
>>>> basically you'll have to register every references ecore metamodel
>>>> in the standalone setup. The type of your uris in your grammar has
>>>> nothing to do with the runtime or the fact that you have to register
>>>> metamodels in the standalone setup.
>>>> Please refer the EMF book to get used to the various EMF concepts.
>>>>
>>>> Regards,
>>>> Sebastian
Previous Topic:Potential for deadlock in DefaultScopeProvider..
Next Topic:Problem: different languages are using the same packages in different projects!
Goto Forum:
  


Current Time: Sat Sep 20 04:49:29 EDT 2025

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

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

Back to the top