Eclipse Community Forums - RDF feed Eclipse Community Forums cross reference / multiple files / JvmModelInferer
I started making my first steps with Xtext and the following simple model:

grammar myDSL with org.eclipse.xtext.xbase.annotations.XbaseWithAnnotations
generate myDSL "..." 

	importSection = XImportSection?
	(entities += Entity)*;

  	'package' name = QualifiedName;

	(annotations += Annotation)*
	(abstract ?= 'abstract')? 'entity' name = ID ('extends' superType = [Entity])? '{'
		(members += Member)*

	(annotations += Annotation)*
	type = JvmTypeReference name = ID;

	annotation = XAnnotation;

... and three files ...

package mymodel

abstract entity Base {
	String key
	String value

package mymodel.packageA

import java.util.Set

abstract entity TypeA extends Base {
	String name
	Set<String> properties

package mymodel.packageB

import java.util.Set
import mymodel.Base

abstract entity TypeB {
	String name
	Set<Base> properties

Everything works fine, code completion, highlighting, organize imports, ...
except the "extends Base" in file TypeA.model.

The error message is:

"Couldn't resolve reference to Entity 'Base'."

Because of the fact, that 'Base' is also correctly referenced in file TypeB.model, I suppose some issue with qualified names/JvmTypeReference and/or the JvmModelInferrer in the context of the 'superType' rule!?

My current JvmModelInferrer:
class MyDSLJvmModelInferrer extends AbstractModelInferrer {

	@Inject extension JvmTypesBuilder

	@Inject extension IQualifiedNameProvider

	def dispatch void infer(Entity element, IJvmDeclaredTypeAcceptor acceptor,
		boolean isPrelinkingPhase) {

		acceptor.accept(element.toClass(element.fullyQualifiedName)).initializeLater [
			documentation = element.documentation
			for (member : element.members) {
				members += member.toField(, member.type)
				members += member.toSetter(, member.type)
				members += member.toGetter(, member.type)

Is there someone who can tell me what's wrong?

Thank you very much in advance,
Andreas Flügge 2013-04-26T10:43:25-00:00
Re: cross reference / multiple files / JvmModelInferer
yes qualified names is the problem. one solution is

superType = [Entity|QualifiedName])]]>
Christian Dietrich 2013-04-26T15:00:22-00:00
Re: cross reference / multiple files / JvmModelInferer
thanks for your reply, that solves the problem.

But I still have to add the import manually (organize imports doesn't work)!
There is also a warning in TypeA.model that the import 'Base' is never used (organize imports even removes the import, resulting in the error described first).

Any idea what's still missing?

Andreas Flügge 2013-04-29T09:34:49-00:00
Re: cross reference / multiple files / JvmModelInferer
organize imports only works for Jvm Refs]]>
Christian Dietrich 2013-04-29T09:51:20-00:00
Re: cross reference / multiple files / JvmModelInferer Is it the common way to implement two dispatching methods (for Entity and JvmTypeReference) for code generation, or is there some other mechanism?
Maybe the modelling doesn't fit?

Thank you,

Andreas Flügge 2013-04-29T11:03:41-00:00
Re: cross reference / multiple files / JvmModelInferer
actually the jvm model inferrer usesally does the generation. never the less you can always subclass JvmModelGenerator and hook into dispatch with your dsls root element.]]>
Christian Dietrich 2013-04-29T12:18:35-00:00