Don't fail when "deprecated" doesn't have a message

EA-57345
This commit is contained in:
Alexander Udalov
2014-06-26 18:40:40 +04:00
parent c18fd179a9
commit c56f397f71
3 changed files with 34 additions and 8 deletions
@@ -229,18 +229,28 @@ public class DeprecatedAnnotationVisitor extends AfterAnalysisHighlightingVisito
}
private static String composeTooltipString(@NotNull DeclarationDescriptor declarationDescriptor, @NotNull AnnotationDescriptor descriptor) {
return "'" + getDescriptorString(declarationDescriptor) + "' is deprecated. " + getMessageFromAnnotationDescriptor(descriptor);
String fact = "'" + getDescriptorString(declarationDescriptor) + "' is deprecated.";
String message = getMessageFromAnnotationDescriptor(descriptor);
return message == null ? fact : fact + " " + message;
}
@Nullable
private static String getMessageFromAnnotationDescriptor(@NotNull AnnotationDescriptor descriptor) {
ClassDescriptor classDescriptor = TypeUtils.getClassDescriptor(descriptor.getType());
assert classDescriptor != null : "ClassDescriptor for kotlin.deprecated mustn't be null";
ValueParameterDescriptor parameter =
DescriptorResolverUtils.getAnnotationParameterByName(DEFAULT_ANNOTATION_MEMBER_NAME, classDescriptor);
assert parameter != null : "kotlin.deprecated must have one parameter called value";
CompileTimeConstant<?> valueArgument = descriptor.getValueArgument(parameter);
assert valueArgument != null : "kotlin.deprecated must have value argument";
return (String) valueArgument.getValue();
if (classDescriptor != null) {
ValueParameterDescriptor parameter =
DescriptorResolverUtils.getAnnotationParameterByName(DEFAULT_ANNOTATION_MEMBER_NAME, classDescriptor);
if (parameter != null) {
CompileTimeConstant<?> valueArgument = descriptor.getValueArgument(parameter);
if (valueArgument != null) {
Object value = valueArgument.getValue();
if (value instanceof String) {
return String.valueOf(value);
}
}
}
}
return null;
}
private static String getDescriptorString(@NotNull DeclarationDescriptor descriptor) {
@@ -0,0 +1,11 @@
deprecated(<error>)</error>
fun foo() {}
deprecated(<error>false</error>)
fun boo() {}
fun far() = <warning descr="'fun foo()' is deprecated.">foo</warning>()
fun bar() = <warning descr="'fun boo()' is deprecated.">boo</warning>()
// NO_CHECK_INFOS
// NO_CHECK_WEAK_WARNINGS
@@ -108,6 +108,11 @@ public class HighlightingTestGenerated extends AbstractHighlightingTest {
doTest("idea/testData/highlighter/deprecated/Inc.kt");
}
@TestMetadata("Invalid.kt")
public void testInvalid() throws Exception {
doTest("idea/testData/highlighter/deprecated/Invalid.kt");
}
@TestMetadata("Invoke.kt")
public void testInvoke() throws Exception {
doTest("idea/testData/highlighter/deprecated/Invoke.kt");