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  |
Eclipse User |
|
|
|
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 #484138 is a reply to message #483878] |
Fri, 04 September 2009 08:25   |
Eclipse User |
|
|
|
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 #485121 is a reply to message #485101] |
Thu, 10 September 2009 10:49   |
Eclipse User |
|
|
|
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 #486280 is a reply to message #485834] |
Thu, 17 September 2009 03:02   |
Eclipse User |
|
|
|
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   |
Eclipse User |
|
|
|
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  |
Eclipse User |
|
|
|
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
|
|
|
Goto Forum:
Current Time: Sat Sep 20 06:37:10 EDT 2025
Powered by FUDForum. Page generated in 0.07905 seconds
|