Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » change builder sorter(how to change the order of the files during xtext build)
change builder sorter [message #1649886] Wed, 04 March 2015 15:01 Go to next message
Silvia Gotta is currently offline Silvia GottaFriend
Messages: 13
Registered: April 2013
Junior Member
Hello,

i'd like to change the order of the files which need to be built during the xtext build.
My problem is the following:
I defined a grammar for a proprieraty programming language. This language splits the code over three different files (*.msi, *.mgi and *.mti).
The msi file contains all the declarations.

During the xtextBuilder doBuild() process, the building files are collected according to an 'as-is' order.
Instead, i'd like to change the predefine order of file so as to list the msi files first, then the mti files and at last the mgi files.

Is it possible?

Thanks in advance,
Silvia


Re: change builder sorter [message #1649917 is a reply to message #1649886] Wed, 04 March 2015 15:20 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

yes this is possible but you have to consider some points

- partial vs. full builds
- the change can be done only global (not per dsl)

to do the change you need to customize ClusteringBuilderState and copy&paster overide writeNewResourceDescriptions

there you might introduce something like

    protected void writeNewResourceDescriptions(
            BuildData buildData,
            IResourceDescriptions oldState,
            CurrentDescriptions newState,
            final IProgressMonitor monitor) {
        int index = 0;
        ResourceSet resourceSet = buildData.getResourceSet();
        List<URI> toBeUpdated = sort(buildData.getToBeUpdated());
.....


(through a modele registered by org.eclipse.xtext.ui.shared.overridingGuiceModule extension point in plugin.xml)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: change builder sorter [message #1649943 is a reply to message #1649917] Wed, 04 March 2015 15:40 Go to previous messageGo to next message
Silvia Gotta is currently offline Silvia GottaFriend
Messages: 13
Registered: April 2013
Junior Member
Thank you Christian, i found the point.
However I don't know how to replace the original ClusteringBuilderState with my customized one.

Should I customize the method
public void configureIResourceDescriptionsPersisted(com.google.inject.Binder binder) {
		binder.bind(org.eclipse.xtext.resource.IResourceDescriptions.class).annotatedWith(com.google.inject.name.Names.named(org.eclipse.xtext.resource.impl.ResourceDescriptionsProvider.PERSISTED_DESCRIPTIONS)).to(org.eclipse.xtext.builder.builderState.IBuilderState.class);
	}

in AbstractXXXUiModule?

Re: change builder sorter [message #1649951 is a reply to message #1649943] Wed, 04 March 2015 15:41 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
No !!!!

as a said:

create a new (AbstractGeneric)Module and register the Module via extension point


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: change builder sorter [message #1649952 is a reply to message #1649951] Wed, 04 March 2015 15:44 Go to previous messageGo to next message
Silvia Gotta is currently offline Silvia GottaFriend
Messages: 13
Registered: April 2013
Junior Member
Sorry, i missed your last line.

I'l try it immediately.

Thank you,
Silvia
Re: change builder sorter [message #1649960 is a reply to message #1649952] Wed, 04 March 2015 15:48 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
e.g.

public class MyBuilderModule extends AbstractGenericModule {

	public void configureIBuilderState(Binder binder) {
		binder.bind(IBuilderState.class).to(OrderingClusteringBuilderState.class).in(Scopes.SINGLETON);
	}

}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: change builder sorter [message #1649969 is a reply to message #1649960] Wed, 04 March 2015 15:52 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
btw make sure you really cannot avoid this.
it ususally should work without adapting it .
can you explain a bit more why you need this?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: change builder sorter [message #1650201 is a reply to message #1649969] Wed, 04 March 2015 18:17 Go to previous messageGo to next message
Silvia Gotta is currently offline Silvia GottaFriend
Messages: 13
Registered: April 2013
Junior Member
Sorry for my delay.
Sure I'l explain you my problem.

My DSL describes assignments of variables where parent containers are on the right side of the var name instead of on the left side:

e.g.:
(file class_A.mti)

class "class_A"

       method "method_A_a"
                "some_var_B" in "some_obj_B" contained_in "some_obj_C" = "some_val_B1"

end_class


where:

"some_obj_C" has type "class_C" and it is declared in "class_A" (file class_A.msi)
"some_obj_B" has type "class_B" and it is declared in "class_C" (file class_B.msi)
"some_var_B" can have values "some_val_B1", "some_val_B2", "some_val_B3", it is declared in "class_B" (file class_B.msi)

In order to make things work, I customized DefaultDeclarativeQualifiedNameProvider. At this point, each object has a container nested qualified name.
However, "some_var_B" came with a wrong qualified name:

class_A.some_var_B

On the contrary, the right qualified name for that var should be:

class_B.some_var_B

The same thing should be for "some_obj_B": the qualified name should be class_C.some_obj_B instead of class_A.some_obj_B.

The only way I found to provide a right qualified name for "some_var_B" and for "some_obj_B" is to extend LinkingHelper and to customize getCrossRefNodeAsString(...).
At the present day, all the references are correctly linked; every CTRL-click on vars and objs can jump into the code. However, the problem view still shows some errors which should not exist anymore.

Those errors seems to be referred to objects whose msi file has been built later than the mti file that contains the references.
This is why I'd like to try to change the builder order files.

Please, if I'm wrong, suggest me a different way.

Thanks,
Silvia










Re: change builder sorter [message #1650324 is a reply to message #1650201] Wed, 04 March 2015 19:40 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi

The first question is: where is the qualified name used?
you know you can refer from one ref to another in scoping?

Another possibility would be to use the user data map of the ieobjectdescriptions with the information about the types
And then query for the information

But that again depends on your usecase.
And it may not be that easy neither


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

[Updated on: Wed, 04 March 2015 19:48]

Report message to a moderator

Re: change builder sorter [message #1651466 is a reply to message #1650324] Thu, 05 March 2015 10:13 Go to previous messageGo to next message
Silvia Gotta is currently offline Silvia GottaFriend
Messages: 13
Registered: April 2013
Junior Member
Hi Christian,

my problem is in DefaultLinkingService.getLinkedObjects(Eobject context, EReference ref, INode node).

1. public List<EObject> getLinkedObjects(EObject context, EReference ref, INode node) 	throws IllegalNodeException {
2. 		final EClass requiredType = ref.getEReferenceType();
3.		if (requiredType == null)
4.			return Collections.<EObject> emptyList();
5.
6.		final String crossRefString = getCrossRefNodeAsString(node);
7.		if (crossRefString != null && !crossRefString.equals("")) {
8.			if (logger.isDebugEnabled()) {
9.				logger.debug("before getLinkedObjects: node: '" + crossRefString + "'");
10.			}
11.			final IScope scope = getScope(context, ref);
12.			QualifiedName qualifiedLinkName =  qualifiedNameConverter.toQualifiedName(crossRefString);
13.			IEObjectDescription eObjectDescription = scope.getSingleElement(qualifiedLinkName);
14.			if (logger.isDebugEnabled()) {
15.				logger.debug("after getLinkedObjects: node: '" + crossRefString + "' result: " + eObjectDescription);
16.			}
17.			if (eObjectDescription != null) 
18.				return Collections.singletonList(eObjectDescription.getEObjectOrProxy());
19.		}
20.		return Collections.emptyList();
21.	}


context contains the assigment ("some_var_B" in "some_obj_B" contained_in "some_obj_C" = "some_val_B1");
ref contains the name 'left_var' of the attribute of the assigment;
node points at the grammar node corresponding to the var "some_var_B";

In scope (line 11) I have the list of qualified name of classes and vars and methods and so on;
crossRefString contains the flat name of my var ("some_var_B");
At line 13, I get a null eObjectDescription because getSingleElement() looks for a flat name var into the scope which contains only qualified names;
the var "some_var_B" is contained in the scope but under the name class_B.some_var_B.

This is the reason why I customized getCrossRefNodeAsString(node); after my customization, crossRefString contains the full dotted name for the var "some_var_B".

I'm not sure this is the right way, but before arriving at this point, I tried to work with scopes (both local and global scopes) but I was not able to reach the goal.
Sorry.
Of course, I can reconsider my way, with a little help Surprised)


Silvia









Re: change builder sorter [message #1651480 is a reply to message #1651466] Thu, 05 March 2015 10:20 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

the point is: why not put them into scope/index by their simple name.
or even do the scoping completely manually (yes this sucks in content assist but using that syntax it will suck anyway)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: change builder sorter [message #1651533 is a reply to message #1651480] Thu, 05 March 2015 11:04 Go to previous messageGo to next message
Silvia Gotta is currently offline Silvia GottaFriend
Messages: 13
Registered: April 2013
Junior Member
Hi,

Simple names leaded to mis-references. Before customizing NameProvider, names were flat but sometime mis-references occured when vars with the same name were used in the code.
CRTL-click jumped into the wrong class, content assit suggested wrong values for those vars; no errors were risen on unexisting var because that var were linked to another class...
I was a mess...

To avoid these problems, I consedered scope and scope providers but I missed myself during scope management. I was not able to provide scopes for those vars which have parent on the right, because I was not able to ecognize the parent name...

Sad

Re: change builder sorter [message #1651540 is a reply to message #1651533] Thu, 05 March 2015 11:08 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

this is what i meant by adapting the scoping

if you have "a in b in c"

a-scope is build through having a look at b
and b-scope is build through having a look at c
and c-scope is global


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: change builder sorter [message #1651577 is a reply to message #1651540] Thu, 05 March 2015 11:30 Go to previous messageGo to next message
Silvia Gotta is currently offline Silvia GottaFriend
Messages: 13
Registered: April 2013
Junior Member
I am not able to get B when scoping for A because in the model of A, the reference to B is still null.

I'm doing something wrong... Sad
Re: change builder sorter [message #1651599 is a reply to message #1651577] Thu, 05 March 2015 11:45 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
this depends on the grammar and the implementation of scoping

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: change builder sorter [message #1651715 is a reply to message #1651599] Thu, 05 March 2015 13:18 Go to previous messageGo to next message
Silvia Gotta is currently offline Silvia GottaFriend
Messages: 13
Registered: April 2013
Junior Member
Ok, I'm putting back all my chages.
At the end all I need is:

1. a name provider which extends the SimpleNameprovider
2. a scope provider which extends the ImportedNamespaceAwareLocalScopeProvider
3. customize the getScope method (directly or using the declarative way)

That's all?

I'm going to try this solution and let you know the result.

Thanks
Silvia
Re: change builder sorter [message #1653701 is a reply to message #1651715] Fri, 06 March 2015 10:47 Go to previous message
Silvia Gotta is currently offline Silvia GottaFriend
Messages: 13
Registered: April 2013
Junior Member
Hi,

I did the test but it didn't work fine.

There were no errors but the vars referenced to wrong instances.
In my example, I wrote two var with the same name, the first contained in the class where the assignment was, the other in another class.
The CTRL-click on the two vars jumped to the same location.

Just a look at my scope provider:
0. class MyScopeProvider extends ImportedNamespaceAwareLocalScopeProvider {
1.       override IScope getScope(EObject context, EReference reference) {
2. 		if(context != null) {
3. 			if(context instanceof MyAssignment) {
4. 				if(reference.name.equalsIgnoreCase("variable")) {
5. 					val my_assignment = context as MyAssignment
6. 					val MyClass e = my_assignment .ofClass?.class_ref
7. 					Scopes::scopeFor(e.variableList)
8. 				}
9.				else if(reference.name.equalsIgnoreCase("ofClass")) {
10.					val my_assignment = context as Assegnazione
11.					val MyClass e = my_assignment .throughClass?.class_ref					
12.					Scopes::scopeFor(e.classList)
13.				}
14.				else if(reference.name.equalsIgnoreCase("throughClass")) {
15.					val MyClass e = context.getContainerOfType(typeof(MyClass))
16.					Scopes::scopeFor(e.classList)
17.				}
18.			}
19.		}		
20.		super.getScope(context, reference)
21.       }
22.}


At line 7, e.variableList is always NULL because vars are declared in file .msi, while assignment is contained in file .mti.
At line 12 and 16, e.classList is always diffent from NULL because 'imported classes' are declared in file .mti.

Thanks,
Silvia
Previous Topic:Create new object when can't resolve reference
Next Topic:Use Xtext features in Jface Viewers
Goto Forum:
  


Current Time: Fri Apr 19 19:23:15 GMT 2024

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

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

Back to the top