Map java.land.Deprecated to jet.deprecated
Change testData for deprecated annotation #KT-2947 Fixed
This commit is contained in:
+12
@@ -22,6 +22,8 @@ import com.intellij.psi.PsiModifierListOwner;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.constants.*;
|
||||
import org.jetbrains.jet.lang.resolve.java.data.ResolverClassData;
|
||||
import org.jetbrains.jet.lang.resolve.java.data.ResolverNamespaceData;
|
||||
import org.jetbrains.jet.lang.resolve.java.data.ResolverScopeData;
|
||||
@@ -142,4 +144,14 @@ public final class DescriptorResolverUtils {
|
||||
assert psiClassQualifiedName != null : "Reading java class with no qualified name";
|
||||
return new FqNameUnsafe(psiClassQualifiedName + "." + getClassObjectName(psiClass.getName()).getName());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static AnnotationDescriptor getAnnotationDescriptorForJavaLangDeprecated(ClassDescriptor classDescriptor) {
|
||||
AnnotationDescriptor annotationDescriptor = new AnnotationDescriptor();
|
||||
annotationDescriptor.setAnnotationType(classDescriptor.getDefaultType());
|
||||
ValueParameterDescriptor value = getValueParameterDescriptorForAnnotationParameter(Name.identifier("value"), classDescriptor);
|
||||
assert value != null : "jet.deprecated must have one parameter called value";
|
||||
annotationDescriptor.setValueArgument(value, new StringValue("Deprecated in Java"));
|
||||
return annotationDescriptor;
|
||||
}
|
||||
}
|
||||
|
||||
+11
@@ -17,11 +17,13 @@
|
||||
package org.jetbrains.jet.lang.resolve.java;
|
||||
|
||||
import com.google.common.collect.*;
|
||||
import com.intellij.psi.CommonClassNames;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.PlatformToKotlinClassMap;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe;
|
||||
@@ -89,6 +91,15 @@ public class JavaToKotlinClassMap extends JavaToKotlinClassMapBuilder implements
|
||||
return classDescriptorMap.get(fqName);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public AnnotationDescriptor mapToAnnotationClass(@NotNull FqName fqName) {
|
||||
ClassDescriptor classDescriptor = classDescriptorMap.get(fqName);
|
||||
if (classDescriptor != null && fqName.getFqName().equals(CommonClassNames.JAVA_LANG_DEPRECATED)) {
|
||||
return DescriptorResolverUtils.getAnnotationDescriptorForJavaLangDeprecated(classDescriptor);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static FqName getJavaClassFqName(@NotNull Class<?> javaClass) {
|
||||
return new FqName(javaClass.getName().replace('$', '.'));
|
||||
}
|
||||
|
||||
+1
@@ -45,6 +45,7 @@ public abstract class JavaToKotlinClassMapBuilder {
|
||||
register(Comparable.class, kotlinBuiltIns.getComparable());
|
||||
register(Enum.class, kotlinBuiltIns.getEnum());
|
||||
register(Annotation.class, kotlinBuiltIns.getAnnotation());
|
||||
register(Deprecated.class, kotlinBuiltIns.getDeprecatedAnnotation(), Direction.JAVA_TO_KOTLIN);
|
||||
|
||||
register(Iterable.class, kotlinBuiltIns.getIterable(), kotlinBuiltIns.getMutableIterable());
|
||||
register(Iterator.class, kotlinBuiltIns.getIterator(), kotlinBuiltIns.getMutableIterator());
|
||||
|
||||
+8
-4
@@ -24,10 +24,8 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
||||
import org.jetbrains.jet.lang.resolve.java.DescriptorResolverUtils;
|
||||
import org.jetbrains.jet.lang.resolve.java.DescriptorSearchRule;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
|
||||
import org.jetbrains.jet.lang.resolve.constants.*;
|
||||
import org.jetbrains.jet.lang.resolve.java.*;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
|
||||
@@ -88,6 +86,12 @@ public final class JavaAnnotationResolver {
|
||||
}
|
||||
|
||||
FqName annotationFqName = new FqName(qname);
|
||||
|
||||
AnnotationDescriptor mappedClassDescriptor = JavaToKotlinClassMap.getInstance().mapToAnnotationClass(annotationFqName);
|
||||
if (mappedClassDescriptor != null) {
|
||||
return mappedClassDescriptor;
|
||||
}
|
||||
|
||||
final ClassDescriptor annotationClass =
|
||||
classResolver.resolveClass(annotationFqName, DescriptorSearchRule.INCLUDE_KOTLIN, postponedTasks);
|
||||
if (annotationClass == null) {
|
||||
|
||||
@@ -2,4 +2,4 @@ import java.util.ArrayList
|
||||
|
||||
<!NONE_APPLICABLE!>ArrayList<!><Int>(1, 1) fun b() {}
|
||||
<!UNRESOLVED_REFERENCE!>Xoo<!>(<!UNRESOLVED_REFERENCE!>x<!>) fun c() {}
|
||||
Deprecated(<!TOO_MANY_ARGUMENTS, UNRESOLVED_REFERENCE!>x<!>) fun a() {}
|
||||
<!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>Deprecated<!>(<!TOO_MANY_ARGUMENTS, UNRESOLVED_REFERENCE!>x<!>) fun a() {}
|
||||
@@ -1,15 +1,15 @@
|
||||
package a
|
||||
|
||||
import java.lang.Deprecated as deprecated
|
||||
import <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>java.lang.Deprecated<!> as deprecated
|
||||
import java.lang.SuppressWarnings as suppresswarnings
|
||||
|
||||
|
||||
deprecated suppresswarnings val s: String = "";
|
||||
<!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>deprecated<!> suppresswarnings val s: String = "";
|
||||
|
||||
deprecated suppresswarnings fun main(args : Array<String>) {
|
||||
<!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>deprecated<!> suppresswarnings fun main(args : Array<String>) {
|
||||
System.out.println("Hello, world!")
|
||||
}
|
||||
|
||||
class Test(deprecated val s: String,
|
||||
class Test(<!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>deprecated<!> val s: String,
|
||||
suppresswarnings val x : Int) {}
|
||||
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
annotation [java.lang.Deprecated] class my
|
||||
annotation Deprecated class my1
|
||||
annotation [<!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>java.lang.Deprecated<!>] class my
|
||||
annotation <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>Deprecated<!> class my1
|
||||
@@ -1,6 +1,5 @@
|
||||
import <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>java.lang.Deprecated<!> as deprecated
|
||||
|
||||
import java.lang.Deprecated as deprecated
|
||||
<!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>Deprecated<!> fun foo() {}
|
||||
|
||||
Deprecated fun foo() {}
|
||||
|
||||
deprecated fun foo1() {}
|
||||
<!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>deprecated<!> fun foo1() {}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
package test
|
||||
|
||||
public open class AnnotatedMethod() : java.lang.Object() {
|
||||
public open Deprecated fun f(): Unit { }
|
||||
public open deprecated("Deprecated in Java") fun f(): Unit { }
|
||||
}
|
||||
|
||||
@@ -2,5 +2,5 @@ namespace test
|
||||
|
||||
public open class test.AnnotatedMethod : java.lang.Object {
|
||||
public final /*constructor*/ fun <init>(): test.AnnotatedMethod
|
||||
public open java.lang.Deprecated() fun f(): jet.Tuple0
|
||||
public open jet.deprecated(value = "Deprecated in Java") fun f(): jet.Tuple0
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Deprecated class MyClass() {
|
||||
deprecated("") class MyClass() {
|
||||
}
|
||||
|
||||
// TESTED_OBJECT_KIND: class
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class MyClass {
|
||||
Deprecated class object {
|
||||
deprecated("") class object {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Deprecated enum class MyEnum {
|
||||
deprecated("") enum class MyEnum {
|
||||
FIRST
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class MyClass() {
|
||||
Deprecated public class MyInnerClass() {}
|
||||
deprecated("") public class MyInnerClass() {}
|
||||
}
|
||||
|
||||
// TESTED_OBJECT_KIND: class
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Deprecated public trait MyTrait {
|
||||
deprecated("") public trait MyTrait {
|
||||
}
|
||||
|
||||
// TESTED_OBJECT_KIND: class
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class MyClass() {
|
||||
val test = ""
|
||||
[Deprecated] get
|
||||
[deprecated("")] get
|
||||
}
|
||||
|
||||
// TESTED_OBJECT_KIND: function
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class MyClass() {
|
||||
var test = ""
|
||||
[Deprecated] set
|
||||
[deprecated("")] set
|
||||
}
|
||||
|
||||
// TESTED_OBJECT_KIND: function
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class MyClass() { }
|
||||
|
||||
Deprecated fun MyClass.test() {}
|
||||
deprecated("") fun MyClass.test() {}
|
||||
|
||||
// TESTED_OBJECT_KIND: function
|
||||
// TESTED_OBJECTS: namespace, test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class MyClass() {
|
||||
Deprecated fun test() {}
|
||||
deprecated("") fun test() {}
|
||||
}
|
||||
|
||||
// TESTED_OBJECT_KIND: function
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class MyClass() {
|
||||
class object {
|
||||
Deprecated fun test() {}
|
||||
deprecated("") fun test() {}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class MyClass() {
|
||||
val test: Int
|
||||
[Deprecated] get(): Int { return 0 }
|
||||
[deprecated("")] get(): Int { return 0 }
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class MyClass() {
|
||||
Deprecated val test = ""
|
||||
deprecated("") val test = ""
|
||||
}
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
class MyClass(Deprecated val test: Int) {}
|
||||
class MyClass(deprecated("") val test: Int) {}
|
||||
|
||||
// TESTED_OBJECT_KIND: function
|
||||
// TESTED_OBJECTS: MyClass, getTest
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class MyClass() {
|
||||
var test = 1
|
||||
[Deprecated] set(i: Int) { test = i }
|
||||
[deprecated("")] set(i: Int) { test = i }
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class MyClass() {
|
||||
Deprecated var test = ""
|
||||
deprecated("") var test = ""
|
||||
}
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
class MyClass(Deprecated var test: Int) {}
|
||||
class MyClass(deprecated("") var test: Int) {}
|
||||
|
||||
|
||||
// TESTED_OBJECT_KIND: function
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Deprecated fun test() {}
|
||||
deprecated("") fun test() {}
|
||||
|
||||
// TESTED_OBJECT_KIND: function
|
||||
// TESTED_OBJECTS: namespace, test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class MyClass() {
|
||||
Deprecated public val test: Int = 0
|
||||
deprecated("") public val test: Int = 0
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Deprecated val test: Int = 0
|
||||
deprecated("") val test: Int = 0
|
||||
|
||||
// TESTED_OBJECT_KIND: property
|
||||
// TESTED_OBJECTS: namespace, test
|
||||
|
||||
Reference in New Issue
Block a user