Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Problem with name provide class
Problem with name provide class [message #756977] Tue, 15 November 2011 20:19 Go to next message
Fon Vitale is currently offline Fon VitaleFriend
Messages: 14
Registered: November 2011
Junior Member
Hi there!

Recently I've started working on a project that mixes xtext and Xpand. For now I'm testing to control the environment. Indeed I have tried from the initial examples to try to generate something.

I'm using the grammar that is created by default:

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

generate myDsl ... 

Model:
	greetings+=Greeting*;
	
Greeting:
	'Hello' name=ID '!';


Add an Xpand proyect and the dependence to xtext project. I define the workflow file as:

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 {
		path = modelPath
		register = org.xtext.example.mydsl.MyDslStandaloneSetup {}
		load = {
			slot = "model"
			type = "Model" 
		}
	}
	
	component = org.eclipse.xpand2.Generator {
		metaModel = org.eclipse.xtend.typesystem.emf.EmfMetaModel {
			metaModelPackage = "org.xtext.example.mydsl.myDsl.MyDslPackage"
		}
		expand = "templates::Template::main FOREACH model"
		outlet = {
			path = targetDir
		}
		fileEncoding = fileEncoding
	}
	
}


As I read in the documentation and forum for Model name does not exist, therefore must be supplied by overriding the names provider in MYDslRuntimeModule class:

MyDslNameProvider.class

package org.xtext.example.mydsl;

import org.eclipse.xtext.naming.DefaultDeclarativeQualifiedNameProvider;
import org.xtext.example.mydsl.myDsl.Model;

public class MyDslNameProvider extends DefaultDeclarativeQualifiedNameProvider {
	public String qualifiedName(Model m) {
		//return m.eResource().getURI().toString();
		return "Model";
	}

}


MyDslRuntimeModule.java

/*
 * generated by Xtext
 */
package org.xtext.example.mydsl;

/**
 * Use this class to register components to be used at runtime / without the Equinox extension registry.
 */
public class MyDslRuntimeModule extends org.xtext.example.mydsl.AbstractMyDslRuntimeModule {

	@Override
	public Class<? extends org.eclipse.xtext.naming.IQualifiedNameProvider> bindIQualifiedNameProvider() {
		return MyDslNameProvider.class;
	}
}



When I try running the worflow of the Xpand project get the following error:

0    ERROR DefaultResourceDescriptionStrategy - java.lang.String cannot be cast to org.eclipse.xtext.naming.QualifiedName
0    ERROR DefaultResourceDescriptionStrategy - java.lang.String cannot be cast to org.eclipse.xtext.naming.QualifiedName
31   WARN  SlotEntry          - Could not find any exported element of type 'Model' -> Slot 'model' is empty.
62   INFO  Workflow           - Done.


Anybody can help me?

Thank you very much.
Re: Problem with name provide class [message #756980 is a reply to message #756977] Tue, 15 November 2011 20:25 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13425
Registered: July 2009
Senior Member
Hi,

do you use Xtext 2.x? The returntype of qualifiedName has changed from String to QualifiedName
http://christiandietrich.wordpress.com/2011/07/16/iqualifiednameproviders-in-xtext-2-0/

~Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Problem with name provide class [message #756981 is a reply to message #756977] Tue, 15 November 2011 20:26 Go to previous messageGo to next message
Meinte Boersma is currently offline Meinte BoersmaFriend
Messages: 434
Registered: July 2009
Location: Leiden, Netherlands
Senior Member
Your qualifiedName method needs to return a org.eclipse.xtext.naming.QualifiedName instance. The following should work (untested):
	public QualifiedName qualifiedName(Model m) {
		//return m.eResource().getURI().toString();
		return QualifiedName.create("Model");
	}

(Darn: I need to learn to type faster to beat Christian Wink)


[Updated on: Tue, 15 November 2011 20:26]

Report message to a moderator

Re: Problem with name provide class [message #756984 is a reply to message #756977] Tue, 15 November 2011 20:31 Go to previous message
Fon Vitale is currently offline Fon VitaleFriend
Messages: 14
Registered: November 2011
Junior Member
It works... I feel so stupid. Sorry and thanks.
Previous Topic:Get the user-chosen ICompletionProposal
Next Topic:Help with expressions, pretty please?
Goto Forum:
  


Current Time: Tue Apr 07 01:45:11 GMT 2020

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

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

Back to the top