From 975a8df4c111ceb1212c9ef283d2430fadb8b603 Mon Sep 17 00:00:00 2001 From: Felipe Zorzo Date: Wed, 30 Aug 2023 21:48:09 -0300 Subject: [PATCH] feat: Replace usages of Enum.values() by Enum.entries (new in Kotlin 1.9) --- .../src/main/kotlin/org/sonar/plsqlopen/lexer/PlSqlLexer.kt | 6 ++++-- .../kotlin/org/sonar/plugins/plsqlopen/api/DclGrammar.kt | 2 +- .../kotlin/org/sonar/plugins/plsqlopen/api/PlSqlKeyword.kt | 6 +++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/zpa-core/src/main/kotlin/org/sonar/plsqlopen/lexer/PlSqlLexer.kt b/zpa-core/src/main/kotlin/org/sonar/plsqlopen/lexer/PlSqlLexer.kt index acd88251..76644df8 100644 --- a/zpa-core/src/main/kotlin/org/sonar/plsqlopen/lexer/PlSqlLexer.kt +++ b/zpa-core/src/main/kotlin/org/sonar/plsqlopen/lexer/PlSqlLexer.kt @@ -76,9 +76,11 @@ object PlSqlLexer { .withChannel(regexp(PlSqlTokenType.INTEGER_LITERAL, INTEGER_LITERAL)) .withChannel(regexp(PlSqlTokenType.STRING_LITERAL, STRING_LITERAL)) .withChannel(regexp(PlSqlTokenType.DATE_LITERAL, DATE_LITERAL)) - .withChannel(IdentifierAndKeywordChannel(or(SIMPLE_IDENTIFIER, QUOTED_IDENTIFIER), false, PlSqlKeyword.values())) + .withChannel(IdentifierAndKeywordChannel(or(SIMPLE_IDENTIFIER, QUOTED_IDENTIFIER), false, + PlSqlKeyword.entries.toTypedArray() + )) .withChannel(RegexPunctuatorChannel(*PlSqlPunctuator.values().filter { it.isRegex }.toTypedArray())) - .withChannel(PunctuatorChannel(*PlSqlPunctuator.values().filter { !it.isRegex }.toTypedArray())) + .withChannel(PunctuatorChannel(*PlSqlPunctuator.entries.filter { !it.isRegex }.toTypedArray())) .withChannel(BlackHoleChannel("(?is)" + or( "\\s&&?$SIMPLE_IDENTIFIER", "\\\$if.*?\\\$then", diff --git a/zpa-core/src/main/kotlin/org/sonar/plugins/plsqlopen/api/DclGrammar.kt b/zpa-core/src/main/kotlin/org/sonar/plugins/plsqlopen/api/DclGrammar.kt index 220a0327..c980ea28 100644 --- a/zpa-core/src/main/kotlin/org/sonar/plugins/plsqlopen/api/DclGrammar.kt +++ b/zpa-core/src/main/kotlin/org/sonar/plugins/plsqlopen/api/DclGrammar.kt @@ -44,7 +44,7 @@ enum class DclGrammar : GrammarRuleKey { } private fun createDclCommands(b: PlSqlGrammarBuilder) { - val keywords = PlSqlKeyword.values().toList() + val keywords = PlSqlKeyword.entries val rest = keywords.subList(1, keywords.size).toTypedArray() b.rule(IDENTIFIER_OR_KEYWORD).define(b.firstOf(GenericTokenType.IDENTIFIER, keywords[0], *rest)) diff --git a/zpa-core/src/main/kotlin/org/sonar/plugins/plsqlopen/api/PlSqlKeyword.kt b/zpa-core/src/main/kotlin/org/sonar/plugins/plsqlopen/api/PlSqlKeyword.kt index 1f333536..93a4b6ad 100644 --- a/zpa-core/src/main/kotlin/org/sonar/plugins/plsqlopen/api/PlSqlKeyword.kt +++ b/zpa-core/src/main/kotlin/org/sonar/plugins/plsqlopen/api/PlSqlKeyword.kt @@ -509,10 +509,10 @@ enum class PlSqlKeyword(override val value: String, val isReserved: Boolean = fa override fun hasToBeSkippedFromAst(node: AstNode?) = false companion object { - fun keywordValues(): Array = - values().map { it.value }.toTypedArray() + val keywordValues: List = + entries.map { it.value } val nonReservedKeywords: List = - values().filter { !it.isReserved } + entries.filter { !it.isReserved } } }