Skip to content
Closed
Show file tree
Hide file tree
Changes from 54 commits
Commits
Show all changes
128 commits
Select commit Hold shift + click to select a range
8488842
feat: first basic dsl
MarcoFratta Sep 3, 2025
725e116
feat: add deployments dsl
MarcoFratta Sep 4, 2025
cfa4c7f
refactor: handle generic types
MarcoFratta Sep 4, 2025
a09052c
feat: add contents handling
MarcoFratta Sep 5, 2025
e20e2b2
feat: handle linking rule
MarcoFratta Sep 5, 2025
dc58811
chore: change error message
MarcoFratta Sep 5, 2025
ff2019d
test: improve testing
MarcoFratta Sep 5, 2025
658e527
feat!: add support for actions and conditions
MarcoFratta Sep 10, 2025
3fa5ab5
test: add tests for new features
MarcoFratta Sep 10, 2025
ce0a83a
feat: add support for terminators
MarcoFratta Sep 10, 2025
73f8ade
refactor: simplify dsl syntax
MarcoFratta Sep 11, 2025
4a3fe19
feat: add support for output monitors
MarcoFratta Sep 11, 2025
4fd2023
feat: add support for layers
MarcoFratta Sep 11, 2025
99c66b3
feat: improve test framework
MarcoFratta Oct 15, 2025
2c2e61b
feat: add support for exporters and global reactions
MarcoFratta Oct 15, 2025
0cc43a9
feat: add support for variables using delegates
MarcoFratta Oct 15, 2025
728c00d
fix: fix seeds problem
MarcoFratta Oct 27, 2025
45af007
refactor: refactor dsl structure
MarcoFratta Oct 27, 2025
3377814
feat: add support for custom nodes definition
MarcoFratta Oct 28, 2025
1a00e1b
feat: add support for node properties
MarcoFratta Oct 28, 2025
3632937
refactor: add code initial documentation
MarcoFratta Nov 8, 2025
58075d0
refactor: move yml test files
MarcoFratta Nov 8, 2025
05388de
refactor: add doc and better testing
MarcoFratta Nov 8, 2025
b0c0279
feat!: add support for alchemist.kts file loading
MarcoFratta Nov 8, 2025
10197cf
feat!: add support for alchemist.kts file loading
MarcoFratta Nov 8, 2025
eab8346
test: test .alchemist.kts file loading
MarcoFratta Nov 8, 2025
0ac359f
refactor: add external imports config file
MarcoFratta Nov 8, 2025
93e7191
feat!: add ksp function helpers generator
MarcoFratta Nov 8, 2025
4feae4c
feat!: add ksp function helpers generator
MarcoFratta Nov 8, 2025
0af86c8
feat: add @BuildDsl to some classes
MarcoFratta Nov 8, 2025
4afa89a
refactor: better code organization
MarcoFratta Nov 10, 2025
d794bf8
test: add performance tests
MarcoFratta Nov 10, 2025
7de533b
feat: add support for batch runs
MarcoFratta Nov 16, 2025
b604010
feat: add custom scope definition for @BuildDsl annotation
MarcoFratta Nov 16, 2025
8439b64
test: add test simulation config
MarcoFratta Nov 16, 2025
e4be08e
chore: sync repo fork
MarcoFratta Nov 16, 2025
19cf438
Merge remote-tracking branch 'upstream/master'
MarcoFratta Nov 16, 2025
f9043ca
Merge branch 'master' into master
MarcoFratta Nov 25, 2025
66a245c
fix: remove vcs.xml changes
MarcoFratta Nov 25, 2025
e15e314
fix: remove useless file
MarcoFratta Nov 25, 2025
209b760
fix: remove .gitignore duplicated folder
MarcoFratta Nov 25, 2025
ef11fad
style: improve formatting
MarcoFratta Nov 25, 2025
2207683
refactor: refactor build.gradle.kts dependency
MarcoFratta Nov 25, 2025
417dc6a
feat: add multiplatform support
MarcoFratta Nov 25, 2025
65f756f
chore: remove useless comment
MarcoFratta Nov 25, 2025
fc36e72
feat: change alchemist script definition
MarcoFratta Nov 26, 2025
985a729
chore: add dependencies versions
MarcoFratta Nov 26, 2025
29ef41e
fix: fix processor tests
MarcoFratta Nov 26, 2025
63b8124
chore: remove println
MarcoFratta Nov 26, 2025
20da4d7
style: remove redundant parenthesis
MarcoFratta Nov 26, 2025
fac688c
style: remove redundant parenthesis
MarcoFratta Nov 26, 2025
c46b844
chore: remove not needed compiler arg
MarcoFratta Nov 26, 2025
bc0ca1c
Merge branch 'master' into master
MarcoFratta Nov 26, 2025
1f809f0
Merge branch 'master' into master
DanySK Nov 26, 2025
bd82f9f
Merge branch 'master' into master
MarcoFratta Nov 26, 2025
9830c28
feat: remove CommitMessageInspectionProfile from vcs.xml
MarcoFratta Nov 26, 2025
420e2a2
fix: fix cpd errors
MarcoFratta Nov 26, 2025
3cbeef6
fix: fix cpd errors in alchemist-loading
MarcoFratta Nov 26, 2025
4abc0a8
fix: rename sources dir names
MarcoFratta Nov 26, 2025
5a8a67c
style: fix vertical spacing inconsistencies
MarcoFratta Nov 26, 2025
f3ff0ec
style: fix vertical spacing inconsistencies
MarcoFratta Nov 26, 2025
2441330
refactor: simplify expression
MarcoFratta Nov 26, 2025
4e5ec58
refactor: simplify expressions
MarcoFratta Nov 26, 2025
45c929b
chore: add empty line at the end
MarcoFratta Nov 26, 2025
9b5f96a
refactor: change annotation from @BuildDsl to @AlchemistKotlinDSL
MarcoFratta Nov 26, 2025
3661269
docs: add missing documentation
MarcoFratta Nov 26, 2025
7e62d79
style: fix detekt errors
MarcoFratta Nov 27, 2025
751172a
style: fix detekt errors
MarcoFratta Nov 27, 2025
3351ab4
Merge branch 'master' into master
MarcoFratta Nov 28, 2025
7ed5e23
refactor: replace exporters function signature
MarcoFratta Nov 28, 2025
49a2306
refactor: better performance test
MarcoFratta Nov 28, 2025
674f211
chore(build): update the javadoc.io cache
DanySK Dec 1, 2025
2215f61
chore(build): update the javadoc.io cache
DanySK Dec 1, 2025
b6a2d28
chore(build): update the javadoc.io cache
DanySK Dec 1, 2025
caff28f
chore(build): update the javadoc.io cache
DanySK Dec 1, 2025
7ec3895
chore(build): update the javadoc.io cache
DanySK Dec 1, 2025
a89e9ff
chore(build): update the javadoc.io cache
DanySK Dec 1, 2025
4052d6f
chore(build): update the javadoc.io cache
DanySK Dec 1, 2025
4128c8e
chore(build): update the javadoc.io cache
DanySK Dec 1, 2025
bbedd33
chore(build): update the javadoc.io cache
DanySK Dec 1, 2025
f4f2b60
chore(build): update the javadoc.io cache
DanySK Dec 1, 2025
9ac4062
chore(build): update the javadoc.io cache
DanySK Dec 1, 2025
6c1fd15
chore(build): update the javadoc.io cache
DanySK Dec 1, 2025
98d5ed1
chore(build): update the javadoc.io cache
DanySK Dec 1, 2025
84a35af
chore(build): update the javadoc.io cache
DanySK Dec 1, 2025
5e8dded
chore(build): update the javadoc.io cache
DanySK Dec 1, 2025
8df2401
chore(build): update the javadoc.io cache
DanySK Dec 1, 2025
8a2f3bf
chore(build): update the javadoc.io cache
DanySK Dec 1, 2025
f2a4f3b
chore(build): update the javadoc.io cache
DanySK Dec 1, 2025
93936d3
chore(build): update the javadoc.io cache
DanySK Dec 1, 2025
c07c910
chore(build): update the javadoc.io cache
DanySK Dec 1, 2025
4f5d195
Merge branch 'master' into master
DanySK Dec 1, 2025
1c6f04b
chore(build): update the javadoc.io cache
DanySK Dec 1, 2025
f24e3dd
chore(build): update the javadoc.io cache
DanySK Dec 1, 2025
cdd5144
chore(build): update the javadoc.io cache
DanySK Dec 1, 2025
1ed4f35
chore(build): update the javadoc.io cache
DanySK Dec 1, 2025
fae4a11
chore(build): update the javadoc.io cache
DanySK Dec 1, 2025
6edb8ac
chore(deps): update react to v2025.12.0-19.2.0 (minor) (#5004)
renovate[bot] Dec 1, 2025
f312b55
Merge branch 'master' into master
DanySK Dec 2, 2025
577b5fc
Merge branch 'master' into master
DanySK Dec 13, 2025
7682742
Merge branch 'master' into master
DanySK Dec 13, 2025
474d9f0
style(dsl-processor): cleanup `ConstructorFinder`
DanySK Dec 15, 2025
5670a7f
build: remove duplicate `-Xcontext-parameters` argument in compiler o…
DanySK Dec 15, 2025
a1e5383
chore: add copyright notice to BoundProcessor.kt
DanySK Dec 15, 2025
0c32587
refactor: simplify type argument formatting in BoundProcessor.kt
DanySK Dec 15, 2025
a991691
chore: remove unnecessary blank line in build.gradle.kts
DanySK Dec 15, 2025
70629ad
chore: remove unused jvm() configuration and test dependencies in bui…
DanySK Dec 15, 2025
fbe7bda
refactor: streamline logging in DslBuilderProcessor.kt
DanySK Dec 15, 2025
4ca02f4
Merge branch 'master' into master
DanySK Dec 15, 2025
d0f788c
style: use orEmpty()
DanySK Dec 15, 2025
127731c
chore: track the dokka caches
DanySK Dec 15, 2025
5a0c4f6
fix: split support types to separate files
DanySK Dec 15, 2025
a2caf85
refactor: move InjectionType to a separate data package
DanySK Dec 15, 2025
1d5977c
refactor: improve logging and structure in DslBuilderProcessor
DanySK Dec 15, 2025
ca3c1aa
refactor: refactor the Kotlin DSL generator
DanySK Dec 18, 2025
414fec4
refactor: enhance context handling in DslBuilderProcessor and Paramet…
DanySK Dec 18, 2025
5ab4dba
refactor: extract ContextType enum to a new file for better organization
DanySK Dec 18, 2025
73be28b
refactor: simplify type checks in ParameterInjector by using isSubtypeOf
DanySK Dec 18, 2025
b2782c2
refactor: simplify manual scope check in ParameterInjector
DanySK Dec 18, 2025
2c69253
refactor: make ProcessorConfig internal and remove unused type consta…
DanySK Dec 18, 2025
9d7e889
refactor: remove redundant logging of found symbols in DslBuilderProc…
DanySK Dec 18, 2025
609179d
refactor: simplify AlchemistKotlinDSL annotation and remove unused pa…
DanySK Dec 18, 2025
e4f8700
marmellata
DanySK Dec 19, 2025
b494dec
marmellata
DanySK Dec 22, 2025
d5d3a6c
feat!: rewrite the code generator
DanySK Dec 23, 2025
136808a
refactor: suppress Detekt false positives for undocumented public fun…
DanySK Dec 23, 2025
0f3745b
refactor: streamline DslBuilderProcessor by removing unused imports a…
DanySK Dec 23, 2025
68cd5c0
feat: enhance simulation context to include RandomGenerator in DSL fu…
DanySK Dec 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,4 @@ scala_compiler.xml

# Exceptions
# Keep 'build' packages in src directories
!**/src/**/build/
!**/src/**/build/**
!**/src/**/build/
6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (C) 2010-2025, Danilo Pianini and contributors
* listed, for each module, in the respective subproject's build.gradle.kts file.
*
* This file is part of Alchemist, and is distributed under the terms of the
* GNU General Public License, with a linking exception,
* as described in the file LICENSE in the Alchemist distribution's top directory.
*/

package it.unibo.alchemist.boundary.dsl

/**
* Annotation used to mark classes that should have DSL builder functions generated.
* When applied to a class, the DSL processor will generate a builder function
* that can be used in Alchemist DSL scripts to create instances of the annotated class.
*
* @param functionName Custom name for the generated DSL function. If empty, defaults to
* the lowercase version of the class name with the first character lowercased.
* @param scope Manual override for the context type. Valid values (case-insensitive):
* - "SIMULATION" or "SIMULATION_CONTEXT" → SimulationContext
* - "EXPORTER" or "EXPORTER_CONTEXT" → ExporterContext
* - "GLOBAL_PROGRAMS" or "GLOBAL_PROGRAMS_CONTEXT" → GlobalProgramsContext
* - "OUTPUT_MONITORS" or "OUTPUT_MONITORS_CONTEXT" → OutputMonitorsContext
* - "TERMINATORS" or "TERMINATORS_CONTEXT" → TerminatorsContext
* - "DEPLOYMENT" or "DEPLOYMENTS_CONTEXT" → DeploymentsContext
* - "DEPLOYMENT_CONTEXT" → DeploymentContext (singular)
* - "PROGRAM" or "PROGRAM_CONTEXT" → ProgramContext
* - "PROPERTY" or "PROPERTY_CONTEXT" → PropertyContext
* If empty, the context type is automatically determined based on the constructor parameters.
* This allows manual context passing to override the default behavior.
* @param injectEnvironment Whether to inject an Environment parameter into the generated builder function.
* @param injectGenerator Whether to inject a Generator parameter into the generated builder function.
* @param injectNode Whether to inject a Node parameter into the generated builder function.
* @param injectReaction Whether to inject a Reaction parameter into the generated builder function.
*/
@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.SOURCE)
annotation class BuildDsl(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AlchemistKotlinDSL maybe is better?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to @AlchemistKotlinDSL

val functionName: String = "",
val scope: String = "",
val injectEnvironment: Boolean = true,
val injectGenerator: Boolean = true,
val injectNode: Boolean = true,
val injectReaction: Boolean = true,
)
25 changes: 25 additions & 0 deletions alchemist-dsl-processor/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import Libs.alchemist

plugins {
id("kotlin-multiplatform-convention")
}
kotlin {
jvm()
sourceSets {
val jvmMain by getting {
dependencies {
api(alchemist("api"))
implementation(libs.ksp.api)
}
kotlin.srcDir("src/main/kotlin")
resources.srcDir("src/main/resources")
}
val jvmTest by getting {
dependencies {
implementation(libs.bundles.testing.compile)
runtimeOnly(libs.bundles.testing.runtimeOnly)
}
kotlin.srcDir("src/test/kotlin")
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package it.unibo.alchemist.boundary.dsl.processor

import com.google.devtools.ksp.symbol.KSTypeArgument
import com.google.devtools.ksp.symbol.KSTypeReference
import com.google.devtools.ksp.symbol.Variance

/**
* Processes type bounds for type parameters, cleaning up internal Kotlin type representations.
*/
object BoundProcessor {
/**
* Processes a type bound reference, cleaning up internal Kotlin type representations and variance annotations.
*
* @param bound The type reference to process
* @param classTypeParamNames List of class type parameter names to replace in the bound
* @return A cleaned string representation of the bound with fully qualified names
*/
fun processBound(bound: KSTypeReference, classTypeParamNames: List<String> = emptyList()): String {
val resolved = bound.resolve()
val decl = resolved.declaration
val qualifiedName = decl.qualifiedName?.asString()

if (qualifiedName != null) {
val arguments = resolved.arguments
val typeString = if (arguments.isNotEmpty()) {
val typeArgs = arguments.joinToString(", ") { arg ->
formatTypeArgument(arg, classTypeParamNames)
}
"$qualifiedName<$typeArgs>"
} else {
qualifiedName
}

val nullableSuffix = if (resolved.isMarkedNullable) "?" else ""
val result = "$typeString$nullableSuffix"
return replaceClassTypeParamReferences(result, classTypeParamNames)
}

val result = TypeExtractor.extractTypeString(bound, emptyList())
return replaceClassTypeParamReferences(result, classTypeParamNames)
}

private fun formatTypeArgument(arg: KSTypeArgument, classTypeParamNames: List<String>): String = when {
arg.type == null -> "*"
arg.variance == Variance.STAR -> "*"
arg.variance == Variance.CONTRAVARIANT -> {
arg.type?.let {
val typeStr = TypeExtractor.extractTypeString(it, emptyList())
val replaced = replaceClassTypeParamReferences(typeStr, classTypeParamNames)
"in $replaced"
} ?: "*"
}
arg.variance == Variance.COVARIANT -> {
arg.type?.let {
val typeStr = TypeExtractor.extractTypeString(it, emptyList())
val replaced = replaceClassTypeParamReferences(typeStr, classTypeParamNames)
"out $replaced"
} ?: "*"
}
else -> {
arg.type?.let {
val typeStr = TypeExtractor.extractTypeString(it, emptyList())
replaceClassTypeParamReferences(typeStr, classTypeParamNames)
} ?: "*"
}
}

private fun replaceClassTypeParamReferences(boundStr: String, classTypeParamNames: List<String>): String {
if (classTypeParamNames.isEmpty()) {
return boundStr
}
var result = boundStr
classTypeParamNames.forEach { paramName ->
val pattern = Regex("""\b[\w.]+\.$paramName\b""")
result = pattern.replace(result) { matchResult ->
val matched = matchResult.value
val prefix = matched.substringBefore(".$paramName")
if (prefix.contains(".")) {
paramName
} else {
matched
}
}
}
return result
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package it.unibo.alchemist.boundary.dsl.processor

import com.google.devtools.ksp.symbol.KSClassDeclaration
import com.google.devtools.ksp.symbol.KSFunctionDeclaration
import com.google.devtools.ksp.symbol.Modifier

/**
* Finds a suitable constructor for a class declaration.
*/
object ConstructorFinder {
/**
* Finds a public constructor for the given class declaration.
* Prefers the primary constructor, otherwise returns the constructor with the most parameters.
*
* @param classDecl The class declaration to find a constructor for
* @return The found constructor, or null if no suitable constructor exists
*/
fun findConstructor(classDecl: KSClassDeclaration): KSFunctionDeclaration? {
val primaryConstructor = classDecl.primaryConstructor
if (primaryConstructor != null && isPublicConstructor(primaryConstructor)) {
return primaryConstructor
}

val constructors = classDecl.getAllFunctions()
.filter { function ->
val simpleName = function.simpleName.asString()
(simpleName == "<init>" || simpleName == classDecl.simpleName.asString()) &&
isPublicConstructor(function)
}
.sortedByDescending { it.parameters.size }

return constructors.firstOrNull()
}

private fun isPublicConstructor(function: KSFunctionDeclaration): Boolean {
val modifiers = function.modifiers
return !modifiers.contains(Modifier.PRIVATE) &&
!modifiers.contains(Modifier.PROTECTED) &&
!modifiers.contains(Modifier.INTERNAL)
}
}
Loading
Loading