diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/diagnostics/ErrorsJvm.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/diagnostics/ErrorsJvm.java index 3bd07dc16c4..b86a4045f21 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/diagnostics/ErrorsJvm.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/diagnostics/ErrorsJvm.java @@ -20,12 +20,15 @@ import com.intellij.psi.PsiElement; import org.jetbrains.jet.lang.diagnostics.DiagnosticFactory1; import org.jetbrains.jet.lang.diagnostics.Errors; -import static org.jetbrains.jet.lang.diagnostics.PositioningStrategies.DECLARATION_OR_DEFAULT; +import static org.jetbrains.jet.lang.diagnostics.PositioningStrategies.DECLARATION_SIGNATURE_OR_DEFAULT; import static org.jetbrains.jet.lang.diagnostics.Severity.ERROR; public interface ErrorsJvm { - DiagnosticFactory1 CONFLICTING_JVM_DECLARATIONS = DiagnosticFactory1.create(ERROR, DECLARATION_OR_DEFAULT); - DiagnosticFactory1 ACCIDENTAL_OVERRIDE = DiagnosticFactory1.create(ERROR, DECLARATION_OR_DEFAULT); + DiagnosticFactory1 CONFLICTING_JVM_DECLARATIONS = + DiagnosticFactory1.create(ERROR, DECLARATION_SIGNATURE_OR_DEFAULT); + + DiagnosticFactory1 ACCIDENTAL_OVERRIDE = + DiagnosticFactory1.create(ERROR, DECLARATION_SIGNATURE_OR_DEFAULT); @SuppressWarnings("UnusedDeclaration") Object _initializer = new Object() { diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java index 59c92b2ed48..272a91b5c17 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java @@ -19,7 +19,6 @@ package org.jetbrains.jet.lang.diagnostics; import com.google.common.collect.ImmutableSet; import com.intellij.openapi.util.TextRange; import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiNameIdentifierOwner; import com.intellij.psi.impl.source.tree.LeafPsiElement; import kotlin.Function1; import org.jetbrains.annotations.NotNull; @@ -165,8 +164,8 @@ public interface Errors { DiagnosticFactory0 DELEGATION_IN_TRAIT = DiagnosticFactory0.create(ERROR); - DiagnosticFactory2 UNMET_TRAIT_REQUIREMENT = - DiagnosticFactory2.create(ERROR, PositioningStrategies.NAME_IDENTIFIER); + DiagnosticFactory2 UNMET_TRAIT_REQUIREMENT = + DiagnosticFactory2.create(ERROR, PositioningStrategies.DECLARATION_NAME); // Enum-specific @@ -178,9 +177,9 @@ public interface Errors { DiagnosticFactory0 CLASS_IN_SUPERTYPE_FOR_ENUM = DiagnosticFactory0.create(ERROR); - DiagnosticFactory1 ENUM_ENTRY_SHOULD_BE_INITIALIZED = DiagnosticFactory1.create(ERROR, NAME_IDENTIFIER); + DiagnosticFactory1 ENUM_ENTRY_SHOULD_BE_INITIALIZED = DiagnosticFactory1.create(ERROR, DECLARATION_NAME); DiagnosticFactory1 ENUM_ENTRY_ILLEGAL_TYPE = DiagnosticFactory1.create(ERROR); - DiagnosticFactory1 LOCAL_ENUM_NOT_ALLOWED = DiagnosticFactory1.create(ERROR, NAME_IDENTIFIER); + DiagnosticFactory1 LOCAL_ENUM_NOT_ALLOWED = DiagnosticFactory1.create(ERROR, DECLARATION_NAME); // Class objects @@ -189,17 +188,17 @@ public interface Errors { // Objects - DiagnosticFactory1 LOCAL_OBJECT_NOT_ALLOWED = DiagnosticFactory1.create(ERROR, NAME_IDENTIFIER); + DiagnosticFactory1 LOCAL_OBJECT_NOT_ALLOWED = DiagnosticFactory1.create(ERROR, DECLARATION_NAME); // Type parameter declarations DiagnosticFactory1 FINAL_UPPER_BOUND = DiagnosticFactory1.create(WARNING); DiagnosticFactory1 FINAL_CLASS_OBJECT_UPPER_BOUND = DiagnosticFactory1.create(ERROR); - DiagnosticFactory1 CONFLICTING_UPPER_BOUNDS = - DiagnosticFactory1.create(ERROR, NAME_IDENTIFIER); - DiagnosticFactory1 CONFLICTING_CLASS_OBJECT_UPPER_BOUNDS - = DiagnosticFactory1.create(ERROR, NAME_IDENTIFIER); + DiagnosticFactory1 CONFLICTING_UPPER_BOUNDS = + DiagnosticFactory1.create(ERROR, DECLARATION_NAME); + DiagnosticFactory1 CONFLICTING_CLASS_OBJECT_UPPER_BOUNDS + = DiagnosticFactory1.create(ERROR, DECLARATION_NAME); DiagnosticFactory2 NAME_IN_CONSTRAINT_IS_NOT_A_TYPE_PARAMETER = DiagnosticFactory2.create(ERROR); @@ -212,9 +211,10 @@ public interface Errors { DiagnosticFactory0 PACKAGE_MEMBER_CANNOT_BE_PROTECTED = DiagnosticFactory0.create(ERROR, modifierSetPosition(JetTokens.PROTECTED_KEYWORD)); - DiagnosticFactory0 PUBLIC_MEMBER_SHOULD_SPECIFY_TYPE = DiagnosticFactory0.create(ERROR, NAMED_ELEMENT); + DiagnosticFactory0 PUBLIC_MEMBER_SHOULD_SPECIFY_TYPE = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE); - DiagnosticFactory2 CONFLICTING_OVERLOADS = DiagnosticFactory2.create(ERROR, DECLARATION); + DiagnosticFactory2 CONFLICTING_OVERLOADS = + DiagnosticFactory2.create(ERROR, DECLARATION_SIGNATURE_OR_DEFAULT); DiagnosticFactory1 ILLEGAL_PLATFORM_NAME = DiagnosticFactory1.create(ERROR); @@ -223,8 +223,8 @@ public interface Errors { DiagnosticFactory1 NOTHING_TO_OVERRIDE = DiagnosticFactory1.create(ERROR, OVERRIDE_MODIFIER); - DiagnosticFactory3 VIRTUAL_MEMBER_HIDDEN = - DiagnosticFactory3.create(ERROR, NAMED_ELEMENT); + DiagnosticFactory3 VIRTUAL_MEMBER_HIDDEN = + DiagnosticFactory3.create(ERROR, DECLARATION_SIGNATURE); DiagnosticFactory2 CANNOT_OVERRIDE_INVISIBLE_MEMBER = DiagnosticFactory2.create(ERROR, OVERRIDE_MODIFIER); @@ -232,7 +232,8 @@ public interface Errors { DiagnosticFactory2 DATA_CLASS_OVERRIDE_CONFLICT = DiagnosticFactory2.create(ERROR); - DiagnosticFactory1 CANNOT_INFER_VISIBILITY = DiagnosticFactory1.create(ERROR, DECLARATION); + DiagnosticFactory1 CANNOT_INFER_VISIBILITY = + DiagnosticFactory1.create(ERROR, DECLARATION_SIGNATURE_OR_DEFAULT); DiagnosticFactory2 OVERRIDING_FINAL_MEMBER = DiagnosticFactory2.create(ERROR, OVERRIDE_MODIFIER); @@ -247,11 +248,12 @@ public interface Errors { DiagnosticFactory2.create(ERROR, DECLARATION_RETURN_TYPE); DiagnosticFactory2 ABSTRACT_MEMBER_NOT_IMPLEMENTED = - DiagnosticFactory2.create(ERROR, NAME_IDENTIFIER); + DiagnosticFactory2.create(ERROR, DECLARATION_NAME); DiagnosticFactory2 MANY_IMPL_MEMBER_NOT_IMPLEMENTED = - DiagnosticFactory2.create(ERROR, NAME_IDENTIFIER); + DiagnosticFactory2.create(ERROR, DECLARATION_NAME); - DiagnosticFactory1> AMBIGUOUS_ANONYMOUS_TYPE_INFERRED = DiagnosticFactory1.create(ERROR, NAMED_ELEMENT); + DiagnosticFactory1> AMBIGUOUS_ANONYMOUS_TYPE_INFERRED = + DiagnosticFactory1.create(ERROR, DECLARATION_SIGNATURE); // Property-specific @@ -273,16 +275,16 @@ public interface Errors { DiagnosticFactory0 DELEGATED_PROPERTY_IN_TRAIT = DiagnosticFactory0.create(ERROR); DiagnosticFactory0 LOCAL_VARIABLE_WITH_DELEGATE = DiagnosticFactory0.create(ERROR); - DiagnosticFactory0 PROPERTY_WITH_NO_TYPE_NO_INITIALIZER = DiagnosticFactory0.create(ERROR, NAMED_ELEMENT); + DiagnosticFactory0 PROPERTY_WITH_NO_TYPE_NO_INITIALIZER = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE); - DiagnosticFactory0 MUST_BE_INITIALIZED = DiagnosticFactory0.create(ERROR, NAMED_ELEMENT); - DiagnosticFactory0 MUST_BE_INITIALIZED_OR_BE_ABSTRACT = DiagnosticFactory0.create(ERROR, NAMED_ELEMENT); + DiagnosticFactory0 MUST_BE_INITIALIZED = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE); + DiagnosticFactory0 MUST_BE_INITIALIZED_OR_BE_ABSTRACT = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE); DiagnosticFactory0 EXTENSION_PROPERTY_WITH_BACKING_FIELD = DiagnosticFactory0.create(ERROR); DiagnosticFactory0 PROPERTY_INITIALIZER_NO_BACKING_FIELD = DiagnosticFactory0.create(ERROR); DiagnosticFactory0 PROPERTY_INITIALIZER_IN_TRAIT = DiagnosticFactory0.create(ERROR); DiagnosticFactory0 FINAL_PROPERTY_IN_TRAIT = DiagnosticFactory0.create(ERROR, FINAL_MODIFIER); - DiagnosticFactory0 BACKING_FIELD_IN_TRAIT = DiagnosticFactory0.create(ERROR, NAMED_ELEMENT); + DiagnosticFactory0 BACKING_FIELD_IN_TRAIT = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE); DiagnosticFactory2 ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS = DiagnosticFactory2.create(ERROR, ABSTRACT_MODIFIER); @@ -297,14 +299,16 @@ public interface Errors { DiagnosticFactory2 ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS = DiagnosticFactory2.create(ERROR, ABSTRACT_MODIFIER); DiagnosticFactory1 ABSTRACT_FUNCTION_WITH_BODY = DiagnosticFactory1.create(ERROR, ABSTRACT_MODIFIER); - DiagnosticFactory1 NON_ABSTRACT_FUNCTION_WITH_NO_BODY = DiagnosticFactory1.create(ERROR, NAMED_ELEMENT); + DiagnosticFactory1 NON_ABSTRACT_FUNCTION_WITH_NO_BODY = + DiagnosticFactory1.create(ERROR, DECLARATION_SIGNATURE); DiagnosticFactory1 FINAL_FUNCTION_WITH_NO_BODY = DiagnosticFactory1.create(ERROR, FINAL_MODIFIER); - DiagnosticFactory1 NON_MEMBER_FUNCTION_NO_BODY = DiagnosticFactory1.create(ERROR, NAMED_ELEMENT); + DiagnosticFactory1 NON_MEMBER_FUNCTION_NO_BODY = + DiagnosticFactory1.create(ERROR, DECLARATION_SIGNATURE); DiagnosticFactory0 VALUE_PARAMETER_WITH_NO_TYPE_ANNOTATION = DiagnosticFactory0.create(ERROR); - DiagnosticFactory0 NO_TAIL_CALLS_FOUND = DiagnosticFactory0.create(WARNING, NAMED_ELEMENT); + DiagnosticFactory0 NO_TAIL_CALLS_FOUND = DiagnosticFactory0.create(WARNING, DECLARATION_SIGNATURE); // Named parameters @@ -313,13 +317,13 @@ public interface Errors { DiagnosticFactory1 MULTIPLE_DEFAULTS_INHERITED_FROM_SUPERTYPES = DiagnosticFactory1.create(ERROR); DiagnosticFactory1 MULTIPLE_DEFAULTS_INHERITED_FROM_SUPERTYPES_WHEN_NO_EXPLICIT_OVERRIDE = - DiagnosticFactory1.create(ERROR, NAME_IDENTIFIER); + DiagnosticFactory1.create(ERROR, DECLARATION_NAME); DiagnosticFactory2 PARAMETER_NAME_CHANGED_ON_OVERRIDE = - DiagnosticFactory2.create(WARNING, NAME_IDENTIFIER); + DiagnosticFactory2.create(WARNING, DECLARATION_NAME); DiagnosticFactory2, Integer> DIFFERENT_NAMES_FOR_THE_SAME_PARAMETER_IN_SUPERTYPES = - DiagnosticFactory2.create(WARNING, NAME_IDENTIFIER); + DiagnosticFactory2.create(WARNING, DECLARATION_NAME); //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -465,16 +469,16 @@ public interface Errors { } })); - DiagnosticFactory0 VARIABLE_WITH_NO_TYPE_NO_INITIALIZER = DiagnosticFactory0.create(ERROR, NAME_IDENTIFIER); + DiagnosticFactory0 VARIABLE_WITH_NO_TYPE_NO_INITIALIZER = DiagnosticFactory0.create(ERROR, DECLARATION_NAME); DiagnosticFactory1 UNINITIALIZED_VARIABLE = DiagnosticFactory1.create(ERROR); DiagnosticFactory1 UNINITIALIZED_PARAMETER = DiagnosticFactory1.create(ERROR); - DiagnosticFactory1 UNUSED_VARIABLE = DiagnosticFactory1.create(WARNING, NAME_IDENTIFIER); - DiagnosticFactory1 UNUSED_PARAMETER = DiagnosticFactory1.create(WARNING, NAME_IDENTIFIER); + DiagnosticFactory1 UNUSED_VARIABLE = DiagnosticFactory1.create(WARNING, DECLARATION_NAME); + DiagnosticFactory1 UNUSED_PARAMETER = DiagnosticFactory1.create(WARNING, DECLARATION_NAME); - DiagnosticFactory1 ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE = - DiagnosticFactory1.create(WARNING, NAME_IDENTIFIER); + DiagnosticFactory1 ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE = + DiagnosticFactory1.create(WARNING, DECLARATION_NAME); DiagnosticFactory1 VARIABLE_WITH_REDUNDANT_INITIALIZER = DiagnosticFactory1.create(WARNING); DiagnosticFactory2 UNUSED_VALUE = DiagnosticFactory2.create(WARNING); DiagnosticFactory1 UNUSED_CHANGED_VALUE = DiagnosticFactory1.create(WARNING); @@ -600,13 +604,13 @@ public interface Errors { DiagnosticFactory1 NESTED_CLASS_ACCESSED_VIA_INSTANCE_REFERENCE = DiagnosticFactory1.create(ERROR); DiagnosticFactory1 INACCESSIBLE_OUTER_CLASS_EXPRESSION = DiagnosticFactory1.create(ERROR); - DiagnosticFactory0 NESTED_CLASS_NOT_ALLOWED = DiagnosticFactory0.create(ERROR, NAME_IDENTIFIER); + DiagnosticFactory0 NESTED_CLASS_NOT_ALLOWED = DiagnosticFactory0.create(ERROR, DECLARATION_NAME); //Inline and inlinable parameters DiagnosticFactory2 INVISIBLE_MEMBER_FROM_INLINE = DiagnosticFactory2.create(ERROR, CALL_ELEMENT); DiagnosticFactory3 NON_LOCAL_RETURN_NOT_ALLOWED = DiagnosticFactory3.create(ERROR, CALL_ELEMENT); DiagnosticFactory2 NOT_YET_SUPPORTED_IN_INLINE = DiagnosticFactory2.create(ERROR); - DiagnosticFactory1 NOTHING_TO_INLINE = DiagnosticFactory1.create(WARNING, NAMED_ELEMENT); + DiagnosticFactory1 NOTHING_TO_INLINE = DiagnosticFactory1.create(WARNING, DECLARATION_SIGNATURE); DiagnosticFactory2 USAGE_IS_NOT_INLINABLE = DiagnosticFactory2.create(ERROR); DiagnosticFactory2 NULLABLE_INLINE_PARAMETER = DiagnosticFactory2.create(ERROR); DiagnosticFactory2 RECURSION_IN_INLINE = DiagnosticFactory2.create(ERROR); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/PositioningStrategies.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/PositioningStrategies.java index 8980b661c07..a66176d0600 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/PositioningStrategies.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/PositioningStrategies.java @@ -92,17 +92,29 @@ public class PositioningStrategies { } }; - public static final PositioningStrategy NAME_IDENTIFIER = new PositioningStrategy() { + private static class DeclarationHeader extends PositioningStrategy { + @Override + public boolean isValid(@NotNull T element) { + if (element instanceof JetNamedDeclaration && !(element instanceof JetObjectDeclaration)) { + if (((JetNamedDeclaration) element).getNameIdentifier() == null) { + return false; + } + } + return super.isValid(element); + } + } + + public static final PositioningStrategy DECLARATION_NAME = new DeclarationHeader() { @NotNull @Override - public List mark(@NotNull PsiNameIdentifierOwner element) { + public List mark(@NotNull JetNamedDeclaration element) { PsiElement nameIdentifier = element.getNameIdentifier(); if (nameIdentifier != null) { if (element instanceof JetClassOrObject) { ASTNode startNode = null; - if (((JetClassOrObject) element).hasModifier(JetTokens.ENUM_KEYWORD)) { + if (element.hasModifier(JetTokens.ENUM_KEYWORD)) { //noinspection ConstantConditions - startNode = ((JetClassOrObject) element).getModifierList().getModifier(JetTokens.ENUM_KEYWORD).getNode(); + startNode = element.getModifierList().getModifier(JetTokens.ENUM_KEYWORD).getNode(); } if (startNode == null) { startNode = element.getNode().findChildByType(TokenSet.create(JetTokens.CLASS_KEYWORD, JetTokens.OBJECT_KEYWORD)); @@ -124,21 +136,14 @@ public class PositioningStrategies { } return markElement(objectKeyword); } - return markElement(element); + return super.mark(element); } }; - public static final PositioningStrategy NAMED_ELEMENT = new DeclarationHeader() { - @Override - public boolean isValid(@NotNull PsiNameIdentifierOwner element) { - return (element.getNameIdentifier() != null || element instanceof JetObjectDeclaration) && super.isValid(element); - } - }; - - private static class DeclarationHeader extends PositioningStrategy { + public static final PositioningStrategy DECLARATION_SIGNATURE = new DeclarationHeader() { @NotNull @Override - public List mark(@NotNull T element) { + public List mark(@NotNull JetDeclaration element) { if (element instanceof JetNamedFunction) { JetNamedFunction function = (JetNamedFunction)element; PsiElement endOfSignatureElement; @@ -199,37 +204,18 @@ public class PositioningStrategies { return markRange(nameAsDeclaration, primaryConstructorParameterList); } else if (element instanceof JetObjectDeclaration) { - return NAME_IDENTIFIER.mark((JetObjectDeclaration) element); + return DECLARATION_NAME.mark((JetObjectDeclaration) element); } return super.mark(element); } - } - - public static final PositioningStrategy DECLARATION = new PositioningStrategy() { - @NotNull - @Override - public List mark(@NotNull JetDeclaration element) { - if (element instanceof PsiNameIdentifierOwner) { - return NAMED_ELEMENT.mark((PsiNameIdentifierOwner) element); - } - return super.mark(element); - } - - @Override - public boolean isValid(@NotNull JetDeclaration element) { - if (element instanceof PsiNameIdentifierOwner) { - return NAMED_ELEMENT.isValid((PsiNameIdentifierOwner) element); - } - return super.isValid(element); - } }; - public static final PositioningStrategy DECLARATION_OR_DEFAULT = new DeclarationHeader() { + public static final PositioningStrategy DECLARATION_SIGNATURE_OR_DEFAULT = new PositioningStrategy() { @NotNull @Override public List mark(@NotNull PsiElement element) { if (element instanceof JetDeclaration) { - return super.mark((JetDeclaration) element); + return DECLARATION_SIGNATURE.mark((JetDeclaration) element); } return DEFAULT.mark(element); } @@ -237,7 +223,7 @@ public class PositioningStrategies { @Override public boolean isValid(@NotNull PsiElement element) { if (element instanceof JetDeclaration) { - return DECLARATION.isValid((JetDeclaration) element); + return DECLARATION_SIGNATURE.isValid((JetDeclaration) element); } return DEFAULT.isValid(element); } diff --git a/compiler/testData/diagnostics/tests/enum/localEnums.kt b/compiler/testData/diagnostics/tests/enum/localEnums.kt index 9a3ccc61f3e..f172891c9bc 100644 --- a/compiler/testData/diagnostics/tests/enum/localEnums.kt +++ b/compiler/testData/diagnostics/tests/enum/localEnums.kt @@ -15,4 +15,6 @@ fun foo() { val f = { enum class E {} } + + enum class {} }