Resolving proxies for Java types fails when model is loaded externally [message #1209039] |
Mon, 25 November 2013 09:56 |
Till F. Messages: 58 Registered: August 2012 |
Member |
|
|
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 16:48] Report message to a moderator
|
|
|
Re: Resolving proxies for Java types fails when model is loaded externally [message #1209523 is a reply to message #1209039] |
Mon, 25 November 2013 15:08 |
Till F. Messages: 58 Registered: August 2012 |
Member |
|
|
Hi,
I think I was able to narrow down the problem to the fact that in the case I load the model from elsewhere, IJvmTypeProvider is a "NullJdtTypeProvider". When loaded by the Xtext editor, it is a "JdtTypeProvider" (without "Null"). Thus I assume that IJvmTypeProvider.Factory is not bound as needed in the former case.
Essentially, this can be found in the abstract RuntimeModule of my language:
// contributed by org.eclipse.xtext.generator.types.TypesGeneratorFragment
public Class<? extends org.eclipse.xtext.common.types.access.IJvmTypeProvider.Factory> bindIJvmTypeProvider$Factory() {
return org.eclipse.xtext.common.types.access.ClasspathTypeProviderFactory.class;
}
and this is how it is bound in the UIModule:
public Class<? extends org.eclipse.xtext.common.types.access.IJvmTypeProvider.Factory> bindIJvmTypeProvider$Factory()
{
return org.eclipse.xtext.common.types.access.jdt.JdtTypeProviderFactory.class;
}
Unfortunately, just copying this into my RuntimeModule doesn't work. How can I get a working IJvmTypeProvider outside the UIModule? Or what am I doing wrong when loading the model?
[Updated on: Tue, 26 November 2013 10:14] Report message to a moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03176 seconds