diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaTypeTransformer.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaTypeTransformer.java index b70b15820f6..1bfaef40a7e 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaTypeTransformer.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaTypeTransformer.java @@ -30,7 +30,10 @@ import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns; import org.jetbrains.jet.rt.signature.JetSignatureReader; import javax.inject.Inject; -import java.util.*; +import java.util.Collections; +import java.util.EnumSet; +import java.util.List; +import java.util.Set; import static org.jetbrains.jet.lang.resolve.java.JavaTypeTransformer.TypeUsage.*; @@ -186,7 +189,16 @@ public class JavaTypeTransformer { TypeParameterDescriptor typeParameterDescriptor = parameters.get(i); TypeUsage howTheProjectionIsUsed = howThisTypeIsUsed == SUPERTYPE ? SUPERTYPE_ARGUMENT : TYPE_ARGUMENT; - arguments.add(transformToTypeProjection(psiArgument, typeParameterDescriptor, typeVariableResolver, howTheProjectionIsUsed)); + TypeProjection typeProjection = transformToTypeProjection( + psiArgument, typeParameterDescriptor, typeVariableResolver, howTheProjectionIsUsed); + + if (typeProjection.getProjectionKind() == typeParameterDescriptor.getVariance()) { + // remove redundant 'out' and 'in' + arguments.add(new TypeProjection(Variance.INVARIANT, typeProjection.getType())); + } + else { + arguments.add(typeProjection); + } } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/TypeParameterDescriptorImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/TypeParameterDescriptorImpl.java index 2430cf6af0b..81f2b9443fa 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/TypeParameterDescriptorImpl.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/TypeParameterDescriptorImpl.java @@ -125,7 +125,6 @@ public class TypeParameterDescriptorImpl extends DeclarationDescriptorNonRootImp @Override public Variance getVariance() { - checkInitialized(); return variance; } diff --git a/compiler/testData/loadJava/RemoveRedundantProjectionKind.java b/compiler/testData/loadJava/RemoveRedundantProjectionKind.java new file mode 100644 index 00000000000..c865f811d50 --- /dev/null +++ b/compiler/testData/loadJava/RemoveRedundantProjectionKind.java @@ -0,0 +1,8 @@ +package test; + +import java.util.Collection; + +public interface RemoveRedundantProjectionKind { + void f(Collection collection); + void f(Comparable comparator); +} diff --git a/compiler/testData/loadJava/RemoveRedundantProjectionKind.kt b/compiler/testData/loadJava/RemoveRedundantProjectionKind.kt new file mode 100644 index 00000000000..f5123ccdeb8 --- /dev/null +++ b/compiler/testData/loadJava/RemoveRedundantProjectionKind.kt @@ -0,0 +1,6 @@ +package test + +public trait RemoveRedundantProjectionKind: Object { + public fun f(p0: Collection?) + public fun f(p0: Comparable?) +} diff --git a/compiler/testData/loadJava/RemoveRedundantProjectionKind.txt b/compiler/testData/loadJava/RemoveRedundantProjectionKind.txt new file mode 100644 index 00000000000..a876698366f --- /dev/null +++ b/compiler/testData/loadJava/RemoveRedundantProjectionKind.txt @@ -0,0 +1,6 @@ +namespace test + +public abstract trait test.RemoveRedundantProjectionKind : java.lang.Object { + public abstract fun f(/*0*/ p0: jet.Collection?): jet.Tuple0 + public abstract fun f(/*0*/ p0: jet.Comparable?): jet.Tuple0 +} diff --git a/compiler/testData/loadJava/kotlinSignature/error/WrongTypeParameterBoundStructure1.java b/compiler/testData/loadJava/kotlinSignature/error/WrongTypeParameterBoundStructure1.java index 65e7ea5dbb7..1f299d5fcb1 100644 --- a/compiler/testData/loadJava/kotlinSignature/error/WrongTypeParameterBoundStructure1.java +++ b/compiler/testData/loadJava/kotlinSignature/error/WrongTypeParameterBoundStructure1.java @@ -7,7 +7,7 @@ import org.jetbrains.jet.jvm.compiler.annotation.ExpectLoadError; public class WrongTypeParameterBoundStructure1 { @ExpectLoadError("'java.lang.Runnable?' type in method signature has 0 type arguments, while 'Runnable' in alternative signature has 1 of them") - @KotlinSignature("fun > foo(a : A, b : List) where B : List") + @KotlinSignature("fun > foo(a : A, b : List) where B : List") public > void foo(A a, List b) { } } diff --git a/compiler/testData/loadJava/kotlinSignature/error/WrongTypeParameterBoundStructure1.kt b/compiler/testData/loadJava/kotlinSignature/error/WrongTypeParameterBoundStructure1.kt index 21dac2f336c..7ccbfb88025 100644 --- a/compiler/testData/loadJava/kotlinSignature/error/WrongTypeParameterBoundStructure1.kt +++ b/compiler/testData/loadJava/kotlinSignature/error/WrongTypeParameterBoundStructure1.kt @@ -3,6 +3,6 @@ package test import java.util.* public open class WrongTypeParameterBoundStructure1 : Object() { - public open fun foo(p0 : A?, p1 : List?) where B : List? { + public open fun foo(p0 : A?, p1 : List?) where B : List? { } } diff --git a/compiler/testData/loadJava/kotlinSignature/error/WrongTypeParameterBoundStructure1.txt b/compiler/testData/loadJava/kotlinSignature/error/WrongTypeParameterBoundStructure1.txt index 5e9e2671a71..18bb06ded17 100644 --- a/compiler/testData/loadJava/kotlinSignature/error/WrongTypeParameterBoundStructure1.txt +++ b/compiler/testData/loadJava/kotlinSignature/error/WrongTypeParameterBoundStructure1.txt @@ -2,5 +2,5 @@ namespace test public open class test.WrongTypeParameterBoundStructure1 : java.lang.Object { public final /*constructor*/ fun (): test.WrongTypeParameterBoundStructure1 - public open fun ?>foo(/*0*/ p0: A?, /*1*/ p1: jet.List?): jet.Tuple0 + public open fun ?>foo(/*0*/ p0: A?, /*1*/ p1: jet.List?): jet.Tuple0 } diff --git a/compiler/testData/loadJava/kotlinSignature/error/WrongTypeParameterBoundStructure2.java b/compiler/testData/loadJava/kotlinSignature/error/WrongTypeParameterBoundStructure2.java index 9c2edc245cb..6c2eaa4d461 100644 --- a/compiler/testData/loadJava/kotlinSignature/error/WrongTypeParameterBoundStructure2.java +++ b/compiler/testData/loadJava/kotlinSignature/error/WrongTypeParameterBoundStructure2.java @@ -7,7 +7,7 @@ import org.jetbrains.jet.jvm.compiler.annotation.ExpectLoadError; public class WrongTypeParameterBoundStructure2 { @ExpectLoadError("'jet.List?' type in method signature has 1 type arguments, while 'List' in alternative signature has 0 of them") - @KotlinSignature("fun foo(a : A, b : List) where B : List") + @KotlinSignature("fun foo(a : A, b : List) where B : List") public > void foo(A a, List b) { } } diff --git a/compiler/testData/loadJava/kotlinSignature/error/WrongTypeParameterBoundStructure2.kt b/compiler/testData/loadJava/kotlinSignature/error/WrongTypeParameterBoundStructure2.kt index 37b98b37864..4f8fff9623a 100644 --- a/compiler/testData/loadJava/kotlinSignature/error/WrongTypeParameterBoundStructure2.kt +++ b/compiler/testData/loadJava/kotlinSignature/error/WrongTypeParameterBoundStructure2.kt @@ -3,6 +3,6 @@ package test import java.util.* public open class WrongTypeParameterBoundStructure2 : Object() { - public open fun foo(p0 : A?, p1 : List?) where B : List? { + public open fun foo(p0 : A?, p1 : List?) where B : List? { } } diff --git a/compiler/testData/loadJava/kotlinSignature/error/WrongTypeParameterBoundStructure2.txt b/compiler/testData/loadJava/kotlinSignature/error/WrongTypeParameterBoundStructure2.txt index 2923e7e3112..05d74d3f8f0 100644 --- a/compiler/testData/loadJava/kotlinSignature/error/WrongTypeParameterBoundStructure2.txt +++ b/compiler/testData/loadJava/kotlinSignature/error/WrongTypeParameterBoundStructure2.txt @@ -2,5 +2,5 @@ namespace test public open class test.WrongTypeParameterBoundStructure2 : java.lang.Object { public final /*constructor*/ fun (): test.WrongTypeParameterBoundStructure2 - public open fun ?>foo(/*0*/ p0: A?, /*1*/ p1: jet.List?): jet.Tuple0 + public open fun ?>foo(/*0*/ p0: A?, /*1*/ p1: jet.List?): jet.Tuple0 } diff --git a/compiler/testData/loadJava/kotlinSignature/error/WrongTypeParametersCount.java b/compiler/testData/loadJava/kotlinSignature/error/WrongTypeParametersCount.java index 64a859c06ae..982c2b113e4 100644 --- a/compiler/testData/loadJava/kotlinSignature/error/WrongTypeParametersCount.java +++ b/compiler/testData/loadJava/kotlinSignature/error/WrongTypeParametersCount.java @@ -7,7 +7,7 @@ import org.jetbrains.jet.jvm.compiler.annotation.ExpectLoadError; public class WrongTypeParametersCount { @ExpectLoadError("Method signature has 2 type parameters, but alternative signature has 3") - @KotlinSignature("fun foo(a : A, b : List)") + @KotlinSignature("fun foo(a : A, b : List)") public void foo(A a, List b) { } } diff --git a/compiler/testData/loadJava/kotlinSignature/error/WrongTypeParametersCount.kt b/compiler/testData/loadJava/kotlinSignature/error/WrongTypeParametersCount.kt index f3009306e7d..160b44928c9 100644 --- a/compiler/testData/loadJava/kotlinSignature/error/WrongTypeParametersCount.kt +++ b/compiler/testData/loadJava/kotlinSignature/error/WrongTypeParametersCount.kt @@ -3,6 +3,6 @@ package test import java.util.* public open class WrongTypeParametersCount : Object() { - public open fun foo(p0 : A?, p1 : List?) { + public open fun foo(p0 : A?, p1 : List?) { } } diff --git a/compiler/testData/loadJava/kotlinSignature/error/WrongTypeParametersCount.txt b/compiler/testData/loadJava/kotlinSignature/error/WrongTypeParametersCount.txt index 99789f5bcea..87ae2d5880d 100644 --- a/compiler/testData/loadJava/kotlinSignature/error/WrongTypeParametersCount.txt +++ b/compiler/testData/loadJava/kotlinSignature/error/WrongTypeParametersCount.txt @@ -2,5 +2,5 @@ namespace test public open class test.WrongTypeParametersCount : java.lang.Object { public final /*constructor*/ fun (): test.WrongTypeParametersCount - public open fun foo(/*0*/ p0: A?, /*1*/ p1: jet.List?): jet.Tuple0 + public open fun foo(/*0*/ p0: A?, /*1*/ p1: jet.List?): jet.Tuple0 } diff --git a/compiler/testData/loadJava/kotlinSignature/error/WrongTypeVariance.java b/compiler/testData/loadJava/kotlinSignature/error/WrongTypeVariance.java index ca276fa76e8..de5f58526f6 100644 --- a/compiler/testData/loadJava/kotlinSignature/error/WrongTypeVariance.java +++ b/compiler/testData/loadJava/kotlinSignature/error/WrongTypeVariance.java @@ -1,5 +1,6 @@ package test; +import java.lang.Number; import java.util.*; import jet.runtime.typeinfo.KotlinSignature; @@ -7,8 +8,8 @@ import org.jetbrains.jet.jvm.compiler.annotation.ExpectLoadError; public class WrongTypeVariance { @ExpectLoadError("Variance mismatch, actual: out, in alternative signature: ") - @KotlinSignature("fun copy(a : List, b : List) : MutableList") - public List copy(List from, List to) { + @KotlinSignature("fun copy(a : Array, b : Array) : MutableList") + public List copy(Number[] from, Number[] to) { throw new UnsupportedOperationException(); } } diff --git a/compiler/testData/loadJava/kotlinSignature/error/WrongTypeVariance.kt b/compiler/testData/loadJava/kotlinSignature/error/WrongTypeVariance.kt index 69220ff10ba..dddca08bb88 100644 --- a/compiler/testData/loadJava/kotlinSignature/error/WrongTypeVariance.kt +++ b/compiler/testData/loadJava/kotlinSignature/error/WrongTypeVariance.kt @@ -3,7 +3,7 @@ package test import java.util.* public open class WrongTypeVariance : Object() { - public open fun copy(p0 : List?, p1 : List?) : MutableList? { + public open fun copy(p0 : Array?, p1 : Array?) : MutableList? { throw UnsupportedOperationException() } } diff --git a/compiler/testData/loadJava/kotlinSignature/error/WrongTypeVariance.txt b/compiler/testData/loadJava/kotlinSignature/error/WrongTypeVariance.txt index fcb164e792e..b61cc9880f9 100644 --- a/compiler/testData/loadJava/kotlinSignature/error/WrongTypeVariance.txt +++ b/compiler/testData/loadJava/kotlinSignature/error/WrongTypeVariance.txt @@ -2,5 +2,5 @@ namespace test public open class test.WrongTypeVariance : java.lang.Object { public final /*constructor*/ fun (): test.WrongTypeVariance - public open fun copy(/*0*/ p0: jet.List?, /*1*/ p1: jet.List?): jet.MutableList? + public open fun copy(/*0*/ p0: jet.Array?, /*1*/ p1: jet.Array?): jet.MutableList? } diff --git a/compiler/tests/org/jetbrains/jet/jvm/compiler/LoadJavaTestGenerated.java b/compiler/tests/org/jetbrains/jet/jvm/compiler/LoadJavaTestGenerated.java index 476993e484c..09f489924fe 100644 --- a/compiler/tests/org/jetbrains/jet/jvm/compiler/LoadJavaTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/jvm/compiler/LoadJavaTestGenerated.java @@ -139,6 +139,11 @@ public class LoadJavaTestGenerated extends AbstractLoadJavaTest { doTest("compiler/testData/loadJava/MyException.java"); } + @TestMetadata("RemoveRedundantProjectionKind.java") + public void testRemoveRedundantProjectionKind() throws Exception { + doTest("compiler/testData/loadJava/RemoveRedundantProjectionKind.java"); + } + @TestMetadata("Simple.java") public void testSimple() throws Exception { doTest("compiler/testData/loadJava/Simple.java"); diff --git a/compiler/tests/org/jetbrains/jet/lang/resolve/lazy/LazyResolveNamespaceComparingTestGenerated.java b/compiler/tests/org/jetbrains/jet/lang/resolve/lazy/LazyResolveNamespaceComparingTestGenerated.java index 06fceef7926..c22111f4f40 100644 --- a/compiler/tests/org/jetbrains/jet/lang/resolve/lazy/LazyResolveNamespaceComparingTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/lang/resolve/lazy/LazyResolveNamespaceComparingTestGenerated.java @@ -1029,6 +1029,11 @@ public class LazyResolveNamespaceComparingTestGenerated extends AbstractLazyReso doTestSinglePackage("compiler/testData/loadJava/MyException.kt"); } + @TestMetadata("RemoveRedundantProjectionKind.kt") + public void testRemoveRedundantProjectionKind() throws Exception { + doTestSinglePackage("compiler/testData/loadJava/RemoveRedundantProjectionKind.kt"); + } + @TestMetadata("Simple.kt") public void testSimple() throws Exception { doTestSinglePackage("compiler/testData/loadJava/Simple.kt"); diff --git a/jdk-annotations/java/util/annotations.xml b/jdk-annotations/java/util/annotations.xml index 0816a32dda9..3251649264e 100644 --- a/jdk-annotations/java/util/annotations.xml +++ b/jdk-annotations/java/util/annotations.xml @@ -11,7 +11,7 @@ - + @@ -56,12 +56,12 @@ - + - + @@ -104,17 +104,17 @@ - + - + - + @@ -144,12 +144,12 @@ - + - + @@ -189,12 +189,12 @@ - + - + @@ -204,12 +204,12 @@ - + - + @@ -274,12 +274,12 @@ - + - + @@ -289,12 +289,12 @@ - + - + @@ -314,12 +314,12 @@ - + - + @@ -329,12 +329,12 @@ - + - + @@ -379,7 +379,7 @@ - + @@ -424,12 +424,12 @@ - + - + @@ -709,7 +709,7 @@ - + @@ -1431,7 +1431,7 @@ + val=""fun <T: Comparable> min(coll : Collection<T>) : T""/> @@ -1444,7 +1444,7 @@ + val=""fun <T> min(coll : Collection<T>, comp : Comparator<in T>) : T""/> @@ -1454,7 +1454,7 @@ + val=""fun <T: Comparable> max(coll : Collection<T>) : T""/> @@ -1467,7 +1467,7 @@ + val=""fun <T> max(coll : Collection<T>, comp : Comparator<in T>) : T""/> @@ -1707,7 +1707,7 @@ + val=""fun <T> unmodifiableCollection(c : Collection<T>) : MutableCollection<T>""/> @@ -1833,13 +1833,13 @@ - + + val=""fun disjoint(c1 : Collection<Any?>, c2 : Collection<Any?>) : Boolean""/> diff --git a/jdk-annotations/java/util/concurrent/annotations.xml b/jdk-annotations/java/util/concurrent/annotations.xml index 1c3df413c31..020884c6f70 100644 --- a/jdk-annotations/java/util/concurrent/annotations.xml +++ b/jdk-annotations/java/util/concurrent/annotations.xml @@ -112,14 +112,14 @@ + val=""fun <T> invokeAll(tasks : Collection<Callable<T>>) : MutableList<Future<T>>""/> + val=""fun <T> invokeAll(tasks : Collection<Callable<T>>, timeout : Long, unit : TimeUnit) : MutableList<Future<T>>""/> @@ -134,14 +134,14 @@ + val=""fun <T> invokeAny(tasks : Collection<Callable<T>>) : T?""/> + val=""fun <T> invokeAny(tasks : Collection<Callable<T>>, timeout : Long, unit : TimeUnit) : T""/> @@ -359,7 +359,7 @@ + val=""fun <T> invokeAll(tasks : Collection<Callable<T>>) : MutableList<Future<T>>""/>