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

com.commercetools.rmf.diff.DiffUtils.kt Maven / Gradle / Ivy

Go to download

RAML API client code generators based on the REST Modeling Framework. https://github.com/vrapio/rest-modeling-framework

There is a newer version: 1.0.0-20241120142200
Show newest version
package com.commercetools.rmf.diff

import io.vrap.rmf.nodes.antlr.NodeTokenProvider
import io.vrap.rmf.raml.model.modules.Api
import io.vrap.rmf.raml.model.resources.Method
import io.vrap.rmf.raml.model.resources.Resource
import io.vrap.rmf.raml.model.types.*
import org.eclipse.emf.ecore.EObject
import org.eclipse.emf.ecore.util.EcoreUtil

fun Api.allAnyTypes(): List {
    return listOf()
        .plus(this.types)
        .plus(this.uses?.flatMap { it.library.types } ?: emptyList())
}

fun List.toAnyTypeMap(): Map {
    return this.associateBy { it.name }
}

fun List.toObjectTypeMap(): Map {
    return this.associateBy { it.name }
}

fun List.toStringTypeMap(): Map {
    return this.associateBy { it.name }
}

fun List.toResourcesMap(): Map {
    return this.associateBy { it.fullUri.template }
}

fun List.toMethodMap(): Map {
    return this.associateBy { "${it.methodName} ${it.resource().fullUri.template}" }
}

fun List.toPropertyMap(): Map {
    return this.associateBy { it.name }
}

fun List.toInstanceMap(): Map {
    return this.associateBy { it.value as String }
}

fun List.toParameterMap(): Map {
    return this.associateBy { it.name }
}

fun Api.allResourceMethods(): List = this.allContainedResources.flatMap { it.methods }

fun EObject.getSource(): Source? {
    val nodeTokenProvider = EcoreUtil.getExistingAdapter(this, NodeTokenProvider::class.java)
    if (nodeTokenProvider is NodeTokenProvider) {
        val nodeToken = nodeTokenProvider.start
        return Source(nodeToken.location, Position(nodeToken.line.toLong(), nodeToken.charPositionInLine.toLong()))
    }
    return null
}

fun Property.typeName(): String? {
    return when(this.type) {
        is ArrayType -> "${(this.type as ArrayType).items?.name}[]"
        else -> this.type?.name
    }
}

fun AnyType.typeName(): String? {
    return when(this) {
        is ArrayType -> "${this.items?.name}[]"
        else -> this.type?.name
    }
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy