generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(actions): add WhenConditionValidator for dynamic actions
Add WhenConditionValidator to validate conditions for dynamic actions. - Introduce WhenConditionValidator class - Implement isAvailable method for condition validation - Update DynamicShireAction to use WhenConditionValidator
- Loading branch information
Showing
4 changed files
with
64 additions
and
5 deletions.
There are no files selected for viewing
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
50 changes: 50 additions & 0 deletions
50
shirelang/src/main/kotlin/com/phodal/shirelang/actions/validator/WhenConditionValidator.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,50 @@ | ||
package com.phodal.shirelang.actions.validator | ||
|
||
import com.intellij.psi.PsiFile | ||
import com.phodal.shirelang.compiler.hobbit.FrontMatterType | ||
import com.phodal.shirelang.compiler.hobbit.Statement | ||
|
||
/** | ||
* Intention variable for condition include: | ||
* - filePath | ||
* - fileName | ||
* - fileType | ||
* - fileExtension | ||
* - fileContent | ||
*/ | ||
class WhenConditionValidator( | ||
private val filePath: String, | ||
private val fileName: String, | ||
private val fileType: String, | ||
private val fileExtension: String, | ||
private val fileContent: String | ||
) { | ||
|
||
fun variables(): Map<String, String> { | ||
return mapOf( | ||
"filePath" to filePath, | ||
"fileName" to fileName, | ||
"fileType" to fileType, | ||
"fileExtension" to fileExtension, | ||
"fileContent" to fileContent | ||
) | ||
} | ||
|
||
companion object { | ||
fun build(file: PsiFile): WhenConditionValidator { | ||
return WhenConditionValidator( | ||
file.virtualFile.path, | ||
file.name, | ||
file.fileType.name, | ||
file.fileType.defaultExtension, | ||
file.text | ||
) | ||
} | ||
|
||
fun isAvailable(conditions: FrontMatterType.Expression, file: PsiFile): Boolean { | ||
val variables: Map<String, String> = build(file).variables() | ||
return (conditions.value as Statement).evaluate(variables) == true | ||
} | ||
} | ||
|
||
} |
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