Local sealed classes are deprecated

This commit is contained in:
Mikhail Glukhikh
2015-11-20 18:10:02 +03:00
parent f98703dcdb
commit 284c1b2ec5
6 changed files with 25 additions and 1 deletions
@@ -127,6 +127,7 @@ public interface Errors {
DiagnosticFactory1<PsiElement, KtModifierKeywordToken> REPEATED_MODIFIER = DiagnosticFactory1.create(ERROR);
DiagnosticFactory2<PsiElement, KtModifierKeywordToken, KtModifierKeywordToken> REDUNDANT_MODIFIER = DiagnosticFactory2.create(WARNING);
DiagnosticFactory2<PsiElement, KtModifierKeywordToken, String> WRONG_MODIFIER_TARGET = DiagnosticFactory2.create(ERROR);
DiagnosticFactory2<PsiElement, KtModifierKeywordToken, String> DEPRECATED_MODIFIER_FOR_TARGET = DiagnosticFactory2.create(WARNING);
DiagnosticFactory2<PsiElement, KtModifierKeywordToken, String> REDUNDANT_MODIFIER_FOR_TARGET = DiagnosticFactory2.create(WARNING);
DiagnosticFactory2<PsiElement, KtModifierKeywordToken, String> WRONG_MODIFIER_CONTAINING_DECLARATION = DiagnosticFactory2.create(ERROR);
DiagnosticFactory2<PsiElement, KtModifierKeywordToken, String> DEPRECATED_MODIFIER_CONTAINING_DECLARATION = DiagnosticFactory2.create(WARNING);
@@ -129,6 +129,7 @@ public class DefaultErrorMessages {
MAP.put(DEPRECATED_MODIFIER_PAIR, "Modifier ''{0}'' is deprecated in presence of ''{1}''", TO_STRING, TO_STRING);
MAP.put(REPEATED_MODIFIER, "Repeated ''{0}''", TO_STRING);
MAP.put(WRONG_MODIFIER_TARGET, "Modifier ''{0}'' is not applicable to ''{1}''", TO_STRING, TO_STRING);
MAP.put(DEPRECATED_MODIFIER_FOR_TARGET, "Modifier ''{0}'' is deprecated for ''{1}''", TO_STRING, TO_STRING);
MAP.put(REDUNDANT_MODIFIER_FOR_TARGET, "Modifier ''{0}'' is redundant for ''{1}''", TO_STRING, TO_STRING);
MAP.put(WRONG_MODIFIER_CONTAINING_DECLARATION, "Modifier ''{0}'' is not applicable inside ''{1}''", TO_STRING, TO_STRING);
MAP.put(DEPRECATED_MODIFIER_CONTAINING_DECLARATION, "Modifier ''{0}'' is deprecated inside ''{1}''", TO_STRING, TO_STRING);
@@ -88,6 +88,12 @@ public object ModifierCheckerCore {
INFIX_KEYWORD to EnumSet.of(FUNCTION)
)
// NOTE: deprecated targets must be possible!
private val deprecatedTargetMap = mapOf<KtModifierKeywordToken, Set<KotlinTarget>>(
// Deprecated in 1.0 beta 3
SEALED_KEYWORD to EnumSet.of(LOCAL_CLASS)
)
// NOTE: redundant targets must be possible!
private val redundantTargetMap = mapOf<KtModifierKeywordToken, Set<KotlinTarget>>(
ABSTRACT_KEYWORD to EnumSet.of(INTERFACE),
@@ -227,8 +233,12 @@ public object ModifierCheckerCore {
trace.report(Errors.WRONG_MODIFIER_TARGET.on(node.psi, modifier, actualTargets.firstOrNull()?.description ?: "this"))
return false
}
val deprecatedTargets = deprecatedTargetMap[modifier] ?: emptySet()
val redundantTargets = redundantTargetMap[modifier] ?: emptySet()
if (actualTargets.any { it in redundantTargets}) {
if (actualTargets.any { it in deprecatedTargets }) {
trace.report(Errors.DEPRECATED_MODIFIER_FOR_TARGET.on(node.psi, modifier, actualTargets.firstOrNull()?.description ?: "this"))
}
else if (actualTargets.any { it in redundantTargets }) {
trace.report(Errors.REDUNDANT_MODIFIER_FOR_TARGET.on(node.psi, modifier, actualTargets.firstOrNull()?.description ?: "this"))
}
return true
@@ -0,0 +1,3 @@
fun foo() {
<!DEPRECATED_MODIFIER_FOR_TARGET!>sealed<!> class My
}
@@ -0,0 +1,3 @@
package
public fun foo(): kotlin.Unit
@@ -13989,6 +13989,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("LocalSealed.kt")
public void testLocalSealed() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/sealed/LocalSealed.kt");
doTest(fileName);
}
@TestMetadata("NeverConstructed.kt")
public void testNeverConstructed() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/sealed/NeverConstructed.kt");