Skip to content

Commit

Permalink
Merge pull request #4 from modelix/kotlin-conversion
Browse files Browse the repository at this point in the history
Kotlin conversion
  • Loading branch information
slisson authored Dec 9, 2023
2 parents 630aa51 + ec3bc7c commit 70293ee
Show file tree
Hide file tree
Showing 358 changed files with 21,628 additions and 20,855 deletions.
1 change: 1 addition & 0 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:

jobs:
pre-commit:
if: false
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ modelix-model-api-gen = { id = "org.modelix.model-api-gen", version.ref = "model
npm-publish = { id = "dev.petuska.npm.publish", version = "3.4.1" }

[versions]
modelixCore = "3.15.0"
modelixCore = "3.15.1"

[libraries]
modelix-model-api = { group = "org.modelix", name = "model-api", version.ref = "modelixCore" }
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package de.slisson.mps.reflection.runtime

import java.lang.reflect.Field
import java.lang.reflect.Modifier

/*Generated by MPS */
object ReflectionUtil {
fun readField(cls: Class<*>, obj: Any?, fieldName: String): Any {
return try {
val field = cls.getDeclaredField(fieldName)
field.setAccessible(true)
field[obj]
} catch (ex: Exception) {
throw RuntimeException("Cannot read field '$fieldName' in class '$cls' of object: $obj", ex)
}
}

fun writeField(cls: Class<*>, obj: Any, fieldName: String, value: Any?) {
try {
val field = cls.getDeclaredField(fieldName)
field.setAccessible(true)
if (Modifier.isFinal(field.modifiers)) {
val modifiersField = Field::class.java.getDeclaredField("modifiers")
modifiersField.setAccessible(true)
val originalModifier = field.modifiers
modifiersField.setInt(field, originalModifier and Modifier.FINAL.inv())
}
field[obj] = value
} catch (ex: Exception) {
throw RuntimeException("Cannot write field '$fieldName' in class '$cls' of object: $obj", ex)
}
}

fun callMethod(
cls: Class<*>,
obj: Any?,
methodName: String,
argumentTypes: Array<Class<*>?>,
arguments: Array<Any?>,
): Any {
return try {
val method = cls.getDeclaredMethod(methodName, *argumentTypes)
method.setAccessible(true)
method.invoke(obj, *arguments)
} catch (ex: Exception) {
throw RuntimeException("Cannot call method '$methodName' in class '$cls' of object: $obj", ex)
}
}

fun callVoidMethod(
cls: Class<*>,
obj: Any?,
methodName: String,
argumentTypes: Array<Class<*>?>,
arguments: Array<Any?>,
) {
callMethod(cls, obj, methodName, argumentTypes, arguments)
}

fun callStaticMethod(
cls: Class<*>,
methodName: String,
argumentTypes: Array<Class<*>?>,
arguments: Array<Any?>,
): Any {
return callMethod(cls, null, methodName, argumentTypes, arguments)
}

fun callStaticVoidMethod(
cls: Class<*>,
methodName: String,
argumentTypes: Array<Class<*>?>,
arguments: Array<Any?>,
) {
callStaticMethod(cls, methodName, argumentTypes, arguments)
}

fun getClass(fqName: String?): Class<*> {
return try {
Class.forName(fqName)
} catch (ex: ClassNotFoundException) {
throw RuntimeException("", ex)
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.modelix.common

import org.modelix.kotlin.utils.ContextValue

/*Generated by MPS */
object AuthorOverride {
var AUTHOR: ContextValue<String> = ContextValue()
private var instanceOwner: String? = null
fun setInstanceOwner(owner: String?) {
instanceOwner = owner
}

fun apply(author: String?): String? {
val override: String? = AUTHOR.getValueOrNull()
if ((override != null && override.length > 0)) {
return override
}
if ((author == null || author.length == 0) && (instanceOwner != null && instanceOwner!!.length > 0)) {
return instanceOwner
}
return author
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.modelix.common

/*Generated by MPS */
object InstanceJwtToken {
var token: String = System.getenv("INITIAL_JWT_TOKEN")
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.modelix.common

/*Generated by MPS */
object PropertyOrEnv {
operator fun get(name: String?): String? {
var value: String? = System.getProperty(name)
if ((value == null || value.length == 0)) {
value = System.getenv(name)
}
if ((value == null || value.length == 0) && name!!.contains(".")) {
val withoutDots: String = name.replace('.', '_')
value = System.getProperty(withoutDots)
if ((value == null || value.length == 0)) {
value = System.getenv(withoutDots)
}
}
return value
}

fun getOrElse(name: String?, defaultValue: String?): String {
val value: String? = get(name)
return (if ((value != null && value.length > 0)) value else (defaultValue)!!)
}

fun getOrElseBoolean(name: String?, defaultValue: Boolean): Boolean {
val value: String? = get(name)
return (if ((value != null && value.length > 0)) value.toBoolean() else defaultValue)
}
}
Loading

0 comments on commit 70293ee

Please sign in to comment.