diff options
Diffstat (limited to 'test-utils/testData')
86 files changed, 8527 insertions, 0 deletions
diff --git a/test-utils/testData/api/abstractFunctions.kt b/test-utils/testData/api/abstractFunctions.kt new file mode 100644 index 00000000..477f6369 --- /dev/null +++ b/test-utils/testData/api/abstractFunctions.kt @@ -0,0 +1,58 @@ +/* + * Copyright 2022 Google LLC + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// WITH_RUNTIME +// TEST PROCESSOR: AbstractFunctionsProcessor +// EXPECTED: +// abstractF01 +// abstractF02 +// abstractF04 +// abstractF05 +// END +// FILE: AbstractClassKotlin.kt +abstract class AbstractClassKotlin { + abstract fun abstractF01() + fun concreteF01() = Unit + companion object { + fun concreteF02() = Unit + @JvmStatic fun concreteF02() = Unit + } +} + +// FILE: InterfaceKotlin.kt +interface InterfaceKotlin { + fun abstractF02() + fun abstractWithDefaultF03() { /*default*/ Unit } + companion object { + fun concreteF03() = Unit + @JvmStatic fun concreteF04() = Unit + } +} + +// FILE: AbstractClassJava.java +public abstract class AbstractClassJava { + public abstract void abstractF04(); + public void concreteF05() {} + public static void staticF01() {} +} + +// FILE: InterfaceJava.java +public interface InterfaceJava { + public void abstractF05(); + public default void abstractWithDefaultF06() { /* default */ } + public static void staticF02() {} +} diff --git a/test-utils/testData/api/allFunctions_java_inherits_kt.kt b/test-utils/testData/api/allFunctions_java_inherits_kt.kt new file mode 100644 index 00000000..bd1303a1 --- /dev/null +++ b/test-utils/testData/api/allFunctions_java_inherits_kt.kt @@ -0,0 +1,46 @@ +/* + * Copyright 2020 Google LLC + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// WITH_RUNTIME +// TEST PROCESSOR: AllFunctionsProcessor +// EXPECTED: +// class: JavaImplOfKotlinInterface +// x +// <init>(): JavaImplOfKotlinInterface +// equals(kotlin.Any): kotlin.Boolean +// hashCode(): kotlin.Int +// toString(): kotlin.String +// class: KotlinInterfaceWithProperty +// x +// equals(kotlin.Any): kotlin.Boolean +// hashCode(): kotlin.Int +// toString(): kotlin.String +// END + +// FILE: KotlinInterfaceWithProperty.kt +interface KotlinInterfaceWithProperty { + var x:Int +} + +// FILE: JavaImplOfKotlinInterface.java +class JavaImplOfKotlinInterface implements KotlinInterfaceWithProperty { + public int getX() { + return 1; + } + public void setX(int value) { + } +} diff --git a/test-utils/testData/api/allFunctions_kotlin.kt b/test-utils/testData/api/allFunctions_kotlin.kt new file mode 100644 index 00000000..febbac12 --- /dev/null +++ b/test-utils/testData/api/allFunctions_kotlin.kt @@ -0,0 +1,72 @@ +/* + * Copyright 2020 Google LLC + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// WITH_RUNTIME +// TEST PROCESSOR: AllFunctionsProcessor +// class: Data +// a +// <init>(kotlin.String): Data +// component1(): kotlin.String +// copy(kotlin.String(hasDefault)): Data +// equals(kotlin.Any): kotlin.Boolean +// hashCode(): kotlin.Int +// toString(): kotlin.String +// class: Sub +// equals(kotlin.Any): kotlin.Boolean +// foo(kotlin.String ...): kotlin.Unit +// hashCode(): kotlin.Int +// toString(): kotlin.String +// class: SubAbstract +// <init>(): SubAbstract +// equals(kotlin.Any): kotlin.Boolean +// foo(kotlin.String ...): kotlin.Unit +// hashCode(): kotlin.Int +// toString(): kotlin.String +// class: Super +// equals(kotlin.Any): kotlin.Boolean +// foo(kotlin.String ...): kotlin.Unit +// hashCode(): kotlin.Int +// toString(): kotlin.String +// class: SuperAbstract +// <init>(): SuperAbstract +// equals(kotlin.Any): kotlin.Boolean +// foo(kotlin.String ...): kotlin.Unit +// hashCode(): kotlin.Int +// toString(): kotlin.String +// EXPECTED: +// END +// FILE: a.kt +data class Data(val a: String) { + override fun equals(other: Any?): Boolean { + return false + } +} + +interface Super { + fun foo(vararg values: String) +} + +interface Sub : Super + +class SubAbstract: SuperAbstract() + +abstract class SuperAbstract { + fun foo(vararg values: String) { + + } +} + diff --git a/test-utils/testData/api/allFunctions_kt_inherits_java.kt b/test-utils/testData/api/allFunctions_kt_inherits_java.kt new file mode 100644 index 00000000..02000432 --- /dev/null +++ b/test-utils/testData/api/allFunctions_kt_inherits_java.kt @@ -0,0 +1,93 @@ +/* + * Copyright 2022 Google LLC + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// WITH_RUNTIME +// TEST PROCESSOR: AllFunctionsProcessor +// EXPECTED: +// class: C +// aFromC +// bFromC +// cFromC +// <init>(): C +// equals(kotlin.Any): kotlin.Boolean +// hashCode(): kotlin.Int +// javaListFun(): kotlin.collections.MutableCollection +// javaPrivateFun(): kotlin.Unit +// javaStrFun(): kotlin.String +// toString(): kotlin.String +// class: Foo +// aFromC +// cFromC +// size +// <init>(): Foo +// bar(): kotlin.Boolean +// baz(kotlin.String,kotlin.String(hasDefault),kotlin.String(hasDefault)): kotlin.Boolean +// contains(kotlin.Number): kotlin.Boolean +// containsAll(kotlin.collections.Collection): kotlin.Boolean +// equals(kotlin.Any): kotlin.Boolean +// forEach(java.util.function.Consumer): kotlin.Unit +// get(kotlin.Int): kotlin.Number +// hashCode(): kotlin.Int +// indexOf(kotlin.Number): kotlin.Int +// isEmpty(): kotlin.Boolean +// iterator(): kotlin.collections.Iterator +// javaListFun(): kotlin.collections.List +// javaStrFun(): kotlin.String +// lastIndexOf(kotlin.Number): kotlin.Int +// listIterator(): kotlin.collections.ListIterator +// listIterator(kotlin.Int): kotlin.collections.ListIterator +// parallelStream(): java.util.stream.Stream +// spliterator(): java.util.Spliterator +// stream(): java.util.stream.Stream +// subList(kotlin.Int,kotlin.Int): kotlin.collections.List +// toArray(java.util.function.IntFunction): kotlin.Array +// toString(): kotlin.String +// END +// FILE: a.kt +abstract class Foo : C(), List<out Number> { + override fun javaListFun(): List<Int> { + throw java.lang.IllegalStateException() + } + + fun bar(): Boolean { + return false + } + + fun baz(input: String, input2: String? = null, input3: String = ""): Boolean { + return false + } +} + +// FILE: C.java +import java.util.Collection; + +class C { + public int aFromC = 1; + private int bFromC = 2; + protected int cFromC = 3; + private void javaPrivateFun() { + + } + + protected Collection<Integer> javaListFun() { + return Arrays.asList(1,2,3) + } + + public String javaStrFun() { + return "str" + } +} diff --git a/test-utils/testData/api/annotatedUtil.kt b/test-utils/testData/api/annotatedUtil.kt new file mode 100644 index 00000000..bbd05785 --- /dev/null +++ b/test-utils/testData/api/annotatedUtil.kt @@ -0,0 +1,149 @@ +/* + * Copyright 2021 Google LLC + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// TEST PROCESSOR: AnnotatedUtilProcessor +// EXPECTED: +// Test: OnlyTestAnnotation +// Test: ParametersTestAnnotationWithValuesTest +// IsPresent: class com.google.devtools.ksp.processor.ParametersTestAnnotation +// ByType: com.google.devtools.ksp.processor.ParametersTestAnnotation[booleanValue=true, byteValue=5, shortValue=202, charValue=k, doubleValue=5.12, floatValue=123.3, intValue=2, longValue=4, stringValue=someValue, kClassValue=class java.lang.Throwable, enumValue=VALUE1] +// Test: ParametersTestAnnotationWithDefaultsTest +// IsPresent: class com.google.devtools.ksp.processor.ParametersTestAnnotation +// ByType: com.google.devtools.ksp.processor.ParametersTestAnnotation[booleanValue=false, byteValue=2, shortValue=3, charValue=b, doubleValue=4.0, floatValue=5.0, intValue=6, longValue=7, stringValue=emptystring, kClassValue=interface com.google.devtools.ksp.processor.ParametersTestAnnotation, enumValue=NONE] +// ByType: com.google.devtools.ksp.processor.ParametersTestAnnotation[booleanValue=false, byteValue=2, shortValue=3, charValue=b, doubleValue=4.0, floatValue=5.0, intValue=6, longValue=7, stringValue=emptystring, kClassValue=interface com.google.devtools.ksp.processor.ParametersTestAnnotation, enumValue=NONE] +// Test: ParametersTestWithNegativeDefaultsAnnotationTest +// IsPresent: class com.google.devtools.ksp.processor.ParametersTestWithNegativeDefaultsAnnotation +// ByType: com.google.devtools.ksp.processor.ParametersTestWithNegativeDefaultsAnnotation[byteValue=-2, shortValue=-3, doubleValue=-4.0, floatValue=-5.0, intValue=-6, longValue=-7] +// ByType: com.google.devtools.ksp.processor.ParametersTestWithNegativeDefaultsAnnotation[byteValue=-2, shortValue=-3, doubleValue=-4.0, floatValue=-5.0, intValue=-6, longValue=-7] +// Test: ParameterArraysTestAnnotationWithDefaultTest +// IsPresent: class com.google.devtools.ksp.processor.ParameterArraysTestAnnotation +// ByType: ParameterArraysTestAnnotation[booleanArrayValue=[true, false],byteArrayValue=[-2, 4],shortArrayValue=[-1, 2, 3],charArrayValue=[a, b, c],doubleArrayValue=[1.1, 2.2, 3.3],floatArrayValue=[1.0, 2.0, 3.3],intArrayValue=[1, 2, 4, 8, 16],longArrayValue=[1, 2, 4, 8, 16, 32],stringArrayValue=[first, second, third],kClassArrayValue=[class kotlin.Throwable, class com.google.devtools.ksp.processor.ParametersTestAnnotation],enumArrayValue=[VALUE1, VALUE2, VALUE1, VALUE2]] +// Test: AnnotationWithinAnAnnotationTest +// IsPresent: class com.google.devtools.ksp.processor.OuterAnnotation +// ByType: com.google.devtools.ksp.processor.OuterAnnotation[innerAnnotation=com.google.devtools.ksp.processor.InnerAnnotation[value=hello from the other side]] +// END +// MODULE: annotations +// FILE: com/google/devtools/ksp/processor/a.kt +package com.google.devtools.ksp.processor + +import kotlin.reflect.KClass +import java.lang.Throwable + +annotation class Test + +@Suppress("LongParameterList") +annotation class ParametersTestAnnotation( + val booleanValue: Boolean = false, + val byteValue: Byte = 2, + val shortValue: Short = 3, + val charValue: Char = 'b', + val doubleValue: Double = 4.0, + val floatValue: Float = 5.0f, + val intValue: Int = 6, + val longValue: Long = 7L, + val stringValue: String = "emptystring", + val kClassValue: KClass<*> = ParametersTestAnnotation::class, + val enumValue: TestEnum = TestEnum.NONE, +) + +@Suppress("LongParameterList") +annotation class ParameterArraysTestAnnotation( + val booleanArrayValue: BooleanArray = booleanArrayOf(), + val byteArrayValue: ByteArray = byteArrayOf(), + val shortArrayValue: ShortArray = shortArrayOf(), + val charArrayValue: CharArray = charArrayOf(), + val doubleArrayValue: DoubleArray = doubleArrayOf(), + val floatArrayValue: FloatArray = floatArrayOf(), + val intArrayValue: IntArray = intArrayOf(), + val longArrayValue: LongArray = longArrayOf(), + val stringArrayValue: Array<String> = emptyArray(), + val kClassArrayValue: Array<KClass<*>> = emptyArray(), + val enumArrayValue: Array<TestEnum> = emptyArray(), +) + +annotation class ParametersTestWithNegativeDefaultsAnnotation( + val byteValue: Byte = -2, + val shortValue: Short = -3, + val doubleValue: Double = -4.0, + val floatValue: Float = -5.0f, + val intValue: Int = -6, + val longValue: Long = -7L, +) + +enum class TestEnum { + NONE, VALUE1, VALUE2 +} + +annotation class InnerAnnotation(val value: String = "default") + +annotation class OuterAnnotation( + val innerAnnotation : InnerAnnotation = InnerAnnotation() +) + +///////////////////////////////////////////////////////// +// Tests +///////////////////////////////////////////////////////// + +@Test +@Test +class OnlyTestAnnotation + +@ParametersTestAnnotation( + booleanValue = true, + byteValue = 5, + shortValue = 202, + charValue = 'k', + doubleValue = 5.12, + floatValue = 123.3f, + intValue = 2, + longValue = 4L, + stringValue = "someValue", + java.lang.Throwable::class, + TestEnum.VALUE1, +) +@Test +class ParametersTestAnnotationWithValuesTest + +@ParametersTestAnnotation +@ParametersTestAnnotation +@Test +class ParametersTestAnnotationWithDefaultsTest + +@ParametersTestWithNegativeDefaultsAnnotation +@ParametersTestWithNegativeDefaultsAnnotation +@Test +class ParametersTestWithNegativeDefaultsAnnotationTest + +@ParameterArraysTestAnnotation( + booleanArrayValue = booleanArrayOf(true, false), + byteArrayValue = byteArrayOf(-2, 4), + shortArrayValue = shortArrayOf(-1, 2, 3), + charArrayValue = charArrayOf('a', 'b', 'c'), + doubleArrayValue = doubleArrayOf(1.1, 2.2, 3.3), + floatArrayValue = floatArrayOf(1.0f, 2.0f, 3.3f), + intArrayValue = intArrayOf(1, 2, 4, 8, 16), + longArrayValue = longArrayOf(1L, 2L, 4L, 8L, 16, 32L), + stringArrayValue = arrayOf("first", "second", "third"), + kClassArrayValue = arrayOf(Throwable::class, ParametersTestAnnotation::class), + enumArrayValue = arrayOf(TestEnum.VALUE1, TestEnum.VALUE2, TestEnum.VALUE1, TestEnum.VALUE2), +) +@Test +class ParameterArraysTestAnnotationWithDefaultTest + +@OuterAnnotation(innerAnnotation = InnerAnnotation("hello from the other side")) +@Test +class AnnotationWithinAnAnnotationTest diff --git a/test-utils/testData/api/annotationInDependencies.kt b/test-utils/testData/api/annotationInDependencies.kt new file mode 100644 index 00000000..705bc560 --- /dev/null +++ b/test-utils/testData/api/annotationInDependencies.kt @@ -0,0 +1,202 @@ +/* + * Copyright 2020 Google LLC + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// WITH_RUNTIME +// TEST PROCESSOR: AnnotationsInDependenciesProcessor +// EXPECTED: +// main.KotlinClass -> +// class main.KotlinClass : annotations.ClassTarget{[value = onClass]} +// class main.KotlinClass : annotations.NoTargetAnnotation{[value = onClass]} +// function myFun : annotations.FunctionTarget{[value = onMyFun]} +// function myFun : annotations.NoTargetAnnotation{[value = onMyFun]} +// getter of property prop : annotations.PropertyGetterTarget{[value = get:]} +// parameter <set-?> : annotations.ValueParameterTarget{[value = onPropSetter]} +// parameter <set-?> : annotations.ValueParameterTarget{[value = onProp]} +// parameter param1 : annotations.NoTargetAnnotation{[value = onParam1]} +// parameter param1 : annotations.ValueParameterTarget{[value = onParam1]} +// parameter param2 : annotations.NoTargetAnnotation{[value = onParam2]} +// parameter param2 : annotations.ValueParameterTarget{[value = onParam2]} +// property prop : annotations.FieldTarget2{[value = field:]} +// property prop : annotations.FieldTarget{[value = onProp]} +// property prop : annotations.NoTargetAnnotation{[value = onProp]} +// property prop : annotations.PropertyTarget{[value = onProp]} +// setter of property prop : annotations.PropertySetterTarget{[value = set:]} +// lib.KotlinClass -> +// class lib.KotlinClass : annotations.ClassTarget{[value = onClass]} +// class lib.KotlinClass : annotations.NoTargetAnnotation{[value = onClass]} +// function myFun : annotations.FunctionTarget{[value = onMyFun]} +// function myFun : annotations.NoTargetAnnotation{[value = onMyFun]} +// getter of property prop : annotations.PropertyGetterTarget{[value = get:]} +// parameter param1 : annotations.NoTargetAnnotation{[value = onParam1]} +// parameter param1 : annotations.ValueParameterTarget{[value = onParam1]} +// parameter param2 : annotations.NoTargetAnnotation{[value = onParam2]} +// parameter param2 : annotations.ValueParameterTarget{[value = onParam2]} +// parameter propInConstructor : annotations.ValueParameterTarget{[value = propInConstructor]} +// property prop : annotations.FieldTarget2{[value = field:]} +// property prop : annotations.FieldTarget{[value = onProp]} +// property prop : annotations.NoTargetAnnotation{[value = onProp]} +// property prop : annotations.PropertyTarget{[value = onProp]} +// setter of property prop : annotations.PropertySetterTarget{[value = set:]} +// main.DataClass -> +// class main.DataClass : annotations.ClassTarget{[value = onDataClass]} +// class main.DataClass : annotations.NoTargetAnnotation{[value = onDataClass]} +// getter of property constructorParam : annotations.PropertyGetterTarget{[value = get:]} +// parameter <set-?> : annotations.ValueParameterTarget{[value = onConstructorParam]} +// parameter constructorParam : annotations.NoTargetAnnotation{[value = onConstructorParam]} +// parameter constructorParam : annotations.ValueParameterTarget{[value = onConstructorParam]} +// property constructorParam : annotations.FieldTarget2{[value = field:]} +// property constructorParam : annotations.FieldTarget{[value = onConstructorParam]} +// property constructorParam : annotations.NoTargetAnnotation{[value = onConstructorParam]} +// property constructorParam : annotations.PropertyTarget{[value = onConstructorParam]} +// property constructorParam : annotations.ValueParameterAndFieldTarget{[value = valueParameterAndField]} +// setter of property constructorParam : annotations.PropertySetterTarget{[value = set:]} +// lib.DataClass -> +// class lib.DataClass : annotations.ClassTarget{[value = onDataClass]} +// class lib.DataClass : annotations.NoTargetAnnotation{[value = onDataClass]} +// getter of property constructorParam : annotations.PropertyGetterTarget{[value = get:]} +// parameter constructorParam : annotations.NoTargetAnnotation{[value = onConstructorParam]} +// property constructorParam : annotations.FieldTarget2{[value = field:]} +// property constructorParam : annotations.FieldTarget{[value = onConstructorParam]} +// property constructorParam : annotations.PropertyTarget{[value = onConstructorParam]} +// setter of property constructorParam : annotations.PropertySetterTarget{[value = set:]} +// END +// MODULE: annotations +// FILE: Annotations.kt +package annotations; +annotation class NoTargetAnnotation(val value:String) + +@Target(AnnotationTarget.FIELD) +annotation class FieldTarget(val value:String) + +@Target(AnnotationTarget.FIELD) +annotation class FieldTarget2(val value:String) + +@Target(AnnotationTarget.PROPERTY) +annotation class PropertyTarget(val value:String) + +@Target(AnnotationTarget.PROPERTY_SETTER) +annotation class PropertySetterTarget(val value:String) + +@Target(AnnotationTarget.PROPERTY_GETTER) +annotation class PropertyGetterTarget(val value:String) + +@Target(AnnotationTarget.CLASS) +annotation class ClassTarget(val value:String) + +@Target(AnnotationTarget.FUNCTION) +annotation class FunctionTarget(val value:String) + +@Target(AnnotationTarget.VALUE_PARAMETER) +annotation class ValueParameterTarget(val value:String) + +@Target(AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.FIELD) +annotation class ValueParameterAndFieldTarget(val value: String) + +// MODULE: lib(annotations) +// FILE: ClassInLib.kt +package lib; +import annotations.*; +@NoTargetAnnotation("onClass") +@ClassTarget("onClass") +class KotlinClass(@ValueParameterTarget("propInConstructor") val propInConstructor: String ) { + @NoTargetAnnotation("onProp") + @FieldTarget("onProp") + @PropertyTarget("onProp") + @set:PropertySetterTarget("set:") + @get:PropertyGetterTarget("get:") + @field:FieldTarget2("field:") + var prop : String = "" + + @NoTargetAnnotation("onMyFun") + @FunctionTarget("onMyFun") + fun myFun( + @NoTargetAnnotation("onParam1") + @ValueParameterTarget("onParam1") + param1: String, + @NoTargetAnnotation("onParam2") + @ValueParameterTarget("onParam2") + param2: Int + ) { + } +} + +@NoTargetAnnotation("onDataClass") +@ClassTarget("onDataClass") +class DataClass( + @NoTargetAnnotation("onConstructorParam") + @FieldTarget("onConstructorParam") + @PropertyTarget("onConstructorParam") + @set:PropertySetterTarget("set:") + @get:PropertyGetterTarget("get:") + @field:FieldTarget2("field:") + var constructorParam : String = "" +) +// FILE: lib/JavaClass.java +package lib; +import annotations.*; +public class JavaClass {} +// MODULE: main(lib, annotations) +// FILE: ClassInModule2.kt +package main; +import annotations.*; +@NoTargetAnnotation("onClass") +@ClassTarget("onClass") +class KotlinClass { + @NoTargetAnnotation("onProp") + @FieldTarget("onProp") + @PropertyTarget("onProp") + @set:PropertySetterTarget("set:") + @get:PropertyGetterTarget("get:") + @field:FieldTarget2("field:") + @setparam:ValueParameterTarget("onProp") + var prop : String = "" + @setparam:ValueParameterTarget("onPropSetter") + set + + @NoTargetAnnotation("onMyFun") + @FunctionTarget("onMyFun") + fun myFun( + @NoTargetAnnotation("onParam1") + @ValueParameterTarget("onParam1") + param1: String, + @NoTargetAnnotation("onParam2") + @ValueParameterTarget("onParam2") + param2: Int + ) { + } +} + +@NoTargetAnnotation("onDataClass") +@ClassTarget("onDataClass") +class DataClass( + @NoTargetAnnotation("onConstructorParam") + @FieldTarget("onConstructorParam") + @PropertyTarget("onConstructorParam") + @set:PropertySetterTarget("set:") + @get:PropertyGetterTarget("get:") + @field:FieldTarget2("field:") + @field:ValueParameterAndFieldTarget("valueParameterAndField") + @setparam:ValueParameterTarget("onConstructorParam") + @ValueParameterTarget("onConstructorParam") + var constructorParam : String = "" +) +// FILE: main/JavaClassInModule2.java +pakage main; +import annotations.*; +@NoTargetAnnotation +class JavaClassInMain { +} diff --git a/test-utils/testData/api/annotationOnConstructorParameter.kt b/test-utils/testData/api/annotationOnConstructorParameter.kt new file mode 100644 index 00000000..9122c287 --- /dev/null +++ b/test-utils/testData/api/annotationOnConstructorParameter.kt @@ -0,0 +1,31 @@ +/* + * Copyright 2020 Google LLC + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// TEST PROCESSOR: AnnotationOnConstructorParameterProcessor +// EXPECTED: +// Anno +// true +// true +// END +//FILE: a.kt +annotation class Anno + +data class Sample( + @Anno val fullName: String +) { + fun foo() = 0 +} diff --git a/test-utils/testData/api/annotationValue_java.kt b/test-utils/testData/api/annotationValue_java.kt new file mode 100644 index 00000000..448ea5e0 --- /dev/null +++ b/test-utils/testData/api/annotationValue_java.kt @@ -0,0 +1,77 @@ +/* + * Copyright 2020 Google LLC + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// WITH_RUNTIME +// TEST PROCESSOR: AnnotationArgumentProcessor +// EXPECTED: +// Str +// 42 +// Foo +// File +// Error type synthetic declaration +// Array +// @Foo +// @Suppress +// G +// ONE +// 31 +// [warning1, warning 2] +// END +// FILE: a.kt + +enum class RGB { + R, G, B +} + +annotation class Foo(val s: Int) + +annotation class Bar( + val argStr: String, + val argInt: Int, + val argClsUser: kotlin.reflect.KClass<*>, + val argClsLib: kotlin.reflect.KClass<*>, + val argClsLocal: kotlin.reflect.KClass<*>, + val argClsArray: kotlin.reflect.KClass<*>, + val argAnnoUser: Foo, + val argAnnoLib: Suppress, + val argEnum: RGB, + val argJavaNum: JavaEnum, + val argDef: Int = 31 +) + +// FILE: C.java + +@SuppressWarnings({"warning1", "warning 2"}) +class C { + +} +// FILE: JavaAnnotated.java +@Bar(argStr = "Str", + argInt = 40 + 2, + argClsUser = Foo.class, + argClsLib = java.io.File.class, + argClsLocal = Local.class, // intentional error type + argClsArray = kotlin.Array.class, + argAnnoUser = @Foo(s = 17), + argAnnoLib = @Suppress(names = {"name1", "name2"}), + argEnum = RGB.G, + argJavaNum = JavaEnum.ONE) +public class JavaAnnotated {} + +// FILE: JavaEnum.java + +enum JavaEnum { ONE, TWO, THREE } diff --git a/test-utils/testData/api/annotationValue_kt.kt b/test-utils/testData/api/annotationValue_kt.kt new file mode 100644 index 00000000..28c28772 --- /dev/null +++ b/test-utils/testData/api/annotationValue_kt.kt @@ -0,0 +1,73 @@ +/* + * Copyright 2020 Google LLC + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// WITH_RUNTIME +// TEST PROCESSOR: AnnotationArgumentProcessor +// EXPECTED: +// defaultInNested +// Str +// 42 +// Foo +// File +// Local +// Array +// @Foo +// @Suppress +// G +// ONE +// 31 +// Throws +// END +// FILE: a.kt + +enum class RGB { + R, G, B +} + +class ThrowsClass { + @Throws(Exception::class) + protected open fun throwsException() { + } +} + +annotation class Foo(val s: Int) { + annotation class Nested(val nestedDefault:String = "defaultInNested") +} + +annotation class Bar( + val argStr: String, + val argInt: Int, + val argClsUser: kotlin.reflect.KClass<*>, + val argClsLib: kotlin.reflect.KClass<*>, + val argClsLocal: kotlin.reflect.KClass<*>, + val argClsArray: kotlin.reflect.KClass<*>, + val argAnnoUser: Foo, + val argAnnoLib: Suppress, + val argEnum: RGB, + val argJavaNum: JavaEnum, + val argDef: Int = 31 +) + +fun Fun() { + @Foo.Nested + @Bar("Str", 40 + 2, Foo::class, java.io.File::class, Local::class, Array<String>::class, Foo(17), Suppress("name1", "name2"), RGB.G, JavaEnum.ONE) + class Local +} + +// FILE: JavaEnum.java + +enum JavaEnum { ONE, TWO, THREE } diff --git a/test-utils/testData/api/annotationWithArbitraryClassValue.kt b/test-utils/testData/api/annotationWithArbitraryClassValue.kt new file mode 100644 index 00000000..34e3fd2e --- /dev/null +++ b/test-utils/testData/api/annotationWithArbitraryClassValue.kt @@ -0,0 +1,38 @@ +/* + * Copyright 2020 Google LLC + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// TEST PROCESSOR: AnnotationArbitraryClassValueProcessor +// EXPECTED: +// User +// String, Company, IntArray, Array<User> +// END +// FILE: a.kt +package com.google.devtools.ksp.processor + +import kotlin.reflect.KClass + +annotation class ClassValueAnnotation( + val classValue: KClass<*>, + val classValues: Array<KClass<*>>) + +data class User(val id: Long, val name: String) +data class Company(val id: Long, val name: String, val location: String) + +@ClassValueAnnotation( + classValue = User::class, + classValues = [String::class, Company::class, IntArray::class, Array<User>::class] +) +class ClassValueAnnotated diff --git a/test-utils/testData/api/annotationWithArrayValue.kt b/test-utils/testData/api/annotationWithArrayValue.kt new file mode 100644 index 00000000..3637429f --- /dev/null +++ b/test-utils/testData/api/annotationWithArrayValue.kt @@ -0,0 +1,65 @@ +/* + * Copyright 2020 Google LLC + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// TEST PROCESSOR: AnnotationArrayValueProcessor +// EXPECTED: +// KotlinAnnotated +// KotlinAnnotation -> +// stringArray = [a, b, null, c] +// classArray = [Any, List<*>] +// JavaAnnotation -> +// stringArray = [x, y, null, z] +// classArray = [String, Long] +// JavaAnnotated +// KotlinAnnotation -> +// stringArray = [j-a, j-b, null, j-c] +// classArray = [Object, List<*>] +// JavaAnnotation -> +// stringArray = [j-x, j-y, null, j-z] +// classArray = [Integer, Character] +// END +// FILE: a.kt + +annotation class KotlinAnnotation(val stringArray: Array<String?>, val classArray: Array<KClass<*>?>) + +@KotlinAnnotation( + stringArray = ["a", "b", null, "c"], + classArray = [Any::class, List::class] +) +@JavaAnnotation( + stringArray = ["x", "y", null, "z"], + classArray = [String::class, Long::class] +) +class KotlinAnnotated + +// FILE: JavaAnnotation.java +public @interface JavaAnnotation { + String[] stringArray(); + Class[] classArray(); +} + +// FILE: JavaAnnotated.java +import java.util.*; +@KotlinAnnotation( + stringArray = {"j-a", "j-b", null, "j-c"}, + classArray = {Object.class, List.class} +) +@JavaAnnotation( + stringArray = {"j-x", "j-y", null, "j-z"}, + classArray = {Integer.class, Character.class} +) +public class JavaAnnotated { +} diff --git a/test-utils/testData/api/annotationWithDefault.kt b/test-utils/testData/api/annotationWithDefault.kt new file mode 100644 index 00000000..ae2d0945 --- /dev/null +++ b/test-utils/testData/api/annotationWithDefault.kt @@ -0,0 +1,155 @@ +/* + * Copyright 2020 Google LLC + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// TEST PROCESSOR: AnnotationDefaultValueProcessor +// EXPECTED: +// KotlinAnnotation -> a:debugKt:false,b:default:true,kClassValue:Array<Array<InnerObj>>:true,topLevelProp:foo:true,companionProp:companion:true +// JavaAnnotation -> debug:debug:false,withDefaultValue:OK:true,nested:@Nested:true +// JavaAnnotation2 -> y:y-kotlin:false,x:x-kotlin:false,z:z-default:true +// KotlinAnnotation2 -> y:y-kotlin:false,x:x-kotlin:false,z:z-default:true,kotlinEnumVal:VALUE_1:true +// KotlinAnnotationLib -> a:debugLibKt:false,b:defaultInLib:true,kClassValue:OtherKotlinAnnotation:true,topLevelProp:bar:true +// JavaAnnotationWithDefaults -> stringVal:foo:true,stringArrayVal:[x, y]:true,typeVal:HashMap<*, *>:true,typeArrayVal:[LinkedHashMap<*, *>]:true,intVal:3:true,intArrayVal:[1, 3, 5]:true,enumVal:JavaEnum.DEFAULT:true,enumArrayVal:[JavaEnum.VAL1, JavaEnum.VAL2]:true,localEnumVal:JavaAnnotationWithDefaults.LocalEnum.LOCAL1:true,otherAnnotationVal:@OtherAnnotation:true,otherAnnotationArrayVal:[@OtherAnnotation]:true,kotlinAnnotationLibVal:@OtherKotlinAnnotation:true +// KotlinAnnotationWithDefaults -> stringVal:foo:false,stringArrayVal:[x, y]:true,typeVal:HashMap<*, *>:true,typeArrayVal:[LinkedHashMap<*, *>]:true,intVal:3:true,intArrayVal:[1, 3, 5]:true,enumVal:JavaEnum.DEFAULT:true,enumArrayVal:[JavaEnum.VAL1, JavaEnum.VAL2]:true,otherAnnotationVal:@OtherAnnotation:true,otherAnnotationArrayVal:[@OtherAnnotation]:true,kotlinAnnotationLibVal:@OtherKotlinAnnotation:true +// KotlinAnnotation -> a:debugKt:false,b:default:true,kClassValue:Array<Array<InnerObj>>:true,topLevelProp:foo:true,companionProp:companion:true +// JavaAnnotation -> debug:debugJava2:false,withDefaultValue:OK:true,nested:@Nested:true +// JavaAnnotation2 -> y:y-java:false,x:x-java:false,z:z-default:true +// KotlinAnnotation2 -> y:y-java:false,x:x-java:false,z:z-default:true,kotlinEnumVal:VALUE_1:true +// END +// MODULE: lib +// FILE: Default.kt +const val Bar = "bar" +annotation class KotlinAnnotationLib(val a: String, val b: String = "defaultInLib", val kClassValue: kotlin.reflect.KClass<*> = OtherKotlinAnnotation::class, val topLevelProp:String = Bar) + +annotation class OtherKotlinAnnotation(val b: String = "otherKotlinAnnotationDefault") + +// FILE: JavaEnum.java +public enum JavaEnum { + VAL1, + VAL2, + DEFAULT +} + +// FILE: OtherAnnotation.java +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +@Retention(RetentionPolicy.RUNTIME) +public @interface OtherAnnotation { + String value(); +} + +// FILE: JavaAnnotationWithDefaults.java +import java.util.HashMap; +import java.util.LinkedHashMap; +public @interface JavaAnnotationWithDefaults { + String stringVal() default "foo"; + String[] stringArrayVal() default {"x", "y"}; + Class<?> typeVal() default HashMap.class; + Class[] typeArrayVal() default {LinkedHashMap.class}; + int intVal() default 3; + int[] intArrayVal() default {1, 3, 5}; + JavaEnum enumVal() default JavaEnum.DEFAULT; + JavaEnum[] enumArrayVal() default {JavaEnum.VAL1, JavaEnum.VAL2}; + LocalEnum localEnumVal() default LocalEnum.LOCAL1; + OtherAnnotation otherAnnotationVal() default @OtherAnnotation("def"); + OtherAnnotation[] otherAnnotationArrayVal() default {@OtherAnnotation("v1")}; + OtherKotlinAnnotation kotlinAnnotationLibVal() default @OtherKotlinAnnotation(b = "JavaAnnotationWithDefaults"); + enum LocalEnum { + LOCAL1, + LOCAL2 + } +} + +// FILE: KotlinAnnotationWithDefaults.kt +import kotlin.reflect.KClass + +annotation class KotlinAnnotationWithDefaults( + val stringVal: String = "foo", + val stringArrayVal: Array<String> = ["x", "y"], + val typeVal: KClass<*> = java.util.HashMap::class, + val typeArrayVal: Array<KClass<*>> = [java.util.LinkedHashMap::class], + val intVal: Int = 3, + val intArrayVal: IntArray = [1, 3, 5], + val enumVal: JavaEnum = JavaEnum.DEFAULT, + val enumArrayVal: Array<JavaEnum> = [JavaEnum.VAL1, JavaEnum.VAL2], + val otherAnnotationVal: OtherAnnotation = OtherAnnotation("def"), + val otherAnnotationArrayVal: Array<OtherAnnotation> = [OtherAnnotation("v1")], + val kotlinAnnotationLibVal: OtherKotlinAnnotation = OtherKotlinAnnotation("1") +) +// MODULE: main(lib) +// FILE: Const.kt +const val Foo = "foo" +const val DebugKt = "debugKt" + +class Container { + companion object { + const val comp = "companion" + } +} + +// FILE: a.kt +import test.KotlinEnum +import Container.Companion.comp + + +annotation class KotlinAnnotation(val a: String, val b:String = "default", val kClassValue: kotlin.reflect.KClass<*> = Array<Array<InnerObj>>::class, val topLevelProp: String = Foo, val companionProp: String = comp) { + object InnerObj +} +annotation class KotlinAnnotation2(val x: String, val y:String = "y-default", val z:String = "z-default", val kotlinEnumVal: KotlinEnum = KotlinEnum.VALUE_1) + +@KotlinAnnotation(DebugKt) +@JavaAnnotation("debug") +@JavaAnnotation2(y="y-kotlin", x="x-kotlin") +@KotlinAnnotation2(y="y-kotlin", x="x-kotlin") +@KotlinAnnotationLib("debugLibKt") +@JavaAnnotationWithDefaults +@KotlinAnnotationWithDefaults(stringVal="foo") //set the value to the same as the default +class A + +// FILE: test.kt +package test + +enum class KotlinEnum { + VALUE_1, + VALUE2 +} + +// FILE: JavaAnnotation.java +public @interface JavaAnnotation { + String debug(); + String withDefaultValue() default "OK"; + @interface Nested { + String nestedX() default "nested"; + } + Nested nested() default @Nested(); +} + +// FILE: JavaAnnotation2.java +public @interface JavaAnnotation2 { + String x() default "x-default"; + String y() default "y-default"; + String z() default "z-default"; +} + +// FILE: JavaAnnotated.java + +@KotlinAnnotation(ConstKt.DebugKt) +@JavaAnnotation("debugJava2") +@JavaAnnotation2(y="y-java", x="x-java") +@KotlinAnnotation2(y="y-java", x="x-java") +public class JavaAnnotated { + +} diff --git a/test-utils/testData/api/annotationWithDefaultValues.kt b/test-utils/testData/api/annotationWithDefaultValues.kt new file mode 100644 index 00000000..94a21dae --- /dev/null +++ b/test-utils/testData/api/annotationWithDefaultValues.kt @@ -0,0 +1,155 @@ +/* + * Copyright 2022 Google LLC + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// TEST PROCESSOR: AnnotationDefaultValuesProcessor +// EXPECTED: +// KotlinAnnotation -> b:default,kClassValue:Array<Array<InnerObj>>,topLevelProp:foo,companionProp:companion +// JavaAnnotation -> withDefaultValue:OK,nested:@Nested +// JavaAnnotation2 -> x:x-default,y:y-default,z:z-default +// KotlinAnnotation2 -> y:y-default,z:z-default,kotlinEnumVal:VALUE_1 +// KotlinAnnotationLib -> b:defaultInLib,kClassValue:OtherKotlinAnnotation,topLevelProp:bar +// JavaAnnotationWithDefaults -> stringVal:foo,stringArrayVal:[x, y],typeVal:HashMap<*, *>,typeArrayVal:[LinkedHashMap<*, *>],intVal:3,intArrayVal:[1, 3, 5],enumVal:JavaEnum.DEFAULT,enumArrayVal:[JavaEnum.VAL1, JavaEnum.VAL2],localEnumVal:JavaAnnotationWithDefaults.LocalEnum.LOCAL1,otherAnnotationVal:@OtherAnnotation,otherAnnotationArrayVal:[@OtherAnnotation],kotlinAnnotationLibVal:@OtherKotlinAnnotation +// KotlinAnnotationWithDefaults -> stringVal:foo,stringArrayVal:[x, y],typeVal:HashMap<*, *>,typeArrayVal:[LinkedHashMap<*, *>],intVal:3,intArrayVal:[1, 3, 5],enumVal:JavaEnum.DEFAULT,enumArrayVal:[JavaEnum.VAL1, JavaEnum.VAL2],otherAnnotationVal:@OtherAnnotation,otherAnnotationArrayVal:[@OtherAnnotation],kotlinAnnotationLibVal:@OtherKotlinAnnotation +// KotlinAnnotation -> b:default,kClassValue:Array<Array<InnerObj>>,topLevelProp:foo,companionProp:companion +// JavaAnnotation -> withDefaultValue:OK,nested:@Nested +// JavaAnnotation2 -> x:x-default,y:y-default,z:z-default +// KotlinAnnotation2 -> y:y-default,z:z-default,kotlinEnumVal:VALUE_1 +// END +// MODULE: lib +// FILE: Default.kt +const val Bar = "bar" +annotation class KotlinAnnotationLib(val a: String, val b: String = "defaultInLib", val kClassValue: kotlin.reflect.KClass<*> = OtherKotlinAnnotation::class, val topLevelProp:String = Bar) + +annotation class OtherKotlinAnnotation(val b: String = "otherKotlinAnnotationDefault") + +// FILE: JavaEnum.java +public enum JavaEnum { + VAL1, + VAL2, + DEFAULT +} + +// FILE: OtherAnnotation.java +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +@Retention(RetentionPolicy.RUNTIME) +public @interface OtherAnnotation { + String value(); +} + +// FILE: JavaAnnotationWithDefaults.java +import java.util.HashMap; +import java.util.LinkedHashMap; +public @interface JavaAnnotationWithDefaults { + String stringVal() default "foo"; + String[] stringArrayVal() default {"x", "y"}; + Class<?> typeVal() default HashMap.class; + Class[] typeArrayVal() default {LinkedHashMap.class}; + int intVal() default 3; + int[] intArrayVal() default {1, 3, 5}; + JavaEnum enumVal() default JavaEnum.DEFAULT; + JavaEnum[] enumArrayVal() default {JavaEnum.VAL1, JavaEnum.VAL2}; + LocalEnum localEnumVal() default LocalEnum.LOCAL1; + OtherAnnotation otherAnnotationVal() default @OtherAnnotation("def"); + OtherAnnotation[] otherAnnotationArrayVal() default {@OtherAnnotation("v1")}; + OtherKotlinAnnotation kotlinAnnotationLibVal() default @OtherKotlinAnnotation(b = "JavaAnnotationWithDefaults"); + enum LocalEnum { + LOCAL1, + LOCAL2 + } +} + +// FILE: KotlinAnnotationWithDefaults.kt +import kotlin.reflect.KClass + +annotation class KotlinAnnotationWithDefaults( + val stringVal: String = "foo", + val stringArrayVal: Array<String> = ["x", "y"], + val typeVal: KClass<*> = java.util.HashMap::class, + val typeArrayVal: Array<KClass<*>> = [java.util.LinkedHashMap::class], + val intVal: Int = 3, + val intArrayVal: IntArray = [1, 3, 5], + val enumVal: JavaEnum = JavaEnum.DEFAULT, + val enumArrayVal: Array<JavaEnum> = [JavaEnum.VAL1, JavaEnum.VAL2], + val otherAnnotationVal: OtherAnnotation = OtherAnnotation("def"), + val otherAnnotationArrayVal: Array<OtherAnnotation> = [OtherAnnotation("v1")], + val kotlinAnnotationLibVal: OtherKotlinAnnotation = OtherKotlinAnnotation("1") +) +// MODULE: main(lib) +// FILE: Const.kt +const val Foo = "foo" +const val DebugKt = "debugKt" + +class Container { + companion object { + const val comp = "companion" + } +} + +// FILE: a.kt +import test.KotlinEnum +import Container.Companion.comp + + +annotation class KotlinAnnotation(val a: String, val b:String = "default", val kClassValue: kotlin.reflect.KClass<*> = Array<Array<InnerObj>>::class, val topLevelProp: String = Foo, val companionProp: String = comp) { + object InnerObj +} +annotation class KotlinAnnotation2(val x: String, val y:String = "y-default", val z:String = "z-default", val kotlinEnumVal: KotlinEnum = KotlinEnum.VALUE_1) + +@KotlinAnnotation(DebugKt) +@JavaAnnotation("debug") +@JavaAnnotation2(y="y-kotlin", x="x-kotlin") +@KotlinAnnotation2(y="y-kotlin", x="x-kotlin") +@KotlinAnnotationLib("debugLibKt") +@JavaAnnotationWithDefaults +@KotlinAnnotationWithDefaults +class A + +// FILE: test.kt +package test + +enum class KotlinEnum { + VALUE_1, + VALUE2 +} + +// FILE: JavaAnnotation.java +public @interface JavaAnnotation { + String debug(); + String withDefaultValue() default "OK"; + @interface Nested { + String nestedX() default "nested"; + } + Nested nested() default @Nested(); +} + +// FILE: JavaAnnotation2.java +public @interface JavaAnnotation2 { + String x() default "x-default"; + String y() default "y-default"; + String z() default "z-default"; +} + +// FILE: JavaAnnotated.java + +@KotlinAnnotation(ConstKt.DebugKt) +@JavaAnnotation("debugJava2") +@JavaAnnotation2(y="y-java", x="x-java") +@KotlinAnnotation2(y="y-java", x="x-java") +public class JavaAnnotated { + +} diff --git a/test-utils/testData/api/annotationWithJavaTypeValue.kt b/test-utils/testData/api/annotationWithJavaTypeValue.kt new file mode 100644 index 00000000..98610371 --- /dev/null +++ b/test-utils/testData/api/annotationWithJavaTypeValue.kt @@ -0,0 +1,49 @@ +/* + * Copyright 2020 Google LLC + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// TEST PROCESSOR: AnnotationJavaTypeValueProcessor +// EXPECTED: +// JavaAnnotated +// JavaAnnotation -> +// primitives = [Character, Boolean, Byte, Short, Integer, Long, Float, Double] +// objects = [Character, Boolean, Byte, Short, Integer, Long, Float, Double] +// primitiveArrays = [Array<Character>, Array<Boolean>, Array<Byte>, Array<Short>, Array<Integer>, Array<Long>, Array<Float>, Array<Double>] +// objectArrays = [Array<Character>, Array<Boolean>, Array<Byte>, Array<Short>, Array<Integer>, Array<Long>, Array<Float>, Array<Double>, Array<String>, Array<Object>] +// END +// FILE: a.kt + + +// FILE: JavaAnnotation.java + +public @ interface JavaAnnotation { + Class[] primitives(); // PsiPrimitiveType + Class[] objects(); // PsiType + Class[] primitiveArrays(); // PsiArrayType + Class[] objectArrays(); // PsiArrayType +} + +// FILE: JavaAnnotated.java + +import java.util.*; + +@JavaAnnotation( + primitives = { char.class, boolean .class, byte.class, short.class, int.class, long.class, float.class, double.class }, + objects = { Character.class, Boolean .class, Byte.class, Short.class, Integer.class, Long.class, Float.class, Double.class }, + primitiveArrays = { char[].class, boolean [].class, byte[].class, short[].class, int[].class, long[].class, float[].class, double[].class }, + objectArrays = { Character[].class, Boolean [].class, Byte[].class, Short[].class, Integer[].class, Long[].class, Float[].class, Double[].class, String[].class, Object[].class } +) +public class JavaAnnotated { +} diff --git a/test-utils/testData/api/asMemberOf.kt b/test-utils/testData/api/asMemberOf.kt new file mode 100644 index 00000000..d96346cc --- /dev/null +++ b/test-utils/testData/api/asMemberOf.kt @@ -0,0 +1,188 @@ +/* + * Copyright 2022 Google LLC + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// WITH_RUNTIME +// TEST PROCESSOR: AsMemberOfProcessor +// EXPECTED: +// Child1!! +// intType: kotlin.Int!! +// baseTypeArg1: kotlin.Int!! +// baseTypeArg2: kotlin.String? +// typePair: kotlin.Pair!!<kotlin.String?, kotlin.Int!!> +// errorType: <Error>? +// extensionProperty: kotlin.String? +// returnInt: () -> kotlin.Int!! +// returnArg1: () -> kotlin.Int!! +// returnArg1Nullable: () -> kotlin.Int? +// returnArg2: () -> kotlin.String? +// returnArg2Nullable: () -> kotlin.String? +// receiveArgs: (kotlin.Int?, kotlin.Int!!, kotlin.String?) -> kotlin.Unit!! +// receiveArgsPair: (kotlin.Pair!!<kotlin.Int!!, kotlin.String?>, kotlin.Pair?<kotlin.Int?, kotlin.String?>) -> kotlin.Unit!! +// functionArgType: <BaseTypeArg1: kotlin.Any?>(Base.functionArgType.BaseTypeArg1?) -> kotlin.String? +// functionArgTypeWithBounds: <in T: kotlin.Int!!>(Base.functionArgTypeWithBounds.T?) -> kotlin.String? +// extensionFunction: kotlin.Int!!.() -> kotlin.Int? +// Child2!!<kotlin.Any?> +// intType: kotlin.Int!! +// baseTypeArg1: kotlin.Any? +// baseTypeArg2: kotlin.Any? +// typePair: kotlin.Pair!!<kotlin.Any?, kotlin.Any?> +// errorType: <Error>? +// extensionProperty: kotlin.Any? +// returnInt: () -> kotlin.Int!! +// returnArg1: () -> kotlin.Any? +// returnArg1Nullable: () -> kotlin.Any? +// returnArg2: () -> kotlin.Any? +// returnArg2Nullable: () -> kotlin.Any? +// receiveArgs: (kotlin.Int?, kotlin.Any?, kotlin.Any?) -> kotlin.Unit!! +// receiveArgsPair: (kotlin.Pair!!<kotlin.Any?, kotlin.Any?>, kotlin.Pair?<kotlin.Any?, kotlin.Any?>) -> kotlin.Unit!! +// functionArgType: <BaseTypeArg1: kotlin.Any?>(Base.functionArgType.BaseTypeArg1?) -> kotlin.Any? +// functionArgTypeWithBounds: <in T: kotlin.Any?>(Base.functionArgTypeWithBounds.T?) -> kotlin.Any? +// extensionFunction: kotlin.Any?.() -> kotlin.Any? +// Child2!!<kotlin.String!!> +// intType: kotlin.Int!! +// baseTypeArg1: kotlin.String!! +// baseTypeArg2: kotlin.String? +// typePair: kotlin.Pair!!<kotlin.String?, kotlin.String!!> +// errorType: <Error>? +// extensionProperty: kotlin.String? +// returnInt: () -> kotlin.Int!! +// returnArg1: () -> kotlin.String!! +// returnArg1Nullable: () -> kotlin.String? +// returnArg2: () -> kotlin.String? +// returnArg2Nullable: () -> kotlin.String? +// receiveArgs: (kotlin.Int?, kotlin.String!!, kotlin.String?) -> kotlin.Unit!! +// receiveArgsPair: (kotlin.Pair!!<kotlin.String!!, kotlin.String?>, kotlin.Pair?<kotlin.String?, kotlin.String?>) -> kotlin.Unit!! +// functionArgType: <BaseTypeArg1: kotlin.Any?>(Base.functionArgType.BaseTypeArg1?) -> kotlin.String? +// functionArgTypeWithBounds: <in T: kotlin.String!!>(Base.functionArgTypeWithBounds.T?) -> kotlin.String? +// extensionFunction: kotlin.String!!.() -> kotlin.String? +// NotAChild!! +// intType: java.lang.IllegalArgumentException: NotAChild is not a sub type of the class/interface that contains `intType` (Base) +// baseTypeArg1: java.lang.IllegalArgumentException: NotAChild is not a sub type of the class/interface that contains `baseTypeArg1` (Base) +// baseTypeArg2: java.lang.IllegalArgumentException: NotAChild is not a sub type of the class/interface that contains `baseTypeArg2` (Base) +// typePair: java.lang.IllegalArgumentException: NotAChild is not a sub type of the class/interface that contains `typePair` (Base) +// errorType: java.lang.IllegalArgumentException: NotAChild is not a sub type of the class/interface that contains `errorType` (Base) +// extensionProperty: java.lang.IllegalArgumentException: NotAChild is not a sub type of the class/interface that contains `extensionProperty` (Base) +// returnInt: java.lang.IllegalArgumentException: NotAChild is not a sub type of the class/interface that contains `returnInt` (Base) +// returnArg1: java.lang.IllegalArgumentException: NotAChild is not a sub type of the class/interface that contains `returnArg1` (Base) +// returnArg1Nullable: java.lang.IllegalArgumentException: NotAChild is not a sub type of the class/interface that contains `returnArg1Nullable` (Base) +// returnArg2: java.lang.IllegalArgumentException: NotAChild is not a sub type of the class/interface that contains `returnArg2` (Base) +// returnArg2Nullable: java.lang.IllegalArgumentException: NotAChild is not a sub type of the class/interface that contains `returnArg2Nullable` (Base) +// receiveArgs: java.lang.IllegalArgumentException: NotAChild is not a sub type of the class/interface that contains `receiveArgs` (Base) +// receiveArgsPair: java.lang.IllegalArgumentException: NotAChild is not a sub type of the class/interface that contains `receiveArgsPair` (Base) +// functionArgType: java.lang.IllegalArgumentException: NotAChild is not a sub type of the class/interface that contains `functionArgType` (Base) +// functionArgTypeWithBounds: java.lang.IllegalArgumentException: NotAChild is not a sub type of the class/interface that contains `functionArgTypeWithBounds` (Base) +// extensionFunction: java.lang.IllegalArgumentException: NotAChild is not a sub type of the class/interface that contains `extensionFunction` (Base) +// List#get +// listOfStrings: (kotlin.Int!!) -> kotlin.String!! +// setOfStrings: java.lang.IllegalArgumentException: Set<String> is not a sub type of the class/interface that contains `get` (List) +// Set#contains +// listOfStrings: java.lang.IllegalArgumentException: List<String> is not a sub type of the class/interface that contains `contains` (Set) +// setOfStrings: (kotlin.String!!) -> kotlin.Boolean!! +// JavaChild1!! +// intType: kotlin.Int!! +// typeArg1: kotlin.String +// typeArg2: kotlin.Int +// errorType: <Error>? +// returnArg1: () -> kotlin.Int +// receiveArgs: (kotlin.String, kotlin.Int, kotlin.Int!!) -> kotlin.Unit!! +// methodArgType: <BaseTypeArg1: kotlin.Any>(JavaBase.methodArgType.BaseTypeArg1, kotlin.Int) -> kotlin.Unit!! +// methodArgTypeWithBounds: <T: kotlin.String>(JavaBase.methodArgTypeWithBounds.T) -> kotlin.Unit!! +// fileLevelFunction: java.lang.IllegalArgumentException: Cannot call asMemberOf with a function that is not declared in a class or an interface +// fileLevelExtensionFunction: java.lang.IllegalArgumentException: Cannot call asMemberOf with a function that is not declared in a class or an interface +// fileLevelProperty: java.lang.IllegalArgumentException: Cannot call asMemberOf with a property that is not declared in a class or an interface +// errorType: (<Error>?) -> <Error>? +// expected comparison failures +// <BaseTypeArg1: kotlin.Any?>(Base.functionArgType.BaseTypeArg1?) -> kotlin.String? +// () -> kotlin.Int!! +// () -> kotlin.Int!! +// (kotlin.Int!!) -> kotlin.Unit!! +// END +// FILE: Input.kt +open class Base<BaseTypeArg1, BaseTypeArg2> { + val intType: Int = 0 + val baseTypeArg1: BaseTypeArg1 = TODO() + val baseTypeArg2: BaseTypeArg2 = TODO() + val typePair: Pair<BaseTypeArg2, BaseTypeArg1> = TODO() + val errorType: NonExistType = TODO() + fun returnInt():Int = TODO() + fun returnArg1(): BaseTypeArg1 = TODO() + fun returnArg1Nullable(): BaseTypeArg1? = TODO() + fun returnArg2(): BaseTypeArg2 = TODO() + fun returnArg2Nullable(): BaseTypeArg2? = TODO() + fun receiveArgs(intArg:Int?, arg1: BaseTypeArg1, arg2:BaseTypeArg2):Unit = TODO() + fun receiveArgsPair( + pairs: Pair<BaseTypeArg1, BaseTypeArg2>, + pairNullable: Pair<BaseTypeArg1?, BaseTypeArg2?>?, + ):Unit = TODO() + // intentional type argument name conflict here to ensure it does not get replaced by mistake + fun <BaseTypeArg1> functionArgType(t:BaseTypeArg1?): BaseTypeArg2 = TODO() + fun <in T: BaseTypeArg1> functionArgTypeWithBounds(t:T?): BaseTypeArg2 = TODO() + fun BaseTypeArg1.extensionFunction():BaseTypeArg1? = TODO() + val BaseTypeArg2.extensionProperty:BaseTypeArg2? = TODO() +} + +open class Child1 : Base<Int, String?>() { +} + +open class Child2<ChildTypeArg1> : Base<ChildTypeArg1, ChildTypeArg1?>() { +} + +class NotAChild +val child2WithString: Child2<String> = TODO() +val listOfStrings: List<String> = TODO() +val setOfStrings: Set<String> = TODO() + +fun <T>List<T>.fileLevelExtensionFunction():Unit = TODO() +fun <T>fileLevelFunction():Unit = TODO() +val fileLevelProperty:Int = 3 +val errorType: NonExistingType + +interface KotlinInterface { + val x:Int + var y:Int +} + +// FILE: JavaInput.java +class JavaBase<BaseTypeArg1, BaseTypeArg2> { + int intType; + BaseTypeArg1 typeArg1; + BaseTypeArg2 typeArg2; + NonExist errorType; + BaseTypeArg2 returnArg1() { + return null; + } + void receiveArgs(BaseTypeArg1 arg1, BaseTypeArg2 arg2, int intArg) { + } + <BaseTypeArg1> void methodArgType(BaseTypeArg1 arg1, BaseTypeArg2 arg2) { + } + <T extends BaseTypeArg1> void methodArgTypeWithBounds(T arg1) { + } +} + +class JavaChild1 extends JavaBase<String, Integer> { +} + +class JavaImpl implements KotlinInterface { + public int getX() { + return 1; + } + public int getY() { + return 1; + } + public void setY(int value) { + } +} diff --git a/test-utils/testData/api/backingFields.kt b/test-utils/testData/api/backingFields.kt new file mode 100644 index 00000000..30a681de --- /dev/null +++ b/test-utils/testData/api/backingFields.kt @@ -0,0 +1,364 @@ +/* + * Copyright 2021 Google LLC + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// WITH_RUNTIME +// TEST PROCESSOR: BackingFieldProcessor +// EXPECTED: +// lib.BaseClass.abstractProp_willBeBacked: false +// lib.BaseClass.abstractProp_wontBeBacked: false +// lib.BaseClass.lateinit_var_1: true +// lib.BaseClass.lateinit_var_2: true +// lib.BaseClass.notOverriddenAbstractProp: true +// lib.BaseClass.overriddenBaseProp_willBeBacked: true +// lib.BaseClass.overriddenBaseProp_wontBeBacked: true +// lib.ChildClass.abstractProp_willBeBacked: true +// lib.ChildClass.abstractProp_wontBeBacked: false +// lib.ChildClass.interfaceProp_willBeBacked: true +// lib.ChildClass.interfaceProp_wontBeBacked: false +// lib.ChildClass.lateinit_var_1: false +// lib.ChildClass.lateinit_var_2: true +// lib.ChildClass.lateinit_var_3: true +// lib.ChildClass.overriddenBaseProp_willBeBacked: true +// lib.ChildClass.overriddenBaseProp_wontBeBacked: false +// lib.ConstructorSetProp.propSetInConstructor: true +// lib.DataClass.value_Param: true +// lib.DataClass.variable_Param: true +// lib.JavaClass.javaField: true +// lib.JavaClass.javaFieldWithAccessors: true +// lib.MyInterface.interfaceProp_willBeBacked: false +// lib.MyInterface.interfaceProp_wontBeBacked: false +// lib.MyInterface.lateinit_var_3: false +// lib.NormalClass.Companion.companionVar: true +// lib.NormalClass.Companion.companion_noBackingVal: false +// lib.NormalClass.Companion.companion_noBackingVar: false +// lib.NormalClass.Companion.companion_withBackingAndGetter: true +// lib.NormalClass.Companion.staticVar: true +// lib.NormalClass.Companion.static_noBackingVal: false +// lib.NormalClass.Companion.static_noBackingVar: false +// lib.NormalClass.Companion.static_withBackingAndGetter: true +// lib.NormalClass.jvmField_withBacking: true +// lib.NormalClass.lateinit_var: true +// lib.NormalClass.value: true +// lib.NormalClass.value_Param: true +// lib.NormalClass.value_noBacking: false +// lib.NormalClass.value_withBacking: true +// lib.NormalClass.variable: true +// lib.NormalClass.variable_Param: true +// lib.NormalClass.variable_noBacking: false +// lib.NormalClass.variable_withBacking: true +// lib.lateinit_var: true +// lib.value: true +// lib.value_noBacking: false +// lib.value_withBacking: true +// lib.variable: true +// lib.variable_noBacking: false +// lib.variable_withBacking: true +// main.BaseClass.abstractProp_willBeBacked: false +// main.BaseClass.abstractProp_wontBeBacked: false +// main.BaseClass.lateinit_var_1: true +// main.BaseClass.lateinit_var_2: true +// main.BaseClass.notOverriddenAbstractProp: true +// main.BaseClass.overriddenBaseProp_willBeBacked: true +// main.BaseClass.overriddenBaseProp_wontBeBacked: true +// main.ChildClass.abstractProp_willBeBacked: true +// main.ChildClass.abstractProp_wontBeBacked: false +// main.ChildClass.interfaceProp_willBeBacked: true +// main.ChildClass.interfaceProp_wontBeBacked: false +// main.ChildClass.lateinit_var_1: false +// main.ChildClass.lateinit_var_2: true +// main.ChildClass.lateinit_var_3: true +// main.ChildClass.overriddenBaseProp_willBeBacked: true +// main.ChildClass.overriddenBaseProp_wontBeBacked: false +// main.ConstructorSetProp.propSetInConstructor: true +// main.DataClass.value_Param: true +// main.DataClass.variable_Param: true +// main.JavaClass.javaField: true +// main.JavaClass.javaFieldWithAccessors: true +// main.MyInterface.interfaceProp_willBeBacked: false +// main.MyInterface.interfaceProp_wontBeBacked: false +// main.MyInterface.lateinit_var_3: false +// main.NormalClass.Companion.companionVar: true +// main.NormalClass.Companion.companion_noBackingVal: false +// main.NormalClass.Companion.companion_noBackingVar: false +// main.NormalClass.Companion.companion_withBackingAndGetter: true +// main.NormalClass.Companion.staticVar: true +// main.NormalClass.Companion.static_noBackingVal: false +// main.NormalClass.Companion.static_noBackingVar: false +// main.NormalClass.Companion.static_withBackingAndGetter: true +// main.NormalClass.lateinit_var: true +// main.NormalClass.value: true +// main.NormalClass.value_Param: true +// main.NormalClass.value_noBacking: false +// main.NormalClass.value_withBacking: true +// main.NormalClass.variable: true +// main.NormalClass.variable_Param: true +// main.NormalClass.variable_noBacking: false +// main.NormalClass.variable_withBacking: true +// main.lateinit_var: true +// main.value: true +// main.value_noBacking: false +// main.value_withBacking: true +// main.variable: true +// main.variable_noBacking: false +// main.variable_withBacking: true +// END + +// MODULE: lib +// FILE: lib.kt +package lib + +val value: String = "" +var variable: String = "" +val value_noBacking: String + get() = "aa" +var variable_noBacking: String + get() = "aa" + set(value) {} +val value_withBacking: String = "" + get() = field +var variable_withBacking: String? = null + get() = field +lateinit var lateinit_var: String + +data class DataClass( + val value_Param: String, + var variable_Param: String +) + +class NormalClass( + val value_Param: String, + var variable_Param: String, + normalParam: String +) { + val value: String = "" + var variable: String = "" + val value_noBacking: String + get() = "aa" + var variable_noBacking: String + get() = "aa" + set(value) {} + val value_withBacking: String = "" + get() = field + var variable_withBacking: String? = null + get() = field + val jvmField_withBacking: String = "" + lateinit var lateinit_var: String + + companion object { + @JvmStatic + var staticVar: String = "" + @JvmStatic + val static_withBackingAndGetter: String = "" + get() = field + @JvmStatic + val static_noBackingVal: String + get() = "" + @JvmStatic + var static_noBackingVar: String + get() = "" + set(value) {} + var companionVar: String = "" + val companion_withBackingAndGetter: String = "" + get() = field + @JvmStatic + val companion_noBackingVal: String + get() = "" + @JvmStatic + var companion_noBackingVar: String + get() = "" + set(value) {} + } +} + +abstract class BaseClass { + open val overriddenBaseProp_willBeBacked: String = "" + open val overriddenBaseProp_wontBeBacked: String = "" + open val notOverriddenAbstractProp: String = "" + abstract val abstractProp_willBeBacked: String + abstract val abstractProp_wontBeBacked: String + open lateinit var lateinit_var_1: String + open lateinit var lateinit_var_2: String +} + +interface MyInterface { + val interfaceProp_willBeBacked: String + val interfaceProp_wontBeBacked: String + var lateinit_var_3: String +} + +class ChildClass: BaseClass(), MyInterface { + override val overriddenBaseProp_willBeBacked: String = "" + override val overriddenBaseProp_wontBeBacked: String + get() = "" + override val abstractProp_willBeBacked: String = "" + override val abstractProp_wontBeBacked: String + get() = "" + override val interfaceProp_willBeBacked: String = "" + override val interfaceProp_wontBeBacked: String + get() = "" + override var lateinit_var_1: String + get() = "" + set(v: String) = Unit + override var lateinit_var_2: String = "" + override lateinit var lateinit_var_3: String +} + +class ConstructorSetProp { + private val propSetInConstructor: Boolean + constructor(propSetInConstructor: Boolean) { + this.propSetInConstructor = propSetInConstructor + } +} + +// FILE: lib/JavaClass.java +package lib; +public class JavaClass { + private String javaField; + private String javaFieldWithAccessors; + + public String getJavaFieldWithAccessors() + { return ""; } + public void setJavaFieldWithAccessors(String value ) + {} + + public String getJavaAccessorWithoutField() + { return ""; } + public void setJavaAccessorWithoutField(String value ) + {} +} + +// MODULE: main(lib) +// FILE: main.kt +package main +val value: String = "" +var variable: String = "" +val value_noBacking: String + get() = "aa" +var variable_noBacking: String + get() = "aa" + set(value) {} +val value_withBacking: String = "" + get() = field +var variable_withBacking: String? = null + get() = field +lateinit var lateinit_var: String + +data class DataClass( + val value_Param: String, + var variable_Param: String +) + +class NormalClass( + val value_Param: String, + var variable_Param: String, + normalParam: String +) { + val value: String = "" + var variable: String = "" + val value_noBacking: String + get() = "aa" + var variable_noBacking: String + get() = "aa" + set(value) {} + val value_withBacking: String = "" + get() = field + var variable_withBacking: String? = null + get() = field + lateinit var lateinit_var: String + + companion object { + @JvmStatic + var staticVar: String = "" + @JvmStatic + val static_withBackingAndGetter: String = "" + get() = field + @JvmStatic + val static_noBackingVal: String + get() = "" + @JvmStatic + var static_noBackingVar: String + get() = "" + set(value) {} + var companionVar: String = "" + val companion_withBackingAndGetter: String = "" + get() = field + @JvmStatic + val companion_noBackingVal: String + get() = "" + @JvmStatic + var companion_noBackingVar: String + get() = "" + set(value) {} + } +} + +abstract class BaseClass { + open val overriddenBaseProp_willBeBacked: String = "" + open val overriddenBaseProp_wontBeBacked: String = "" + open val notOverriddenAbstractProp: String = "" + abstract val abstractProp_willBeBacked: String + abstract val abstractProp_wontBeBacked: String + open lateinit var lateinit_var_1: String + open lateinit var lateinit_var_2: String +} + +interface MyInterface { + val interfaceProp_willBeBacked: String + val interfaceProp_wontBeBacked: String + var lateinit_var_3: String +} + +class ChildClass: BaseClass(), MyInterface { + override val overriddenBaseProp_willBeBacked: String = "" + override val overriddenBaseProp_wontBeBacked: String + get() = "" + override val abstractProp_willBeBacked: String = "" + override val abstractProp_wontBeBacked: String + get() = "" + override val interfaceProp_willBeBacked: String = "" + override val interfaceProp_wontBeBacked: String + get() = "" + override var lateinit_var_1: String + get() = "" + set(v: String) = Unit + override var lateinit_var_2: String = "" + override lateinit var lateinit_var_3: String +} + +class ConstructorSetProp { + private val propSetInConstructor: Boolean + constructor(propSetInConstructor: Boolean) { + this.propSetInConstructor = propSetInConstructor + } +} + +// FILE: main/JavaClass.java +package main; +public class JavaClass { + private String javaField; + private String javaFieldWithAccessors; + + public String getJavaFieldWithAccessors() + { return ""; } + public void setJavaFieldWithAccessors(String value ) + {} + + public String getJavaAccessorWithoutField() + { return ""; } + public void setJavaAccessorWithoutField(String value ) + {} +} diff --git a/test-utils/testData/api/builtInTypes.kt b/test-utils/testData/api/builtInTypes.kt new file mode 100644 index 00000000..37ae4519 --- /dev/null +++ b/test-utils/testData/api/builtInTypes.kt @@ -0,0 +1,54 @@ +/* + * Copyright 2020 Google LLC + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// WITH_RUNTIME +// TEST PROCESSOR: BuiltInTypesProcessor +// EXPECTED: +// Annotation: OK +// Any: OK +// Array<*>: OK +// Boolean: OK +// Byte: OK +// Char: OK +// Double: OK +// Float: OK +// Int: OK +// Iterable<*>: OK +// Long: OK +// Nothing: OK +// Number: OK +// Short: OK +// String: OK +// Unit: OK +// END + +val a: Any = 0 +val b: Unit = Unit +val c: Number = 0 +val d: Byte = 0 +val e: Short = 0 +val f: Int = 0 +val g: Long = 0 +val h: Float = 0.0f +val i: Double = 0.0 +val j: Char = '0' +val k: Boolean = false +val l: String = "" +val m: Iterable<*> = listOf<Any>() +val n: Annotation = object: Annotation {} +fun foo(): Nothing = throw Error() +val o: Array<*> = arrayOf<Any>() diff --git a/test-utils/testData/api/checkOverride.kt b/test-utils/testData/api/checkOverride.kt new file mode 100644 index 00000000..435395bd --- /dev/null +++ b/test-utils/testData/api/checkOverride.kt @@ -0,0 +1,189 @@ +/* + * Copyright 2020 Google LLC + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// TEST PROCESSOR: CheckOverrideProcessor +// EXPECTED: +// KotlinList.get overrides JavaList.get: false +// KotlinList.foo overrides JavaList.foo: true +// KotlinList.fooo overrides JavaList.foo: false +// KotlinList.foo overrides KotlinList.foo: false +// KotlinList.equals overrides JavaList.equals: true +// KotlinList2.baz overrides KotlinList.baz: true +// KotlinList2.baz overrides KotlinList.bazz: false +// KotlinList2.bazz overrides KotlinList.bazz: true +// KotlinList2.bazz overrides KotlinList.baz: false +// KotlinList2.baz overrides KotlinList2.baz: false +// JavaImpl.getY overrides JavaImpl.getX: false +// JavaImpl.getY overrides MyInterface.x: false +// JavaImpl.getX overrides MyInterface.x: true +// JavaImpl.setY overrides MyInterface.y: true +// JavaImpl.setX overrides MyInterface.x: false +// JavaImpl.getY overrides JavaImpl.getY: false +// MyInterface.x overrides JavaImpl.getY: false +// MyInterface.x overrides JavaImpl.getX: false +// MyInterface.y overrides JavaImpl.setY: false +// MyInterface.y overrides MyInterface.y: false +// MyInterface2.receiveList overrides MyInterface2ImplWithoutType.receiveList: false +// MyInterface2ImplWithoutType.receiveList overrides MyInterface2.receiveList: true +// MyInterface2ImplWithType.receiveList overrides MyInterface2.receiveList: true +// MyInterface2ImplWithType.receiveList overrides MyInterface2ImplWithoutType.receiveList: true +// JavaDifferentReturnType.foo overrides JavaList.foo: true +// Base.f1 overrides MyInterface3.f1: true +// Base.prop overrides MyInterface3.prop: true +// JBase.getProp overrides MyInterface3.prop: true +// END +// FILE: a.kt + +annotation class GetAnno +annotation class FooAnno +annotation class BarAnno +annotation class BazAnno +annotation class Baz2Anno +annotation class BazzAnno +annotation class Bazz2Anno + +open class KotlinList(): JavaList() { + @GetAnno + fun get(): Double { + return 2.0 + } + + override fun equals(other: Any?): Boolean { + return false + } + + @FooAnno + override fun foo(): Int { + return 2 + } + + @BarAnno + override fun fooo(): Int { + return 2 + } + + @Baz2Anno + open val baz: Int get() { + return 1 + } + + @Bazz2Anno + open val bazz: Int get() { + return 1 + } +} + +class KotlinList2(@BazzAnno override val bazz: Int = 2): KotlinList() { + @BazAnno + override val baz: Int get() { + return 2 + } +} + +interface MyInterface { + val x: Int + var y: Int +} + +enum class EnumType { + FOO, + BAR; +} + +interface MyInterface2<T> { + fun receiveList(argsInParent : List<T>):Unit +} + +interface MyInterface2ImplWithoutType<T> : MyInterface2<T> { + override fun receiveList(argsInParent : List<T>):Unit +} + +interface MyInterface2ImplWithType : MyInterface2ImplWithoutType<EnumType> { + override fun receiveList(argsInParent : List<EnumType>):Unit +} + +interface MyInterface3 { + fun f1() + val prop: String +} + +open class Base { + val prop: String = "" + fun f1() { + } +} + +class BaseOverride: MyInterface3, Base() { + fun f2() {} +} + +// FILE: JBaseOverride.java +public class JBaseOverride extends JBase implements MyInterface3 { + +} + +// FILE: JBase.java + +public class JBase { + public String getProp() { + return "JBase"; + } +} + +// FILE: JavaList.java + +import java.util.*; + +public class JavaList extends List<String> { + @Override + public String get(int index) { + return "OK"; + } + + protected int foo() { + return 1; + } +} + +// FILE: JavaImpl.java + +public class JavaImpl implements MyInterface { + public int getX() { + return 1; + } + + public int getY() { + return 1; + } + + public void setY(int value) { + + } + + // intentional override check for a val property + public void setX(int value) { + return value; + } +} + +// FILE: JavaDifferentReturnType.java +public abstract class JavaDifferentReturnType extends JavaList { + // intentional different return type + protected String foo() { + return ""; + } +} diff --git a/test-utils/testData/api/classKinds.kt b/test-utils/testData/api/classKinds.kt new file mode 100644 index 00000000..867cc8d9 --- /dev/null +++ b/test-utils/testData/api/classKinds.kt @@ -0,0 +1,55 @@ +/* + * Copyright 2020 Google LLC + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// WITH_RUNTIME +// TEST PROCESSOR: ClassKindsProcessor +// EXPECTED: +// JA: ANNOTATION_CLASS +// JC: CLASS +// JE.ENTRY: ENUM_ENTRY +// JE: ENUM_CLASS +// JI: INTERFACE +// KA: ANNOTATION_CLASS +// KC: CLASS +// KE.ENTRY: ENUM_ENTRY +// KE: ENUM_CLASS +// KI: INTERFACE +// KO: OBJECT +// kotlin.Annotation: INTERFACE +// kotlin.Any: CLASS +// kotlin.Deprecated: ANNOTATION_CLASS +// kotlin.DeprecationLevel.WARNING: ENUM_ENTRY +// kotlin.DeprecationLevel: ENUM_CLASS +// kotlin.Double.Companion: OBJECT +// END + +// FILE: K.kt +class KC +interface KI +annotation class KA +object KO +enum class KE { + ENTRY +} + +// FILE: J.java +class JC {} +interface JI {} +@interface JA {} +enum JE { + ENTRY +} diff --git a/test-utils/testData/api/companion.kt b/test-utils/testData/api/companion.kt new file mode 100644 index 00000000..1ca09b75 --- /dev/null +++ b/test-utils/testData/api/companion.kt @@ -0,0 +1,31 @@ +/* + * Copyright 2020 Google LLC + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// WITH_RUNTIME +// TEST PROCESSOR: ClassWithCompanionProcessor +// EXPECTED: +// Foo:false +// companion:false +// obj:false +// K:true +// END + +class Foo { + object companion {} + object obj {} + companion object K {} +} diff --git a/test-utils/testData/api/constProperties.kt b/test-utils/testData/api/constProperties.kt new file mode 100644 index 00000000..18a601ca --- /dev/null +++ b/test-utils/testData/api/constProperties.kt @@ -0,0 +1,57 @@ +// WITH_RUNTIME +// TEST PROCESSOR: ConstPropertiesProcessor +// EXPECTED: +// insideCompanionConstCompiled +// insideCompanionConstSource +// insideObjectConstCompiled +// insideObjectConstSource +// topLevelConstCompiled +// topLevelConstSource +// END +// MODULE: lib +// FILE: compiledProperties.kt +package foo.compiled + +const val topLevelConstCompiled: String = "hello" +val topLevelCompiled: String = "hello" +val topLevelDelegatedCompiled by lazy { "hello" } +var topLevelVarCompiled: String = "hello" +val topLevelCustomGetterCompiled: String get() = "hello" +object TestObject { + const val insideObjectConstCompiled: Boolean = true + val insideObjectCompiled: String = "hello" + val insideObjectDelegatedCompiled by lazy { "hello" } + var insideVarObjectCompiled: String = "hello" + val insideObjectCustomGetterCompiled: String get() = "hello" +} +interface Foo { + val abstractCompiled: Long + val abstractWithDefaultCompiled: Long get() = 100L + companion object { + const val insideCompanionConstCompiled: Int = 34 + } +} + +// MODULE: main(lib) +// FILE: sourceProperties.kt +package foo.source + +const val topLevelConstSource: String = "hello" +val topLevelSource: String = "hello" +val topLevelDelegatedSource by lazy { "hello" } +var topLevelVarSource: String = "hello" +val topLevelCustomGetterSource: String get() = "hello" +object TestObject { + const val insideObjectConstSource: Boolean = true + val insideObjectSource: String = "hello" + val insideObjectDelegatedSource by lazy { "hello" } + var insideVarObjectSource: String = "hello" + val insideObjectCustomGetterSource: String get() = "hello" +} +interface Foo { + val abstractSource: Long + val abstractWithDefaultSource: Long get() = 100L + companion object { + const val insideCompanionConstSource: Int = 34 + } +} diff --git a/test-utils/testData/api/constructorDeclarations.kt b/test-utils/testData/api/constructorDeclarations.kt new file mode 100644 index 00000000..43889271 --- /dev/null +++ b/test-utils/testData/api/constructorDeclarations.kt @@ -0,0 +1,349 @@ +/* + * Copyright 2020 Google LLC + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// WITH_RUNTIME +// TEST PROCESSOR: ConstructorDeclarationsProcessor +// EXPECTED: +// class: AbstractJavaClassWithExplicitConstructor +// <init>(kotlin.Int): AbstractJavaClassWithExplicitConstructor +// class: lib.AbstractJavaClassWithExplicitConstructor +// <init>(kotlin.Int): lib.AbstractJavaClassWithExplicitConstructor +// class: AbstractJavaClassWithExplicitEmptyConstructor +// <init>(): AbstractJavaClassWithExplicitEmptyConstructor +// class: lib.AbstractJavaClassWithExplicitEmptyConstructor +// <init>(): lib.AbstractJavaClassWithExplicitEmptyConstructor +// class: AbstractJavaClassWithMultipleConstructors1 +// <init>(): AbstractJavaClassWithMultipleConstructors1 +// <init>(kotlin.Int): AbstractJavaClassWithMultipleConstructors1 +// <init>(kotlin.String): AbstractJavaClassWithMultipleConstructors1 +// class: lib.AbstractJavaClassWithMultipleConstructors1 +// <init>(): lib.AbstractJavaClassWithMultipleConstructors1 +// <init>(kotlin.Int): lib.AbstractJavaClassWithMultipleConstructors1 +// <init>(kotlin.String): lib.AbstractJavaClassWithMultipleConstructors1 +// class: AbstractJavaClassWithoutExplicitConstructor +// <init>(): AbstractJavaClassWithoutExplicitConstructor +// class: lib.AbstractJavaClassWithoutExplicitConstructor +// <init>(): lib.AbstractJavaClassWithoutExplicitConstructor +// class: AbstractKotlinClassWithExplicitConstructor +// <init>(kotlin.Int): AbstractKotlinClassWithExplicitConstructor +// class: lib.AbstractKotlinClassWithExplicitConstructor +// <init>(kotlin.Int): lib.AbstractKotlinClassWithExplicitConstructor +// class: AbstractKotlinClassWithExplicitEmptyConstructor +// <init>(): AbstractKotlinClassWithExplicitEmptyConstructor +// class: lib.AbstractKotlinClassWithExplicitEmptyConstructor +// <init>(): lib.AbstractKotlinClassWithExplicitEmptyConstructor +// class: AbstractKotlinClassWithMultipleConstructors1 +// <init>(): AbstractKotlinClassWithMultipleConstructors1 +// <init>(kotlin.Int): AbstractKotlinClassWithMultipleConstructors1 +// <init>(kotlin.String): AbstractKotlinClassWithMultipleConstructors1 +// class: lib.AbstractKotlinClassWithMultipleConstructors1 +// <init>(): lib.AbstractKotlinClassWithMultipleConstructors1 +// <init>(kotlin.Int): lib.AbstractKotlinClassWithMultipleConstructors1 +// <init>(kotlin.String): lib.AbstractKotlinClassWithMultipleConstructors1 +// class: AbstractKotlinClassWithMultipleConstructors2 +// <init>(kotlin.Float): AbstractKotlinClassWithMultipleConstructors2 +// <init>(kotlin.Int): AbstractKotlinClassWithMultipleConstructors2 +// <init>(kotlin.String): AbstractKotlinClassWithMultipleConstructors2 +// class: lib.AbstractKotlinClassWithMultipleConstructors2 +// <init>(kotlin.Float): lib.AbstractKotlinClassWithMultipleConstructors2 +// <init>(kotlin.Int): lib.AbstractKotlinClassWithMultipleConstructors2 +// <init>(kotlin.String): lib.AbstractKotlinClassWithMultipleConstructors2 +// class: AbstractKotlinClassWithPrimaryConstructor +// <init>(kotlin.Int): AbstractKotlinClassWithPrimaryConstructor +// class: lib.AbstractKotlinClassWithPrimaryConstructor +// <init>(kotlin.Int): lib.AbstractKotlinClassWithPrimaryConstructor +// class: AbstractKotlinClassWithoutExplicitConstructor +// <init>(): AbstractKotlinClassWithoutExplicitConstructor +// class: lib.AbstractKotlinClassWithoutExplicitConstructor +// <init>(): lib.AbstractKotlinClassWithoutExplicitConstructor +// class: DataClass +// <init>(kotlin.Int,kotlin.String): DataClass +// class: lib.DataClass +// <init>(kotlin.Int,kotlin.String): lib.DataClass +// class: DataClassWithSecondaryConstructor +// <init>(kotlin.Int): DataClassWithSecondaryConstructor +// <init>(kotlin.Int,kotlin.String): DataClassWithSecondaryConstructor +// class: lib.DataClassWithSecondaryConstructor +// <init>(kotlin.Int): lib.DataClassWithSecondaryConstructor +// <init>(kotlin.Int,kotlin.String): lib.DataClassWithSecondaryConstructor +// class: JavaAnnotation +// <init>(): JavaAnnotation +// class: lib.JavaAnnotation +// <init>(): lib.JavaAnnotation +// class: JavaClassWithExplicitConstructor +// <init>(kotlin.Int): JavaClassWithExplicitConstructor +// class: lib.JavaClassWithExplicitConstructor +// <init>(kotlin.Int): lib.JavaClassWithExplicitConstructor +// class: JavaClassWithExplicitEmptyConstructor +// <init>(): JavaClassWithExplicitEmptyConstructor +// class: lib.JavaClassWithExplicitEmptyConstructor +// <init>(): lib.JavaClassWithExplicitEmptyConstructor +// class: JavaClassWithMultipleConstructors1 +// <init>(): JavaClassWithMultipleConstructors1 +// <init>(kotlin.Int): JavaClassWithMultipleConstructors1 +// <init>(kotlin.String): JavaClassWithMultipleConstructors1 +// class: lib.JavaClassWithMultipleConstructors1 +// <init>(): lib.JavaClassWithMultipleConstructors1 +// <init>(kotlin.Int): lib.JavaClassWithMultipleConstructors1 +// <init>(kotlin.String): lib.JavaClassWithMultipleConstructors1 +// class: JavaClassWithoutExplicitConstructor +// <init>(): JavaClassWithoutExplicitConstructor +// class: lib.JavaClassWithoutExplicitConstructor +// <init>(): lib.JavaClassWithoutExplicitConstructor +// class: JavaInterface +// class: lib.JavaInterface +// class: KotlinAnnotation +// <init>(): KotlinAnnotation +// class: lib.KotlinAnnotation +// <init>(): lib.KotlinAnnotation +// class: KotlinClassWithCompanion +// <init>(): KotlinClassWithCompanion +// class: lib.KotlinClassWithCompanion +// <init>(): lib.KotlinClassWithCompanion +// class: KotlinClassWithExplicitConstructor +// <init>(kotlin.Int): KotlinClassWithExplicitConstructor +// class: lib.KotlinClassWithExplicitConstructor +// <init>(kotlin.Int): lib.KotlinClassWithExplicitConstructor +// class: KotlinClassWithExplicitEmptyConstructor +// <init>(): KotlinClassWithExplicitEmptyConstructor +// class: lib.KotlinClassWithExplicitEmptyConstructor +// <init>(): lib.KotlinClassWithExplicitEmptyConstructor +// class: KotlinClassWithMultipleConstructors1 +// <init>(): KotlinClassWithMultipleConstructors1 +// <init>(kotlin.Int): KotlinClassWithMultipleConstructors1 +// <init>(kotlin.String): KotlinClassWithMultipleConstructors1 +// class: lib.KotlinClassWithMultipleConstructors1 +// <init>(): lib.KotlinClassWithMultipleConstructors1 +// <init>(kotlin.Int): lib.KotlinClassWithMultipleConstructors1 +// <init>(kotlin.String): lib.KotlinClassWithMultipleConstructors1 +// class: KotlinClassWithMultipleConstructors2 +// <init>(kotlin.Float): KotlinClassWithMultipleConstructors2 +// <init>(kotlin.Int): KotlinClassWithMultipleConstructors2 +// <init>(kotlin.String): KotlinClassWithMultipleConstructors2 +// class: lib.KotlinClassWithMultipleConstructors2 +// <init>(kotlin.Float): lib.KotlinClassWithMultipleConstructors2 +// <init>(kotlin.Int): lib.KotlinClassWithMultipleConstructors2 +// <init>(kotlin.String): lib.KotlinClassWithMultipleConstructors2 +// class: KotlinClassWithNamedCompanion +// <init>(): KotlinClassWithNamedCompanion +// class: lib.KotlinClassWithNamedCompanion +// <init>(): lib.KotlinClassWithNamedCompanion +// class: KotlinClassWithPrimaryConstructor +// <init>(kotlin.Int): KotlinClassWithPrimaryConstructor +// class: lib.KotlinClassWithPrimaryConstructor +// <init>(kotlin.Int): lib.KotlinClassWithPrimaryConstructor +// class: KotlinClassWithoutExplicitConstructor +// <init>(): KotlinClassWithoutExplicitConstructor +// class: lib.KotlinClassWithoutExplicitConstructor +// <init>(): lib.KotlinClassWithoutExplicitConstructor +// class: KotlinInterface +// class: lib.KotlinInterface +// class: KotlinObject +// <init>(): KotlinObject +// class: lib.KotlinObject +// <init>(): lib.KotlinObject +// END + +// MODULE: lib +// FILE: lib/JavaInterface.java +package lib; +interface JavaInterface { +} +// FILE: lib/AbstractJavaClassWithoutExplicitConstructor.java +package lib; +abstract class AbstractJavaClassWithoutExplicitConstructor { +} +// FILE: lib/AbstractJavaClassWithExplicitEmptyConstructor.java +package lib; +abstract class AbstractJavaClassWithExplicitEmptyConstructor { + AbstractJavaClassWithExplicitEmptyConstructor() {} +} +// FILE: lib/AbstractJavaClassWithExplicitConstructor.java +package lib; +abstract class AbstractJavaClassWithExplicitConstructor { + AbstractJavaClassWithExplicitConstructor(int x) {} +} +// FILE: lib/AbstractJavaClassWithMultipleConstructors1.java +package lib; +abstract class AbstractJavaClassWithMultipleConstructors1 { + AbstractJavaClassWithMultipleConstructors1() {} + AbstractJavaClassWithMultipleConstructors1(int y) {} + AbstractJavaClassWithMultipleConstructors1(String x) {} +} +// FILE: lib/JavaClassWithoutExplicitConstructor.java +package lib; +class JavaClassWithoutExplicitConstructor { +} +// FILE: lib/JavaClassWithExplicitEmptyConstructor.java +package lib; +class JavaClassWithExplicitEmptyConstructor { + JavaClassWithExplicitEmptyConstructor() {} +} +// FILE: lib/JavaClassWithExplicitConstructor.java +package lib; +class JavaClassWithExplicitConstructor { + JavaClassWithExplicitConstructor(int x) {} +} +// FILE: lib/JavaClassWithMultipleConstructors1.java +package lib; +class JavaClassWithMultipleConstructors1 { + JavaClassWithMultipleConstructors1() {} + JavaClassWithMultipleConstructors1(int y) {} + JavaClassWithMultipleConstructors1(String x) {} +} +// FILE: JavaAnnotation.java +package lib; +public @interface JavaAnnotation { +} +// FILE: kotlin_lib.kt +package lib +interface KotlinInterface {} +class KotlinClassWithoutExplicitConstructor { +} +class KotlinClassWithExplicitEmptyConstructor() {} +class KotlinClassWithPrimaryConstructor(x:Int) { +} +class KotlinClassWithExplicitConstructor { + constructor(x:Int) {} +} +class KotlinClassWithMultipleConstructors1 { + constructor() {} + constructor(y:Int): this() {} + constructor(x: String) : this() {} +} +class KotlinClassWithMultipleConstructors2(z:Float) { + constructor(y:Int): this(0f) {} + constructor(x: String) : this(0f) {} +} +abstract class AbstractKotlinClassWithoutExplicitConstructor { +} +abstract class AbstractKotlinClassWithPrimaryConstructor(x:Int) { +} +abstract class AbstractKotlinClassWithExplicitEmptyConstructor() {} +abstract class AbstractKotlinClassWithExplicitConstructor { + constructor(x:Int) {} +} +abstract class AbstractKotlinClassWithMultipleConstructors1 { + constructor() {} + constructor(y:Int): this() {} + constructor(x: String) : this() {} +} +abstract class AbstractKotlinClassWithMultipleConstructors2(z:Float) { + constructor(y:Int): this(0f) {} + constructor(x: String) : this(0f) {} +} +annotation class KotlinAnnotation +object KotlinObject {} +class KotlinClassWithCompanion { + companion object +} +class KotlinClassWithNamedCompanion { + companion object MyCompanion +} +data class DataClass(val x:Int, var y:String) +data class DataClassWithSecondaryConstructor(val x:Int, val y:String) { + constructor(x:Int) : this(x, "") +} +// MODULE: main(lib) +// FILE: JavaInterface.java +interface JavaInterface { +} +// FILE: AbstractJavaClassWithoutExplicitConstructor.java +abstract class AbstractJavaClassWithoutExplicitConstructor { +} +// FILE: AbstractJavaClassWithExplicitEmptyConstructor.java +abstract class AbstractJavaClassWithExplicitEmptyConstructor { + AbstractJavaClassWithExplicitEmptyConstructor() {} +} +// FILE: AbstractJavaClassWithExplicitConstructor.java +abstract class AbstractJavaClassWithExplicitConstructor { + AbstractJavaClassWithExplicitConstructor(int x) {} +} +// FILE: AbstractJavaClassWithMultipleConstructors1.java +abstract class AbstractJavaClassWithMultipleConstructors1 { + AbstractJavaClassWithMultipleConstructors1() {} + AbstractJavaClassWithMultipleConstructors1(int y) {} + AbstractJavaClassWithMultipleConstructors1(String x) {} +} +// FILE: JavaClassWithoutExplicitConstructor.java +class JavaClassWithoutExplicitConstructor { +} +// FILE: JavaClassWithExplicitEmptyConstructor.java +class JavaClassWithExplicitEmptyConstructor { + JavaClassWithExplicitEmptyConstructor() {} +} +// FILE: JavaClassWithExplicitConstructor.java +class JavaClassWithExplicitConstructor { + JavaClassWithExplicitConstructor(int x) {} +} +// FILE: JavaClassWithMultipleConstructors1.java +class JavaClassWithMultipleConstructors1 { + JavaClassWithMultipleConstructors1() {} + JavaClassWithMultipleConstructors1(int y) {} + JavaClassWithMultipleConstructors1(String x) {} +} +// FILE: JavaAnnotation.java +public @interface JavaAnnotation { +} +// FILE: kotlin.kt +interface KotlinInterface {} +class KotlinClassWithoutExplicitConstructor { +} +class KotlinClassWithExplicitEmptyConstructor() {} +class KotlinClassWithPrimaryConstructor(x:Int) { +} +class KotlinClassWithExplicitConstructor { + constructor(x:Int) {} +} +class KotlinClassWithMultipleConstructors1 { + constructor() {} + constructor(y:Int): this() {} + constructor(x: String) : this() {} +} +class KotlinClassWithMultipleConstructors2(z:Float) { + constructor(y:Int): this(0f) {} + constructor(x: String) : this(0f) {} +} +abstract class AbstractKotlinClassWithoutExplicitConstructor { +} +abstract class AbstractKotlinClassWithPrimaryConstructor(x:Int) { +} +abstract class AbstractKotlinClassWithExplicitEmptyConstructor() {} +abstract class AbstractKotlinClassWithExplicitConstructor { + constructor(x:Int) {} +} +abstract class AbstractKotlinClassWithMultipleConstructors1 { + constructor() {} + constructor(y:Int): this() {} + constructor(x: String) : this() {} +} +abstract class AbstractKotlinClassWithMultipleConstructors2(z:Float) { + constructor(y:Int): this(0f) {} + constructor(x: String) : this(0f) {} +} +annotation class KotlinAnnotation +object KotlinObject {} +class KotlinClassWithCompanion { + companion object +} +class KotlinClassWithNamedCompanion { + companion object MyCompanion +} +data class DataClass(val x:Int, var y:String) +data class DataClassWithSecondaryConstructor(val x:Int, val y:String) { + constructor(x:Int) : this(x, "") +}
\ No newline at end of file diff --git a/test-utils/testData/api/crossModuleTypeAlias.kt b/test-utils/testData/api/crossModuleTypeAlias.kt new file mode 100644 index 00000000..92a86a0f --- /dev/null +++ b/test-utils/testData/api/crossModuleTypeAlias.kt @@ -0,0 +1,42 @@ +/* + * Copyright 2022 Google LLC + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// WITH_RUNTIME +// TEST PROCESSOR: CrossModuleTypeAliasTestProcessor +// EXPECTED: +// A1(KOTLIN) +// A2(KOTLIN_LIB) +// M1(KOTLIN_LIB) +// END + +// MODULE: module1 +// FILE: M1.kt +class M1 + +// MODULE: module2(module1) +// FILE: M2.kt +typealias A2 = M1 + +// MODULE: main(module1, module2) +// FILE: main.kt +typealias A1 = M1 + +class TestTarget { + val a1: A1 = TODO() + val a2: A2 = TODO() + val m1: M1 = TODO() +} diff --git a/test-utils/testData/api/declarationInconsistency.kt b/test-utils/testData/api/declarationInconsistency.kt new file mode 100644 index 00000000..6f3b39b8 --- /dev/null +++ b/test-utils/testData/api/declarationInconsistency.kt @@ -0,0 +1,31 @@ +/* + * Copyright 2020 Google LLC + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// WITH_RUNTIME +// TEST PROCESSOR: DeclarationInconsistencyProcessor +// EXPECTED: +// via type: java.io.Serializable +// equals +// hashCode +// toString +// via find declaration: java.io.Serializable +// equals +// hashCode +// toString +// END +//FILE: a.kt +val x = 3 diff --git a/test-utils/testData/api/declarationOrder.kt b/test-utils/testData/api/declarationOrder.kt new file mode 100644 index 00000000..7de65a23 --- /dev/null +++ b/test-utils/testData/api/declarationOrder.kt @@ -0,0 +1,156 @@ +/* + * Copyright 2022 Google LLC + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// WITH_RUNTIME +// TEST PROCESSOR: DeclarationOrderProcessor +// EXPECTED: +// lib.KotlinClass +// b:Ljava/lang/String; +// a:Ljava/lang/String; +// c:Ljava/lang/String; +// isB:Ljava/lang/String; +// isA:Ljava/lang/String; +// isC:Ljava/lang/String; +// noBackingB:Ljava/lang/String; +// noBackingA:Ljava/lang/String; +// noBackingC:Ljava/lang/String; +// noBackingVarB:Ljava/lang/String; +// noBackingVarA:Ljava/lang/String; +// noBackingVarC:Ljava/lang/String; +// overloaded:(Ljava/lang/String;)Ljava/lang/String; +// overloaded:(I)Ljava/lang/String; +// overloaded:()Ljava/lang/String; +// overloaded:(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String; +// <init>:()V +// lib.JavaClass +// b:Ljava/lang/String; +// a:Ljava/lang/String; +// c:Ljava/lang/String; +// overloaded:(Ljava/lang/String;)V +// overloaded:(I)V +// overloaded:()V +// overloaded:(Ljava/lang/String;Ljava/lang/String;)V +// <init>:()V +// KotlinClass +// b:Ljava/lang/String; +// a:Ljava/lang/String; +// c:Ljava/lang/String; +// isB:Ljava/lang/String; +// isA:Ljava/lang/String; +// isC:Ljava/lang/String; +// noBackingB:Ljava/lang/String; +// noBackingA:Ljava/lang/String; +// noBackingC:Ljava/lang/String; +// noBackingVarB:Ljava/lang/String; +// noBackingVarA:Ljava/lang/String; +// noBackingVarC:Ljava/lang/String; +// overloaded:(Ljava/lang/String;)Ljava/lang/String; +// overloaded:(I)Ljava/lang/String; +// overloaded:()Ljava/lang/String; +// overloaded:(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String; +// <init>:()V +// JavaClass +// b:Ljava/lang/String; +// a:Ljava/lang/String; +// c:Ljava/lang/String; +// overloaded:(Ljava/lang/String;)V +// overloaded:(I)V +// overloaded:()V +// overloaded:(Ljava/lang/String;Ljava/lang/String;)V +// <init>:()V +// END +// MODULE: module1 +// FILE: lib/KotlinClass.kt +package lib; +class KotlinClass { + val b: String = TODO() + val a: String = TODO() + val c: String = TODO() + val isB:String = TODO() + val isA:String = TODO() + val isC:String = TODO() + val noBackingB: String + get() = "" + val noBackingA: String + get() = "" + val noBackingC: String + get() = "" + var noBackingVarB: String + get() = "" + set(value) {} + var noBackingVarA: String + get() = "" + set(value) {} + var noBackingVarC: String + get() = "" + set(value) {} + fun overloaded(x:String): String = TODO() + fun overloaded(x:Int): String = TODO() + fun overloaded(): String = TODO() + fun overloaded(x:String, y:String): String = TODO() +} +// FILE: lib/JavaClass.java +package lib; +public class JavaClass { + // notice the non alphabetic order, which is triggering the problem + String b = ""; + String a = ""; + String c = ""; + void overloaded(String x) {} + void overloaded(int x) {} + void overloaded() {} + void overloaded(String x, String y) {} +} +// MODULE: main(module1) +// FILE: main.kt +class KotlinClass { + val b: String? = TODO() + val a: String = TODO() + val c: String? = TODO() + val isB:String = TODO() + val isA:String = TODO() + val isC:String = TODO() + val noBackingB: String + get() = "" + val noBackingA: String + get() = "" + val noBackingC: String + get() = "" + var noBackingVarB: String + get() = "" + set(value) {} + var noBackingVarA: String + get() = "" + set(value) {} + var noBackingVarC: String + get() = "" + set(value) {} + fun overloaded(x:String): String = TODO() + fun overloaded(x:Int): String = TODO() + fun overloaded(): String = TODO() + fun overloaded(x:String, y:String): String = TODO() +} +// FILE: JavaClass.java +public class JavaClass { + String b = ""; + String a = ""; + String c = ""; + void overloaded(String x) {} + void overloaded(int x) {} + void overloaded() {} + void overloaded(String x, String y) {} +} diff --git a/test-utils/testData/api/declarationPackageName.kt b/test-utils/testData/api/declarationPackageName.kt new file mode 100644 index 00000000..bf3df55f --- /dev/null +++ b/test-utils/testData/api/declarationPackageName.kt @@ -0,0 +1,98 @@ +/* + * Copyright 2020 Google LLC + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// TEST PROCESSOR: DeclarationPackageNameProcessor +// EXPECTED: +// <no name>:J1 +// <no name>:J1.<init> +// <no name>:J2 +// <no name>:J2.<init> +// <no name>:K1 +// <no name>:K1.<init> +// <no name>:K2 +// <no name>:K2.<init> +// test.java.pack:C +// test.java.pack:C.<init> +// test.java.pack:Inner +// test.java.pack:Inner.<init> +// test.java.pack:Nested +// test.java.pack:Nested.<init> +// test.pack:Inner +// test.pack:Inner.<init> +// test.pack:Inner.innerFoo +// test.pack:InnerLocal +// test.pack:InnerLocal.<init> +// test.pack:Nested +// test.pack:Nested.<init> +// test.pack:Nested.nestedFoo +// test.pack:Outer +// test.pack:Outer.<init> +// test.pack:Outer.Foo +// test.pack:Val +// test.pack:a +// test.pack:innerVal +// test.pack:nestedVal +// END + +// MODULE: module1 +// FILE: K1.kt +class K1 + +// FILE: J1.java +class J1 { +} + +// MODULE: main(module1) +// FILE: K2.kt +class K2 + +// FILE: J2.java +class J2 { +} + +// FILE: a.kt +package test.pack + +class Outer { + val Val + + fun Foo() {} + + inner class Inner { + val innerVal: Int + fun innerFoo() { + class InnerLocal + } + } + class Nested { + private val nestedVal: Int + fun nestedFoo() { + val a = 1 + } + } +} + +//FILE: test/java/pack/C.java +package test.java.pack; + +public class C { + class Inner { + + } + + static class Nested {} +} diff --git a/test-utils/testData/api/declarationUtil.kt b/test-utils/testData/api/declarationUtil.kt new file mode 100644 index 00000000..368fb799 --- /dev/null +++ b/test-utils/testData/api/declarationUtil.kt @@ -0,0 +1,100 @@ +/* + * Copyright 2020 Google LLC + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// TEST PROCESSOR: DeclarationUtilProcessor +// FORMAT: <name>: isInternal: isLocal: isPrivate: isProtected: isPublic: isOpen +// EXPECTED: +// Cls: internal +// Cls / <init>: public +// Cls.b: public open +// Cls / <init>: public +// Cls / <init> / aaa: local +// Cls.prop: public open +// Cls.protectedProp: protected open +// Cls.abstractITFFun: public open +// Cls.pri: private +// ITF: public open +// ITF.prop: public open +// ITF.protectedProp: protected open +// ITF.b: public open +// ITF.abstractITFFun: public open +// ITF.nonAbstractITFFun: public open +// ITF.nonAbstractITFFun / aa: local +// NestedClassSubjects: public open +// NestedClassSubjects.NestedDataClass: public +// NestedClassSubjects.NestedDataClass / <init>: public +// NestedClassSubjects.NestedDataClass.field: public +// NestedClassSubjects.NestedFinalClass: public +// NestedClassSubjects.NestedFinalClass / <init>: public +// NestedClassSubjects.NestedFinalClass.field: public +// NestedClassSubjects.NestedOpenClass: public open +// NestedClassSubjects.NestedOpenClass / <init>: public +// NestedClassSubjects.NestedOpenClass.field: public +// NestedClassSubjects.NestedInterface: public open +// SealedBase: public open +// SealedBase.<init>: public +// SealedImpl: public +// SealedImpl.<init>: public +// END +// FILE: a.kt +internal class Cls(override val b: Int) : ITF { + constructor() { + val aaa = 2 + Cls(aaa) + } + override val prop: Int = 2 + + override val protectedProp: Int = 2 + + override fun abstractITFFun(): Int { + return 2 + } + + private val pri: Int = 3 +} + +interface ITF { + val prop: Int + + protected val protectedProp: Int + + val b: Int = 1 + + fun abstractITFFun(): Int + + fun nonAbstractITFFun(): Int { + val aa = "local" + return 1 + } +} + +interface NestedClassSubjects { + data class NestedDataClass( + val field: String, + ) + class NestedFinalClass( + val field: String, + ) + open class NestedOpenClass( + val field: String, + ) + interface NestedInterface +} + +sealed class SealedBase + +class SealedImpl: SealedBase diff --git a/test-utils/testData/api/declared.kt b/test-utils/testData/api/declared.kt new file mode 100644 index 00000000..1eb567ce --- /dev/null +++ b/test-utils/testData/api/declared.kt @@ -0,0 +1,46 @@ +/* + * Copyright 2022 Google LLC + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// TEST PROCESSOR: DeclaredProcessor +// EXPECTED: +// Base class declared functions: +// subFun +// synthetic constructor for Sub +// Sub class declared functions: +// baseFun +// <init> +// JavaSource class declared functions: +// javaSourceFun +// synthetic constructor for JavaSource +// END +// MODULE: module1 +// FILE: lib.kt +open class Base { + fun baseFun() {} +} +// MODULE: main(module1) +// FILE: sub.kt +class Sub: Base() { + fun subFun() {} +} + +// FILE: JavaSource.java +public class JavaSource { + public int javaSourceFun() { + return 1 + } +} diff --git a/test-utils/testData/api/docString.kt b/test-utils/testData/api/docString.kt new file mode 100644 index 00000000..1432c05a --- /dev/null +++ b/test-utils/testData/api/docString.kt @@ -0,0 +1,141 @@ +/* + * Copyright 2020 Google LLC + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// TEST PROCESSOR: DocStringProcessor +// EXPECTED: +// <init>: \n This is a java doc\n\n This is a second line\n\n more lines\n +// <init>: \n inner class\n +// <init>: \n nest class\n +// <init>: \n top level class\n\n doc can have multiple lines\n\n third non-empty line\n +// Inner: \n inner class\n +// JavaSrc: \n This is a java doc\n\n This is a second line\n\n more lines\n +// Nested: \n nest class\n +// TopClass: \n top level class\n\n doc can have multiple lines\n\n third non-empty line\n +// f1: \n top level function\n +// f2: \n member function\n +// foo: \n\n\n member function\n\n +// j1: \n field\n +// j2: null +// j3: null +// v1: \n\n top level property\n\n +// v2: Irregular doc comment 1 +// v3: \n Irregular doc comment 2 +// v4: Irregular doc comment 3 *\n +// v5: \n owned doc comment\n +// v6: null +// v7: null +// v8: \n member property\n +// END +// FILE: KotlinSrc.kt + +/** + * top level function + */ +fun f1() = 0 + +/** + * + * top level property + * + */ +val v1 = 0 + + +/** * Irregular doc comment 1***/ +val v2 = 0 + +/** + * Irregular doc comment 2*/ +val v3 = 0 + +/** Irregular doc comment 3 * + */ +val v4 = 0 + +/** + * unassociated doc comment + */ +/** + * owned doc comment + */ +val v5 = 0 + +/* Not doc comment 1 */ +val v6 = 0 + +// Not doc comment 2 +val v7 = 0 + +/** + * top level class + * + * doc can have multiple lines + * + * third non-empty line + */ +class TopClass { + /** + * nest class + */ + class Nested + + /** + * inner class + */ + class Inner + + /** + * member function + */ + fun f2() = 0 + + /** + * member property + */ + val v8 = 0 +} + +// FILE: JavaSrc.java +/** + * This is a java doc + * + * This is a second line + * + * more lines + */ +class JavaSrc { + /** + * + * + * member function + * + */ + int foo() { + return 0; + } + + /** + * field + */ + int j1 = 0; + + // Not a doc + int j2 = 0; + + /* Not a doc */ + int j3 = 0; +} diff --git a/test-utils/testData/api/equivalentJavaWildcards.kt b/test-utils/testData/api/equivalentJavaWildcards.kt new file mode 100644 index 00000000..c4f3ecf0 --- /dev/null +++ b/test-utils/testData/api/equivalentJavaWildcards.kt @@ -0,0 +1,208 @@ +/* + * Copyright 2020 Google LLC + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// WITH_RUNTIME +// TEST PROCESSOR: EquivalentJavaWildcardProcessor +// EXPECTED: +// X : Any -> Any +// <init> : X -> X +// Y : X -> X +// <init> : Y -> Y +// A : Any -> Any +// T1 : Any? -> Any? +// T2 : Any? -> Any? +// <init> : A<T1, T2> -> A<T1, T2> +// B : Any -> Any +// T : Any? -> Any? +// synthetic constructor for B : B<*> -> B<out Any?> +// bar1 : [@kotlin.jvm.JvmSuppressWildcards] A<X, X> -> [@kotlin.jvm.JvmSuppressWildcards] A<X, X> +// - INVARIANT X : X -> X +// - INVARIANT X : X -> X +// - @JvmSuppressWildcards : JvmSuppressWildcards -> JvmSuppressWildcards +// bar2 : [@kotlin.jvm.JvmSuppressWildcards] A<X, X> -> [@kotlin.jvm.JvmSuppressWildcards] A<in X, out X> +// - INVARIANT X : X -> X +// - INVARIANT X : X -> X +// - @JvmSuppressWildcards : JvmSuppressWildcards -> JvmSuppressWildcards +// bar3 : [@kotlin.jvm.JvmWildcard] A<X, X> -> [@kotlin.jvm.JvmWildcard] A<X, X> +// - INVARIANT X : X -> X +// - INVARIANT X : X -> X +// - @JvmWildcard : JvmWildcard -> JvmWildcard +// p1 : A<in X, out X> -> A<X, X> +// - CONTRAVARIANT X : X -> X +// - COVARIANT X : X -> X +// p1.getter() : A<in X, out X> -> A<X, X> +// - CONTRAVARIANT X : X -> X +// - COVARIANT X : X -> X +// p2 : A<Any, Y> -> A<Any, Y> +// - INVARIANT Any : Any -> Any +// - INVARIANT Y : Y -> Y +// p2.getter() : A<Any, Y> -> A<Any, Y> +// - INVARIANT Any : Any -> Any +// - INVARIANT Y : Y -> Y +// p3 : A<*, *> -> A<Any?, Any?> +// p3.getter() : A<*, *> -> A<Any?, Any?> +// - STAR Any : Any? -> Any? +// - STAR Any : Any? -> Any? +// p4 : B<X> -> B<X> +// - INVARIANT X : X -> X +// p4.getter() : B<X> -> B<X> +// - INVARIANT X : X -> X +// p5 : B<in X> -> B<in X> +// - CONTRAVARIANT X : X -> X +// p5.getter() : B<in X> -> B<in X> +// - CONTRAVARIANT X : X -> X +// p6 : B<out X> -> B<out X> +// - COVARIANT X : X -> X +// p6.getter() : B<out X> -> B<out X> +// - COVARIANT X : X -> X +// p7 : B<*> -> B<out Any?> +// p7.getter() : B<*> -> B<out Any?> +// - STAR Any : Any? -> Any? +// p8 : B<A<X, out Y>> -> B<A<X, Y>> +// - INVARIANT A : A<X, out Y> -> A<X, Y> +// - - INVARIANT X : X -> X +// - - COVARIANT Y : Y -> Y +// p8.getter() : B<A<X, out Y>> -> B<A<X, Y>> +// - INVARIANT A<X, out Y> : A<X, out Y> -> A<in X, Y> +// - - INVARIANT X : X -> X +// - - COVARIANT Y : Y -> Y +// v1 : A<X, X> -> A<in X, out X> +// - INVARIANT X : X -> X +// - INVARIANT X : X -> X +// v2 : A<Any, Y> -> A<Any, Y> +// - INVARIANT Any : Any -> Any +// - INVARIANT Y : Y -> Y +// v3 : A<*, *> -> A<out Any?, out Any?> +// v4 : B<X> -> B<X> +// - INVARIANT X : X -> X +// v5 : B<in X> -> B<in X> +// - CONTRAVARIANT X : X -> X +// v6 : B<out X> -> B<out X> +// - COVARIANT X : X -> X +// v7 : B<*> -> B<out Any?> +// v8 : B<A<X, out Y>> -> B<A<X, Y>> +// - INVARIANT A : A<X, out Y> -> A<X, Y> +// - - INVARIANT X : X -> X +// - - COVARIANT Y : Y -> Y +// foo : Unit -> Unit +// r1 : A<X, X> -> A<X, X> +// - INVARIANT X : X -> X +// - INVARIANT X : X -> X +// r2 : A<Any, Y> -> A<Any, Y> +// - INVARIANT Any : Any -> Any +// - INVARIANT Y : Y -> Y +// r3 : A<*, *> -> A<Any?, Any?> +// r4 : B<X> -> B<X> +// - INVARIANT X : X -> X +// r5 : B<in X> -> B<in X> +// - CONTRAVARIANT X : X -> X +// r6 : B<out X> -> B<out X> +// - COVARIANT X : X -> X +// r7 : B<*> -> B<out Any?> +// r8 : B<A<X, out Y>> -> B<A<X, Y>> +// - INVARIANT A : A<X, out Y> -> A<X, Y> +// - - INVARIANT X : X -> X +// - - COVARIANT Y : Y -> Y +// C1 : A<X, X> -> A<X, X> +// - INVARIANT X : X -> X +// - INVARIANT X : X -> X +// <init> : C1 -> C1 +// C2 : A<Any, Y> -> A<Any, Y> +// - INVARIANT Any : Any -> Any +// - INVARIANT Y : Y -> Y +// <init> : C2 -> C2 +// C3 : B<X> -> B<X> +// - INVARIANT X : X -> X +// <init> : C3 -> C3 +// C4 : B<A<X, out Y>> -> B<A<in X, out Y>> +// - INVARIANT A : A<X, out Y> -> A<in X, out Y> +// - - INVARIANT X : X -> X +// - - COVARIANT Y : Y -> Y +// <init> : C4 -> C4 +// END + +open class X() +final class Y() : X() + +open class A<in T1, out T2>() +open class B<T> + +// FIXME: should this annotation propagate to the return type? +// @JvmSuppressWildcards(false) +// fun bar(): A<X, X> = TODO() + +// A<X, X> +fun bar1(): @JvmSuppressWildcards(true) A<X, X> = TODO() +// A<? super X, ? extends X> +fun bar2(): @JvmSuppressWildcards(false) A<X, X> = TODO() +// A<X, X> +fun bar3(): @JvmWildcard A<X, X> = TODO() + +// A<X, X> +val p1: A<in X, out X> = TODO() +// A<java.lang.Object, Y> +val p2: A<Any, Y> = TODO() +// A<?, ?> +val p3: A<*, *> = TODO() +// B<X> +val p4: B<X> = TODO() +// B<? super X> +val p5: B<in X> = TODO() +// B<? extends X> +val p6: B<out X> = TODO() +// B<?> +val p7: B<*> = TODO() +// B<A<X, Y>> +val p8: B<A<X, out Y>> + +// void foo(A<? super X, ? extends X>, A<java.lang.Object, Y>, A<?, ?>, B<X>, B<? super X>, B<? extends X>, B<?>, B<A<X, Y>>); +fun foo( + v1: A<X, X>, + v2: A<Any, Y>, + v3: A<*, *>, + v4: B<X>, + v5: B<in X>, + v6: B<out X>, + v7: B<*>, + v8: B<A<X, out Y>>, +): Unit = Unit + +// A<X, X> +fun r1(): A<X, X> = TODO() +// A<java.lang.Object, Y> +fun r2(): A<Any, Y> = TODO() +// A<?, ?> +fun r3(): A<*, *> = TODO() +// B<X> +fun r4(): B<X> = TODO() +// B<? super X> +fun r5(): B<in X> = TODO() +// B<? extends X> +fun r6(): B<out X> = TODO() +// B<?> +fun r7(): B<*> = TODO() +// B<A<X, Y>> +fun r8(): B<A<X, out Y>> = TODO() + +// extends A<X, X> +class C1() : A<X, X>() +// A<java.lang.Object, Y> +class C2() : A<Any, Y>() +// B<X> +class C3() : B<X>() +// B<A<? super X, ? extends Y>> +class C4() : B<A<X, out Y>>() diff --git a/test-utils/testData/api/errorTypes.kt b/test-utils/testData/api/errorTypes.kt new file mode 100644 index 00000000..ab2a4afe --- /dev/null +++ b/test-utils/testData/api/errorTypes.kt @@ -0,0 +1,44 @@ +/* + * Copyright 2020 Google LLC + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// WITH_RUNTIME +// TEST PROCESSOR: ErrorTypeProcessor +// EXPECTED: +// ERROR TYPE +// kotlin.collections.Map +// kotlin.String +// ERROR TYPE +// errorInComponent is assignable from errorAtTop: false +// errorInComponent is assignable from class C: false +// Any is assignable from errorInComponent: false +// class C is assignable from errorInComponent: false +// Any is assignable from class C: true +// Cls's super type is Error type: true +// Cls's annotation is Error type: true +// END +// FILE: a.kt +class C { + val errorAtTop = mutableMapOf<String, NonExistType, Int>() + val errorInComponent: Map<String, NonExistType> +} + +// FILE: Cls.java + +@NonExistingAnnotation +public class Cls extends NonExistType { + +} diff --git a/test-utils/testData/api/functionTypeAlias.kt b/test-utils/testData/api/functionTypeAlias.kt new file mode 100644 index 00000000..1e9f775a --- /dev/null +++ b/test-utils/testData/api/functionTypeAlias.kt @@ -0,0 +1,41 @@ +/* + * Copyright 2020 Google LLC + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// WITH_RUNTIME +// TEST PROCESSOR: FunctionTypeAliasProcessor +// EXPECTED: +// Function1<String, String> ?= Function1<String, String> : true / true +// Function1<String, String> ?= String : false / false +// Function1<String, String> ?= [typealias F] : false / false +// Function1<String, String> ?= [typealias Foo] : true / true +// String ?= Function1<String, String> : false / false +// String ?= String : true / true +// String ?= [typealias F] : true / true +// String ?= [typealias Foo] : false / false +// [typealias F] ?= Function1<String, String> : false / false +// [typealias F] ?= String : true / true +// [typealias F] ?= [typealias F] : true / true +// [typealias F] ?= [typealias Foo] : false / false +// [typealias Foo] ?= Function1<String, String> : true / true +// [typealias Foo] ?= String : false / false +// [typealias Foo] ?= [typealias F] : false / false +// [typealias Foo] ?= [typealias Foo] : true / true +// END + +typealias F = String +val y: Foo = { it } +typealias Foo = (F) -> String diff --git a/test-utils/testData/api/functionTypeAnnotation.kt b/test-utils/testData/api/functionTypeAnnotation.kt new file mode 100644 index 00000000..900a700d --- /dev/null +++ b/test-utils/testData/api/functionTypeAnnotation.kt @@ -0,0 +1,33 @@ +/* + * Copyright 2022 Google LLC + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +// WITH_RUNTIME +// TEST PROCESSOR: FunctionTypeAnnotationProcessor +// EXPECTED: +// strExt0: Function1 @ExtensionFunctionType +// strExt1: Function2 @ExtensionFunctionType +// strWithAnnoExt0: Function1 @A, @ExtensionFunctionType +// strWithAnnoExt1: Function2 @A, @ExtensionFunctionType +// END +// FILE: a.kt +annotation class A + +val strExt0: String.() -> Unit = TODO() +val strExt1: String.(Int) -> Unit = TODO() +val strWithAnnoExt0: @A String.() -> Unit = TODO() +val strWithAnnoExt1: @A String.(@A Int) -> Unit = TODO() diff --git a/test-utils/testData/api/functionTypes.kt b/test-utils/testData/api/functionTypes.kt new file mode 100644 index 00000000..69f8366f --- /dev/null +++ b/test-utils/testData/api/functionTypes.kt @@ -0,0 +1,72 @@ +/* + * Copyright 2021 Google LLC + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// WITH_RUNTIME +// TEST PROCESSOR: FunctionTypeProcessor +// EXPECTED: +// a: Function0 : true, false +// b: Function1 : true, false +// c: Function0 : true, false +// d: Function2 : true, false +// e: KFunction0 : true, false +// f: KSuspendFunction0 : false, true +// g: KFunction1 : true, false +// h: KSuspendFunction1 : false, true +// i: Function1 : true, false +// j: SuspendFunction1 : false, true +// k: SuspendFunction0 : false, true +// l: SuspendFunction1 : false, true +// m: SuspendFunction0 : false, true +// n: SuspendFunction2 : false, true +// o: KFunction0 : true, false +// p: KSuspendFunction0 : false, true +// vbar: KSuspendFunction0 : false, true +// vfoo: KFunction0 : true, false +// END + +@file:Suppress("Boolean", "Byte", "Int", "Short", "Double", "Float", "Unit", "Suppress", "C") + +class C { + fun foo(): Boolean = true + suspend fun bar(): Int = 0 + val vfoo = ::foo + val vbar = ::bar +} + +fun foo() = Unit +suspend fun bar() = Unit + +val a: () -> Unit = TODO() +val b: (Int) -> Unit = TODO() +val c: () -> Byte = TODO() +val d: (Short, Float) -> Double = TODO() + +val e = C().vfoo +val f = C().vbar +val g = C::foo +val h = C::bar + +val i: Int.() -> Boolean = TODO() +val j: suspend Boolean.() -> Int = TODO() + +val k: suspend () -> Unit = TODO() +val l: suspend (Int) -> Unit = TODO() +val m: suspend () -> Byte = TODO() +val n: suspend (Short, Float) -> Double = TODO() + +val o = ::foo +val p = ::bar diff --git a/test-utils/testData/api/getAnnotationByTypeWithInnerDefault.kt b/test-utils/testData/api/getAnnotationByTypeWithInnerDefault.kt new file mode 100644 index 00000000..56346813 --- /dev/null +++ b/test-utils/testData/api/getAnnotationByTypeWithInnerDefault.kt @@ -0,0 +1,42 @@ +/* + * Copyright 2022 Google LLC + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// WITH_RUNTIME +// TEST PROCESSOR: GetAnnotationByTypeProcessor +// EXPECTED: +// com.google.devtools.ksp.processor.KotlinAnnotationWithInnerDefaults.InnerAnnotation[innerAnnotationDefault=7, moreInnerAnnotation=com.google.devtools.ksp.processor.KotlinAnnotationWithInnerDefaults.InnerAnnotation.MoreInnerAnnotation[moreInnerAnnotationDefault=OK]] +// END +// MODULE: lib +// FILE: KotlinAnnotationWithInnerDefaults.kt +package com.google.devtools.ksp.processor +annotation class KotlinAnnotationWithInnerDefaults( + val innerAnnotationVal: InnerAnnotation = InnerAnnotation(innerAnnotationDefault = 7) +) { + annotation class InnerAnnotation( + val innerAnnotationDefault: Int, + val moreInnerAnnotation: MoreInnerAnnotation = MoreInnerAnnotation("OK") + ) { + annotation class MoreInnerAnnotation(val moreInnerAnnotationDefault: String) + } +} + +// MODULE: main(lib) +// FILE: com/google/devtools/ksp/processor/a.kt +package com.google.devtools.ksp.processor + +@KotlinAnnotationWithInnerDefaults +class A diff --git a/test-utils/testData/api/getByName.kt b/test-utils/testData/api/getByName.kt new file mode 100644 index 00000000..51f826b0 --- /dev/null +++ b/test-utils/testData/api/getByName.kt @@ -0,0 +1,77 @@ +/* + * Copyright 2021 Google LLC + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// TEST PROCESSOR: GetByNameProcessor +// EXPECTED: +// all success +// END +// MODULE: lib1 +// FILE: foo.kt +package lib1 + +open class Foo { + fun lib1MemberFun() = 1 + fun overload(a: Int) = "Overload" + fun overload() = "Overload" + val lib1MemberProp = 1.0 + + class FooNested {} +} + +fun lib1TopFun(): Int { + return 1 +} + +val lib1TopProp = "1" + +// FILE: Bar.java +package lib1; + +class Bar { + public int lib1JavaMemberFun() { + return 1; + } +} + +// MODULE: lib2 +// FILE: foo.kt +package lib2 + +class Foo { + fun lib2MemberFun() = 1 + val lib2MemberProp = 1.0 +} + +// MODULE: main(lib1, lib2) +// FILE: a.kt +package source + +class FooInSource { + fun sourceMemberFun() = 1 + val sourceMemberProp = 1.0 + class FooInSourceNested +} + +val propInSource = 1 +// FILE: main.kt +package main +import lib1.Foo + +class KotlinMain : Foo { + fun lib1MemberFun(a: Int) = 1 +} + diff --git a/test-utils/testData/api/getPackage.kt b/test-utils/testData/api/getPackage.kt new file mode 100644 index 00000000..537be348 --- /dev/null +++ b/test-utils/testData/api/getPackage.kt @@ -0,0 +1,99 @@ +/* + * Copyright 2021 Google LLC + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// TEST PROCESSOR: GetPackageProcessor +// EXPECTED: +// symbols from package lib1 +// lib1.FooInSource KOTLIN +// lib1.propInSource KOTLIN +// lib1.Bar JAVA_LIB +// lib1.Foo KOTLIN_LIB +// lib1.funcFoo KOTLIN_LIB +// symbols from package lib2 +// lib2.Foo KOTLIN_LIB +// lib2.a KOTLIN_LIB +// symbols from package main.test +// main.test.KotlinMain KOTLIN +// main.test.C JAVA +// main.test.D JAVA +// END + +// MODULE: lib1 +// FILE: foo.kt +package lib1 + +class Foo + +fun funcFoo(): Int { + return 1 +} + +// FILE: Bar.java +package lib1; + +class Bar {} + +// MODULE: lib2 +// FILE: foo.kt +package lib2 + +class Foo + +val a = 0 + +// FILE: Bar.java + +class Bar {} + +// MODULE: main(lib1, lib2) +// FILE: a.kt +package lib1 +class FooInSource + +val propInSource = 1 +// FILE: main.kt +package main.test + +class KotlinMain + +// FILE: main/test/C.java +package main.test; + +public class C { + +} + +class D { + +} + +// FILE: wrongDir/K.java +package main; + +public class K { + +} + +class KK {} + + +// FILE: main/test/main/test/L.java +package main.test; + +public class L { + +} diff --git a/test-utils/testData/api/getSymbolsFromAnnotation.kt b/test-utils/testData/api/getSymbolsFromAnnotation.kt new file mode 100644 index 00000000..587e3f59 --- /dev/null +++ b/test-utils/testData/api/getSymbolsFromAnnotation.kt @@ -0,0 +1,161 @@ +/* + * Copyright 2022 Google LLC + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// TEST PROCESSOR: GetSymbolsFromAnnotationProcessor +// EXPECTED: +// ==== Anno superficial==== +// Foo:KSClassDeclaration +// <init>:KSFunctionDeclaration +// constructorParameterFoo:KSValueParameter +// param:KSValueParameter +// constructorParameterFoo:KSPropertyDeclaration +// propertyFoo:KSPropertyDeclaration +// functionFoo:KSFunctionDeclaration +// p1:KSValueParameter +// Bar:KSClassDeclaration +// Baz:KSClassDeclaration +// Burp:KSClassDeclaration +// Flux:KSTypeAlias +// ==== Anno in depth ==== +// Foo:KSClassDeclaration +// <init>:KSFunctionDeclaration +// constructorParameterFoo:KSValueParameter +// param:KSValueParameter +// constructorParameterFoo:KSPropertyDeclaration +// propertyFoo:KSPropertyDeclaration +// functionFoo:KSFunctionDeclaration +// p1:KSValueParameter +// local:KSPropertyDeclaration +// Bar:KSClassDeclaration +// Baz:KSClassDeclaration +// Burp:KSClassDeclaration +// Flux:KSTypeAlias +// ==== Bnno superficial==== +// File: Foo.kt:KSFile +// <init>:KSFunctionDeclaration +// propertyFoo.getter():KSPropertyAccessorImpl +// p2:KSValueParameter +// ==== Bnno in depth ==== +// File: Foo.kt:KSFile +// <init>:KSFunctionDeclaration +// propertyFoo.getter():KSPropertyAccessorImpl +// p2:KSValueParameter +// ==== A1 superficial==== +// Foo:KSClassDeclaration +// <init>:KSFunctionDeclaration +// constructorParameterFoo:KSValueParameter +// param:KSValueParameter +// constructorParameterFoo:KSPropertyDeclaration +// propertyFoo:KSPropertyDeclaration +// functionFoo:KSFunctionDeclaration +// p1:KSValueParameter +// Bar:KSClassDeclaration +// Baz:KSClassDeclaration +// Burp:KSClassDeclaration +// Flux:KSTypeAlias +// ==== A1 in depth ==== +// Foo:KSClassDeclaration +// <init>:KSFunctionDeclaration +// constructorParameterFoo:KSValueParameter +// param:KSValueParameter +// constructorParameterFoo:KSPropertyDeclaration +// propertyFoo:KSPropertyDeclaration +// functionFoo:KSFunctionDeclaration +// p1:KSValueParameter +// local:KSPropertyDeclaration +// Bar:KSClassDeclaration +// Baz:KSClassDeclaration +// Burp:KSClassDeclaration +// Flux:KSTypeAlias +// ==== A2 superficial==== +// Foo:KSClassDeclaration +// <init>:KSFunctionDeclaration +// constructorParameterFoo:KSValueParameter +// param:KSValueParameter +// constructorParameterFoo:KSPropertyDeclaration +// propertyFoo:KSPropertyDeclaration +// functionFoo:KSFunctionDeclaration +// p1:KSValueParameter +// Bar:KSClassDeclaration +// Baz:KSClassDeclaration +// Burp:KSClassDeclaration +// Flux:KSTypeAlias +// ==== A2 in depth ==== +// Foo:KSClassDeclaration +// <init>:KSFunctionDeclaration +// constructorParameterFoo:KSValueParameter +// param:KSValueParameter +// constructorParameterFoo:KSPropertyDeclaration +// propertyFoo:KSPropertyDeclaration +// functionFoo:KSFunctionDeclaration +// p1:KSValueParameter +// local:KSPropertyDeclaration +// Bar:KSClassDeclaration +// Baz:KSClassDeclaration +// Burp:KSClassDeclaration +// Flux:KSTypeAlias +// ==== Cnno in depth ==== +// constructorParameterFoo:KSValueParameter +// <set-?>:KSValueParameter +// x:KSValueParameter +// x:KSPropertyDeclaration +// END +//FILE: annotations.kt +annotation class Anno +annotation class Bnno +annotation class Cnno +typealias A1 = Anno +typealias A2 = A1 + +//FILE: Foo.kt +@file:Bnno + +import Anno +import Anno as A3 + +@Anno +class Foo @Anno constructor(@Anno @param:Cnno val constructorParameterFoo: Int, @Anno param: Int){ + @Bnno constructor() { + + } + + @Anno + val propertyFoo: String + @Bnno get() = TODO() + + @Anno + fun functionFoo(@Anno p1: Int, @Bnno p2: Int) { + @Anno val local = 1 + } + + @setparam:Cnno + var a = 1 +} + +class C(@Cnno val x: Int) + +@A1 +class Bar + +@A2 +class Baz + +@A3 +class Burp + +@Anno +typealias Flux = String diff --git a/test-utils/testData/api/hello.kt b/test-utils/testData/api/hello.kt new file mode 100644 index 00000000..f8949c69 --- /dev/null +++ b/test-utils/testData/api/hello.kt @@ -0,0 +1,116 @@ +/* + * Copyright 2020 Google LLC + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// WITH_RUNTIME +// TEST PROCESSOR: HelloProcessor +// EXPECTED: +// 8 +// AClass +// Bar.BBB +// Bar.list +// C +// C.f +// C.javaFun +// test.Foo +// test.ITF +// END +//FILE: a.kt +package test +annotation class Anno + + +@Anno +class Foo() { + val k = "123" + var a : String = "123" + val aaa : (Int) -> Int = { a -> 1 } + fun bar(): Int { +// val aa = 1234 + return 3 + } +} + +@Anno +interface ITF<T> { + fun fooITF() = 1 +} + +//FILE: b.kt +import test.Anno +import test.ITF + +class Bar<out S, out D>() : ITF<D> { + @Anno + val list : List<Int>? = null + val funInObj = foo() + open internal fun foo(c: C, dd: () -> D): Int { + val a = 1 +// fun <TTT> foo(c: C, dd: () -> TTT): Int { +// return 1 +// } + return 1 + } + @Anno + class BBB { + fun <TTA: String> fofo(c: C, dd: () -> TTA): Int { + return 1 + } + fun <TTA: Int> fofofo(c: C, dd: () -> TTA): Int { + return 1 + } + } + val a = 1 + + val kk + get() = 1 + + companion object { + val s = 1 + fun foo() = 123 + } +} + +//FILE: c.kt +import test.Anno + +@Anno +class AClass(val a: Int, val b: String, c: Double) { + fun foo() = a + b.length + c +} + +fun <D> foo(c: C, dd: () -> D) = 1 + +class CC: C() {} + +// FILE: C.java +import java.util.List; +import java.util.ArrayList; +import test.Foo; +import test.ITF; +import test.Anno; + +@Anno +class C { + @Anno + public Foo f = new Foo(); + List<? extends ITF> list = new ArrayList<>(); + + @Anno + public String javaFun() { + return f.k; + } +} diff --git a/test-utils/testData/api/implicitElements.kt b/test-utils/testData/api/implicitElements.kt new file mode 100644 index 00000000..88d670c5 --- /dev/null +++ b/test-utils/testData/api/implicitElements.kt @@ -0,0 +1,69 @@ +/* + * Copyright 2020 Google LLC + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// TEST PROCESSOR: ImplicitElementProcessor +// EXPECTED: +// <init>; origin: SYNTHETIC +// synthetic constructor for Cls +// <null> +// <null> +// <init>,<init>,<init> +// readOnly.get(): SYNTHETIC annotations from property: GetAnno +// readOnly.getter.owner: readOnly: KOTLIN +// readWrite.get(): KOTLIN +// readWrite.set(): SYNTHETIC annotations from property: SetAnno +// <init> +// comp1.get(): SYNTHETIC +// comp2.get(): SYNTHETIC +// comp2.set(): SYNTHETIC +// GetAnno +// <init> +// synthetic constructor for ImplictConstructorJava +// END +// FILE: a.kt +annotation class GetAnno +annotation class SetAnno + +class Cls { + @get:GetAnno + val readOnly: Int = 1 + + @set:SetAnno + var readWrite: Int = 2 + get() = 1 +} + +data class Data(@get:GetAnno val comp1: Int, var comp2: Int) + +class ClassWithoutImplicitPrimaryConstructor : ITF { + constructor(x: Int) +} + +interface ITF + +// FILE: JavaClass.java +public class JavaClass { + public JavaClass() { this(1); } + public JavaClass(int a) { this(a, "ok"); } + public JavaClass(int a, String s) { } +} + +// FILE:ImplictConstructorJava.java + +public class ImplictConstructorJava { + +}
\ No newline at end of file diff --git a/test-utils/testData/api/implicitPropertyAccessors.kt b/test-utils/testData/api/implicitPropertyAccessors.kt new file mode 100644 index 00000000..af885296 --- /dev/null +++ b/test-utils/testData/api/implicitPropertyAccessors.kt @@ -0,0 +1,34 @@ +/* + * Copyright 2022 Google LLC + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// TEST PROCESSOR: ImplicitPropertyAccessorProcessor +// EXPECTED: +// Int +// String +// <set-?> +// String +// END +// FILE: a.kt + +class Foo { + val privateGetterVal: Int + private get + + var privateGetterVar: String + set + private get +} diff --git a/test-utils/testData/api/inheritedTypeAlias.kt b/test-utils/testData/api/inheritedTypeAlias.kt new file mode 100644 index 00000000..9fa622c3 --- /dev/null +++ b/test-utils/testData/api/inheritedTypeAlias.kt @@ -0,0 +1,36 @@ +/* + * Copyright 2022 Google LLC + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// TEST PROCESSOR: InheritedTypeAliasProcessor +// EXPECTED: +// sub: arg :INVARIANT Float +// sub: prop :INVARIANT Int +// super: arg :INVARIANT Float +// super: prop :INVARIANT Int +// END + +typealias AliasMap<T> = Map<String, T> +typealias AliasFun<T> = (T) -> Double + + +interface Sub : Super + + +interface Super { + val prop: AliasMap<Int> + fun foo(arg: AliasFun<Float>) +} diff --git a/test-utils/testData/api/innerTypes.kt b/test-utils/testData/api/innerTypes.kt new file mode 100644 index 00000000..ee3c5d80 --- /dev/null +++ b/test-utils/testData/api/innerTypes.kt @@ -0,0 +1,51 @@ +/* + * Copyright 2021 Google LLC + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// WITH_RUNTIME +// TEST PROCESSOR: InnerTypeProcessor +// EXPECTED: +// C1<*>: [C1<STAR Any>] +// C1<Int>: [C1<INVARIANT Int>] +// C2<*, *>: [C1.C2<STAR Any>, C1<STAR Any>] +// C2<Short, Int>: [C1.C2<INVARIANT Short>, C1<INVARIANT Int>] +// C3<*, *, *>: [C1.C2.C3<STAR Any>, C1.C2<STAR Any>, C1<STAR Any>] +// C3<Byte, Short, Int>: [C1.C2.C3<INVARIANT Byte>, C1.C2<INVARIANT Short>, C1<INVARIANT Int>] +// C4<*>: [C1.C4<STAR Any>] +// C4<Double>: [C1.C4<INVARIANT Double>] +// C5<*, *>: [C1.C4.C5<STAR Any>, C1.C4<STAR Any>] +// C5<Float, Double>: [C1.C4.C5<INVARIANT Float>, C1.C4<INVARIANT Double>] +// END + +@file:Suppress("Byte", "Int", "Short", "Double", "Float", "Suppress", "Any") + +class C1<T1> { + inner class C2<T2> { + inner class C3<T3> { + + } + } + + class C4<T4> { + inner class C5<T5> + } +} + +val c1 = C1<Int>() +val c2 = c1.C2<Short>() +val c3 = c2.C3<Byte>() +val c4 = C1.C4<Double>() +val c5 = c4.C5<Float>() diff --git a/test-utils/testData/api/interfaceWithDefault.kt b/test-utils/testData/api/interfaceWithDefault.kt new file mode 100644 index 00000000..75a005f1 --- /dev/null +++ b/test-utils/testData/api/interfaceWithDefault.kt @@ -0,0 +1,78 @@ +/* + * Copyright 2020 Google LLC + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// TEST PROCESSOR: DefaultFunctionProcessor +// EXPECTED: +// funLiteral: false +// funWithBody: false +// emptyFun: true +// foo: false +// bar: true +// iterator: true +// equals: false +// interfaceProperty: isAbstract: true: isMutable: false +// interfaceVar: isAbstract: true: isMutable: true +// nonAbstractInterfaceProp: isAbstract: false: isMutable: false +// B: true +// parameterVal: isAbstract: false: isMutable: false +// parameterVar: isAbstract: false: isMutable: true +// abstractVar: isAbstract: true: isMutable: true +// abstractProperty: isAbstract: true: isMutable: false +// a: false +// normalField: isMutable: true +// finalField: isMutable: false +// END +// FILE: a.kt +interface KTInterface: Sequence<String> { + fun funLiteral() = 1 + + fun funWithBody(): Int { + return 1 + } + + fun emptyFun() + + val interfaceProperty: String + + var interfaceVar: Int + + val nonAbstractInterfaceProp: Int + get() = 1 +} + +abstract class B(val parameterVal: String, var parameterVar: String) { + abstract var abstractVar: String + abstract val abstractProperty: String + val a: String = "str" +} + +// FILE: C.java +interface C { + default int foo() { + return 1; + } + + int bar() +} + +// FILE: D.java + +class D { + int normalField; + + final int finalField; +} diff --git a/test-utils/testData/api/javaAnnotatedUtil.kt b/test-utils/testData/api/javaAnnotatedUtil.kt new file mode 100644 index 00000000..e6da243a --- /dev/null +++ b/test-utils/testData/api/javaAnnotatedUtil.kt @@ -0,0 +1,171 @@ +/* + * Copyright 2021 Google LLC + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// TEST PROCESSOR: AnnotatedUtilProcessor +// EXPECTED: +// Test: OnlyTestAnnotation +// Test: ParametersTestAnnotationWithValuesTest +// IsPresent: class com.google.devtools.ksp.processor.ParametersTestAnnotation +// ByType: com.google.devtools.ksp.processor.ParametersTestAnnotation[booleanValue=true, byteValue=5, shortValue=202, charValue=k, doubleValue=5.12, floatValue=123.3, intValue=2, longValue=4, stringValue=someValue, kClassValue=class java.lang.Throwable, enumValue=VALUE1] +// Test: ParametersTestAnnotationWithIntegerLiteralValuesTest +// IsPresent: class com.google.devtools.ksp.processor.ParametersTestAnnotation +// ByType: com.google.devtools.ksp.processor.ParametersTestAnnotation[booleanValue=true, byteValue=5, shortValue=202, charValue=k, doubleValue=5.0, floatValue=123.0, intValue=2, longValue=4, stringValue=someValue, kClassValue=class java.lang.Throwable, enumValue=VALUE1] +// Test: ParametersTestAnnotationWithDefaultsTest +// IsPresent: class com.google.devtools.ksp.processor.ParametersTestAnnotation +// ByType: com.google.devtools.ksp.processor.ParametersTestAnnotation[booleanValue=false, byteValue=2, shortValue=3, charValue=b, doubleValue=4.0, floatValue=5.0, intValue=6, longValue=7, stringValue=emptystring, kClassValue=interface com.google.devtools.ksp.processor.ParametersTestAnnotation, enumValue=NONE] +// ByType: com.google.devtools.ksp.processor.ParametersTestAnnotation[booleanValue=false, byteValue=2, shortValue=3, charValue=b, doubleValue=4.0, floatValue=5.0, intValue=6, longValue=7, stringValue=emptystring, kClassValue=interface com.google.devtools.ksp.processor.ParametersTestAnnotation, enumValue=NONE] +// Test: ParametersTestWithNegativeDefaultsAnnotationTest +// IsPresent: class com.google.devtools.ksp.processor.ParametersTestWithNegativeDefaultsAnnotation +// ByType: com.google.devtools.ksp.processor.ParametersTestWithNegativeDefaultsAnnotation[byteValue=-2, shortValue=-3, doubleValue=-4.0, floatValue=-5.0, intValue=-6, longValue=-7] +// ByType: com.google.devtools.ksp.processor.ParametersTestWithNegativeDefaultsAnnotation[byteValue=-2, shortValue=-3, doubleValue=-4.0, floatValue=-5.0, intValue=-6, longValue=-7] +// Test: ParameterArraysTestAnnotationWithDefaultTest +// IsPresent: class com.google.devtools.ksp.processor.ParameterArraysTestAnnotation +// ByType: ParameterArraysTestAnnotation[booleanArrayValue=[true, false],byteArrayValue=[-2, 4],shortArrayValue=[-1, 2, 3],charArrayValue=[a, b, c],doubleArrayValue=[1.1, 2.2, 3.3],floatArrayValue=[1.0, 2.0, 3.3],intArrayValue=[1, 2, 4, 8, 16],longArrayValue=[1, 2, 4, 8, 16, 32],stringArrayValue=[first, second, third],kClassArrayValue=[class kotlin.Throwable, class com.google.devtools.ksp.processor.ParametersTestAnnotation],enumArrayValue=[VALUE1, VALUE2, VALUE1, VALUE2]] +// Test: AnnotationWithinAnAnnotationTest +// IsPresent: class com.google.devtools.ksp.processor.OuterAnnotation +// ByType: com.google.devtools.ksp.processor.OuterAnnotation[innerAnnotation=com.google.devtools.ksp.processor.InnerAnnotation[value=hello from the other side]] +// END +// FILE: com/google/devtools/ksp/processor/A.java +package com.google.devtools.ksp.processor; + +import kotlin.reflect.KClass + +public class A {} + + +public @interface Test {} + +public @interface ParametersTestAnnotation { + Boolean booleanValue() default false; + Byte byteValue() default 2; + Short shortValue() default 3; + Char charValue() default 'b'; + Double doubleValue() default 4.0; + Float floatValue() default 5.0f; + Int intValue() default 6; + Long longValue() default 7L; + String stringValue() default "emptystring"; + Class<?> kClassValue() default ParametersTestAnnotation.class; + TestEnum enumValue() default TestEnum.NONE; +} + +public @interface ParametersTestWithNegativeDefaultsAnnotation { + Byte byteValue() default -2; + Short shortValue() default -3; + Double doubleValue() default -4.0; + Float floatValue() default -5.0f; + Int intValue() default -6; + Long longValue() default -7L; +} + +public @interface ParameterArraysTestAnnotation { + boolean[] booleanArrayValue(); + byte[] byteArrayValue() default { }; + short[] shortArrayValue() default { }; + char[] charArrayValue() default { }; + double[] doubleArrayValue() default { }; + float[] floatArrayValue() default { }; + int[] intArrayValue() default { }; + long[] longArrayValue() default { }; + string[] stringArrayValue() default { }; + Class[] kClassArrayValue() default { }; + TestEnum[] enumArrayValue() default { }; +} + +public enum TestEnum { + NONE, VALUE1, VALUE2; +} + +public @interface InnerAnnotation { + String value() default "defaultValue"; +} + +public @interface OuterAnnotation { + InnerAnnotation innerAnnotation() default InnerAnnotation(); +} + +///////////////////////////////////////////////////////// +// Tests +///////////////////////////////////////////////////////// + +@Test +@Test +public class OnlyTestAnnotation {} + +@ParametersTestAnnotation( + booleanValue = true, + byteValue = 5, + shortValue = 202, + charValue = 'k', + doubleValue = 5.12, + floatValue = 123.3f, + intValue = 2, + longValue = 4L, + stringValue = "someValue", + kClassValue = java.lang.Throwable.class, + enumValue = TestEnum.VALUE1 +) +@Test +public class ParametersTestAnnotationWithValuesTest {} + +@ParametersTestAnnotation( + booleanValue = true, + byteValue = 5, + shortValue = 202, + charValue = 'k', + doubleValue = 5, + floatValue = 123, + intValue = 2, + longValue = 4, + stringValue = "someValue", + kClassValue = java.lang.Throwable.class, + enumValue = TestEnum.VALUE1 +) +@Test +public class ParametersTestAnnotationWithIntegerLiteralValuesTest {} + +@ParametersTestAnnotation +@ParametersTestAnnotation +@Test +public class ParametersTestAnnotationWithDefaultsTest {} + +@ParametersTestWithNegativeDefaultsAnnotation +@ParametersTestWithNegativeDefaultsAnnotation +@Test +public class ParametersTestWithNegativeDefaultsAnnotationTest {} + +@ParameterArraysTestAnnotation( + booleanArrayValue = {true, false}, + byteArrayValue = {-2, 4}, + shortArrayValue = {-1, 2, 3}, + charArrayValue = {'a', 'b', 'c'}, + doubleArrayValue = {1.1, 2.2, 3.3}, + floatArrayValue = {1.0f, 2.0f, 3.3f}, + intArrayValue = {1, 2, 4, 8, 16}, + longArrayValue = {1L, 2L, 4L, 8L, 16, 32L}, + stringArrayValue = {"first", "second", "third"}, + kClassArrayValue = {java.lang.Throwable.class, ParametersTestAnnotation.class}, + enumArrayValue = {TestEnum.VALUE1, TestEnum.VALUE2, TestEnum.VALUE1, TestEnum.VALUE2} +) +@Test +public class ParameterArraysTestAnnotationWithDefaultTest {} + +@OuterAnnotation(innerAnnotation = @InnerAnnotation(value = "hello from the other side")) +@Test +public class AnnotationWithinAnAnnotationTest {} + +// FILE: Annotations.kt diff --git a/test-utils/testData/api/javaModifiers.kt b/test-utils/testData/api/javaModifiers.kt new file mode 100644 index 00000000..04aa1c0d --- /dev/null +++ b/test-utils/testData/api/javaModifiers.kt @@ -0,0 +1,244 @@ +/* + * Copyright 2020 Google LLC + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// TEST PROCESSOR: JavaModifierProcessor +// EXPECTED: +// C: ABSTRACT PUBLIC : ABSTRACT PUBLIC +// C.staticStr: PRIVATE : PRIVATE +// C.s1: FINAL JAVA_TRANSIENT : FINAL JAVA_TRANSIENT +// C.i1: JAVA_STATIC JAVA_VOLATILE PROTECTED : JAVA_STATIC JAVA_VOLATILE PROTECTED +// C.NestedC: JAVA_STATIC PUBLIC : JAVA_STATIC PUBLIC +// NestedC.<init>: FINAL PUBLIC : FINAL PUBLIC +// C.InnerC: PUBLIC : PUBLIC +// InnerC.<init>: FINAL PUBLIC : FINAL PUBLIC +// C.intFun: JAVA_DEFAULT JAVA_SYNCHRONIZED : JAVA_DEFAULT JAVA_SYNCHRONIZED +// C.foo: ABSTRACT JAVA_STRICT : ABSTRACT JAVA_STRICT +// C.<init>: FINAL PUBLIC : FINAL PUBLIC +// OuterJavaClass: PUBLIC : PUBLIC +// OuterJavaClass.staticPublicField: JAVA_STATIC PUBLIC : JAVA_STATIC PUBLIC +// OuterJavaClass.staticPackageProtectedField: JAVA_STATIC : JAVA_STATIC +// OuterJavaClass.staticProtectedField: JAVA_STATIC PROTECTED : JAVA_STATIC PROTECTED +// OuterJavaClass.staticPrivateField: JAVA_STATIC PRIVATE : JAVA_STATIC PRIVATE +// OuterJavaClass.InnerJavaClass: PUBLIC : PUBLIC +// InnerJavaClass.<init>: FINAL PUBLIC : FINAL PUBLIC +// OuterJavaClass.NestedJavaClass: JAVA_STATIC PUBLIC : JAVA_STATIC PUBLIC +// NestedJavaClass.<init>: FINAL PUBLIC : FINAL PUBLIC +// OuterJavaClass.staticPublicMethod: JAVA_STATIC PUBLIC : JAVA_STATIC PUBLIC +// OuterJavaClass.staticPackageProtectedMethod: JAVA_STATIC : JAVA_STATIC +// OuterJavaClass.staticProtectedMethod: JAVA_STATIC PROTECTED : JAVA_STATIC PROTECTED +// OuterJavaClass.staticPrivateMethod: JAVA_STATIC PRIVATE : JAVA_STATIC PRIVATE +// OuterJavaClass.<init>: FINAL PUBLIC : FINAL PUBLIC +// OuterKotlinClass: OPEN : PUBLIC +// OuterKotlinClass.InnerKotlinClass: INNER : FINAL PUBLIC +// InnerKotlinClass.<init>: FINAL PUBLIC : FINAL PUBLIC +// OuterKotlinClass.NestedKotlinClass: OPEN : PUBLIC +// NestedKotlinClass.<init>: FINAL PUBLIC : FINAL PUBLIC +// OuterKotlinClass.Companion: : FINAL JAVA_STATIC PUBLIC +// Companion.companionMethod: : FINAL PUBLIC +// Companion.companionField: CONST : FINAL PUBLIC +// Companion.privateCompanionMethod: PRIVATE : FINAL PRIVATE +// Companion.privateCompanionField: PRIVATE : FINAL PRIVATE +// Companion.jvmStaticCompanionMethod: : FINAL JAVA_STATIC PUBLIC +// Companion.jvmStaticCompanionField: : FINAL JAVA_STATIC PUBLIC +// Companion.customJvmStaticCompanionMethod: : FINAL PUBLIC +// Companion.customJvmStaticCompanionField: : FINAL PUBLIC +// Companion.<init>: FINAL PUBLIC : FINAL PUBLIC +// OuterKotlinClass.transientProperty: : FINAL JAVA_TRANSIENT PUBLIC +// OuterKotlinClass.volatileProperty: : FINAL JAVA_VOLATILE PUBLIC +// OuterKotlinClass.strictfpFun: : FINAL JAVA_STRICT PUBLIC +// OuterKotlinClass.synchronizedFun: : FINAL JAVA_SYNCHRONIZED PUBLIC +// OuterKotlinClass.<init>: FINAL PUBLIC : FINAL PUBLIC +// DependencyOuterJavaClass: OPEN PUBLIC : PUBLIC +// DependencyOuterJavaClass.DependencyNestedJavaClass: OPEN PUBLIC : PUBLIC +// DependencyNestedJavaClass.<init>: FINAL PUBLIC : FINAL PUBLIC +// DependencyOuterJavaClass.DependencyInnerJavaClass: INNER OPEN PUBLIC : PUBLIC +// DependencyInnerJavaClass.<init>: FINAL PUBLIC : FINAL PUBLIC +// DependencyOuterJavaClass.synchronizedFun: JAVA_SYNCHRONIZED OPEN : JAVA_SYNCHRONIZED +// DependencyOuterJavaClass.strictfpFun: JAVA_STRICT OPEN : JAVA_STRICT +// DependencyOuterJavaClass.transientField: FINAL JAVA_TRANSIENT : FINAL JAVA_TRANSIENT +// DependencyOuterJavaClass.volatileField: FINAL JAVA_VOLATILE : FINAL JAVA_VOLATILE +// DependencyOuterJavaClass.staticPublicMethod: JAVA_STATIC PUBLIC : JAVA_STATIC PUBLIC +// DependencyOuterJavaClass.staticPackageProtectedMethod: JAVA_STATIC : JAVA_STATIC +// DependencyOuterJavaClass.staticProtectedMethod: JAVA_STATIC PROTECTED : JAVA_STATIC PROTECTED +// DependencyOuterJavaClass.staticPrivateMethod: JAVA_STATIC PRIVATE : JAVA_STATIC PRIVATE +// DependencyOuterJavaClass.staticPublicField: FINAL JAVA_STATIC PUBLIC : FINAL JAVA_STATIC PUBLIC +// DependencyOuterJavaClass.staticPackageProtectedField: FINAL JAVA_STATIC : FINAL JAVA_STATIC +// DependencyOuterJavaClass.staticProtectedField: FINAL JAVA_STATIC PROTECTED : FINAL JAVA_STATIC PROTECTED +// DependencyOuterJavaClass.staticPrivateField: FINAL JAVA_STATIC PRIVATE : FINAL JAVA_STATIC PRIVATE +// DependencyOuterJavaClass.<init>: FINAL PUBLIC : FINAL PUBLIC +// DependencyOuterKotlinClass: OPEN PUBLIC : PUBLIC +// DependencyOuterKotlinClass.transientProperty: FINAL PUBLIC : FINAL JAVA_TRANSIENT PUBLIC +// DependencyOuterKotlinClass.volatileProperty: FINAL PUBLIC : FINAL JAVA_VOLATILE PUBLIC +// DependencyOuterKotlinClass.strictfpFun: FINAL PUBLIC : FINAL JAVA_STRICT PUBLIC +// DependencyOuterKotlinClass.synchronizedFun: FINAL PUBLIC : FINAL JAVA_SYNCHRONIZED PUBLIC +// DependencyOuterKotlinClass.Companion: FINAL PUBLIC : FINAL PUBLIC +// Companion.companionField: FINAL PUBLIC : FINAL PUBLIC +// Companion.customJvmStaticCompanionField: FINAL PUBLIC : FINAL PUBLIC +// Companion.jvmStaticCompanionField: FINAL PUBLIC : FINAL PUBLIC +// Companion.privateCompanionField: FINAL PUBLIC : FINAL PUBLIC +// Companion.companionMethod: FINAL PUBLIC : FINAL PUBLIC +// Companion.customJvmStaticCompanionMethod: FINAL PUBLIC : FINAL PUBLIC +// Companion.jvmStaticCompanionMethod: FINAL PUBLIC : FINAL PUBLIC +// Companion.privateCompanionMethod: FINAL PRIVATE : FINAL PRIVATE +// Companion.<init>: FINAL PRIVATE : FINAL PRIVATE +// DependencyOuterKotlinClass.DependencyInnerKotlinClass: FINAL INNER PUBLIC : FINAL PUBLIC +// DependencyInnerKotlinClass.<init>: FINAL PUBLIC : FINAL PUBLIC +// DependencyOuterKotlinClass.DependencyNestedKotlinClass: OPEN PUBLIC : PUBLIC +// DependencyNestedKotlinClass.<init>: FINAL PUBLIC : FINAL PUBLIC +// DependencyOuterKotlinClass.<init>: FINAL PUBLIC : FINAL PUBLIC +// END +// MODULE: module1 +// FILE: DependencyOuterJavaClass.java +public class DependencyOuterJavaClass { + public class DependencyInnerJavaClass {} + public static class DependencyNestedJavaClass {} + public static void staticPublicMethod() {} + public static String staticPublicField; + static void staticPackageProtectedMethod() {} + static String staticPackageProtectedField; + protected static void staticProtectedMethod() {} + protected static String staticProtectedField; + private static void staticPrivateMethod() {} + private static String staticPrivateField; + transient String transientField = ""; + volatile String volatileField = ""; + synchronized String synchronizedFun() { return ""; } + strictfp String strictfpFun() { return ""; } +} +// FILE: DependencyOuterKotlinClass.kt +typealias DependencyCustomJvmStatic=JvmStatic +open class DependencyOuterKotlinClass { + inner class DependencyInnerKotlinClass + open class DependencyNestedKotlinClass + companion object { + fun companionMethod() {} + val companionField:String = "" + private fun privateCompanionMethod() {} + val privateCompanionField:String = "" + @JvmStatic + fun jvmStaticCompanionMethod() {} + @JvmStatic + val jvmStaticCompanionField:String = "" + @DependencyCustomJvmStatic + fun customJvmStaticCompanionMethod() {} + @DependencyCustomJvmStatic + val customJvmStaticCompanionField:String = "" + } + + @Transient + val transientProperty: String = "" + + @Volatile + var volatileProperty: String = "" + + @Strictfp + fun strictfpFun(): String = "" + + @Synchronized + fun synchronizedFun(): String = "" +} +// MODULE: main(module1) +// FILE: a.kt +annotation class Test + +@Test +class Foo : C() { + +} + +@Test +class Bar : OuterJavaClass() + +@Test +class Baz : OuterKotlinClass() + +@Test +class JavaDependency : DependencyOuterJavaClass() + +@Test +class KotlinDependency : DependencyOuterKotlinClass() + +// FILE: C.java + +public abstract class C { + + private String staticStr = "str" + + final transient String s1; + + protected static volatile int i1; + + default synchronized int intFun() { + return 1; + } + + abstract strictfp void foo() {} + + public static class NestedC { + + } + + public class InnerC { + + } +} + +// FILE: OuterJavaClass.java +public class OuterJavaClass { + public class InnerJavaClass {} + public static class NestedJavaClass {} + public static void staticPublicMethod() {} + public static String staticPublicField; + static void staticPackageProtectedMethod() {} + static String staticPackageProtectedField; + protected static void staticProtectedMethod() {} + protected static String staticProtectedField; + private static void staticPrivateMethod() {} + private static String staticPrivateField; +} +// FILE: OuterKotlinClass.kt +typealias CustomJvmStatic=JvmStatic +open class OuterKotlinClass { + inner class InnerKotlinClass + open class NestedKotlinClass + companion object { + fun companionMethod() {} + const val companionField:String = "" + private fun privateCompanionMethod() {} + private val privateCompanionField:String = "" + @JvmStatic + fun jvmStaticCompanionMethod() {} + @JvmStatic + val jvmStaticCompanionField:String = "" + @CustomJvmStatic + fun customJvmStaticCompanionMethod() {} + @CustomJvmStatic + val customJvmStaticCompanionField:String = "" + } + + @Transient + val transientProperty: String = "" + + @Volatile + var volatileProperty: String = "" + + @Strictfp + fun strictfpFun(): String = "" + + @Synchronized + fun synchronizedFun(): String = "" +} diff --git a/test-utils/testData/api/javaNonNullTypes.kt b/test-utils/testData/api/javaNonNullTypes.kt new file mode 100644 index 00000000..7a383bf7 --- /dev/null +++ b/test-utils/testData/api/javaNonNullTypes.kt @@ -0,0 +1,78 @@ +/* + * Copyright 2022 Google LLC + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// WITH_RUNTIME +// TEST PROCESSOR: JavaNonNullProcessor +// EXPECTED: +// javaNotNullFieldRef: NOT_NULL +// javaNullableFieldRef: NULLABLE +// javaBothFieldRef: PLATFORM +// javaNoneFieldRef: NULLABLE +// bothField: PLATFORM +// nullableField: NULLABLE +// notNullField: NOT_NULL +// noneField: PLATFORM +// notNullFun: NOT_NULL +// nullableParam: NULLABLE +// END +// MODULE: lib +// FILE: dummy.kt +class dummy + +// FILE: org/jetbrains/annotations/NotNull.java +package org.jetbrains.annotations; + +public @interface NotNull { + +} + +// FILE: org/jetbrains/annotations/Nullable.java +package org.jetbrains.annotations; + +public @interface Nullable { + +} + +// MODULE: main(lib) +// FILE: a.kt +val javaNotNullFieldRef = JavaNonNull().notNullField +val javaNullableFieldRef = JavaNonNull().nullableField +val javaBothFieldRef = JavaNonNull().bothField +val javaNoneFieldRef = JavaNonNull().nonField + + +// FILE: JavaNonNull.java +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + + +public class JavaNonNull { + @Nullable + @NotNull + public String bothField; + + @Nullable + public String nullableField; + + @NotNull + public String notNullField; + + public String noneField; + + @NotNull + public String notNullFun(@Nullable String nullableParam) {} +} diff --git a/test-utils/testData/api/javaSubtype.kt b/test-utils/testData/api/javaSubtype.kt new file mode 100644 index 00000000..80c3b566 --- /dev/null +++ b/test-utils/testData/api/javaSubtype.kt @@ -0,0 +1,36 @@ +/* + * Copyright 2022 Google LLC + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// TEST PROCESSOR: JavaSubtypeProcessor +// EXPECTED: +// true +// END +// FILE: a.kt +class A + +// FILE: Container.java + +public class Container { + String str; +} + +// FILE: IntSupplier.java +import kotlin.jvm.functions.Function0; + +public class IntSupplier implements Function0<Integer> { + @Override public Integer invoke() { return 1; } +} diff --git a/test-utils/testData/api/javaToKotlinMapper.kt b/test-utils/testData/api/javaToKotlinMapper.kt new file mode 100644 index 00000000..71aba602 --- /dev/null +++ b/test-utils/testData/api/javaToKotlinMapper.kt @@ -0,0 +1,32 @@ +/* + * Copyright 2020 Google LLC + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// WITH_RUNTIME +// TEST PROCESSOR: JavaToKotlinMapProcessor +// EXPECTED: +// java.lang.String -> kotlin.String +// java.lang.Integer -> kotlin.Int +// java.util.List -> kotlin.collections.List +// java.util.Map.Entry -> kotlin.collections.Map.Entry +// java.lang.Void -> null +// kotlin.Throwable -> java.lang.Throwable +// kotlin.Int -> java.lang.Integer +// kotlin.Nothing -> java.lang.Void +// kotlin.IntArray -> null +// END + +val unused = Unit diff --git a/test-utils/testData/api/javaTypes.kt b/test-utils/testData/api/javaTypes.kt new file mode 100644 index 00000000..16ae1abd --- /dev/null +++ b/test-utils/testData/api/javaTypes.kt @@ -0,0 +1,34 @@ +/* + * Copyright 2020 Google LLC + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// WITH_RUNTIME +// TEST PROCESSOR: TypeComparisonProcessor +// EXPECTED: +// (String..String?) ?= (String..String?) : true +// (String..String?) ?= String : true +// (String..String?) ?= String? : true +// String ?= (String..String?) : true +// String ?= String : true +// String ?= String? : false +// String? ?= (String..String?) : true +// String? ?= String : true +// String? ?= String? : true +// END + +val j = java.lang.String.valueOf("") +val x: String = j +val y: String? = j diff --git a/test-utils/testData/api/javaTypes2.kt b/test-utils/testData/api/javaTypes2.kt new file mode 100644 index 00000000..b72d706c --- /dev/null +++ b/test-utils/testData/api/javaTypes2.kt @@ -0,0 +1,47 @@ +/* + * Copyright 2020 Google LLC + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// WITH_RUNTIME +// TEST PROCESSOR: TypeComparisonProcessor +// EXPECTED: +// (Array<(C..C?)>..Array<out (C..C?)>?) ?= (Array<(C..C?)>..Array<out (C..C?)>?) : true +// (Array<(C..C?)>..Array<out (C..C?)>?) ?= Array<C> : true +// (Array<(C..C?)>..Array<out (C..C?)>?) ?= Array<D> : true +// Array<C> ?= (Array<(C..C?)>..Array<out (C..C?)>?) : true +// Array<C> ?= Array<C> : true +// Array<C> ?= Array<D> : false +// Array<D> ?= (Array<(C..C?)>..Array<out (C..C?)>?) : false +// Array<D> ?= Array<C> : false +// Array<D> ?= Array<D> : true +// END + +// FILE: ArrayTest.java +class ArrayTest { + public static C[] javaArrayOfC() { + return null; + } +} + +// FILE: K.kt +@file:kotlin.Suppress("C", "D", "Suppress", "Any", "ArrayTest") + +open class C +open class D : C() + +val j = ArrayTest.javaArrayOfC() +val c: Array<C> = arrayOf() +val d: Array<D> = arrayOf() diff --git a/test-utils/testData/api/javaWildcards2.kt b/test-utils/testData/api/javaWildcards2.kt new file mode 100644 index 00000000..f84e274a --- /dev/null +++ b/test-utils/testData/api/javaWildcards2.kt @@ -0,0 +1,108 @@ +/* + * Copyright 2020 Google LLC + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// WITH_RUNTIME +// TEST PROCESSOR: JavaWildcard2Processor +// EXPECTED: +// MyEnum : Any +// <init> : MyEnum +// VarianceSubjectSuppressed : Any +// R : Any? +// starList : List<Any?> +// typeArgList : List<R> +// numberList : List<Number> +// stringList : List<String> +// enumList : List<MyEnum> +// jvmWildcard : List<out [@kotlin.jvm.JvmWildcard] String> +// suppressJvmWildcard : List<[@kotlin.jvm.JvmSuppressWildcards] Number> +// <init> : VarianceSubjectSuppressed<R> +// propWithFinalType : String +// propWithFinalType.getter() : String +// <set-?> : String +// propWithOpenType : Number +// propWithOpenType.getter() : Number +// <set-?> : Number +// propWithFinalGeneric : List<String> +// propWithFinalGeneric.getter() : List<String> +// <set-?> : List<String> +// propWithOpenGeneric : List<Number> +// propWithOpenGeneric.getter() : List<Number> +// <set-?> : List<Number> +// propWithTypeArg : R +// propWithTypeArg.getter() : R +// <set-?> : R +// propWithTypeArgGeneric : List<R> +// propWithTypeArgGeneric.getter() : List<R> +// <set-?> : List<R> +// propWithOpenTypeButSuppressAnnotation : Number +// propWithOpenTypeButSuppressAnnotation.getter() : Number +// <set-?> : Number +// list2 : List<Any?> +// list1 : List<Any?> +// list3 : List<R> +// listTypeArg : List<R> +// list4 : List<Number> +// listTypeArgNumber : List<Number> +// list5 : List<String> +// listTypeArgString : List<String> +// list6 : List<MyEnum> +// listTypeArgEnum : List<MyEnum> +// list7 : List<out [@kotlin.jvm.JvmWildcard] String> +// explicitJvmWildcard : List<out [@kotlin.jvm.JvmWildcard] String> +// list8 : List<[@kotlin.jvm.JvmSuppressWildcards] Number> +// explicitJvmSuppressWildcard_OnType : List<[@kotlin.jvm.JvmSuppressWildcards] Number> +// list9 : [@kotlin.jvm.JvmSuppressWildcards] List<Number> +// explicitJvmSuppressWildcard_OnType2 : [@kotlin.jvm.JvmSuppressWildcards] List<Number> +// END + +enum class MyEnum() + +@JvmSuppressWildcards +class VarianceSubjectSuppressed<R>( + starList: List<*>, + typeArgList: List<R>, + numberList: List<Number>, + stringList: List<String>, + enumList: List<MyEnum>, + jvmWildcard: List<@JvmWildcard String>, + suppressJvmWildcard: List<@JvmSuppressWildcards Number> +) { + var propWithFinalType: String = "" + var propWithOpenType: Number = 3 + var propWithFinalGeneric: List<String> = TODO() + var propWithOpenGeneric: List<Number> = TODO() + var propWithTypeArg: R = TODO() + var propWithTypeArgGeneric: List<R> = TODO() + @JvmSuppressWildcards + var propWithOpenTypeButSuppressAnnotation: Number = 3 + fun list1(list2: List<*>): List<*> { TODO() } + fun listTypeArg(list3: List<R>): List<R> { TODO() } + fun listTypeArgNumber(list4: List<Number>): List<Number> { TODO() } + fun listTypeArgString(list5: List<String>): List<String> { TODO() } + fun listTypeArgEnum(list6: List<MyEnum>): List<MyEnum> { TODO() } + fun explicitJvmWildcard( + list7: List<@JvmWildcard String> + ): List<@JvmWildcard String> { TODO() } + + fun explicitJvmSuppressWildcard_OnType( + list8: List<@JvmSuppressWildcards Number> + ): List<@JvmSuppressWildcards Number> { TODO() } + + fun explicitJvmSuppressWildcard_OnType2( + list9: @JvmSuppressWildcards List<Number> + ): @JvmSuppressWildcards List<Number> { TODO() } +} diff --git a/test-utils/testData/api/lateinitProperties.kt b/test-utils/testData/api/lateinitProperties.kt new file mode 100644 index 00000000..af98f766 --- /dev/null +++ b/test-utils/testData/api/lateinitProperties.kt @@ -0,0 +1,56 @@ +/* + * Copyright 2022 Google LLC + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// WITH_RUNTIME +// TEST PROCESSOR: LateinitPropertiesProcessor +// EXPECTED: +// prop1 +// prop2 +// prop3 +// propSource1 +// propSource2 +// propSource3 +// END +// MODULE: lib +// FILE: compiledProperties.kt +package test.compiled + +open class Foo { + lateinit var prop1: Any + companion object { + lateinit var prop2: Any + } +} + +object Bar : Foo() { + lateinit var prop3: Any +} + +// MODULE: main(lib) +// FILE: sourceProperties.kt +package test.source + +open class FooSource { + lateinit var propSource1: Any + companion object { + lateinit var propSource2: Any + } +} + +object BarSource : Foo() { + lateinit var propSource3: Any +} diff --git a/test-utils/testData/api/libOrigins.kt b/test-utils/testData/api/libOrigins.kt new file mode 100644 index 00000000..719b4810 --- /dev/null +++ b/test-utils/testData/api/libOrigins.kt @@ -0,0 +1,338 @@ +/* + * Copyright 2020 Google LLC + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// TEST PROCESSOR: LibOriginsProcessor +// EXPECTED: +// annotation: Anno1: KOTLIN_LIB +// annotation: Anno2: JAVA_LIB +// annotation: Anno3: KOTLIN +// annotation: Anno4: JAVA +// classifier ref: Anno1: KOTLIN_LIB +// classifier ref: Anno1: KOTLIN_LIB +// classifier ref: Anno2: JAVA_LIB +// classifier ref: Anno2: KOTLIN_LIB +// classifier ref: Anno3: KOTLIN +// classifier ref: Anno3: KOTLIN_LIB +// classifier ref: Anno4: JAVA +// classifier ref: Anno4: KOTLIN_LIB +// classifier ref: Annotation: KOTLIN_LIB +// classifier ref: Annotation: KOTLIN_LIB +// classifier ref: Annotation: KOTLIN_LIB +// classifier ref: Annotation: KOTLIN_LIB +// classifier ref: Any: JAVA_LIB +// classifier ref: Any: JAVA_LIB +// classifier ref: Any: JAVA_LIB +// classifier ref: Any: KOTLIN_LIB +// classifier ref: Any: KOTLIN_LIB +// classifier ref: Any: KOTLIN_LIB +// classifier ref: ArrayList<(T2..T2?)>: JAVA_LIB +// classifier ref: Byte: JAVA_LIB +// classifier ref: Byte: JAVA_LIB +// classifier ref: Byte: JAVA_LIB +// classifier ref: Int: KOTLIN_LIB +// classifier ref: Int: KOTLIN_LIB +// classifier ref: Int: KOTLIN_LIB +// classifier ref: Int: KOTLIN_LIB +// classifier ref: Int: KOTLIN_LIB +// classifier ref: Int: KOTLIN_LIB +// classifier ref: Int: KOTLIN_LIB +// classifier ref: Int: KOTLIN_LIB +// classifier ref: Int: KOTLIN_LIB +// classifier ref: Int: KOTLIN_LIB +// classifier ref: Int: KOTLIN_LIB +// classifier ref: Int: KOTLIN_LIB +// classifier ref: JavaLib: JAVA_LIB +// classifier ref: JavaLib: JAVA_LIB +// classifier ref: JavaLib: JAVA_LIB +// classifier ref: JavaLib<T2>: JAVA_LIB +// classifier ref: KotlinLibClass: KOTLIN_LIB +// classifier ref: KotlinLibClass: KOTLIN_LIB +// classifier ref: KotlinLibClass: KOTLIN_LIB +// classifier ref: KotlinLibClass: KOTLIN_LIB +// classifier ref: KotlinLibClass: KOTLIN_LIB +// classifier ref: KotlinLibClass: KOTLIN_LIB +// classifier ref: KotlinLibClass<T1>: KOTLIN_LIB +// classifier ref: KotlinSrcClass: SYNTHETIC +// classifier ref: List<Int>: KOTLIN_LIB +// classifier ref: List<T1>: KOTLIN_LIB +// classifier ref: List<T1>: KOTLIN_LIB +// classifier ref: List<T1>: KOTLIN_LIB +// classifier ref: List<T1>: KOTLIN_LIB +// classifier ref: Long: JAVA +// classifier ref: Long: JAVA +// classifier ref: Long: JAVA +// classifier ref: Object: JAVA +// classifier ref: Set: KOTLIN +// classifier ref: Set: KOTLIN +// classifier ref: Set: KOTLIN +// classifier ref: Set: KOTLIN +// classifier ref: Set<T3>: SYNTHETIC +// classifier ref: Short: KOTLIN +// classifier ref: Short: KOTLIN +// classifier ref: Short: KOTLIN +// classifier ref: Short: KOTLIN +// classifier ref: Short: KOTLIN +// classifier ref: Short: KOTLIN +// classifier ref: Short: KOTLIN +// classifier ref: Short: KOTLIN +// classifier ref: Short: KOTLIN +// classifier ref: Short: SYNTHETIC +// classifier ref: Short: SYNTHETIC +// classifier ref: Short: SYNTHETIC +// classifier ref: T1: KOTLIN_LIB +// classifier ref: T1: KOTLIN_LIB +// classifier ref: T1: KOTLIN_LIB +// classifier ref: T1: KOTLIN_LIB +// classifier ref: T1: KOTLIN_LIB +// classifier ref: T1: KOTLIN_LIB +// classifier ref: T2: JAVA_LIB +// classifier ref: T2: JAVA_LIB +// classifier ref: T2: JAVA_LIB +// classifier ref: T3: KOTLIN +// classifier ref: T3: KOTLIN +// classifier ref: T3: KOTLIN +// classifier ref: T3: KOTLIN +// classifier ref: T3: SYNTHETIC +// classifier ref: T4: JAVA +// classifier ref: T4: JAVA +// declaration: <init>: KOTLIN +// declaration: foo.bar.Anno1.<init>: KOTLIN_LIB +// declaration: foo.bar.Anno1: KOTLIN_LIB +// declaration: foo.bar.Anno2.<init>: KOTLIN_LIB +// declaration: foo.bar.Anno2: KOTLIN_LIB +// declaration: foo.bar.Anno3.<init>: KOTLIN_LIB +// declaration: foo.bar.Anno3: KOTLIN_LIB +// declaration: foo.bar.Anno4.<init>: KOTLIN_LIB +// declaration: foo.bar.Anno4: KOTLIN_LIB +// declaration: foo.bar.JavaLib.<init>: JAVA_LIB +// declaration: foo.bar.JavaLib.T2: JAVA_LIB +// declaration: foo.bar.JavaLib.T2: JAVA_LIB +// declaration: foo.bar.JavaLib.f1: JAVA_LIB +// declaration: foo.bar.JavaLib.javaLibField: JAVA_LIB +// declaration: foo.bar.JavaLib.javaLibFunction: JAVA_LIB +// declaration: foo.bar.JavaLib: JAVA_LIB +// declaration: foo.bar.JavaSrc.<init>: SYNTHETIC +// declaration: foo.bar.JavaSrc.LinkedList: JAVA +// declaration: foo.bar.JavaSrc.f2: JAVA +// declaration: foo.bar.JavaSrc.javaSrcField: JAVA +// declaration: foo.bar.JavaSrc.javaSrcFunction: JAVA +// declaration: foo.bar.JavaSrc.p0: JAVA +// declaration: foo.bar.JavaSrc: JAVA +// declaration: foo.bar.KotlinLibClass.<init>: KOTLIN_LIB +// declaration: foo.bar.KotlinLibClass.T1: KOTLIN_LIB +// declaration: foo.bar.KotlinLibClass.T1: KOTLIN_LIB +// declaration: foo.bar.KotlinLibClass.f1: KOTLIN_LIB +// declaration: foo.bar.KotlinLibClass.f2: KOTLIN_LIB +// declaration: foo.bar.KotlinLibClass.f3: KOTLIN_LIB +// declaration: foo.bar.KotlinLibClass.p1: KOTLIN_LIB +// declaration: foo.bar.KotlinLibClass.p2: KOTLIN_LIB +// declaration: foo.bar.KotlinLibClass.p3: KOTLIN_LIB +// declaration: foo.bar.KotlinLibClass: KOTLIN_LIB +// declaration: foo.bar.KotlinSrcClass.T3: KOTLIN +// declaration: foo.bar.KotlinSrcClass.g1: KOTLIN +// declaration: foo.bar.KotlinSrcClass.g2: KOTLIN +// declaration: foo.bar.KotlinSrcClass.g3: KOTLIN +// declaration: foo.bar.KotlinSrcClass.q1: KOTLIN +// declaration: foo.bar.KotlinSrcClass.q2: KOTLIN +// declaration: foo.bar.KotlinSrcClass.q3: KOTLIN +// declaration: foo.bar.KotlinSrcClass: KOTLIN +// declaration: foo.bar.kotlinLibFuntion: KOTLIN_LIB +// declaration: foo.bar.kotlinLibProperty: KOTLIN_LIB +// declaration: foo.bar.kotlinSrcFuntion: KOTLIN +// declaration: foo.bar.kotlinSrcProperty: KOTLIN +// property accessor: kotlinLibProperty.getter(): KOTLIN_LIB +// property accessor: kotlinSrcProperty.getter(): SYNTHETIC +// property accessor: p1.getter(): KOTLIN_LIB +// property accessor: p2.getter(): KOTLIN_LIB +// property accessor: p3.getter(): KOTLIN_LIB +// property accessor: q1.getter(): SYNTHETIC +// property accessor: q2.getter(): SYNTHETIC +// property accessor: q3.getter(): SYNTHETIC +// reference: Anno1: KOTLIN_LIB +// reference: Anno1: KOTLIN_LIB +// reference: Anno2: JAVA_LIB +// reference: Anno2: KOTLIN_LIB +// reference: Anno3: KOTLIN +// reference: Anno3: KOTLIN_LIB +// reference: Anno4: JAVA +// reference: Anno4: KOTLIN_LIB +// reference: Annotation: KOTLIN_LIB +// reference: Annotation: KOTLIN_LIB +// reference: Annotation: KOTLIN_LIB +// reference: Annotation: KOTLIN_LIB +// reference: Any: JAVA_LIB +// reference: Any: JAVA_LIB +// reference: Any: JAVA_LIB +// reference: Any: KOTLIN_LIB +// reference: Any: KOTLIN_LIB +// reference: Any: KOTLIN_LIB +// reference: Any: SYNTHETIC +// reference: Any?: SYNTHETIC +// reference: ArrayList<(T2..T2?)>: JAVA_LIB +// reference: Byte: JAVA_LIB +// reference: Byte: JAVA_LIB +// reference: Byte: JAVA_LIB +// reference: Int: KOTLIN_LIB +// reference: Int: KOTLIN_LIB +// reference: Int: KOTLIN_LIB +// reference: Int: KOTLIN_LIB +// reference: Int: KOTLIN_LIB +// reference: Int: KOTLIN_LIB +// reference: Int: KOTLIN_LIB +// reference: Int: KOTLIN_LIB +// reference: Int: KOTLIN_LIB +// reference: Int: KOTLIN_LIB +// reference: Int: KOTLIN_LIB +// reference: Int: KOTLIN_LIB +// reference: JavaLib<T2>: JAVA_LIB +// reference: JavaSrc: SYNTHETIC +// reference: KotlinLibClass<T1>: KOTLIN_LIB +// reference: KotlinSrcClass<T3>: KOTLIN +// reference: List<Int>: KOTLIN_LIB +// reference: List<T1>: KOTLIN_LIB +// reference: List<T1>: KOTLIN_LIB +// reference: List<T1>: KOTLIN_LIB +// reference: List<T1>: KOTLIN_LIB +// reference: Long: JAVA +// reference: Long: JAVA +// reference: Long: JAVA +// reference: Object: JAVA +// reference: Set: KOTLIN +// reference: Set: KOTLIN +// reference: Set: KOTLIN +// reference: Set: KOTLIN +// reference: Set<T3>: SYNTHETIC +// reference: Short: KOTLIN +// reference: Short: KOTLIN +// reference: Short: KOTLIN +// reference: Short: KOTLIN +// reference: Short: KOTLIN +// reference: Short: KOTLIN +// reference: Short: KOTLIN +// reference: Short: KOTLIN +// reference: Short: KOTLIN +// reference: Short: SYNTHETIC +// reference: Short: SYNTHETIC +// reference: Short: SYNTHETIC +// reference: T1: KOTLIN_LIB +// reference: T1: KOTLIN_LIB +// reference: T1: KOTLIN_LIB +// reference: T1: KOTLIN_LIB +// reference: T1: KOTLIN_LIB +// reference: T1: KOTLIN_LIB +// reference: T2: JAVA_LIB +// reference: T2: JAVA_LIB +// reference: T2: JAVA_LIB +// reference: T3: KOTLIN +// reference: T3: KOTLIN +// reference: T3: KOTLIN +// reference: T3: KOTLIN +// reference: T3: SYNTHETIC +// reference: T4: JAVA +// reference: T4: JAVA +// type arg: INVARIANT Int: KOTLIN_LIB +// type arg: INVARIANT Short: KOTLIN +// type arg: INVARIANT T1: KOTLIN_LIB +// type arg: INVARIANT T1: KOTLIN_LIB +// type arg: INVARIANT T1: KOTLIN_LIB +// type arg: INVARIANT T1: KOTLIN_LIB +// type arg: INVARIANT T1: KOTLIN_LIB +// type arg: INVARIANT T2: JAVA_LIB +// type arg: INVARIANT T2: JAVA_LIB +// type arg: INVARIANT T3: KOTLIN +// type arg: INVARIANT T3: KOTLIN +// type arg: INVARIANT T3: KOTLIN +// type arg: INVARIANT T3: SYNTHETIC +// value param: p0: JAVA_LIB +// value param: p1: JAVA_LIB +// value param: p1: KOTLIN_LIB +// value param: p2: KOTLIN_LIB +// value param: p4: KOTLIN_LIB +// value param: p5: KOTLIN_LIB +// value param: p6: KOTLIN_LIB +// value param: q1: KOTLIN +// value param: q2: KOTLIN +// value param: q4: KOTLIN +// value param: q5: KOTLIN +// value param: q6: KOTLIN +// END +// MODULE: module1 +// FILE: KotlinLib.kt +package foo.bar + +val kotlinLibProperty: Int = 0 +fun kotlinLibFuntion(): Int = 0 + +annotation class Anno1 +annotation class Anno2 +annotation class Anno3 +annotation class Anno4 + +@Anno1 +class KotlinLibClass<T1>(val p1: List<T1>, val p2: Int) { + val p3: Int = 0 + fun f1(p4: T1): Int = 0 + fun f2(p5: List<T1>): Int = 0 + fun f3(p6: List<Int>): Int = 0 +} + +// FILE: JavaLib.java +package foo.bar; + +import java.util.ArrayList; + +@Anno2 +class JavaLib<T2> { + Byte javaLibField = 0; + Byte javaLibFunction() { + return 0; + } + Byte f1(T2 p0, ArrayList<T2> p1) { + return 0; + } +} + +// MODULE: main(module1) +// FILE: KotlinSrc.kt +package foo.bar +val kotlinSrcProperty: Short = 0 +fun kotlinSrcFuntion(): Short = 0 + +@Anno3 +class KotlinSrcClass<T3>(val q1: Set<T3>, val q2: Short) { + val q3: Short = 0 + fun g1(q4: T3): Short = 0 + fun g2(q5: Set<T3>): Short = 0 + fun g3(q6: Set<Short>): Short = 0 +} + +// FILE: JavaSrc.java +package foo.bar; + +import java.util.LinkedList; + +@Anno4 +class JavaSrc { + Long javaSrcField = 0; + Long javaSrcFunction() { + return 0; + } + Long f2<T4>(T4 p0, LinkedList<T4> p1) { + return 0; + } +} + diff --git a/test-utils/testData/api/makeNullable.kt b/test-utils/testData/api/makeNullable.kt new file mode 100644 index 00000000..2321e959 --- /dev/null +++ b/test-utils/testData/api/makeNullable.kt @@ -0,0 +1,40 @@ +/* + * Copyright 2020 Google LLC + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// WITH_RUNTIME +// TEST PROCESSOR: MakeNullableProcessor +// EXPECTED: +// Int ?= Int : true +// Int ?= Int? : false +// Int ?= String : false +// Int ?= String? : false +// Int? ?= Int : true +// Int? ?= Int? : true +// Int? ?= String : false +// Int? ?= String? : false +// String ?= Int : false +// String ?= Int? : false +// String ?= String : true +// String ?= String? : false +// String? ?= Int : false +// String? ?= Int? : false +// String? ?= String : true +// String? ?= String? : true +// END + +val x: String = "" +val y: Int? = 0 diff --git a/test-utils/testData/api/mangledNames.kt b/test-utils/testData/api/mangledNames.kt new file mode 100644 index 00000000..cb00475a --- /dev/null +++ b/test-utils/testData/api/mangledNames.kt @@ -0,0 +1,194 @@ +/* + * Copyright 2020 Google LLC + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// WITH_RUNTIME +// TEST PROCESSOR: MangledNamesProcessor +// EXPECTED: +// JavaEnum -> declarations +// JavaEnum.VAL1 -> declarations +// JavaEnum.VAL2 -> declarations +// values -> values +// valueOf -> valueOf +// <init> -> <init> +// JavaInput -> declarations +// javaFunction -> javaFunction +// staticJavaFunction -> staticJavaFunction +// getX -> getX +// getY -> getY +// setY -> setY +// mainPackage.Foo -> declarations +// get-normalProp -> getNormalProp +// set-normalProp -> setNormalProp +// get-inlineProp -> getInlineProp-HRn7Rpw +// set-inlineProp -> setInlineProp-E03SJzc +// get-internalProp -> getInternalProp$mainModule +// set-internalProp -> setInternalProp$mainModule +// get-internalInlineProp -> getInternalInlineProp-HRn7Rpw$mainModule +// set-internalInlineProp -> setInternalInlineProp-E03SJzc$mainModule +// get-jvmNameProp -> explicitGetterName +// set-jvmNameProp -> explicitSetterName +// normalFun -> normalFun +// hasJvmName -> explicitJvmName +// inlineReceivingFun -> inlineReceivingFun-E03SJzc +// inlineReturningFun -> inlineReturningFun-HRn7Rpw +// internalInlineReceivingFun -> internalInlineReceivingFun-E03SJzc$mainModule +// internalInlineReturningFun -> internalInlineReturningFun-HRn7Rpw$mainModule +// mainPackage.AbstractKotlinClass -> declarations +// get-abstractVar -> getAbstractVar +// set-abstractVar -> setAbstractVar +// get-abstractVal -> getAbstractVal +// get-internalAbstractVar -> getInternalAbstractVar$mainModule +// set-internalAbstractVar -> setInternalAbstractVar$mainModule +// get-internalAbstractVal -> getInternalAbstractVal$mainModule +// set-internalAbstractVal -> setInternalAbstractVal$mainModule +// fileLevelInternalFun -> fileLevelInternalFun +// fileLevelInlineReceivingFun -> fileLevelInlineReceivingFun-E03SJzc +// fileLevelInlineReturningFun -> fileLevelInlineReturningFun +// fileLevelInternalInlineReceivingFun -> fileLevelInternalInlineReceivingFun-E03SJzc +// fileLevelInternalInlineReturningFun -> fileLevelInternalInlineReturningFun +// mainPackage.MyInterface -> declarations +// get-x -> getX +// get-y -> getY +// set-y -> setY +// libPackage.Foo -> declarations +// get-inlineProp -> getInlineProp-b_MPbnQ +// set-inlineProp -> setInlineProp-mQ73O9w +// get-internalInlineProp -> getInternalInlineProp-b_MPbnQ$lib +// set-internalInlineProp -> setInternalInlineProp-mQ73O9w$lib +// get-internalProp -> getInternalProp$lib +// set-internalProp -> setInternalProp$lib +// get-jvmNameProp -> explicitGetterName +// set-jvmNameProp -> explicitSetterName +// get-normalProp -> getNormalProp +// set-normalProp -> setNormalProp +// hasJvmName -> explicitJvmName +// inlineReceivingFun -> inlineReceivingFun-mQ73O9w +// inlineReturningFun -> inlineReturningFun-b_MPbnQ +// internalInlineReceivingFun -> internalInlineReceivingFun-mQ73O9w$lib +// internalInlineReturningFun -> internalInlineReturningFun-b_MPbnQ$lib +// normalFun -> normalFun +// <init> -> <init> +// libPackage.AbstractKotlinClass -> declarations +// get-abstractVal -> getAbstractVal +// get-abstractVar -> getAbstractVar +// set-abstractVar -> setAbstractVar +// get-internalAbstractVal -> getInternalAbstractVal$lib +// set-internalAbstractVal -> setInternalAbstractVal$lib +// get-internalAbstractVar -> getInternalAbstractVar$lib +// set-internalAbstractVar -> setInternalAbstractVar$lib +// libPackage.MyInterface -> declarations +// get-x -> getX +// get-y -> getY +// set-y -> setY +// END +// MODULE: lib +// FILE: input.kt +/** + * control group + */ +package libPackage; +inline class Inline1(val value:String) +class Foo { + var normalProp:String = TODO() + var inlineProp: Inline1 = TODO() + internal var internalProp: String = TODO() + internal var internalInlineProp: Inline1 = TODO() + @get:JvmName("explicitGetterName") + @set:JvmName("explicitSetterName") + var jvmNameProp:String + fun normalFun() {} + @JvmName("explicitJvmName") + fun hasJvmName() {} + fun inlineReceivingFun(value: Inline1) {} + fun inlineReturningFun(): Inline1 = TODO() + internal fun internalInlineReceivingFun(value: Inline1) {} + internal fun internalInlineReturningFun(): Inline1 = TODO() +} + +abstract class AbstractKotlinClass { + abstract var abstractVar:String + abstract val abstractVal:String + internal abstract var internalAbstractVar:String + internal abstract var internalAbstractVal:String +} + +interface MyInterface { + val x:Int + var y:Int +} +// MODULE: mainModule(lib) +// FILE: input.kt +package mainPackage; +inline class Inline1(val value:String) +class Foo { + var normalProp:String = TODO() + var inlineProp: Inline1 = TODO() + internal var internalProp: String = TODO() + internal var internalInlineProp: Inline1 = TODO() + @get:JvmName("explicitGetterName") + @set:JvmName("explicitSetterName") + var jvmNameProp:String + fun normalFun() {} + @JvmName("explicitJvmName") + fun hasJvmName() {} + fun inlineReceivingFun(value: Inline1) {} + fun inlineReturningFun(): Inline1 = TODO() + internal fun internalInlineReceivingFun(value: Inline1) {} + internal fun internalInlineReturningFun(): Inline1 = TODO() +} + +abstract class AbstractKotlinClass { + abstract var abstractVar:String + abstract val abstractVal:String + internal abstract var internalAbstractVar:String + internal abstract var internalAbstractVal:String +} + +internal fun fileLevelInternalFun(): Unit = TODO() +fun fileLevelInlineReceivingFun(inline1: Inline1): Unit = TODO() +fun fileLevelInlineReturningFun(): Inline1 = TODO() +fun fileLevelInternalInlineReceivingFun(inline1: Inline1): Unit = TODO() +fun fileLevelInternalInlineReturningFun(): Inline1 = TODO() + +interface MyInterface { + val x:Int + var y:Int +} + +// FILE: JavaInput.java +import mainPackage.MyInterface; + +class JavaInput implements MyInterface { + String javaField; + String javaFunction() {} + static String staticJavaField; + static void staticJavaFunction() {} + public int getX() { + return 1; + } + public int getY() { + return 1; + } + public void setY(int value) { + } +} + +// FILE: JavaEnum.java +public enum JavaEnum { + VAL1, + VAL2; +} diff --git a/test-utils/testData/api/multipleModules.kt b/test-utils/testData/api/multipleModules.kt new file mode 100644 index 00000000..b33df4e2 --- /dev/null +++ b/test-utils/testData/api/multipleModules.kt @@ -0,0 +1,56 @@ +/* + * Copyright 2022 Google LLC + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// WITH_RUNTIME +// TEST PROCESSOR: MultiModuleTestProcessor +// EXPECTED: +// ClassInMainModule[KOTLIN] +// ClassInModule1[KOTLIN_LIB] +// ClassInModule2[KOTLIN_LIB] +// JavaClassInMainModule[JAVA] +// JavaClassInModule1[JAVA_LIB] +// JavaClassInModule2[JAVA_LIB] +// TestTarget[KOTLIN] +// END +// MODULE: module1 +// FILE: ClassInModule1.kt +class ClassInModule1 { + val javaClassInModule1: JavaClassInModule1 = TODO() +} +// FILE: JavaClassInModule1.java +public class JavaClassInModule1 {} +// MODULE: module2(module1) +// FILE: ClassInModule2.kt +class ClassInModule2 { + val javaClassInModule2: JavaClassInModule2 = TODO() + val classInModule1: ClassInModule1 = TODO() +} +// FILE: JavaClassInModule2.java +public class JavaClassInModule2 {} +// MODULE: main(module1, module2) +// FILE: main.kt +class TestTarget { + val field: ClassInMainModule = TODO() +} +// FILE: ClassInMainModule.kt +class ClassInMainModule { + val field: ClassInModule2 = TODO() + val javaClassInMainModule : JavaClassInMainModule = TODO() +} +// FILE: JavaClassInMainModule.java +class JavaClassInMainModule { +} diff --git a/test-utils/testData/api/nestedClassType.kt b/test-utils/testData/api/nestedClassType.kt new file mode 100644 index 00000000..fd2f8bf4 --- /dev/null +++ b/test-utils/testData/api/nestedClassType.kt @@ -0,0 +1,41 @@ +/* + * Copyright 2022 Google LLC + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// TEST PROCESSOR: NestedClassTypeProcessor +// EXPECTED: +// foo +// @TypeAnno1 +// COVARIANT String +// bar +// , @TypeAnno2 +// CONTRAVARIANT Int,INVARIANT String +// END +// FILE: a.kt +annotation class TypeAnno1 +annotation class TypeAnno2 + +class Outer<T> { + inner class InnerGeneric<P> + inner class Inner +} + +class G<T> + +class C { + val foo: Outer<out @TypeAnno1 String>.Inner + val bar: Outer<@TypeAnno2 String>.InnerGeneric<in Int> +} diff --git a/test-utils/testData/api/nullableTypes.kt b/test-utils/testData/api/nullableTypes.kt new file mode 100644 index 00000000..ed3eb6d7 --- /dev/null +++ b/test-utils/testData/api/nullableTypes.kt @@ -0,0 +1,49 @@ +/* + * Copyright 2021 Google LLC + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// WITH_RUNTIME +// TEST PROCESSOR: NullableTypeProcessor +// EXPECTED: +// a: [], [@TA] +// b: [SUSPEND], [@TA] +// c: [], [@TA] +// d: [SUSPEND], [@TA] +// e: [], [@TA] +// f: [], [@TA] +// g: [], [@TA] +// h: [], [@TA] +// i: [], [@TA] +// j: [], [@TA] +// k: [], [@TA] +// END + +@Target(AnnotationTarget.TYPE) +annotation class TA + +val a: @TA (() -> Unit)? = {} +val b: (@TA suspend () -> Unit)? = {} +val c: @TA (() -> Unit) = {} +val d: (@TA suspend () -> Unit) = {} +val e: (@TA String)? + +// Parser doesn't allow `@TA (String)` +val f: (@TA String)? = "" +val g: (@TA String?) = "" +val h: (@TA String?)? = "" +val i: @TA String = "" +val j: (@TA String) = "" +val k: ((@TA String)?) = "" diff --git a/test-utils/testData/api/overridee.kt b/test-utils/testData/api/overridee.kt new file mode 100644 index 00000000..39173f93 --- /dev/null +++ b/test-utils/testData/api/overridee.kt @@ -0,0 +1,321 @@ +/* + * Copyright 2020 Google LLC + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// WITH_RUNTIME +// TEST PROCESSOR: OverrideeProcessor +// EXPECTED: +// NoOverride: +// NoOverride.propInParam -> null +// NoOverride.prop -> null +// NoOverride.func(param:Int) -> null +// Subject: +// Companion.companionMethod() -> null +// Subject.notOverridingProp -> null +// Subject.overriddenBaseProp -> Base.overriddenBaseProp +// Subject.overriddenAbstractBaseProp -> Base.overriddenAbstractBaseProp +// Subject.openGrandBaseProp -> GrandBase.openGrandBaseProp +// Subject.abstractGrandBaseProp -> GrandBase.abstractGrandBaseProp +// Subject.overriddenGrandBaseProp -> Base.overriddenGrandBaseProp +// Subject.overriddenAbstractGrandBaseProp -> Base.overriddenAbstractGrandBaseProp +// Subject.openFun() -> Base.openFun() +// Subject.abstractFun() -> Base.abstractFun() +// Subject.openFunWithGenericArg(t:String) -> Base.openFunWithGenericArg(t:T) +// Subject.abstractFunWithGenericArg(t:String) -> Base.abstractFunWithGenericArg(t:T) +// Subject.nonOverridingMethod() -> null +// Subject.overriddenGrandBaseFun() -> Base.overriddenGrandBaseFun() +// Subject.overriddenAbstractGrandBaseFun() -> Base.overriddenAbstractGrandBaseFun() +// Subject.openGrandBaseFun() -> GrandBase.openGrandBaseFun() +// Subject.abstractGrandBaseFun() -> GrandBase.abstractGrandBaseFun() +// JavaSubject.Subject: +// Subject.openFun() -> Base.openFun() +// Subject.abstractFun() -> Base.abstractFun() +// Subject.openFunWithGenericArg(t:String) -> Base.openFunWithGenericArg(t:T) +// Subject.abstractFunWithGenericArg(t:String) -> Base.abstractFunWithGenericArg(t:T) +// Subject.nonOverridingMethod() -> null +// Subject.overriddenGrandBaseFun() -> Base.overriddenGrandBaseFun() +// Subject.overriddenAbstractGrandBaseFun() -> Base.overriddenAbstractGrandBaseFun() +// Subject.openGrandBaseFun() -> GrandBase.openGrandBaseFun() +// Subject.abstractGrandBaseFun() -> GrandBase.abstractGrandBaseFun() +// Subject.staticMethod() -> null +// lib.Subject: +// Companion.companionMethod() -> null +// Subject.abstractGrandBaseProp -> GrandBase.abstractGrandBaseProp +// Subject.notOverridingProp -> null +// Subject.openGrandBaseProp -> GrandBase.openGrandBaseProp +// Subject.overriddenAbstractBaseProp -> Base.overriddenAbstractBaseProp +// Subject.overriddenAbstractGrandBaseProp -> Base.overriddenAbstractGrandBaseProp +// Subject.overriddenBaseProp -> Base.overriddenBaseProp +// Subject.overriddenGrandBaseProp -> Base.overriddenGrandBaseProp +// Subject.abstractFun() -> Base.abstractFun() +// Subject.abstractFunWithGenericArg(t:String) -> Base.abstractFunWithGenericArg(t:T) +// Subject.abstractGrandBaseFun() -> GrandBase.abstractGrandBaseFun() +// Subject.nonOverridingMethod() -> null +// Subject.openFun() -> Base.openFun() +// Subject.openFunWithGenericArg(t:String) -> Base.openFunWithGenericArg(t:T) +// Subject.openGrandBaseFun() -> GrandBase.openGrandBaseFun() +// Subject.overriddenAbstractGrandBaseFun() -> Base.overriddenAbstractGrandBaseFun() +// Subject.overriddenGrandBaseFun() -> Base.overriddenGrandBaseFun() +// ConflictingSubject1: +// ConflictingSubject1.absFoo() -> MyInterface.absFoo() +// ConflictingSubject2: +// ConflictingSubject2.absFoo() -> MyAbstract.absFoo() +// ConflictingSubject3: +// ConflictingSubject3.absFoo() -> MyInterface.absFoo() +// ConflictingSubject4: +// ConflictingSubject4.absFoo() -> MyInterface2.absFoo() +// OverrideOrder1: +// OverrideOrder1.foo() -> GrandBaseInterface2.foo() +// OverrideOrder2: +// OverrideOrder2.foo() -> GrandBaseInterface1.foo() +// JavaAccessorImpl: +// JavaAccessorImpl.getX() -> KtInterfaceWithProperty.x +// JavaAccessorImpl.getY() -> KtInterfaceWithProperty.y +// JavaAccessorImpl.setY(value:Int) -> KtInterfaceWithProperty.y +// JavaAnno: +// JavaAnno.intParam() -> null +// JavaAnnos: +// JavaAnnos.value() -> null +// PrimaryConstructorOverride: +// PrimaryConstructorOverride.x -> KtInterfaceWithProperty.x +// PrimaryConstructorOverride.y -> KtInterfaceWithProperty.y +// END +// MODULE: lib +// FILE: lib.kt +package lib; +abstract class GrandBase { + open var openGrandBaseProp: Int = 0 + abstract var abstractGrandBaseProp: Int + open var overriddenGrandBaseProp: Int = 0 + abstract var overriddenAbstractGrandBaseProp: Int + open fun openGrandBaseFun() {} + abstract fun abstractGrandBaseFun() + open fun overriddenGrandBaseFun() {} + abstract fun overriddenAbstractGrandBaseFun() +} +abstract class Base<T> : GrandBase() { + open var overriddenBaseProp: Int = 0 + abstract var overriddenAbstractBaseProp: Int + override var overriddenGrandBaseProp:Int = 0 + override var overriddenAbstractGrandBaseProp: Int = 0 + open fun openFun() {} + abstract fun abstractFun():Unit + open fun openFunWithGenericArg(t:T):T = TODO() + abstract fun abstractFunWithGenericArg(t:T):T + override open fun overriddenGrandBaseFun() {} + override open fun overriddenAbstractGrandBaseFun() {} +} + +abstract class Subject: Base<String>() { + var notOverridingProp: Int = 0 + override open var overriddenBaseProp: Int = 0 + override var overriddenAbstractBaseProp: Int = 0 + override open var openGrandBaseProp: Int = 0 + override var abstractGrandBaseProp: Int = 0 + override var overriddenGrandBaseProp:Int = 0 + override var overriddenAbstractGrandBaseProp: Int = 0 + override fun openFun() {} + override fun abstractFun() {} + override fun openFunWithGenericArg(t:String):String = TODO() + override fun abstractFunWithGenericArg(t:String):String = TODO() + fun nonOverridingMethod(): String =TODO() + override fun overriddenGrandBaseFun() {} + override fun overriddenAbstractGrandBaseFun() {} + override fun openGrandBaseFun() {} + override fun abstractGrandBaseFun() {} + companion object { + fun companionMethod(): String =TODO() + } +} +// MODULE: main(lib) +// FILE: a.kt +class NoOverride(val propInParam: Int) { + val prop: Int + fun func(val param: Int) { + + } +} + +interface KtInterfaceWithProperty { + val x:Int + var y:Int +} + +interface Intermediate: KtInterfaceWithProperty + +class PrimaryConstructorOverride(override val x: Int): Intermediate { + override val y: Int = 1 +} + +abstract class GrandBase { + open var openGrandBaseProp: Int = 0 + abstract var abstractGrandBaseProp: Int = 0 + open var overriddenGrandBaseProp: Int = 0 + abstract var overriddenAbstractGrandBaseProp: Int = 0 + open fun openGrandBaseFun() {} + abstract fun abstractGrandBaseFun() + open fun overriddenGrandBaseFun() {} + abstract fun overriddenAbstractGrandBaseFun() +} +abstract class Base<T> : GrandBase() { + open var overriddenBaseProp: Int = 0 + var overriddenAbstractBaseProp: Int = 0 + override var overriddenGrandBaseProp:Int = 0 + override var overriddenAbstractGrandBaseProp: Int = 0 + open fun openFun() {} + abstract fun abstractFun():Unit + open fun openFunWithGenericArg(t:T):T = TODO() + abstract fun abstractFunWithGenericArg(t:T):T + override open fun overriddenGrandBaseFun() {} + override open fun overriddenAbstractGrandBaseFun() {} +} + +abstract class Subject: Base<String>() { + var notOverridingProp: Int = 0 + override open var overriddenBaseProp: Int = 0 + override var overriddenAbstractBaseProp: Int = 0 + override open var openGrandBaseProp: Int = 0 + override var abstractGrandBaseProp: Int = 0 + override var overriddenGrandBaseProp:Int = 0 + override var overriddenAbstractGrandBaseProp: Int = 0 + override fun openFun() {} + override fun abstractFun() {} + override fun openFunWithGenericArg(t:String):String = TODO() + override fun abstractFunWithGenericArg(t:String):String = TODO() + fun nonOverridingMethod(): String =TODO() + override fun overriddenGrandBaseFun() {} + override fun overriddenAbstractGrandBaseFun() {} + override fun openGrandBaseFun() {} + override fun abstractGrandBaseFun() {} + companion object { + fun companionMethod(): String =TODO() + } +} + +// FILE: conflictingOverrides.kt +interface MyInterface { + fun absFoo(): Unit +} + +interface MyInterface2 { + fun absFoo(): Unit +} + +abstract class MyAbstract: MyInterface { + override fun absFoo(): Unit {val a = 1} +} + +class ConflictingSubject1: MyInterface, MyAbstract() { + override fun absFoo(): Unit = TODO() +} + +class ConflictingSubject2: MyAbstract(), MyInterface { + override fun absFoo(): Unit = TODO() +} + +class ConflictingSubject3: MyInterface, MyInterface2 { + override fun absFoo(): Unit = TODO() +} + +class ConflictingSubject4: MyInterface2, MyInterface { + override fun absFoo(): Unit = TODO() +} + +// FILE: overrideOrder.kt +interface GrandBaseInterface1 { + fun foo(): Unit +} + +interface GrandBaseInterface2 { + fun foo(): Unit +} + +interface BaseInterface1 : GrandBaseInterface1 { +} + +interface BaseInterface2 : GrandBaseInterface2 { +} + +class OverrideOrder1 : BaseInterface1, GrandBaseInterface2 { + override fun foo() = TODO() +} +class OverrideOrder2 : BaseInterface2, GrandBaseInterface1 { + override fun foo() = TODO() +} + +// FILE: JavaSubject.java +public class JavaSubject { + static abstract class GrandBase { + void openGrandBaseFun() {} + abstract void abstractGrandBaseFun(); + void overriddenGrandBaseFun() {} + abstract void overriddenAbstractGrandBaseFun(); + } + static abstract class Base<T> extends GrandBase { + void openFun() {} + abstract void abstractFun(); + T openFunWithGenericArg(T t) { + return null; + } + abstract T abstractFunWithGenericArg(T t); + void overriddenGrandBaseFun() {} + void overriddenAbstractGrandBaseFun() {} + } + + static abstract class Subject extends Base<String> { + void openFun() {} + void abstractFun() {} + String openFunWithGenericArg(String t) { + return null; + } + String abstractFunWithGenericArg(String t) { + return null; + } + String nonOverridingMethod() { + return null; + } + void overriddenGrandBaseFun() {} + void overriddenAbstractGrandBaseFun() {} + void openGrandBaseFun() {} + void abstractGrandBaseFun() {} + static String staticMethod() { + return null; + } + } +} + +// FILE: JavaImpl.java +class JavaAccessorImpl implements KtInterfaceWithProperty { + public int getX() { + return 1; + } + public int getY() { + return 1; + } + public void setY(int value) { + } +} + +// FILE: JavaAnno.java +@java.lang.annotation.Repeatable(JavaAnnos.class) +public @interface JavaAnno { + int intParam(); +} + +// FILE: JavaAnnos.java +public @interface JavaAnnos { + JavaAnno[] value(); +} diff --git a/test-utils/testData/api/parameterTypes.kt b/test-utils/testData/api/parameterTypes.kt new file mode 100644 index 00000000..36fb2cdd --- /dev/null +++ b/test-utils/testData/api/parameterTypes.kt @@ -0,0 +1,41 @@ +/* + * Copyright 2022 Google LLC + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// TEST PROCESSOR: ParameterTypeProcessor +// EXPECTED: +// a: Int +// b: <ERROR TYPE> +// c: <ERROR TYPE> +// errorValue: <ERROR TYPE> +// v: String +// value: Int +// END + +class Foo { + var a: ErrorType + set(errorValue) { + a = errorValue + } + var x + get() = "OK" + set(v) = Unit + var a:Int + get() = a + set(value) { a = value } + + fun foo(a: Int, b: NonExist, c) +} diff --git a/test-utils/testData/api/parent.kt b/test-utils/testData/api/parent.kt new file mode 100644 index 00000000..5237289b --- /dev/null +++ b/test-utils/testData/api/parent.kt @@ -0,0 +1,298 @@ +/* + * Copyright 2022 Google LLC + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// TEST PROCESSOR: ParentProcessor +// EXPECTED: +// parent of File: a.kt: null +// parent of Any: Anno +// parent of Anno: File: a.kt +// parent of Anno: synthetic constructor for Anno +// parent of synthetic constructor for Anno: Anno +// parent of Int: Int +// parent of Int: INVARIANT Int +// parent of INVARIANT Int: Map +// parent of T: T +// parent of T: INVARIANT T +// parent of INVARIANT T: Map +// parent of Map: Map +// parent of Map: Alias +// parent of Any?: T +// parent of T: Alias +// parent of Alias: File: a.kt +// parent of Int: Int +// parent of Int: INVARIANT Int +// parent of INVARIANT Int: List +// parent of List: List +// parent of List: topProp +// parent of Int: Int +// parent of Int: INVARIANT Int +// parent of INVARIANT Int: List<Int> +// parent of List<Int>: List<Int> +// parent of List<Int>: topProp.getter() +// parent of topProp.getter(): topProp +// parent of Anno: Anno +// parent of Anno: @Anno +// parent of @Anno: topProp +// parent of topProp: File: a.kt +// parent of T: T +// parent of T: topFun +// parent of Any?: T +// parent of T: topFun +// parent of Anno: Anno +// parent of Anno: @Anno +// parent of @Anno: topFun +// parent of topFun: File: a.kt +// parent of Any: ITF +// parent of ITF: File: a.kt +// parent of ITF: ITF +// parent of ITF: topClass +// parent of Anno: Anno +// parent of Anno: @Anno +// parent of @Anno: topClass +// parent of topClass: File: a.kt +// parent of Int: Int +// parent of Int: i +// parent of i: memberFun +// parent of Int: memberFun +// parent of memberFun: topClass +// parent of Any: InnerClass +// parent of Any?: P +// parent of P: InnerClass +// parent of InnerClass: topClass +// parent of P: P +// parent of P: p +// parent of p: innerFun +// parent of Int: innerFun +// parent of innerFun: InnerClass +// parent of InnerClass<*>: synthetic constructor for InnerClass +// parent of synthetic constructor for InnerClass: InnerClass +// parent of Int: Int +// parent of Int: a +// parent of Int: Int +// parent of Int: a.getter() +// parent of a.getter(): a +// parent of a: topClass +// parent of String: String +// parent of String: b +// parent of b.getter(): b +// parent of String: String +// parent of String: <set-?> +// parent of <set-?>: b.setter() +// parent of b.setter(): b +// parent of b: topClass +// parent of topClass: synthetic constructor for topClass +// parent of synthetic constructor for topClass: topClass +// parent of Any: CMYK +// parent of CMYK: File: a.kt +// parent of Any: C +// parent of C: CMYK +// parent of C: synthetic constructor for C +// parent of synthetic constructor for C: C +// parent of Any: M +// parent of M: CMYK +// parent of M: synthetic constructor for M +// parent of synthetic constructor for M: M +// parent of Any: Y +// parent of Y: CMYK +// parent of Y: synthetic constructor for Y +// parent of synthetic constructor for Y: Y +// parent of Any: K +// parent of K: CMYK +// parent of K: synthetic constructor for K +// parent of synthetic constructor for K: K +// parent of CMYK: synthetic constructor for CMYK +// parent of synthetic constructor for CMYK: CMYK +// parent of File: Bnno.kt: null +// parent of Any: Bnno +// parent of Bnno: File: Bnno.kt +// parent of Bnno: synthetic constructor for Bnno +// parent of synthetic constructor for Bnno: Bnno +// parent of File: B.java: null +// parent of ITF: ITF +// parent of ITF: B +// parent of T: B +// parent of Anno: Anno +// parent of Anno: @Anno +// parent of @Anno: B +// parent of p: Bnno +// parent of p.Bnno: Bnno +// parent of Bnno: @Bnno +// parent of @Bnno: B +// parent of B: File: B.java +// parent of T: T +// parent of T: t +// parent of t: B +// parent of T: T +// parent of T: t +// parent of t: foo +// parent of Int: Int +// parent of Int: i +// parent of i: foo +// parent of Int: Int +// parent of Int: foo +// parent of foo: B +// parent of B<*>: synthetic constructor for B +// parent of synthetic constructor for B: B +// parent of RGB: RGB +// parent of RGB: INVARIANT RGB +// parent of INVARIANT RGB: Enum<RGB> +// parent of Enum<RGB>: Enum<RGB> +// parent of Enum<RGB>: RGB +// parent of RGB: File: B.java +// parent of R: RGB +// parent of G: RGB +// parent of B: RGB +// parent of RGB: RGB +// parent of RGB: INVARIANT RGB +// parent of INVARIANT RGB: Array<(RGB..RGB?)> +// parent of Array<(RGB..RGB?)>: Array<(RGB..RGB?)> +// parent of Array<(RGB..RGB?)>: values +// parent of values: RGB +// parent of java: String +// parent of lang: String +// parent of String: String +// parent of String: name +// parent of name: valueOf +// parent of RGB: RGB +// parent of RGB: valueOf +// parent of valueOf: RGB +// parent of RGB: synthetic constructor for RGB +// parent of synthetic constructor for RGB: RGB +// parent of YUV: YUV +// parent of YUV: INVARIANT YUV +// parent of INVARIANT YUV: Enum<YUV> +// parent of Enum<YUV>: Enum<YUV> +// parent of Enum<YUV>: YUV +// parent of YUV: null +// parent of YUV: YUV +// parent of YUV: Y +// parent of Y: YUV +// parent of YUV: YUV +// parent of YUV: U +// parent of U: YUV +// parent of YUV: YUV +// parent of YUV: V +// parent of V: YUV +// parent of String: String +// parent of String: value +// parent of value: valueOf +// parent of YUV: YUV +// parent of YUV: valueOf +// parent of valueOf: YUV +// parent of YUV: YUV +// parent of YUV: INVARIANT YUV +// parent of INVARIANT YUV: Array<YUV> +// parent of Array<YUV>: Array<YUV> +// parent of Array<YUV>: values +// parent of values: YUV +// parent of YUV: YUV +// parent of YUV: <init> +// parent of <init>: YUV +// parent of HSV: HSV +// parent of HSV: INVARIANT HSV +// parent of INVARIANT HSV: Enum<(HSV..HSV?)> +// parent of Enum<(HSV..HSV?)>: Enum<(HSV..HSV?)> +// parent of Enum<(HSV..HSV?)>: HSV +// parent of HSV: null +// parent of HSV: HSV +// parent of HSV: H +// parent of H: HSV +// parent of HSV: HSV +// parent of HSV: S +// parent of S: HSV +// parent of HSV: HSV +// parent of HSV: V +// parent of V: HSV +// parent of String: String +// parent of String: value +// parent of value: valueOf +// parent of HSV: HSV +// parent of HSV: valueOf +// parent of valueOf: HSV +// parent of HSV: HSV +// parent of HSV: INVARIANT HSV +// parent of INVARIANT HSV: Array<HSV> +// parent of Array<HSV>: Array<HSV> +// parent of Array<HSV>: values +// parent of values: HSV +// parent of HSV: HSV +// parent of HSV: <init> +// parent of <init>: HSV +// END + +// MODULE: lib +// FILE: YUV.kt +enum class YUV { + Y, U, V +} + +// FILE: HSV.java +enum HSV { + H, S, V +} + +// MODULE: main(lib) + +// FILE: a.kt +annotation class Anno + +typealias Alias<T> = Map<Int, T> + +@Anno +val topProp : List<Int>? = null + +@Anno +fun <T> topFun() : T? { + return null +} + +interface ITF + +@Anno +class topClass: ITF { + fun memberFun(i: Int) = 1 + class InnerClass<P> { + fun innerFun(p: P) = 1 + } + + val a: Int = 1 + var b: String + get() = "1" +} + +enum class CMYK { + C, M, Y, K +} + +// FILE: Bnno.kt +package p + +annotation class Bnno + +// FILE: B.java +@Anno +@p.Bnno +public class B<T> implements ITF { + private T t; + public int foo(T t, int i) { + return 1; + } +} + +enum RGB { + R, G, B +} diff --git a/test-utils/testData/api/platformDeclaration.kt b/test-utils/testData/api/platformDeclaration.kt new file mode 100644 index 00000000..40b8be1c --- /dev/null +++ b/test-utils/testData/api/platformDeclaration.kt @@ -0,0 +1,103 @@ +/* + * Copyright 2020 Google LLC + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// WITH_RUNTIME +// TEST PROCESSOR: PlatformDeclarationProcessor +// EXPECTED: +// Actual.kt : Clazz : true : false : [] : [Expect.kt] +// Actual.kt : Clazz.foo : true : false : [] : [Expect.kt] +// Actual.kt : ExpectNotFoundClass : true : false : [] : [] +// Actual.kt : ExpectNotFoundFun : true : false : [] : [] +// Actual.kt : ExpectNotFoundVal : true : false : [] : [] +// Actual.kt : Klass : true : false : [] : [Expect.kt] +// Actual.kt : RGB : true : false : [] : [Expect.kt] +// Actual.kt : RGB.B : true : false : [] : [Expect.kt] +// Actual.kt : RGB.G : true : false : [] : [Expect.kt] +// Actual.kt : RGB.R : true : false : [] : [Expect.kt] +// Actual.kt : RGB.v : false : false : [] : [] +// Actual.kt : bar : true : false : [] : [Expect.kt] +// Actual.kt : baz : true : false : [] : [Expect.kt] +// Coffee.java : Coffee : false : false : [] : [] +// Coffee.java : Coffee.baz : false : false : [] : [] +// Coffee.java : Coffee.foo : false : false : [] : [] +// Expect.kt : ActualNotFoundClass : false : true : [] : [] +// Expect.kt : ActualNotFoundFun : false : true : [] : [] +// Expect.kt : ActualNotFoundVal : false : true : [] : [] +// Expect.kt : Clazz : false : true : [Actual.kt] : [] +// Expect.kt : Clazz.foo : false : true : [Actual.kt] : [] +// Expect.kt : Klass : false : true : [Actual.kt] : [] +// Expect.kt : NormalClass : false : false : [] : [] +// Expect.kt : NormalFun : false : false : [] : [] +// Expect.kt : NormalVal : false : false : [] : [] +// Expect.kt : RGB : false : true : [Actual.kt] : [] +// Expect.kt : RGB.B : false : true : [Actual.kt] : [] +// Expect.kt : RGB.G : false : true : [Actual.kt] : [] +// Expect.kt : RGB.R : false : true : [Actual.kt] : [] +// Expect.kt : bar : false : true : [Actual.kt] : [] +// Expect.kt : baz : false : true : [Actual.kt] : [] +// END + +// FILE: Expect.kt +expect class Clazz { + fun foo(): String +} + +expect fun bar(): String +expect val baz: String +expect class Klass + +class NormalClass +fun NormalFun(): String = "" +val NormalVal: String = "" + +expect class ActualNotFoundClass +expect fun ActualNotFoundFun(): String +expect val ActualNotFoundVal: String + +expect enum class RGB { + R, + expect G, + B +} + +// FILE: Actual.kt +actual class Clazz { + actual fun foo(): String = "foo" +} + +actual fun bar(): String = "bar" +actual val baz: String = "baz" +actual typealias Klass = String + +actual class ExpectNotFoundClass +actual fun ExpectNotFoundFun(): String +actual val ExpectNotFoundVal: String + +actual enum class RGB(val v: Int) { + actual R(0xFF0000), + actual G(0x00FF00), + actual B(0x0000FF) +} + +// FILE: Coffee.java +class Coffee { + String foo() { + return null + } + + String baz = null +} diff --git a/test-utils/testData/api/rawTypes.kt b/test-utils/testData/api/rawTypes.kt new file mode 100644 index 00000000..aa948a8f --- /dev/null +++ b/test-utils/testData/api/rawTypes.kt @@ -0,0 +1,100 @@ +/* + * Copyright 2022 Google LLC + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// WITH_RUNTIME +// TEST PROCESSOR: RawTypesProcessor +// EXPECTED: +// barRaw +// barRawField +// barRawGet +// barRawGetCompiled +// fooRaw +// fooRawField +// fooRawGet +// fooRawGetCompiled +// p4 +// p5 +// END +// MODULE: lib +// FILE: dummy.kt +// FILE: Api.java +public interface Api {} + +// FILE: Foo.java +public class Foo<T> {} + +// FILE: Bar.java +public class Bar<T extends Api> {} + +// FILE: UsageCompiled.java +public abstract class UsageCompiled { + public static void usage( + Foo<?> fooWildcardCompiled, + Foo<? super Api> fooWildcardExCompiled, + Bar<?> barWildcardCompiled, + Bar<? extends Api> barWildcardExCompiled, + Foo fooRawCompiled, + Bar barRawCompiled + ) {} + + public abstract Foo<?> fooWildcardGetCompiled(); + public abstract Foo<? super Api> fooWildcardExGetCompiled(); + public abstract Bar<?> barWildcardGetCompiled(); + public abstract Bar<? extends Api> barWildcardExGetCompiled(); + public abstract Foo fooRawGetCompiled(); + public abstract Bar barRawGetCompiled(); +} + +// MODULE: main(lib) +// FILE: usage.kt +fun usage( + fooStar: Foo<*>, + fooIn: Foo<in Api>, + fooOut: Foo<out Api>, + barStar: Bar<*>, +) = Unit + +val fooStarProp: Foo<*> +val fooInProp: Foo<in Api> +val fooOutProp: Foo<out Api> +val barStarProp: Bar<*> + +// FILE: Usage.java +public abstract class Usage { + public Foo<?> fooWildcardField; + public Foo<? super Api> fooWildcardExField; + public Bar<?> barWildcardField; + public Bar<? extends Api> barWildcardExField; + public Foo fooRawField; + public Bar barRawField; + + public static void usage( + Foo<?> fooWildcard, + Foo<? super Api> fooWildcardEx, + Bar<?> barWildcard, + Bar<? extends Api> barWildcardEx, + Foo fooRaw, + Bar barRaw + ) {} + + public abstract Foo<?> fooWildcardGet(); + public abstract Foo<? super Api> fooWildcardExGet(); + public abstract Bar<?> barWildcardGet(); + public abstract Bar<? extends Api> barWildcardExGet(); + public abstract Foo fooRawGet(); + public abstract Bar barRawGet(); +} diff --git a/test-utils/testData/api/recordJavaAnnotationTypes.kt b/test-utils/testData/api/recordJavaAnnotationTypes.kt new file mode 100644 index 00000000..c268f6a2 --- /dev/null +++ b/test-utils/testData/api/recordJavaAnnotationTypes.kt @@ -0,0 +1,46 @@ +/* + * Copyright 2020 Google LLC + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// WITH_RUNTIME +// TEST PROCESSOR: RecordJavaProcessor +// EXPECTED: +// java.util.List: javaSrc/p1/J.java +// p1.Anno: javaSrc/p1/J.java +// p1.Bnno: javaSrc/p1/J.java +// p1.K: javaSrc/p1/J.java +// END + +// FILE: p1/J.java +package p1; + +import java.util.List; + +@interface Anno { +} + +@Anno +@Bnno +public class J { + List<K> l = null; +} + +// FILE: p1/K.kt +package p1; + +annotation class Bnno + +class K diff --git a/test-utils/testData/api/recordJavaAsMemberOf.kt b/test-utils/testData/api/recordJavaAsMemberOf.kt new file mode 100644 index 00000000..4c06bc1c --- /dev/null +++ b/test-utils/testData/api/recordJavaAsMemberOf.kt @@ -0,0 +1,47 @@ +/* + * Copyright 2020 Google LLC + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// WITH_RUNTIME +// TEST PROCESSOR: RecordJavaAsMemberOfProcessor +// EXPECTED: +// p1.A: javaSrc/p1/B.java +// p1.B: javaSrc/p1/A.java +// p1.C: javaSrc/p1/B.java +// p1.D: javaSrc/p1/A.java +// p1.D: javaSrc/p1/B.java +// p1.E: javaSrc/p1/B.java +// END + +// FILE: p1/A.java +package p1; +public class A<T> extends B<T, D> { +} + +// FILE: p1/B.java +package p1; +public class B<T, R> { + public <T extends D> R f(A<? super C> p, E p2) { + return null; + } +} + +// FILE: p1/C.kt +package p1; +class C +class D +class E +val a = A<C>()
\ No newline at end of file diff --git a/test-utils/testData/api/recordJavaGetAllMembers.kt b/test-utils/testData/api/recordJavaGetAllMembers.kt new file mode 100644 index 00000000..55da59d9 --- /dev/null +++ b/test-utils/testData/api/recordJavaGetAllMembers.kt @@ -0,0 +1,65 @@ +/* + * Copyright 2020 Google LLC + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// WITH_RUNTIME +// TEST PROCESSOR: RecordJavaGetAllMembersProcessor +// EXPECTED: +// p1.C: javaSrc/p1/B.java +// p1.D: javaSrc/p1/C.java +// p1.R2: javaSrc/p1/B.java +// p1.R3: javaSrc/p1/C.java +// p1.V2: javaSrc/p1/B.java +// p1.V3: javaSrc/p1/C.java +// END + +// FILE: p1/A.kt +package p1; +class A : B { + fun f1(): R1 + val v1: V1 = TODO() +} + +// FILE: p1/B.java +package p1; +public class B extends C { + R2 f2() { return null } + V2 v2 = null; +} + +// FILE: p1/C.java +package p1; +public class C extends D { + R3 f3() { return null } + V3 v3 = null; +} + +// FILE: p1/D.kt +package p1; + +class D { + fun f4(): R4 + val v4: V4 = TODO() +} + +class R1 +class R2 +class R3 +class R4 +class V1 +class V2 +class V3 +class V4 diff --git a/test-utils/testData/api/recordJavaOverrides.kt b/test-utils/testData/api/recordJavaOverrides.kt new file mode 100644 index 00000000..f8c9b88f --- /dev/null +++ b/test-utils/testData/api/recordJavaOverrides.kt @@ -0,0 +1,71 @@ +/* + * Copyright 2020 Google LLC + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// WITH_RUNTIME +// TEST PROCESSOR: RecordJavaOverridesProcessor +// EXPECTED: +// p1.B: javaSrc/p1/A.java +// p1.C: javaSrc/p1/B.java +// p1.R1: javaSrc/p1/A.java +// p1.R1: javaSrc/p1/C.java +// p1.R2: javaSrc/p1/A.java +// p1.R2: javaSrc/p1/C.java +// p1.V1: javaSrc/p1/A.java +// p1.V1: javaSrc/p1/C.java +// p1.V2: javaSrc/p1/A.java +// p1.V2: javaSrc/p1/C.java +// END + +// FILE: p1/A.java +package p1; +public class A extends B { + R1 f1(V1 v) { + return null + } + + R2 f2(V2 v) { + return null + } +} + +// FILE: p1/B.java +package p1; +public class B extends C { + R1 f1(V1 v) { + return null + } +} + +// FILE: p1/C.java +package p1; +public class C extends D { + R1 f1(V1 v) { + return null + } + + R2 f2(V2 v) { + return null + } +} + +// FILE: p1/D.kt +package p1; + +class V1 +class V2 +class R1 +class R2 diff --git a/test-utils/testData/api/recordJavaResolutions.kt b/test-utils/testData/api/recordJavaResolutions.kt new file mode 100644 index 00000000..4f535ce5 --- /dev/null +++ b/test-utils/testData/api/recordJavaResolutions.kt @@ -0,0 +1,90 @@ +/* + * Copyright 2020 Google LLC + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// WITH_RUNTIME +// TEST PROCESSOR: RecordJavaProcessor +// EXPECTED: +// p3.K3: javaSrc/p1/TestJ2K.java +// p1.J1: javaSrc/p1/TestJ2J.java +// p1.J3: javaSrc/p1/TestJ2J.java +// p1.K1: javaSrc/p1/TestJ2K.java +// p1.K3: javaSrc/p1/TestJ2K.java +// p2.J2: javaSrc/p1/TestJ2J.java +// p2.K2: javaSrc/p1/TestJ2K.java +// p3.J3: javaSrc/p1/TestJ2J.java +// END + +// FILE: p1/TestJ2K.java +package p1; + +import p2.K2; +import p3.*; + +public class TestJ2K { + K1 k1 = null; + K2 k2 = null; + K3 k3 = null; +} + +// FILE: p1/TestJ2J.java +package p1; + +import p2.J2; +import p3.*; + +public class TestJ2J { + J1 j1 = null; + J2 j2 = null; + J3 j3 = null; +} + +// FILE: p1/K1.kt +package p1 +class K1 +// FILE: p1/K2.kt +package p1 +class K2 +// FILE: p2/K2.kt +package p2 +class K2 +// FILE: p3/K1.kt +package p3 +class K1 +// FILE: p3/K2.kt +package p3 +class K2 +// FILE: p3/K3.kt +package p3 +class K3 +// FILE: p1/J1.java +package p1; +public class J1 {} +// FILE: p1/J2.java +package p1; +public class J2 {} +// FILE: p2/J2.java +package p2; +public class J2 {} +// FILE: p3/J1.java +package p3; +public class J1 {} +// FILE: p3/J2.java +package p3; +public class J2 {} +// FILE: p3/J3.java +package p3; +public class J3 {} diff --git a/test-utils/testData/api/recordJavaSupertypes.kt b/test-utils/testData/api/recordJavaSupertypes.kt new file mode 100644 index 00000000..d7b7a37f --- /dev/null +++ b/test-utils/testData/api/recordJavaSupertypes.kt @@ -0,0 +1,42 @@ +/* + * Copyright 2020 Google LLC + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// WITH_RUNTIME +// TEST PROCESSOR: RecordJavaSupertypesProcessor +// EXPECTED: +// <anonymous>.A: javaSrc/A.java +// <anonymous>.B: javaSrc/A.java +// <anonymous>.C: javaSrc/A.java +// <anonymous>.D: javaSrc/C.java +// END + +// FILE: A.java +public class A extends B<C<A>> { +} + +// FILE: B.kt +open class B<T>() : C<T>() + +// FILE: C.java +public class C<T> extends D { + +} + +// FILE: D.java +public class D { + +}
\ No newline at end of file diff --git a/test-utils/testData/api/referenceElement.kt b/test-utils/testData/api/referenceElement.kt new file mode 100644 index 00000000..513ad429 --- /dev/null +++ b/test-utils/testData/api/referenceElement.kt @@ -0,0 +1,75 @@ +/* + * Copyright 2020 Google LLC + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// WITH_RUNTIME +// TEST PROCESSOR: ReferenceElementProcessor +// EXPECTED: +// KSClassifierReferenceImpl: Qualifier of B is A +// KSClassifierReferenceImpl: Qualifier of C is A +// KSClassifierReferenceImpl: Qualifier of Int is null +// KSClassifierReferenceImpl: Qualifier of String is null +// KSClassifierReferenceDescriptorImpl: Qualifier of Int is null +// KSClassifierReferenceDescriptorImpl: Qualifier of String is null +// KSClassifierReferenceDescriptorImpl: Qualifier of Y is X +// KSClassifierReferenceDescriptorImpl: Qualifier of Z<Int> is X<String> +// KSDefNonNullReferenceImpl: Enclosed type of T +// KSClassifierReferenceJavaImpl: Qualifier of H is J<String> +// KSClassifierReferenceJavaImpl: Qualifier of I is J +// KSClassifierReferenceJavaImpl: Qualifier of Object is null +// KSClassifierReferenceJavaImpl: Qualifier of Object is null +// KSClassifierReferenceJavaImpl: Qualifier of Object is null +// KSClassifierReferenceJavaImpl: Qualifier of Object is null +// KSClassifierReferenceJavaImpl: Qualifier of String is null +// END + +// MODULE: lib +// FILE: lib.kt +class X<T1> { + class Y + inner class Z<T2> +} + +val z: X.Y = X.Y() +val w: X<String>.Z<Int> = X<String>().Z<Int>() + +// MODULE: main(lib) +// FILE: reference.kt +class A<T1> { + class B + inner class C<T2> +} + +class DefNonNull<T> { + val u: T & Any +} + +val x: A.B = A.B() +val y: A<String>.C<Int> = A<String>().C<Int>() + +// FILE: J.java +class J<T> { + class H { + } + + static class I { + } +} + +class K { + J<String>.H x = null; + J.I z = null; +} diff --git a/test-utils/testData/api/replaceWithErrorTypeArgs.kt b/test-utils/testData/api/replaceWithErrorTypeArgs.kt new file mode 100644 index 00000000..4a4bd9b0 --- /dev/null +++ b/test-utils/testData/api/replaceWithErrorTypeArgs.kt @@ -0,0 +1,134 @@ +/* + * Copyright 2020 Google LLC + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// WITH_RUNTIME +// TEST PROCESSOR: ReplaceWithErrorTypeArgsProcessor +// EXPECTED: +// KS.star.replace([INVARIANT Int, INVARIANT String]): KS<Int, String> +// KS.star.replace([INVARIANT NotExist1, INVARIANT NotExist2]): <ERROR TYPE> +// KS.asType([INVARIANT Int, INVARIANT String]): KS<Int, String> +// KS.asType([INVARIANT NotExist1, INVARIANT NotExist2]): <ERROR TYPE> +// KS.asType(emptyList()): KS<T1, T2> +// KL.star.replace([INVARIANT Int, INVARIANT String]): KL<Int, String> +// KL.star.replace([INVARIANT NotExist1, INVARIANT NotExist2]): <ERROR TYPE> +// KL.asType([INVARIANT Int, INVARIANT String]): KL<Int, String> +// KL.asType([INVARIANT NotExist1, INVARIANT NotExist2]): <ERROR TYPE> +// KL.asType(emptyList()): KL<T1, T2> +// JS.star.replace([INVARIANT Int, INVARIANT String]): JS<Int, String> +// JS.star.replace([INVARIANT NotExist1, INVARIANT NotExist2]): <ERROR TYPE> +// JS.asType([INVARIANT Int, INVARIANT String]): JS<Int, String> +// JS.asType([INVARIANT NotExist1, INVARIANT NotExist2]): <ERROR TYPE> +// JS.asType(emptyList()): JS<T1, T2> +// JL.star.replace([INVARIANT Int, INVARIANT String]): JL<Int, String> +// JL.star.replace([INVARIANT NotExist1, INVARIANT NotExist2]): <ERROR TYPE> +// JL.asType([INVARIANT Int, INVARIANT String]): JL<Int, String> +// JL.asType([INVARIANT NotExist1, INVARIANT NotExist2]): <ERROR TYPE> +// JL.asType(emptyList()): JL<T1, T2> +// KS1.star.replace([INVARIANT Int, INVARIANT String]): <ERROR TYPE> +// KS1.star.replace([INVARIANT NotExist1, INVARIANT NotExist2]): <ERROR TYPE> +// KS1.asType([INVARIANT Int, INVARIANT String]): <ERROR TYPE> +// KS1.asType([INVARIANT NotExist1, INVARIANT NotExist2]): <ERROR TYPE> +// KS1.asType(emptyList()): KS1<T> +// KL1.star.replace([INVARIANT Int, INVARIANT String]): <ERROR TYPE> +// KL1.star.replace([INVARIANT NotExist1, INVARIANT NotExist2]): <ERROR TYPE> +// KL1.asType([INVARIANT Int, INVARIANT String]): <ERROR TYPE> +// KL1.asType([INVARIANT NotExist1, INVARIANT NotExist2]): <ERROR TYPE> +// KL1.asType(emptyList()): KL1<T> +// JS1.star.replace([INVARIANT Int, INVARIANT String]): <ERROR TYPE> +// JS1.star.replace([INVARIANT NotExist1, INVARIANT NotExist2]): <ERROR TYPE> +// JS1.asType([INVARIANT Int, INVARIANT String]): <ERROR TYPE> +// JS1.asType([INVARIANT NotExist1, INVARIANT NotExist2]): <ERROR TYPE> +// JS1.asType(emptyList()): JS1<T> +// JL1.star.replace([INVARIANT Int, INVARIANT String]): <ERROR TYPE> +// JL1.star.replace([INVARIANT NotExist1, INVARIANT NotExist2]): <ERROR TYPE> +// JL1.asType([INVARIANT Int, INVARIANT String]): <ERROR TYPE> +// JL1.asType([INVARIANT NotExist1, INVARIANT NotExist2]): <ERROR TYPE> +// JL1.asType(emptyList()): JL1<T> +// JSE.star.replace([INVARIANT Int, INVARIANT String]): <ERROR TYPE> +// JSE.star.replace([INVARIANT NotExist1, INVARIANT NotExist2]): <ERROR TYPE> +// JSE.asType([INVARIANT Int, INVARIANT String]): <ERROR TYPE> +// JSE.asType([INVARIANT NotExist1, INVARIANT NotExist2]): <ERROR TYPE> +// JSE.asType(emptyList()): JSE +// JSE.E.star.replace([INVARIANT Int, INVARIANT String]): <ERROR TYPE> +// JSE.E.star.replace([INVARIANT NotExist1, INVARIANT NotExist2]): <ERROR TYPE> +// JSE.E.asType([INVARIANT Int, INVARIANT String]): <ERROR TYPE> +// JSE.E.asType([INVARIANT NotExist1, INVARIANT NotExist2]): <ERROR TYPE> +// JSE.E.asType(emptyList()): JSE.E +// JLE.star.replace([INVARIANT Int, INVARIANT String]): <ERROR TYPE> +// JLE.star.replace([INVARIANT NotExist1, INVARIANT NotExist2]): <ERROR TYPE> +// JLE.asType([INVARIANT Int, INVARIANT String]): <ERROR TYPE> +// JLE.asType([INVARIANT NotExist1, INVARIANT NotExist2]): <ERROR TYPE> +// JLE.asType(emptyList()): JLE +// JLE.E.star.replace([INVARIANT Int, INVARIANT String]): <ERROR TYPE> +// JLE.E.star.replace([INVARIANT NotExist1, INVARIANT NotExist2]): <ERROR TYPE> +// JLE.E.asType([INVARIANT Int, INVARIANT String]): <ERROR TYPE> +// JLE.E.asType([INVARIANT NotExist1, INVARIANT NotExist2]): <ERROR TYPE> +// JLE.E.asType(emptyList()): JLE.E +// KSE.star.replace([INVARIANT Int, INVARIANT String]): <ERROR TYPE> +// KSE.star.replace([INVARIANT NotExist1, INVARIANT NotExist2]): <ERROR TYPE> +// KSE.asType([INVARIANT Int, INVARIANT String]): <ERROR TYPE> +// KSE.asType([INVARIANT NotExist1, INVARIANT NotExist2]): <ERROR TYPE> +// KSE.asType(emptyList()): KSE +// KSE.E.star.replace([INVARIANT Int, INVARIANT String]): <ERROR TYPE> +// KSE.E.star.replace([INVARIANT NotExist1, INVARIANT NotExist2]): <ERROR TYPE> +// KSE.E.asType([INVARIANT Int, INVARIANT String]): <ERROR TYPE> +// KSE.E.asType([INVARIANT NotExist1, INVARIANT NotExist2]): <ERROR TYPE> +// KSE.E.asType(emptyList()): E +// KLE.star.replace([INVARIANT Int, INVARIANT String]): <ERROR TYPE> +// KLE.star.replace([INVARIANT NotExist1, INVARIANT NotExist2]): <ERROR TYPE> +// KLE.asType([INVARIANT Int, INVARIANT String]): <ERROR TYPE> +// KLE.asType([INVARIANT NotExist1, INVARIANT NotExist2]): <ERROR TYPE> +// KLE.asType(emptyList()): KLE +// KLE.E.star.replace([INVARIANT Int, INVARIANT String]): <ERROR TYPE> +// KLE.E.star.replace([INVARIANT NotExist1, INVARIANT NotExist2]): <ERROR TYPE> +// KLE.E.asType([INVARIANT Int, INVARIANT String]): <ERROR TYPE> +// KLE.E.asType([INVARIANT NotExist1, INVARIANT NotExist2]): <ERROR TYPE> +// KLE.E.asType(emptyList()): KLE.E +// END + +// MODULE: lib +// FILE: JL.java +class JL<T1, T2> {} +class JL1<T> {} +enum JLE { + E +} + +// FILE: KL.kt +class KL<T1, T2> +class KL1<T> +enum class KLE { + E +} + +// MODULE: main(lib) +// FILE: JS.java +class JS<T1, T2> {} +class JS1<T> {} +enum JSE { + E +} + +// FILE: KS.kt +class KS<T1, T2> +class KS1<T> +enum class KSE { + E +} + +val x: KS<Int, String> = TODO() +val y: KS<NotExist1, NotExist2> = TODO() diff --git a/test-utils/testData/api/resolveJavaType.kt b/test-utils/testData/api/resolveJavaType.kt new file mode 100644 index 00000000..b732b270 --- /dev/null +++ b/test-utils/testData/api/resolveJavaType.kt @@ -0,0 +1,135 @@ +/* + * Copyright 2020 Google LLC + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// TEST PROCESSOR: ResolveJavaTypeProcessor +// EXPECTED: +// C<*kotlin.Any?> +// C.<init>.X? +// C<*kotlin.Any?> +// kotlin.Int +// kotlin.String? +// kotlin.collections.MutableSet<*kotlin.Any?>? +// kotlin.Unit +// kotlin.IntArray? +// C.T? +// C.PFun.P? +// kotlin.collections.MutableList<out kotlin.collections.MutableSet<kotlin.Double?>?>? +// kotlin.collections.MutableList<in kotlin.collections.MutableList<out kotlin.Double?>?>? +// Bar? +// kotlin.Array<Bar?>? +// Foo<Base.T?, Base.Inner.P?>? +// Bar<Base.Inner.P?, Base.T?>? +// kotlin.collections.MutableList<Base.T?>? +// kotlin.Unit +// Base.T? +// kotlin.Unit +// kotlin.Array<Base.T?>? +// kotlin.Unit +// kotlin.Array<Base.T?>? +// kotlin.Unit +// kotlin.collections.MutableList<Base.T?>? +// kotlin.Unit +// Base.T? +// kotlin.Unit +// kotlin.Array<Base.T?>? +// kotlin.Unit +// kotlin.Array<Base.T?>? +// kotlin.Unit +// Base<Another.T?, Another.T?>? +// kotlin.Int +// kotlin.Int +// JavaEnum +// kotlin.Unit +// kotlin.Array<JavaEnum?>? +// kotlin.String? +// JavaEnum? +// END +// FILE: a.kt +annotation class Test +@Test +class Foo<P>: C<P>() { + +} + +class Bar + +// FILE: C.java +import java.util.List; +import java.util.Set; + +public class C<T> { + public C() {} + // to reproduce the case where type reference is owned by a constructor + public <X> C(X x) {} + public int intFun() {} + + public String strFun() {} + + public void wildcardParam(Set<?> param1) {} + + public int[] intArrayFun() {} + + public T TFoo() {} + + public <P> P PFun() {} + + public List<? extends Set<Double>> extendsSetFun() {} + + public List<? super List<? extends Double>> extendsListTFun() {} + + public Bar BarFun() {} + + public Bar[] BarArryFun() {} +} + +// FILE: Base.java +import java.util.List; + +class Foo<T1,T2> {} +class Bar<T1, T2> {} + +class Base<T,P> { + void genericT(List<T> t){}; + void singleT(T t){}; + void varargT(T... t){}; + void arrayT(T[] t){}; + + class Inner<P> { + void genericT(List<T> t){}; + void singleT(T t){}; + void varargT(T... t){}; + void arrayT(T[] t){}; + Foo<T, P> foo; + Bar<P, T> bar; + } +} + +class Another<T> { + Base<T, T> base; +} + +public enum JavaEnum { + VAL1(1), + VAL2(2); + + private int x; + + JavaEnum(int x) { + this.x = x; + } + void enumMethod() {} +} diff --git a/test-utils/testData/api/sealedClass.kt b/test-utils/testData/api/sealedClass.kt new file mode 100644 index 00000000..1af34fcd --- /dev/null +++ b/test-utils/testData/api/sealedClass.kt @@ -0,0 +1,42 @@ +/* + * Copyright 2021 Google LLC + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// TEST PROCESSOR: SealedClassProcessor +// EXPECTED: +// from lib +// [Const: KOTLIN_LIB, NotANumber: KOTLIN_LIB, Sum: KOTLIN_LIB] +// from source +// Expr : [Const: KOTLIN, NotANumber: KOTLIN, Sum: KOTLIN] +// Const : [] +// Sum : [] +// NotANumber : [] +// END + +// MODULE: lib +// FILE: lib.kt +package lib +sealed class Expr +data class Const(val number: Double) : Expr() +data class Sum(val e1: Expr, val e2: Expr) : Expr() +object NotANumber : Expr() + +// MODULE: main(lib) +// FILE: sealed.kt +sealed class Expr +data class Const(val number: Double) : Expr() +data class Sum(val e1: Expr, val e2: Expr) : Expr() +object NotANumber : Expr() diff --git a/test-utils/testData/api/signatureMapper.kt b/test-utils/testData/api/signatureMapper.kt new file mode 100644 index 00000000..dab48bb6 --- /dev/null +++ b/test-utils/testData/api/signatureMapper.kt @@ -0,0 +1,53 @@ +/* + * Copyright 2020 Google LLC + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// TEST PROCESSOR: MapSignatureProcessor +// EXPECTED: +// LCls; +// a: I +// foo: ()Ljava/lang/String; +// <init>: ()V +// LJavaIntefaceWithVoid; +// getVoid: ()Ljava/lang/Void; +// LJavaClass; +// <init>: ()V +// LJavaAnno; +// intParam: I +// <init>: (I)V +// END + +// FILE: Cls.kt +class Cls { + val a: Int = 1 + + fun foo(): String { return "1" } +} + +// FILE: JavaIntefaceWithVoid.java +interface JavaIntefaceWithVoid { + Void getVoid(); +} + +// FILE: JavaClass.java +class JavaClass { + JavaClass() {} +} + +// FILE: JavaAnno.java +@interface JavaAnno { + int intParam(); +} diff --git a/test-utils/testData/api/superTypes.kt b/test-utils/testData/api/superTypes.kt new file mode 100644 index 00000000..ce944f0a --- /dev/null +++ b/test-utils/testData/api/superTypes.kt @@ -0,0 +1,112 @@ +/* + * Copyright 2020 Google LLC + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// WITH_RUNTIME +// TEST PROCESSOR: SuperTypesProcessor +// EXPECTED: +// KotlinInterfaceInLib: kotlin.Any +// KotlinInterfaceInLibWithSuper: KotlinInterfaceInLib +// AbstractKotlinClassInLib: kotlin.Any +// AbstractKotlinClassInLibWithSuperClass: AbstractKotlinClassInLib +// AbstractKotlinClassInLibWithSuperInterface: KotlinInterfaceInLib +// KotlinClassInLib: kotlin.Any +// KotlinClassInLibWithSuperAbstract: AbstractKotlinClassInLib +// KotlinClassInLibWithSuperClass: KotlinClassInLib +// KotlinClassInLibWithSuperInterface: KotlinInterfaceInLib +// JavaInterfaceInLib: kotlin.Any +// JavaInterfaceInLibWithSuper: JavaInterfaceInLib +// AbstractJavaClassInLib: kotlin.Any +// AbstractJavaClassInLibWithSuperInterface: JavaInterfaceInLib +// AbstractJavaClassInLibWithSuperClass: AbstractJavaClassInLib +// JavaClassInLib: kotlin.Any +// JavaClassInLibWithSuperInterface: JavaInterfaceInLib +// JavaClassInLibWithSuperAbstract: AbstractJavaClassInLib +// JavaClassInLibWithSuperClass: JavaClassInLib +// KotlinInterfaceInSource: kotlin.Any +// KotlinInterfaceInSourceWithSuper: KotlinInterfaceInSource +// AbstractKotlinClassInSource: kotlin.Any +// AbstractKotlinClassInSourceWithSuperClass: AbstractKotlinClassInSource +// AbstractKotlinClassInSourceWithSuperInterface: KotlinInterfaceInSource +// KotlinClassInSource: kotlin.Any +// KotlinClassInSourceWithSuperAbstract: AbstractKotlinClassInSource +// KotlinClassInSourceWithSuperClass: KotlinClassInSource +// KotlinClassInSourceWithSuperInterface: KotlinInterfaceInSource +// JavaInterfaceInSource: kotlin.Any +// JavaInterfaceInSourceWithSuper: JavaInterfaceInSource +// AbstractJavaClassInSource: kotlin.Any +// AbstractJavaClassInSourceWithSuperInterface: JavaInterfaceInSource +// AbstractJavaClassInSourceWithSuperClass: AbstractJavaClassInSource +// JavaClassInSource: kotlin.Any +// JavaClassInSourceWithSuperInterface: JavaInterfaceInSource +// JavaClassInSourceWithSuperAbstract: AbstractJavaClassInSource +// JavaClassInSourceWithSuperClass: JavaClassInSource +// END + +// MODULE: lib +// FILE: KotlinLib.kt +interface KotlinInterfaceInLib +interface KotlinInterfaceInLibWithSuper : KotlinInterfaceInLib + +abstract class AbstractKotlinClassInLib +abstract class AbstractKotlinClassInLibWithSuperClass : AbstractKotlinClassInLib() +abstract class AbstractKotlinClassInLibWithSuperInterface : KotlinInterfaceInLib + +open class KotlinClassInLib +open class KotlinClassInLibWithSuperAbstract : AbstractKotlinClassInLib() +open class KotlinClassInLibWithSuperClass : KotlinClassInLib() +open class KotlinClassInLibWithSuperInterface : KotlinInterfaceInLib + +// FILE: JavaLib.java +interface JavaInterfaceInLib {} +interface JavaInterfaceInLibWithSuper extends JavaInterfaceInLib {} + +abstract class AbstractJavaClassInLib {} +abstract class AbstractJavaClassInLibWithSuperInterface implements JavaInterfaceInLib {} +abstract class AbstractJavaClassInLibWithSuperClass extends AbstractJavaClassInLib {} + +class JavaClassInLib {} +class JavaClassInLibWithSuperInterface implements JavaInterfaceInLib {} +class JavaClassInLibWithSuperAbstract extends AbstractJavaClassInLib {} +class JavaClassInLibWithSuperClass extends JavaClassInLib {} + +// MODULE: main(lib) +// FILE: KotlinSource.kt +interface KotlinInterfaceInSource +interface KotlinInterfaceInSourceWithSuper : KotlinInterfaceInSource + +abstract class AbstractKotlinClassInSource +abstract class AbstractKotlinClassInSourceWithSuperClass : AbstractKotlinClassInSource() +abstract class AbstractKotlinClassInSourceWithSuperInterface : KotlinInterfaceInSource + +open class KotlinClassInSource +open class KotlinClassInSourceWithSuperAbstract : AbstractKotlinClassInSource() +open class KotlinClassInSourceWithSuperClass : KotlinClassInSource() +open class KotlinClassInSourceWithSuperInterface : KotlinInterfaceInSource + +// FILE: JavaSource.java +interface JavaInterfaceInSource {} +interface JavaInterfaceInSourceWithSuper extends JavaInterfaceInSource {} + +abstract class AbstractJavaClassInSource {} +abstract class AbstractJavaClassInSourceWithSuperInterface implements JavaInterfaceInSource {} +abstract class AbstractJavaClassInSourceWithSuperClass extends AbstractJavaClassInSource {} + +class JavaClassInSource {} +class JavaClassInSourceWithSuperInterface implements JavaInterfaceInSource {} +class JavaClassInSourceWithSuperAbstract extends AbstractJavaClassInSource {} +class JavaClassInSourceWithSuperClass extends JavaClassInSource {} + diff --git a/test-utils/testData/api/throwList.kt b/test-utils/testData/api/throwList.kt new file mode 100644 index 00000000..56431756 --- /dev/null +++ b/test-utils/testData/api/throwList.kt @@ -0,0 +1,107 @@ +/* + * Copyright 2021 Google LLC + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +// TEST PROCESSOR: ThrowListProcessor +// EXPECTED: +// java.io.IOException,java.util.NoSuchElementException +// java.io.IOException,java.lang.IndexOutOfBoundsException +// java.io.IOException,java.util.NoSuchElementException +// java.lang.IndexOutOfBoundsException +// java.io.IOException +// java.io.IOException,java.lang.IndexOutOfBoundsException +// java.lang.IndexOutOfBoundsException +// java.lang.IllegalArgumentException +// java.lang.IllegalStateException +// java.io.IOException +// java.lang.IllegalStateException,java.lang.IllegalArgumentException +// java.io.IOException +// java.lang.IndexOutOfBoundsException +// java.io.IOException,java.lang.IndexOutOfBoundsException +// java.io.IOException +// END +// MODULE: lib +// FILE: JavaLib.java +import java.io.IOException; +import java.lang.IndexOutOfBoundsException; +public class JavaLib { + public JavaLib() throws IOException { + + } + + public void foo() throws IOException { + throw new IOException(); + } + public void foo(int i) throws IndexOutOfBoundsException { + throw new IndexOutOfBoundsException(); + } + public void foo(String[] s) throws IOException, IndexOutOfBoundsException { + throw new IOException(); + } +} +// FILE: KtLib.kt +import java.io.IOException +import java.lang.IllegalArgumentException +import java.lang.IllegalStateException + +class KtLib { + @Throws(java.io.IOException::class) + fun throwsLibKt() { + throw java.io.IOException() + } + @Throws(java.lang.IndexOutOfBoundsException::class) + fun throwsLibKt(i: Int) { + throw java.lang.IndexOutOfBoundsException() + } + @Throws(java.io.IOException::class, java.lang.IndexOutOfBoundsException::class) + fun throwsLibKt(s: Array<String>) { + throw java.io.IOException() + } + + @get:Throws(IllegalArgumentException::class) + val getterThrows: Int = 3 + @set:Throws(IllegalStateException::class) + var setterThrows: Int = 3 + @get:Throws(IOException::class) + @set:Throws(IllegalStateException::class, IllegalArgumentException::class) + var bothThrows: Int = 3 +} +// MODULE: main(lib) +// FILE: ThrowsException.java +import java.io.IOException; +import java.lang.IndexOutOfBoundsException; + +public class ThrowsException { + public int foo() throws IOException, IndexOutOfBoundsException{ + return 1; + } +} +// FILE: a.kt +class ThrowsKt { + @Throws(java.io.IOException::class, java.util.NoSuchElementException::class) + fun throwsKT() + + @set:Throws(java.lang.IndexOutOfBoundsException::class) + var a: Int + @Throws(java.io.IOException::class, java.util.NoSuchElementException::class) + get() { + return 1 + } + set(a: Int) { + + } +} diff --git a/test-utils/testData/api/topLevelMembers.kt b/test-utils/testData/api/topLevelMembers.kt new file mode 100644 index 00000000..aee7e330 --- /dev/null +++ b/test-utils/testData/api/topLevelMembers.kt @@ -0,0 +1,138 @@ +/* + * Copyright 2020 Google LLC + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// WITH_RUNTIME +// TEST PROCESSOR: TopLevelMemberProcessor +// EXPECTED: +// lib : <init> -> lib.LibJavaClass +// lib : <init> -> lib.RealLibClass +// lib : <init> -> lib.RealLibClass$Companion +// lib : functionInLib -> lib.LibKt +// lib : functionInLibCompanion -> lib.RealLibClass$Companion +// lib : functionInLibJvmName -> lib.LibCustomClassName +// lib : functionInLibRealClass -> lib.RealLibClass +// lib : javaFieldInLib -> lib.LibJavaClass +// lib : javaMethodInLib -> lib.LibJavaClass +// lib : jvmStaticFunctionInLibCompanion -> lib.RealLibClass$Companion +// lib : jvmStaticValueInLibCompanion -> lib.RealLibClass$Companion +// lib : jvmStaticVariableInLibCompanion -> lib.RealLibClass$Companion +// lib : valueInLib -> lib.LibKt +// lib : valueInLibCompanion -> lib.RealLibClass$Companion +// lib : valueInLibJvmName -> lib.LibCustomClassName +// lib : valueInLibRealClass -> lib.RealLibClass +// lib : variableInLib -> lib.LibKt +// lib : variableInLibCompanion -> lib.RealLibClass$Companion +// lib : variableInLibJvmName -> lib.LibCustomClassName +// lib : variableInLibRealClass -> lib.RealLibClass +// main : <init> -> main.MainJavaClass +// main : <init> -> main.RealMainClass +// main : <init> -> main.RealMainClass$Companion +// main : functionInMain -> main.MainKt +// main : functionInMainCompanion -> main.RealMainClass$Companion +// main : functionInMainJvmName -> main.MainCustomClassName +// main : functionInMainRealClass -> main.RealMainClass +// main : javaFieldInMain -> main.MainJavaClass +// main : javaMethodInMain -> main.MainJavaClass +// main : jvmStaticFunctionInMainCompanion -> main.RealMainClass$Companion +// main : jvmStaticValueInMainCompanion -> main.RealMainClass$Companion +// main : jvmStaticVariableInMainCompanion -> main.RealMainClass$Companion +// main : valueInMain -> main.MainKt +// main : valueInMainCompanion -> main.RealMainClass$Companion +// main : valueInMainJvmName -> main.MainCustomClassName +// main : valueInMainRealClass -> main.RealMainClass +// main : variableInMain -> main.MainKt +// main : variableInMainCompanion -> main.RealMainClass$Companion +// main : variableInMainJvmName -> main.MainCustomClassName +// main : variableInMainRealClass -> main.RealMainClass +// END + +// MODULE: lib +// FILE: lib.kt +package lib +fun functionInLib() {} +val valueInLib: String = "" +var variableInLib: String = "" +class RealLibClass { + fun functionInLibRealClass() {} + val valueInLibRealClass: String = "" + var variableInLibRealClass: String = "" + + companion object { + fun functionInLibCompanion() {} + val valueInLibCompanion: String = "" + var variableInLibCompanion: String = "" + @JvmStatic + fun jvmStaticFunctionInLibCompanion() {} + @JvmStatic + val jvmStaticValueInLibCompanion: String = "" + @JvmStatic + var jvmStaticVariableInLibCompanion: String = "" + } +} +// FILE: customName.kt +@file:JvmName("LibCustomClassName") +package lib +fun functionInLibJvmName() {} +val valueInLibJvmName: String = "" +var variableInLibJvmName: String = "" + +// FILE: lib/LibJavaClass.java +package lib; +public class LibJavaClass { + public LibJavaClass() {} + private String javaFieldInLib; + private void javaMethodInLib() { + } +} + +// MODULE: main(lib) +// FILE: main.kt +package main +fun functionInMain() {} +val valueInMain: String = "" +var variableInMain: String = "" +class RealMainClass { + fun functionInMainRealClass() {} + val valueInMainRealClass: String = "" + var variableInMainRealClass: String = "" + + companion object { + fun functionInMainCompanion() {} + val valueInMainCompanion: String = "" + var variableInMainCompanion: String = "" + @JvmStatic + fun jvmStaticFunctionInMainCompanion() {} + @JvmStatic + val jvmStaticValueInMainCompanion: String = "" + @JvmStatic + var jvmStaticVariableInMainCompanion: String = "" + } +} +// FILE: customName.kt +@file:JvmName("MainCustomClassName") +package main +fun functionInMainJvmName() {} +val valueInMainJvmName: String = "" +var variableInMainJvmName: String = "" +// FILE: main/MainJavaClass.java +package main; +public class MainJavaClass { + public MainJavaClass() {} + private String javaFieldInMain; + private void javaMethodInMain() { + } +} diff --git a/test-utils/testData/api/typeAlias.kt b/test-utils/testData/api/typeAlias.kt new file mode 100644 index 00000000..3d1e2777 --- /dev/null +++ b/test-utils/testData/api/typeAlias.kt @@ -0,0 +1,55 @@ +/* + * Copyright 2020 Google LLC + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// WITH_RUNTIME +// TEST PROCESSOR: TypeAliasProcessor +// EXPECTED: +// a : A = String +// b : B = String +// c : CC = A = String +// d : String +// listOfInt : ListOfInt = List<Int> +// listOfInt_B : ListOfInt_B = ListOfInt = List<Int> +// listOfInt_C : ListOfInt_C = ListOfInt_B = ListOfInt = List<Int> +// myList : MyList<Long> = List<T> +// myList_B : List<Number> +// myList_String : MyList_String = MyList<String> = List<T> +// myList_b_String : MyList_B_String = MyList_B<String> = MyList<R> = List<T> +// END + +typealias A = String +typealias B = String +typealias CC = A +typealias ListOfInt = List<Int> +typealias ListOfInt_B = ListOfInt +typealias ListOfInt_C = ListOfInt_B +typealias MyList<T> = List<T> +typealias MyList_B<R> = MyList<R> +typealias MyList_String = MyList<String> +typealias MyList_B_String = MyList_B<String> + +val a: A = "" +val b: B = "" +val c: CC = "" +val d: String = "" +val listOfInt: ListOfInt = TODO() +val listOfInt_B: ListOfInt_B = TODO() +val listOfInt_C: ListOfInt_C = TODO() +val myList: MyList<Long> = TODO() +val myList_B: List<Number> = TODO() +val myList_String: MyList_String = TODO() +val myList_b_String: MyList_B_String = TODO() diff --git a/test-utils/testData/api/typeAliasComparison.kt b/test-utils/testData/api/typeAliasComparison.kt new file mode 100644 index 00000000..63262c5b --- /dev/null +++ b/test-utils/testData/api/typeAliasComparison.kt @@ -0,0 +1,46 @@ +/* + * Copyright 2020 Google LLC + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// WITH_RUNTIME +// TEST PROCESSOR: TypeAliasComparisonProcessor +// EXPECTED: +// String = String : true +// String = String : true +// String = String : true +// String = String : true +// String = [@Anno] [typealias F] : true +// String = [@Anno] [typealias F] : true +// String = [@Bnno] [typealias F] : true +// String = [@Bnno] [typealias F] : true +// [@Anno] [typealias F] = String : true +// [@Anno] [typealias F] = String : true +// [@Anno] [typealias F] = [@Anno] [typealias F] : true +// [@Anno] [typealias F] = [@Bnno] [typealias F] : true +// [@Bnno] [typealias F] = String : true +// [@Bnno] [typealias F] = String : true +// [@Bnno] [typealias F] = [@Anno] [typealias F] : true +// [@Bnno] [typealias F] = [@Bnno] [typealias F] : true +// END + +annotation class Anno +annotation class Bnno + +typealias F = String +typealias Foo = (@Anno F) -> String + +fun bar(arg: @Bnno F) { +} diff --git a/test-utils/testData/api/typeComposure.kt b/test-utils/testData/api/typeComposure.kt new file mode 100644 index 00000000..cf4666b8 --- /dev/null +++ b/test-utils/testData/api/typeComposure.kt @@ -0,0 +1,127 @@ +/* + * Copyright 2020 Google LLC + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// WITH_RUNTIME +// TEST PROCESSOR: TypeComposureProcessor +// EXPECTED: +// C<*> ?= C<*> : true +// C<*> ?= C<Any> : true +// C<*> ?= C<Int> : true +// C<*> ?= C<Number> : true +// C<*> ?= C<in Any> : true +// C<*> ?= C<in Int> : true +// C<*> ?= C<in Number> : true +// C<*> ?= C<out Any> : true +// C<*> ?= C<out Int> : true +// C<*> ?= C<out Number> : true +// C<Any> ?= C<*> : false +// C<Any> ?= C<Any> : true +// C<Any> ?= C<Int> : false +// C<Any> ?= C<Number> : false +// C<Any> ?= C<in Any> : false +// C<Any> ?= C<in Int> : false +// C<Any> ?= C<in Number> : false +// C<Any> ?= C<out Any> : false +// C<Any> ?= C<out Int> : false +// C<Any> ?= C<out Number> : false +// C<Int> ?= C<*> : false +// C<Int> ?= C<Any> : false +// C<Int> ?= C<Int> : true +// C<Int> ?= C<Number> : false +// C<Int> ?= C<in Any> : false +// C<Int> ?= C<in Int> : false +// C<Int> ?= C<in Number> : false +// C<Int> ?= C<out Any> : false +// C<Int> ?= C<out Int> : false +// C<Int> ?= C<out Number> : false +// C<Number> ?= C<*> : false +// C<Number> ?= C<Any> : false +// C<Number> ?= C<Int> : false +// C<Number> ?= C<Number> : true +// C<Number> ?= C<in Any> : false +// C<Number> ?= C<in Int> : false +// C<Number> ?= C<in Number> : false +// C<Number> ?= C<out Any> : false +// C<Number> ?= C<out Int> : false +// C<Number> ?= C<out Number> : false +// C<in Any> ?= C<*> : false +// C<in Any> ?= C<Any> : true +// C<in Any> ?= C<Int> : false +// C<in Any> ?= C<Number> : false +// C<in Any> ?= C<in Any> : true +// C<in Any> ?= C<in Int> : false +// C<in Any> ?= C<in Number> : false +// C<in Any> ?= C<out Any> : false +// C<in Any> ?= C<out Int> : false +// C<in Any> ?= C<out Number> : false +// C<in Int> ?= C<*> : false +// C<in Int> ?= C<Any> : true +// C<in Int> ?= C<Int> : true +// C<in Int> ?= C<Number> : true +// C<in Int> ?= C<in Any> : true +// C<in Int> ?= C<in Int> : true +// C<in Int> ?= C<in Number> : true +// C<in Int> ?= C<out Any> : false +// C<in Int> ?= C<out Int> : false +// C<in Int> ?= C<out Number> : false +// C<in Number> ?= C<*> : false +// C<in Number> ?= C<Any> : true +// C<in Number> ?= C<Int> : false +// C<in Number> ?= C<Number> : true +// C<in Number> ?= C<in Any> : true +// C<in Number> ?= C<in Int> : false +// C<in Number> ?= C<in Number> : true +// C<in Number> ?= C<out Any> : false +// C<in Number> ?= C<out Int> : false +// C<in Number> ?= C<out Number> : false +// C<out Any> ?= C<*> : false +// C<out Any> ?= C<Any> : true +// C<out Any> ?= C<Int> : true +// C<out Any> ?= C<Number> : true +// C<out Any> ?= C<in Any> : false +// C<out Any> ?= C<in Int> : false +// C<out Any> ?= C<in Number> : false +// C<out Any> ?= C<out Any> : true +// C<out Any> ?= C<out Int> : true +// C<out Any> ?= C<out Number> : true +// C<out Int> ?= C<*> : false +// C<out Int> ?= C<Any> : false +// C<out Int> ?= C<Int> : true +// C<out Int> ?= C<Number> : false +// C<out Int> ?= C<in Any> : false +// C<out Int> ?= C<in Int> : false +// C<out Int> ?= C<in Number> : false +// C<out Int> ?= C<out Any> : false +// C<out Int> ?= C<out Int> : true +// C<out Int> ?= C<out Number> : false +// C<out Number> ?= C<*> : false +// C<out Number> ?= C<Any> : false +// C<out Number> ?= C<Int> : true +// C<out Number> ?= C<Number> : true +// C<out Number> ?= C<in Any> : false +// C<out Number> ?= C<in Int> : false +// C<out Number> ?= C<in Number> : false +// C<out Number> ?= C<out Any> : false +// C<out Number> ?= C<out Int> : true +// C<out Number> ?= C<out Number> : true +// END + +open class C<T> + +val a: Int = 0 +val b: Number = 0 +val c: C<Int> = C<Int>() diff --git a/test-utils/testData/api/typeParameterEquals.kt b/test-utils/testData/api/typeParameterEquals.kt new file mode 100644 index 00000000..93060cb7 --- /dev/null +++ b/test-utils/testData/api/typeParameterEquals.kt @@ -0,0 +1,31 @@ +/* + * Copyright 2022 Google LLC + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// TEST PROCESSOR: TypeParameterEqualsProcessor +// EXPECTED: +// true +// true +// END + + +// FILE: a.kt + +interface Foo<T> { + val t: T +} + +interface I<T, K: T> diff --git a/test-utils/testData/api/typeParameterReference.kt b/test-utils/testData/api/typeParameterReference.kt new file mode 100644 index 00000000..bc1428d2 --- /dev/null +++ b/test-utils/testData/api/typeParameterReference.kt @@ -0,0 +1,82 @@ +/* + * Copyright 2020 Google LLC + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// WITH_RUNTIME +// TEST PROCESSOR: TypeParameterReferenceProcessor +// EXPECTED: +// LibFoo: false +// SelfReferencing: false +// kotlin.String: false +// SelfReferencing.T: false +// Foo.T1: true +// Foo.bar.T2: false +// foo.T3: false +// T +// List<T> +// T +// MutableList<(T..T?)> +// (SelfReferencingJava<(T..T?)>..SelfReferencingJava<(T..T?)>?) +// (T1..T1?) +// END + +// MODULE: lib +// FILE: lib.kt +interface LibFoo<T> { + val v: T + val w: List<T> +} + +// FILE: LibSR.kt +package lib; +class SelfReferencing<T : SelfReferencing<T>> + +// FILE: JavaLib.java +import java.util.List; + +interface JavaLib<T> { + public T genericFun(); + public List<T> list(); +} + +// MODULE: main(lib) +// FILE: main.kt + +class SelfReferencing<T : SelfReferencing<T>> + +class Foo<T1> { + inner class Bar { + val v: T1? + } + + fun <T2> bar(p: T2) = 1 + + val libFoo: LibFoo<String> +} + +fun <T3> foo(p: T3) = 1 + +// FILE: SelfReferencingJava.java +public class SelfReferencingJava<T extends SelfReferencingJava<T>> { +} + +// FILE: BoundedTypeParameter.java + +public class BoundedTypeParameter { + static <T1, T2 extends T1> T2 method(T1 input) { + return null; + } +} diff --git a/test-utils/testData/api/validateTypes.kt b/test-utils/testData/api/validateTypes.kt new file mode 100644 index 00000000..2a592307 --- /dev/null +++ b/test-utils/testData/api/validateTypes.kt @@ -0,0 +1,108 @@ +/* + * Copyright 2022 Google LLC + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// WITH_RUNTIME +// TEST PROCESSOR: ValidateProcessor +// EXPECTED: +// ErrorInMember invalid +// goodProp valid +// badProp invalid +// errorFun invalid +// <init> valid +// SkipErrorInMember valid +// skipProp valid +// skipFun valid +// <init> valid +// GoodClass valid +// C valid +// BadJavaClass invalid +// ErrorAnnotationType invalid +// ErrorInAnnotationArgumentSingleType invalid +// ErrorInAnnotationArgumentMultipleTypes invalid +// ErrorInAnnotationArgumentComposed invalid +// ValidAnnotationArgumentType valid +// END +// FILE: a.kt +annotation class Anno(val i: Int) + +annotation class AnnoWithTypes( + val type: KClass<*> = Any::class, + val types: Array<KClass<*>> = [] +) + +annotation class AnnoComposed( + val composed: AnnoWithTypes +) + +@Anno(1) +class ErrorInMember : C { + val goodProp: Int + val badProp: () -> NonExistType + fun errorFun(): NonExistType { + + } +} + +class SkipErrorInMember { + val skipProp: NonExistType + fun skipFun(): NonExitType { + + } +} + +@NonExistAnnotation +class ErrorAnnotationType { +} + +@Anno(1) +open class GoodClass { + val a: Int = 1 + + fun foo(): Int = 1 + + fun bar() { + val x = a + } +} + +@AnnoWithTypes(type = NonExistType::class) +class ErrorInAnnotationArgumentSingleType { + +} + +@AnnoWithTypes(types = [ GoodClass::class, NonExistType::class ]) +class ErrorInAnnotationArgumentMultipleTypes { + +} + +@AnnoComposed(composed = AnnoWithTypes(type = NonExistType::class)) +class ErrorInAnnotationArgumentComposed { + +} + +@AnnoWithTypes(type = GoodClass::class) +class ValidAnnotationArgumentType { + +} + +// FILE: C.java + +public class C extends GoodClass {} + +class BadJavaClass extends NonExistType { + +} diff --git a/test-utils/testData/api/varianceTypeCheck.kt b/test-utils/testData/api/varianceTypeCheck.kt new file mode 100644 index 00000000..a644570b --- /dev/null +++ b/test-utils/testData/api/varianceTypeCheck.kt @@ -0,0 +1,84 @@ +/* + * Copyright 2020 Google LLC + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// WITH_RUNTIME +// TEST PROCESSOR: TypeComparisonProcessor +// EXPECTED: +// Any ?= Any : true +// Any ?= Any? : false +// Any ?= Foo<*> : true +// Any ?= Foo<A> : true +// Any ?= Foo<C> : true +// Any ?= Foo<in B> : true +// Any ?= Foo<out B> : true +// Any? ?= Any : true +// Any? ?= Any? : true +// Any? ?= Foo<*> : true +// Any? ?= Foo<A> : true +// Any? ?= Foo<C> : true +// Any? ?= Foo<in B> : true +// Any? ?= Foo<out B> : true +// Foo<*> ?= Any : false +// Foo<*> ?= Any? : false +// Foo<*> ?= Foo<*> : true +// Foo<*> ?= Foo<A> : true +// Foo<*> ?= Foo<C> : true +// Foo<*> ?= Foo<in B> : true +// Foo<*> ?= Foo<out B> : true +// Foo<A> ?= Any : false +// Foo<A> ?= Any? : false +// Foo<A> ?= Foo<*> : false +// Foo<A> ?= Foo<A> : true +// Foo<A> ?= Foo<C> : false +// Foo<A> ?= Foo<in B> : false +// Foo<A> ?= Foo<out B> : false +// Foo<C> ?= Any : false +// Foo<C> ?= Any? : false +// Foo<C> ?= Foo<*> : false +// Foo<C> ?= Foo<A> : false +// Foo<C> ?= Foo<C> : true +// Foo<C> ?= Foo<in B> : false +// Foo<C> ?= Foo<out B> : false +// Foo<in B> ?= Any : false +// Foo<in B> ?= Any? : false +// Foo<in B> ?= Foo<*> : false +// Foo<in B> ?= Foo<A> : true +// Foo<in B> ?= Foo<C> : false +// Foo<in B> ?= Foo<in B> : true +// Foo<in B> ?= Foo<out B> : false +// Foo<out B> ?= Any : false +// Foo<out B> ?= Any? : false +// Foo<out B> ?= Foo<*> : false +// Foo<out B> ?= Foo<A> : false +// Foo<out B> ?= Foo<C> : true +// Foo<out B> ?= Foo<in B> : false +// Foo<out B> ?= Foo<out B> : true +// END + +@file:kotlin.Suppress("A", "B", "C", "Suppress") + +open class A +open class B: A() +open class C: B() + +class Foo<T> + +var ib: Foo<in B> = Foo<B>() +var ob: Foo<out B> = Foo<B>() + +var a: Foo<A> = Foo<A>() +var c: Foo<C> = Foo<C>() diff --git a/test-utils/testData/api/visibilities.kt b/test-utils/testData/api/visibilities.kt new file mode 100644 index 00000000..cc650894 --- /dev/null +++ b/test-utils/testData/api/visibilities.kt @@ -0,0 +1,125 @@ +/* + * Copyright 2020 Google LLC + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// TEST PROCESSOR: VisibilityProcessor +// EXPECTED: +// publicFun: PUBLIC,visible in A, B, D: true, true, true +// packageFun: JAVA_PACKAGE,visible in A, B, D: true, false, true +// privateFun: PRIVATE,visible in A, B, D: false, false, false +// protectedFun: PROTECTED,visible in A, B, D: true, false, true +// <init>: PUBLIC,visible in A, B, D: true, true, true +// javaPackageField: JAVA_PACKAGE,visible in A, B, D: true, false, true +// x: INTERNAL,visible in A, B, D: false, false, false +// y: PROTECTED,visible in A, B, D: true, false, true +// y: PUBLIC,visible in A, B, D: true, true, true +// LibEnumJava: valueOf: PUBLIC +// LibEnumJava: values: PUBLIC +// LibEnumJava: <init>: PRIVATE +// LibEnum: valueOf: PUBLIC +// LibEnum: values: PUBLIC +// LibEnum: <init>: PRIVATE +// Enum: <init>: PRIVATE +// Enum: values: PUBLIC +// Enum: valueOf: PUBLIC +// KtEnum: <init>: PRIVATE +// KtEnumWithVal: <init>: PRIVATE +// END + +// MODULE: lib +// FILE: JavaClass.java +public class JavaClass { + int javaPackageField; +} + +// FILE: LibEnumJava.java +public enum LibEnumJava { + R(0),G(1),B(2); + private final int v; + LibEnumJava(int v) { + this.v = v; + } +} + +// FILE: lib.kt +open class KotlinClass { + open internal val x: Int = 0 + open protected val y: Int = 0 +} + +enum class LibEnum(val value: Int) { + A(0), B(1), C(2); +} + +// MODULE: main(lib) +// FILE: a.kt +annotation class TestA +annotation class TestB +annotation class TestD + +@TestA +class A : C() { +} + +@TestD +class D {} + +class KotlinSubClass : KotlinClass() { + public override val y = 1 +} + +enum class KtEnum { + A,B,C +} + +enum class KtEnumWithVal(val a: Int) { + A(0), B(1), C(2) +} + +// FILE: C.java +class C { + public int publicFun() { + return 1; + } + + int packageFun() { + return 1; + } + + private int privateFun() { + return 1; + } + + protected int protectedFun() { + return 1; + } +} + +// FILE: Enum.java +public enum Enum { + Y,U,V; + private final int v; + Enum(int v) { + this.v = v; + } +} +// FILE: b.kt +package somePackage + +import TestB + +@TestB +class B |