Don't fail when "deprecated" doesn't have a message
EA-57345
This commit is contained in:
@@ -229,18 +229,28 @@ public class DeprecatedAnnotationVisitor extends AfterAnalysisHighlightingVisito
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static String composeTooltipString(@NotNull DeclarationDescriptor declarationDescriptor, @NotNull AnnotationDescriptor descriptor) {
|
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) {
|
private static String getMessageFromAnnotationDescriptor(@NotNull AnnotationDescriptor descriptor) {
|
||||||
ClassDescriptor classDescriptor = TypeUtils.getClassDescriptor(descriptor.getType());
|
ClassDescriptor classDescriptor = TypeUtils.getClassDescriptor(descriptor.getType());
|
||||||
assert classDescriptor != null : "ClassDescriptor for kotlin.deprecated mustn't be null";
|
if (classDescriptor != null) {
|
||||||
ValueParameterDescriptor parameter =
|
ValueParameterDescriptor parameter =
|
||||||
DescriptorResolverUtils.getAnnotationParameterByName(DEFAULT_ANNOTATION_MEMBER_NAME, classDescriptor);
|
DescriptorResolverUtils.getAnnotationParameterByName(DEFAULT_ANNOTATION_MEMBER_NAME, classDescriptor);
|
||||||
assert parameter != null : "kotlin.deprecated must have one parameter called value";
|
if (parameter != null) {
|
||||||
CompileTimeConstant<?> valueArgument = descriptor.getValueArgument(parameter);
|
CompileTimeConstant<?> valueArgument = descriptor.getValueArgument(parameter);
|
||||||
assert valueArgument != null : "kotlin.deprecated must have value argument";
|
if (valueArgument != null) {
|
||||||
return (String) valueArgument.getValue();
|
Object value = valueArgument.getValue();
|
||||||
|
if (value instanceof String) {
|
||||||
|
return String.valueOf(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getDescriptorString(@NotNull DeclarationDescriptor descriptor) {
|
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");
|
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")
|
@TestMetadata("Invoke.kt")
|
||||||
public void testInvoke() throws Exception {
|
public void testInvoke() throws Exception {
|
||||||
doTest("idea/testData/highlighter/deprecated/Invoke.kt");
|
doTest("idea/testData/highlighter/deprecated/Invoke.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user