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(compiler): refactor built-in methods to enum class #18
Refactored built-in methods from MethodCall to ExpressionBuiltInMethod enum class for better code organization and readability. This change also includes updates to the WhenConditionCompletionProvider and ShireExpression classes to use the new enum class.
- Loading branch information
Showing
3 changed files
with
58 additions
and
54 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
...elang/src/main/kotlin/com/phodal/shirelang/compiler/hobbit/ast/ExpressionBuiltInMethod.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,37 @@ | ||
package com.phodal.shirelang.compiler.hobbit.ast | ||
|
||
/** | ||
* This enum class `ExpressionBuiltInMethod` provides a set of built-in methods for string manipulation in Kotlin. | ||
* Each enum constant represents a specific built-in method, and holds information about the method's name, description, | ||
* the string to be inserted after the method call, and the position to move the caret to after insertion. | ||
* | ||
*/ | ||
enum class ExpressionBuiltInMethod( | ||
val methodName: String, | ||
val description: String, | ||
val postInsertString: String = "()", | ||
val moveCaret: Int = 2, | ||
) { | ||
LENGTH("length", "The length of the string"), | ||
TRIM("trim", "The trimmed string"), | ||
CONTAINS("contains", "Check if the string contains a substring", "(\"\")", 2), | ||
STARTS_WITH("startsWith", "Check if the string starts with a substring", "(\"\")", 2), | ||
ENDS_WITH("endsWith", "Check if the string ends with a substring", "(\"\")", 2), | ||
LOWERCASE("lowercase", "The lowercase version of the string"), | ||
UPPERCASE("uppercase", "The uppercase version of the string"), | ||
IS_EMPTY("isEmpty", "Check if the string is empty"), | ||
IS_NOT_EMPTY("isNotEmpty", "Check if the string is not empty"), | ||
FIRST("first", "The first character of the string"), | ||
LAST("last", "The last character of the string"), | ||
MATCHES("matches", "Check if the string matches a regex pattern", "(\"//\")", 3); | ||
|
||
companion object { | ||
fun fromString(methodName: String): ExpressionBuiltInMethod? { | ||
return values().find { it.methodName == methodName } | ||
} | ||
|
||
fun completionProvider(): Array<ExpressionBuiltInMethod> { | ||
return values() | ||
} | ||
} | ||
} |
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