report 'trait' keyword as deprecated, provide quickfix for replacing with 'interface'

This commit is contained in:
Dmitry Jemerov
2015-05-13 19:29:15 +02:00
parent 3dce96e01c
commit dc9523016a
13 changed files with 109 additions and 1 deletions
@@ -142,6 +142,7 @@ public interface Errors {
DiagnosticFactory0<JetDelegatorToSuperClass> SUPERTYPE_NOT_INITIALIZED = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<PsiElement> DEPRECATED_TRAIT_KEYWORD = DiagnosticFactory0.create(WARNING);
DiagnosticFactory0<JetTypeReference> DELEGATION_NOT_TO_TRAIT = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<JetTypeReference> SUPERTYPE_NOT_A_CLASS_OR_TRAIT = DiagnosticFactory0.create(ERROR);
@@ -262,6 +262,7 @@ public class DefaultErrorMessages {
MAP.put(ENUM_ENTRY_AFTER_ENUM_MEMBER, "Enum entry ''{0}'' is not allowed after a member", NAME);
MAP.put(DELEGATION_IN_TRAIT, "Interfaces cannot use delegation");
MAP.put(DELEGATION_NOT_TO_TRAIT, "Only interfaces can be delegated to");
MAP.put(DEPRECATED_TRAIT_KEYWORD, "'trait' keyword is deprecated, use 'interface' instead");
MAP.put(UNMET_TRAIT_REQUIREMENT, "Super interface ''{0}'' requires subclasses to extend ''{1}''", NAME, NAME);
MAP.put(NO_CONSTRUCTOR, "This class does not have a constructor");
MAP.put(NOT_A_CLASS, "Not a class");
@@ -247,6 +247,11 @@ public class DeclarationsChecker {
checkTypeParameters(aClass);
if (aClass.isInterface()) {
ASTNode traitKeyword = aClass.getNode().findChildByType(JetTokens.TRAIT_KEYWORD);
if (traitKeyword != null) {
trace.report(Errors.DEPRECATED_TRAIT_KEYWORD.on(traitKeyword.getPsi()));
}
checkTraitModifiers(aClass);
checkConstructorInTrait(aClass);
}
@@ -0,0 +1,2 @@
<!DEPRECATED_TRAIT_KEYWORD!>trait<!> A {
}
@@ -0,0 +1,7 @@
package
internal interface A {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -181,6 +181,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("DeprecatedTraitKeyword.kt")
public void testDeprecatedTraitKeyword() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/DeprecatedTraitKeyword.kt");
doTest(fileName);
}
@TestMetadata("DiamondFunction.kt")
public void testDiamondFunction() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/DiamondFunction.kt");