Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » cross reference / multiple files / JvmModelInferer
cross reference / multiple files / JvmModelInferer [message #1049847] Fri, 26 April 2013 10:43 Go to next message
Andreas  Flügge is currently offline Andreas Flügge
Messages: 12
Registered: July 2009
Junior Member
Hello!

I started making my first steps with Xtext and the following simple model:

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

Model:
	PackageDeclaration
	importSection = XImportSection?
	(entities += Entity)*;

PackageDeclaration:
  	'package' name = QualifiedName;

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

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

Annotation:
	annotation = XAnnotation;


... and three files ...

Base.model:
package mymodel

abstract entity Base {
	String key
	String value
}


TypeA.model:
package mymodel.packageA

import java.util.Set

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


TypeB.model:
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.name, member.type)
				members += member.toSetter(member.name, member.type)
				members += member.toGetter(member.name, member.type)
			}
		]
	}
}


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

Thank you very much in advance,
Andreas
Re: cross reference / multiple files / JvmModelInferer [message #1049996 is a reply to message #1049847] Fri, 26 April 2013 15:00 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6398
Registered: July 2009
Senior Member
HI,

yes qualified names is the problem. one solution is

superType = [Entity|QualifiedName])
Re: cross reference / multiple files / JvmModelInferer [message #1051852 is a reply to message #1049996] Mon, 29 April 2013 09:34 Go to previous messageGo to next message
Andreas  Flügge is currently offline Andreas Flügge
Messages: 12
Registered: July 2009
Junior Member
Hello Christian,

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?

Thanks,
Andreas
Re: cross reference / multiple files / JvmModelInferer [message #1051864 is a reply to message #1051852] Mon, 29 April 2013 09:51 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6398
Registered: July 2009
Senior Member
Hi,

organize imports only works for Jvm Refs
Re: cross reference / multiple files / JvmModelInferer [message #1051907 is a reply to message #1051864] Mon, 29 April 2013 11:03 Go to previous messageGo to next message
Andreas  Flügge is currently offline Andreas Flügge
Messages: 12
Registered: July 2009
Junior Member
Assuming I 'extend' from JvmTypeReference and would like to generate some code (concerning the members) traversing along the 'entity' hierachy.
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

Re: cross reference / multiple files / JvmModelInferer [message #1051951 is a reply to message #1051907] Mon, 29 April 2013 12:18 Go to previous message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6398
Registered: July 2009
Senior Member
Hmmm,

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. http://www.eclipse.org/forums/index.php/mv/msg/473491/1038310/#msg_1038310
Previous Topic:Using the XText Formatter
Next Topic:Building an Eclipse Product for XText
Goto Forum:
  


Current Time: Fri Oct 31 20:54:34 GMT 2014

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

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