Packages: move collections to kotlin.collections.

This commit is contained in:
Ilya Gorbunov
2015-11-23 23:34:54 +03:00
parent 9fbbc9db98
commit 9c0f0cad70
19 changed files with 288 additions and 187 deletions
+1 -1
View File
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package kotlin
package kotlin.collections
/**
* Classes that inherit from this interface can be represented as a sequence of elements that can
+1 -1
View File
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package kotlin
package kotlin.collections
/**
* An iterator over a collection or another entity that can be represented as a sequence of elements.
@@ -175,7 +175,7 @@ class LazyJavaClassDescriptor(
?: FakePureImplementationsProvider.getPurelyImplementedInterface(fqName)
?: return null
if (purelyImplementedFqName.isRoot || purelyImplementedFqName.parent() != KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAME) return null
if (purelyImplementedFqName.isRoot || !purelyImplementedFqName.toUnsafe().startsWith(KotlinBuiltIns.BUILT_INS_PACKAGE_NAME)) return null
val classDescriptor = c.module.builtIns.getBuiltInClassByNameNullable(purelyImplementedFqName.shortName()) ?: return null
@@ -18,6 +18,7 @@
package org.jetbrains.kotlin.load.java
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.builtins.KotlinBuiltIns.FQ_NAMES as BUILTIN_NAMES
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.load.java.BuiltinMethodsWithSpecialGenericSignature.getSpecialSignatureInfo
import org.jetbrains.kotlin.load.java.BuiltinMethodsWithSpecialGenericSignature.sameAsBuiltinMethodWithErasedValueParameters
@@ -25,37 +26,41 @@ import org.jetbrains.kotlin.load.java.BuiltinSpecialProperties.getBuiltinSpecial
import org.jetbrains.kotlin.load.java.descriptors.JavaCallableMemberDescriptor
import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.FqNameUnsafe
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.descriptorUtil.*
import org.jetbrains.kotlin.types.checker.TypeCheckingProcedure
private fun FqName.child(name: String): FqName = child(Name.identifier(name))
private fun FqNameUnsafe.childSafe(name: String): FqName = child(Name.identifier(name)).toSafe()
object BuiltinSpecialProperties {
private val PROPERTY_FQ_NAME_TO_JVM_GETTER_NAME_MAP = mapOf(
FqName("kotlin.Enum.name") to Name.identifier("name"),
FqName("kotlin.Enum.ordinal") to Name.identifier("ordinal"),
FqName("kotlin.Collection.size") to Name.identifier("size"),
FqName("kotlin.Map.size") to Name.identifier("size"),
FqName("kotlin.CharSequence.length") to Name.identifier("length"),
FqName("kotlin.Map.keys") to Name.identifier("keySet"),
FqName("kotlin.Map.values") to Name.identifier("values"),
FqName("kotlin.Map.entries") to Name.identifier("entrySet")
private val PROPERTY_FQ_NAME_TO_JVM_GETTER_NAME_MAP = mapOf<FqName, Name>(
BUILTIN_NAMES._enum.childSafe("name") to Name.identifier("name"),
BUILTIN_NAMES._enum.childSafe("ordinal") to Name.identifier("ordinal"),
BUILTIN_NAMES.collection.child("size") to Name.identifier("size"),
BUILTIN_NAMES.map.child("size") to Name.identifier("size"),
BUILTIN_NAMES.charSequence.childSafe("length") to Name.identifier("length"),
BUILTIN_NAMES.map.child("keys") to Name.identifier("keySet"),
BUILTIN_NAMES.map.child("values") to Name.identifier("values"),
BUILTIN_NAMES.map.child("entries") to Name.identifier("entrySet")
)
private val GETTER_JVM_NAME_TO_PROPERTIES_SHORT_NAME_MAP: Map<Name, List<Name>> =
PROPERTY_FQ_NAME_TO_JVM_GETTER_NAME_MAP.getInversedShortNamesMap()
private val FQ_NAMES = PROPERTY_FQ_NAME_TO_JVM_GETTER_NAME_MAP.keys
internal val SHORT_NAMES = FQ_NAMES.map { it.shortName() }.toSet()
private val SPECIAL_FQ_NAMES = PROPERTY_FQ_NAME_TO_JVM_GETTER_NAME_MAP.keys
internal val SPECIAL_SHORT_NAMES = SPECIAL_FQ_NAMES.map { it.shortName() }.toSet()
fun hasBuiltinSpecialPropertyFqName(callableMemberDescriptor: CallableMemberDescriptor): Boolean {
if (callableMemberDescriptor.name !in SHORT_NAMES) return false
if (callableMemberDescriptor.name !in SPECIAL_SHORT_NAMES) return false
return callableMemberDescriptor.hasBuiltinSpecialPropertyFqNameImpl()
}
private fun CallableMemberDescriptor.hasBuiltinSpecialPropertyFqNameImpl(): Boolean {
if (fqNameOrNull() in FQ_NAMES) return true
if (fqNameOrNull() in SPECIAL_FQ_NAMES) return true
if (!isFromBuiltins()) return false
return overriddenDescriptors.any { hasBuiltinSpecialPropertyFqName(it) }
@@ -74,9 +79,9 @@ object BuiltinSpecialProperties {
object BuiltinMethodsWithSpecialGenericSignature {
private val ERASED_COLLECTION_PARAMETER_FQ_NAMES = setOf(
FqName("kotlin.Collection.containsAll"),
FqName("kotlin.MutableCollection.removeAll"),
FqName("kotlin.MutableCollection.retainAll")
BUILTIN_NAMES.collection.child("containsAll"),
BUILTIN_NAMES.mutableCollection.child("removeAll"),
BUILTIN_NAMES.mutableCollection.child("retainAll")
)
enum class DefaultValue(val value: Any?) {
@@ -84,16 +89,16 @@ object BuiltinMethodsWithSpecialGenericSignature {
}
private val GENERIC_PARAMETERS_METHODS_TO_DEFAULT_VALUES_MAP = mapOf(
FqName("kotlin.Collection.contains") to DefaultValue.FALSE,
FqName("kotlin.MutableCollection.remove") to DefaultValue.FALSE,
FqName("kotlin.Map.containsKey") to DefaultValue.FALSE,
FqName("kotlin.Map.containsValue") to DefaultValue.FALSE,
BUILTIN_NAMES.collection.child("contains") to DefaultValue.FALSE,
BUILTIN_NAMES.mutableCollection.child("remove") to DefaultValue.FALSE,
BUILTIN_NAMES.map.child("containsKey") to DefaultValue.FALSE,
BUILTIN_NAMES.map.child("containsValue") to DefaultValue.FALSE,
FqName("kotlin.Map.get") to DefaultValue.NULL,
FqName("kotlin.MutableMap.remove") to DefaultValue.NULL,
BUILTIN_NAMES.map.child("get") to DefaultValue.NULL,
BUILTIN_NAMES.mutableMap.child("remove") to DefaultValue.NULL,
FqName("kotlin.List.indexOf") to DefaultValue.INDEX,
FqName("kotlin.List.lastIndexOf") to DefaultValue.INDEX
BUILTIN_NAMES.list.child("indexOf") to DefaultValue.INDEX,
BUILTIN_NAMES.list.child("lastIndexOf") to DefaultValue.INDEX
)
private val ERASED_VALUE_PARAMETERS_FQ_NAMES =
@@ -153,17 +158,17 @@ object BuiltinMethodsWithSpecialGenericSignature {
}
object BuiltinMethodsWithDifferentJvmName {
val REMOVE_AT_FQ_NAME = FqName("kotlin.MutableList.removeAt")
val REMOVE_AT_FQ_NAME = BUILTIN_NAMES.mutableList.child("removeAt")
val FQ_NAMES_TO_JVM_MAP: Map<FqName, Name> = mapOf(
FqName("kotlin.Number.toByte") to Name.identifier("byteValue"),
FqName("kotlin.Number.toShort") to Name.identifier("shortValue"),
FqName("kotlin.Number.toInt") to Name.identifier("intValue"),
FqName("kotlin.Number.toLong") to Name.identifier("longValue"),
FqName("kotlin.Number.toFloat") to Name.identifier("floatValue"),
FqName("kotlin.Number.toDouble") to Name.identifier("doubleValue"),
REMOVE_AT_FQ_NAME to Name.identifier("remove"),
FqName("kotlin.CharSequence.get") to Name.identifier("charAt")
BUILTIN_NAMES.number.childSafe("toByte") to Name.identifier("byteValue"),
BUILTIN_NAMES.number.childSafe("toShort") to Name.identifier("shortValue"),
BUILTIN_NAMES.number.childSafe("toInt") to Name.identifier("intValue"),
BUILTIN_NAMES.number.childSafe("toLong") to Name.identifier("longValue"),
BUILTIN_NAMES.number.childSafe("toFloat") to Name.identifier("floatValue"),
BUILTIN_NAMES.number.childSafe("toDouble") to Name.identifier("doubleValue"),
REMOVE_AT_FQ_NAME to Name.identifier("remove"),
BUILTIN_NAMES.charSequence.childSafe("get") to Name.identifier("charAt")
)
val ORIGINAL_SHORT_NAMES: List<Name> = FQ_NAMES_TO_JVM_MAP.keys.map { it.shortName() }
@@ -194,7 +199,7 @@ object BuiltinMethodsWithDifferentJvmName {
@Suppress("UNCHECKED_CAST")
fun <T : CallableMemberDescriptor> T.getOverriddenBuiltinWithDifferentJvmName(): T? {
if (name !in BuiltinMethodsWithDifferentJvmName.ORIGINAL_SHORT_NAMES
&& propertyIfAccessor.name !in BuiltinSpecialProperties.SHORT_NAMES) return null
&& propertyIfAccessor.name !in BuiltinSpecialProperties.SPECIAL_SHORT_NAMES) return null
return when (this) {
is PropertyDescriptor, is PropertyAccessorDescriptor ->
@@ -120,15 +120,15 @@ class JvmNameResolver(
"kotlin/Cloneable",
"kotlin/Annotation",
"kotlin/Iterable", "kotlin/MutableIterable",
"kotlin/Collection", "kotlin/MutableCollection",
"kotlin/List", "kotlin/MutableList",
"kotlin/Set", "kotlin/MutableSet",
"kotlin/Map", "kotlin/MutableMap",
"kotlin/Map.Entry", "kotlin/MutableMap.MutableEntry",
"kotlin/collections/Iterable", "kotlin/collections/MutableIterable",
"kotlin/collections/Collection", "kotlin/collections/MutableCollection",
"kotlin/collections/List", "kotlin/collections/MutableList",
"kotlin/collections/Set", "kotlin/collections/MutableSet",
"kotlin/collections/Map", "kotlin/collections/MutableMap",
"kotlin/collections/Map.Entry", "kotlin/collections/MutableMap.MutableEntry",
"kotlin/Iterator", "kotlin/MutableIterator",
"kotlin/ListIterator", "kotlin/MutableListIterator"
"kotlin/collections/Iterator", "kotlin/collections/MutableIterator",
"kotlin/collections/ListIterator", "kotlin/collections/MutableListIterator"
)
private val PREDEFINED_STRINGS_MAP = PREDEFINED_STRINGS.withIndex().toMapBy({ it.value }, { it.index })
@@ -127,6 +127,7 @@ public abstract class KotlinBuiltIns {
public final FqNameUnsafe cloneable = fqNameUnsafe("Cloneable");
public final FqNameUnsafe suppress = fqNameUnsafe("Suppress");
public final FqNameUnsafe unit = fqNameUnsafe("Unit");
public final FqNameUnsafe charSequence = fqNameUnsafe("CharSequence");
public final FqNameUnsafe string = fqNameUnsafe("String");
public final FqNameUnsafe array = fqNameUnsafe("Array");
@@ -138,11 +139,11 @@ public abstract class KotlinBuiltIns {
public final FqNameUnsafe _long = fqNameUnsafe("Long");
public final FqNameUnsafe _float = fqNameUnsafe("Float");
public final FqNameUnsafe _double = fqNameUnsafe("Double");
public final FqNameUnsafe number = fqNameUnsafe("Number");
public final FqNameUnsafe _enum = fqNameUnsafe("Enum");
public final FqNameUnsafe _collection = fqNameUnsafe("Collection");
public final FqNameUnsafe _list = fqNameUnsafe("List");
public final FqNameUnsafe _set = fqNameUnsafe("Set");
public final FqNameUnsafe _iterable = fqNameUnsafe("Iterable");
public final FqName throwable = fqName("Throwable");
@@ -157,9 +158,23 @@ public abstract class KotlinBuiltIns {
public final FqName mustBeDocumented = annotationName("MustBeDocumented");
public final FqName unsafeVariance = fqName("UnsafeVariance");
public final FqName mutableList = fqName("MutableList");
public final FqName mutableSet = fqName("MutableSet");
public final FqName mutableMap = fqName("MutableMap");
public final FqName iterator = collectionsFqName("Iterator");
public final FqName iterable = collectionsFqName("Iterable");
public final FqName collection = collectionsFqName("Collection");
public final FqName list = collectionsFqName("List");
public final FqName set = collectionsFqName("Set");
public final FqName map = collectionsFqName("Map");
public final FqName mutableIterator = collectionsFqName("MutableIterator");
public final FqName mutableIterable = collectionsFqName("MutableIterable");
public final FqName mutableCollection = collectionsFqName("MutableCollection");
public final FqName mutableList = collectionsFqName("MutableList");
public final FqName mutableSet = collectionsFqName("MutableSet");
public final FqName mutableMap = collectionsFqName("MutableMap");
private final FqNameUnsafe _collection = collection.toUnsafe();
private final FqNameUnsafe _list = list.toUnsafe();
private final FqNameUnsafe _set = set.toUnsafe();
private final FqNameUnsafe _iterable = iterable.toUnsafe();
public final FqNameUnsafe kClass = reflect("KClass");
public final FqNameUnsafe kCallable = reflect("KCallable");
@@ -189,6 +204,11 @@ public abstract class KotlinBuiltIns {
return BUILT_INS_PACKAGE_FQ_NAME.child(Name.identifier(simpleName));
}
@NotNull
private static FqName collectionsFqName(@NotNull String simpleName) {
return COLLECTIONS_PACKAGE_FQ_NAME.child(Name.identifier(simpleName));
}
@NotNull
private static FqNameUnsafe reflect(@NotNull String simpleName) {
return ReflectionTypesKt.getKOTLIN_REFLECT_FQ_NAME().child(Name.identifier(simpleName)).toUnsafe();
@@ -212,6 +232,21 @@ public abstract class KotlinBuiltIns {
return builtinsPackageFragment;
}
@NotNull
public BuiltinsPackageFragment getCollectionsPackageFragment() {
return collectionsPackageFragment;
}
@NotNull
public BuiltinsPackageFragment getRangesPackageFragment() {
return rangesPackageFragment;
}
@NotNull
public BuiltinsPackageFragment getAnnotationPackageFragment() {
return annotationPackageFragment;
}
public boolean isBuiltInPackageFragment(@Nullable PackageFragmentDescriptor packageFragment) {
return packageFragment != null && packageFragment.getContainingDeclaration() == getBuiltInsModule();
}
@@ -221,11 +256,6 @@ public abstract class KotlinBuiltIns {
return builtinsPackageFragment.getMemberScope();
}
@NotNull
public MemberScope getAnnotationPackageScope() {
return annotationPackageFragment.getMemberScope();
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// GET CLASS
@@ -493,62 +523,62 @@ public abstract class KotlinBuiltIns {
@NotNull
public ClassDescriptor getIterator() {
return getBuiltInClassByName("Iterator");
return getBuiltInClassByName("Iterator", collectionsPackageFragment);
}
@NotNull
public ClassDescriptor getIterable() {
return getBuiltInClassByName("Iterable");
return getBuiltInClassByName("Iterable", collectionsPackageFragment);
}
@NotNull
public ClassDescriptor getMutableIterable() {
return getBuiltInClassByName("MutableIterable");
return getBuiltInClassByName("MutableIterable", collectionsPackageFragment);
}
@NotNull
public ClassDescriptor getMutableIterator() {
return getBuiltInClassByName("MutableIterator");
return getBuiltInClassByName("MutableIterator", collectionsPackageFragment);
}
@NotNull
public ClassDescriptor getCollection() {
return getBuiltInClassByName("Collection");
return getBuiltInClassByName("Collection", collectionsPackageFragment);
}
@NotNull
public ClassDescriptor getMutableCollection() {
return getBuiltInClassByName("MutableCollection");
return getBuiltInClassByName("MutableCollection", collectionsPackageFragment);
}
@NotNull
public ClassDescriptor getList() {
return getBuiltInClassByName("List");
return getBuiltInClassByName("List", collectionsPackageFragment);
}
@NotNull
public ClassDescriptor getMutableList() {
return getBuiltInClassByName("MutableList");
return getBuiltInClassByName("MutableList", collectionsPackageFragment);
}
@NotNull
public ClassDescriptor getSet() {
return getBuiltInClassByName("Set");
return getBuiltInClassByName("Set", collectionsPackageFragment);
}
@NotNull
public ClassDescriptor getMutableSet() {
return getBuiltInClassByName("MutableSet");
return getBuiltInClassByName("MutableSet", collectionsPackageFragment);
}
@NotNull
public ClassDescriptor getMap() {
return getBuiltInClassByName("Map");
return getBuiltInClassByName("Map", collectionsPackageFragment);
}
@NotNull
public ClassDescriptor getMutableMap() {
return getBuiltInClassByName("MutableMap");
return getBuiltInClassByName("MutableMap", collectionsPackageFragment);
}
@NotNull
@@ -567,12 +597,12 @@ public abstract class KotlinBuiltIns {
@NotNull
public ClassDescriptor getListIterator() {
return getBuiltInClassByName("ListIterator");
return getBuiltInClassByName("ListIterator", collectionsPackageFragment);
}
@NotNull
public ClassDescriptor getMutableListIterator() {
return getBuiltInClassByName("MutableListIterator");
return getBuiltInClassByName("MutableListIterator", collectionsPackageFragment);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -17,6 +17,7 @@
package org.jetbrains.kotlin.builtins;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.name.FqName;
import org.jetbrains.kotlin.name.Name;
import java.util.Collections;
@@ -39,6 +40,8 @@ public enum PrimitiveType {
private final Name typeName;
private final Name arrayTypeName;
private FqName typeFqName = null;
private FqName arrayTypeFqName = null;
private PrimitiveType(String typeName) {
this.typeName = Name.identifier(typeName);
@@ -50,8 +53,26 @@ public enum PrimitiveType {
return typeName;
}
@NotNull
public FqName getTypeFqName() {
if (typeFqName != null)
return typeFqName;
typeFqName = KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAME.child(typeName);
return typeFqName;
}
@NotNull
public Name getArrayTypeName() {
return arrayTypeName;
}
@NotNull
public FqName getArrayTypeFqName() {
if (arrayTypeFqName != null)
return arrayTypeFqName;
arrayTypeFqName = KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAME.child(arrayTypeName);
return arrayTypeFqName;
}
}
@@ -0,0 +1,20 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* 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.
*/
package kotlin.collections
// remove after bootstrapping packages
public class PackagePlaceholder
@@ -0,0 +1,20 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* 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.
*/
package kotlin.ranges
// remove after bootstrapping packages
public class PackagePlaceholder