how to get access to global scope inside a AbstractDeclarativeScopeProvider method? [message #895423] |
Thu, 12 July 2012 16:00  |
Eclipse User |
|
|
|
Hi,
I'm learn to deal with scope using this model:
Organization:
'Organization:'
'{'
'code' name=ID
'name' longname=STRING
('description' description=STRING)?
('Partnerships:' '{' partnerships+=Partnership* '}')?
'}';
Partnership:
'Partnership:'
'{'
'partner' company=[Organization|Fqn]
('agreement' agreement=STRING)?
'}'
;
I could try the ArithmeticsScopeProvider example:
@Override
public IScope getScope(EObject context, EReference reference) {
IScope scope = super.getScope(context, reference);
return new FilteringScope(scope,
new Predicate<IEObjectDescription>() {
public boolean apply(IEObjectDescription input) {
return input!=null && input.getName()!=null && input.getName().getSegmentCount()==1;
};
});
}
But what I want to know is how could I get access to global scope values inside a AbstractDeclarativeScopeProvider method like the one below. I can't call super.getscope() as in ArithmeticsScopeProvider because I will get a Stack exception. So how to know all Organizations discovered by xtext inside this method?:
IScope scope_Partnership_company(Organization context, EReference ref) {}
thanks for any tip.
regards,
Cristiano
|
|
|
|
|
|
|
Re: how to get access to global scope inside a AbstractDeclarativeScopeProvider method? [message #895692 is a reply to message #895604] |
Sat, 14 July 2012 23:43   |
Eclipse User |
|
|
|
Hi Christian,
I'm trying to do what you have suggested. I could load two resources using the same resourceSet.
The org1.organization has a dependency to org2.organization, but the link resolution is not working. I did some debugging and note that the value of company attribute is null, so the global scope seems not to be working in the test.
Should I activate something in the test? Could you point what I'm missing?
thanks
@InjectWith(typeof(OrganizationDslInjectorProvider))
@RunWith(typeof(XtextRunner))
/**
* Test
*/
class TestCompleteOrganizationModel {
@Inject
private ParseHelper<Organization> parser
@Inject
private Provider<XtextResourceSet> resourceSetProvider
@Inject
private IScopeProvider scopeProvider
private XtextResourceSet resourceSet
private Organization orgModel1
private Organization orgModel2
def parseTestFile (String name) {
val cl = Thread::currentThread().getContextClassLoader()
val in = cl.getResourceAsStream(name)
assertNotNull("Couldn't find the resource file in classpath.", in)
val uri = URI::createFileURI(name)
return parser.parse(in, uri, null, resourceSet);
}
@Before
def void before(){
resourceSet = resourceSetProvider.get
orgModel2 = parseTestFile("tests/data/org2.organization")
assertNotNull(orgModel2)
orgModel1 = parseTestFile("tests/data/org1.organization")
assertNotNull(orgModel1)
}
@Test
def void ensureOnlyExternalCompaniesProposalsForPartnerCompany(){
val partner = orgModel1.partnerships.head
assertNotNull(partner)
val reference = OrganizationDslPackage::eINSTANCE.partnership_Company
var scope = scopeProvider.getScope(partner, reference)
var list = scope.allElements
var actual = scope.allElements.map[name.toString].join(", ")
assertEquals("Org2Company", actual)
}
|
|
|
|
Re: how to get access to global scope inside a AbstractDeclarativeScopeProvider method? [message #895745 is a reply to message #895710] |
Sun, 15 July 2012 12:22  |
Eclipse User |
|
|
|
Hi Christian,
I could run the tests properly using the workaround stated in the latest bug comment, thanks. 
Now that my tests are running I would like to ask one more question about a strange behavior that I noted in the scope computing. I'm getting duplicated items when they come from the same current resource.
For example, this is the result for the test variable in the method below:
[systemAnalyst, javaProgrammer, Org1.systemAnalyst, Org1.javaProgrammer, Org2.systemAnalyst, Org2.javaProgrammer]
Repair the occurrence of systemAnalyst and javaProgrammer, with and without parent, that comes from the same resource.
why this happen? The Content Assist handle this properly, but it is curious.
public IScope scope_Worker_personRoles(Organization context,
EReference reference) {
IScope scope = delegateGetScope(context, reference);
final String orgNameToFix = context.getName();
String test = scope.getAllElements().toString();
return new FilteringScope(scope, new Predicate<IEObjectDescription>() {
public boolean apply(IEObjectDescription input) {
if (input != null
&& input.getEObjectOrProxy() instanceof BusinessRole
&& input.getEObjectOrProxy().eContainer() != null) {
return input.getEObjectOrProxy().eContainer().eGet(OrganizationDslPackage.eINSTANCE .getOrganization_Name()).equals(orgNameToFix);
}
return false;
};
});
}
BusinessRole:
'Role:'
'{'
'code' name=ID
'name' longname=STRING
'}';
Worker:
'Worker:'
'{'
'person' person=[Person]
('roles' '(' personRoles+=[BusinessRole] (',' personRoles+=[BusinessRole])* ')')?
'}';
|
|
|
Powered by
FUDForum. Page generated in 0.57990 seconds