Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Questions about two problems with Xpect
Questions about two problems with Xpect [message #1777438] Wed, 29 November 2017 11:58 Go to next message
Axel Guckelsberger is currently offline Axel GuckelsbergerFriend
Messages: 335
Registered: July 2009
Senior Member
Hi all,

I am trying to get started with using Xpect. Here is what I did so far:

1. Installed from update site into my IDE as well as into the target platform (both based on Oxygen SR1).
2. Started a runtime where my DSL bundle is included.
3. Created a simple test case to begin with.

Now I am more or less blocked by two problems. Maybe they are easy to solve and I just do not see something obvious.

First problem I observed is that
/* XPECT_SETUP my.simple.ParserTest END_SETUP */
works when using the Xpect editor only. But when using the Xpect+Xtext editor it has an error marker because the JvmDeclaredType can not be resolved. Is this related to that my DSL does not utilise Xbase? Or do I need to configure something for getting this to work? Or is it rather a bug in Xpect?

The more critical error appears if I execute a test:

java.lang.NullPointerException
	at org.xpect.xtext.lib.setup.XtextStandaloneSetup.<init>(XtextStandaloneSetup.java:40)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at org.xpect.state.StateContainer.createFactory(StateContainer.java:154)
	at org.xpect.state.StateContainer.getFactory(StateContainer.java:271)
	at org.xpect.state.StateContainer.createInstance(StateContainer.java:174)
	at org.xpect.state.StateContainer.createInstance(StateContainer.java:198)
	at org.xpect.state.StateContainer.get(StateContainer.java:248)
	at org.xpect.state.StateContainer.get(StateContainer.java:210)
	at org.xpect.state.StateContainer.createFactory(StateContainer.java:150)
	at org.xpect.state.StateContainer.getFactory(StateContainer.java:271)
	at org.xpect.state.StateContainer.createInstance(StateContainer.java:174)
	at org.xpect.state.StateContainer.createInstance(StateContainer.java:198)
	at org.xpect.state.StateContainer.get(StateContainer.java:248)
	at org.xpect.state.StateContainer.get(StateContainer.java:210)
	at org.xpect.runner.XpectFileRunner.run(XpectFileRunner.java:135)
	at org.xpect.runner.XpectRunner.runChild(XpectRunner.java:208)
	at org.xpect.runner.XpectRunner.runChild(XpectRunner.java:1)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.xpect.runner.XpectRunner.run(XpectRunner.java:194)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:539)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:761)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:461)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:207)


This NPE seems to be caused by a missing injector in Xpect's XtextStandaloneSetup constructor:

	public XtextStandaloneSetup(FileSetupContext ctx, org.xpect.xtext.lib.setup.emf.ResourceSet resourceSet, Injector injector) {
		super();
		this.resourceSetConfig = resourceSet;
		this.ctx = ctx;
		JvmModelInferrerRegistryFix.apply();
		injector.injectMembers(this);
	}


The stack trace points to
injector.injectMembers(this);
so the only cause for a NPE is that the "injector" argument is null. Any idea how to fix that?

Thanks for your assistance!
Re: Questions about two problems with Xpect [message #1777488 is a reply to message #1777438] Wed, 29 November 2017 16:32 Go to previous messageGo to next message
Moritz Eysholdt is currently offline Moritz EysholdtFriend
Messages: 161
Registered: July 2009
Location: Kiel, Germany
Senior Member
Hi Axel,

could you try to put the following into the plugin.xml of the project in which your Xpect tests are?

Xpect reads the plugin.xml also when tests are executed as plain JUnit test (standalone mode, no OSGi/Equinox)

<plugin>
   <extension
         point="org.xpect.fileExtensions">
      <fileExtension
            fileExtension="myfileext"
            xtextLanguageName="lanugage.name.as.specified.in.the.xtext.grammar"
            xtextRuntimeModule="com.product.MyLanguageRuntimeModule"
            xtextUiModule="com.product.MyLanguageUIModule">
      </fileExtension>
  </extension>
</plugin>
Re: Questions about two problems with Xpect [message #1777492 is a reply to message #1777488] Wed, 29 November 2017 16:55 Go to previous message
Axel Guckelsberger is currently offline Axel GuckelsbergerFriend
Messages: 335
Registered: July 2009
Senior Member
Hi Moritz,

thank you very much. This fixed the second problem. Tests can now be executed.

Best regards,

Axel
Previous Topic:Parsing Exponent Expression
Next Topic:Xtend 2: M2T how to skip generation of expression result in output file
Goto Forum:
  


Current Time: Tue Jan 16 07:28:58 GMT 2018

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

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