Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » RuntimeException - Context not valid for type(Instance creation problem)
RuntimeException - Context not valid for type [message #1793151] Tue, 31 July 2018 16:42 Go to next message
Maude Sabourin is currently offline Maude SabourinFriend
Messages: 11
Registered: May 2018
Junior Member
I am getting the following error when attempting to create an instance of my model :

java.lang.RuntimeException: The context 'Domainmodel returns Domainmodel' is not valid for type 'Domainmodel'
Recommended contexts for type 'Domainmodel': [Domainmodel returns Domainmodel]
The context 'Domainmodel returns Domainmodel' is valid for types: Domainmodel, null

Semantic Object: Domainmodel
URI: platform:/resource/canardnoex.sample/testsimple.canNoEx
at org.eclipse.xtext.serializer.diagnostic.ISerializationDiagnostic$ExceptionThrowingAcceptor.accept(ISerializationDiagnostic.java:131)
at org.xtext.example.canardNoExtends.serializer.CanNoExSemanticSequencer.sequence(CanNoExSemanticSequencer.java:68)
at org.eclipse.xtext.serializer.sequencer.AbstractSemanticSequencer.createSequence(AbstractSemanticSequencer.java:67)
at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:118)

...etc


A picture of my ecore
https://imgur.com/a/OboNgwd

A simplified version of my grammar

Domainmodel:
    (elements+=Type | links+=Rel)*;

Type: 
Category|Block;

Category:
'cat' nameCat=STRING;

Block: 
'block' name=STRING;

Rel:
'source' src=Block 'destination' des=Block;


I know that the problem is in the xtext definition of domainmodel, as I've done a test where 'Rel' was a subtype of 'Type' and this problem didn't pop.

I can't use the version mentioned just above because the 'Rel' isn't, in that case, doing a verification check to make sure the 'Block' linked do exist.

Thus, I would like to find a way to make the initial definition work.

Notes :
- Any instance of the grammar gives this error, even if it contains only 1 'Type', no 'Type', only 1 'Rel', and so on..
- Attached are :
the actual ecore file
the full grammar version

Thanks a lot!
Re: RuntimeException - Context not valid for type [message #1793162 is a reply to message #1793151] Tue, 31 July 2018 19:24 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 12254
Registered: July 2009
Senior Member
Hi, can you please provide a reproducing unit test? i could not reproduce it with a simple one

package org.xtext.example.mydsl.tests

import com.google.inject.Inject
import com.google.inject.Provider
import org.eclipse.emf.common.util.URI
import org.eclipse.emf.ecore.resource.ResourceSet
import org.eclipse.xtext.serializer.ISerializer
import org.eclipse.xtext.testing.InjectWith
import org.eclipse.xtext.testing.extensions.InjectionExtension
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.^extension.ExtendWith
import org.xtext.example.mydsl.myDsl.MyDslFactory

@ExtendWith(InjectionExtension)
@InjectWith(MyDslInjectorProvider)
class DummyTest {
	
	@Inject extension ISerializer
	@Inject Provider<ResourceSet> rsp
	
	@Test
	def void testIt() {
		val rs = rsp.get
		val r = rs.createResource(URI.createURI("dummy.mydsl"))
		val m = MyDslFactory.eINSTANCE.createDomainmodel=> [
			elements += MyDslFactory.eINSTANCE.createCategory=>[
				nameCat="Hugo"
			]
		]
		r.contents+=m
		println(m.serialize)
	}
	
}


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: RuntimeException - Context not valid for type [message #1793226 is a reply to message #1793162] Wed, 01 August 2018 19:45 Go to previous messageGo to next message
Maude Sabourin is currently offline Maude SabourinFriend
Messages: 11
Registered: May 2018
Junior Member
Hi Christian,

Thanks for your answer. I do not know how to create a unit test. I was creating an instance with the UI rather than programatically.

I ended up creating a new project and copy-pasting the xtext-emf content and the error is now gone. I believe I might have modified some core files too much which caused corruption in the project.

Do you know of a tutorial explaining how to create such tests? I could really use those.

*edit* I actually previously skipped the part of this tutorial talking about JUnit test : https://eclipsesource.com/blogs/tutorials/emf-tutorial/

Thanks

[Updated on: Wed, 01 August 2018 19:50]

Report message to a moderator

Re: RuntimeException - Context not valid for type [message #1793229 is a reply to message #1793226] Wed, 01 August 2018 20:17 Go to previous message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 12254
Registered: July 2009
Senior Member
well i have provided you with an example.
unfortunately i dont know your complete usecase = where does the model you serialize com from?


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:How to generate .vhdl code/template from my grammar
Next Topic:Display EXPENSIVE checks when building
Goto Forum:
  


Current Time: Wed Sep 26 15:24:50 GMT 2018

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

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

Back to the top