Skip to content

Commit

Permalink
Fix deprecated JavaLexer.isKeyword usage
Browse files Browse the repository at this point in the history
  • Loading branch information
RedNesto committed Sep 13, 2024
1 parent 07d1a7c commit 5771346
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
5 changes: 2 additions & 3 deletions src/main/kotlin/creator/custom/BuiltinValidations.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -61,7 +60,7 @@ object BuiltinValidations {

val validClassFqn = validationErrorIf<String>(MCDevBundle("creator.validation.class_fqn")) {
it.isBlank() || it.split('.').any { part ->
!StringUtil.isJavaIdentifier(part) || JavaLexer.isKeyword(part, LanguageLevel.HIGHEST)
!StringUtil.isJavaIdentifier(part) || part.isJavaKeyword()
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/creator/field-validation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -42,5 +42,5 @@ fun isValidClassName(className: String): Boolean {
return false
}
// keyword identifier
return !fieldNameSplit.any { it.isJavaKeyword() }
return !fieldNameSplit.any { it.isJavaSoftKeyword() }
}
2 changes: 1 addition & 1 deletion src/main/kotlin/util/Parameter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
6 changes: 4 additions & 2 deletions src/main/kotlin/util/utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand Down

0 comments on commit 5771346

Please sign in to comment.