Skip to content

Commit

Permalink
updating lionweb
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomassetti committed Jun 30, 2023
1 parent e28915d commit a097c3f
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ private fun Any?.toJsonElement(): JsonElement {
is Number -> toJson()
is Char -> toJson()
is Boolean -> toJson()
else -> throw IllegalArgumentException("${this} cannot be converted to JSON")
else -> throw IllegalArgumentException("$this cannot be converted to JSON")
}
}

fun jsonObject(vararg values: Pair<String, *>) : JsonObject {
fun jsonObject(vararg values: Pair<String, *>): JsonObject {
val jo = JsonObject()
values.forEach {
jo.add(it.first, it.second.toJsonElement())
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ org.gradle.jvmargs=-XX:MaxMetaspaceSize=512m
jvm_version=1.8
junit_version=4.13.2
gson_version=2.10.1
lionwebVersion=0.0.19-SNAPSHOT
lionwebVersion=0.0.22
kspVersion=1.0.11
lionwebGenGradlePluginID=com.strumenta.kolasu.lionwebgen
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import org.jetbrains.kotlin.idea.KotlinFileType
import org.jetbrains.kotlin.psi.KtDeclaration
import org.jetbrains.kotlin.psi.KtFile
import java.io.File
import kotlin.test.assertEquals

private val KtDeclaration.fqName: String
get() {
Expand All @@ -23,30 +22,30 @@ private val KtDeclaration.fqName: String
}
class KotlinCodeProcessor {

fun astClassesDeclaredInFile(code: String) : Set<String> {
fun astClassesDeclaredInFile(code: String): Set<String> {
val ktFile = parse(code)
return ktFile.declarations.map {
it.fqName
}.toSet()
}
fun classesDeclaredInFile(code: String) : Set<String> {
fun classesDeclaredInFile(code: String): Set<String> {
val ktFile = parse(code)
return ktFile.declarations.map {
it.fqName
}.toSet()
}

fun astClassesDeclaredInFile(file: File) : Set<String> {
fun astClassesDeclaredInFile(file: File): Set<String> {
require(file.isFile)
return astClassesDeclaredInFile(file.readText())
}

fun classesDeclaredInFile(file: File) : Set<String> {
fun classesDeclaredInFile(file: File): Set<String> {
require(file.isFile)
return classesDeclaredInFile(file.readText())
}

fun classesDeclaredInDir(file: File) : Set<String> {
fun classesDeclaredInDir(file: File): Set<String> {
require(file.isDirectory)
val set = mutableSetOf<String>()
file.listFiles()?.forEach {
Expand All @@ -58,7 +57,7 @@ class KotlinCodeProcessor {
return set
}

fun astClassesDeclaredInDir(file: File) : Set<String> {
fun astClassesDeclaredInDir(file: File): Set<String> {
require(file.isDirectory)
val set = mutableSetOf<String>()
file.listFiles()?.forEach {
Expand All @@ -74,11 +73,12 @@ class KotlinCodeProcessor {
val disposable = Disposer.newDisposable()
try {
val env = KotlinCoreEnvironment.createForProduction(
disposable, CompilerConfiguration(), EnvironmentConfigFiles.JVM_CONFIG_FILES)
disposable, CompilerConfiguration(), EnvironmentConfigFiles.JVM_CONFIG_FILES
)
val file = LightVirtualFile("temp.kt", KotlinFileType.INSTANCE, code)
return PsiManager.getInstance(env.project).findFile(file) as KtFile
} finally {
disposable.dispose()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ class LanguageGeneratorCommand(val language: Language) : CliktCommand() {
override fun run() {
JsonSerialization.saveLanguageToFile(language, languageFile)
}
}
}
6 changes: 2 additions & 4 deletions lionweb-gen/src/test/kotlin/ClassesGenerationFromEMFTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import org.junit.jupiter.api.Test

class ClassesGenerationFromEMFTest {

private fun loadEPackage(name: String) : EPackage {
private fun loadEPackage(name: String): EPackage {
val inputStream = this.javaClass.getResourceAsStream("/$name.ecore")
requireNotNull(inputStream)
val resource = EcoreResourceFactoryImpl().createResource(URI.createURI("resource://${name}.ecore"))
val resource = EcoreResourceFactoryImpl().createResource(URI.createURI("resource://$name.ecore"))
resource.load(inputStream, mapOf<Any, Any>())
assertEquals(1, resource.contents.size)
return resource.contents.first() as EPackage
Expand All @@ -27,7 +27,6 @@ class ClassesGenerationFromEMFTest {
val xbaseLWLanguage = emfMMImporter.importEPackage(xbasePackage)
val xtendLWLanguage = emfMMImporter.importEPackage(xtendPackage)


val generated = ASTGenerator("xtend.stuff", xtendLWLanguage).generateClasses()
assertEquals(1, generated.size)
println(generated.first().code)
Expand All @@ -39,7 +38,6 @@ class ClassesGenerationFromEMFTest {
val emfMMImporter = EMFMetamodelImporter()
val occiLWLanguage = emfMMImporter.importEPackage(occiPackage)


// val generated = ASTGenerator("xtend.stuff", xtendLWLanguage).generateClasses()
// assertEquals(1, generated.size)
// println(generated.first().code)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ public data class Property(
val existingASTClasses = KotlinCodeProcessor().astClassesDeclaredInFile(code)
assertEquals(setOf("com.strumenta.props.PropertiesFile", "com.strumenta.props.Property"), existingASTClasses)
}
}
}

0 comments on commit a097c3f

Please sign in to comment.