kotlin.annotation.Target / Retention have now more priority than same java classes if import java.lang.annotation.* is available
This commit is contained in:
+8
-4
@@ -57,6 +57,12 @@ public enum TopDownAnalyzerFacadeForJVM {
|
|||||||
|
|
||||||
public static final List<ImportPath> DEFAULT_IMPORTS = buildDefaultImports();
|
public static final List<ImportPath> DEFAULT_IMPORTS = buildDefaultImports();
|
||||||
|
|
||||||
|
private static void addAllClassifiersToImportPathList(List<ImportPath> list, JetScope scope) {
|
||||||
|
for (DeclarationDescriptor descriptor : scope.getDescriptors(DescriptorKindFilter.CLASSIFIERS, JetScope.ALL_NAME_FILTER)) {
|
||||||
|
list.add(new ImportPath(DescriptorUtils.getFqNameSafe(descriptor), false));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static List<ImportPath> buildDefaultImports() {
|
private static List<ImportPath> buildDefaultImports() {
|
||||||
List<ImportPath> list = new ArrayList<ImportPath>();
|
List<ImportPath> list = new ArrayList<ImportPath>();
|
||||||
list.add(new ImportPath("java.lang.*"));
|
list.add(new ImportPath("java.lang.*"));
|
||||||
@@ -65,10 +71,8 @@ public enum TopDownAnalyzerFacadeForJVM {
|
|||||||
list.add(new ImportPath("kotlin.jvm.*"));
|
list.add(new ImportPath("kotlin.jvm.*"));
|
||||||
list.add(new ImportPath("kotlin.io.*"));
|
list.add(new ImportPath("kotlin.io.*"));
|
||||||
|
|
||||||
JetScope builtInsScope = KotlinBuiltIns.getInstance().getBuiltInsPackageScope();
|
addAllClassifiersToImportPathList(list, KotlinBuiltIns.getInstance().getBuiltInsPackageScope());
|
||||||
for (DeclarationDescriptor descriptor : builtInsScope.getDescriptors(DescriptorKindFilter.CLASSIFIERS, JetScope.ALL_NAME_FILTER)) {
|
addAllClassifiersToImportPathList(list, KotlinBuiltIns.getInstance().getAnnotationPackageScope());
|
||||||
list.add(new ImportPath(DescriptorUtils.getFqNameSafe(descriptor), false));
|
|
||||||
}
|
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import java.lang.annotation.Retention
|
||||||
|
import java.lang.annotation.Target
|
||||||
import java.lang.annotation.*
|
import java.lang.annotation.*
|
||||||
|
|
||||||
<!DEPRECATED_JAVA_ANNOTATION!>@java.lang.annotation.Retention(RetentionPolicy.CLASS)<!>
|
<!DEPRECATED_JAVA_ANNOTATION!>@java.lang.annotation.Retention(RetentionPolicy.CLASS)<!>
|
||||||
|
|||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
import java.lang.annotation.*
|
||||||
|
|
||||||
|
<!DEPRECATED_JAVA_ANNOTATION!>@java.lang.annotation.Target(ElementType.PACKAGE)<!>
|
||||||
|
@Target(AnnotationTarget.CLASSIFIER)
|
||||||
|
annotation class my
|
||||||
|
|
||||||
|
<!DEPRECATED_JAVA_ANNOTATION!>@java.lang.annotation.Retention(RetentionPolicy.SOURCE)<!>
|
||||||
|
@Retention(AnnotationRetention.BINARY)
|
||||||
|
annotation class your
|
||||||
+15
@@ -0,0 +1,15 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
java.lang.annotation.Target(value = {ElementType.PACKAGE}) kotlin.annotation.Target(allowedTargets = {AnnotationTarget.CLASSIFIER}) kotlin.annotation.annotation() public final class my : kotlin.Annotation {
|
||||||
|
public constructor my()
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
|
|
||||||
|
java.lang.annotation.Retention(value = RetentionPolicy.SOURCE) kotlin.annotation.Retention(value = AnnotationRetention.BINARY) kotlin.annotation.annotation() public final class your : kotlin.Annotation {
|
||||||
|
public constructor your()
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
@@ -1049,6 +1049,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("javaKotlinTargetRetention.kt")
|
||||||
|
public void testJavaKotlinTargetRetention() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/options/javaKotlinTargetRetention.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("javaretention.kt")
|
@TestMetadata("javaretention.kt")
|
||||||
public void testJavaretention() throws Exception {
|
public void testJavaretention() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/options/javaretention.kt");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/options/javaretention.kt");
|
||||||
|
|||||||
@@ -166,7 +166,7 @@ public class AnnotationGenTest extends CodegenTestCase {
|
|||||||
|
|
||||||
public void testAnnotationWithParamForParamInFunction() throws Exception {
|
public void testAnnotationWithParamForParamInFunction() throws Exception {
|
||||||
ClassLoader loader = loadFileGetClassLoader("import java.lang.annotation.*\n" +
|
ClassLoader loader = loadFileGetClassLoader("import java.lang.annotation.*\n" +
|
||||||
"Retention(RetentionPolicy.RUNTIME) annotation class A(val a: String)\n" +
|
"@java.lang.annotation.Retention(RetentionPolicy.RUNTIME) annotation class A(val a: String)\n" +
|
||||||
"fun x(A(\"239\") i: Int) {}");
|
"fun x(A(\"239\") i: Int) {}");
|
||||||
Class<?> packageClass = getPackageSrcClass(loader);
|
Class<?> packageClass = getPackageSrcClass(loader);
|
||||||
Method packageClassMethod = packageClass.getMethod("x", int.class);
|
Method packageClassMethod = packageClass.getMethod("x", int.class);
|
||||||
@@ -246,7 +246,7 @@ public class AnnotationGenTest extends CodegenTestCase {
|
|||||||
InvocationTargetException {
|
InvocationTargetException {
|
||||||
loadText("import java.lang.annotation.*\n" +
|
loadText("import java.lang.annotation.*\n" +
|
||||||
"" +
|
"" +
|
||||||
"Retention(RetentionPolicy.RUNTIME) annotation class A(val a: String)\n" +
|
"@java.lang.annotation.Retention(RetentionPolicy.RUNTIME) annotation class A(val a: String)\n" +
|
||||||
"" +
|
"" +
|
||||||
"A(\"239\") class B()");
|
"A(\"239\") class B()");
|
||||||
Class aClass = generateClass("A");
|
Class aClass = generateClass("A");
|
||||||
@@ -280,7 +280,7 @@ public class AnnotationGenTest extends CodegenTestCase {
|
|||||||
loadText("import java.lang.annotation.*\n" +
|
loadText("import java.lang.annotation.*\n" +
|
||||||
"" +
|
"" +
|
||||||
"annotation class C(val c: String)\n" +
|
"annotation class C(val c: String)\n" +
|
||||||
"Retention(RetentionPolicy.RUNTIME) annotation class A(val a: C)\n" +
|
"@java.lang.annotation.Retention(RetentionPolicy.RUNTIME) annotation class A(val a: C)\n" +
|
||||||
"" +
|
"" +
|
||||||
"A(C(\"239\")) class B()");
|
"A(C(\"239\")) class B()");
|
||||||
Class aClass = generateClass("A");
|
Class aClass = generateClass("A");
|
||||||
@@ -317,7 +317,7 @@ public class AnnotationGenTest extends CodegenTestCase {
|
|||||||
InvocationTargetException {
|
InvocationTargetException {
|
||||||
loadText("import java.lang.annotation.*\n" +
|
loadText("import java.lang.annotation.*\n" +
|
||||||
"" +
|
"" +
|
||||||
"Retention(RetentionPolicy.RUNTIME) annotation class A(val a: Array<String>)\n" +
|
"@java.lang.annotation.Retention(RetentionPolicy.RUNTIME) annotation class A(val a: Array<String>)\n" +
|
||||||
"" +
|
"" +
|
||||||
"A(array(\"239\",\"932\")) class B()");
|
"A(array(\"239\",\"932\")) class B()");
|
||||||
Class aClass = generateClass("A");
|
Class aClass = generateClass("A");
|
||||||
@@ -352,7 +352,7 @@ public class AnnotationGenTest extends CodegenTestCase {
|
|||||||
InvocationTargetException {
|
InvocationTargetException {
|
||||||
loadText("import java.lang.annotation.*\n" +
|
loadText("import java.lang.annotation.*\n" +
|
||||||
"" +
|
"" +
|
||||||
"Retention(RetentionPolicy.RUNTIME) annotation class A(val a: IntArray)\n" +
|
"@java.lang.annotation.Retention(RetentionPolicy.RUNTIME) annotation class A(val a: IntArray)\n" +
|
||||||
"" +
|
"" +
|
||||||
"A(intArray(239,932)) class B()");
|
"A(intArray(239,932)) class B()");
|
||||||
Class aClass = generateClass("A");
|
Class aClass = generateClass("A");
|
||||||
@@ -387,7 +387,7 @@ public class AnnotationGenTest extends CodegenTestCase {
|
|||||||
InvocationTargetException {
|
InvocationTargetException {
|
||||||
loadText("import java.lang.annotation.*\n" +
|
loadText("import java.lang.annotation.*\n" +
|
||||||
"" +
|
"" +
|
||||||
"Target(ElementType.TYPE, ElementType.METHOD) annotation class A");
|
"@java.lang.annotation.Target(ElementType.TYPE, ElementType.METHOD) annotation class A");
|
||||||
Class aClass = generateClass("A");
|
Class aClass = generateClass("A");
|
||||||
|
|
||||||
Target annotation = (Target)aClass.getAnnotation(Target.class);
|
Target annotation = (Target)aClass.getAnnotation(Target.class);
|
||||||
@@ -407,8 +407,9 @@ public class AnnotationGenTest extends CodegenTestCase {
|
|||||||
InstantiationException,
|
InstantiationException,
|
||||||
InvocationTargetException {
|
InvocationTargetException {
|
||||||
loadText("import java.lang.annotation.*\n" +
|
loadText("import java.lang.annotation.*\n" +
|
||||||
|
"import java.lang.annotation.Retention\n" +
|
||||||
"" +
|
"" +
|
||||||
"Retention(RetentionPolicy.RUNTIME) annotation class A(val a: Array<Retention>)\n" +
|
"@Retention(RetentionPolicy.RUNTIME) annotation class A(val a: Array<Retention>)\n" +
|
||||||
"" +
|
"" +
|
||||||
"A(array(Retention(RetentionPolicy.RUNTIME),Retention(RetentionPolicy.SOURCE))) class B()");
|
"A(array(Retention(RetentionPolicy.RUNTIME),Retention(RetentionPolicy.SOURCE))) class B()");
|
||||||
Class aClass = generateClass("A");
|
Class aClass = generateClass("A");
|
||||||
|
|||||||
@@ -240,6 +240,11 @@ public class KotlinBuiltIns {
|
|||||||
return builtinsPackageFragment.getMemberScope();
|
return builtinsPackageFragment.getMemberScope();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public JetScope getAnnotationPackageScope() {
|
||||||
|
return annotationPackageFragment.getMemberScope();
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// GET CLASS
|
// GET CLASS
|
||||||
|
|||||||
Reference in New Issue
Block a user