From b63d3905f99d7aaa7933576624855f922fd5d459 Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Tue, 22 May 2012 18:23:43 +0400 Subject: [PATCH] KT-1256 Error highlighting in IDE should be less annoying #KT-1256 fixed --- .../messages/AnalyzerWithCompilerReport.java | 1 + .../jet/checkers/CheckerTestUtil.java | 7 +- .../lang/diagnostics/AbstractDiagnostic.java | 35 ++- .../jet/lang/diagnostics/Diagnostic.java | 2 + .../DiagnosticFactoryWithPsiElement.java | 4 + .../DiagnosticWithParameters1.java | 6 - .../DiagnosticWithParameters2.java | 6 - .../DiagnosticWithParameters3.java | 6 - .../jet/lang/diagnostics/Errors.java | 206 +++++------------- .../diagnostics/PositioningStrategies.java | 169 ++++++++++++-- .../lang/diagnostics/PositioningStrategy.java | 4 +- .../lang/diagnostics/SimpleDiagnostic.java | 6 - .../jet/lang/psi/JetNamedFunction.java | 22 -- .../jet/lang/resolve/DeclarationsChecker.java | 6 + .../jet/lang/resolve/DescriptorResolver.java | 4 - .../testData/diagnostics/tests/Abstract.jet | 10 +- .../tests/AbstractInAbstractClass.jet | 13 +- .../diagnostics/tests/AbstractInClass.jet | 13 +- .../diagnostics/tests/AbstractInEnum.jet | 13 +- .../diagnostics/tests/AbstractInTrait.jet | 6 +- .../diagnostics/tests/Constructors.jet | 4 +- .../diagnostics/tests/FunctionReturnTypes.jet | 4 +- .../diagnostics/tests/IllegalModifiers.jet | 4 +- .../diagnostics/tests/PrimaryConstructors.jet | 4 +- .../testData/diagnostics/tests/Properties.jet | 2 +- .../UninitializedOrReassignedVariables.jet | 14 +- .../tests/extensions/ExtensionFunctions.jet | 4 +- .../diagnosticWithSyntaxError/funEquals.jet | 1 + .../diagnosticWithSyntaxError/funKeyword.jet | 1 + .../incompleteVal.jet | 3 + .../incompleteValWithAccessor.jet | 3 + .../incompleteWhen.jet | 3 + .../diagnosticWithSyntaxError/namedFun.jet | 1 + .../incompleteCode/incompleteAssignment.jet | 4 +- .../infos/PropertiesWithBackingFields.jet | 24 +- .../override/ComplexValRedeclaration.jet | 4 +- ...lictingPropertySignatureFromSuperclass.jet | 4 +- .../diagnostics/tests/override/Generics.jet | 12 +- .../MultipleDefaultParametersInSupertypes.jet | 4 +- ...efaultParametersInSupertypesNoOverride.jet | 4 +- .../tests/override/NonGenerics.jet | 10 +- .../diagnostics/tests/scopes/kt1822.jet | 2 +- .../jet/plugin/highlighter/JetPsiChecker.java | 3 +- idea/testData/checker/Abstract.jet | 36 +-- idea/testData/checker/Constructors.jet | 2 +- idea/testData/checker/ExtensionFunctions.jet | 2 +- idea/testData/checker/Override.jet | 4 +- .../testData/checker/OverridesAndGenerics.jet | 2 +- idea/testData/checker/PrimaryConstructors.jet | 2 +- .../infos/PropertiesWithBackingFields.jet | 22 +- 50 files changed, 386 insertions(+), 342 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/funEquals.jet create mode 100644 compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/funKeyword.jet create mode 100644 compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/incompleteVal.jet create mode 100644 compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/incompleteValWithAccessor.jet create mode 100644 compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/incompleteWhen.jet create mode 100644 compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/namedFun.jet diff --git a/compiler/cli/src/org/jetbrains/jet/cli/common/messages/AnalyzerWithCompilerReport.java b/compiler/cli/src/org/jetbrains/jet/cli/common/messages/AnalyzerWithCompilerReport.java index 24c2f1b1175..35eac40657b 100644 --- a/compiler/cli/src/org/jetbrains/jet/cli/common/messages/AnalyzerWithCompilerReport.java +++ b/compiler/cli/src/org/jetbrains/jet/cli/common/messages/AnalyzerWithCompilerReport.java @@ -75,6 +75,7 @@ public final class AnalyzerWithCompilerReport { } private void reportDiagnostic(@NotNull Diagnostic diagnostic) { + if (!diagnostic.isValid()) return; DiagnosticUtils.LineAndColumn lineAndColumn = DiagnosticUtils.getLineAndColumn(diagnostic); VirtualFile virtualFile = diagnostic.getPsiFile().getVirtualFile(); String path = virtualFile == null ? null : virtualFile.getPath(); diff --git a/compiler/frontend/src/org/jetbrains/jet/checkers/CheckerTestUtil.java b/compiler/frontend/src/org/jetbrains/jet/checkers/CheckerTestUtil.java index 3cf3bedd3f3..66dce9ec9c4 100644 --- a/compiler/frontend/src/org/jetbrains/jet/checkers/CheckerTestUtil.java +++ b/compiler/frontend/src/org/jetbrains/jet/checkers/CheckerTestUtil.java @@ -343,6 +343,11 @@ public class CheckerTestUtil { public PsiFile getPsiFile() { return errorElement.getContainingFile(); } + + @Override + public boolean isValid() { + return true; + } } private static List getSortedDiagnosticDescriptors(Collection diagnostics) { @@ -353,7 +358,7 @@ public class CheckerTestUtil { DiagnosticDescriptor currentDiagnosticDescriptor = null; for (Diagnostic diagnostic : list) { List textRanges = diagnostic.getTextRanges(); - if (textRanges.isEmpty()) continue; + if (!diagnostic.isValid()) continue; TextRange textRange = textRanges.get(0); if (currentDiagnosticDescriptor != null && currentDiagnosticDescriptor.equalRange(textRange)) { diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/AbstractDiagnostic.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/AbstractDiagnostic.java index 33450c87fe2..52898fde7a5 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/AbstractDiagnostic.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/AbstractDiagnostic.java @@ -16,20 +16,24 @@ package org.jetbrains.jet.lang.diagnostics; +import com.intellij.openapi.util.TextRange; import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiErrorElement; import com.intellij.psi.PsiFile; import org.jetbrains.annotations.NotNull; +import java.util.List; + /** * @author svtk */ public abstract class AbstractDiagnostic implements ParametrizedDiagnostic { private final E psiElement; - private final AbstractDiagnosticFactory factory; + private final DiagnosticFactoryWithPsiElement factory; private final Severity severity; public AbstractDiagnostic(@NotNull E psiElement, - @NotNull AbstractDiagnosticFactory factory, + @NotNull DiagnosticFactoryWithPsiElement factory, @NotNull Severity severity) { this.psiElement = psiElement; this.factory = factory; @@ -38,7 +42,7 @@ public abstract class AbstractDiagnostic implements Parame @NotNull @Override - public AbstractDiagnosticFactory getFactory() { + public DiagnosticFactoryWithPsiElement getFactory() { return factory; } @@ -59,4 +63,29 @@ public abstract class AbstractDiagnostic implements Parame public E getPsiElement() { return psiElement; } + + @Override + @NotNull + public List getTextRanges() { + return getFactory().getTextRanges(this); + } + + @Override + public boolean isValid() { + if (!getFactory().isValid(this)) return false; + if (hasSyntaxErrors(psiElement)) return false; + return true; + } + + private static boolean hasSyntaxErrors(@NotNull PsiElement psiElement) { + if (psiElement instanceof PsiErrorElement) return true; + + PsiElement lastChild = psiElement.getLastChild(); + if (lastChild != null && hasSyntaxErrors(lastChild)) return true; + + PsiElement[] children = psiElement.getChildren(); + if (children.length > 0 && hasSyntaxErrors(children[children.length - 1])) return true; + + return false; + } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Diagnostic.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Diagnostic.java index 8fcfbf18762..7bb35b821ae 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Diagnostic.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Diagnostic.java @@ -42,4 +42,6 @@ public interface Diagnostic { @NotNull PsiFile getPsiFile(); + + boolean isValid(); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticFactoryWithPsiElement.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticFactoryWithPsiElement.java index 54d5bdbd909..7e532aec7bf 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticFactoryWithPsiElement.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticFactoryWithPsiElement.java @@ -36,4 +36,8 @@ public abstract class DiagnosticFactoryWithPsiElement exte protected List getTextRanges(ParametrizedDiagnostic diagnostic) { return positioningStrategy.mark(diagnostic.getPsiElement()); } + + protected boolean isValid(ParametrizedDiagnostic diagnostic) { + return positioningStrategy.isValid(diagnostic.getPsiElement()); + } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticWithParameters1.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticWithParameters1.java index 50976c627c4..275a2846f67 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticWithParameters1.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticWithParameters1.java @@ -43,12 +43,6 @@ public class DiagnosticWithParameters1 extends Abstract return (DiagnosticFactory1)super.getFactory(); } - @Override - @NotNull - public List getTextRanges() { - return getFactory().getTextRanges(this); - } - @NotNull public A getA() { return a; diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticWithParameters2.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticWithParameters2.java index 272577dcfba..3e3b94e7fa6 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticWithParameters2.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticWithParameters2.java @@ -46,12 +46,6 @@ public class DiagnosticWithParameters2 extends Abstr return (DiagnosticFactory2)super.getFactory(); } - @Override - @NotNull - public List getTextRanges() { - return getFactory().getTextRanges(this); - } - @NotNull public A getA() { return a; diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticWithParameters3.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticWithParameters3.java index febe21d7a5b..931b779a19e 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticWithParameters3.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticWithParameters3.java @@ -49,12 +49,6 @@ public class DiagnosticWithParameters3 extends Ab return (DiagnosticFactory3)super.getFactory(); } - @Override - @NotNull - public List getTextRanges() { - return getFactory().getTextRanges(this); - } - @NotNull public A getA() { return a; 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 902de8fe6a4..553a6f2e167 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java @@ -31,9 +31,9 @@ import org.jetbrains.jet.lexer.JetTokens; import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.util.Collection; -import java.util.Collections; import java.util.List; +import static org.jetbrains.jet.lang.diagnostics.PositioningStrategies.*; import static org.jetbrains.jet.lang.diagnostics.Severity.ERROR; import static org.jetbrains.jet.lang.diagnostics.Severity.WARNING; @@ -51,7 +51,7 @@ public interface Errors { //Elements with "INVISIBLE_REFERENCE" error are marked as unresolved, unlike elements with "INVISIBLE_MEMBER" error DiagnosticFactory2 INVISIBLE_REFERENCE = DiagnosticFactory2.create(ERROR); - DiagnosticFactory2 INVISIBLE_MEMBER = DiagnosticFactory2.create(ERROR, PositioningStrategies.CALL_ELEMENT); + DiagnosticFactory2 INVISIBLE_MEMBER = DiagnosticFactory2.create(ERROR, CALL_ELEMENT); RedeclarationDiagnosticFactory REDECLARATION = new RedeclarationDiagnosticFactory(ERROR); RedeclarationDiagnosticFactory NAME_SHADOWING = new RedeclarationDiagnosticFactory(WARNING); @@ -62,16 +62,16 @@ public interface Errors { DiagnosticFactory2 REDUNDANT_MODIFIER = DiagnosticFactory2.create(Severity.WARNING); SimpleDiagnosticFactory ABSTRACT_MODIFIER_IN_TRAIT = SimpleDiagnosticFactory - .create(WARNING, PositioningStrategies.POSITION_ABSTRACT_MODIFIER); + .create(WARNING, ABSTRACT_MODIFIER); SimpleDiagnosticFactory OPEN_MODIFIER_IN_TRAIT = SimpleDiagnosticFactory - .create(WARNING, PositioningStrategies.positionModifier(JetTokens.OPEN_KEYWORD)); + .create(WARNING, positionModifier(JetTokens.OPEN_KEYWORD)); SimpleDiagnosticFactory REDUNDANT_MODIFIER_IN_GETTER = SimpleDiagnosticFactory.create(WARNING); SimpleDiagnosticFactory TRAIT_CAN_NOT_BE_FINAL = SimpleDiagnosticFactory.create(ERROR); SimpleDiagnosticFactory TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM = SimpleDiagnosticFactory.create(ERROR); SimpleDiagnosticFactory RETURN_NOT_ALLOWED = SimpleDiagnosticFactory.create(ERROR); SimpleDiagnosticFactory PROJECTION_IN_IMMEDIATE_ARGUMENT_TO_SUPERTYPE = - SimpleDiagnosticFactory.create(ERROR, PositioningStrategies.PROJECTION_MODIFIER); + SimpleDiagnosticFactory.create(ERROR, PROJECTION_MODIFIER); SimpleDiagnosticFactoryLABEL_NAME_CLASH = SimpleDiagnosticFactory.create(WARNING); SimpleDiagnosticFactory EXPRESSION_EXPECTED_NAMESPACE_FOUND = SimpleDiagnosticFactory.create(ERROR); @@ -95,12 +95,10 @@ public interface Errors { SimpleDiagnosticFactory NON_VARARG_SPREAD = SimpleDiagnosticFactory.create(ERROR); SimpleDiagnosticFactory MANY_FUNCTION_LITERAL_ARGUMENTS = SimpleDiagnosticFactory.create(ERROR); - SimpleDiagnosticFactory PROPERTY_WITH_NO_TYPE_NO_INITIALIZER = SimpleDiagnosticFactory.create(ERROR); + SimpleDiagnosticFactory PROPERTY_WITH_NO_TYPE_NO_INITIALIZER = SimpleDiagnosticFactory.create(ERROR, NAMED_ELEMENT); - SimpleDiagnosticFactory ABSTRACT_PROPERTY_IN_PRIMARY_CONSTRUCTOR_PARAMETERS = SimpleDiagnosticFactory - .create(ERROR, PositioningStrategies.POSITION_ABSTRACT_MODIFIER); - SimpleDiagnosticFactory ABSTRACT_PROPERTY_NOT_IN_CLASS = SimpleDiagnosticFactory.create(ERROR, - PositioningStrategies.POSITION_ABSTRACT_MODIFIER); + SimpleDiagnosticFactory ABSTRACT_PROPERTY_IN_PRIMARY_CONSTRUCTOR_PARAMETERS = SimpleDiagnosticFactory.create(ERROR, ABSTRACT_MODIFIER); + SimpleDiagnosticFactory ABSTRACT_PROPERTY_NOT_IN_CLASS = SimpleDiagnosticFactory.create(ERROR, ABSTRACT_MODIFIER); SimpleDiagnosticFactory ABSTRACT_PROPERTY_WITH_INITIALIZER = SimpleDiagnosticFactory.create(ERROR); SimpleDiagnosticFactory ABSTRACT_PROPERTY_WITH_GETTER = SimpleDiagnosticFactory.create(ERROR); SimpleDiagnosticFactoryABSTRACT_PROPERTY_WITH_SETTER = SimpleDiagnosticFactory.create(ERROR); @@ -108,35 +106,23 @@ public interface Errors { SimpleDiagnosticFactory PACKAGE_MEMBER_CANNOT_BE_PROTECTED = SimpleDiagnosticFactory.create(ERROR); SimpleDiagnosticFactory GETTER_VISIBILITY_DIFFERS_FROM_PROPERTY_VISIBILITY = SimpleDiagnosticFactory.create(ERROR); - SimpleDiagnosticFactory BACKING_FIELD_IN_TRAIT = SimpleDiagnosticFactory.create(ERROR, - PositioningStrategies.POSITION_NAME_IDENTIFIER); - SimpleDiagnosticFactory MUST_BE_INITIALIZED = SimpleDiagnosticFactory.create(ERROR, - PositioningStrategies.POSITION_NAME_IDENTIFIER); - SimpleDiagnosticFactory MUST_BE_INITIALIZED_OR_BE_ABSTRACT = SimpleDiagnosticFactory.create(ERROR, - PositioningStrategies.POSITION_NAME_IDENTIFIER); + SimpleDiagnosticFactory BACKING_FIELD_IN_TRAIT = SimpleDiagnosticFactory.create(ERROR, NAMED_ELEMENT); + SimpleDiagnosticFactory MUST_BE_INITIALIZED = SimpleDiagnosticFactory.create(ERROR, NAMED_ELEMENT); + SimpleDiagnosticFactory MUST_BE_INITIALIZED_OR_BE_ABSTRACT = SimpleDiagnosticFactory.create(ERROR, NAMED_ELEMENT); SimpleDiagnosticFactoryPROPERTY_INITIALIZER_IN_TRAIT = SimpleDiagnosticFactory.create(ERROR); SimpleDiagnosticFactory PROPERTY_INITIALIZER_NO_BACKING_FIELD = SimpleDiagnosticFactory.create(ERROR); - DiagnosticFactory2 ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS = - DiagnosticFactory2.create(ERROR, PositioningStrategies.POSITION_ABSTRACT_MODIFIER); - DiagnosticFactory2 ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS = - DiagnosticFactory2.create(ERROR,PositioningStrategies.POSITION_ABSTRACT_MODIFIER); - DiagnosticFactory1 ABSTRACT_FUNCTION_WITH_BODY = - DiagnosticFactory1.create(ERROR, PositioningStrategies.POSITION_ABSTRACT_MODIFIER); - DiagnosticFactory1 NON_ABSTRACT_FUNCTION_WITH_NO_BODY = - DiagnosticFactory1.create(ERROR, PositioningStrategies.POSITION_NAME_IDENTIFIER); - DiagnosticFactory1 NON_MEMBER_ABSTRACT_FUNCTION = - DiagnosticFactory1.create(ERROR, PositioningStrategies.POSITION_ABSTRACT_MODIFIER); - - DiagnosticFactory1 NON_MEMBER_FUNCTION_NO_BODY = - DiagnosticFactory1.create(ERROR, PositioningStrategies.POSITION_NAME_IDENTIFIER); - SimpleDiagnosticFactory NON_FINAL_MEMBER_IN_FINAL_CLASS = - SimpleDiagnosticFactory.create(ERROR, PositioningStrategies.positionModifier(JetTokens.OPEN_KEYWORD)); - - SimpleDiagnosticFactory PUBLIC_MEMBER_SHOULD_SPECIFY_TYPE = - SimpleDiagnosticFactory.create(ERROR, PositioningStrategies.POSITION_NAME_IDENTIFIER); - - SimpleDiagnosticFactory PROJECTION_ON_NON_CLASS_TYPE_ARGUMENT = - SimpleDiagnosticFactory.create(ERROR, PositioningStrategies.PROJECTION_MODIFIER); + DiagnosticFactory2 ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS = DiagnosticFactory2.create(ERROR, ABSTRACT_MODIFIER); + 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_MEMBER_ABSTRACT_FUNCTION = DiagnosticFactory1.create(ERROR, ABSTRACT_MODIFIER); + + DiagnosticFactory1 NON_MEMBER_FUNCTION_NO_BODY = DiagnosticFactory1.create(ERROR, NAMED_ELEMENT); + SimpleDiagnosticFactory NON_FINAL_MEMBER_IN_FINAL_CLASS = SimpleDiagnosticFactory.create(ERROR, positionModifier(JetTokens.OPEN_KEYWORD)); + + SimpleDiagnosticFactory PUBLIC_MEMBER_SHOULD_SPECIFY_TYPE = SimpleDiagnosticFactory.create(ERROR, NAMED_ELEMENT); + + SimpleDiagnosticFactory PROJECTION_ON_NON_CLASS_TYPE_ARGUMENT = SimpleDiagnosticFactory.create(ERROR, PROJECTION_MODIFIER); SimpleDiagnosticFactory SUPERTYPE_NOT_INITIALIZED = SimpleDiagnosticFactory.create(ERROR); SimpleDiagnosticFactory SUPERTYPE_NOT_INITIALIZED_DEFAULT = SimpleDiagnosticFactory.create(ERROR); SimpleDiagnosticFactory SECONDARY_CONSTRUCTOR_BUT_NO_PRIMARY = SimpleDiagnosticFactory.create(ERROR); @@ -144,26 +130,21 @@ public interface Errors { SimpleDiagnosticFactory BY_IN_SECONDARY_CONSTRUCTOR = SimpleDiagnosticFactory.create(ERROR); SimpleDiagnosticFactory INITIALIZER_WITH_NO_ARGUMENTS = SimpleDiagnosticFactory.create(ERROR); SimpleDiagnosticFactory MANY_CALLS_TO_THIS = SimpleDiagnosticFactory.create(ERROR); - DiagnosticFactory1 NOTHING_TO_OVERRIDE = - DiagnosticFactory1.create(ERROR, PositioningStrategies.POSITION_OVERRIDE_MODIFIER); - DiagnosticFactory3 - VIRTUAL_MEMBER_HIDDEN = DiagnosticFactory3.create(ERROR, PositioningStrategies.POSITION_NAME_IDENTIFIER); + DiagnosticFactory1 NOTHING_TO_OVERRIDE = DiagnosticFactory1.create(ERROR, OVERRIDE_MODIFIER); + DiagnosticFactory3 VIRTUAL_MEMBER_HIDDEN = + DiagnosticFactory3.create(ERROR, NAMED_ELEMENT); DiagnosticFactory3 CANNOT_OVERRIDE_INVISIBLE_MEMBER = - DiagnosticFactory3.create(ERROR, PositioningStrategies.POSITION_OVERRIDE_MODIFIER); - SimpleDiagnosticFactory CANNOT_INFER_VISIBILITY = SimpleDiagnosticFactory.create(ERROR, PositioningStrategies.POSITION_OVERRIDE_MODIFIER); + DiagnosticFactory3.create(ERROR, OVERRIDE_MODIFIER); + SimpleDiagnosticFactory CANNOT_INFER_VISIBILITY = SimpleDiagnosticFactory.create(ERROR, DECLARATION); - DiagnosticFactory1 ENUM_ENTRY_SHOULD_BE_INITIALIZED = - DiagnosticFactory1.create(ERROR, PositioningStrategies.POSITION_NAME_IDENTIFIER); + DiagnosticFactory1 ENUM_ENTRY_SHOULD_BE_INITIALIZED = DiagnosticFactory1.create(ERROR, NAME_IDENTIFIER); DiagnosticFactory1 ENUM_ENTRY_ILLEGAL_TYPE = DiagnosticFactory1.create(ERROR); DiagnosticFactory1 UNINITIALIZED_VARIABLE = DiagnosticFactory1.create(ERROR); DiagnosticFactory1 UNINITIALIZED_PARAMETER = DiagnosticFactory1.create(ERROR); - UnusedElementDiagnosticFactory UNUSED_VARIABLE = - UnusedElementDiagnosticFactory.create(WARNING, PositioningStrategies.POSITION_NAME_IDENTIFIER); - UnusedElementDiagnosticFactory UNUSED_PARAMETER = - UnusedElementDiagnosticFactory.create(WARNING, PositioningStrategies.POSITION_NAME_IDENTIFIER); - UnusedElementDiagnosticFactory ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE = - UnusedElementDiagnosticFactory.create(WARNING, PositioningStrategies.POSITION_NAME_IDENTIFIER); + UnusedElementDiagnosticFactory UNUSED_VARIABLE = UnusedElementDiagnosticFactory.create(WARNING, NAME_IDENTIFIER); + UnusedElementDiagnosticFactory UNUSED_PARAMETER = UnusedElementDiagnosticFactory.create(WARNING, NAME_IDENTIFIER); + UnusedElementDiagnosticFactory ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE = UnusedElementDiagnosticFactory.create(WARNING, NAME_IDENTIFIER); DiagnosticFactory1 VARIABLE_WITH_REDUNDANT_INITIALIZER = DiagnosticFactory1.create(WARNING); DiagnosticFactory2 UNUSED_VALUE = DiagnosticFactory2.create(WARNING); DiagnosticFactory1 UNUSED_CHANGED_VALUE = DiagnosticFactory1.create(WARNING); @@ -194,10 +175,8 @@ public interface Errors { SimpleDiagnosticFactory LOCAL_VARIABLE_WITH_SETTER = SimpleDiagnosticFactory.create(ERROR); SimpleDiagnosticFactory VAL_WITH_SETTER = SimpleDiagnosticFactory.create(ERROR); - SimpleDiagnosticFactory NO_GET_METHOD = - SimpleDiagnosticFactory.create(ERROR, PositioningStrategies.POSITION_ARRAY_ACCESS); - SimpleDiagnosticFactory NO_SET_METHOD = - SimpleDiagnosticFactory.create(ERROR, PositioningStrategies.POSITION_ARRAY_ACCESS); + SimpleDiagnosticFactory NO_GET_METHOD = SimpleDiagnosticFactory.create(ERROR, ARRAY_ACCESS); + SimpleDiagnosticFactory NO_SET_METHOD = SimpleDiagnosticFactory.create(ERROR, ARRAY_ACCESS); SimpleDiagnosticFactory INC_DEC_SHOULD_NOT_RETURN_UNIT = SimpleDiagnosticFactory.create(ERROR); DiagnosticFactory2 ASSIGNMENT_OPERATOR_SHOULD_RETURN_UNIT = @@ -239,24 +218,7 @@ public interface Errors { DiagnosticFactory1 CALLEE_NOT_A_FUNCTION = DiagnosticFactory1.create(ERROR); SimpleDiagnosticFactory RETURN_IN_FUNCTION_WITH_EXPRESSION_BODY = SimpleDiagnosticFactory.create(ERROR); - SimpleDiagnosticFactory NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY = - SimpleDiagnosticFactory.create(ERROR, - new PositioningStrategy() { - @NotNull - @Override - public List mark(@NotNull JetDeclarationWithBody element) { - JetExpression bodyExpression = element.getBodyExpression(); - if (!(bodyExpression instanceof JetBlockExpression)) { - return markElement(element); - } - JetBlockExpression blockExpression = (JetBlockExpression)bodyExpression; - TextRange lastBracketRange = blockExpression.getLastBracketRange(); - if (lastBracketRange == null) { - return Collections.emptyList(); - } - return markRange(lastBracketRange); - } - }); + SimpleDiagnosticFactory NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY = SimpleDiagnosticFactory.create(ERROR, DECLARATION_WITH_BODY); DiagnosticFactory1 RETURN_TYPE_MISMATCH = DiagnosticFactory1.create(ERROR); DiagnosticFactory1 EXPECTED_TYPE_MISMATCH = DiagnosticFactory1.create(ERROR); DiagnosticFactory1 ASSIGNMENT_TYPE_MISMATCH = DiagnosticFactory1.create(ERROR); @@ -273,33 +235,10 @@ public interface Errors { DiagnosticFactory1 TOO_MANY_ARGUMENTS = DiagnosticFactory1.create(ERROR); DiagnosticFactory1 ERROR_COMPILE_TIME_VALUE = DiagnosticFactory1.create(ERROR); - SimpleDiagnosticFactory ELSE_MISPLACED_IN_WHEN = SimpleDiagnosticFactory.create(ERROR, new PositioningStrategy() { - @NotNull - @Override - public List mark(@NotNull JetWhenEntry entry) { - PsiElement elseKeywordElement = entry.getElseKeywordElement(); - assert elseKeywordElement != null; - return markElement(elseKeywordElement); - } - }); - - SimpleDiagnosticFactory - NO_ELSE_IN_WHEN = new SimpleDiagnosticFactory(ERROR, new PositioningStrategy() { - @NotNull - @Override - public List mark(@NotNull JetWhenExpression element) { - return markElement(element.getWhenKeywordElement()); - } - }); - SimpleDiagnosticFactory TYPE_MISMATCH_IN_RANGE = - new SimpleDiagnosticFactory(ERROR, - new PositioningStrategy() { - @NotNull - @Override - public List mark(@NotNull JetWhenConditionInRange condition) { - return markElement(condition.getOperationReference()); - } - }); + SimpleDiagnosticFactory ELSE_MISPLACED_IN_WHEN = SimpleDiagnosticFactory.create(ERROR, ELSE_ENTRY); + + SimpleDiagnosticFactory NO_ELSE_IN_WHEN = new SimpleDiagnosticFactory(ERROR, WHEN_EXPRESSION); + SimpleDiagnosticFactory TYPE_MISMATCH_IN_RANGE = new SimpleDiagnosticFactory(ERROR, WHEN_CONDITION_IN_RANGE); SimpleDiagnosticFactory CYCLIC_INHERITANCE_HIERARCHY = SimpleDiagnosticFactory.create(ERROR); SimpleDiagnosticFactory MANY_CLASSES_IN_SUPERTYPE_LIST = SimpleDiagnosticFactory.create(ERROR); @@ -318,15 +257,7 @@ public interface Errors { DiagnosticFactory1 NOT_A_RETURN_LABEL = DiagnosticFactory1.create(ERROR); SimpleDiagnosticFactory ANONYMOUS_INITIALIZER_WITHOUT_CONSTRUCTOR = SimpleDiagnosticFactory.create(ERROR); - SimpleDiagnosticFactory NULLABLE_SUPERTYPE = SimpleDiagnosticFactory.create(ERROR, - new PositioningStrategy() { - @NotNull - @Override - public List mark(@NotNull JetNullableType element) { - return markNode( - element.getQuestionMarkNode()); - } - }); + SimpleDiagnosticFactory NULLABLE_SUPERTYPE = SimpleDiagnosticFactory.create(ERROR, NULLABLE_TYPE); DiagnosticFactory1 UNSAFE_CALL = DiagnosticFactory1.create(ERROR); SimpleDiagnosticFactory AMBIGUOUS_LABEL = SimpleDiagnosticFactory.create(ERROR); DiagnosticFactory1 UNSUPPORTED = DiagnosticFactory1.create(ERROR); @@ -354,15 +285,14 @@ public interface Errors { DiagnosticFactory2 SENSELESS_COMPARISON = DiagnosticFactory2.create(WARNING); - DiagnosticFactory2 OVERRIDING_FINAL_MEMBER = - DiagnosticFactory2.create(ERROR); + DiagnosticFactory2 OVERRIDING_FINAL_MEMBER = DiagnosticFactory2.create(ERROR); DiagnosticFactory3 CANNOT_WEAKEN_ACCESS_PRIVILEGE = - DiagnosticFactory3.create(ERROR, PositioningStrategies.POSITION_VISIBILITY_MODIFIER); + DiagnosticFactory3.create(ERROR, VISIBILITY_MODIFIER); DiagnosticFactory3 CANNOT_CHANGE_ACCESS_PRIVILEGE = - DiagnosticFactory3.create(ERROR, PositioningStrategies.POSITION_VISIBILITY_MODIFIER); + DiagnosticFactory3.create(ERROR, VISIBILITY_MODIFIER); DiagnosticFactory2 RETURN_TYPE_MISMATCH_ON_OVERRIDE = - DiagnosticFactory2.create(ERROR, PositioningStrategies.POSITION_DECLARATION); + DiagnosticFactory2.create(ERROR, DECLARATION_RETURN_TYPE); DiagnosticFactory2 VAR_OVERRIDDEN_BY_VAL = DiagnosticFactory2.create(ERROR, new PositioningStrategy() { @@ -379,46 +309,16 @@ public interface Errors { DiagnosticFactory2 MANY_IMPL_MEMBER_NOT_IMPLEMENTED = DiagnosticFactory2.create(ERROR); - SimpleDiagnosticFactory DEFAULT_VALUE_NOT_ALLOWED_IN_OVERRIDE = SimpleDiagnosticFactory.create(ERROR, PositioningStrategies.PARAMETER_DEFAULT_VALUE); - DiagnosticFactory1 MULTIPLE_DEFAULTS_INHERITED_FROM_SUPERTYPES = DiagnosticFactory1.create(ERROR, PositioningStrategies.POSITION_NAME_IDENTIFIER); - DiagnosticFactory1 MULTIPLE_DEFAULTS_INHERITED_FROM_SUPERTYPES_WHEN_NO_EXPLICIT_OVERRIDE = DiagnosticFactory1.create(ERROR, PositioningStrategies.POSITION_NAME_IDENTIFIER); - DiagnosticFactory2 PARAMETER_NAME_CHANGED_ON_OVERRIDE = DiagnosticFactory2.create(WARNING, PositioningStrategies.POSITION_NAME_IDENTIFIER); - DiagnosticFactory2, Integer> DIFFERENT_NAMES_FOR_THE_SAME_PARAMETER_IN_SUPERTYPES = DiagnosticFactory2.create(WARNING, PositioningStrategies.POSITION_NAME_IDENTIFIER); + SimpleDiagnosticFactory DEFAULT_VALUE_NOT_ALLOWED_IN_OVERRIDE = SimpleDiagnosticFactory.create(ERROR, PARAMETER_DEFAULT_VALUE); + DiagnosticFactory1 MULTIPLE_DEFAULTS_INHERITED_FROM_SUPERTYPES = DiagnosticFactory1.create(ERROR); + DiagnosticFactory1 MULTIPLE_DEFAULTS_INHERITED_FROM_SUPERTYPES_WHEN_NO_EXPLICIT_OVERRIDE = + DiagnosticFactory1.create(ERROR, NAME_IDENTIFIER); + DiagnosticFactory2 PARAMETER_NAME_CHANGED_ON_OVERRIDE = + DiagnosticFactory2.create(WARNING, NAME_IDENTIFIER); + DiagnosticFactory2, Integer> DIFFERENT_NAMES_FOR_THE_SAME_PARAMETER_IN_SUPERTYPES = + DiagnosticFactory2.create(WARNING, NAME_IDENTIFIER); - DiagnosticFactory2 CONFLICTING_OVERLOADS = - DiagnosticFactory2.create(ERROR, new PositioningStrategy() { - @NotNull - @Override - public List mark(@NotNull JetDeclaration jetDeclaration) { - if (jetDeclaration instanceof JetNamedFunction) { - JetNamedFunction functionElement = (JetNamedFunction)jetDeclaration; - return markRange(new TextRange( - functionElement.getStartOfSignatureElement().getTextRange().getStartOffset(), - functionElement.getEndOfSignatureElement().getTextRange().getEndOffset() - )); - } - else if (jetDeclaration instanceof JetClass) { - // primary constructor - JetClass klass = (JetClass)jetDeclaration; - PsiElement nameAsDeclaration = klass.getNameIdentifier(); - if (nameAsDeclaration == null) { - return markElement(klass); - } - PsiElement primaryConstructorParameterList = klass.getPrimaryConstructorParameterList(); - if (primaryConstructorParameterList == null) { - return markRange(nameAsDeclaration.getTextRange()); - } - return markRange(new TextRange( - nameAsDeclaration.getTextRange().getStartOffset(), - primaryConstructorParameterList.getTextRange().getEndOffset() - )); - } - else { - // safe way - return markElement(jetDeclaration); - } - } - }); + DiagnosticFactory2 CONFLICTING_OVERLOADS = DiagnosticFactory2.create(ERROR, DECLARATION); DiagnosticFactory3 RESULT_TYPE_MISMATCH = DiagnosticFactory3.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 0f9f14ac019..2a8e3b23fbf 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/PositioningStrategies.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/PositioningStrategies.java @@ -21,14 +21,12 @@ import com.google.common.collect.Lists; import com.intellij.lang.ASTNode; import com.intellij.openapi.util.TextRange; import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiErrorElement; import com.intellij.psi.PsiNameIdentifierOwner; import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lexer.JetKeywordToken; import org.jetbrains.jet.lexer.JetTokens; -import java.util.Collections; import java.util.List; /** @@ -38,7 +36,7 @@ public class PositioningStrategies { public static final PositioningStrategy DEFAULT = new PositioningStrategy(); - public static final PositioningStrategy POSITION_DECLARATION = new PositioningStrategy() { + public static final PositioningStrategy DECLARATION_RETURN_TYPE = new PositioningStrategy() { @NotNull @Override public List mark(@NotNull JetDeclaration declaration) { @@ -70,7 +68,7 @@ public class PositioningStrategies { } }; - public static final PositioningStrategy POSITION_NAME_IDENTIFIER = new PositioningStrategy() { + public static final PositioningStrategy NAME_IDENTIFIER = new PositioningStrategy() { @NotNull @Override public List mark(@NotNull PsiNameIdentifierOwner element) { @@ -82,28 +80,109 @@ public class PositioningStrategies { } }; - public static final PositioningStrategy POSITION_ABSTRACT_MODIFIER = positionModifier(JetTokens.ABSTRACT_KEYWORD); + public static final PositioningStrategy NAMED_ELEMENT = new PositioningStrategy() { + @NotNull + @Override + public List mark(@NotNull PsiNameIdentifierOwner element) { + if (element instanceof JetNamedFunction) { + JetNamedFunction function = (JetNamedFunction)element; + PsiElement endOfSignatureElement; + JetParameterList valueParameterList = function.getValueParameterList(); + JetElement returnTypeRef = function.getReturnTypeRef(); + PsiElement nameIdentifier = function.getNameIdentifier(); + if (returnTypeRef != null) { + endOfSignatureElement = returnTypeRef; + } + else if (valueParameterList != null) { + endOfSignatureElement = valueParameterList; + } + else if (nameIdentifier != null) { + endOfSignatureElement = nameIdentifier; + } + else { + endOfSignatureElement = function; + } + return markRange(new TextRange( + function.getTextRange().getStartOffset(), endOfSignatureElement.getTextRange().getEndOffset())); + } + else if (element instanceof JetProperty) { + JetProperty property = (JetProperty) element; + PsiElement endOfSignatureElement; + JetTypeReference propertyTypeRef = property.getPropertyTypeRef(); + PsiElement nameIdentifier = property.getNameIdentifier(); + if (propertyTypeRef != null) { + endOfSignatureElement = propertyTypeRef; + } + else if (nameIdentifier != null) { + endOfSignatureElement = nameIdentifier; + } + else { + endOfSignatureElement = property; + } + return markRange(new TextRange( + property.getTextRange().getStartOffset(), endOfSignatureElement.getTextRange().getEndOffset())); + } + else if (element instanceof JetClass) { + // primary constructor + JetClass klass = (JetClass)element; + PsiElement nameAsDeclaration = klass.getNameIdentifier(); + if (nameAsDeclaration == null) { + return markElement(klass); + } + PsiElement primaryConstructorParameterList = klass.getPrimaryConstructorParameterList(); + if (primaryConstructorParameterList == null) { + return markRange(nameAsDeclaration.getTextRange()); + } + return markRange(new TextRange( + nameAsDeclaration.getTextRange().getStartOffset(), primaryConstructorParameterList.getTextRange().getEndOffset())); + } + return super.mark(element); + } + @Override + public boolean isValid(@NotNull PsiNameIdentifierOwner element) { + return element.getNameIdentifier() != null; + } + }; + + 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 ABSTRACT_MODIFIER = positionModifier(JetTokens.ABSTRACT_KEYWORD); - public static final PositioningStrategy POSITION_OVERRIDE_MODIFIER = positionModifier(JetTokens.OVERRIDE_KEYWORD); + public static final PositioningStrategy OVERRIDE_MODIFIER = positionModifier(JetTokens.OVERRIDE_KEYWORD); public static PositioningStrategy positionModifier(final JetKeywordToken token) { return new PositioningStrategy() { @NotNull @Override public List mark(@NotNull JetModifierListOwner modifierListOwner) { - if (modifierListOwner.hasModifier(token)) { - JetModifierList modifierList = modifierListOwner.getModifierList(); - assert modifierList != null; - ASTNode node = modifierList.getModifierNode(token); - assert node != null; - return markNode(node); - } - return markElement(modifierListOwner); + assert modifierListOwner.hasModifier(token); + JetModifierList modifierList = modifierListOwner.getModifierList(); + assert modifierList != null; + ASTNode node = modifierList.getModifierNode(token); + assert node != null; + return markNode(node); } }; } - public static PositioningStrategy POSITION_ARRAY_ACCESS = new PositioningStrategy() { + public static PositioningStrategy ARRAY_ACCESS = new PositioningStrategy() { @NotNull @Override public List mark(@NotNull JetArrayAccessExpression element) { @@ -111,7 +190,7 @@ public class PositioningStrategies { } }; - public static PositioningStrategy POSITION_VISIBILITY_MODIFIER = new PositioningStrategy() { + public static PositioningStrategy VISIBILITY_MODIFIER = new PositioningStrategy() { @NotNull @Override public List mark(@NotNull JetModifierListOwner element) { @@ -161,4 +240,62 @@ public class PositioningStrategies { return markElement(callElement); } }; + + public static PositioningStrategy DECLARATION_WITH_BODY = new PositioningStrategy() { + @NotNull + @Override + public List mark(@NotNull JetDeclarationWithBody element) { + JetExpression bodyExpression = element.getBodyExpression(); + if ((bodyExpression instanceof JetBlockExpression)) { + TextRange lastBracketRange = ((JetBlockExpression) bodyExpression).getLastBracketRange(); + if (lastBracketRange != null) { + return markRange(lastBracketRange); + } + } + return markElement(element); + } + + @Override + public boolean isValid(@NotNull JetDeclarationWithBody element) { + JetExpression bodyExpression = element.getBodyExpression(); + if (!(bodyExpression instanceof JetBlockExpression)) return false; + if (((JetBlockExpression) bodyExpression).getLastBracketRange() == null) return false; + return true; + } + }; + + public static PositioningStrategy ELSE_ENTRY = new PositioningStrategy() { + @NotNull + @Override + public List mark(@NotNull JetWhenEntry entry) { + PsiElement elseKeywordElement = entry.getElseKeywordElement(); + assert elseKeywordElement != null; + return markElement(elseKeywordElement); + } + }; + + public static PositioningStrategy WHEN_EXPRESSION = new PositioningStrategy() { + @NotNull + @Override + public List mark(@NotNull JetWhenExpression element) { + return markElement(element.getWhenKeywordElement()); + } + }; + + public static PositioningStrategy WHEN_CONDITION_IN_RANGE = + new PositioningStrategy() { + @NotNull + @Override + public List mark(@NotNull JetWhenConditionInRange condition) { + return markElement(condition.getOperationReference()); + } + }; + + public static PositioningStrategy NULLABLE_TYPE = new PositioningStrategy() { + @NotNull + @Override + public List mark(@NotNull JetNullableType element) { + return markNode(element.getQuestionMarkNode()); + } + }; } \ No newline at end of file diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/PositioningStrategy.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/PositioningStrategy.java index 664b31de612..c4b463b2752 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/PositioningStrategy.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/PositioningStrategy.java @@ -34,8 +34,8 @@ public class PositioningStrategy { return markElement(element); } - protected boolean hasSyntaxError(@NotNull E element) { - return element.getLastChild() instanceof PsiErrorElement; + public boolean isValid(@NotNull E element) { + return true; } @NotNull diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/SimpleDiagnostic.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/SimpleDiagnostic.java index 5dbaf4f5123..cd40b721b17 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/SimpleDiagnostic.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/SimpleDiagnostic.java @@ -37,10 +37,4 @@ public class SimpleDiagnostic extends AbstractDiagnostic getFactory() { return (SimpleDiagnosticFactory)super.getFactory(); } - - @Override - @NotNull - public List getTextRanges() { - return getFactory().getTextRanges(this); - } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetNamedFunction.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetNamedFunction.java index 0342b2d43d1..f2cf9f6b15b 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetNamedFunction.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetNamedFunction.java @@ -69,28 +69,6 @@ public class JetNamedFunction extends JetFunction implements StubBasedPsiElement return findChildByType(JetTokens.EQ); } - @NotNull - public JetElement getStartOfSignatureElement() { - return this; - } - - @NotNull - public JetElement getEndOfSignatureElement() { - JetElement r = getReturnTypeRef(); - if (r != null) { - return r; - } - - r = getValueParameterList(); - if (r != null) { - return r; - } - - // otherwise it is an error - - return this; - } - /** * Returns full qualified name for function "package_fqn.function_name" * Not null for top level functions. diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DeclarationsChecker.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DeclarationsChecker.java index 3e5b789e9e5..3abf906e574 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DeclarationsChecker.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DeclarationsChecker.java @@ -221,14 +221,20 @@ public class DeclarationsChecker { trace.report(BACKING_FIELD_IN_TRAIT.on(property)); } if (initializer == null) { + boolean error = false; if (backingFieldRequired && !inTrait && !trace.getBindingContext().get(BindingContext.IS_INITIALIZED, propertyDescriptor)) { if (classDescriptor == null || hasAccessorImplementation) { + error = true; trace.report(MUST_BE_INITIALIZED.on(property)); } else { + error = true; trace.report(MUST_BE_INITIALIZED_OR_BE_ABSTRACT.on(property)); } } + if (!error && property.getPropertyTypeRef() == null) { + trace.report(PROPERTY_WITH_NO_TYPE_NO_INITIALIZER.on(property)); + } return; } if (inTrait) { diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorResolver.java index 5920a5bf212..b00a909da19 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorResolver.java @@ -646,10 +646,6 @@ public class DescriptorResolver { if (propertyTypeRef == null) { final JetExpression initializer = property.getInitializer(); if (initializer == null) { - PsiElement nameIdentifier = property.getNameIdentifier(); - if (nameIdentifier != null) { - trace.report(PROPERTY_WITH_NO_TYPE_NO_INITIALIZER.on(nameIdentifier)); - } return ErrorUtils.createErrorType("No type, no body"); } else { diff --git a/compiler/testData/diagnostics/tests/Abstract.jet b/compiler/testData/diagnostics/tests/Abstract.jet index 35a73b65f5a..b0eeeaaddb9 100644 --- a/compiler/testData/diagnostics/tests/Abstract.jet +++ b/compiler/testData/diagnostics/tests/Abstract.jet @@ -1,17 +1,17 @@ // FILE: b.kt package MyNamespace //properties - val a: Int + val a: Int val a1: Int = 1 abstract val a2: Int abstract val a3: Int = 1 - var b: Int private set + var b: Int private set var b1: Int = 0; private set abstract var b2: Int private set abstract var b3: Int = 0; private set - var c: Int set(v: Int) { $c = v } + var c: Int set(v: Int) { $c = v } var c1: Int = 0; set(v: Int) { $c1 = v } abstract var c2: Int set(v: Int) { $c2 = v } abstract var c3: Int = 0; set(v: Int) { $c3 = v } @@ -22,7 +22,7 @@ package MyNamespace abstract val e3: Int = 0; get() = a //methods - fun f() + fun f() fun g() {} abstract fun h() abstract fun j() {} @@ -34,7 +34,7 @@ package MyNamespace var j: Int get() = i; abstract set var j1: Int = 0; get() = i; abstract set - var k: Int abstract set + var k: Int abstract set var k1: Int = 0; abstract set var l: Int abstract get abstract set diff --git a/compiler/testData/diagnostics/tests/AbstractInAbstractClass.jet b/compiler/testData/diagnostics/tests/AbstractInAbstractClass.jet index 0501b6ec31a..218bb40075e 100644 --- a/compiler/testData/diagnostics/tests/AbstractInAbstractClass.jet +++ b/compiler/testData/diagnostics/tests/AbstractInAbstractClass.jet @@ -2,17 +2,17 @@ package abstract abstract class MyAbstractClass() { //properties - val a: Int + val a: Int val a1: Int = 1 abstract val a2: Int abstract val a3: Int = 1 - var b: Int private set + var b: Int private set var b1: Int = 0; private set abstract var b2: Int private set abstract var b3: Int = 0; private set - var c: Int set(v: Int) { $c = v } + var c: Int set(v: Int) { $c = v } var c1: Int = 0; set(v: Int) { $c1 = v } abstract var c2: Int set(v: Int) { $c2 = v } abstract var c3: Int = 0; set(v: Int) { $c3 = v } @@ -23,7 +23,7 @@ abstract class MyAbstractClass() { abstract val e3: Int = 0; get() = a //methods - fun f() + fun f() fun g() {} abstract fun h() abstract fun j() {} @@ -35,12 +35,11 @@ abstract class MyAbstractClass() { var j: Int get() = i; abstract set var j1: Int get() = i; abstract set - var k: Int abstract set + var k: Int abstract set var k1: Int = 0; abstract set var l: Int abstract get abstract set var l1: Int = 0; abstract get abstract set var n: Int abstract get abstract set(v: Int) {} -} - +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/AbstractInClass.jet b/compiler/testData/diagnostics/tests/AbstractInClass.jet index 1c3fd6fc74c..587fbecf3e6 100644 --- a/compiler/testData/diagnostics/tests/AbstractInClass.jet +++ b/compiler/testData/diagnostics/tests/AbstractInClass.jet @@ -2,17 +2,17 @@ package abstract class MyClass() { //properties - val a: Int + val a: Int val a1: Int = 1 abstract val a2: Int abstract val a3: Int = 1 - var b: Int private set + var b: Int private set var b1: Int = 0; private set abstract var b2: Int private set abstract var b3: Int = 0; private set - var c: Int set(v: Int) { $c = v } + var c: Int set(v: Int) { $c = v } var c1: Int = 0; set(v: Int) { $c1 = v } abstract var c2: Int set(v: Int) { $c2 = v } abstract var c3: Int = 0; set(v: Int) { $c3 = v } @@ -23,7 +23,7 @@ class MyClass() { abstract val e3: Int = 0; get() = a //methods - fun f() + fun f() fun g() {} abstract fun h() abstract fun j() {} @@ -35,12 +35,11 @@ class MyClass() { var j: Int get() = i; abstract set var j1: Int = 0; get() = i; abstract set - var k: Int abstract set + var k: Int abstract set var k1: Int = 0; abstract set var l: Int abstract get abstract set var l1: Int = 0; abstract get abstract set var n: Int abstract get abstract set(v: Int) {} -} - +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/AbstractInEnum.jet b/compiler/testData/diagnostics/tests/AbstractInEnum.jet index 46d557bc435..fe330dd5291 100644 --- a/compiler/testData/diagnostics/tests/AbstractInEnum.jet +++ b/compiler/testData/diagnostics/tests/AbstractInEnum.jet @@ -3,17 +3,17 @@ package abstract enum class MyEnum() { //properties - val a: Int + val a: Int val a1: Int = 1 abstract val a2: Int abstract val a3: Int = 1 - var b: Int private set + var b: Int private set var b1: Int = 0; private set abstract var b2: Int private set abstract var b3: Int = 0; private set - var c: Int set(v: Int) { $c = v } + var c: Int set(v: Int) { $c = v } var c1: Int = 0; set(v: Int) { $c1 = v } abstract var c2: Int set(v: Int) { $c2 = v } abstract var c3: Int = 0; set(v: Int) { $c3 = v } @@ -24,7 +24,7 @@ enum class MyEnum() { abstract val e3: Int = 0; get() = a //methods - fun f() + fun f() fun g() {} abstract fun h() abstract fun j() {} @@ -36,12 +36,11 @@ enum class MyEnum() { var j: Int get() = i; abstract set var j1: Int = 0; get() = i; abstract set - var k: Int abstract set + var k: Int abstract set var k1: Int = 0; abstract set var l: Int abstract get abstract set var l1: Int = 0; abstract get abstract set var n: Int abstract get abstract set(v: Int) {} -} - +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/AbstractInTrait.jet b/compiler/testData/diagnostics/tests/AbstractInTrait.jet index cb9aff440f1..777898b1f12 100644 --- a/compiler/testData/diagnostics/tests/AbstractInTrait.jet +++ b/compiler/testData/diagnostics/tests/AbstractInTrait.jet @@ -12,8 +12,8 @@ trait MyTrait { abstract var b2: Int private set abstract var b3: Int = 0; private set - var c: Int set(v: Int) { $c = v } - var c1: Int = 0; set(v: Int) { $c1 = v } + var c: Int set(v: Int) { $c = v } + var c1: Int = 0; set(v: Int) { $c1 = v } abstract var c2: Int set(v: Int) { $c2 = v } abstract var c3: Int = 0; set(v: Int) { $c3 = v } @@ -42,4 +42,4 @@ trait MyTrait { var l1: Int = 0; abstract get abstract set var n: Int abstract get abstract set(v: Int) {} -} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/Constructors.jet b/compiler/testData/diagnostics/tests/Constructors.jet index fbce71c5942..7781fdecedd 100644 --- a/compiler/testData/diagnostics/tests/Constructors.jet +++ b/compiler/testData/diagnostics/tests/Constructors.jet @@ -28,12 +28,12 @@ class WithPC1(a : Int) { } -class Foo() : WithPC0, this() { +class Foo() : WithPC0, this() { } class WithCPI_Dup(x : Int) { - var x : Int + var x : Int } class WithCPI(x : Int) { diff --git a/compiler/testData/diagnostics/tests/FunctionReturnTypes.jet b/compiler/testData/diagnostics/tests/FunctionReturnTypes.jet index 1ee14186849..5202b74ec61 100644 --- a/compiler/testData/diagnostics/tests/FunctionReturnTypes.jet +++ b/compiler/testData/diagnostics/tests/FunctionReturnTypes.jet @@ -168,9 +168,9 @@ fun f(): Int { fun f1(): Int = if (1 < 2) 1 else returnNothing() -public fun f2() = 1 +public fun f2() = 1 class B() { - protected fun f() = "ss" + protected fun f() = "ss" } fun testFunctionLiterals() { diff --git a/compiler/testData/diagnostics/tests/IllegalModifiers.jet b/compiler/testData/diagnostics/tests/IllegalModifiers.jet index 4310bafcdc3..af975b94c9d 100644 --- a/compiler/testData/diagnostics/tests/IllegalModifiers.jet +++ b/compiler/testData/diagnostics/tests/IllegalModifiers.jet @@ -5,7 +5,7 @@ abstract class A() { abstract open fun g() final open fun h() {} - open var r: String + open var r: String get abstract protected set } @@ -18,4 +18,4 @@ class FinalClass() { open get(): Int = $i var j: Int = 1 open set(v: Int) {} -} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/PrimaryConstructors.jet b/compiler/testData/diagnostics/tests/PrimaryConstructors.jet index 250ee0d30df..5d88604bae2 100644 --- a/compiler/testData/diagnostics/tests/PrimaryConstructors.jet +++ b/compiler/testData/diagnostics/tests/PrimaryConstructors.jet @@ -1,5 +1,5 @@ class X { - val x : Int + val x : Int } open class Y() { @@ -26,4 +26,4 @@ class MyIterable : Iterable throw UnsupportedOperationException() } } -} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/Properties.jet b/compiler/testData/diagnostics/tests/Properties.jet index 437fb593054..aa2d11b6880 100644 --- a/compiler/testData/diagnostics/tests/Properties.jet +++ b/compiler/testData/diagnostics/tests/Properties.jet @@ -25,5 +25,5 @@ class Test() { $b = $a a = $b } - public val i = 1 + public val i = 1 } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/UninitializedOrReassignedVariables.jet b/compiler/testData/diagnostics/tests/UninitializedOrReassignedVariables.jet index 115c131f135..27be26f068d 100644 --- a/compiler/testData/diagnostics/tests/UninitializedOrReassignedVariables.jet +++ b/compiler/testData/diagnostics/tests/UninitializedOrReassignedVariables.jet @@ -161,7 +161,7 @@ class AnonymousInitializers(var a: String, val b: String) { } } - val o: String + val o: String { if (1 < 3) { $o = "a" @@ -198,7 +198,7 @@ open class Open(a: Int, w: Int) {} class LocalValsVsProperties(val a: Int, w: Int) : Open(a, w) { val x : Int - val y : Int + val y : Int { $x = 1 val b = x @@ -267,7 +267,7 @@ class ClassObject() { fun foo() { val a = object { val x : Int - val y : Int + val y : Int val z : Int { $x = 1 @@ -281,11 +281,11 @@ fun foo() { } class TestObjectExpression() { - val a : Int + val a : Int fun foo() { val a = object { val x : Int - val y : Int + val y : Int { if (true) x = 12 @@ -308,7 +308,7 @@ class TestObjectExpression() { object TestObjectDeclaration { val x : Int - val y : Int + val y : Int { $x = 1 } @@ -349,4 +349,4 @@ fun test(m : M) { fun test1(m : M) { m.x++ m.y-- -} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/extensions/ExtensionFunctions.jet b/compiler/testData/diagnostics/tests/extensions/ExtensionFunctions.jet index 8051f93bbc1..02da9a79a31 100644 --- a/compiler/testData/diagnostics/tests/extensions/ExtensionFunctions.jet +++ b/compiler/testData/diagnostics/tests/extensions/ExtensionFunctions.jet @@ -36,7 +36,7 @@ fun test() { val Int.abs : Int get() = if (this > 0) this else -this; -val T.foo : T +val T.foo : T fun Int.foo() = this @@ -72,4 +72,4 @@ import outer.* c?.equals2(null) if (command == null) 1 - } + } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/funEquals.jet b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/funEquals.jet new file mode 100644 index 00000000000..b397ef72dc6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/funEquals.jet @@ -0,0 +1 @@ +fun foo() = diff --git a/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/funKeyword.jet b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/funKeyword.jet new file mode 100644 index 00000000000..2f860b37dbf --- /dev/null +++ b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/funKeyword.jet @@ -0,0 +1 @@ +fun \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/incompleteVal.jet b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/incompleteVal.jet new file mode 100644 index 00000000000..f64b8ae0cff --- /dev/null +++ b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/incompleteVal.jet @@ -0,0 +1,3 @@ +package c + +val i = diff --git a/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/incompleteValWithAccessor.jet b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/incompleteValWithAccessor.jet new file mode 100644 index 00000000000..400320515ef --- /dev/null +++ b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/incompleteValWithAccessor.jet @@ -0,0 +1,3 @@ +package c + +val i : String get() = \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/incompleteWhen.jet b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/incompleteWhen.jet new file mode 100644 index 00000000000..d76fd7427d0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/incompleteWhen.jet @@ -0,0 +1,3 @@ +fun test(a: Any) { + when (a) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/namedFun.jet b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/namedFun.jet new file mode 100644 index 00000000000..2a484039cfe --- /dev/null +++ b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/namedFun.jet @@ -0,0 +1 @@ +fun bar() diff --git a/compiler/testData/diagnostics/tests/incompleteCode/incompleteAssignment.jet b/compiler/testData/diagnostics/tests/incompleteCode/incompleteAssignment.jet index df22e37e58c..0c45eac6f7e 100644 --- a/compiler/testData/diagnostics/tests/incompleteCode/incompleteAssignment.jet +++ b/compiler/testData/diagnostics/tests/incompleteCode/incompleteAssignment.jet @@ -6,7 +6,7 @@ fun sum(a : IntArray) : Int { res = 0 for (e in a) res += -} +} fun main(args : Array) { test(0) test(1, 1) @@ -27,4 +27,4 @@ fun assertEquals(actual : T?, expected : T?, message : Any? = null) { else throw AssertionError(message) } -} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/infos/PropertiesWithBackingFields.jet b/compiler/testData/diagnostics/tests/infos/PropertiesWithBackingFields.jet index 5673109ef75..f157ae0c1c5 100644 --- a/compiler/testData/diagnostics/tests/infos/PropertiesWithBackingFields.jet +++ b/compiler/testData/diagnostics/tests/infos/PropertiesWithBackingFields.jet @@ -3,8 +3,8 @@ abstract class Test() { abstract val x1 : Int get abstract val x2 : Int get() = 1 - val a : Int - val b : Int get + val a : Int + val b : Int get val c = 1 val c1 = 1 @@ -15,7 +15,7 @@ abstract class Test() { get() { return 1 } val c4 : Int get() = 1 - val c5 : Int + val c5 : Int get() = $c5 + 1 abstract var y : Int @@ -26,19 +26,19 @@ abstract class Test() { abstract var y5 : Int set(x) {} get() = 1 abstract var y6 : Int set(x) {} - var v : Int - var v1 : Int get - var v2 : Int get set - var v3 : Int get() = 1; set + var v : Int + var v1 : Int get + var v2 : Int get set + var v3 : Int get() = 1; set var v4 : Int get() = 1; set(x){} - var v5 : Int get() = 1; set(x){$v5 = x} - var v6 : Int get() = $v6 + 1; set(x){} + var v5 : Int get() = 1; set(x){$v5 = x} + var v6 : Int get() = $v6 + 1; set(x){} abstract val v7 : Int get abstract var v8 : Int get set - var v9 : Int set - var v10 : Int get + var v9 : Int set + var v10 : Int get abstract val v11 : Int abstract get abstract var v12 : Int abstract get abstract set @@ -56,4 +56,4 @@ class TestPCParameters(w : Int, x : Int, val y : Int, var z : Int) : Super(w) { fun foo() = x -} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/override/ComplexValRedeclaration.jet b/compiler/testData/diagnostics/tests/override/ComplexValRedeclaration.jet index d2927deec76..24c27d44bfb 100644 --- a/compiler/testData/diagnostics/tests/override/ComplexValRedeclaration.jet +++ b/compiler/testData/diagnostics/tests/override/ComplexValRedeclaration.jet @@ -5,5 +5,5 @@ abstract class MyAbstractClass { } abstract class MyLegalAbstractClass2(t : T) : MyAbstractClass() { - val pr : T = t -} + val pr : T = t +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/override/ConflictingPropertySignatureFromSuperclass.jet b/compiler/testData/diagnostics/tests/override/ConflictingPropertySignatureFromSuperclass.jet index dd4b57b2031..c38f3682183 100644 --- a/compiler/testData/diagnostics/tests/override/ConflictingPropertySignatureFromSuperclass.jet +++ b/compiler/testData/diagnostics/tests/override/ConflictingPropertySignatureFromSuperclass.jet @@ -3,5 +3,5 @@ open class Aaa() { } open class Bbb() : Aaa() { - val bar = "aa" -} + val bar = "aa" +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/override/Generics.jet b/compiler/testData/diagnostics/tests/override/Generics.jet index f356b2b0117..5dbff912acf 100644 --- a/compiler/testData/diagnostics/tests/override/Generics.jet +++ b/compiler/testData/diagnostics/tests/override/Generics.jet @@ -23,8 +23,8 @@ open class MyGenericClass(t : T) : MyTrait, MyAbstractClass(), MyProps< class MyChildClass() : MyGenericClass(1) {} class MyChildClass1(t : T) : MyGenericClass(t) {} class MyChildClass2(t : T) : MyGenericClass(t) { - fun foo(t: T) = t - val pr : T = t + fun foo(t: T) = t + val pr : T = t override fun bar(t: T) = t override val p : T = t } @@ -43,7 +43,7 @@ abstract class MyAbstractClass1 : MyTrait, MyAbstractClass() { class MyIllegalGenericClass1 : MyTrait, MyAbstractClass() {} class MyIllegalGenericClass2(r : R) : MyTrait, MyAbstractClass() { override fun foo(r: R) = r - override val pr : R = r + override val pr : R = r } class MyIllegalClass1 : MyTrait, MyAbstractClass() {} abstract class MyLegalAbstractClass1 : MyTrait, MyAbstractClass() {} @@ -51,10 +51,10 @@ abstract class MyLegalAbstractClass1 : MyTrait, MyAbstractClass() { class MyIllegalClass2(t : T) : MyTrait, MyAbstractClass() { fun foo(t: T) = t fun bar(t: T) = t - val pr : T = t + val pr : T = t } abstract class MyLegalAbstractClass2(t : T) : MyTrait, MyAbstractClass() { fun foo(t: T) = t fun bar(t: T) = t - val pr : T = t -} + val pr : T = t +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/override/MultipleDefaultParametersInSupertypes.jet b/compiler/testData/diagnostics/tests/override/MultipleDefaultParametersInSupertypes.jet index 69057c4aecd..aad916d41ef 100644 --- a/compiler/testData/diagnostics/tests/override/MultipleDefaultParametersInSupertypes.jet +++ b/compiler/testData/diagnostics/tests/override/MultipleDefaultParametersInSupertypes.jet @@ -7,9 +7,9 @@ trait Y { } class Z : X, Y { - override fun foo(a : Int) {} + override fun foo(a : Int) {} } object ZO : X, Y { - override fun foo(a : Int) {} + override fun foo(a : Int) {} } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/override/MultipleDefaultParametersInSupertypesNoOverride.jet b/compiler/testData/diagnostics/tests/override/MultipleDefaultParametersInSupertypesNoOverride.jet index 647f92f359f..c3cc0415c30 100644 --- a/compiler/testData/diagnostics/tests/override/MultipleDefaultParametersInSupertypesNoOverride.jet +++ b/compiler/testData/diagnostics/tests/override/MultipleDefaultParametersInSupertypesNoOverride.jet @@ -7,9 +7,9 @@ trait Y { } class Z : X, Y { - fun foo(a : Int) {} + fun foo(a : Int) {} } object ZO : X, Y { - fun foo(a : Int) {} + fun foo(a : Int) {} } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/override/NonGenerics.jet b/compiler/testData/diagnostics/tests/override/NonGenerics.jet index 59d099ed572..f61c506e0ad 100644 --- a/compiler/testData/diagnostics/tests/override/NonGenerics.jet +++ b/compiler/testData/diagnostics/tests/override/NonGenerics.jet @@ -36,15 +36,15 @@ class MyIllegalClass3() : MyTrait, MyAbstr } class MyIllegalClass4() : MyTrait, MyAbstractClass() { - fun foo() {} - val pr : Unit + fun foo() {} + val pr : Unit override fun other() {} override val otherPr : Int = 1 } class MyChildClass1() : MyClass() { - fun foo() {} - val pr : Unit = #() + fun foo() {} + val pr : Unit = #() override fun bar() {} override val prr : Unit = #() -} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/scopes/kt1822.jet b/compiler/testData/diagnostics/tests/scopes/kt1822.jet index 77031e1edf5..75282544459 100644 --- a/compiler/testData/diagnostics/tests/scopes/kt1822.jet +++ b/compiler/testData/diagnostics/tests/scopes/kt1822.jet @@ -10,7 +10,7 @@ trait T { } class G : C(), T { - override fun foo() {} //should be an error "cannot infer visibility"; for now 'public' is inferred in such cases + override fun foo() {} //should be an error "cannot infer visibility"; for now 'public' is inferred in such cases } open class A { diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java index c11debd4cdd..1ee55bb828d 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java @@ -142,6 +142,7 @@ public class JetPsiChecker implements Annotator { private static void registerDiagnosticAnnotations(@NotNull Diagnostic diagnostic, @NotNull Set redeclarations, @NotNull final AnnotationHolder holder) { + if (!diagnostic.isValid()) return; List textRanges = diagnostic.getTextRanges(); if (diagnostic.getSeverity() == Severity.ERROR) { if (diagnostic.getFactory() == Errors.UNRESOLVED_IDE_TEMPLATE) { @@ -271,7 +272,7 @@ public class JetPsiChecker implements Annotator { @NotNull AnnotationHolder holder) { if (!redeclarations.add(redeclarationDiagnostic.getPsiElement())) return null; List textRanges = redeclarationDiagnostic.getTextRanges(); - if (textRanges.isEmpty()) return null; + if (!redeclarationDiagnostic.isValid()) return null; Annotation annotation = holder.createErrorAnnotation(textRanges.get(0), ""); annotation.setTooltip(getMessage(redeclarationDiagnostic)); return annotation; diff --git a/idea/testData/checker/Abstract.jet b/idea/testData/checker/Abstract.jet index 07f39c65a4b..5b8e02c093d 100644 --- a/idea/testData/checker/Abstract.jet +++ b/idea/testData/checker/Abstract.jet @@ -2,17 +2,17 @@ package abstract class MyClass() { //properties - val a: Int + val a: Int val a1: Int = 1 abstract val a2: Int abstract val a3: Int = 1 - var b: Int private set + var b: Int private set var b1: Int = 0; private set abstract var b2: Int private set abstract var b3: Int = 0; private set - var c: Int set(v: Int) { $c = v } + var c: Int set(v: Int) { $c = v } var c1: Int = 0; set(v: Int) { $c1 = v } abstract var c2: Int set(v: Int) { $c2 = v } abstract var c3: Int = 0; set(v: Int) { $c3 = v } @@ -23,7 +23,7 @@ class MyClass() { abstract val e3: Int = 0; get() = a //methods - fun f() + fun f() fun g() {} abstract fun h() abstract fun j() {} @@ -31,17 +31,17 @@ class MyClass() { abstract class MyAbstractClass() { //properties - val a: Int + val a: Int val a1: Int = 1 abstract val a2: Int abstract val a3: Int = 1 - var b: Int private set + var b: Int private set var b1: Int = 0; private set abstract var b2: Int private set abstract var b3: Int = 0; private set - var c: Int set(v: Int) { $c = v } + var c: Int set(v: Int) { $c = v } var c1: Int = 0; set(v: Int) { $c1 = v } abstract var c2: Int set(v: Int) { $c2 = v } abstract var c3: Int = 0; set(v: Int) { $c3 = v } @@ -52,7 +52,7 @@ abstract class MyAbstractClass() { abstract val e3: Int = 0; get() = a //methods - fun f() + fun f() fun g() {} abstract fun h() abstract fun j() {} @@ -70,8 +70,8 @@ trait MyTrait { abstract var b2: Int private set abstract var b3: Int = 0; private set - var c: Int set(v: Int) { $c = v } - var c1: Int = 0; set(v: Int) { $c1 = v } + var c: Int set(v: Int) { $c = v } + var c1: Int = 0; set(v: Int) { $c1 = v } abstract var c2: Int set(v: Int) { $c2 = v } abstract var c3: Int = 0; set(v: Int) { $c3 = v } @@ -89,17 +89,17 @@ trait MyTrait { enum class MyEnum() { //properties - val a: Int + val a: Int val a1: Int = 1 abstract val a2: Int abstract val a3: Int = 1 - var b: Int private set + var b: Int private set var b1: Int = 0; private set abstract var b2: Int private set abstract var b3: Int = 0; private set - var c: Int set(v: Int) { $c = v } + var c: Int set(v: Int) { $c = v } var c1: Int = 0; set(v: Int) { $c1 = v } abstract var c2: Int set(v: Int) { $c2 = v } abstract var c3: Int = 0; set(v: Int) { $c3 = v } @@ -110,7 +110,7 @@ enum class MyEnum() { abstract val e3: Int = 0; get() = a //methods - fun f() + fun f() fun g() {} abstract fun h() abstract fun j() {} @@ -120,17 +120,17 @@ abstract enum class MyAbstractEnum() {} //package MyNamespace { //properties - val a: Int + val a: Int val a1: Int = 1 abstract val a2: Int abstract val a3: Int = 1 - var b: Int private set + var b: Int private set var b1: Int = 0; private set abstract var b2: Int private set abstract var b3: Int = 0; private set - var c: Int set(v: Int) { $c = v } + var c: Int set(v: Int) { $c = v } var c1: Int = 0; set(v: Int) { $c1 = v } abstract var c2: Int set(v: Int) { $c2 = v } abstract var c3: Int = 0; set(v: Int) { $c3 = v } @@ -141,7 +141,7 @@ abstract enum class MyAbstractEnum() {} abstract val e3: Int = 0; get() = a //methods - fun f() + fun f() fun g() {} abstract fun h() abstract fun j() {} diff --git a/idea/testData/checker/Constructors.jet b/idea/testData/checker/Constructors.jet index cbd1033db99..6ee22576d6c 100644 --- a/idea/testData/checker/Constructors.jet +++ b/idea/testData/checker/Constructors.jet @@ -34,7 +34,7 @@ class Foo() : WithPC0(), this() { } class WithCPI_Dup(x : Int) { - var x : Int + var x : Int } class WithCPI(x : Int) { diff --git a/idea/testData/checker/ExtensionFunctions.jet b/idea/testData/checker/ExtensionFunctions.jet index 7548d4db054..78561cef3ec 100644 --- a/idea/testData/checker/ExtensionFunctions.jet +++ b/idea/testData/checker/ExtensionFunctions.jet @@ -33,7 +33,7 @@ fun test() { val Int.abs : Int get() = if (this > 0) this else -this; -val T.foo : T +val T.foo : T fun Int.foo() = this diff --git a/idea/testData/checker/Override.jet b/idea/testData/checker/Override.jet index 3d1e6876cc1..4450315a952 100644 --- a/idea/testData/checker/Override.jet +++ b/idea/testData/checker/Override.jet @@ -26,11 +26,11 @@ package override } class MyIllegalClass4 : MyTrait, MyAbstractClass() { - fun foo() {} + fun foo() {} override fun other() {} } class MyChildClass1 : MyClass() { - fun foo() {} + fun foo() {} override fun bar() {} } diff --git a/idea/testData/checker/OverridesAndGenerics.jet b/idea/testData/checker/OverridesAndGenerics.jet index 8452a4dcb9e..009961e6adb 100644 --- a/idea/testData/checker/OverridesAndGenerics.jet +++ b/idea/testData/checker/OverridesAndGenerics.jet @@ -14,7 +14,7 @@ class MyChildClass : MyGenericClass() {} class MyChildClass1 : MyGenericClass() {} class MyChildClass2 : MyGenericClass() { - fun foo(t: T) = t + fun foo(t: T) = t override fun bar(t: T) = t } diff --git a/idea/testData/checker/PrimaryConstructors.jet b/idea/testData/checker/PrimaryConstructors.jet index 4b5c750568c..c38e9008be3 100644 --- a/idea/testData/checker/PrimaryConstructors.jet +++ b/idea/testData/checker/PrimaryConstructors.jet @@ -1,5 +1,5 @@ class X { - val x : Int + val x : Int } open class Y() { diff --git a/idea/testData/checker/infos/PropertiesWithBackingFields.jet b/idea/testData/checker/infos/PropertiesWithBackingFields.jet index 5e9b644e94c..c37abc5ef15 100644 --- a/idea/testData/checker/infos/PropertiesWithBackingFields.jet +++ b/idea/testData/checker/infos/PropertiesWithBackingFields.jet @@ -3,8 +3,8 @@ abstract val x1 : Int get abstract val x2 : Int get() = 1 - val a : Int - val b : Int get + val a : Int + val b : Int get val c = 1 val c1 = 1 @@ -15,7 +15,7 @@ get() { return 1 } val c4 : Int get() = 1 - val c5 : Int + val c5 : Int get() = $c5 + 1 abstract var y : Int @@ -26,17 +26,17 @@ abstract var y5 : Int set(x) {} get() = 1 abstract var y6 : Int set(x) {} - var v : Int - var v1 : Int get - var v2 : Int get set - var v3 : Int get() = 1; set + var v : Int + var v1 : Int get + var v2 : Int get set + var v3 : Int get() = 1; set var v4 : Int get() = 1; set(x){} - var v5 : Int get() = 1; set(x){$v5 = x} - var v6 : Int get() = $v6 + 1; set(x){} + var v5 : Int get() = 1; set(x){$v5 = x} + var v6 : Int get() = $v6 + 1; set(x){} - var v9 : Int set - var v10 : Int get + var v9 : Int set + var v10 : Int get } -- GitLab