Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [IJvmModelInferrer] Referencing not yet existing classes
[IJvmModelInferrer] Referencing not yet existing classes [message #1123300] Wed, 02 October 2013 12:16 Go to next message
Boris Brodski is currently offline Boris BrodskiFriend
Messages: 111
Registered: July 2009
Senior Member

I have Xtext grammar like

Entity: 'entity' name=ID ('extends' ext=[Entity])?;

Using IJvmModelInferrer I generate interfaces for each entity:

* Entity1 => interface IEntity1
* Entity2 => interface IEntity2

Now, if I extend Entity2 from Entity1 I want to extend generated interfaces as well:

* Entity1 => interface IEntity1
* Entity2 extends Entity1 => interface IEntity2 extends IEntity1

In order to infer Entity2 in this case I have to get JvmTypeReference for the IEntity1 interface. If the order of the generation is Entity1, Entity2 this isn't a problem. Inferring Entity2 first otherwise results in a problem, that IEntity1 doesn't exist yet.

Is there a standard way to use classes/interfaces, that doesn't yet exist?
(Besides using appender appending full qualified name of the class as string?)

Thank you in advice!

Re: [IJvmModelInferrer] Referencing not yet existing classes [message #1128058 is a reply to message #1123300] Mon, 07 October 2013 09:40 Go to previous message
Boris Brodski is currently offline Boris BrodskiFriend
Messages: 111
Registered: July 2009
Senior Member
Let me be more concrete:

When getting a reference to a not yet inferred class/interface, JvmTypesBuilder.newTypeRef() returns an instance of the JvmUnknownTypeReference class with the required canonical name saved in it. You can use this reference. This is fine, but it has at least following problems:

1. Adding such reference to the "superTypes" list of the class always produces "implements" no matter whether JvmUnknownTypeReference points to the class or interface. (There are currently no way to detect or set this)

2. No import manager get used making the generated code complex to test. Your test depends on the order of class inference. For example, you trying to get "interface A extends B". Then generated code imports B, if it was already inferred and doesn't import B using canonical name, if B wasn't inferred yet: "interface A extends org.eclipse.text.B".

Is there some workarounds? Especially to "1"?

Thank you!

Xtext 2.4.3
Previous Topic:Problem generating RCP with Xtext
Next Topic:FileNotFoundException when renaming a project
Goto Forum:

Current Time: Sat Jul 11 06:21:39 GMT 2020

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

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

Back to the top