Skip to content

Commit

Permalink
[Parser] Remove header and impl tokens
Browse files Browse the repository at this point in the history
They cause deprecation errors since 2.0, and it looks like nobody uses them

^KT-52315 Fixed
  • Loading branch information
KvanTTT authored and qodana-bot committed Aug 9, 2024
1 parent 67088b4 commit 76592dc
Show file tree
Hide file tree
Showing 26 changed files with 38 additions and 358 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ object FirExpectActualDeclarationChecker : FirBasicDeclarationChecker(MppChecker
KtFakeSourceElementKind.DataClassGeneratedMembers -> false
KtFakeSourceElementKind.EnumGeneratedDeclaration -> false
KtFakeSourceElementKind.ImplicitConstructor -> false
else -> hasModifier(KtTokens.ACTUAL_KEYWORD) || hasModifier(KtTokens.IMPL_KEYWORD)
else -> hasModifier(KtTokens.ACTUAL_KEYWORD)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,23 +130,12 @@ object FirModifierChecker : FirBasicDeclarationChecker(MppCheckerKind.Common) {
return false
}

if (parent is FirRegularClass) {
if (modifierToken == KtTokens.EXPECT_KEYWORD || modifierToken == KtTokens.HEADER_KEYWORD) {
reporter.reportOn(modifierSource, FirErrors.WRONG_MODIFIER_TARGET, modifierToken, "nested class", context)
return false
}
if (parent is FirRegularClass && modifierToken == KtTokens.EXPECT_KEYWORD) {
reporter.reportOn(modifierSource, FirErrors.WRONG_MODIFIER_TARGET, modifierToken, "nested class", context)
return false
}

val deprecatedModifierReplacement = deprecatedKmpModifierMap[modifierToken]
if (deprecatedModifierReplacement != null) {
reporter.reportOn(
modifierSource,
FirErrors.DEPRECATED_MODIFIER,
modifierToken,
deprecatedModifierReplacement,
context
)
} else if (checkModifier(FirErrors.DEPRECATED_MODIFIER_FOR_TARGET)) {
if (checkModifier(FirErrors.DEPRECATED_MODIFIER_FOR_TARGET)) {
checkModifier(FirErrors.REDUNDANT_MODIFIER_FOR_TARGET)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ open class Modifier(var modifiers: Long = ModifierFlag.NONE.value) {

fun hasCrossinline(): Boolean = hasFlag(ModifierFlag.PARAMETER_CROSSINLINE)

fun hasExpect(): Boolean = hasFlag(ModifierFlag.PLATFORM_EXPECT) || hasFlag(ModifierFlag.PLATFORM_HEADER)
fun hasExpect(): Boolean = hasFlag(ModifierFlag.PLATFORM_EXPECT)

fun hasActual(): Boolean = hasFlag(ModifierFlag.PLATFORM_ACTUAL) || hasFlag(ModifierFlag.PLATFORM_IMPL)
fun hasActual(): Boolean = hasFlag(ModifierFlag.PLATFORM_ACTUAL)

fun hasConst(): Boolean = hasFlag(ModifierFlag.PARAMETER_CONST)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,10 @@ enum class ModifierFlag(val value: Long) {
PARAMETER_CONST(1L shl 28),
PLATFORM_EXPECT(1L shl 29),
PLATFORM_ACTUAL(1L shl 30),
PLATFORM_HEADER(1L shl 31),
PLATFORM_IMPL(1L shl 32),
VARIANCE_IN(1L shl 33),
VARIANCE_OUT(1L shl 34),
VARIANCE_INVARIANT(1L shl 35),
REIFICATION_REIFIED(1L shl 36);
VARIANCE_IN(1L shl 31),
VARIANCE_OUT(1L shl 32),
VARIANCE_INVARIANT(1L shl 33),
REIFICATION_REIFIED(1L shl 34);

companion object {
val ElementTypeToModifierFlagMap: Map<IElementType, ModifierFlag> = mutableMapOf(
Expand Down Expand Up @@ -89,8 +87,6 @@ enum class ModifierFlag(val value: Long) {
// Platform
KtTokens.EXPECT_KEYWORD to PLATFORM_EXPECT,
KtTokens.ACTUAL_KEYWORD to PLATFORM_ACTUAL,
KtTokens.HEADER_KEYWORD to PLATFORM_HEADER,
KtTokens.IMPL_KEYWORD to PLATFORM_IMPL,

// Variance
KtTokens.IN_KEYWORD to VARIANCE_IN,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,13 +246,8 @@ public void checkModifiersForDestructuringDeclaration(@NotNull KtDestructuringDe
private void checkIllegalHeader(@NotNull KtModifierListOwner modifierListOwner, @NotNull DeclarationDescriptor descriptor) {
// Most cases are already handled by ModifierCheckerCore, only check nested classes here
KtModifierList modifierList = modifierListOwner.getModifierList();
PsiElement keyword = modifierList != null ? modifierList.getModifier(HEADER_KEYWORD) : null;
if (keyword != null &&
descriptor instanceof ClassDescriptor && descriptor.getContainingDeclaration() instanceof ClassDescriptor) {
trace.report(WRONG_MODIFIER_TARGET.on(keyword, KtTokens.HEADER_KEYWORD, "nested class"));
}
else if (keyword == null && modifierList != null) {
keyword = modifierList.getModifier(EXPECT_KEYWORD);
if (modifierList != null) {
PsiElement keyword = modifierList.getModifier(EXPECT_KEYWORD);
if (keyword != null &&
descriptor instanceof ClassDescriptor && descriptor.getContainingDeclaration() instanceof ClassDescriptor) {
trace.report(WRONG_MODIFIER_TARGET.on(keyword, KtTokens.EXPECT_KEYWORD, "nested class"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,9 @@ object ModifierCheckerCore {
trace.report(Errors.WRONG_MODIFIER_TARGET.on(node.psi, modifier, actualTargets.firstOrNull()?.description ?: "this"))
return false
}
val deprecatedModifierReplacement = deprecatedKmpModifierMap[modifier]
val deprecatedTargets = deprecatedTargetMap[modifier] ?: emptySet()
val redundantTargets = redundantTargetMap[modifier] ?: emptySet()
when {
deprecatedModifierReplacement != null ->
trace.report(Errors.DEPRECATED_MODIFIER.on(node.psi, modifier, deprecatedModifierReplacement))
actualTargets.any { it in deprecatedTargets } ->
trace.report(
Errors.DEPRECATED_MODIFIER_FOR_TARGET.on(
Expand Down
15 changes: 5 additions & 10 deletions compiler/psi/src/org/jetbrains/kotlin/lexer/KtTokens.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,9 @@ public interface KtTokens {
int INFIX_KEYWORD_Id = 142;
int CONST_KEYWORD_Id = 143;
int SUSPEND_KEYWORD_Id = 144;
int HEADER_KEYWORD_Id = 145;
int IMPL_KEYWORD_Id = 146;
int EXPECT_KEYWORD_Id = 147;
int ACTUAL_KEYWORD_Id = 148;
int INTERPOLATION_PREFIX_Id = 149;
int EXPECT_KEYWORD_Id = 145;
int ACTUAL_KEYWORD_Id = 146;
int INTERPOLATION_PREFIX_Id = 147;

KtToken EOF = new KtToken("EOF", EOF_Id);

Expand Down Expand Up @@ -347,9 +345,6 @@ public interface KtTokens {

KtModifierKeywordToken SUSPEND_KEYWORD = KtModifierKeywordToken.softKeywordModifier("suspend", SUSPEND_KEYWORD_Id);

KtModifierKeywordToken HEADER_KEYWORD = KtModifierKeywordToken.softKeywordModifier("header", HEADER_KEYWORD_Id);
KtModifierKeywordToken IMPL_KEYWORD = KtModifierKeywordToken.softKeywordModifier("impl", IMPL_KEYWORD_Id);

KtModifierKeywordToken EXPECT_KEYWORD = KtModifierKeywordToken.softKeywordModifier("expect", EXPECT_KEYWORD_Id);
KtModifierKeywordToken ACTUAL_KEYWORD = KtModifierKeywordToken.softKeywordModifier("actual", ACTUAL_KEYWORD_Id);

Expand All @@ -374,7 +369,7 @@ public interface KtTokens {
LATEINIT_KEYWORD,
DATA_KEYWORD, INLINE_KEYWORD, NOINLINE_KEYWORD, TAILREC_KEYWORD, EXTERNAL_KEYWORD,
ANNOTATION_KEYWORD, CROSSINLINE_KEYWORD, CONST_KEYWORD, OPERATOR_KEYWORD, INFIX_KEYWORD,
SUSPEND_KEYWORD, HEADER_KEYWORD, IMPL_KEYWORD, EXPECT_KEYWORD, ACTUAL_KEYWORD,
SUSPEND_KEYWORD, EXPECT_KEYWORD, ACTUAL_KEYWORD,
VALUE_KEYWORD, CONTEXT_KEYWORD
);

Expand All @@ -390,7 +385,7 @@ public interface KtTokens {
REIFIED_KEYWORD, COMPANION_KEYWORD, SEALED_KEYWORD, LATEINIT_KEYWORD,
DATA_KEYWORD, INLINE_KEYWORD, NOINLINE_KEYWORD, TAILREC_KEYWORD, EXTERNAL_KEYWORD, ANNOTATION_KEYWORD, CROSSINLINE_KEYWORD,
CONST_KEYWORD, OPERATOR_KEYWORD, INFIX_KEYWORD, SUSPEND_KEYWORD,
HEADER_KEYWORD, IMPL_KEYWORD, EXPECT_KEYWORD, ACTUAL_KEYWORD, FUN_KEYWORD, VALUE_KEYWORD
EXPECT_KEYWORD, ACTUAL_KEYWORD, FUN_KEYWORD, VALUE_KEYWORD
};

TokenSet MODIFIER_KEYWORDS = TokenSet.create(MODIFIER_KEYWORDS_ARRAY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,13 @@ private val MODIFIERS_TO_REPLACE = mapOf(
PROTECTED_KEYWORD to listOf(PUBLIC_KEYWORD, PRIVATE_KEYWORD, INTERNAL_KEYWORD),
PRIVATE_KEYWORD to listOf(PUBLIC_KEYWORD, PROTECTED_KEYWORD, INTERNAL_KEYWORD),
INTERNAL_KEYWORD to listOf(PUBLIC_KEYWORD, PROTECTED_KEYWORD, PRIVATE_KEYWORD),
HEADER_KEYWORD to listOf(IMPL_KEYWORD, ACTUAL_KEYWORD, EXPECT_KEYWORD),
IMPL_KEYWORD to listOf(HEADER_KEYWORD, EXPECT_KEYWORD, ACTUAL_KEYWORD),
EXPECT_KEYWORD to listOf(IMPL_KEYWORD, ACTUAL_KEYWORD, HEADER_KEYWORD),
ACTUAL_KEYWORD to listOf(HEADER_KEYWORD, EXPECT_KEYWORD, IMPL_KEYWORD)
EXPECT_KEYWORD to listOf(ACTUAL_KEYWORD),
ACTUAL_KEYWORD to listOf(EXPECT_KEYWORD),
)

val MODIFIERS_ORDER = listOf(
PUBLIC_KEYWORD, PROTECTED_KEYWORD, PRIVATE_KEYWORD, INTERNAL_KEYWORD,
HEADER_KEYWORD, IMPL_KEYWORD, EXPECT_KEYWORD, ACTUAL_KEYWORD,
EXPECT_KEYWORD, ACTUAL_KEYWORD,
FINAL_KEYWORD, OPEN_KEYWORD, ABSTRACT_KEYWORD, SEALED_KEYWORD,
CONST_KEYWORD,
EXTERNAL_KEYWORD,
Expand Down
8 changes: 4 additions & 4 deletions compiler/psi/src/org/jetbrains/kotlin/psi/psiUtil/psiUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -457,11 +457,11 @@ inline fun <reified T : PsiElement> PsiElement.getLastParentOfTypeInRow() = pare
inline fun <reified T : PsiElement> PsiElement.getLastParentOfTypeInRowWithSelf() = parentsWithSelf
.takeWhile { it is T }.lastOrNull() as? T

fun KtModifierListOwner.hasExpectModifier() = hasModifier(KtTokens.HEADER_KEYWORD) || hasModifier(KtTokens.EXPECT_KEYWORD)
fun KtModifierList.hasExpectModifier() = hasModifier(KtTokens.HEADER_KEYWORD) || hasModifier(KtTokens.EXPECT_KEYWORD)
fun KtModifierListOwner.hasExpectModifier() = hasModifier(KtTokens.EXPECT_KEYWORD)
fun KtModifierList.hasExpectModifier() = hasModifier(KtTokens.EXPECT_KEYWORD)

fun KtModifierListOwner.hasActualModifier() = hasModifier(KtTokens.IMPL_KEYWORD) || hasModifier(KtTokens.ACTUAL_KEYWORD)
fun KtModifierList.hasActualModifier() = hasModifier(KtTokens.IMPL_KEYWORD) || hasModifier(KtTokens.ACTUAL_KEYWORD)
fun KtModifierListOwner.hasActualModifier() = hasModifier(KtTokens.ACTUAL_KEYWORD)
fun KtModifierList.hasActualModifier() = hasModifier(KtTokens.ACTUAL_KEYWORD)
fun KtModifierList.hasSuspendModifier() = hasModifier(KtTokens.SUSPEND_KEYWORD)

fun KtModifierList.hasFunModifier() = hasModifier(KtTokens.FUN_KEYWORD)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ object KotlinStubVersions {
// Though only kotlin declarations (no code in the bodies) are stubbed, please do increase this version
// if you are not 100% sure it can be avoided.
// Increasing this version will lead to reindexing of all kotlin source files on the first IDE startup with the new version.
const val SOURCE_STUB_VERSION = 162
const val SOURCE_STUB_VERSION = 163

// Binary stub version should be increased if stub format (org.jetbrains.kotlin.psi.stubs.impl) is changed
// or changes are made to the core stub building code (org.jetbrains.kotlin.idea.decompiler.stubBuilder).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ private fun buildCompatibilityMap(): Map<Pair<KtKeywordToken, KtKeywordToken>, C
// (see the KEEP https://github.com/Kotlin/KEEP/blob/master/proposals/sealed-class-inheritance.md)
result += incompatibilityRegister(SEALED_KEYWORD, INNER_KEYWORD)

// header / expect / impl / actual are all incompatible
result += incompatibilityRegister(HEADER_KEYWORD, EXPECT_KEYWORD, IMPL_KEYWORD, ACTUAL_KEYWORD)
// expect / actual are all incompatible
result += incompatibilityRegister(EXPECT_KEYWORD, ACTUAL_KEYWORD)

return result
}
Expand Down Expand Up @@ -128,8 +128,6 @@ private fun compatibilityRegister(
val featureDependencies = mapOf(
SUSPEND_KEYWORD to listOf(LanguageFeature.Coroutines),
INLINE_KEYWORD to listOf(LanguageFeature.InlineProperties, LanguageFeature.InlineClasses),
HEADER_KEYWORD to listOf(LanguageFeature.MultiPlatformProjects),
IMPL_KEYWORD to listOf(LanguageFeature.MultiPlatformProjects),
EXPECT_KEYWORD to listOf(LanguageFeature.MultiPlatformProjects),
ACTUAL_KEYWORD to listOf(LanguageFeature.MultiPlatformProjects),
LATEINIT_KEYWORD to listOf(LanguageFeature.LateinitTopLevelProperties, LanguageFeature.LateinitLocalVariables),
Expand Down Expand Up @@ -235,28 +233,6 @@ val possibleTargetMap = mapOf(
CONST_KEYWORD to EnumSet.of(KotlinTarget.MEMBER_PROPERTY, KotlinTarget.TOP_LEVEL_PROPERTY),
OPERATOR_KEYWORD to EnumSet.of(KotlinTarget.FUNCTION),
INFIX_KEYWORD to EnumSet.of(KotlinTarget.FUNCTION),
HEADER_KEYWORD to EnumSet.of(
KotlinTarget.TOP_LEVEL_FUNCTION,
KotlinTarget.TOP_LEVEL_PROPERTY,
KotlinTarget.CLASS_ONLY,
KotlinTarget.OBJECT,
KotlinTarget.INTERFACE,
KotlinTarget.ENUM_CLASS,
KotlinTarget.ANNOTATION_CLASS
),
IMPL_KEYWORD to EnumSet.of(
KotlinTarget.TOP_LEVEL_FUNCTION,
KotlinTarget.MEMBER_FUNCTION,
KotlinTarget.TOP_LEVEL_PROPERTY,
KotlinTarget.MEMBER_PROPERTY,
KotlinTarget.CONSTRUCTOR,
KotlinTarget.CLASS_ONLY,
KotlinTarget.OBJECT,
KotlinTarget.INTERFACE,
KotlinTarget.ENUM_CLASS,
KotlinTarget.ANNOTATION_CLASS,
KotlinTarget.TYPEALIAS
),
EXPECT_KEYWORD to EnumSet.of(
KotlinTarget.TOP_LEVEL_FUNCTION,
KotlinTarget.TOP_LEVEL_PROPERTY,
Expand Down Expand Up @@ -288,11 +264,6 @@ val deprecatedTargetMap = mapOf<KtKeywordToken, Set<KotlinTarget>>()

val deprecatedParentTargetMap = mapOf<KtKeywordToken, Set<KotlinTarget>>()

val deprecatedKmpModifierMap = mapOf(
HEADER_KEYWORD to EXPECT_KEYWORD,
IMPL_KEYWORD to ACTUAL_KEYWORD
)

// NOTE: redundant targets must be possible!
val redundantTargetMap = mapOf<KtKeywordToken, Set<KotlinTarget>>(
OPEN_KEYWORD to EnumSet.of(KotlinTarget.INTERFACE)
Expand Down

This file was deleted.

Loading

0 comments on commit 76592dc

Please sign in to comment.