Minor: Extract code for checking Dalvik identifiers to frontend
This commit is contained in:
+22
@@ -0,0 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
|
* that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
@file:JvmName("DalvikIdentifierUtils")
|
||||||
|
package org.jetbrains.kotlin.resolve.jvm.checkers
|
||||||
|
|
||||||
|
fun isValidDalvikIdentifier(identifier: String) = identifier.all { isValidDalvikCharacter(it) }
|
||||||
|
|
||||||
|
// https://source.android.com/devices/tech/dalvik/dex-format.html#string-syntax
|
||||||
|
private fun isValidDalvikCharacter(c: Char) = when (c) {
|
||||||
|
in 'A'..'Z' -> true
|
||||||
|
in 'a'..'z' -> true
|
||||||
|
in '0'..'9' -> true
|
||||||
|
'$', '-', '_' -> true
|
||||||
|
in '\u00a1' .. '\u1fff' -> true
|
||||||
|
in '\u2010' .. '\u2027' -> true
|
||||||
|
in '\u2030' .. '\ud7ff' -> true
|
||||||
|
in '\ue000' .. '\uffef' -> true
|
||||||
|
else -> false
|
||||||
|
}
|
||||||
+2
-14
@@ -39,6 +39,7 @@ import org.jetbrains.kotlin.idea.quickfix.RenameIdentifierFix
|
|||||||
import org.jetbrains.kotlin.lexer.KtTokens
|
import org.jetbrains.kotlin.lexer.KtTokens
|
||||||
import org.jetbrains.kotlin.psi.KtPsiUtil
|
import org.jetbrains.kotlin.psi.KtPsiUtil
|
||||||
import org.jetbrains.kotlin.psi.KtVisitorVoid
|
import org.jetbrains.kotlin.psi.KtVisitorVoid
|
||||||
|
import org.jetbrains.kotlin.resolve.jvm.checkers.isValidDalvikIdentifier
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
class IllegalIdentifierInspection : AbstractKotlinInspection() {
|
class IllegalIdentifierInspection : AbstractKotlinInspection() {
|
||||||
@@ -59,7 +60,7 @@ class IllegalIdentifierInspection : AbstractKotlinInspection() {
|
|||||||
// This is already an error
|
// This is already an error
|
||||||
if (unquotedName.isEmpty()) return
|
if (unquotedName.isEmpty()) return
|
||||||
|
|
||||||
if (!unquotedName.all { isValidDalvikCharacter(it) } && checkAndroidFacet(element)) {
|
if (!isValidDalvikIdentifier(unquotedName) && checkAndroidFacet(element)) {
|
||||||
if (element.isInUnitTests()) {
|
if (element.isInUnitTests()) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -94,19 +95,6 @@ class IllegalIdentifierInspection : AbstractKotlinInspection() {
|
|||||||
private fun checkAndroidFacet(element: PsiElement): Boolean {
|
private fun checkAndroidFacet(element: PsiElement): Boolean {
|
||||||
return element.getAndroidFacetForFile() != null || ApplicationManager.getApplication().isUnitTestMode
|
return element.getAndroidFacetForFile() != null || ApplicationManager.getApplication().isUnitTestMode
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://source.android.com/devices/tech/dalvik/dex-format.html#string-syntax
|
|
||||||
private fun isValidDalvikCharacter(c: Char) = when (c) {
|
|
||||||
in 'A'..'Z' -> true
|
|
||||||
in 'a'..'z' -> true
|
|
||||||
in '0'..'9' -> true
|
|
||||||
'$', '-', '_' -> true
|
|
||||||
in '\u00a1' .. '\u1fff' -> true
|
|
||||||
in '\u2010' .. '\u2027' -> true
|
|
||||||
in '\u2030' .. '\ud7ff' -> true
|
|
||||||
in '\ue000' .. '\uffef' -> true
|
|
||||||
else -> false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user