alternative signature applies for names
mapped in standard library (and differs from auto transformed Java signature) e.g.Collections.copy(MutableList, List)
This commit is contained in:
+26
-6
@@ -25,6 +25,7 @@ import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ComparatorUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.asm4.Type;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
|
||||
@@ -36,10 +37,7 @@ import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
||||
import org.jetbrains.jet.resolve.DescriptorRenderer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author Evgeny Gerashchenko
|
||||
@@ -173,7 +171,8 @@ class AlternativeSignatureData {
|
||||
ClassifierDescriptor declarationDescriptor = originalTypeConstructor.getDeclarationDescriptor();
|
||||
assert declarationDescriptor != null;
|
||||
String fqName = DescriptorUtils.getFQName(declarationDescriptor).toSafe().getFqName();
|
||||
if (!fqName.equals(expectedFqNamePostfix) && !fqName.endsWith("." + expectedFqNamePostfix)) {
|
||||
ClassDescriptor classFromLibrary = getExpectedFromLibrary(expectedFqNamePostfix);
|
||||
if (!fqName.equals(expectedFqNamePostfix) && !fqName.endsWith("." + expectedFqNamePostfix) && classFromLibrary == null) {
|
||||
fail("Alternative signature type mismatch, expected: %s, actual: %s", expectedFqNamePostfix, fqName);
|
||||
}
|
||||
|
||||
@@ -213,7 +212,13 @@ class AlternativeSignatureData {
|
||||
altArguments.add(new TypeProjection(variance, alternativeType));
|
||||
}
|
||||
|
||||
TypeConstructor typeConstructor = originalTypeConstructor;
|
||||
TypeConstructor typeConstructor;
|
||||
if (classFromLibrary != null) {
|
||||
typeConstructor = classFromLibrary.getTypeConstructor();
|
||||
}
|
||||
else {
|
||||
typeConstructor = originalTypeConstructor;
|
||||
}
|
||||
ClassifierDescriptor typeConstructorClassifier = typeConstructor.getDeclarationDescriptor();
|
||||
if (typeConstructorClassifier instanceof TypeParameterDescriptor
|
||||
&& originalToAltTypeParameters.containsKey(typeConstructorClassifier)) {
|
||||
@@ -234,6 +239,21 @@ class AlternativeSignatureData {
|
||||
altArguments, memberScope);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private ClassDescriptor getExpectedFromLibrary(String expectedFqNamePostfix) {
|
||||
Type javaAnalog = KotlinToJavaTypesMap.getInstance().getJavaAnalog(autoType);
|
||||
if (javaAnalog == null || javaAnalog.getSort() != Type.OBJECT) return null;
|
||||
Collection<ClassDescriptor> descriptors =
|
||||
JavaToKotlinClassMap.getInstance().mapPlatformClass(JvmClassName.byType(javaAnalog).getFqName());
|
||||
for (ClassDescriptor descriptor : descriptors) {
|
||||
String fqName = DescriptorUtils.getFQName(descriptor).getFqName();
|
||||
if (fqName.endsWith("." + expectedFqNamePostfix)) {
|
||||
return descriptor;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetType visitSelfType(JetSelfType type, Void data) {
|
||||
throw new UnsupportedOperationException("Self-types are not supported yet");
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import java.util.HashMap
|
||||
|
||||
fun box() : String {
|
||||
if (!testIteratingOverMap1()) return "fail 1"
|
||||
if (!testIteratingOverMap2()) return "fail 2"
|
||||
return "OK"
|
||||
}
|
||||
|
||||
fun testIteratingOverMap1() : Boolean {
|
||||
val map = HashMap<String, Int>()
|
||||
map.put("a", 1)
|
||||
for (entry in map.entrySet()) {
|
||||
entry.setValue(2)
|
||||
}
|
||||
return map.get("a") == 2
|
||||
}
|
||||
|
||||
fun testIteratingOverMap2() : Boolean {
|
||||
val map : MutableMap<String, Int> = HashMap<String, Int>()
|
||||
map.put("a", 1)
|
||||
for (entry in map.entrySet()) {
|
||||
entry.setValue(2)
|
||||
}
|
||||
return map.get("a") == 2
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package test;
|
||||
|
||||
import java.lang.UnsupportedOperationException;
|
||||
import java.util.*;
|
||||
import jet.runtime.typeinfo.KotlinSignature;
|
||||
|
||||
public class MethodWithMappedClasses {
|
||||
@KotlinSignature("fun <T> copy(dest : MutableList<in T>, src : List<out T>)")
|
||||
public <T> void copy(List<? super T> dest, List<? extends T> src) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package test
|
||||
|
||||
import java.util.*
|
||||
|
||||
public open class MethodWithMappedClasses : Object() {
|
||||
public open fun <T> copy(p0 : MutableList<in T>, p1 : List<out T>) {}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace test
|
||||
|
||||
public open class test.MethodWithMappedClasses : java.lang.Object {
|
||||
public final /*constructor*/ fun <init>(): test.MethodWithMappedClasses
|
||||
public open fun </*0*/ T : jet.Any?>copy(/*0*/ p0: jet.MutableList<in T>, /*1*/ p1: jet.List<out T>): jet.Tuple0
|
||||
}
|
||||
@@ -43,4 +43,8 @@ public class JdkAnnotationsTest extends CodegenTestCase {
|
||||
public void testKt1397() {
|
||||
blackBoxFile("regressions/kt1397.kt");
|
||||
}
|
||||
|
||||
public void testIteratingOverHashMap() {
|
||||
blackBoxFile("jdk-annotations/iteratingOverHashMap.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -250,6 +250,11 @@ public class LoadJavaTestGenerated extends AbstractLoadJavaTest {
|
||||
doTest("compiler/testData/loadJava/kotlinSignature/MethodWithGenerics.java");
|
||||
}
|
||||
|
||||
@TestMetadata("MethodWithMappedClasses.java")
|
||||
public void testMethodWithMappedClasses() throws Exception {
|
||||
doTest("compiler/testData/loadJava/kotlinSignature/MethodWithMappedClasses.java");
|
||||
}
|
||||
|
||||
@TestMetadata("MethodWithTupleType.java")
|
||||
public void testMethodWithTupleType() throws Exception {
|
||||
doTest("compiler/testData/loadJava/kotlinSignature/MethodWithTupleType.java");
|
||||
|
||||
+5
@@ -1125,6 +1125,11 @@ public class LazyResolveNamespaceComparingTestGenerated extends AbstractLazyReso
|
||||
doTestSinglePackage("compiler/testData/loadJava/kotlinSignature/MethodWithGenerics.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("MethodWithMappedClasses.kt")
|
||||
public void testMethodWithMappedClasses() throws Exception {
|
||||
doTestSinglePackage("compiler/testData/loadJava/kotlinSignature/MethodWithMappedClasses.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("MethodWithTupleType.kt")
|
||||
public void testMethodWithTupleType() throws Exception {
|
||||
doTestSinglePackage("compiler/testData/loadJava/kotlinSignature/MethodWithTupleType.kt");
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import java.util.HashMap
|
||||
|
||||
fun foo(map : HashMap<String, Int>) {
|
||||
for (<caret>entry : Map.Entry<String, Int> in map.entrySet()) {
|
||||
for (<caret>entry : MutableMap.MutableEntry<String, Int> in map.entrySet()) {
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user