Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Cross-reference issues
Cross-reference issues [message #1724499] Wed, 24 February 2016 04:12 Go to next message
Eclipse UserFriend
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 10:10 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Cross-reference issues [message #1724559 is a reply to message #1724552] Wed, 24 February 2016 11:01 Go to previous messageGo to next message
Eclipse UserFriend
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 11:06 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Cross-reference issues [message #1724562 is a reply to message #1724560] Wed, 24 February 2016 11:25 Go to previous messageGo to next message
Eclipse UserFriend
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 11:55 Go to previous messageGo to next message
Eclipse UserFriend
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 11:56] by Moderator

Re: Cross-reference issues [message #1724569 is a reply to message #1724568] Wed, 24 February 2016 12:00 Go to previous messageGo to next message
Eclipse UserFriend
The pregenerated main is just an option / starting point
Re: Cross-reference issues [message #1724570 is a reply to message #1724568] Wed, 24 February 2016 12:00 Go to previous messageGo to next message
Eclipse UserFriend
And no it is not used until you actually use it by calling it
Re: Cross-reference issues [message #1724655 is a reply to message #1724570] Thu, 25 February 2016 05:15 Go to previous messageGo to next message
Eclipse UserFriend
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 05:26 Go to previous messageGo to next message
Eclipse UserFriend
a genmodel file is not a xtext file. did you name your language genmodel ?!?

[Updated on: Thu, 25 February 2016 05:26] by Moderator

Re: Cross-reference issues [message #1724660 is a reply to message #1724658] Thu, 25 February 2016 05:27 Go to previous messageGo to next message
Eclipse UserFriend
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 05:44 Go to previous messageGo to next message
Eclipse UserFriend
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 05:48 Go to previous message
Eclipse UserFriend
no problem. feel free to ask any question
Previous Topic:IllegalStateException for specific text
Next Topic:Xtext 2.8.4 with Maven but without Tycho
Goto Forum:
  


Current Time: Wed Jul 23 21:51:04 EDT 2025

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

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

Back to the top