Combining Importing scope and a local scope [message #1699296] |
Tue, 23 June 2015 09:41 |
Eleanor Richie Messages: 125 Registered: August 2014 |
Senior Member |
|
|
Hi,
I have a language that allows something like this:
package pack{
field foo1
field foo2
}
definitions def {
field fox1
field fox2
}
use MyFile.pack.all; //It means that ALL the fields in the package pack are included in the coming expression.
expression using def //After the using I have a cross-reference with the definitions
{
field expField
ref fox1
ref foo1
ref expField
}
---------------------------------------------------------------
I override the method internalGetImportedNamespaceResolvers so that it can resolve the fields in the package and it worked. Then I followed this example to https://github.com/LorenzoBettini/xtext-scoping/blob/master/org.xtext.example.helloscoping/org.xtext.example.helloscoping/src/org/xtext/example/helloscoping/scoping/HelloScopingScopeProvider.java to add the fields in the used definition scope to the expression and it worked but then I found that the work I had done for the package to be included is no longer working.
Here is my implementation for getscope:
@Override
public IScope getScope(EObject context, EReference reference) {
if (context == null) {
throw new NullPointerException("context");
}
IScope result = null;
if (context instanceof FieldReference){
FieldReference fieldReference = (FieldReference) context;
Expression exp= (Expression) fieldReference.eContainer();
if(exp== null || exp.getUsedDefinition() == null) {
return IScope.NULLSCOPE;
}
IScope parentScope = Scopes.scopeFor(exp.getUsedDefinition().getFields(), IScope.NULLSCOPE);
return Scopes.scopeFor(exp.getFields(), parentScope);
}
else if (!(context instanceof Model)) {
result = getScope(context.eContainer(), reference);
}
else {
result = getResourceScope(context.eResource(), reference);
}
return getLocalElementsScope(result, context, reference);
}
----------------------------------------------------------------
All I want is like combining the scope of the definition, expression and the used package in a single scope for the expression. Any Help Please?
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: Combining Importing scope and a local scope [message #1699512 is a reply to message #1699503] |
Wed, 24 June 2015 16:46 |
|
(1)
you have to remove fragment = types.TypesGeneratorFragment auto-inject {} as well
(2)
then your multi file extension stuff does not seem to work
change the workflow to
var fileExtensions = "p4,jmod"
and merge plugin.xml and plugin.xml_gen
(3)
reenable global scope in the scope provider
def IScope scope_Field_declaration(Field context, EReference reference) {
val view = EcoreUtil2.getRootContainer(context) as View;
new SimpleScope(delegateGetScope(context, reference), Scopes.scopedElementsFor(view.fields), true)
}
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: Combining Importing scope and a local scope [message #1699686 is a reply to message #1699679] |
Thu, 25 June 2015 19:38 |
|
if it is a java project and the lib jar is on the classpath you can do
import "classpath:/lib/test.mydsl" explicitely or implicitely
public class MyDslImportUriGlobalScopeProvider extends
ImportUriGlobalScopeProvider {
@Override
protected LinkedHashSet<URI> getImportedUris(Resource resource) {
LinkedHashSet<URI> importedUris = super.getImportedUris(resource);
importedUris.add(URI.createURI("classpath:/lib/test.mydsl"));
return importedUris;
}
}
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
Powered by
FUDForum. Page generated in 0.08607 seconds