All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.prezi.spaghetti.kotlin.AbstractKotlinMethodGeneratorVisitor.groovy Maven / Gradle / Ivy

The newest version!
package com.prezi.spaghetti.kotlin

import com.prezi.spaghetti.ast.MethodNode
import com.prezi.spaghetti.ast.MethodParameterNode

abstract class AbstractKotlinMethodGeneratorVisitor extends AbstractKotlinGeneratorVisitor {

	@Override
	String visitMethodNode(MethodNode node) {
		def returnType = node.returnType.accept(this)
		returnType = wrapNullableTypeReference(returnType, node)
		def typeParams = node.typeParameters ? "<" + node.typeParameters*.name.join(", ") + "> " : ""
		def params = node.parameters*.accept(this).join(", ")

		return \
"""	fun ${typeParams}${node.name}(${params}):${returnType}
"""
	}

	@Override
	String visitMethodParameterNode(MethodParameterNode node) {
		def type = node.type.accept(this)
		type = wrapNullableTypeReference(type, node)
		def result = node.name + ':' + type
		if (node.isOptional()) {
			result = result + "? = null"
		}
		return result
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy