Change tooltip message for deprecated items
This commit is contained in:
@@ -29,6 +29,7 @@ import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.calls.ResolvedCall;
|
||||
import org.jetbrains.jet.lang.resolve.calls.VariableAsFunctionResolvedCall;
|
||||
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
||||
@@ -37,6 +38,7 @@ import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.types.TypeUtils;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
import org.jetbrains.jet.resolve.DescriptorRenderer;
|
||||
|
||||
public class DeprecatedAnnotationVisitor extends AfterAnalysisHighlightingVisitor {
|
||||
|
||||
@@ -204,11 +206,11 @@ public class DeprecatedAnnotationVisitor extends AfterAnalysisHighlightingVisito
|
||||
AnnotationDescriptor deprecated = getDeprecated(descriptor);
|
||||
if (deprecated != null) {
|
||||
if (isWarning) {
|
||||
holder.createInfoAnnotation(element, getMessage(deprecated))
|
||||
holder.createInfoAnnotation(element, composeTooltipString(descriptor, deprecated))
|
||||
.setTextAttributes(CodeInsightColors.WARNINGS_ATTRIBUTES);
|
||||
}
|
||||
else {
|
||||
holder.createInfoAnnotation(element, getMessage(deprecated))
|
||||
holder.createInfoAnnotation(element, composeTooltipString(descriptor, deprecated))
|
||||
.setTextAttributes(CodeInsightColors.DEPRECATED_ATTRIBUTES);
|
||||
}
|
||||
return true;
|
||||
@@ -228,7 +230,11 @@ public class DeprecatedAnnotationVisitor extends AfterAnalysisHighlightingVisito
|
||||
return null;
|
||||
}
|
||||
|
||||
private static String getMessage(AnnotationDescriptor descriptor) {
|
||||
private static String composeTooltipString(@NotNull DeclarationDescriptor declarationDescriptor, @NotNull AnnotationDescriptor descriptor) {
|
||||
return "'" + getDescriptorString(declarationDescriptor) + "' is deprecated. " + getMessageFromAnnotationDescriptor(descriptor);
|
||||
}
|
||||
|
||||
private static String getMessageFromAnnotationDescriptor(@NotNull AnnotationDescriptor descriptor) {
|
||||
ClassDescriptor classDescriptor = TypeUtils.getClassDescriptor(descriptor.getType());
|
||||
assert classDescriptor != null : "ClassDescriptor for jet.deprecated mustn't be null";
|
||||
ValueParameterDescriptor parameterDescriptor =
|
||||
@@ -238,4 +244,31 @@ public class DeprecatedAnnotationVisitor extends AfterAnalysisHighlightingVisito
|
||||
assert valueArgument != null : "jet.deprecated must have value argument";
|
||||
return (String) valueArgument.getValue();
|
||||
}
|
||||
|
||||
private static String getDescriptorString(@NotNull DeclarationDescriptor descriptor) {
|
||||
if (descriptor instanceof ClassDescriptor) {
|
||||
return DescriptorUtils.getFQName(descriptor).getFqName();
|
||||
}
|
||||
else if (descriptor instanceof ConstructorDescriptor) {
|
||||
DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration();
|
||||
assert containingDeclaration != null;
|
||||
return "constructor for " + containingDeclaration.getName();
|
||||
}
|
||||
else if (descriptor instanceof PropertyGetterDescriptor) {
|
||||
return "getter for " + ((PropertyGetterDescriptor) descriptor).getCorrespondingProperty().getName();
|
||||
}
|
||||
else if (descriptor instanceof PropertySetterDescriptor) {
|
||||
return "setter for " + ((PropertySetterDescriptor) descriptor).getCorrespondingProperty().getName();
|
||||
}
|
||||
else if (descriptor instanceof PropertyDescriptor) {
|
||||
if (((PropertyDescriptor) descriptor).isVar()) {
|
||||
return "var " + descriptor.getName();
|
||||
}
|
||||
return "val " + descriptor.getName();
|
||||
}
|
||||
else if (descriptor instanceof FunctionDescriptor) {
|
||||
return "fun " + descriptor.getName() + DescriptorRenderer.TEXT.renderFunctionParameters((FunctionDescriptor) descriptor);
|
||||
}
|
||||
return DescriptorRenderer.TEXT.render(descriptor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,14 +2,14 @@ package test
|
||||
|
||||
<info>import</info> java.util.ArrayList
|
||||
|
||||
deprecated("'test.MyClass' is deprecated") <info>open</info> class MyClass {}
|
||||
deprecated("Use A instead") <info>open</info> class MyClass {}
|
||||
|
||||
fun test() {
|
||||
val a : <info descr="'test.MyClass' is deprecated">MyClass</info>? = null
|
||||
val b = <info descr="'test.MyClass' is deprecated">MyClass</info>()
|
||||
val c = ArrayList<<info descr="'test.MyClass' is deprecated">MyClass</info>>()
|
||||
val a : <info descr="'test.MyClass' is deprecated. Use A instead">MyClass</info>? = null
|
||||
val b = <info descr="'test.MyClass' is deprecated. Use A instead">MyClass</info>()
|
||||
val c = ArrayList<<info descr="'test.MyClass' is deprecated. Use A instead">MyClass</info>>()
|
||||
}
|
||||
|
||||
class Test(): <info descr="'test.MyClass' is deprecated">MyClass</info>() {}
|
||||
class Test(): <info descr="'test.MyClass' is deprecated. Use A instead">MyClass</info>() {}
|
||||
|
||||
class Test2(param: <info descr="'test.MyClass' is deprecated">MyClass</info>) {}
|
||||
class Test2(param: <info descr="'test.MyClass' is deprecated. Use A instead">MyClass</info>) {}
|
||||
@@ -1,19 +1,19 @@
|
||||
fun test() {
|
||||
<info descr="'MyClass.<class-object-for-MyClass>' is deprecated">MyClass</info>.test
|
||||
<info descr="'MyClass.<class-object-for-MyClass>' is deprecated. Use A instead">MyClass</info>.test
|
||||
MyClass()
|
||||
val a: MyClass? = null
|
||||
val b: MyTrait? = null
|
||||
<info descr="'MyTrait.<class-object-for-MyTrait>' is deprecated">MyTrait</info>.test
|
||||
<info descr="'MyTrait.<class-object-for-MyTrait>' is deprecated. Use A instead">MyTrait</info>.test
|
||||
}
|
||||
|
||||
class MyClass(): MyTrait {
|
||||
deprecated("'MyClass.<class-object-for-MyClass>' is deprecated") class object {
|
||||
deprecated("Use A instead") class object {
|
||||
val <info>test</info>: String = ""
|
||||
}
|
||||
}
|
||||
|
||||
trait MyTrait {
|
||||
deprecated("'MyTrait.<class-object-for-MyTrait>' is deprecated") class object {
|
||||
deprecated("Use A instead") class object {
|
||||
val <info>test</info>: String = ""
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,18 @@
|
||||
fun test() {
|
||||
<info descr="'fun test1()' is deprecated">test1</info>()
|
||||
MyClass().<info descr="'fun test2()' is deprecated">test2</info>()
|
||||
MyClass.<info descr="'fun test3()' is deprecated">test3</info>()
|
||||
<info descr="'fun test1()' is deprecated. Use A instead">test1</info>()
|
||||
MyClass().<info descr="'fun test2()' is deprecated. Use A instead">test2</info>()
|
||||
MyClass.<info descr="'fun test3()' is deprecated. Use A instead">test3</info>()
|
||||
|
||||
<info descr="'fun test4(x : jet.Int, y : jet.Int)' is deprecated">test4</info>(1, 2)
|
||||
<info descr="'fun test4(x : jet.Int, y : jet.Int)' is deprecated. Use A instead">test4</info>(1, 2)
|
||||
}
|
||||
|
||||
deprecated("'fun test1()' is deprecated") fun test1() { }
|
||||
deprecated("'fun test4(x : jet.Int, y : jet.Int)' is deprecated") fun test4(x: Int, y: Int) { }
|
||||
deprecated("Use A instead") fun test1() { }
|
||||
deprecated("Use A instead") fun test4(x: Int, y: Int) { }
|
||||
|
||||
class MyClass() {
|
||||
deprecated("'fun test2()' is deprecated") fun test2() {}
|
||||
deprecated("Use A instead") fun test2() {}
|
||||
|
||||
class object {
|
||||
deprecated("'fun test3()' is deprecated") fun test3() {}
|
||||
deprecated("Use A instead") fun test3() {}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
class MyClass {}
|
||||
|
||||
deprecated("'fun get(i : MyClass)' is deprecated") fun MyClass.get(i: MyClass): MyClass { return MyClass() }
|
||||
deprecated("Use A instead") fun MyClass.get(i: MyClass): MyClass { return MyClass() }
|
||||
|
||||
fun test() {
|
||||
val x1 = MyClass()
|
||||
val x2 = MyClass()
|
||||
|
||||
<info descr="'fun get(i : MyClass)' is deprecated">x1[x2]</info>
|
||||
<info descr="'fun get(i : MyClass)' is deprecated. Use A instead">x1[x2]</info>
|
||||
}
|
||||
@@ -1,19 +1,19 @@
|
||||
fun test() {
|
||||
val c = MyClass()
|
||||
c.<info descr="'getter for test1' is deprecated">test1</info>
|
||||
c.<info descr="'getter for test2' is deprecated">test2</info>
|
||||
c.<info descr="'getter for test1' is deprecated. Use A instead">test1</info>
|
||||
c.<info descr="'getter for test2' is deprecated. Use A instead">test2</info>
|
||||
c.test2 = ""
|
||||
|
||||
c.<info descr="'val test3' is deprecated">test3</info>
|
||||
c.<info descr="'val test3' is deprecated. Use A instead">test3</info>
|
||||
}
|
||||
|
||||
class MyClass() {
|
||||
<info>public</info> val <info>test1</info>: String = ""
|
||||
[deprecated("'getter for test1' is deprecated")] <info>get</info>
|
||||
[deprecated("Use A instead")] <info>get</info>
|
||||
|
||||
<info>public</info> var <info>test2</info>: String = ""
|
||||
[deprecated("'getter for test2' is deprecated")] <info>get</info>
|
||||
[deprecated("Use A instead")] <info>get</info>
|
||||
|
||||
deprecated("'val test3' is deprecated") <info>public</info> val <info>test3</info>: String = ""
|
||||
[deprecated("'getter for test3' is deprecated")] <info>get</info>
|
||||
deprecated("Use A instead") <info>public</info> val <info>test3</info>: String = ""
|
||||
[deprecated("Use A instead")] <info>get</info>
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
class MyClass {}
|
||||
|
||||
deprecated("'fun inc()' is deprecated") fun MyClass.inc(): MyClass { return MyClass() }
|
||||
deprecated("Use A instead") fun MyClass.inc(): MyClass { return MyClass() }
|
||||
|
||||
fun test() {
|
||||
var x3 = MyClass()
|
||||
x3<info descr="'fun inc()' is deprecated">++</info>
|
||||
x3<info descr="'fun inc()' is deprecated. Use A instead">++</info>
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
class MyRunnable() {}
|
||||
|
||||
deprecated("'fun invoke()' is deprecated") fun MyRunnable.invoke() {
|
||||
deprecated("Use A instead") fun MyRunnable.invoke() {
|
||||
}
|
||||
|
||||
fun test() {
|
||||
val m = MyRunnable()
|
||||
<info descr="'fun invoke()' is deprecated">m()</info>
|
||||
<info descr="'fun invoke()' is deprecated. Use A instead">m()</info>
|
||||
}
|
||||
@@ -1,36 +1,36 @@
|
||||
class MyClass {}
|
||||
|
||||
deprecated("'fun minus(i : MyClass)' is deprecated") fun MyClass.minus(i: MyClass) { }
|
||||
deprecated("'fun div(i : MyClass)' is deprecated") fun MyClass.div(i: MyClass) { }
|
||||
deprecated("'fun times(i : MyClass)' is deprecated") fun MyClass.times(i: MyClass) { }
|
||||
deprecated("Use A instead") fun MyClass.minus(i: MyClass) { }
|
||||
deprecated("Use A instead") fun MyClass.div(i: MyClass) { }
|
||||
deprecated("Use A instead") fun MyClass.times(i: MyClass) { }
|
||||
|
||||
deprecated("'fun not()' is deprecated") fun MyClass.not() { }
|
||||
deprecated("'fun plus()' is deprecated") fun MyClass.plus() { }
|
||||
deprecated("Use A instead") fun MyClass.not() { }
|
||||
deprecated("Use A instead") fun MyClass.plus() { }
|
||||
|
||||
deprecated("'fun contains(i : MyClass)' is deprecated") fun MyClass.contains(i: MyClass): Boolean { return false }
|
||||
deprecated("Use A instead") fun MyClass.contains(i: MyClass): Boolean { return false }
|
||||
|
||||
deprecated("'fun plusAssign(i : MyClass)' is deprecated") fun MyClass.plusAssign(i: MyClass) { }
|
||||
deprecated("Use A instead") fun MyClass.plusAssign(i: MyClass) { }
|
||||
|
||||
deprecated("'fun equals(i : jet.Any?)' is deprecated") fun MyClass.equals(i: Any?): Boolean { return false }
|
||||
deprecated("'fun compareTo(i : MyClass)' is deprecated") fun MyClass.compareTo(i: MyClass): Int { return 0 }
|
||||
deprecated("Use A instead") fun MyClass.equals(i: Any?): Boolean { return false }
|
||||
deprecated("Use A instead") fun MyClass.compareTo(i: MyClass): Int { return 0 }
|
||||
|
||||
fun test() {
|
||||
val x1 = MyClass()
|
||||
val x2 = MyClass()
|
||||
|
||||
x1 <info descr="'fun minus(i : MyClass)' is deprecated">-</info> x2
|
||||
x1 <info descr="'fun div(i : MyClass)' is deprecated">/</info> x2
|
||||
x1 <info descr="'fun times(i : MyClass)' is deprecated">*</info> x2
|
||||
x1 <info descr="'fun minus(i : MyClass)' is deprecated. Use A instead">-</info> x2
|
||||
x1 <info descr="'fun div(i : MyClass)' is deprecated. Use A instead">/</info> x2
|
||||
x1 <info descr="'fun times(i : MyClass)' is deprecated. Use A instead">*</info> x2
|
||||
|
||||
<info descr="'fun not()' is deprecated">!</info>x1
|
||||
<info descr="'fun plus()' is deprecated">+</info>x1
|
||||
<info descr="'fun not()' is deprecated. Use A instead">!</info>x1
|
||||
<info descr="'fun plus()' is deprecated. Use A instead">+</info>x1
|
||||
|
||||
x1 <info descr="'fun contains(i : MyClass)' is deprecated">in</info> x2
|
||||
x1 <info descr="'fun contains(i : MyClass)' is deprecated">!in</info> x2
|
||||
x1 <info descr="'fun contains(i : MyClass)' is deprecated. Use A instead">in</info> x2
|
||||
x1 <info descr="'fun contains(i : MyClass)' is deprecated. Use A instead">!in</info> x2
|
||||
|
||||
x1 <info descr="'fun plusAssign(i : MyClass)' is deprecated">+=</info> x2
|
||||
x1 <info descr="'fun plusAssign(i : MyClass)' is deprecated. Use A instead">+=</info> x2
|
||||
|
||||
x1 <info descr="'fun equals(i : jet.Any?)' is deprecated">==</info> x2
|
||||
x1 <info descr="'fun equals(i : jet.Any?)' is deprecated">!=</info> x2
|
||||
x1 <info descr="'fun compareTo(i : MyClass)' is deprecated">></info> x2
|
||||
x1 <info descr="'fun equals(i : jet.Any?)' is deprecated. Use A instead">==</info> x2
|
||||
x1 <info descr="'fun equals(i : jet.Any?)' is deprecated. Use A instead">!=</info> x2
|
||||
x1 <info descr="'fun compareTo(i : MyClass)' is deprecated. Use A instead">></info> x2
|
||||
}
|
||||
@@ -1,22 +1,22 @@
|
||||
fun test() {
|
||||
<info descr="'val test1' is deprecated">test1</info>
|
||||
MyClass().<info descr="'val test2' is deprecated">test2</info>
|
||||
MyClass.<info descr="'val test3' is deprecated">test3</info>
|
||||
<info descr="'val test1' is deprecated. Use A instead">test1</info>
|
||||
MyClass().<info descr="'val test2' is deprecated. Use A instead">test2</info>
|
||||
MyClass.<info descr="'val test3' is deprecated. Use A instead">test3</info>
|
||||
|
||||
<info descr="'var test4' is deprecated">test4</info>
|
||||
MyClass().<info descr="'var test5' is deprecated">test5</info>
|
||||
MyClass.<info descr="'var test6' is deprecated">test6</info>
|
||||
<info descr="'var test4' is deprecated. Use A instead">test4</info>
|
||||
MyClass().<info descr="'var test5' is deprecated. Use A instead">test5</info>
|
||||
MyClass.<info descr="'var test6' is deprecated. Use A instead">test6</info>
|
||||
}
|
||||
|
||||
deprecated("'val test1' is deprecated") val <info>test1</info>: String = ""
|
||||
deprecated("'var test4' is deprecated") var <info>test4</info>: String = ""
|
||||
deprecated("Use A instead") val <info>test1</info>: String = ""
|
||||
deprecated("Use A instead") var <info>test4</info>: String = ""
|
||||
|
||||
class MyClass() {
|
||||
deprecated("'val test2' is deprecated") val <info>test2</info>: String = ""
|
||||
deprecated("'var test5' is deprecated") var <info>test5</info>: String = ""
|
||||
deprecated("Use A instead") val <info>test2</info>: String = ""
|
||||
deprecated("Use A instead") var <info>test5</info>: String = ""
|
||||
|
||||
class object {
|
||||
deprecated("'val test3' is deprecated") val <info>test3</info>: String = ""
|
||||
deprecated("'var test6' is deprecated") var <info>test6</info>: String = ""
|
||||
deprecated("Use A instead") val <info>test3</info>: String = ""
|
||||
deprecated("Use A instead") var <info>test6</info>: String = ""
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
class MyClass { }
|
||||
|
||||
deprecated("'fun rangeTo(i : MyClass)' is deprecated") fun MyClass.rangeTo(i: MyClass): IntIterator {
|
||||
deprecated("Use A instead") fun MyClass.rangeTo(i: MyClass): IntIterator {
|
||||
throw Exception()
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ fun test() {
|
||||
val x1 = MyClass()
|
||||
val x2 = MyClass()
|
||||
|
||||
for (i in x1<info descr="'fun rangeTo(i : MyClass)' is deprecated">..</info>x2) {
|
||||
for (i in x1<info descr="'fun rangeTo(i : MyClass)' is deprecated. Use A instead">..</info>x2) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
fun test() {
|
||||
MyClass().test1
|
||||
MyClass().<info descr="'setter for test1' is deprecated">test1</info> = 0
|
||||
MyClass().<info descr="'setter for test1' is deprecated. Use A instead">test1</info> = 0
|
||||
|
||||
MyClass().<info descr="'setter for test1' is deprecated">test1</info>++
|
||||
MyClass().<info descr="'setter for test1' is deprecated">test1</info>--
|
||||
MyClass().<info descr="'setter for test1' is deprecated. Use A instead">test1</info>++
|
||||
MyClass().<info descr="'setter for test1' is deprecated. Use A instead">test1</info>--
|
||||
|
||||
++MyClass().<info descr="'setter for test1' is deprecated">test1</info>
|
||||
--MyClass().<info descr="'setter for test1' is deprecated">test1</info>
|
||||
++MyClass().<info descr="'setter for test1' is deprecated. Use A instead">test1</info>
|
||||
--MyClass().<info descr="'setter for test1' is deprecated. Use A instead">test1</info>
|
||||
|
||||
MyClass().<info descr="'setter for test1' is deprecated">test1</info> += 1
|
||||
MyClass().<info descr="'setter for test1' is deprecated">test1</info> -= 1
|
||||
MyClass().<info descr="'setter for test1' is deprecated">test1</info> /= 1
|
||||
MyClass().<info descr="'setter for test1' is deprecated">test1</info> *= 1
|
||||
MyClass().<info descr="'setter for test1' is deprecated. Use A instead">test1</info> += 1
|
||||
MyClass().<info descr="'setter for test1' is deprecated. Use A instead">test1</info> -= 1
|
||||
MyClass().<info descr="'setter for test1' is deprecated. Use A instead">test1</info> /= 1
|
||||
MyClass().<info descr="'setter for test1' is deprecated. Use A instead">test1</info> *= 1
|
||||
|
||||
test2
|
||||
<info descr="'setter for test2' is deprecated">test2</info> = 10
|
||||
<info descr="'setter for test2' is deprecated. Use A instead">test2</info> = 10
|
||||
}
|
||||
|
||||
class MyClass() {
|
||||
<info>public</info> var <info>test1</info>: Int = 0
|
||||
[deprecated("'setter for test1' is deprecated")] <info>set</info>
|
||||
[deprecated("Use A instead")] <info>set</info>
|
||||
}
|
||||
|
||||
<info>public</info> var <info>test2</info>: Int = 0
|
||||
[deprecated("'setter for test2' is deprecated")] <info>set</info>
|
||||
[deprecated("Use A instead")] <info>set</info>
|
||||
@@ -1,10 +1,10 @@
|
||||
deprecated("'MyTrait' is deprecated") trait MyTrait { }
|
||||
deprecated("Use A instead") trait MyTrait { }
|
||||
|
||||
fun test() {
|
||||
val a: <info descr="'MyTrait' is deprecated">MyTrait</info>? = null
|
||||
val b: List<<info descr="'MyTrait' is deprecated">MyTrait</info>>? = null
|
||||
val a: <info descr="'MyTrait' is deprecated. Use A instead">MyTrait</info>? = null
|
||||
val b: List<<info descr="'MyTrait' is deprecated. Use A instead">MyTrait</info>>? = null
|
||||
}
|
||||
|
||||
class Test(): <info descr="'MyTrait' is deprecated">MyTrait</info> { }
|
||||
class Test(): <info descr="'MyTrait' is deprecated. Use A instead">MyTrait</info> { }
|
||||
|
||||
class Test2(param: <info descr="'MyTrait' is deprecated">MyTrait</info>) {}
|
||||
class Test2(param: <info descr="'MyTrait' is deprecated. Use A instead">MyTrait</info>) {}
|
||||
Reference in New Issue
Block a user