Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Cannot run extended 15 minute tutorial(When trying to add unit tests to the Domainmodel parser I get errors of type "Couldn't resolve reference to JvmAnnotationType 'InjectWith'.")
Cannot run extended 15 minute tutorial [message #731526] Sat, 01 October 2011 15:22 Go to next message
bogdan.petrovici is currently offline bogdan.petroviciFriend
Messages: 5
Registered: October 2011
Junior Member
Hello,

I have recently started studying the documentation for Xtext and I am unable to properly generate a unit test for the example language provided in the section "15 minutes tutorial - Extended".

When writing the example code I get the error "Couldn't resolve reference to JvmAnnotationType 'InjectWith'." and I am unable to figure out which is the source of the problem.

I have imported org.eclipse.xtext.junit4 in my source file but that doesn't seem to help at all and I can see the org.eclipse.xtext.junit4_2.0.1.v201108020636.jar file is referenced in Plug-in Dependencies.

Could anyone help me with this? I'm sure that it's just some configuration step that I'm missing but I can't find any lead on Google and the documentation is pretty vague on this matter.
Re: Cannot run extended 15 minute tutorial [message #731528 is a reply to message #731526] Sat, 01 October 2011 15:29 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

did you add the corresponding imports?

package test

import org.eclipse.xtext.junit4.InjectWith
import org.junit.runner.RunWith
import org.eclipse.xtext.junit4.XtextRunner
import org.eclipse.xtext.example.domainmodel.DomainmodelInjectorProvider

@InjectWith(typeof(DomainmodelInjectorProvider))
@RunWith(typeof(XtextRunner))
class Test {
	
}


~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Cannot run extended 15 minute tutorial [message #731535 is a reply to message #731528] Sat, 01 October 2011 15:57 Go to previous messageGo to next message
bogdan.petrovici is currently offline bogdan.petroviciFriend
Messages: 5
Registered: October 2011
Junior Member
Thank you for the quick reply, that did the trick.
Re: Cannot run extended 15 minute tutorial [message #731560 is a reply to message #731535] Sat, 01 October 2011 18:20 Go to previous messageGo to next message
bogdan.petrovici is currently offline bogdan.petroviciFriend
Messages: 5
Registered: October 2011
Junior Member
Now I only have one error left. Eclipse does not seem to recognize assertSame even when I import the package for it. My code is:

import org.eclipse.xtext.junit4.InjectWith
import org.junit.runner.RunWith
import org.eclipse.xtext.junit4.XtextRunner
import org.example.domainmodel.DomainmodelInjectorProvider
import org.example.domainmodel.domainmodel.Domainmodel
import org.example.domainmodel.domainmodel.Entity
import org.eclipse.xtext.xtend2.lib
import com.google.inject.Inject
import org.eclipse.xtext.junit4.util.ParseHelper
import org.junit.Test
import org.junit.Assert

@InjectWith(typeof(DomainmodelInjectorProvider))
@RunWith(typeof(XtextRunner))
class ParserTest{
	
	@Inject ParseHelper<Domainmodel> parser
	
	@Test
	def void testParseDomainmodel(){
		val model=parser.parse("
			entity MyEntity{
				parent: MyEntity
			}
		")
		
		val entity = model.elements.get(0) as Entity
	    assertSame(entity, entity.features.get(0).type)
	}
}


When I modify the ParserTest class to inherit from TestCase then I get the following error for assertSame: "Incompatible receiver type. Expected java.lang.String but was ParserTest"

Could you please help me with this issue?
Re: Cannot run extended 15 minute tutorial [message #731562 is a reply to message #731560] Sat, 01 October 2011 18:25 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

same as in Java: import static org.junit.Assert.*

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Cannot run extended 15 minute tutorial [message #731563 is a reply to message #731562] Sat, 01 October 2011 18:35 Go to previous messageGo to next message
bogdan.petrovici is currently offline bogdan.petroviciFriend
Messages: 5
Registered: October 2011
Junior Member
Thank you again for the reply. Now the example is fully functional.
Re: Cannot run extended 15 minute tutorial [message #731647 is a reply to message #731563] Sun, 02 October 2011 08:45 Go to previous messageGo to next message
bogdan.petrovici is currently offline bogdan.petroviciFriend
Messages: 5
Registered: October 2011
Junior Member
I have a problem with the code generator example in the extended 15 minute tutorial. When I opened the Eclipse application with my plugin the generated code in xtend-gen contained the <<IF>> tokens and I removed the generated code from the project but I cannot regenerate it no matter what I try. Does anyone know which operations trigger the code generator for xtend-gen?
Re: Cannot run extended 15 minute tutorial [message #731649 is a reply to message #731647] Sun, 02 October 2011 09:01 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

Are you talking about the Xtend-gen Folder in the Host project or about the src-gen in the Model project in the runtime Application. In both cases a clean Build on the project should trigger a rebuild. what exactly did you do when Removing the generated Code?

Regards Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Referencing models defined in files outside of eclipse
Next Topic:display of keywords
Goto Forum:
  


Current Time: Tue Apr 23 14:25:45 GMT 2024

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

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

Back to the top