Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » (Xbase)Method refers to missing type .. : List Values cannot get passed as parameter or return value
(Xbase)Method refers to missing type .. : List Values cannot get passed as parameter or return value [message #1776469] Thu, 16 November 2017 16:27 Go to next message
René Bärnreuther is currently offline René BärnreutherFriend
Messages: 31
Registered: October 2017

I'm currently struggeling to implement list types correctly because they cannot be passed as Parameter to my operations (the error "the method e(Java.util.List<Integer>) from the type Test5 (my generated class) refers to the missing type java.util.list<Integer>). I achieve the same behaviour when I try do return a List from a operation and set it to a variable of the expected list type.

The important parts of my DSL are the following:

Variable returns XVariableDeclaration:
	{Variable} writeable?='variable' simpleName=ID  ':' (typing=DataType);
	=> ({Method} 'operation' name=ValidID
	'(') (parameter+=Parameter (',' parameter+=Parameter)*)? ')' ('returns' returnTyping=DataType)?

	{Parameter} 'parameter' name=ID ':' parameterTyping=DataType;
// more stuff [..]
	(SimpleDataType | ComplexDataType | ListType);

	=> ('list' '<' type=DataType) '>';

	{SimpleDataType} typeName=('integer' | 'string' | 'rational' | 'boolean');

To use ComplexDataTypes and SimpleDataTypes as variables works as expected. Return-values work, too.

My typecomputer looks like this:

if(XVariableDeclaration instanceof Variable){

/* other types, simple datatype and complex data type */
 /* ... */ else if (vr.typing instanceof ListType) {
			state.assignType(vr, getTypeForName(listTypeUtil.getListTypeString(vr.typing as ListType), state))
			for (additional : vr.additionalVariables) {
					getTypeForName(listTypeUtil.getListTypeString(vr.typing as ListType), state))
		} }

The getListTypeString method returns for the variable "list<integer>" the type "java.util.List<Integer>" and works like this similiar for other cases.

My compiler looks like this:
	override _toJavaStatement(XVariableDeclaration variable, ITreeAppendable a, boolean isReferenced) { = variable.simpleName
		if (variable instanceof Variable) {
			if (variable.typing instanceof SimpleDataType) {
				a.append(createAppendString(variable.typing as SimpleDataType, variable))
			} else if (variable.typing instanceof ComplexDataType) { /* ComplexDataType */
				a.append(createAppendString(variable.typing as ComplexDataType, variable))
			} else if (variable.typing instanceof ListType) {
				a.append(createAppendString(variable.typing as ListType, variable))

		} else {
			super._toJavaStatement(variable, a, isReferenced)
	/* Creates variable declaration of list type  */
	def createAppendString(ListType lt, Variable vr) {
		var appendString = ""
		appendString += "java.util.List<"
		appendString += calculateInnerTypeString(lt)
		appendString += "> "
		appendString += vr.simpleName
		appendString += " = new java.util.ArrayList<"
		appendString += calculateInnerTypeString(lt)
		appendString += ">();"

InnerTypeString calculates the innertypes of the List. For list<string> it will return "String".

An example translation looks like the following:
variable liste: list<integer>
-> java.util.List<Integer> liste = new java.util.ArrayList<Integer>();

This works as expected (at least as far as I know, maybe there are better ways..).

My operations in the inferrer will be converted like this:
	 * Generates all operations in the program
	def inferMethods(List<Method> methods, List<JvmMember> members) {
		for (method : methods) {
			var type = method.returnTyping
			var returntype = getTypeRefFor(type)
			if (returntype === null) {
				returntype = typeRef(Void.TYPE)
			members += method.toMethod(, returntype) [
				for (param : method.parameter) {
					parameters += param.toParameter(, getTypeRefFor(param.parameterTyping))
				static = true
				body = method.body

	 * Returns the typeRef for the given datatype
	 * null, if no type is found
	def /* @nullable */ getTypeRefFor(DataType parameterType) {
		if (parameterType instanceof SimpleDataType) {
			return getSimpleDataType(parameterType.typeName)
		} else if (parameterType instanceof ComplexDataType) {
			var cdt = parameterType as ComplexDataType
			if (cdt.typeName instanceof Composition) {
				return typeRef((cdt.typeName as Composition).name)
			} else if (cdt.typeName instanceof Enumeration) {
				return typeRef((cdt.typeName as Enumeration).name)
		} else if (parameterType instanceof ListType) {
			return typeRef("java.util.List<" + calculateInnerTypeString(parameterType as ListType) + ">")
		} else {
			return null

So it will return "java.util.List<String>" for a returnvalue of "list<string>".

The problem arises for calls like this:
operation e(parameter l : list<integer>){
main { 
	variable listInt : list<integer>;
	listInt <-- [1,2,3]; // puts in 1,2,3 in the list

On e the error mentioned above arrises and I'm not sure why.

My guess would be that I need to type the Method and the Parameter for it explictly, is this correct or do I need to change something else to make this work?

If there are any more relevant details I forgot, feel free to ask for them.

Thanks in Advance!

Re: (Xbase)Method refers to missing type .. : List Values cannot get passed as parameter or return v [message #1776474 is a reply to message #1776469] Thu, 16 November 2017 18:29 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14336
Registered: July 2009
Senior Member
the typeRef method looks like org.eclipse.xtext.xbase.jvmmodel.JvmTypeReferenceBuilder.typeRef(String, JvmTypeReference...)

so i would have expected to use

typeRef("java.util.List", typeRef("java.lang.String"))

Need professional support for Xtext, Xpand, EMF?
Go to:
Twitter : @chrdietrich
Blog :
Previous Topic:Two DSL in same project
Next Topic:Auto-completion not working
Goto Forum:

Current Time: Thu Aug 11 15:10:36 GMT 2022

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

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

Back to the top