From 4e1a90ee614c3fc6fc2c916314c2a8f3e2f71986 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Thu, 14 May 2015 15:55:51 +0300 Subject: [PATCH] Diagnostics for incorrect enum members order, when enum entry follows enum member. A few diagnostic tests. Now incorrect enum members order is treated as a warning. --- .../jetbrains/kotlin/diagnostics/Errors.java | 1 + .../rendering/DefaultErrorMessages.java | 1 + .../jetbrains/kotlin/parsing/JetParsing.java | 58 ++++++++++++------- .../kotlin/resolve/DeclarationsChecker.java | 13 +++++ .../tests/enum/enumEntriesAtTheEnd.kt | 9 +++ .../tests/enum/enumEntriesAtTheEnd.txt | 57 ++++++++++++++++++ .../diagnostics/tests/enum/enumMixed.kt | 9 +++ .../diagnostics/tests/enum/enumMixed.txt | 57 ++++++++++++++++++ .../tests/enum/enumMixedWithCommas.kt | 9 +++ .../tests/enum/enumMixedWithCommas.txt | 57 ++++++++++++++++++ .../tests/enum/enumMixedWithSemicolons.kt | 9 +++ .../tests/enum/enumMixedWithSemicolons.txt | 57 ++++++++++++++++++ .../psi/EnumSemicolonBetweenWithMembers.txt | 37 ++++-------- .../checkers/JetDiagnosticsTestGenerated.java | 24 ++++++++ 14 files changed, 351 insertions(+), 47 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/enum/enumEntriesAtTheEnd.kt create mode 100644 compiler/testData/diagnostics/tests/enum/enumEntriesAtTheEnd.txt create mode 100644 compiler/testData/diagnostics/tests/enum/enumMixed.kt create mode 100644 compiler/testData/diagnostics/tests/enum/enumMixed.txt create mode 100644 compiler/testData/diagnostics/tests/enum/enumMixedWithCommas.kt create mode 100644 compiler/testData/diagnostics/tests/enum/enumMixedWithCommas.txt create mode 100644 compiler/testData/diagnostics/tests/enum/enumMixedWithSemicolons.kt create mode 100644 compiler/testData/diagnostics/tests/enum/enumMixedWithSemicolons.txt diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index c749a0e082f..fe6b9c41729 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -213,6 +213,7 @@ public interface Errors { DiagnosticFactory1 LOCAL_ENUM_NOT_ALLOWED = DiagnosticFactory1.create(ERROR, DECLARATION_NAME); DiagnosticFactory2 ENUM_ENTRY_USES_DEPRECATED_OR_NO_DELIMITER = DiagnosticFactory2.create(WARNING, DECLARATION_NAME); DiagnosticFactory1 ENUM_ENTRY_USES_DEPRECATED_SUPER_CONSTRUCTOR = DiagnosticFactory1.create(WARNING, DELEGATOR_SUPER_CALL); + DiagnosticFactory1 ENUM_ENTRY_AFTER_ENUM_MEMBER = DiagnosticFactory1.create(WARNING, DECLARATION_NAME); // Companion objects diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java index 6245a7536b4..144c0fe4732 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -259,6 +259,7 @@ public class DefaultErrorMessages { MAP.put(LOCAL_ENUM_NOT_ALLOWED, "Enum class ''{0}'' cannot be local", NAME); MAP.put(ENUM_ENTRY_USES_DEPRECATED_OR_NO_DELIMITER, "Enum entry ''{0}'' should have a correct delimiter ''{1}'' after it", NAME, STRING); MAP.put(ENUM_ENTRY_USES_DEPRECATED_SUPER_CONSTRUCTOR, "Enum entry ''{0}'' uses deprecated super constructor syntax, use ENTRY(arguments) instead", NAME); + 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(UNMET_TRAIT_REQUIREMENT, "Super interface ''{0}'' requires subclasses to extend ''{1}''", NAME, NAME); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/parsing/JetParsing.java b/compiler/frontend/src/org/jetbrains/kotlin/parsing/JetParsing.java index 26a3c8a304e..dfcccf4a910 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/parsing/JetParsing.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/parsing/JetParsing.java @@ -754,7 +754,7 @@ public class JetParsing extends AbstractJetParsing { parseEnumEntries(); // TODO: syntax without SEMICOLON is deprecated, KT-7605 consumeIf(SEMICOLON); - parseMembers(); + parseMembers(true); // Members can include also entries, but it's deprecated syntax expect(RBRACE, "Expecting '}' to close enum class body"); myBuilder.restoreNewlinesState(); @@ -771,30 +771,34 @@ public class JetParsing extends AbstractJetParsing { if (!parseEnumEntry()) { break; } - // TODO: syntax with SEMICOLON between enum entries is deprecated, KT-7605 - if (at(SEMICOLON)) { - // Semicolon can be legally here only if member follows - PsiBuilder.Marker temp = mark(); + parseEnumEntryDelimiter(); + } + } + + private void parseEnumEntryDelimiter() { + // TODO: syntax with SEMICOLON between enum entries is deprecated, KT-7605 + if (at(SEMICOLON)) { + // Semicolon can be legally here only if member follows + PsiBuilder.Marker temp = mark(); + advance(); // SEMICOLON + ModifierDetector detector = new ModifierDetector(); + parseModifierList(detector, ONLY_ESCAPED_REGULAR_ANNOTATIONS); + if (!atSet(SOFT_KEYWORDS_AT_MEMBER_START) && at(IDENTIFIER)) { + // Otherwise it's old syntax that's not supported + temp.rollbackTo(); + // Despite of the error, try to restore and parse next enum entry + temp = mark(); advance(); // SEMICOLON - ModifierDetector detector = new ModifierDetector(); - parseModifierList(detector, ONLY_ESCAPED_REGULAR_ANNOTATIONS); - if (!atSet(SOFT_KEYWORDS_AT_MEMBER_START) && at(IDENTIFIER)) { - // Otherwise it's old syntax that's not supported - temp.rollbackTo(); - // Despite of the error, try to restore and parse next enum entry - temp = mark(); - advance(); // SEMICOLON - temp.error("Expecting ','"); - } - else { - temp.rollbackTo(); - } + temp.error("Expecting ','"); } else { - // TODO: syntax without COMMA is deprecated (only last entry is an exception), KT-7605 - consumeIf(COMMA); + temp.rollbackTo(); } } + else { + // TODO: syntax without COMMA is deprecated (only last entry is an exception), KT-7605 + consumeIf(COMMA); + } } /* @@ -879,11 +883,23 @@ public class JetParsing extends AbstractJetParsing { * ; */ private void parseMembers() { + parseMembers(false); + } + + private void parseMembers(boolean deprecatedEnumEntryPossible) { while (!eof()) { if (at(RBRACE)) { break; } - parseMemberDeclaration(); + if (deprecatedEnumEntryPossible && parseEnumEntry()) { + // Enum entry is deprecated here + // Error is generated later in DeclarationsChecker + parseEnumEntryDelimiter(); + consumeIf(SEMICOLON); + } + else { + parseMemberDeclaration(); + } } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DeclarationsChecker.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DeclarationsChecker.java index 5ed9d7aac42..9833a32e1cc 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DeclarationsChecker.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DeclarationsChecker.java @@ -585,6 +585,16 @@ public class DeclarationsChecker { return !enumEntryExpectedDelimiter(enumEntry).isEmpty(); } + static public boolean enumEntryAfterEnumMember(@NotNull JetEnumEntry enumEntry) { + PsiElement previous = enumEntry.getPrevSibling(); + while (previous != null) { + if (previous instanceof JetEnumEntry) return false; + if (previous instanceof JetDeclaration) return true; + previous = previous.getPrevSibling(); + } + return false; + } + private void checkEnumEntry(@NotNull JetEnumEntry enumEntry, @NotNull ClassDescriptor classDescriptor) { DeclarationDescriptor declaration = classDescriptor.getContainingDeclaration(); assert DescriptorUtils.isEnumClass(declaration) : "Enum entry should be declared in enum class: " + classDescriptor; @@ -597,6 +607,9 @@ public class DeclarationsChecker { if (!neededDelimiter.isEmpty()) { trace.report(Errors.ENUM_ENTRY_USES_DEPRECATED_OR_NO_DELIMITER.on(enumEntry, classDescriptor, neededDelimiter)); } + if (enumEntryAfterEnumMember(enumEntry)) { + trace.report(Errors.ENUM_ENTRY_AFTER_ENUM_MEMBER.on(enumEntry, classDescriptor)); + } List delegationSpecifiers = enumEntry.getDelegationSpecifiers(); ConstructorDescriptor constructor = enumClass.getUnsubstitutedPrimaryConstructor(); diff --git a/compiler/testData/diagnostics/tests/enum/enumEntriesAtTheEnd.kt b/compiler/testData/diagnostics/tests/enum/enumEntriesAtTheEnd.kt new file mode 100644 index 00000000000..cf217066119 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/enumEntriesAtTheEnd.kt @@ -0,0 +1,9 @@ +enum class MixedEnum { + companion object { + val first = 1 + } + fun foo(): String = "xyz" + ENTRY1 + ENTRY2 + ENTRY3 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/enum/enumEntriesAtTheEnd.txt b/compiler/testData/diagnostics/tests/enum/enumEntriesAtTheEnd.txt new file mode 100644 index 00000000000..64f6142c482 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/enumEntriesAtTheEnd.txt @@ -0,0 +1,57 @@ +package + +internal final enum class MixedEnum : kotlin.Enum { + public enum entry ENTRY1 : MixedEnum { + private constructor ENTRY1() + public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: MixedEnum): kotlin.Int + public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + internal final override /*1*/ /*fake_override*/ fun foo(): kotlin.String + public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final override /*1*/ /*fake_override*/ fun name(): kotlin.String + public final override /*1*/ /*fake_override*/ fun ordinal(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + public enum entry ENTRY2 : MixedEnum { + private constructor ENTRY2() + public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: MixedEnum): kotlin.Int + public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + internal final override /*1*/ /*fake_override*/ fun foo(): kotlin.String + public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final override /*1*/ /*fake_override*/ fun name(): kotlin.String + public final override /*1*/ /*fake_override*/ fun ordinal(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + public enum entry ENTRY3 : MixedEnum { + private constructor ENTRY3() + public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: MixedEnum): kotlin.Int + public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + internal final override /*1*/ /*fake_override*/ fun foo(): kotlin.String + public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final override /*1*/ /*fake_override*/ fun name(): kotlin.String + public final override /*1*/ /*fake_override*/ fun ordinal(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + private constructor MixedEnum() + public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: MixedEnum): kotlin.Int + public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + internal final fun foo(): kotlin.String + public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final override /*1*/ /*fake_override*/ fun name(): kotlin.String + public final override /*1*/ /*fake_override*/ fun ordinal(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + internal companion object Companion { + private constructor Companion() + internal final val first: kotlin.Int = 1 + 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 + } + + // Static members + public final /*synthesized*/ fun valueOf(/*0*/ value: kotlin.String): MixedEnum + public final /*synthesized*/ fun values(): kotlin.Array +} diff --git a/compiler/testData/diagnostics/tests/enum/enumMixed.kt b/compiler/testData/diagnostics/tests/enum/enumMixed.kt new file mode 100644 index 00000000000..2833ebf11aa --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/enumMixed.kt @@ -0,0 +1,9 @@ +enum class MixedEnum { + ENTRY1 + companion object { + val first = 1 + } + ENTRY2 + fun foo(): String = "xyz" + ENTRY3 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/enum/enumMixed.txt b/compiler/testData/diagnostics/tests/enum/enumMixed.txt new file mode 100644 index 00000000000..64f6142c482 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/enumMixed.txt @@ -0,0 +1,57 @@ +package + +internal final enum class MixedEnum : kotlin.Enum { + public enum entry ENTRY1 : MixedEnum { + private constructor ENTRY1() + public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: MixedEnum): kotlin.Int + public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + internal final override /*1*/ /*fake_override*/ fun foo(): kotlin.String + public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final override /*1*/ /*fake_override*/ fun name(): kotlin.String + public final override /*1*/ /*fake_override*/ fun ordinal(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + public enum entry ENTRY2 : MixedEnum { + private constructor ENTRY2() + public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: MixedEnum): kotlin.Int + public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + internal final override /*1*/ /*fake_override*/ fun foo(): kotlin.String + public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final override /*1*/ /*fake_override*/ fun name(): kotlin.String + public final override /*1*/ /*fake_override*/ fun ordinal(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + public enum entry ENTRY3 : MixedEnum { + private constructor ENTRY3() + public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: MixedEnum): kotlin.Int + public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + internal final override /*1*/ /*fake_override*/ fun foo(): kotlin.String + public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final override /*1*/ /*fake_override*/ fun name(): kotlin.String + public final override /*1*/ /*fake_override*/ fun ordinal(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + private constructor MixedEnum() + public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: MixedEnum): kotlin.Int + public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + internal final fun foo(): kotlin.String + public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final override /*1*/ /*fake_override*/ fun name(): kotlin.String + public final override /*1*/ /*fake_override*/ fun ordinal(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + internal companion object Companion { + private constructor Companion() + internal final val first: kotlin.Int = 1 + 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 + } + + // Static members + public final /*synthesized*/ fun valueOf(/*0*/ value: kotlin.String): MixedEnum + public final /*synthesized*/ fun values(): kotlin.Array +} diff --git a/compiler/testData/diagnostics/tests/enum/enumMixedWithCommas.kt b/compiler/testData/diagnostics/tests/enum/enumMixedWithCommas.kt new file mode 100644 index 00000000000..8b44dcdb63a --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/enumMixedWithCommas.kt @@ -0,0 +1,9 @@ +enum class MixedEnum { + ENTRY1, + companion object { + val first = 1 + } + ENTRY2, + fun foo(): String = "xyz" + ENTRY3 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/enum/enumMixedWithCommas.txt b/compiler/testData/diagnostics/tests/enum/enumMixedWithCommas.txt new file mode 100644 index 00000000000..64f6142c482 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/enumMixedWithCommas.txt @@ -0,0 +1,57 @@ +package + +internal final enum class MixedEnum : kotlin.Enum { + public enum entry ENTRY1 : MixedEnum { + private constructor ENTRY1() + public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: MixedEnum): kotlin.Int + public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + internal final override /*1*/ /*fake_override*/ fun foo(): kotlin.String + public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final override /*1*/ /*fake_override*/ fun name(): kotlin.String + public final override /*1*/ /*fake_override*/ fun ordinal(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + public enum entry ENTRY2 : MixedEnum { + private constructor ENTRY2() + public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: MixedEnum): kotlin.Int + public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + internal final override /*1*/ /*fake_override*/ fun foo(): kotlin.String + public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final override /*1*/ /*fake_override*/ fun name(): kotlin.String + public final override /*1*/ /*fake_override*/ fun ordinal(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + public enum entry ENTRY3 : MixedEnum { + private constructor ENTRY3() + public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: MixedEnum): kotlin.Int + public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + internal final override /*1*/ /*fake_override*/ fun foo(): kotlin.String + public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final override /*1*/ /*fake_override*/ fun name(): kotlin.String + public final override /*1*/ /*fake_override*/ fun ordinal(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + private constructor MixedEnum() + public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: MixedEnum): kotlin.Int + public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + internal final fun foo(): kotlin.String + public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final override /*1*/ /*fake_override*/ fun name(): kotlin.String + public final override /*1*/ /*fake_override*/ fun ordinal(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + internal companion object Companion { + private constructor Companion() + internal final val first: kotlin.Int = 1 + 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 + } + + // Static members + public final /*synthesized*/ fun valueOf(/*0*/ value: kotlin.String): MixedEnum + public final /*synthesized*/ fun values(): kotlin.Array +} diff --git a/compiler/testData/diagnostics/tests/enum/enumMixedWithSemicolons.kt b/compiler/testData/diagnostics/tests/enum/enumMixedWithSemicolons.kt new file mode 100644 index 00000000000..cb3b917cfce --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/enumMixedWithSemicolons.kt @@ -0,0 +1,9 @@ +enum class MixedEnum { + ENTRY1; + companion object { + val first = 1 + } + ENTRY2; + fun foo(): String = "xyz" + ENTRY3 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/enum/enumMixedWithSemicolons.txt b/compiler/testData/diagnostics/tests/enum/enumMixedWithSemicolons.txt new file mode 100644 index 00000000000..64f6142c482 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/enumMixedWithSemicolons.txt @@ -0,0 +1,57 @@ +package + +internal final enum class MixedEnum : kotlin.Enum { + public enum entry ENTRY1 : MixedEnum { + private constructor ENTRY1() + public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: MixedEnum): kotlin.Int + public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + internal final override /*1*/ /*fake_override*/ fun foo(): kotlin.String + public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final override /*1*/ /*fake_override*/ fun name(): kotlin.String + public final override /*1*/ /*fake_override*/ fun ordinal(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + public enum entry ENTRY2 : MixedEnum { + private constructor ENTRY2() + public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: MixedEnum): kotlin.Int + public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + internal final override /*1*/ /*fake_override*/ fun foo(): kotlin.String + public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final override /*1*/ /*fake_override*/ fun name(): kotlin.String + public final override /*1*/ /*fake_override*/ fun ordinal(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + public enum entry ENTRY3 : MixedEnum { + private constructor ENTRY3() + public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: MixedEnum): kotlin.Int + public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + internal final override /*1*/ /*fake_override*/ fun foo(): kotlin.String + public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final override /*1*/ /*fake_override*/ fun name(): kotlin.String + public final override /*1*/ /*fake_override*/ fun ordinal(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + private constructor MixedEnum() + public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: MixedEnum): kotlin.Int + public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + internal final fun foo(): kotlin.String + public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final override /*1*/ /*fake_override*/ fun name(): kotlin.String + public final override /*1*/ /*fake_override*/ fun ordinal(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + internal companion object Companion { + private constructor Companion() + internal final val first: kotlin.Int = 1 + 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 + } + + // Static members + public final /*synthesized*/ fun valueOf(/*0*/ value: kotlin.String): MixedEnum + public final /*synthesized*/ fun values(): kotlin.Array +} diff --git a/compiler/testData/psi/EnumSemicolonBetweenWithMembers.txt b/compiler/testData/psi/EnumSemicolonBetweenWithMembers.txt index 8940dc5a323..9387c30c840 100644 --- a/compiler/testData/psi/EnumSemicolonBetweenWithMembers.txt +++ b/compiler/testData/psi/EnumSemicolonBetweenWithMembers.txt @@ -30,15 +30,10 @@ JetFile: EnumSemicolonBetweenWithMembers.kt INTEGER_CONSTANT PsiElement(INTEGER_LITERAL)('1') PsiWhiteSpace('\n ') - MODIFIER_LIST - ANNOTATION_ENTRY - CONSTRUCTOR_CALLEE - TYPE_REFERENCE - USER_TYPE - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('SOUTH') - PsiErrorElement:Expecting member declaration - PsiElement(SEMICOLON)(';') + ENUM_ENTRY + OBJECT_DECLARATION_NAME + PsiElement(IDENTIFIER)('SOUTH') + PsiElement(SEMICOLON)(';') PsiWhiteSpace('\n ') OBJECT_DECLARATION MODIFIER_LIST @@ -64,24 +59,14 @@ JetFile: EnumSemicolonBetweenWithMembers.kt PsiWhiteSpace('\n ') PsiElement(RBRACE)('}') PsiWhiteSpace('\n ') - MODIFIER_LIST - ANNOTATION_ENTRY - CONSTRUCTOR_CALLEE - TYPE_REFERENCE - USER_TYPE - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('WEST') - PsiErrorElement:Expecting member declaration + ENUM_ENTRY + OBJECT_DECLARATION_NAME + PsiElement(IDENTIFIER)('WEST') + PsiErrorElement:Expecting ',' PsiElement(SEMICOLON)(';') PsiWhiteSpace('\n ') - MODIFIER_LIST - ANNOTATION_ENTRY - CONSTRUCTOR_CALLEE - TYPE_REFERENCE - USER_TYPE - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('EAST') - PsiErrorElement:Expecting member declaration - + ENUM_ENTRY + OBJECT_DECLARATION_NAME + PsiElement(IDENTIFIER)('EAST') PsiWhiteSpace('\n') PsiElement(RBRACE)('}') \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java index c3aa35caf79..839037dfb6d 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java @@ -4188,6 +4188,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { doTest(fileName); } + @TestMetadata("enumEntriesAtTheEnd.kt") + public void testEnumEntriesAtTheEnd() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/enum/enumEntriesAtTheEnd.kt"); + doTest(fileName); + } + @TestMetadata("enumEntryCannotHaveClassObject.kt") public void testEnumEntryCannotHaveClassObject() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/enum/enumEntryCannotHaveClassObject.kt"); @@ -4230,6 +4236,24 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { doTest(fileName); } + @TestMetadata("enumMixed.kt") + public void testEnumMixed() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/enum/enumMixed.kt"); + doTest(fileName); + } + + @TestMetadata("enumMixedWithCommas.kt") + public void testEnumMixedWithCommas() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/enum/enumMixedWithCommas.kt"); + doTest(fileName); + } + + @TestMetadata("enumMixedWithSemicolons.kt") + public void testEnumMixedWithSemicolons() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/enum/enumMixedWithSemicolons.kt"); + doTest(fileName); + } + @TestMetadata("enumModifier.kt") public void testEnumModifier() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/enum/enumModifier.kt");