Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » XText - Cannot load model in standalone setup(Guice related exception)
icon5.gif  XText - Cannot load model in standalone setup [message #1419362] Mon, 08 September 2014 13:42 Go to next message
C Tran is currently offline C TranFriend
Messages: 15
Registered: July 2014
Junior Member
Hi Joerg and everyone,

I have defined a language to define conditional expressions using XText. The generated editor works fine that should indicate the parser and other components are valid. I want to use ONLY the parser in my scenario and I followed the instructions at http://wiki.eclipse.org/Xtext/FAQ#Why_do_I_get_compilation_errors_when_trying_to_import_an_existing_Xtext_grammar_using_the_with_statement.3F

Here is my code of Unit test (written in Xtend):

import uk.ac.man.xman.dsl.ConditionDSLStandaloneSetup

@RunWith(XtextRunner)

class ParsingText {

       @Test
       def void parseSampleText () {
               new StandaloneSetup().setPlatformUri("../");
                val injector = new ConditionDSLStandaloneSetup().createInjectorAndDoEMFRegistration();
                val resourceSet = injector.getInstance(typeof(XtextResourceSet));
                resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
                val uri  = URI.createURI("dummy:/example.cdsl")
                val resource = resourceSet.createResource(uri); //ERROR happened here
                val in = new ByteArrayInputStream("((id1 == 1) && (id2 == 2))".getBytes());
                resource.load(in, resourceSet.getLoadOptions());
       }
}


However, I faced an exception:
com.google.inject.ProvisionException: Guice provision errors:

1) Error injecting constructor, org.eclipse.emf.common.util.WrappedException: java.lang.ArrayIndexOutOfBoundsException: 3
at org.eclipse.xtext.common.services.TerminalsGrammarAccess.<init>(Unknown Source)
at org.eclipse.xtext.common.services.TerminalsGrammarAccess.class(Unknown Source)
while locating org.eclipse.xtext.common.services.TerminalsGrammarAccess
for parameter 1 at uk.ac.man.xman.dsl.services.ConditionDSLGrammarAccess.<init>(Unknown Source)
at uk.ac.man.xman.dsl.services.ConditionDSLGrammarAccess.class(Unknown Source)
while locating uk.ac.man.xman.dsl.services.ConditionDSLGrammarAccess
while locating org.eclipse.xtext.IGrammarAccess
for field at org.eclipse.xtext.linking.lazy.LazyLinker.grammarAccess(Unknown Source)
while locating org.eclipse.xtext.linking.lazy.LazyLinker
while locating org.eclipse.xtext.linking.ILinker
for field at org.eclipse.xtext.resource.XtextResource.linker(Unknown Source)
while locating org.eclipse.xtext.linking.lazy.LazyLinkingResource
while locating org.eclipse.xtext.resource.XtextResource
Caused by: org.eclipse.emf.common.util.WrappedException: java.lang.ArrayIndexOutOfBoundsException: 3
at org.eclipse.xtext.parser.BaseEPackageAccess.loadResource(BaseEPackageAccess.java:57)
at org.eclipse.xtext.parser.BaseEPackageAccess.loadGrammarFile(BaseEPackageAccess.java:44)
at org.eclipse.xtext.service.GrammarProvider.getGrammar(GrammarProvider.java:60)
at org.eclipse.xtext.common.services.TerminalsGrammarAccess.internalFindGrammar(TerminalsGrammarAccess.java:37)
at org.eclipse.xtext.common.services.TerminalsGrammarAccess.<init>(TerminalsGrammarAccess.java:33)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
....

Any idea why this happened? Your help is appreciated.
Re: XText - Cannot load model in standalone setup [message #1420245 is a reply to message #1419362] Tue, 09 September 2014 18:30 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

i cannot reproduce that. do you have any customizations in your dsl? where did you place the test.
btw testing is more easy like that if you use the parseHelper class (and yourdslinjectorprovider)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: XText - Cannot load model in standalone setup [message #1420253 is a reply to message #1420245] Tue, 09 September 2014 18:41 Go to previous messageGo to next message
C Tran is currently offline C TranFriend
Messages: 15
Registered: July 2014
Junior Member
Christian,

Thanks for your reply. My language is actually simple.

Here is my language definition:
grammar uk.ac.man.xman.dsl.ConditionDSL with org.eclipse.xtext.common.Terminals

generate conditionDSL "www.ac.uk/xman/dsl/ConditionDSL"

Model:
	expression=Expression;

Expression:
	CompositeExpression;

CompositeExpression returns Expression:
	PrimaryExpression (({AND.left=current} '&&' | {OR.left=current} '||') right=PrimaryExpression)*;

PrimaryExpression returns Expression:
	{PrimaryExpression} ('(' e=Expression ')' |
	 name=ID Operator INT | FLOAT | STRING) |
	 Constant;

Constant:
	value = '.';

FLOAT:
	INT '.' INT;

Operator:
	('>' | '<' | '==' | '!=' | '<=' | '>=');


Is this enough for inspection? I could even upload my projects if it helps.

You seemed to suggest the exception has relation to my language. But the (generated) editor runs fine though.

My test was placed in the test project which was automatically created when I started my DSL project (using Wizard).

I also tried parseHelper and ...injectorprovider but I encountered similar exception.

[Updated on: Tue, 09 September 2014 18:41]

Report message to a moderator

Re: XText - Cannot load model in standalone setup [message #1420254 is a reply to message #1420253] Tue, 09 September 2014 18:43 Go to previous messageGo to next message
C Tran is currently offline C TranFriend
Messages: 15
Registered: July 2014
Junior Member
Please note there is "http://" preceding "www.ac.uk/xman/dsl/ConditionDSL" . I was not allowed to put the full URL in my post.
Re: XText - Cannot load model in standalone setup [message #1420258 is a reply to message #1420254] Tue, 09 September 2014 18:45 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
hi,

works fine with your grammar too.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: XText - Cannot load model in standalone setup [message #1420261 is a reply to message #1420258] Tue, 09 September 2014 18:53 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
can you try to recreate the project in a different workspace?
which xtext version / os / jdk do you use?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: XText - Cannot load model in standalone setup [message #1421987 is a reply to message #1420261] Fri, 12 September 2014 06:33 Go to previous message
C Tran is currently offline C TranFriend
Messages: 15
Registered: July 2014
Junior Member
Hi Christian,

I actually had tried what you suggested before reading your reply. Surprisingly (to me at least), it worked. I think the problem was caused by my own mistake when I chose to run Generate XText artefacts. I used Kepler with Xtext 2.4.3 to create my language and although the MWE2 workflow (to generate artifacts) completed, there was an error (see below).

error(10):  internal error: Can't get property indirectDelegates using method get/isIndirectDelegates from org.antlr.tool.Grammar instance : java.lang.NullPointerException


I thought the generated artifacts were unusable and looked for a solution to get rid of the above error. I read somewhere this error exists in old Xtext (2.4.x) and hence I decided to use Luna with Xtext 2.6.x to generate Xtext artifacts. Generation was successful without errors. So, I went on using those generated stuff in Kepler because I also use Spray that requires Xtext 2.4.x.

Today, I used Kepler and ignored the error and discovered everything was ok.

Many thanks to you (Christian) for your time and support anyway. Hope my experience will help someone.

[Updated on: Fri, 12 September 2014 06:34]

Report message to a moderator

Previous Topic:[solved] [Xbase] java like variable declaration
Next Topic:xtext 2.4.1 in eclipse luna
Goto Forum:
  


Current Time: Sat Apr 20 02:27:57 GMT 2024

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

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

Back to the top