From 146498ec32b2dd7203a92aa3574f1cdfcdb7674d Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Tue, 15 Apr 2014 21:30:51 +0400 Subject: [PATCH] Sort out renderers for diagnostics - change NAMED to be Renderer and render Named's name. It was used in multiple places with arbitrary arguments, not only Named: change renderers in those places to TO_STRING - add STRING, which is Renderer and renders string itself. Change all places where strings were used with either TO_STRING or NAMED to STRING - change NOT_AN_ANNOTATION_CLASS diagnostic to be reported on descriptor, not any string - change "unused variable/parameter" diagnostics to be reported on VariableDescriptor, not Object --- .../jet/lang/diagnostics/Errors.java | 8 +-- .../rendering/DefaultErrorMessages.java | 65 +++++++++---------- .../lang/diagnostics/rendering/Renderers.java | 17 +++-- .../jet/lang/resolve/AnnotationResolver.java | 5 +- .../plugin/highlighter/IdeErrorMessages.java | 10 +-- .../assignedButNeverAccessedVariable.kt | 7 ++ .../assignedButNeverAccessedVariable1.txt | 2 + .../diagnosticMessage/unusedParameter.kt | 4 ++ .../diagnosticMessage/unusedParameter1.txt | 2 + .../diagnosticMessage/unusedVariable.kt | 6 ++ .../diagnosticMessage/unusedVariable1.txt | 2 + .../DiagnosticMessageTestGenerated.java | 15 +++++ 12 files changed, 92 insertions(+), 51 deletions(-) create mode 100644 idea/testData/diagnosticMessage/assignedButNeverAccessedVariable.kt create mode 100644 idea/testData/diagnosticMessage/assignedButNeverAccessedVariable1.txt create mode 100644 idea/testData/diagnosticMessage/unusedParameter.kt create mode 100644 idea/testData/diagnosticMessage/unusedParameter1.txt create mode 100644 idea/testData/diagnosticMessage/unusedVariable.kt create mode 100644 idea/testData/diagnosticMessage/unusedVariable1.txt 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 61474c536bf..97e0f6d1299 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java @@ -115,7 +115,7 @@ public interface Errors { DiagnosticFactory0 SUPERTYPES_FOR_ANNOTATION_CLASS = DiagnosticFactory0.create(ERROR); DiagnosticFactory0 MISSING_VAL_ON_ANNOTATION_PARAMETER = DiagnosticFactory0.create(WARNING); DiagnosticFactory0 ANNOTATION_CLASS_CONSTRUCTOR_CALL = DiagnosticFactory0.create(ERROR); - DiagnosticFactory1 NOT_AN_ANNOTATION_CLASS = DiagnosticFactory1.create(ERROR); + DiagnosticFactory1 NOT_AN_ANNOTATION_CLASS = DiagnosticFactory1.create(ERROR); DiagnosticFactory0 ANNOTATION_CLASS_WITH_BODY = DiagnosticFactory0.create(ERROR); DiagnosticFactory0 INVALID_TYPE_OF_ANNOTATION_MEMBER = DiagnosticFactory0.create(ERROR); DiagnosticFactory0 NULLABLE_TYPE_OF_ANNOTATION_MEMBER = DiagnosticFactory0.create(ERROR); @@ -445,10 +445,10 @@ public interface Errors { 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, NAME_IDENTIFIER); + DiagnosticFactory1 UNUSED_PARAMETER = DiagnosticFactory1.create(WARNING, NAME_IDENTIFIER); - DiagnosticFactory1 ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE = + DiagnosticFactory1 ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE = DiagnosticFactory1.create(WARNING, NAME_IDENTIFIER); DiagnosticFactory1 VARIABLE_WITH_REDUNDANT_INITIALIZER = DiagnosticFactory1.create(WARNING); DiagnosticFactory2 UNUSED_VALUE = DiagnosticFactory2.create(WARNING); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/rendering/DefaultErrorMessages.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/rendering/DefaultErrorMessages.java index 2ee3f3c242a..4f903961f49 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/rendering/DefaultErrorMessages.java @@ -26,7 +26,6 @@ import org.jetbrains.jet.lang.psi.JetTypeConstraint; import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lexer.JetKeywordToken; import org.jetbrains.jet.lexer.JetModifierKeywordToken; -import org.jetbrains.jet.renderer.DescriptorRenderer; import org.jetbrains.jet.renderer.Renderer; import java.lang.reflect.Field; @@ -35,8 +34,7 @@ import java.util.Collection; import static org.jetbrains.jet.lang.diagnostics.Errors.*; import static org.jetbrains.jet.lang.diagnostics.rendering.Renderers.*; -import static org.jetbrains.jet.renderer.DescriptorRenderer.SHORT_NAMES_IN_TYPES; -import static org.jetbrains.jet.renderer.DescriptorRenderer.TEXT; +import static org.jetbrains.jet.renderer.DescriptorRenderer.*; public class DefaultErrorMessages { public static final DiagnosticFactoryToRendererMap MAP = new DiagnosticFactoryToRendererMap(); @@ -56,8 +54,8 @@ public class DefaultErrorMessages { MAP.put(INVISIBLE_REFERENCE, "Cannot access ''{0}'': it is ''{1}'' in ''{2}''", NAME, TO_STRING, NAME); MAP.put(INVISIBLE_MEMBER, "Cannot access ''{0}'': it is ''{1}'' in ''{2}''", NAME, TO_STRING, NAME); - MAP.put(REDECLARATION, "Redeclaration: {0}", NAME); - MAP.put(NAME_SHADOWING, "Name shadowed: {0}", NAME); + MAP.put(REDECLARATION, "Redeclaration: {0}", STRING); + MAP.put(NAME_SHADOWING, "Name shadowed: {0}", STRING); MAP.put(TYPE_MISMATCH, "Type mismatch: inferred type is {1} but {0} was expected", RENDER_TYPE, RENDER_TYPE); MAP.put(INCOMPATIBLE_MODIFIERS, "Incompatible modifiers: ''{0}''", new Renderer>() { @@ -142,8 +140,8 @@ public class DefaultErrorMessages { MAP.put(PROPERTY_INITIALIZER_IN_TRAIT, "Property initializers are not allowed in traits"); MAP.put(FINAL_PROPERTY_IN_TRAIT, "Abstract property in trait cannot be final"); MAP.put(PROPERTY_INITIALIZER_NO_BACKING_FIELD, "Initializer is not allowed here because this property has no backing field"); - MAP.put(ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS, "Abstract property ''{0}'' in non-abstract class ''{1}''", NAME, NAME); - MAP.put(ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS, "Abstract function ''{0}'' in non-abstract class ''{1}''", NAME, NAME); + MAP.put(ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS, "Abstract property ''{0}'' in non-abstract class ''{1}''", STRING, NAME); + MAP.put(ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS, "Abstract function ''{0}'' in non-abstract class ''{1}''", STRING, NAME); MAP.put(ABSTRACT_FUNCTION_WITH_BODY, "A function ''{0}'' with body cannot be abstract", NAME); MAP.put(NON_ABSTRACT_FUNCTION_WITH_NO_BODY, "Function ''{0}'' without a body must be abstract", NAME); MAP.put(FINAL_FUNCTION_WITH_NO_BODY, "Function ''{0}'' without body cannot be final", NAME); @@ -161,7 +159,7 @@ public class DefaultErrorMessages { MAP.put(DATA_CLASS_OVERRIDE_CONFLICT, "Function ''{0}'' generated for the data class conflicts with member of supertype ''{1}''", NAME, NAME); MAP.put(CANNOT_OVERRIDE_INVISIBLE_MEMBER, "''{0}'' cannot has no access to ''{1}'' in class {2}, so it cannot override it", - DescriptorRenderer.TEXT, DescriptorRenderer.TEXT, DescriptorRenderer.TEXT); + TEXT, TEXT, TEXT); MAP.put(CANNOT_INFER_VISIBILITY, "Cannot infer visibility. Please specify it explicitly"); MAP.put(ENUM_ENTRY_SHOULD_BE_INITIALIZED, "Missing delegation specifier ''{0}''", NAME); @@ -219,7 +217,7 @@ public class DefaultErrorMessages { MAP.put(EQUALS_MISSING, "No method 'equals(kotlin.Any?): kotlin.Boolean' available"); MAP.put(ASSIGNMENT_IN_EXPRESSION_CONTEXT, "Assignments are not expressions, and only expressions are allowed in this context"); MAP.put(PACKAGE_IS_NOT_AN_EXPRESSION, "'package' is not an expression, it can only be used on the left-hand side of a dot ('.')"); - MAP.put(SUPER_IS_NOT_AN_EXPRESSION, "''{0}'' is not an expression, it can only be used on the left-hand side of a dot ('.')", TO_STRING); + MAP.put(SUPER_IS_NOT_AN_EXPRESSION, "''{0}'' is not an expression, it can only be used on the left-hand side of a dot ('.')", STRING); MAP.put(DECLARATION_IN_ILLEGAL_CONTEXT, "Declarations are not allowed in this position"); MAP.put(SETTER_PARAMETER_WITH_DEFAULT_VALUE, "Setter parameters cannot have default values"); MAP.put(NO_THIS, "'this' is not defined in this context"); @@ -255,11 +253,12 @@ public class DefaultErrorMessages { MAP.put(ITERATOR_MISSING, "For-loop range must have an iterator() method"); MAP.put(ITERATOR_AMBIGUITY, "Method ''iterator()'' is ambiguous for this expression: {0}", AMBIGUOUS_CALLS); - MAP.put(DELEGATE_SPECIAL_FUNCTION_MISSING, "Missing ''{0}'' method on delegate of type ''{1}''", TO_STRING, RENDER_TYPE); - MAP.put(DELEGATE_SPECIAL_FUNCTION_AMBIGUITY, "Overload resolution ambiguity on method ''{0}'': {1}", TO_STRING, AMBIGUOUS_CALLS); - MAP.put(DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE, "Property delegate must have a ''{0}'' method. None of the following functions is suitable: {1}", TO_STRING, AMBIGUOUS_CALLS); + MAP.put(DELEGATE_SPECIAL_FUNCTION_MISSING, "Missing ''{0}'' method on delegate of type ''{1}''", STRING, RENDER_TYPE); + MAP.put(DELEGATE_SPECIAL_FUNCTION_AMBIGUITY, "Overload resolution ambiguity on method ''{0}'': {1}", STRING, AMBIGUOUS_CALLS); + MAP.put(DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE, "Property delegate must have a ''{0}'' method. None of the following functions is suitable: {1}", + STRING, AMBIGUOUS_CALLS); MAP.put(DELEGATE_SPECIAL_FUNCTION_RETURN_TYPE_MISMATCH, "The ''{0}'' function of property delegate is expected to return ''{1}'', but returns ''{2}''", - TO_STRING, RENDER_TYPE, RENDER_TYPE); + STRING, RENDER_TYPE, RENDER_TYPE); MAP.put(COMPARE_TO_TYPE_MISMATCH, "''compareTo()'' must return kotlin.Int, but returns {0}", RENDER_TYPE); @@ -294,9 +293,9 @@ public class DefaultErrorMessages { MAP.put(CONFLICTING_UPPER_BOUNDS, "Upper bounds of {0} have empty intersection", NAME); MAP.put(CONFLICTING_CLASS_OBJECT_UPPER_BOUNDS, "Class object upper bounds of {0} have empty intersection", NAME); - MAP.put(TOO_MANY_ARGUMENTS, "Too many arguments for {0}", DescriptorRenderer.TEXT); + MAP.put(TOO_MANY_ARGUMENTS, "Too many arguments for {0}", TEXT); - MAP.put(CONSTANT_EXPECTED_TYPE_MISMATCH, "An {0} literal does not conform to the expected type {1}", TO_STRING, RENDER_TYPE); + MAP.put(CONSTANT_EXPECTED_TYPE_MISMATCH, "An {0} literal does not conform to the expected type {1}", STRING, RENDER_TYPE); MAP.put(INTEGER_OVERFLOW, "This operation has led to an overflow"); MAP.put(INT_LITERAL_OUT_OF_RANGE, "The value is out of range"); MAP.put(WRONG_LONG_SUFFIX, "Use 'L' instead of 'l'"); @@ -322,14 +321,14 @@ public class DefaultErrorMessages { MAP.put(FINAL_SUPERTYPE, "This type is final, so it cannot be inherited from"); MAP.put(SINGLETON_IN_SUPERTYPE, "Cannot inherit from a singleton"); - MAP.put(ILLEGAL_SELECTOR, "Expression ''{0}'' cannot be a selector (occur after a dot)", TO_STRING); + MAP.put(ILLEGAL_SELECTOR, "Expression ''{0}'' cannot be a selector (occur after a dot)", STRING); MAP.put(NO_TAIL_CALLS_FOUND, "A function is marked as tail-recursive but no tail calls are found"); MAP.put(VALUE_PARAMETER_WITH_NO_TYPE_ANNOTATION, "A type annotation is required on a value parameter"); MAP.put(BREAK_OR_CONTINUE_OUTSIDE_A_LOOP, "'break' and 'continue' are only allowed inside a loop"); MAP.put(BREAK_OR_CONTINUE_JUMPS_ACROSS_FUNCTION_BOUNDARY, "'break' or 'continue' jumps across a function boundary"); - MAP.put(NOT_A_LOOP_LABEL, "The label ''{0}'' does not denote a loop", TO_STRING); - MAP.put(NOT_A_RETURN_LABEL, "The label ''{0}'' does not reference to a context from which we can return", TO_STRING); + MAP.put(NOT_A_LOOP_LABEL, "The label ''{0}'' does not denote a loop", STRING); + MAP.put(NOT_A_RETURN_LABEL, "The label ''{0}'' does not reference to a context from which we can return", STRING); MAP.put(ANONYMOUS_INITIALIZER_IN_TRAIT, "Anonymous initializers are not allowed in traits"); MAP.put(NULLABLE_SUPERTYPE, "A supertype cannot be nullable"); @@ -339,7 +338,7 @@ public class DefaultErrorMessages { "Using ''{0}?'' is likely to mislead the reader", RENDER_TYPE); MAP.put(UNSAFE_CALL, "Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type {0}", RENDER_TYPE); MAP.put(AMBIGUOUS_LABEL, "Ambiguous label"); - MAP.put(UNSUPPORTED, "Unsupported [{0}]", TO_STRING); + MAP.put(UNSUPPORTED, "Unsupported [{0}]", STRING); MAP.put(UNNECESSARY_SAFE_CALL, "Unnecessary safe call on a non-null receiver of type {0}", RENDER_TYPE); MAP.put(UNNECESSARY_NOT_NULL_ASSERTION, "Unnecessary non-null assertion (!!) on a non-null receiver of type {0}", RENDER_TYPE); MAP.put(NAME_IN_CONSTRAINT_IS_NOT_A_TYPE_PARAMETER, "{0} does not refer to a type parameter of {1}", new Renderer() { @@ -349,9 +348,9 @@ public class DefaultErrorMessages { //noinspection ConstantConditions return typeConstraint.getSubjectTypeParameterName().getReferencedName(); } - }, NAME); - MAP.put(AUTOCAST_IMPOSSIBLE, "Automatic cast to ''{0}'' is impossible, because ''{1}'' could have changed since the is-check", RENDER_TYPE, - NAME); + }, TO_STRING); + MAP.put(AUTOCAST_IMPOSSIBLE, + "Automatic cast to ''{0}'' is impossible, because ''{1}'' could have changed since the is-check", RENDER_TYPE, STRING); MAP.put(VARIANCE_ON_TYPE_PARAMETER_OF_FUNCTION_OR_PROPERTY, "Variance annotations are only allowed for type parameters of classes and traits"); MAP.put(REDUNDANT_PROJECTION, "Projection is redundant: the corresponding type parameter of {0} has the same variance", NAME); @@ -385,21 +384,19 @@ public class DefaultErrorMessages { MAP.put(CANNOT_CHANGE_ACCESS_PRIVILEGE, "Cannot change access privilege ''{0}'' for ''{1}'' in ''{2}''", TO_STRING, NAME, NAME); MAP.put(RETURN_TYPE_MISMATCH_ON_OVERRIDE, "Return type of ''{0}'' is not a subtype of the return type of overridden member {1}", - NAME, DescriptorRenderer.TEXT); + NAME, TEXT); - MAP.put(PROPERTY_TYPE_MISMATCH_ON_OVERRIDE, "Type of ''{0}'' doesn't match to the type of overridden var-property {1}", - NAME, DescriptorRenderer.TEXT); + MAP.put(PROPERTY_TYPE_MISMATCH_ON_OVERRIDE, "Type of ''{0}'' doesn't match to the type of overridden var-property {1}", NAME, TEXT); - MAP.put(VAR_OVERRIDDEN_BY_VAL, "Var-property {0} cannot be overridden by val-property {1}", DescriptorRenderer.TEXT, - DescriptorRenderer.TEXT); + MAP.put(VAR_OVERRIDDEN_BY_VAL, "Var-property {0} cannot be overridden by val-property {1}", TEXT, TEXT); MAP.put(ABSTRACT_MEMBER_NOT_IMPLEMENTED, "{0} must be declared abstract or implement abstract member {1}", RENDER_CLASS_OR_OBJECT, - DescriptorRenderer.TEXT); + TEXT); MAP.put(MANY_IMPL_MEMBER_NOT_IMPLEMENTED, "{0} must override {1} because it inherits many implementations of it", - RENDER_CLASS_OR_OBJECT, DescriptorRenderer.TEXT); + RENDER_CLASS_OR_OBJECT, TEXT); - MAP.put(CONFLICTING_OVERLOADS, "''{0}'' is already defined in {1}", DescriptorRenderer.COMPACT_WITH_MODIFIERS, TO_STRING); + MAP.put(CONFLICTING_OVERLOADS, "''{0}'' is already defined in {1}", COMPACT_WITH_MODIFIERS, STRING); MAP.put(FUNCTION_EXPECTED, "Expression ''{0}''{1} cannot be invoked as a function. The function 'invoke()' is not found", ELEMENT_TEXT, new Renderer() { @NotNull @@ -419,11 +416,11 @@ public class DefaultErrorMessages { MAP.put(NON_TAIL_RECURSIVE_CALL, "Recursive call is not a tail call"); MAP.put(TAIL_RECURSION_IN_TRY_IS_NOT_SUPPORTED, "Tail recursion optimization inside try/catch/finally is not supported"); - MAP.put(RESULT_TYPE_MISMATCH, "{0} must return {1} but returns {2}", TO_STRING, RENDER_TYPE, RENDER_TYPE); + MAP.put(RESULT_TYPE_MISMATCH, "{0} must return {1} but returns {2}", STRING, RENDER_TYPE, RENDER_TYPE); MAP.put(UNSAFE_INFIX_CALL, "Infix call corresponds to a dot-qualified call ''{0}.{1}({2})'' which is not allowed on a nullable receiver ''{0}''. " + "Use '?.'-qualified call instead", - TO_STRING, TO_STRING, TO_STRING); + STRING, STRING, STRING); MAP.put(OVERLOAD_RESOLUTION_AMBIGUITY, "Overload resolution ambiguity: {0}", AMBIGUOUS_CALLS); MAP.put(NONE_APPLICABLE, "None of the following functions can be called with the arguments supplied: {0}", AMBIGUOUS_CALLS); @@ -444,7 +441,7 @@ public class DefaultErrorMessages { MAP.put(WRONG_NUMBER_OF_TYPE_ARGUMENTS, "{0,choice,0#No type arguments|1#Type argument|1<{0,number,integer} type arguments} expected", null); MAP.put(NO_TYPE_ARGUMENTS_ON_RHS, "{0,choice,0#No type arguments|1#Type argument|1<{0,number,integer} type arguments} expected. " + - "Use ''{1}'' if you don''t want to pass type arguments", null, TO_STRING); + "Use ''{1}'' if you don''t want to pass type arguments", null, STRING); MAP.put(DANGLING_FUNCTION_LITERAL_ARGUMENT_SUSPECTED, "This expression is treated as an argument to the function call on the previous line. " + @@ -455,7 +452,7 @@ public class DefaultErrorMessages { MAP.put(SUPERTYPES_FOR_ANNOTATION_CLASS, "Annotation class cannot have supertypes"); MAP.put(MISSING_VAL_ON_ANNOTATION_PARAMETER, "'val' keyword is missing on annotation parameter"); MAP.put(ANNOTATION_CLASS_CONSTRUCTOR_CALL, "Annotation class cannot be instantiated"); - MAP.put(NOT_AN_ANNOTATION_CLASS, "''{0}'' is not an annotation class", TO_STRING); + MAP.put(NOT_AN_ANNOTATION_CLASS, "''{0}'' is not an annotation class", NAME); MAP.put(ANNOTATION_CLASS_WITH_BODY, "Body is not allowed for annotation class"); MAP.put(INVALID_TYPE_OF_ANNOTATION_MEMBER, "Invalid type of annotation member"); MAP.put(NULLABLE_TYPE_OF_ANNOTATION_MEMBER, "An annotation parameter cannot be nullable"); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/rendering/Renderers.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/rendering/Renderers.java index 73effcb8f40..d8dcaf251fb 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/rendering/Renderers.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/rendering/Renderers.java @@ -65,14 +65,19 @@ public class Renderers { } }; - public static final Renderer NAME = new Renderer() { + public static final Renderer STRING = new Renderer() { @NotNull @Override - public String render(@NotNull Object element) { - if (element instanceof Named) { - return ((Named) element).getName().asString(); - } - return element.toString(); + public String render(@NotNull String element) { + return element; + } + }; + + public static final Renderer NAME = new Renderer() { + @NotNull + @Override + public String render(@NotNull Named element) { + return element.getName().asString(); } }; diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/AnnotationResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/AnnotationResolver.java index a6e31b0b0ce..67eca3be4a7 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/AnnotationResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/AnnotationResolver.java @@ -51,6 +51,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import static org.jetbrains.jet.lang.diagnostics.Errors.NOT_AN_ANNOTATION_CLASS; import static org.jetbrains.jet.lang.resolve.BindingContext.ANNOTATION_DESCRIPTOR_TO_PSI_ELEMENT; import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE; @@ -177,11 +178,11 @@ public class AnnotationResolver { ConstructorDescriptor constructor = (ConstructorDescriptor)descriptor; ClassDescriptor classDescriptor = constructor.getContainingDeclaration(); if (classDescriptor.getKind() != ClassKind.ANNOTATION_CLASS) { - trace.report(Errors.NOT_AN_ANNOTATION_CLASS.on(entryElement, classDescriptor.getName().asString())); + trace.report(NOT_AN_ANNOTATION_CLASS.on(entryElement, classDescriptor)); } } else { - trace.report(Errors.NOT_AN_ANNOTATION_CLASS.on(entryElement, descriptor.getName().asString())); + trace.report(NOT_AN_ANNOTATION_CLASS.on(entryElement, descriptor)); } } } diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/IdeErrorMessages.java b/idea/src/org/jetbrains/jet/plugin/highlighter/IdeErrorMessages.java index 84cbc7b1099..9a593b41233 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/IdeErrorMessages.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/IdeErrorMessages.java @@ -25,7 +25,7 @@ import org.jetbrains.jet.renderer.DescriptorRenderer; import static org.jetbrains.jet.lang.diagnostics.Errors.*; import static org.jetbrains.jet.lang.diagnostics.rendering.Renderers.RENDER_CLASS_OR_OBJECT; -import static org.jetbrains.jet.lang.diagnostics.rendering.Renderers.TO_STRING; +import static org.jetbrains.jet.lang.diagnostics.rendering.Renderers.STRING; import static org.jetbrains.jet.lang.diagnostics.rendering.TabledDescriptorRenderer.TextElementType; import static org.jetbrains.jet.plugin.highlighter.HtmlTabledDescriptorRenderer.tableForTypes; import static org.jetbrains.jet.plugin.highlighter.IdeRenderers.*; @@ -86,11 +86,11 @@ public class IdeErrorMessages { MAP.put(MANY_IMPL_MEMBER_NOT_IMPLEMENTED, "{0} must override {1}
because it inherits many implementations of it", RENDER_CLASS_OR_OBJECT, DescriptorRenderer.HTML); MAP.put(CONFLICTING_OVERLOADS, "''{0}''
is already defined in {1}", - DescriptorRenderer.HTML_COMPACT_WITH_MODIFIERS, TO_STRING); + DescriptorRenderer.HTML_COMPACT_WITH_MODIFIERS, STRING); MAP.put(RESULT_TYPE_MISMATCH, "Function return type mismatch." + "" + - "
Expected:{1}
Found:{2}
", TO_STRING, HTML_RENDER_TYPE, HTML_RENDER_TYPE); + "Found:{2}", STRING, HTML_RENDER_TYPE, HTML_RENDER_TYPE); MAP.put(OVERLOAD_RESOLUTION_AMBIGUITY, "Overload resolution ambiguity. All these functions match.
    {0}
", HTML_AMBIGUOUS_CALLS); MAP.put(NONE_APPLICABLE, "None of the following functions can be called with the arguments supplied.
    {0}
", @@ -98,9 +98,9 @@ public class IdeErrorMessages { MAP.put(CANNOT_COMPLETE_RESOLVE, "Cannot choose among the following candidates without completing type inference:
    {0}
", HTML_AMBIGUOUS_CALLS); MAP.put(UNRESOLVED_REFERENCE_WRONG_RECEIVER, "Unresolved reference.
None of the following candidates is applicable because of receiver type mismatch:
    {0}
", HTML_AMBIGUOUS_CALLS); - MAP.put(DELEGATE_SPECIAL_FUNCTION_AMBIGUITY, "Overload resolution ambiguity on method ''{0}''. All these functions match.
    {1}
", TO_STRING, HTML_AMBIGUOUS_CALLS); + MAP.put(DELEGATE_SPECIAL_FUNCTION_AMBIGUITY, "Overload resolution ambiguity on method ''{0}''. All these functions match.
    {1}
", STRING, HTML_AMBIGUOUS_CALLS); MAP.put(DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE, "Property delegate must have a ''{0}'' method. None of the following functions is suitable.
    {1}
", - TO_STRING, HTML_NONE_APPLICABLE_CALLS); + STRING, HTML_NONE_APPLICABLE_CALLS); MAP.setImmutable(); } diff --git a/idea/testData/diagnosticMessage/assignedButNeverAccessedVariable.kt b/idea/testData/diagnosticMessage/assignedButNeverAccessedVariable.kt new file mode 100644 index 00000000000..14962d44dc2 --- /dev/null +++ b/idea/testData/diagnosticMessage/assignedButNeverAccessedVariable.kt @@ -0,0 +1,7 @@ +// !DIAGNOSTICS_NUMBER: 1 +// !DIAGNOSTICS: ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE + +fun foo() { + var x = "a" + x = "b" +} diff --git a/idea/testData/diagnosticMessage/assignedButNeverAccessedVariable1.txt b/idea/testData/diagnosticMessage/assignedButNeverAccessedVariable1.txt new file mode 100644 index 00000000000..a8174ab7e50 --- /dev/null +++ b/idea/testData/diagnosticMessage/assignedButNeverAccessedVariable1.txt @@ -0,0 +1,2 @@ + +Variable 'x' is assigned but never accessed diff --git a/idea/testData/diagnosticMessage/unusedParameter.kt b/idea/testData/diagnosticMessage/unusedParameter.kt new file mode 100644 index 00000000000..2a9a7f02b08 --- /dev/null +++ b/idea/testData/diagnosticMessage/unusedParameter.kt @@ -0,0 +1,4 @@ +// !DIAGNOSTICS_NUMBER: 1 +// !DIAGNOSTICS: UNUSED_PARAMETER + +fun foo(unused: String) {} diff --git a/idea/testData/diagnosticMessage/unusedParameter1.txt b/idea/testData/diagnosticMessage/unusedParameter1.txt new file mode 100644 index 00000000000..0de9d991fd8 --- /dev/null +++ b/idea/testData/diagnosticMessage/unusedParameter1.txt @@ -0,0 +1,2 @@ + +Parameter 'unused' is never used diff --git a/idea/testData/diagnosticMessage/unusedVariable.kt b/idea/testData/diagnosticMessage/unusedVariable.kt new file mode 100644 index 00000000000..eb8a09f606c --- /dev/null +++ b/idea/testData/diagnosticMessage/unusedVariable.kt @@ -0,0 +1,6 @@ +// !DIAGNOSTICS_NUMBER: 1 +// !DIAGNOSTICS: UNUSED_VARIABLE + +fun foo() { + val x = 42 +} diff --git a/idea/testData/diagnosticMessage/unusedVariable1.txt b/idea/testData/diagnosticMessage/unusedVariable1.txt new file mode 100644 index 00000000000..a2c4edf0f3b --- /dev/null +++ b/idea/testData/diagnosticMessage/unusedVariable1.txt @@ -0,0 +1,2 @@ + +Variable 'x' is never used diff --git a/idea/tests/org/jetbrains/jet/plugin/highlighter/DiagnosticMessageTestGenerated.java b/idea/tests/org/jetbrains/jet/plugin/highlighter/DiagnosticMessageTestGenerated.java index 05f24ea5796..8a2bd535e56 100644 --- a/idea/tests/org/jetbrains/jet/plugin/highlighter/DiagnosticMessageTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/plugin/highlighter/DiagnosticMessageTestGenerated.java @@ -36,6 +36,11 @@ public class DiagnosticMessageTestGenerated extends AbstractDiagnosticMessageTes JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/diagnosticMessage"), Pattern.compile("^(.+)\\.kt$"), true); } + @TestMetadata("assignedButNeverAccessedVariable.kt") + public void testAssignedButNeverAccessedVariable() throws Exception { + doTest("idea/testData/diagnosticMessage/assignedButNeverAccessedVariable.kt"); + } + @TestMetadata("conflictingOverloadsClass.kt") public void testConflictingOverloadsClass() throws Exception { doTest("idea/testData/diagnosticMessage/conflictingOverloadsClass.kt"); @@ -101,11 +106,21 @@ public class DiagnosticMessageTestGenerated extends AbstractDiagnosticMessageTes doTest("idea/testData/diagnosticMessage/typeMismatchWithNothing.kt"); } + @TestMetadata("unusedParameter.kt") + public void testUnusedParameter() throws Exception { + doTest("idea/testData/diagnosticMessage/unusedParameter.kt"); + } + @TestMetadata("unusedValue.kt") public void testUnusedValue() throws Exception { doTest("idea/testData/diagnosticMessage/unusedValue.kt"); } + @TestMetadata("unusedVariable.kt") + public void testUnusedVariable() throws Exception { + doTest("idea/testData/diagnosticMessage/unusedVariable.kt"); + } + @TestMetadata("upperBoundViolated.kt") public void testUpperBoundViolated() throws Exception { doTest("idea/testData/diagnosticMessage/upperBoundViolated.kt");