Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Problem: XPand & JavaVMTypes
Problem: XPand & JavaVMTypes [message #667389] Thu, 28 April 2011 13:26 Go to next message
Tobias L. is currently offline Tobias L.Friend
Messages: 24
Registered: July 2010
Junior Member
Hello,

how I can print the "canonicalName()" from a JvmType?

The DSL is configured by the official xtext document and the references to JavaVMTypes in my Model works fine.

In my case as example:
JavaType:
    JavaPrimitive | JavaClass;
    
JavaPrimitive:
	'primitive' type=[types::JvmType|ID] 'mapped-to' name=ID ';';

JavaClass:
	'class' type=[types::JvmType|QualifiedName] 'mapped-to' name=ID ';';


and
class java.lang.Integer mapped-to Integer;
class java.lang.Long mapped-to Long;
class java.util.Date mapped-to Date;
class java.lang.String mapped-to String;

primitive boolean mapped-to boolean;
primitive int mapped-to int;
primitive long mapped-to long;


Now a have a Xpand Generator Template that should print the "type.type.canonicalName".

1. I not have any auto-completion for the JvmTypes!
2. The output is always "void"

rg.eclipse.xtext.common.types.impl.JvmVoidImpl@5932926d (eProxyURI: platform:/resource//example.valuetypes/src/model/Java.valuetypes#xtextLink_::0.0.0.3.1::1::/2)



What can I do to solve this Problem?
Any Dependency in the Manifest??!?

Thanks in advanced,
Tobias.

Re: Problem: XPand & JavaVMTypes [message #667398 is a reply to message #667389] Thu, 28 April 2011 14:11 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi Tobias,

I think there is something wrong with your setup.

I create a new Xtext Project With Wizard

Change Grammar and Workflow to

grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals

import "http://www.eclipse.org/xtext/common/JavaVMTypes" as types

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

Model: types+=JavaType*;

JavaType:
    JavaPrimitive | JavaClass;
    
JavaPrimitive:
	'primitive' type=[types::JvmType|ID] 'mapped-to' name=ID ';';

JavaClass:
	'class' type=[types::JvmType|QualifiedName] 'mapped-to' name=ID ';';
	
QualifiedName: ID("." ID)*;


module org.xtext.example.mydsl.MyDsl

import org.eclipse.emf.mwe.utils.*
import org.eclipse.xtext.generator.*
import org.eclipse.xtext.ui.generator.*

var grammarURI = "classpath:/org/xtext/example/mydsl/MyDsl.xtext"
var file.extensions = "mydsl"
var projectName = "org.xtext.example.mydsl"
var runtimeProject = "../${projectName}"

Workflow {
    bean = StandaloneSetup {
		platformUri = "${runtimeProject}/.."
	}

	component = DirectoryCleaner {
		directory = "${runtimeProject}/src-gen"
	}

	component = DirectoryCleaner {
		directory = "${runtimeProject}.ui/src-gen"
	}

	component = Generator {
		pathRtProject = runtimeProject
		pathUiProject = "${runtimeProject}.ui"
		projectNameRt = projectName
		projectNameUi = "${projectName}.ui"
		language = {
			uri = grammarURI
			fileExtensions = file.extensions

			// Java API to access grammar elements (required by several other fragments)
			fragment = grammarAccess.GrammarAccessFragment {}

			// generates Java API for the generated EPackages 
			fragment = ecore.EcoreGeneratorFragment {
				referencedGenModels="classpath:/model/JavaVMTypes.genmodel"
			}

			// the serialization component
			fragment = parseTreeConstructor.ParseTreeConstructorFragment {}

			// a custom ResourceFactory for use with EMF 
			fragment = resourceFactory.ResourceFactoryFragment {
				fileExtensions = file.extensions
			}

			// The antlr parser generator fragment.
			fragment = parser.antlr.XtextAntlrGeneratorFragment {
			//  options = {
			//		backtrack = true
			//	}
			}

			// java-based API for validation 
			fragment = validation.JavaValidatorFragment {
				composedCheck = "org.eclipse.xtext.validation.ImportUriValidator"
				composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"
				// registerForImportedPackages = true
			}

			// scoping and exporting API
			// fragment = scoping.ImportURIScopingFragment {}
			// fragment = exporting.SimpleNamesFragment {}

			// scoping and exporting API 
			fragment = scoping.ImportNamespacesScopingFragment {}
			fragment = exporting.QualifiedNamesFragment {}
			fragment = builder.BuilderIntegrationFragment {}

			// formatter API 
			fragment = formatting.FormatterFragment {}

			// labeling API 
			fragment = labeling.LabelProviderFragment {}

			// outline API 
			fragment = outline.TransformerFragment {}
			fragment = outline.OutlineNodeAdapterFactoryFragment {}
			fragment = outline.QuickOutlineFragment {}

			// quickfix API 
			fragment = quickfix.QuickfixProviderFragment {}

			// content assist API  
			fragment = contentAssist.JavaBasedContentAssistFragment {}

			// generates a more lightweight Antlr parser and lexer tailored for content assist  
			fragment = parser.antlr.XtextAntlrUiGeneratorFragment {}
			
			fragment = types.TypesGeneratorFragment {}

			// project wizard (optional) 
			// fragment = projectWizard.SimpleProjectWizardFragment {
			// 		generatorProjectName = "${projectName}.generator" 
			//		modelFileExtension = file.extensions
			// }
		}
	}
}



Go to the generator project (I have content assist there)

and use following WF and template and it works nicely
«IMPORT org::xtext::example::mydsl::myDsl»

«DEFINE main FOR List[JavaType]-»
«FILE "test.txt"-»
«FOREACH this AS type»
«type.type.canonicalName»
«ENDFOREACH»
«ENDFILE-»
«ENDDEFINE»


module workflow.MyDslGenerator

import org.eclipse.emf.mwe.utils.*

var targetDir = "src-gen"
var fileEncoding = "Cp1252"
var modelPath = "src/model"

Workflow {

	component = org.eclipse.xtext.mwe.Reader {
		// lookup all resources on the classpath
		// useJavaClassPath = true

		// or define search scope explicitly
		path = modelPath

		// this class will be generated by the xtext generator 
		register = org.xtext.example.mydsl.MyDslStandaloneSetup {}
		load = {
			slot = "types"
			type = "JavaType"
		}
	}

	component = org.eclipse.xpand2.Generator {
		expand = "templates::Template::main FOR types"
		outlet = {
			path = targetDir
		}
		fileEncoding = fileEncoding
	}
}



P.S: as you see i use JavaBeansMetamodel in the Template

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Thu, 28 April 2011 14:11]

Report message to a moderator

Re: Problem: XPand & JavaVMTypes [message #667401 is a reply to message #667389] Thu, 28 April 2011 14:27 Go to previous messageGo to next message
Tobias L. is currently offline Tobias L.Friend
Messages: 24
Registered: July 2010
Junior Member
Hi Christian,

thank you for your reply.

I use the EMF Metamodell.

What is the differences or the advantage/disadvantages of these both metamodels? I can't found an answer in google search.

I thougt, that EMF is the prefered metamodel?!

Tobias.
Re: Problem: XPand & JavaVMTypes [message #667428 is a reply to message #667401] Thu, 28 April 2011 16:12 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

The MetaModel in this case builds Xpands Typesystem. If you work with Java Classes JavaBeansMetaModel is fine in most cases. This is why it is default in Xtext. If you are using Dynamic EMF then EMF(Registry)MetaModel might be better. Same e.g. for some M2Ms.

=> You can use both but the easiest with Xtext is to use JavaBeansMM

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Problem: XPand & JavaVMTypes [message #667452 is a reply to message #667389] Thu, 28 April 2011 19:57 Go to previous messageGo to next message
Tobias L. is currently offline Tobias L.Friend
Messages: 24
Registered: July 2010
Junior Member
Hi Christian,

Thank you for your short description about MM.

How I can change the Metamodel?
Nothing works. In Window -> Preferences -> Xpand I selected JavaBeansMM as default. In Project-Settings I selected JBMM as default MM....

When I use IMPORT ....::MyDsl in Xpand there is a Warning like "Namespace ... is unknown or unused" and the whole template has errors...

Any idea?

Tobias.
Re: Problem: XPand & JavaVMTypes [message #667459 is a reply to message #667452] Thu, 28 April 2011 21:30 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

have a look what i have posted before

«IMPORT org::xtext::example::mydsl::myDsl»


component = org.eclipse.xpand2.Generator {
		expand = "templates::Template::main FOR types"
		outlet = {
			path = targetDir
		}
		fileEncoding = fileEncoding
	}


=> use JavaPackages for Imports
=> JavaBeansMetamodel ist Default

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:OutOfMemoryError: Java heap space
Next Topic:Dynamic Model Evolution in xText based DSLs
Goto Forum:
  


Current Time: Thu Apr 25 23:17:18 GMT 2024

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

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

Back to the top