Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Adding generated objects to the index
Adding generated objects to the index [message #1833861] Mon, 26 October 2020 14:11 Go to next message
Elie Richa is currently offline Elie RichaFriend
Messages: 72
Registered: February 2016
Member
Hello,

I'm trying to achieve a complex scenario with my Xtext language and couldn't find the info I was looking for in existing posts. So I'm creating a new post but feel free to point me to existing answers if I missed them.

I'm compiling my Xtext language in the following way:

1. Source files are parsed into an EMF object tree as usual
2. My Xtext generator compiles each object tree into a tree of simpler objects within the same language/metamodel
3. The generated object tree of each source file is serialized as XMI and an XMI traceability file is also serialized to link input objects to their corresponding output object(s).
4. A final resolution stage is run (I provided an additional BuilderParticipant). It loads each generated XMI file and converts references to the input object tree into references to the corresponding generated objects thanks to the traceability files.

I'm using this workflow to solve the typical problem of generating references in the output of a model transformation based on objects in the input.

Here are my questions:

a. Is this a good workflow? Is there a better way to do this with Xtext?

b. The serializations at step 3 are not strictly necessary, i.e. I don't need the files on disk. Would it be okay to generate resources in the same ResourceSet as the input sources, and have step 4 look them up in there without going through serialization to disk?

c. Is there a way to make objects generated by step 2 visible in the Xtext index and referenceable via qualified names in the input language? I feel this is similar to what Xbase does when the JVM model inferrer generates objects that are then referenceable from the input language. Digging a bit further it seems that the process is based on IDerivedStateComputer which gets called before indexing. Am I on the right track? How would I contribute generated objects to the index to make them referenceable? Would I associate the generated IEObjectDescriptions to the same IResourceDescription as the input file?

d. Since the objects generated at step 2 are within the same language, in theory I could serialize into the same Xtext concrete syntax. Would that help in making them visible in the index?

Thanks!

Elie


Elie Richa, Ph.D
Software Engineer, AdaCore
https://www.adacore.com
Re: Adding generated objects to the index [message #1833862 is a reply to message #1833861] Mon, 26 October 2020 14:14 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
hi, did you have a look at the concept of IDerivedStateComputer
http://xtextcasts.org/episodes/18-model-optimization

this is the ususal way to do such M2M in a proper way that also knows about indexing.
it is also used by Xbase/Xtend/JvmModelInferrer


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Mon, 26 October 2020 14:19]

Report message to a moderator

Re: Adding generated objects to the index [message #1833874 is a reply to message #1833862] Mon, 26 October 2020 17:11 Go to previous messageGo to next message
Elie Richa is currently offline Elie RichaFriend
Messages: 72
Registered: February 2016
Member
I hadn't investigated IDerivedStateComputer in detail yet. Thank you for the pointers!

From what I see in the Xbase/Xtend/JvmModelInferrer, generated objects get instantiated in the same resource, which is probably what gets them indexed later. Traceability information is stored in Adapters of resources. Deferred initializers are called if not preIndexingPhase and they rely on traceability information.

To reuse my existing logic, I feel I could do the following:

1. Generate objects in the IDerivedStateComputer in the same resource so they get indexed. Traceability information can go into an Adapter of the resource (even though it's stored as EObjects as well, but I don't want those to get indexed).
2. Still in the IDerivedStateComputer, if not preIndexingPhase, I can execute my existing resolution logic to to update references in the generated objects based on the traceability data.
3. My Xtext generator retrieves the generated object tree already computed by the IDerivedStateComputer and simply writes it to disk.

Some remaining questions:
a. When I'm called with preIndexingPhase = false, can I assume that derived state has already been computed for for all other resources with preIndexingPhase = true?
b. I see in JvmModelAssociator that the IJvmModelInferrer always gets called regardless of preIndexingPhase. Does it mean the output model gets generated twice? Or is there a mechanism in the inferrer to avoid re-generating output objects if there's already a mapping for an input object?

Thanks.

Elie


Elie Richa, Ph.D
Software Engineer, AdaCore
https://www.adacore.com
Re: Adding generated objects to the index [message #1833875 is a reply to message #1833874] Mon, 26 October 2020 17:45 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
i dont get the update references stuff.
if you can calculate the name you can use
SyntheticLinkingSupport to create the same proxies
Xtext creates for normal cross reference.

the derived state method gets called twice.
once before, once after indexing

you hint on all other resources i dont get

(1) all resources are indexed
(2) all resources are resolved


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Adding generated objects to the index [message #1833878 is a reply to message #1833875] Mon, 26 October 2020 18:11 Go to previous messageGo to next message
Elie Richa is currently offline Elie RichaFriend
Messages: 72
Registered: February 2016
Member
I talk about "updating references" because in my current architecture I don't use proxies to defer reference resolution. Instead, the output objects refer to the input objects in a first phase (because the references have a type that's general enough to store input and output objects alike). Then a second phase of "reference resolution" converts each reference to an input object into a reference to the corresponding output object.

So in my architecture the input objects serve as proxies that are resolved in the second phase into output objects.

As for the indexing and derived state computation, your reply already answers most of it (Thanks!). What I don't yet understand is this piece of code from JvmModelAssociator:

	public void installDerivedState(final DerivedStateAwareResource resource, boolean preIndexingPhase) {
		...
		JvmDeclaredTypeAcceptor acceptor = new JvmDeclaredTypeAcceptor(resource);
		try {
			IJvmModelInferrer inferrer = inferrerProvider.get();
			if (inferrer instanceof AbstractModelInferrer) {
				((AbstractModelInferrer) inferrer).setContext(resource);
			}
			inferrer.infer(eObject, acceptor, preIndexingPhase);
		} catch (RuntimeException e) {
			operationCanceledManager.propagateAsErrorIfCancelException(e);
			LOG.error("Error calling inferrer", e);
		}
		...
		if (!preIndexingPhase) {
			...
                }


As you said, the derived state method gets called twice: once before and once after indexing. So it means that the inferrer above is called twice.

Does it create the objects in both calls? Or does it use preIndexingPhase to not re-create the same objects?


Elie Richa, Ph.D
Software Engineer, AdaCore
https://www.adacore.com
Re: Adding generated objects to the index [message #1833879 is a reply to message #1833878] Mon, 26 October 2020 18:54 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
yes. infers twice

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Mon, 26 October 2020 18:54]

Report message to a moderator

Re: Adding generated objects to the index [message #1833903 is a reply to message #1833879] Tue, 27 October 2020 13:50 Go to previous message
Elie Richa is currently offline Elie RichaFriend
Messages: 72
Registered: February 2016
Member
Ok thanks for the help Christian. Now I will have to do some experiments to understand better.

Elie Richa, Ph.D
Software Engineer, AdaCore
https://www.adacore.com
Previous Topic:xtend code
Next Topic:Parallel Serialization
Goto Forum:
  


Current Time: Wed Apr 24 21:22:35 GMT 2024

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

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

Back to the top