Resolving proxies for Java types fails when model is loaded externally [message #1209039] |
Mon, 25 November 2013 04:56  |
Eclipse User |
|
|
|
Hi,
certain proxies in my language cannot be resolved if I load my language from another plugin. This affects proxies for Java types only (e.g. JvmDeclaredType). Within the Xtext editor everything works fine (scoping, linking, proposals etc.). My setup is somewhat complex already, thus I'm trying to give you a brief summary of anything that should be related with the problem:
- My language uses importURI to "include" other language files
- This (importURI) is bricked, when the TypesGeneratorFragment is activated (because TypesAwareDefaultGlobalScopeProvider is used as IGlobalScopePriver then)
- But I also want to include Java types support. However, I don't need/want to use Xbase, since I have my own expressions, etc.
- ==> My solution was to
-> enable the new scoping and exporting API as well as the TypesGeneratorFragment (as if Xbase were used)
-> but override the binding of IGlobalScopeProvider so that ImportUriGlobalScopeProvider is still bound
-> and handle Java types manually using TypesAwareDefaultGlobalScopeProvider that is also bound in the RuntimeModule by myself
This has enabled mit to refer to any Java element in the environment by using grammer rules and a custom scope provider like below, but also leaves importURI intact.
PTSJavaImport:
'jimport' importedType=[JavaTypes::JvmGenericType|FULLQUALIFIEDNAME] ';'
;
PTSActualJElement:
{PTSActualJElement}
jElement=[JavaTypes::JvmIdentifiableElement|ID]
;
Scope Provider:
// PTSpecJavaScopeProvider derives from and uses members of TypesAwareDefaultGlobalScopeProvider
@Inject
private PTSpecJavaScopeProvider _pTSpecGlobalJavaScopeProvider;
public IScope scope_PTSJavaImport_importedType(PTSRoot root, EReference ref)
{
return _pTSpecGlobalJavaScopeProvider.getScope(root.eResource(), ref);
}
public IScope scope_PTSActualJElement_jElement(PTSContainer container, EReference ref)
{
// calculates scope (list of JvmIdentifiableElement) based on 'jimports' above
return _pTSpecGlobalJavaScopeProvider.getPTSpecJavaScope(container);
}
This however stops working if I load the language file from another plugin using the following code (i.e. references to Java elements are unresolved proxies; e.g. PTSJavaImport_importedType or PTSActualJElement_jElement).
public static PTSRoot loadFullPTSModel(URI platformResourceURI) throws IOException
{
ResourceSet emfResourceSet = new ResourceSetImpl();
Resource emfResource = emfResourceSet.getResource(platformResourceURI, true);
emfResource.load(null);
EcoreUtil.resolveAll(emfResourceSet);
EObject root = emfResource.getContents().get(0);
return (PTSRoot)root;
}
// above is called like this ("platform:/" URI is used)
IResource myFile;
URI ptsResourceURI = URI.createPlatformResourceURI(myFile.getFullPath().toString(), true);
PTSRoot root = PTSpecUtils.loadFullPTSModel(ptsResourceURI);
Surely I could check .eIsProxy() at corresponding places and try to get the JvmType using IJvmTypeProvider.findTypeByName(fqn) manually; but I think it shouldn't be necessary. What could be wrong with my setup above that resolving does not work automatically (and only when "used" from another plugin than the UIModule of my language)?
As already mentioned there are several other links to external resources that needs to be resolved as well (importURI related but also links to plain EMF models) - and in this case everything goes well irrespectively of how the model is loaded.
[Updated on: Mon, 25 November 2013 11:48] by Moderator
|
|
|
|
|
Re: Resolving proxies for Java types fails when model is loaded externally [message #1211169 is a reply to message #1210001] |
Tue, 26 November 2013 04:46  |
Eclipse User |
|
|
|
Hi Christian,
thanks for the info.
Actually, what I'm doing isn't "standalone"; I'm still in the eclipse environment. If I got you right you say that the RuntimeModule (main language plugin) is designed in a way that it can be used "standalone"? In this case I would have to rephrase my question: How can I programatically load my model in eclipse so that JvmType proxies are resolved (i.e. exactly like the Xtext editor does it)?
Cheers,
Till
|
|
|
Powered by
FUDForum. Page generated in 0.18112 seconds