generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(shirelang): add ShireToolchainFunctionProvider and update GitFun…
…ctionProvider #112 Added a new ShireToolchainFunctionProvider class to handle Shire toolchain functions. This provider supports built-in functions, variables, and processes in Shire. Also, updated the GitFunctionProvider to use 'entries' instead of 'values' for function name matching.
- Loading branch information
Showing
3 changed files
with
67 additions
and
2 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
shirelang/src/main/kotlin/com/phodal/shirelang/provider/ShireToolchainFunctionProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.phodal.shirelang.provider | ||
|
||
import com.intellij.openapi.project.Project | ||
import com.phodal.shirecore.provider.function.ToolchainFunctionProvider | ||
|
||
enum class ShireProvideType(val type: String) { | ||
Variable("variable"), | ||
Function("function"), | ||
Process("process") | ||
; | ||
|
||
companion object { | ||
fun fromString(value: String): ShireProvideType? { | ||
return entries.firstOrNull { it.type == value } | ||
} | ||
} | ||
} | ||
|
||
enum class ShireToolchainFunction(val funName: String) { | ||
/** | ||
* The provider function offers, Built-in functions in Shire, Built-in variables in Shire, Built-in processes in Shire | ||
* for example: `provider("variable")` will return all variables in tables | ||
*/ | ||
Provider("provider"); | ||
|
||
companion object { | ||
fun fromString(value: String): ShireToolchainFunction? { | ||
return entries.firstOrNull { it.funName == value } | ||
} | ||
} | ||
} | ||
|
||
class ShireToolchainFunctionProvider : ToolchainFunctionProvider { | ||
override fun isApplicable(project: Project, funcName: String): Boolean { | ||
return ShireToolchainFunction.entries.any { it.funName == funcName } | ||
} | ||
|
||
override fun execute(project: Project, funcName: String, args: List<Any>, allVariables: Map<String, Any?>): Any { | ||
val gitFunc = ShireToolchainFunction.fromString(funcName) | ||
?: throw IllegalArgumentException("Shire[Toolchain]: Invalid Toolchain function name") | ||
|
||
return when (gitFunc) { | ||
ShireToolchainFunction.Provider -> { | ||
val type = args.first() as String | ||
when (ShireProvideType.fromString(type)) { | ||
ShireProvideType.Variable -> { | ||
return allVariables | ||
} | ||
|
||
ShireProvideType.Function -> { | ||
return emptyList<Any>() | ||
} | ||
|
||
ShireProvideType.Process -> { | ||
return emptyList<Any>() | ||
} | ||
|
||
null -> TODO() | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters