[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.modeling.tmf] Re: Domain model example: Proposal with entity attributes

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.getContents().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