Map java.land.Deprecated to jet.deprecated

Change testData for deprecated annotation
 #KT-2947 Fixed
This commit is contained in:
Natalia.Ukhorskaya
2012-10-18 19:14:04 +04:00
parent f9c1c041d7
commit 62d8153ada
42 changed files with 107 additions and 98 deletions
@@ -29,7 +29,6 @@ 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;
@@ -38,7 +37,6 @@ 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 {
@@ -206,11 +204,11 @@ public class DeprecatedAnnotationVisitor extends AfterAnalysisHighlightingVisito
AnnotationDescriptor deprecated = getDeprecated(descriptor);
if (deprecated != null) {
if (isWarning) {
holder.createInfoAnnotation(element, "'" + renderName(descriptor) + "' is deprecated")
holder.createInfoAnnotation(element, getMessage(deprecated))
.setTextAttributes(CodeInsightColors.WARNINGS_ATTRIBUTES);
}
else {
holder.createInfoAnnotation(element, "'" + renderName(descriptor) + "' is deprecated")
holder.createInfoAnnotation(element, getMessage(deprecated))
.setTextAttributes(CodeInsightColors.DEPRECATED_ATTRIBUTES);
}
return true;
@@ -230,30 +228,14 @@ public class DeprecatedAnnotationVisitor extends AfterAnalysisHighlightingVisito
return null;
}
private static String renderName(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);
private static String getMessage(AnnotationDescriptor descriptor) {
ClassDescriptor classDescriptor = TypeUtils.getClassDescriptor(descriptor.getType());
assert classDescriptor != null : "ClassDescriptor for jet.deprecated mustn't be null";
ValueParameterDescriptor parameterDescriptor =
DescriptorResolverUtils.getValueParameterDescriptorForAnnotationParameter(Name.identifier("value"), classDescriptor);
assert parameterDescriptor != null : "jet.deprecated must have one parameter called value";
CompileTimeConstant<?> valueArgument = descriptor.getValueArgument(parameterDescriptor);
assert valueArgument != null : "jet.deprecated must have value argument";
return (String) valueArgument.getValue();
}
}
@@ -2,7 +2,7 @@ package test
<info>import</info> java.util.ArrayList
Deprecated <info>open</info> class MyClass {}
deprecated("'test.MyClass' is deprecated") <info>open</info> class MyClass {}
fun test() {
val a : <info descr="'test.MyClass' is deprecated">MyClass</info>? = null
@@ -7,13 +7,13 @@ fun test() {
}
class MyClass(): MyTrait {
Deprecated class object {
deprecated("'MyClass.<class-object-for-MyClass>' is deprecated") class object {
val <info>test</info>: String = ""
}
}
trait MyTrait {
Deprecated class object {
deprecated("'MyTrait.<class-object-for-MyTrait>' is deprecated") class object {
val <info>test</info>: String = ""
}
}
@@ -6,13 +6,13 @@ fun test() {
<info descr="'fun test4(x : jet.Int, y : jet.Int)' is deprecated">test4</info>(1, 2)
}
Deprecated fun test1() { }
Deprecated fun test4(x: Int, y: Int) { }
deprecated("'fun test1()' is deprecated") fun test1() { }
deprecated("'fun test4(x : jet.Int, y : jet.Int)' is deprecated") fun test4(x: Int, y: Int) { }
class MyClass() {
Deprecated fun test2() {}
deprecated("'fun test2()' is deprecated") fun test2() {}
class object {
Deprecated fun test3() {}
deprecated("'fun test3()' is deprecated") fun test3() {}
}
}
+1 -1
View File
@@ -1,6 +1,6 @@
class MyClass {}
Deprecated fun MyClass.get(i: MyClass): MyClass { return MyClass() }
deprecated("'fun get(i : MyClass)' is deprecated") fun MyClass.get(i: MyClass): MyClass { return MyClass() }
fun test() {
val x1 = MyClass()
@@ -9,11 +9,11 @@ fun test() {
class MyClass() {
<info>public</info> val <info>test1</info>: String = ""
[Deprecated] <info descr="null">get</info>
[deprecated("'getter for test1' is deprecated")] <info>get</info>
<info>public</info> var <info>test2</info>: String = ""
[Deprecated] <info descr="null">get</info>
[deprecated("'getter for test2' is deprecated")] <info>get</info>
Deprecated <info>public</info> val <info>test3</info>: String = ""
[Deprecated] <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>
}
+1 -1
View File
@@ -1,6 +1,6 @@
class MyClass {}
Deprecated fun MyClass.inc(): MyClass { return MyClass() }
deprecated("'fun inc()' is deprecated") fun MyClass.inc(): MyClass { return MyClass() }
fun test() {
var x3 = MyClass()
@@ -1,6 +1,6 @@
class MyRunnable() {}
Deprecated fun MyRunnable.invoke() {
deprecated("'fun invoke()' is deprecated") fun MyRunnable.invoke() {
}
fun test() {
@@ -1,18 +1,18 @@
class MyClass {}
Deprecated fun MyClass.minus(i: MyClass) { }
Deprecated fun MyClass.div(i: MyClass) { }
Deprecated fun MyClass.times(i: 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 fun MyClass.not() { }
Deprecated fun MyClass.plus() { }
deprecated("'fun not()' is deprecated") fun MyClass.not() { }
deprecated("'fun plus()' is deprecated") fun MyClass.plus() { }
Deprecated fun MyClass.contains(i: MyClass): Boolean { return false }
deprecated("'fun contains(i : MyClass)' is deprecated") fun MyClass.contains(i: MyClass): Boolean { return false }
Deprecated fun MyClass.plusAssign(i: MyClass) { }
deprecated("'fun plusAssign(i : MyClass)' is deprecated") fun MyClass.plusAssign(i: MyClass) { }
Deprecated fun MyClass.equals(i: Any?): Boolean { return false }
Deprecated fun MyClass.compareTo(i: MyClass): Int { return 0 }
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 }
fun test() {
val x1 = MyClass()
@@ -8,15 +8,15 @@ fun test() {
MyClass.<info descr="'var test6' is deprecated">test6</info>
}
Deprecated val <info>test1</info>: String = ""
Deprecated var <info>test4</info>: String = ""
deprecated("'val test1' is deprecated") val <info>test1</info>: String = ""
deprecated("'var test4' is deprecated") var <info>test4</info>: String = ""
class MyClass() {
Deprecated val <info>test2</info>: String = ""
Deprecated var <info>test5</info>: String = ""
deprecated("'val test2' is deprecated") val <info>test2</info>: String = ""
deprecated("'var test5' is deprecated") var <info>test5</info>: String = ""
class object {
Deprecated val <info>test3</info>: String = ""
Deprecated var <info>test6</info>: String = ""
deprecated("'val test3' is deprecated") val <info>test3</info>: String = ""
deprecated("'var test6' is deprecated") var <info>test6</info>: String = ""
}
}
@@ -1,6 +1,6 @@
class MyClass { }
Deprecated fun MyClass.rangeTo(i: MyClass): IntIterator {
deprecated("'fun rangeTo(i : MyClass)' is deprecated") fun MyClass.rangeTo(i: MyClass): IntIterator {
throw Exception()
}
@@ -19,8 +19,8 @@ fun test() {
class MyClass() {
<info>public</info> var <info>test1</info>: Int = 0
[Deprecated] <info>set</info>
[deprecated("'setter for test1' is deprecated")] <info>set</info>
}
<info>public</info> var <info>test2</info>: Int = 0
[Deprecated] <info>set</info>
[deprecated("'setter for test2' is deprecated")] <info>set</info>
@@ -1,4 +1,4 @@
Deprecated trait MyTrait { }
deprecated("'MyTrait' is deprecated") trait MyTrait { }
fun test() {
val a: <info descr="'MyTrait' is deprecated">MyTrait</info>? = null