|
|
|
|
|
Re: how to get access to global scope inside a AbstractDeclarativeScopeProvider method? [message #895692 is a reply to message #895604] |
Sun, 15 July 2012 03:43 |
Cristiano Gavião Messages: 279 Registered: July 2009 |
Senior Member |
|
|
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 16:22 |
Cristiano Gavião Messages: 279 Registered: July 2009 |
Senior Member |
|
|
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.02985 seconds