Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Cross-reference issues
Cross-reference issues [message #1724499] Wed, 24 February 2016 09:12 Go to next message
Josselin Kerdraon is currently offline Josselin KerdraonFriend
Messages: 29
Registered: February 2016
Junior Member
Hi,

I have issues with the cross-references to develop a simple editor with variables.

VariableDeclaration:
	(prefix='ext' | prefix='in' | prefix='out')? 'var' name=STR ('=' value=Expression)?
	;


VariableAssignment:
	ref=[VariableDeclaration|STR] '=' value=INT
	;


while editor validates the code, VariableAssignment class have the "ref" attribute initialized. But when you run the script, value is the only attribute initialized.
My java classes are generated by a .mwe2 file. Do I have something specific to add in this file to take care of cross-referencing ? Or something else in an other file ?


Re: Cross-reference issues [message #1724552 is a reply to message #1724499] Wed, 24 February 2016 15:10 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Are the referenced locally (the this should work out of the box) or
globally (other file)
In both case having a look at your script runner would be interesting


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Cross-reference issues [message #1724559 is a reply to message #1724552] Wed, 24 February 2016 16:01 Go to previous messageGo to next message
Josselin Kerdraon is currently offline Josselin KerdraonFriend
Messages: 29
Registered: February 2016
Junior Member
I want to create the variables locally with the runner.

I can't show you all the runner beacuse it's really big but its initialized like this:

 InputStream is = new StringInputStream(s);
                Reader reader = new InputStreamReader(is);
                IParseResult result = parser.parse(reader);
                EObject eRoot = result.getRootASTElement();


s is the editor String. and parser is a AbstractAntlrParser child

grammar rules are made like this (not complete):

Script:
	instructions+=Instruction*;
	
Instruction:
	statemement=Statement ';'
;	
	
Statement: 
	function=VariableDeclaration |
	function=VariableAssignment
	;



to get the variableDeclaration we want assign I get it like this:

VariableAssignment var =  ((VariableAssignmentImpl)statement.getFunction()).getRef()


But ref attribute is null.
Re: Cross-reference issues [message #1724560 is a reply to message #1724559] Wed, 24 February 2016 16:06 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

you simply call the parse.
the parser itself does not know anything about resolving cross refs.

thus you should do something like

https://wiki.eclipse.org/Xtext/FAQ#How_do_I_load_my_model_in_a_standalone_Java_application.C2.A0.3F


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Cross-reference issues [message #1724562 is a reply to message #1724560] Wed, 24 February 2016 16:25 Go to previous messageGo to next message
Josselin Kerdraon is currently offline Josselin KerdraonFriend
Messages: 29
Registered: February 2016
Junior Member
Hi,

my parser is initialized like this:

            Injector guiceInjector = new ScriptStandaloneSetup().createInjectorAndDoEMFRegistration();
            parser = guiceInjector.getInstance(ScriptParser.class);


I'm going to try with the link you gave to me
Re: Cross-reference issues [message #1724568 is a reply to message #1724562] Wed, 24 February 2016 16:55 Go to previous messageGo to next message
Josselin Kerdraon is currently offline Josselin KerdraonFriend
Messages: 29
Registered: February 2016
Junior Member
Sorry I'm beginner, and I'm on an old project that use Xtext.

The fact is that when you generate files with .mwe2 it generates a Main.java file, but I don't know where it's used. Is it important ?

This is the runGenerator method called by this main:

    protected void runGenerator(String string) {
        // load the resource
        ResourceSet set = resourceSetProvider.get();
        Resource resource = set.getResource(URI.createURI(string), true);

        // validate the resource
        List<Issue> list = validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl);
        if (!list.isEmpty()) {
            for (Issue issue : list) {
                System.err.println(issue);
            }
            return;
        }

        // configure and start the generator
        fileAccess.setOutputPath("src-gen/");
        generator.doGenerate(resource, fileAccess);
    }

[Updated on: Wed, 24 February 2016 16:56]

Report message to a moderator

Re: Cross-reference issues [message #1724569 is a reply to message #1724568] Wed, 24 February 2016 17:00 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
The pregenerated main is just an option / starting point

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Cross-reference issues [message #1724570 is a reply to message #1724568] Wed, 24 February 2016 17:00 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
And no it is not used until you actually use it by calling it

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Cross-reference issues [message #1724655 is a reply to message #1724570] Thu, 25 February 2016 10:15 Go to previous messageGo to next message
Josselin Kerdraon is currently offline Josselin KerdraonFriend
Messages: 29
Registered: February 2016
Junior Member
Ok so I wrote this:

                
                 Injector injector = new ScriptStandaloneSetup().createInjectorAndDoEMFRegistration();
                XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);
                resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
                Resource resource = resourceSet.createResource(URI.createURI("platform:/resource/fr.untel.example.script/src-gen/fr/untel/example/script/Script.genmodel"));
                InputStream in = new ByteArrayInputStream(s.getBytes());
                resource.load(in, resourceSet.getLoadOptions());
                this.script = (Script) resource.getContents().get(0);


s is the string typed by the user in editor

I have this error when I call resource.load :

org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Content is not allowed in prolog.
at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl.java:195)
at org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLResourceImpl.java:253)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1518)
...
Re: Cross-reference issues [message #1724658 is a reply to message #1724655] Thu, 25 February 2016 10:26 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
a genmodel file is not a xtext file. did you name your language genmodel ?!?

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

[Updated on: Thu, 25 February 2016 10:26]

Report message to a moderator

Re: Cross-reference issues [message #1724660 is a reply to message #1724658] Thu, 25 February 2016 10:27 Go to previous messageGo to next message
Josselin Kerdraon is currently offline Josselin KerdraonFriend
Messages: 29
Registered: February 2016
Junior Member
I have the same error with the .xtext file
Re: Cross-reference issues [message #1724664 is a reply to message #1724660] Thu, 25 February 2016 10:44 Go to previous messageGo to next message
Josselin Kerdraon is currently offline Josselin KerdraonFriend
Messages: 29
Registered: February 2016
Junior Member
Ok finally I found that the extension should be ".fml" as described in .mwe2 file. i didn't find any file with this extension so I thought it was not the good extension.

Now it works fine.

Thank you very much Christian, and sorry to be a noob in xtext devlopment
Re: Cross-reference issues [message #1724665 is a reply to message #1724664] Thu, 25 February 2016 10:48 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
no problem. feel free to ask any question

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:IllegalStateException for specific text
Next Topic:Xtext 2.8.4 with Maven but without Tycho
Goto Forum:
  


Current Time: Thu Apr 25 23:38:56 GMT 2024

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

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

Back to the top