use the importURI mechanism to incude an ecore model [message #875280] |
Tue, 22 May 2012 09:13  |
Eclipse User |
|
|
|
Hi all!
I was wondering whether it is possible to use the importURI mechanism to include an ecore model?
And if it is possible, what do I need to customize in order to export all elements contained in the ecore resource?
To explain more, this is an example of the editor I want to have:
import "A.ecore" as ecore
Foreach i in ecore.Class1ofA
[...]
And I would like to have by autocompletion all EClasses of the model I imported!
The grammer I have is:
Model:
elements+=Element*;
Element:
(g+=Import)+ f=Foreach
;
Import:
'import' importURI=STRING 'as'name=ID
;
Foreach:
'Foreach' name=ID 'in' table=Table
;
Table:
ecoreTypes=[Import]'.'class=???
;
Do you have any idea ?
Thanks a lot!
|
|
|
|
|
|
Re: use the importURI mechanism to incude an ecore model [message #882438 is a reply to message #876014] |
Wed, 06 June 2012 09:12   |
Eclipse User |
|
|
|
Hi,
I developped the grammer and the scope class. Now, I have another problem : it seems that there are ambiguities between rules (rule Fonction and rule Variable) while using autocompletion, and I don't know how to resolve that.
This is my grammar : (In the Foreach rule, we can call Variable rule or Fonction rule.)
import "..." as ecore
generate ...
Model:
im=Import
(elements+=Template_file)*;
Import:
'import' package=[ecore::EPackage|STRING]
;
Template_file:
Foreach
;
Foreach:
'Foreach' name=ID 'in' table=Create_table
(tpl+=(Variable|Fonction))+
'EndForeach'
;
Create_table:
sgbd=SGBD_Querry | fct=Fonction
;
SGBD_Querry:
'SELECT * FROM' class=[ecore::EClass| ID]
;
Variable:
'$' foreach=[Foreach] '.' attribut=[ecore::EAttribute|ID]
;
Fonction:
'$' field=[ecore::EClass |ID] '.' Operation=[ecore::EOperation |ID] '(' (parametres+=ID (',' parametres+=ID)*)* ');'
;
And the scope class is:
public class Test1ScopeProvider extends AbstractDeclarativeScopeProvider {
public IScope scope_Import_package(Import context, EReference reference) {
IScope result = new FilteringScope(delegateGetScope(context, reference), new Predicate<IEObjectDescription>() {
@Override
public boolean apply(IEObjectDescription input) {
String isNSURI = input.getUserData("nsURI");
return "true".equals(isNSURI);
}
});
return result;
}
public IScope scope_SGBD_Querry_class(Model context, EReference reference) {
return Scopes.scopeFor(EcoreUtil2.getAllContentsOfType(context.getIm().getPackage(), EClass.class));
}
public IScope scope_Variable_attribut(Variable context,EReference reference){
return Scopes.scopeFor(EcoreUtil2.getAllContentsOfType(context.getForeach().getTable().getSgbd().getClass_(), EAttribute.class));
}
public IScope scope_Fonction_field(Model context,EReference reference ){
// I return only classes that have EOperations as children
ArrayList<EObject> result= new ArrayList<EObject>();
java.util.List<EClass> allClasses=EcoreUtil2.getAllContentsOfType(context.getIm().getPackage(), EClass.class);
int i =0;
while(i<allClasses.size()){
EObject classe=allClasses.get(i);
List<EOperation> allOperations= EcoreUtil2.getAllContentsOfType(classe,EOperation.class);
if(!allOperations.isEmpty()){
result.add(classe);
}
i++;
}
return Scopes.scopeFor(result);
}
public IScope scope_Fonction_Operation(Fonction context,EReference reference ){
return Scopes.scopeFor(EcoreUtil2.getAllContentsOfType(context.getField(), EOperation.class));
}
}
I don't have problems of compilation, but when I instantiate the editor, autocompletion tool gives wrong propositions!!
This is an example of the ecore models I use : (I can't post images,so this is the textual representation of the model)
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0"
xmlns:xmi="..." xmlns:xsi="..."
xmlns:ecore="..." name="MyPackage"
nsURI="..." nsPrefix="">
<eClassifiers xsi:type="ecore:EClass" name="Class1">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="Att1"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="Att2"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="class2">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="Att" defaultValueLiteral=""/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Operation">
<eOperations name="operation1"/>
<eOperations name="operation2"/>
</eClassifiers>
</ecore:EPackage>
And this what I have in the editor:
import "..."
Foreach i in SELECT * FROM Class1
$i.Att1 //Nothing was proposed after $i. so I wrote the name of the attribute
//Autocompletion proposes here $ or ( !!!
$Operation. //Nothing is proposed !!!
EndForeach
Have you an idea of the problem?
Thanks
Asma
[Updated on: Wed, 06 June 2012 09:15] by Moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.04716 seconds