Refer to builtin names in HeuristicSignatures and j2k TypeVisitor

This commit is contained in:
Ilya Gorbunov
2015-11-25 19:34:13 +03:00
parent 346291af7b
commit 83ef48d0ac
3 changed files with 48 additions and 40 deletions
@@ -48,7 +48,7 @@ public class TypeIntrinsics {
public static Iterator asMutableIterator(Object obj) {
if (obj instanceof KMappedMarker && !(obj instanceof KMutableIterator)) {
throwCce(obj, "kotlin.MutableIterator");
throwCce(obj, "kotlin.collections.MutableIterator");
}
return castToIterator(obj);
}
@@ -76,7 +76,7 @@ public class TypeIntrinsics {
public static ListIterator asMutableListIterator(Object obj) {
if (obj instanceof KMappedMarker && !(obj instanceof KMutableListIterator)) {
throwCce(obj, "kotlin.MutableListIterator");
throwCce(obj, "kotlin.collections.MutableListIterator");
}
return castToListIterator(obj);
}
@@ -104,7 +104,7 @@ public class TypeIntrinsics {
public static Iterable asMutableIterable(Object obj) {
if (obj instanceof KMappedMarker && !(obj instanceof KMutableIterable)) {
throwCce(obj, "kotlin.MutableIterable");
throwCce(obj, "kotlin.collections.MutableIterable");
}
return castToIterable(obj);
}
@@ -132,7 +132,7 @@ public class TypeIntrinsics {
public static Collection asMutableCollection(Object obj) {
if (obj instanceof KMappedMarker && !(obj instanceof KMutableCollection)) {
throwCce(obj, "kotlin.MutableCollection");
throwCce(obj, "kotlin.collections.MutableCollection");
}
return castToCollection(obj);
}
@@ -160,7 +160,7 @@ public class TypeIntrinsics {
public static List asMutableList(Object obj) {
if (obj instanceof KMappedMarker && !(obj instanceof KMutableList)) {
throwCce(obj, "kotlin.MutableList");
throwCce(obj, "kotlin.collections.MutableList");
}
return castToList(obj);
}
@@ -188,7 +188,7 @@ public class TypeIntrinsics {
public static Set asMutableSet(Object obj) {
if (obj instanceof KMappedMarker && !(obj instanceof KMutableSet)) {
throwCce(obj, "kotlin.MutableSet");
throwCce(obj, "kotlin.collections.MutableSet");
}
return castToSet(obj);
}
@@ -216,7 +216,7 @@ public class TypeIntrinsics {
public static Map asMutableMap(Object obj) {
if (obj instanceof KMappedMarker && !(obj instanceof KMutableMap)) {
throwCce(obj, "kotlin.MutableMap");
throwCce(obj, "kotlin.collections.MutableMap");
}
return castToMap(obj);
}
@@ -244,7 +244,7 @@ public class TypeIntrinsics {
public static Map.Entry asMutableMapEntry(Object obj) {
if (obj instanceof KMappedMarker && !(obj instanceof KMutableMap.Entry)) {
throwCce(obj, "kotlin.MutableMap.MutableEntry");
throwCce(obj, "kotlin.collections.MutableMap.MutableEntry");
}
return castToMapEntry(obj);
}
@@ -17,6 +17,7 @@
package org.jetbrains.kotlin.idea.core
import com.intellij.openapi.project.Project
import org.jetbrains.kotlin.builtins.KotlinBuiltIns.FQ_NAMES as BUILTIN_NAMES
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
@@ -89,24 +90,24 @@ internal class HeuristicSignatures(
private val signatures = HashMap<Pair<FqName, Name>, List<String>>()
init {
registerSignature("kotlin.Collection", "contains", "E")
registerSignature("kotlin.Collection", "containsAll", "kotlin.Collection<E>")
registerSignature("kotlin.MutableCollection", "remove", "E")
registerSignature("kotlin.MutableCollection", "removeAll", "kotlin.Collection<E>")
registerSignature("kotlin.MutableCollection", "retainAll", "kotlin.Collection<E>")
registerSignature("kotlin.List", "indexOf", "E")
registerSignature("kotlin.List", "lastIndexOf", "E")
registerSignature("kotlin.Map", "get", "K")
registerSignature("kotlin.Map", "containsKey", "K")
registerSignature("kotlin.Map", "containsValue", "V")
registerSignature("kotlin.MutableMap", "remove", "K")
registerSignature(BUILTIN_NAMES.collection, "contains", "E")
registerSignature(BUILTIN_NAMES.collection, "containsAll", BUILTIN_NAMES.collection.asString() + "<E>")
registerSignature(BUILTIN_NAMES.mutableCollection, "remove", "E")
registerSignature(BUILTIN_NAMES.mutableCollection, "removeAll", BUILTIN_NAMES.collection.asString() + "<E>")
registerSignature(BUILTIN_NAMES.mutableCollection, "retainAll", BUILTIN_NAMES.collection.asString() + "<E>")
registerSignature(BUILTIN_NAMES.list, "indexOf", "E")
registerSignature(BUILTIN_NAMES.list, "lastIndexOf", "E")
registerSignature(BUILTIN_NAMES.map, "get", "K")
registerSignature(BUILTIN_NAMES.map, "containsKey", "K")
registerSignature(BUILTIN_NAMES.map, "containsValue", "V")
registerSignature(BUILTIN_NAMES.mutableMap, "remove", "K")
}
private fun registerSignature(
classFqName: String,
classFqName: FqName,
name: String,
vararg parameterTypes: String) {
signatures[FqName(classFqName) to Name.identifier(name)] = parameterTypes.toList()
signatures[classFqName to Name.identifier(name)] = parameterTypes.toList()
}
}
}
+26 -19
View File
@@ -22,6 +22,7 @@ import com.intellij.psi.impl.source.PsiClassReferenceType
import org.jetbrains.kotlin.j2k.ast.*
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.resolve.jvm.JvmPrimitiveType
import org.jetbrains.kotlin.builtins.KotlinBuiltIns.FQ_NAMES as BUILTIN_NAMES
private val PRIMITIVE_TYPES_NAMES = JvmPrimitiveType.values().map { it.javaKeywordName }
@@ -127,28 +128,34 @@ class TypeVisitor(
companion object {
private val toKotlinTypesMap: Map<String, String> = mapOf(
CommonClassNames.JAVA_LANG_OBJECT to "kotlin.Any",
CommonClassNames.JAVA_LANG_BYTE to "kotlin.Byte",
CommonClassNames.JAVA_LANG_CHARACTER to "kotlin.Char",
CommonClassNames.JAVA_LANG_DOUBLE to "kotlin.Double",
CommonClassNames.JAVA_LANG_FLOAT to "kotlin.Float",
CommonClassNames.JAVA_LANG_INTEGER to "kotlin.Int",
CommonClassNames.JAVA_LANG_LONG to "kotlin.Long",
CommonClassNames.JAVA_LANG_SHORT to "kotlin.Short",
CommonClassNames.JAVA_LANG_BOOLEAN to "kotlin.Boolean",
CommonClassNames.JAVA_LANG_ITERABLE to "kotlin.Iterable",
CommonClassNames.JAVA_UTIL_ITERATOR to "kotlin.Iterator",
CommonClassNames.JAVA_UTIL_LIST to "kotlin.List",
CommonClassNames.JAVA_UTIL_COLLECTION to "kotlin.Collection",
CommonClassNames.JAVA_UTIL_SET to "kotlin.Set",
CommonClassNames.JAVA_UTIL_MAP to "kotlin.Map"
CommonClassNames.JAVA_LANG_OBJECT to BUILTIN_NAMES.any.asString(),
CommonClassNames.JAVA_LANG_BYTE to BUILTIN_NAMES._byte.asString(),
CommonClassNames.JAVA_LANG_CHARACTER to BUILTIN_NAMES._char.asString(),
CommonClassNames.JAVA_LANG_DOUBLE to BUILTIN_NAMES._double.asString(),
CommonClassNames.JAVA_LANG_FLOAT to BUILTIN_NAMES._float.asString(),
CommonClassNames.JAVA_LANG_INTEGER to BUILTIN_NAMES._int.asString(),
CommonClassNames.JAVA_LANG_LONG to BUILTIN_NAMES._long.asString(),
CommonClassNames.JAVA_LANG_SHORT to BUILTIN_NAMES._short.asString(),
CommonClassNames.JAVA_LANG_BOOLEAN to BUILTIN_NAMES._boolean.asString(),
CommonClassNames.JAVA_LANG_ITERABLE to BUILTIN_NAMES.iterable.asString(),
CommonClassNames.JAVA_UTIL_ITERATOR to BUILTIN_NAMES.iterator.asString(),
CommonClassNames.JAVA_UTIL_LIST to BUILTIN_NAMES.list.asString(),
CommonClassNames.JAVA_UTIL_COLLECTION to BUILTIN_NAMES.collection.asString(),
CommonClassNames.JAVA_UTIL_SET to BUILTIN_NAMES.set.asString(),
CommonClassNames.JAVA_UTIL_MAP to BUILTIN_NAMES.map.asString(),
CommonClassNames.JAVA_UTIL_MAP_ENTRY to BUILTIN_NAMES.mapEntry.asString(),
java.util.ListIterator::class.java.canonicalName to BUILTIN_NAMES.listIterator.asString()
)
val toKotlinMutableTypesMap: Map<String, String> = mapOf(
CommonClassNames.JAVA_UTIL_LIST to "kotlin.MutableList",
CommonClassNames.JAVA_UTIL_COLLECTION to "kotlin.MutableCollection",
CommonClassNames.JAVA_UTIL_SET to "kotlin.MutableSet",
CommonClassNames.JAVA_UTIL_MAP to "kotlin.MutableMap"
CommonClassNames.JAVA_UTIL_ITERATOR to BUILTIN_NAMES.mutableIterator.asString(),
CommonClassNames.JAVA_UTIL_LIST to BUILTIN_NAMES.mutableList.asString(),
CommonClassNames.JAVA_UTIL_COLLECTION to BUILTIN_NAMES.mutableCollection.asString(),
CommonClassNames.JAVA_UTIL_SET to BUILTIN_NAMES.mutableSet.asString(),
CommonClassNames.JAVA_UTIL_MAP to BUILTIN_NAMES.mutableMap.asString(),
CommonClassNames.JAVA_UTIL_MAP_ENTRY to BUILTIN_NAMES.mutableMapEntry.asString(),
java.util.ListIterator::class.java.canonicalName to BUILTIN_NAMES.mutableListIterator.asString()
)
}
}