As part of a research idea, I’m now creating a language to write Use Cases, using Xtext. It is also a good opportunity to analyze more deeply this framework for building textual DSLs in Eclipse.

But this is not why I’m writing this post. After I wrote the language specification, I wanted to create some tests. I followed the very brief tutorial and wrote a simple test. However, It didn’t work. The failure trace in JUnit always presented an error:

org.eclipse.xtext.parser.ParseException: java.lang.IllegalStateException: Unresolved proxy http://wwww.levysiqueira.com.br/MyLanguage.ecore#//Element.Make sure the EPackage has been registered.

at org.eclipse.xtext.parser.antlr.AbstractAntlrParser.doParse(AbstractAntlrParser.java:105)

...

(I changed the name of my Ecore file and element.)

As I added a plug-in for the EMF model – including the Ecore – in the Eclipse plugin folder, I didn’t expect to see this message. I tried several solutions to “register” the ePackage, for instance, changing the Project settings, adding the Ecore file in the project, changing the configuration that launches the JUnit test, etc. I finally gave up and registered manually the metamodel programmatically in the test (based on this faq). Here is the example:

@InjectWith(MyLanguageInjectorProvider)
@RunWith(XtextRunner)

class SubjectTest {

  @Inject ParseHelper<EntryElement> parser

  @Test
  def void parseDomainmodel() {
    MyModelPackage.eINSTANCE.eClass()
    val model = parser.parse(
      "element Teste;"
    )
    assertEquals(model.element.name, "Teste")
  }
}

Where MyLanguage is the name of my language and MyModel is the name of my Ecore model. This finally made it work… But I still don’t know why this message appears.

Now I’ll try to use the plug-in xtext-utils for unit testing. Hopefully it will not need this form of registration.

Deixe uma resposta

O seu endereço de e-mail não será publicado. Campos obrigatórios são marcados com *

*