SLC: add nullability annotation to value param of non-synthetic enum members

^KT-57567
This commit is contained in:
Jinseong Jeon
2023-04-05 01:18:01 -07:00
committed by Ilya Kirillov
parent 9fe30bfc12
commit 0ca86c86be
2 changed files with 9 additions and 3 deletions
@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.analysis.api.symbols.sourcePsiSafe
import org.jetbrains.kotlin.analysis.api.types.KtTypeMappingMode
import org.jetbrains.kotlin.asJava.classes.lazyPub
import org.jetbrains.kotlin.asJava.elements.KtLightIdentifier
import org.jetbrains.kotlin.builtins.StandardNames
import org.jetbrains.kotlin.light.classes.symbol.*
import org.jetbrains.kotlin.light.classes.symbol.annotations.annotateByKtType
import org.jetbrains.kotlin.light.classes.symbol.methods.SymbolLightMethodBase
@@ -59,7 +60,12 @@ internal abstract class SymbolLightParameterCommon(
if (isDeclaredAsVararg()) return NullabilityType.NotNull
val nullabilityApplicable = !containingMethod.hasModifierProperty(PsiModifier.PRIVATE) &&
!containingMethod.containingClass.let { it.isAnnotationType || it.isEnum }
!containingMethod.containingClass.isAnnotationType &&
// `enum` synthetic members (e.g., values or valueOf) are not applicable for nullability.
// In other words, `enum` non-synthetic members are applicable for nullability.
// Technically, we should retrieve the symbol for the containing method and see if its origin is not synthetic.
// But, only `enum#valueOf` has a value parameter we want to filter out, so this is cheap yet feasible.
(!containingMethod.containingClass.isEnum || containingMethod.name != StandardNames.ENUM_VALUE_OF.identifier)
return if (nullabilityApplicable) {
parameterSymbolPointer.withSymbol(ktModule) { getTypeNullability(it.returnType) }
@@ -23,7 +23,7 @@ public enum Event /* Event*/ {
@kotlin.jvm.JvmStatic()
@org.jetbrains.annotations.Nullable()
public static final Event upTo(State);// upTo(State)
public static final Event upTo(@org.jetbrains.annotations.NotNull() State);// upTo(State)
@org.jetbrains.annotations.NotNull()
public static Event valueOf(java.lang.String) throws java.lang.IllegalArgumentException, java.lang.NullPointerException;// valueOf(java.lang.String)
@@ -61,7 +61,7 @@ public enum State /* State*/ {
private State();// .ctor()
public final boolean isAtLeast(State);// isAtLeast(State)
public final boolean isAtLeast(@org.jetbrains.annotations.NotNull() State);// isAtLeast(State)
public final boolean isFinished();// isFinished()