From 57713466832bc2000d193087556e4f7673622d27 Mon Sep 17 00:00:00 2001 From: RedNesto Date: Fri, 13 Sep 2024 13:14:42 +0200 Subject: [PATCH] Fix deprecated JavaLexer.isKeyword usage --- src/main/kotlin/creator/custom/BuiltinValidations.kt | 5 ++--- src/main/kotlin/creator/field-validation.kt | 4 ++-- src/main/kotlin/util/Parameter.kt | 2 +- src/main/kotlin/util/utils.kt | 6 ++++-- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/creator/custom/BuiltinValidations.kt b/src/main/kotlin/creator/custom/BuiltinValidations.kt index f34e51d21..103abfe93 100644 --- a/src/main/kotlin/creator/custom/BuiltinValidations.kt +++ b/src/main/kotlin/creator/custom/BuiltinValidations.kt @@ -23,13 +23,12 @@ package com.demonwav.mcdev.creator.custom import com.demonwav.mcdev.asset.MCDevBundle import com.demonwav.mcdev.platform.fabric.util.FabricVersions import com.demonwav.mcdev.util.SemanticVersion -import com.intellij.lang.java.lexer.JavaLexer +import com.demonwav.mcdev.util.isJavaKeyword import com.intellij.openapi.ui.ComboBox import com.intellij.openapi.ui.ValidationInfo import com.intellij.openapi.ui.validation.DialogValidation import com.intellij.openapi.ui.validation.validationErrorIf import com.intellij.openapi.util.text.StringUtil -import com.intellij.pom.java.LanguageLevel import javax.swing.JComponent object BuiltinValidations { @@ -61,7 +60,7 @@ object BuiltinValidations { val validClassFqn = validationErrorIf(MCDevBundle("creator.validation.class_fqn")) { it.isBlank() || it.split('.').any { part -> - !StringUtil.isJavaIdentifier(part) || JavaLexer.isKeyword(part, LanguageLevel.HIGHEST) + !StringUtil.isJavaIdentifier(part) || part.isJavaKeyword() } } diff --git a/src/main/kotlin/creator/field-validation.kt b/src/main/kotlin/creator/field-validation.kt index 36ff5d32b..8ef9380b0 100644 --- a/src/main/kotlin/creator/field-validation.kt +++ b/src/main/kotlin/creator/field-validation.kt @@ -20,7 +20,7 @@ package com.demonwav.mcdev.creator -import com.demonwav.mcdev.util.isJavaKeyword +import com.demonwav.mcdev.util.isJavaSoftKeyword fun isValidClassName(className: String): Boolean { // default package @@ -42,5 +42,5 @@ fun isValidClassName(className: String): Boolean { return false } // keyword identifier - return !fieldNameSplit.any { it.isJavaKeyword() } + return !fieldNameSplit.any { it.isJavaSoftKeyword() } } diff --git a/src/main/kotlin/util/Parameter.kt b/src/main/kotlin/util/Parameter.kt index 28c30bbe1..0a6dcc59d 100644 --- a/src/main/kotlin/util/Parameter.kt +++ b/src/main/kotlin/util/Parameter.kt @@ -27,6 +27,6 @@ data class Parameter(val name: String?, val type: PsiType) { constructor(parameter: PsiParameter) : this(parameter.name, parameter.type) init { - assert(name?.isJavaKeyword() != true) + assert(name?.isJavaSoftKeyword() != true) } } diff --git a/src/main/kotlin/util/utils.kt b/src/main/kotlin/util/utils.kt index 66e42669a..d96ac0be8 100644 --- a/src/main/kotlin/util/utils.kt +++ b/src/main/kotlin/util/utils.kt @@ -299,14 +299,16 @@ fun String.getSimilarity(text: String, bonus: Int = 0): Int { return distance + bonus } -fun String.isJavaKeyword() = PsiUtil.isSoftKeyword(this, LanguageLevel.HIGHEST) +fun String.isJavaKeyword() = PsiUtil.isKeyword(this, LanguageLevel.HIGHEST) + +fun String.isJavaSoftKeyword() = PsiUtil.isSoftKeyword(this, LanguageLevel.HIGHEST) fun String.toJavaIdentifier(allowDollars: Boolean = true): String { if (this.isEmpty()) { return "_" } - if (this.isJavaKeyword()) { + if (this.isJavaSoftKeyword()) { return "_$this" }