[KAPT] KT-64301 Report invalid enum value names
Merge-request: KT-MR-13520 Merged-by: Pavel Mikhailovskii <Pavel.Mikhailovskii@jetbrains.com>
This commit is contained in:
committed by
Space Team
parent
676e350b6f
commit
1015ae858e
@@ -0,0 +1,51 @@
|
|||||||
|
/**
|
||||||
|
* public final annotation class Anno : kotlin/Annotation {
|
||||||
|
*
|
||||||
|
* // signature: <init>(LColor;)V
|
||||||
|
* public constructor(color: Color)
|
||||||
|
*
|
||||||
|
* // getter: color()LColor;
|
||||||
|
* public final val color: Color
|
||||||
|
* public final get
|
||||||
|
*
|
||||||
|
* // module name: main
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
@kotlin.Metadata()
|
||||||
|
@Anno(color = Color.InvalidFieldName)
|
||||||
|
@java.lang.annotation.Retention(value = java.lang.annotation.RetentionPolicy.RUNTIME)
|
||||||
|
public abstract @interface Anno {
|
||||||
|
|
||||||
|
public abstract Color color();
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* public final enum class Color : kotlin/Enum<Color> {
|
||||||
|
*
|
||||||
|
* // signature: <init>(Ljava/lang/String;I)V
|
||||||
|
* private constructor()
|
||||||
|
*
|
||||||
|
* BLACK,
|
||||||
|
*
|
||||||
|
* WHI-TE,
|
||||||
|
*
|
||||||
|
* // module name: main
|
||||||
|
*
|
||||||
|
* // has Enum.entries
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
@kotlin.Metadata()
|
||||||
|
public enum Color {
|
||||||
|
/*public static final*/ BLACK /* = new Color() */;
|
||||||
|
|
||||||
|
Color() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@org.jetbrains.annotations.NotNull()
|
||||||
|
public static kotlin.enums.EnumEntries<Color> getEntries() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
// FIR_BLOCKED: LC don't support illegal java identifiers
|
|
||||||
enum class Color {
|
enum class Color {
|
||||||
BLACK, `WHI-TE`
|
BLACK, `WHI-TE`
|
||||||
}
|
}
|
||||||
@@ -6,5 +5,5 @@ enum class Color {
|
|||||||
@Anno(Color.`WHI-TE`)
|
@Anno(Color.`WHI-TE`)
|
||||||
annotation class Anno(val color: Color)
|
annotation class Anno(val color: Color)
|
||||||
|
|
||||||
// EXPECTED_ERROR: (kotlin:6:1) an enum annotation value must be an enum constant
|
// EXPECTED_ERROR: (kotlin:5:1) an enum annotation value must be an enum constant
|
||||||
// EXPECTED_ERROR: (other:-1:-1) 'WHI-TE' is an invalid Java enum value name
|
// EXPECTED_ERROR: (other:-1:-1) 'WHI-TE' is an invalid Java enum value name
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ import org.jetbrains.kotlin.psi.psiUtil.parameterIndex
|
|||||||
import org.jetbrains.kotlin.resolve.calls.util.getCalleeExpressionIfAny
|
import org.jetbrains.kotlin.resolve.calls.util.getCalleeExpressionIfAny
|
||||||
import org.jetbrains.kotlin.utils.toMetadataVersion
|
import org.jetbrains.kotlin.utils.toMetadataVersion
|
||||||
import org.jetbrains.kotlin.kapt3.base.KaptOptions
|
import org.jetbrains.kotlin.kapt3.base.KaptOptions
|
||||||
|
import org.jetbrains.kotlin.kapt3.base.javac.kaptError
|
||||||
import org.jetbrains.kotlin.kapt3.stubs.MembersPositionComparator
|
import org.jetbrains.kotlin.kapt3.stubs.MembersPositionComparator
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.children
|
import org.jetbrains.kotlin.psi.psiUtil.children
|
||||||
import org.jetbrains.kotlin.utils.Printer
|
import org.jetbrains.kotlin.utils.Printer
|
||||||
@@ -466,7 +467,9 @@ private class StubGenerator(
|
|||||||
|
|
||||||
private fun convertDotQualifiedExpression(dotQualifiedExpression: KtDotQualifiedExpression): String? {
|
private fun convertDotQualifiedExpression(dotQualifiedExpression: KtDotQualifiedExpression): String? {
|
||||||
val qualifier = dotQualifiedExpression.lastChild as? KtNameReferenceExpression ?: return null
|
val qualifier = dotQualifiedExpression.lastChild as? KtNameReferenceExpression ?: return null
|
||||||
val name = qualifier.text.takeIf { isValidIdentifier(it) } ?: "InvalidFieldName"
|
val name = qualifier.text.takeIf { isValidIdentifier(it) } ?: "InvalidFieldName".also {
|
||||||
|
onError("'${qualifier.text.removeSurrounding("`")}' is an invalid Java enum value name")
|
||||||
|
}
|
||||||
val lhs = when (val left = dotQualifiedExpression.firstChild) {
|
val lhs = when (val left = dotQualifiedExpression.firstChild) {
|
||||||
is KtNameReferenceExpression -> left.getReferencedName()
|
is KtNameReferenceExpression -> left.getReferencedName()
|
||||||
is KtDotQualifiedExpression -> convertDotQualifiedExpression(left) ?: return null
|
is KtDotQualifiedExpression -> convertDotQualifiedExpression(left) ?: return null
|
||||||
|
|||||||
@@ -85,11 +85,7 @@ private fun run(
|
|||||||
WriterBackedKaptLogger(isVerbose = false),
|
WriterBackedKaptLogger(isVerbose = false),
|
||||||
)
|
)
|
||||||
val onError = { message: String ->
|
val onError = { message: String ->
|
||||||
if (context.options[KaptFlag.STRICT]) {
|
context.reportKaptError(*message.split("\n").toTypedArray())
|
||||||
context.reportKaptError(*message.split("\n").toTypedArray())
|
|
||||||
} else {
|
|
||||||
context.logger.warn(message)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return context to generateStubs(module, files, options, onError, metadataRenderer = { renderMetadata(it) })
|
return context to generateStubs(module, files, options, onError, metadataRenderer = { renderMetadata(it) })
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user