Add tests for mutability annotation support in type resolver

This commit is contained in:
Alexey Sedunov
2013-03-29 16:11:07 +04:00
parent fc7bb67aca
commit 6a7cd7c6e3
16 changed files with 200 additions and 2 deletions
+1
View File
@@ -4,6 +4,7 @@
<modules>
<module fileurl="file://$PROJECT_DIR$/Kotlin.iml" filepath="$PROJECT_DIR$/Kotlin.iml" />
<module fileurl="file://$PROJECT_DIR$/compiler/android-tests/android-tests.iml" filepath="$PROJECT_DIR$/compiler/android-tests/android-tests.iml" />
<module fileurl="file://$PROJECT_DIR$/compiler/annotations-ext/annotations-ext.iml" filepath="$PROJECT_DIR$/compiler/annotations-ext/annotations-ext.iml" />
<module fileurl="file://$PROJECT_DIR$/compiler/backend/backend.iml" filepath="$PROJECT_DIR$/compiler/backend/backend.iml" />
<module fileurl="file://$PROJECT_DIR$/build-tools/build-tools.iml" filepath="$PROJECT_DIR$/build-tools/build-tools.iml" />
<module fileurl="file://$PROJECT_DIR$/compiler/cli/cli.iml" filepath="$PROJECT_DIR$/compiler/cli/cli.iml" />
@@ -269,6 +269,7 @@ public class JavaTypeTransformer {
}
public static TypeUsage adjustTypeUsageWithMutabilityAnnotations(PsiModifierListOwner owner, TypeUsage originalTypeUsage) {
// Overrides type usage in method signature depending on mutability annotation present
EnumSet<TypeUsage> signatureTypeUsages =
EnumSet.of(TypeUsage.MEMBER_SIGNATURE_COVARIANT, TypeUsage.MEMBER_SIGNATURE_CONTRAVARIANT, TypeUsage.MEMBER_SIGNATURE_INVARIANT);
if (!signatureTypeUsages.contains(originalTypeUsage)) {
@@ -0,0 +1,11 @@
package test;
import org.jetbrains.annotations.*;
public interface LoadIterable<T> {
public @Mutable Iterable<T> getIterable();
public void setIterable(@Mutable Iterable<T> Iterable);
public @ReadOnly Iterable<T> getReadOnlyIterable();
public void setReadOnlyIterable(@ReadOnly Iterable<T> Iterable);
}
@@ -0,0 +1,9 @@
package test
public trait LoadIterable<T> : java.lang.Object {
public fun getIterable(): MutableIterable<T>?
public fun setIterable(p0: MutableIterable<T>?)
public fun getReadOnlyIterable(): Iterable<T>?
public fun setReadOnlyIterable(p0: Iterable<T>?)
}
@@ -0,0 +1,8 @@
package test
public trait LoadIterable</*0*/ T> : java.lang.Object {
public abstract fun getIterable() : jet.MutableIterable<T>?
public abstract fun getReadOnlyIterable() : jet.Iterable<T>?
public abstract fun setIterable(/*0*/ p0 : jet.MutableIterable<T>?) : jet.Unit
public abstract fun setReadOnlyIterable(/*0*/ p0 : jet.Iterable<T>?) : jet.Unit
}
@@ -0,0 +1,8 @@
package test;
import org.jetbrains.annotations.*;
public interface LoadIterableWithConflict<T> {
public @ReadOnly @Mutable Iterable<T> getIterable();
public void setIterable(@ReadOnly @Mutable Iterable<T> Iterable);
}
@@ -0,0 +1,6 @@
package test
public trait LoadIterableWithConflict<T> : java.lang.Object {
public fun getIterable(): MutableIterable<T>?
public fun setIterable(p0: MutableIterable<T>?)
}
@@ -0,0 +1,6 @@
package test
public trait LoadIterableWithConflict</*0*/ T> : java.lang.Object {
public abstract fun getIterable() : jet.MutableIterable<T>?
public abstract fun setIterable(/*0*/ p0 : jet.MutableIterable<T>?) : jet.Unit
}
@@ -0,0 +1,11 @@
package test;
import org.jetbrains.annotations.*;
public interface LoadIterableWithNullability<T> {
public @NotNull @Mutable Iterable<T> getIterable();
public void setIterable(@Mutable @NotNull Iterable<T> Iterable);
public @NotNull @ReadOnly Iterable<T> getReadOnlyIterable();
public void setReadOnlyIterable(@ReadOnly @NotNull Iterable<T> Iterable);
}
@@ -0,0 +1,9 @@
package test
public trait LoadIterableWithNullability<T> : java.lang.Object {
public fun getIterable(): MutableIterable<T>
public fun setIterable(p0: MutableIterable<T>)
public fun getReadOnlyIterable(): Iterable<T>
public fun setReadOnlyIterable(p0: Iterable<T>)
}
@@ -0,0 +1,8 @@
package test
public trait LoadIterableWithNullability</*0*/ T> : java.lang.Object {
public abstract fun getIterable() : jet.MutableIterable<T>
public abstract fun getReadOnlyIterable() : jet.Iterable<T>
public abstract fun setIterable(/*0*/ p0 : jet.MutableIterable<T>) : jet.Unit
public abstract fun setReadOnlyIterable(/*0*/ p0 : jet.Iterable<T>) : jet.Unit
}
@@ -0,0 +1,22 @@
package test;
import org.jetbrains.annotations.*;
import java.util.ArrayList;
public interface LoadIterableWithPropagation {
public interface LoadIterable<T> {
public @Mutable Iterable<T> getIterable();
public void setIterable(@Mutable Iterable<T> Iterable);
public @ReadOnly Iterable<T> getReadOnlyIterable();
public void setReadOnlyIterable(@ReadOnly Iterable<T> Iterable);
}
public class LoadIterableImpl<T> implements LoadIterable<T> {
public Iterable<T> getIterable() {return new ArrayList<T>();}
public void setIterable(Iterable<T> Iterable) {}
public Iterable<T> getReadOnlyIterable() {return new ArrayList<T>();}
public void setReadOnlyIterable(Iterable<T> Iterable) {}
}
}
@@ -0,0 +1,21 @@
package test
import java.util.ArrayList
public trait LoadIterableWithPropagation: java.lang.Object {
public trait LoadIterable<T> : java.lang.Object {
public fun getIterable(): MutableIterable<T>?
public fun setIterable(p0: MutableIterable<T>?)
public fun getReadOnlyIterable(): Iterable<T>?
public fun setReadOnlyIterable(p0: Iterable<T>?)
}
public open class LoadIterableImpl<T> : LoadIterable<T> {
public override fun getIterable(): MutableIterable<T>? = ArrayList<T>()
public override fun setIterable(p0: MutableIterable<T>?): Unit {}
public override fun getReadOnlyIterable(): Iterable<T>? = ArrayList<T>()
public override fun setReadOnlyIterable(p0: Iterable<T>?): Unit {}
}
}
@@ -0,0 +1,19 @@
package test
public trait LoadIterableWithPropagation : java.lang.Object {
public trait LoadIterable</*0*/ T> : java.lang.Object {
public abstract fun getIterable() : jet.MutableIterable<T>?
public abstract fun getReadOnlyIterable() : jet.Iterable<T>?
public abstract fun setIterable(/*0*/ p0 : jet.MutableIterable<T>?) : jet.Unit
public abstract fun setReadOnlyIterable(/*0*/ p0 : jet.Iterable<T>?) : jet.Unit
}
public open class LoadIterableImpl</*0*/ T> : test.LoadIterableWithPropagation.LoadIterable<T> {
public constructor LoadIterableImpl</*0*/ T>()
public open override /*1*/ fun getIterable() : jet.MutableIterable<T>?
public open override /*1*/ fun getReadOnlyIterable() : jet.Iterable<T>?
public open override /*1*/ fun setIterable(/*0*/ p0 : jet.MutableIterable<T>?) : jet.Unit
public open override /*1*/ fun setReadOnlyIterable(/*0*/ p0 : jet.Iterable<T>?) : jet.Unit
}
}
@@ -33,7 +33,7 @@ import org.jetbrains.jet.jvm.compiler.AbstractLoadJavaTest;
@InnerTestClasses({LoadJavaTestGenerated.CompiledJavaCompareWithKotlin.class, LoadJavaTestGenerated.CompiledJavaIncludeObjectMethods.class, LoadJavaTestGenerated.CompiledJava.class, LoadJavaTestGenerated.SourceJava.class, LoadJavaTestGenerated.JavaAgainstKotlin.class})
public class LoadJavaTestGenerated extends AbstractLoadJavaTest {
@TestMetadata("compiler/testData/loadJava/compiledJavaCompareWithKotlin")
@InnerTestClasses({CompiledJavaCompareWithKotlin.Annotation.class, CompiledJavaCompareWithKotlin.Constructor.class, CompiledJavaCompareWithKotlin.JavaBean.class, CompiledJavaCompareWithKotlin.KotlinSignature.class, CompiledJavaCompareWithKotlin.Library.class, CompiledJavaCompareWithKotlin.Modality.class, CompiledJavaCompareWithKotlin.NotNull.class, CompiledJavaCompareWithKotlin.Vararg.class})
@InnerTestClasses({CompiledJavaCompareWithKotlin.Annotation.class, CompiledJavaCompareWithKotlin.Constructor.class, CompiledJavaCompareWithKotlin.JavaBean.class, CompiledJavaCompareWithKotlin.KotlinSignature.class, CompiledJavaCompareWithKotlin.Library.class, CompiledJavaCompareWithKotlin.Modality.class, CompiledJavaCompareWithKotlin.Mutability.class, CompiledJavaCompareWithKotlin.NotNull.class, CompiledJavaCompareWithKotlin.Vararg.class})
public static class CompiledJavaCompareWithKotlin extends AbstractLoadJavaTest {
public void testAllFilesPresentInCompiledJavaCompareWithKotlin() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/loadJava/compiledJavaCompareWithKotlin"), Pattern.compile("^(.+)\\.java$"), true);
@@ -914,6 +914,34 @@ public class LoadJavaTestGenerated extends AbstractLoadJavaTest {
}
@TestMetadata("compiler/testData/loadJava/compiledJavaCompareWithKotlin/mutability")
public static class Mutability extends AbstractLoadJavaTest {
public void testAllFilesPresentInMutability() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/loadJava/compiledJavaCompareWithKotlin/mutability"), Pattern.compile("^(.+)\\.java$"), true);
}
@TestMetadata("LoadIterable.java")
public void testLoadIterable() throws Exception {
doTest("compiler/testData/loadJava/compiledJavaCompareWithKotlin/mutability/LoadIterable.java");
}
@TestMetadata("LoadIterableWithConflict.java")
public void testLoadIterableWithConflict() throws Exception {
doTest("compiler/testData/loadJava/compiledJavaCompareWithKotlin/mutability/LoadIterableWithConflict.java");
}
@TestMetadata("LoadIterableWithNullability.java")
public void testLoadIterableWithNullability() throws Exception {
doTest("compiler/testData/loadJava/compiledJavaCompareWithKotlin/mutability/LoadIterableWithNullability.java");
}
@TestMetadata("LoadIterableWithPropagation.java")
public void testLoadIterableWithPropagation() throws Exception {
doTest("compiler/testData/loadJava/compiledJavaCompareWithKotlin/mutability/LoadIterableWithPropagation.java");
}
}
@TestMetadata("compiler/testData/loadJava/compiledJavaCompareWithKotlin/notNull")
public static class NotNull extends AbstractLoadJavaTest {
public void testAllFilesPresentInNotNull() throws Exception {
@@ -964,6 +992,7 @@ public class LoadJavaTestGenerated extends AbstractLoadJavaTest {
suite.addTest(KotlinSignature.innerSuite());
suite.addTestSuite(Library.class);
suite.addTestSuite(Modality.class);
suite.addTestSuite(Mutability.class);
suite.addTestSuite(NotNull.class);
suite.addTestSuite(Vararg.class);
return suite;
@@ -1075,7 +1075,7 @@ public class LazyResolveNamespaceComparingTestGenerated extends AbstractLazyReso
}
@TestMetadata("compiler/testData/loadJava/compiledJavaCompareWithKotlin")
@InnerTestClasses({CompiledJavaCompareWithKotlin.Annotation.class, CompiledJavaCompareWithKotlin.Constructor.class, CompiledJavaCompareWithKotlin.JavaBean.class, CompiledJavaCompareWithKotlin.KotlinSignature.class, CompiledJavaCompareWithKotlin.Library.class, CompiledJavaCompareWithKotlin.Modality.class, CompiledJavaCompareWithKotlin.NotNull.class, CompiledJavaCompareWithKotlin.Vararg.class})
@InnerTestClasses({CompiledJavaCompareWithKotlin.Annotation.class, CompiledJavaCompareWithKotlin.Constructor.class, CompiledJavaCompareWithKotlin.JavaBean.class, CompiledJavaCompareWithKotlin.KotlinSignature.class, CompiledJavaCompareWithKotlin.Library.class, CompiledJavaCompareWithKotlin.Modality.class, CompiledJavaCompareWithKotlin.Mutability.class, CompiledJavaCompareWithKotlin.NotNull.class, CompiledJavaCompareWithKotlin.Vararg.class})
public static class CompiledJavaCompareWithKotlin extends AbstractLazyResolveNamespaceComparingTest {
public void testAllFilesPresentInCompiledJavaCompareWithKotlin() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/loadJava/compiledJavaCompareWithKotlin"), Pattern.compile("^(.+)\\.kt$"), true);
@@ -1956,6 +1956,34 @@ public class LazyResolveNamespaceComparingTestGenerated extends AbstractLazyReso
}
@TestMetadata("compiler/testData/loadJava/compiledJavaCompareWithKotlin/mutability")
public static class Mutability extends AbstractLazyResolveNamespaceComparingTest {
public void testAllFilesPresentInMutability() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/loadJava/compiledJavaCompareWithKotlin/mutability"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("LoadIterable.kt")
public void testLoadIterable() throws Exception {
doTestNotCheckingPrimaryConstructors("compiler/testData/loadJava/compiledJavaCompareWithKotlin/mutability/LoadIterable.kt");
}
@TestMetadata("LoadIterableWithConflict.kt")
public void testLoadIterableWithConflict() throws Exception {
doTestNotCheckingPrimaryConstructors("compiler/testData/loadJava/compiledJavaCompareWithKotlin/mutability/LoadIterableWithConflict.kt");
}
@TestMetadata("LoadIterableWithNullability.kt")
public void testLoadIterableWithNullability() throws Exception {
doTestNotCheckingPrimaryConstructors("compiler/testData/loadJava/compiledJavaCompareWithKotlin/mutability/LoadIterableWithNullability.kt");
}
@TestMetadata("LoadIterableWithPropagation.kt")
public void testLoadIterableWithPropagation() throws Exception {
doTestNotCheckingPrimaryConstructors("compiler/testData/loadJava/compiledJavaCompareWithKotlin/mutability/LoadIterableWithPropagation.kt");
}
}
@TestMetadata("compiler/testData/loadJava/compiledJavaCompareWithKotlin/notNull")
public static class NotNull extends AbstractLazyResolveNamespaceComparingTest {
public void testAllFilesPresentInNotNull() throws Exception {
@@ -2006,6 +2034,7 @@ public class LazyResolveNamespaceComparingTestGenerated extends AbstractLazyReso
suite.addTest(KotlinSignature.innerSuite());
suite.addTestSuite(Library.class);
suite.addTestSuite(Modality.class);
suite.addTestSuite(Mutability.class);
suite.addTestSuite(NotNull.class);
suite.addTestSuite(Vararg.class);
return suite;