Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Resolving proxies for Java types fails when model is loaded externally
Resolving proxies for Java types fails when model is loaded externally [message #1209039] Mon, 25 November 2013 09:56 Go to next message
Till Fischer is currently offline Till FischerFriend
Messages: 57
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 Go to previous messageGo to next message
Till Fischer is currently offline Till FischerFriend
Messages: 57
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

Re: Resolving proxies for Java types fails when model is loaded externally [message #1210001 is a reply to message #1209523] Mon, 25 November 2013 20:26 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6485
Registered: July 2009
Senior Member
Hi,

standalone you ususally use org.eclipse.xtext.common.types.access.impl.ClasspathTypeProvider
i doubt you get the jdtprovider running (needs a workspace with a javaproject etc)
Re: Resolving proxies for Java types fails when model is loaded externally [message #1211169 is a reply to message #1210001] Tue, 26 November 2013 09:46 Go to previous message
Till Fischer is currently offline Till FischerFriend
Messages: 57
Registered: August 2012
Member
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
Previous Topic:Call Formatter
Next Topic:Generator problems when using cross references in xtext
Goto Forum:
  


Current Time: Mon Nov 24 00:10:24 GMT 2014

Powered by FUDForum. Page generated in 0.02033 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software