Packages: move Ranges, Progression, ProgressionIterators to kotlin.ranges and PrimitiveIterators to kotlin.collections.

This commit is contained in:
Ilya Gorbunov
2015-11-23 21:37:29 +03:00
parent a3efa1ea6c
commit 9fbbc9db98
18 changed files with 84 additions and 49 deletions
@@ -24,20 +24,23 @@ import org.jetbrains.org.objectweb.asm.Type.*
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
class RangeTo : IntrinsicMethod() { class RangeTo : IntrinsicMethod() {
private fun nameToPrimitive(name: String): Type = private fun rangeTypeToPrimitiveType(rangeType: Type): Type {
when (name) { val fqName = rangeType.internalName
"Double" -> DOUBLE_TYPE val name = fqName.substringAfter("kotlin/ranges/").substringBefore("Range")
"Float" -> FLOAT_TYPE return when (name) {
"Long" -> LONG_TYPE "Double" -> DOUBLE_TYPE
"Int" -> INT_TYPE "Float" -> FLOAT_TYPE
"Short" -> SHORT_TYPE "Long" -> LONG_TYPE
"Char" -> CHAR_TYPE "Int" -> INT_TYPE
"Byte" -> BYTE_TYPE "Short" -> SHORT_TYPE
else -> throw IllegalStateException("RangeTo intrinsic can only work for primitive types: $name") "Char" -> CHAR_TYPE
} "Byte" -> BYTE_TYPE
else -> throw IllegalStateException("RangeTo intrinsic can only work for primitive types: $fqName")
}
}
override fun toCallable(method: CallableMethod): Callable { override fun toCallable(method: CallableMethod): Callable {
val argType = nameToPrimitive(method.returnType.internalName.substringAfter("kotlin/").substringBefore("Range")) val argType = rangeTypeToPrimitiveType(method.returnType)
return object : IntrinsicCallable( return object : IntrinsicCallable(
method.returnType, method.returnType,
method.valueParameterTypes.map { argType }, method.valueParameterTypes.map { argType },
+1 -1
View File
@@ -16,7 +16,7 @@
// Auto-generated file. DO NOT EDIT! // Auto-generated file. DO NOT EDIT!
package kotlin package kotlin.collections
/** An iterator over a sequence of values of type `Byte`. */ /** An iterator over a sequence of values of type `Byte`. */
public abstract class ByteIterator : Iterator<Byte> { public abstract class ByteIterator : Iterator<Byte> {
@@ -16,7 +16,7 @@
// Auto-generated file. DO NOT EDIT! // Auto-generated file. DO NOT EDIT!
package kotlin package kotlin.ranges
/** /**
* An iterator over a progression of values of type `Byte`. * An iterator over a progression of values of type `Byte`.
+1 -1
View File
@@ -16,7 +16,7 @@
// Auto-generated file. DO NOT EDIT! // Auto-generated file. DO NOT EDIT!
package kotlin package kotlin.ranges
import kotlin.internal.getProgressionLastElement import kotlin.internal.getProgressionLastElement
+1 -1
View File
@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package kotlin package kotlin.ranges
/** /**
* Represents a range of values (for example, numbers or characters). * Represents a range of values (for example, numbers or characters).
+1 -1
View File
@@ -16,7 +16,7 @@
// Auto-generated file. DO NOT EDIT! // Auto-generated file. DO NOT EDIT!
package kotlin package kotlin.ranges
@Deprecated("Use IntRange instead.", ReplaceWith("IntRange"), level = DeprecationLevel.WARNING) @Deprecated("Use IntRange instead.", ReplaceWith("IntRange"), level = DeprecationLevel.WARNING)
/** /**
@@ -274,7 +274,7 @@ fun ClassDescriptor.hasRealKotlinSuperClassWithOverrideOf(
if (doesOverrideBuiltinDeclaration) { if (doesOverrideBuiltinDeclaration) {
val containingPackageFragment = DescriptorUtils.getParentOfType(superClassDescriptor, PackageFragmentDescriptor::class.java) val containingPackageFragment = DescriptorUtils.getParentOfType(superClassDescriptor, PackageFragmentDescriptor::class.java)
if (containingPackageFragment === superClassDescriptor.builtIns.builtInsPackageFragment) return false if (superClassDescriptor.builtIns.isBuiltInPackageFragment(containingPackageFragment)) return false
return true return true
} }
} }
@@ -50,15 +50,21 @@ public abstract class KotlinBuiltIns {
public static final Name BUILT_INS_PACKAGE_NAME = Name.identifier("kotlin"); public static final Name BUILT_INS_PACKAGE_NAME = Name.identifier("kotlin");
public static final FqName BUILT_INS_PACKAGE_FQ_NAME = FqName.topLevel(BUILT_INS_PACKAGE_NAME); public static final FqName BUILT_INS_PACKAGE_FQ_NAME = FqName.topLevel(BUILT_INS_PACKAGE_NAME);
public static final FqName ANNOTATION_PACKAGE_FQ_NAME = BUILT_INS_PACKAGE_FQ_NAME.child(Name.identifier("annotation")); public static final FqName ANNOTATION_PACKAGE_FQ_NAME = BUILT_INS_PACKAGE_FQ_NAME.child(Name.identifier("annotation"));
public static final FqName COLLECTIONS_PACKAGE_FQ_NAME = BUILT_INS_PACKAGE_FQ_NAME.child(Name.identifier("collections"));
public static final FqName RANGES_PACKAGE_FQ_NAME = BUILT_INS_PACKAGE_FQ_NAME.child(Name.identifier("ranges"));
public static final Set<FqName> BUILT_INS_PACKAGE_FQ_NAMES = setOf( public static final Set<FqName> BUILT_INS_PACKAGE_FQ_NAMES = setOf(
BUILT_INS_PACKAGE_FQ_NAME, BUILT_INS_PACKAGE_FQ_NAME,
COLLECTIONS_PACKAGE_FQ_NAME,
RANGES_PACKAGE_FQ_NAME,
ANNOTATION_PACKAGE_FQ_NAME, ANNOTATION_PACKAGE_FQ_NAME,
ReflectionTypesKt.getKOTLIN_REFLECT_FQ_NAME() ReflectionTypesKt.getKOTLIN_REFLECT_FQ_NAME()
); );
protected final ModuleDescriptorImpl builtInsModule; protected final ModuleDescriptorImpl builtInsModule;
private final BuiltinsPackageFragment builtinsPackageFragment; private final BuiltinsPackageFragment builtinsPackageFragment;
private final BuiltinsPackageFragment collectionsPackageFragment;
private final BuiltinsPackageFragment rangesPackageFragment;
private final BuiltinsPackageFragment annotationPackageFragment; private final BuiltinsPackageFragment annotationPackageFragment;
private final Map<PrimitiveType, KotlinType> primitiveTypeToArrayKotlinType; private final Map<PrimitiveType, KotlinType> primitiveTypeToArrayKotlinType;
@@ -89,6 +95,8 @@ public abstract class KotlinBuiltIns {
builtInsModule.setDependencies(builtInsModule); builtInsModule.setDependencies(builtInsModule);
builtinsPackageFragment = (BuiltinsPackageFragment) single(packageFragmentProvider.getPackageFragments(BUILT_INS_PACKAGE_FQ_NAME)); builtinsPackageFragment = (BuiltinsPackageFragment) single(packageFragmentProvider.getPackageFragments(BUILT_INS_PACKAGE_FQ_NAME));
collectionsPackageFragment = (BuiltinsPackageFragment) single(packageFragmentProvider.getPackageFragments(COLLECTIONS_PACKAGE_FQ_NAME));
rangesPackageFragment = (BuiltinsPackageFragment) single(packageFragmentProvider.getPackageFragments(RANGES_PACKAGE_FQ_NAME));
annotationPackageFragment = (BuiltinsPackageFragment) single(packageFragmentProvider.getPackageFragments(ANNOTATION_PACKAGE_FQ_NAME)); annotationPackageFragment = (BuiltinsPackageFragment) single(packageFragmentProvider.getPackageFragments(ANNOTATION_PACKAGE_FQ_NAME));
primitiveTypeToArrayKotlinType = new EnumMap<PrimitiveType, KotlinType>(PrimitiveType.class); primitiveTypeToArrayKotlinType = new EnumMap<PrimitiveType, KotlinType>(PrimitiveType.class);
@@ -204,6 +212,10 @@ public abstract class KotlinBuiltIns {
return builtinsPackageFragment; return builtinsPackageFragment;
} }
public boolean isBuiltInPackageFragment(@Nullable PackageFragmentDescriptor packageFragment) {
return packageFragment != null && packageFragment.getContainingDeclaration() == getBuiltInsModule();
}
@NotNull @NotNull
public MemberScope getBuiltInsPackageScope() { public MemberScope getBuiltInsPackageScope() {
return builtinsPackageFragment.getMemberScope(); return builtinsPackageFragment.getMemberScope();
@@ -222,24 +234,32 @@ public abstract class KotlinBuiltIns {
@NotNull @NotNull
public ClassDescriptor getAnnotationClassByName(@NotNull Name simpleName) { public ClassDescriptor getAnnotationClassByName(@NotNull Name simpleName) {
ClassifierDescriptor classifier = annotationPackageFragment.getMemberScope().getContributedClassifier(simpleName, return getBuiltInClassByName(simpleName, annotationPackageFragment);
NoLookupLocation.FROM_BUILTINS);
assert classifier instanceof ClassDescriptor : "Must be a class descriptor " + simpleName + ", but was " +
(classifier == null ? "null" : classifier.toString());
return (ClassDescriptor) classifier;
} }
@NotNull @NotNull
public ClassDescriptor getBuiltInClassByName(@NotNull Name simpleName) { public ClassDescriptor getBuiltInClassByName(@NotNull Name simpleName) {
ClassDescriptor classDescriptor = getBuiltInClassByNameNullable(simpleName); return getBuiltInClassByName(simpleName, getBuiltInsPackageFragment());
}
@NotNull
private static ClassDescriptor getBuiltInClassByName(@NotNull Name simpleName, @NotNull PackageFragmentDescriptor packageFragment) {
ClassDescriptor classDescriptor = getBuiltInClassByNameNullable(simpleName, packageFragment);
assert classDescriptor != null : "Built-in class " + simpleName + " is not found"; assert classDescriptor != null : "Built-in class " + simpleName + " is not found";
return classDescriptor; return classDescriptor;
} }
@Nullable @Nullable
public ClassDescriptor getBuiltInClassByNameNullable(@NotNull Name simpleName) { public ClassDescriptor getBuiltInClassByNameNullable(@NotNull Name simpleName) {
ClassifierDescriptor classifier = getBuiltInsPackageFragment().getMemberScope().getContributedClassifier(simpleName, return getBuiltInClassByNameNullable(simpleName, getBuiltInsPackageFragment());
NoLookupLocation.FROM_BUILTINS); }
@Nullable
private static ClassDescriptor getBuiltInClassByNameNullable(@NotNull Name simpleName, @NotNull PackageFragmentDescriptor packageFragment) {
ClassifierDescriptor classifier = packageFragment.getMemberScope().getContributedClassifier(
simpleName,
NoLookupLocation.FROM_BUILTINS);
assert classifier == null || assert classifier == null ||
classifier instanceof ClassDescriptor : "Must be a class descriptor " + simpleName + ", but was " + classifier; classifier instanceof ClassDescriptor : "Must be a class descriptor " + simpleName + ", but was " + classifier;
return (ClassDescriptor) classifier; return (ClassDescriptor) classifier;
@@ -250,6 +270,13 @@ public abstract class KotlinBuiltIns {
return getBuiltInClassByName(Name.identifier(simpleName)); return getBuiltInClassByName(Name.identifier(simpleName));
} }
@NotNull
private static ClassDescriptor getBuiltInClassByName(@NotNull String simpleName, PackageFragmentDescriptor packageFragment) {
return getBuiltInClassByName(Name.identifier(simpleName), packageFragment);
}
// Special // Special
@NotNull @NotNull
@@ -314,10 +341,10 @@ public abstract class KotlinBuiltIns {
@NotNull @NotNull
public Set<DeclarationDescriptor> getIntegralRanges() { public Set<DeclarationDescriptor> getIntegralRanges() {
return SetsKt.<DeclarationDescriptor>setOf( return SetsKt.<DeclarationDescriptor>setOf(
getBuiltInClassByName("ByteRange"), getBuiltInClassByName("ByteRange", rangesPackageFragment),
getBuiltInClassByName("ShortRange"), getBuiltInClassByName("ShortRange", rangesPackageFragment),
getBuiltInClassByName("CharRange"), getBuiltInClassByName("CharRange", rangesPackageFragment),
getBuiltInClassByName("IntRange") getBuiltInClassByName("IntRange", rangesPackageFragment)
); );
} }
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.generators.builtins.generateBuiltIns.*
import java.io.PrintWriter import java.io.PrintWriter
class GenerateIterators(out: PrintWriter) : BuiltInsSourceGenerator(out) { class GenerateIterators(out: PrintWriter) : BuiltInsSourceGenerator(out) {
override fun getPackage() = "kotlin.collections"
override fun generateBody() { override fun generateBody() {
for (kind in PrimitiveType.values()) { for (kind in PrimitiveType.values()) {
val s = kind.capitalized val s = kind.capitalized
@@ -76,6 +76,7 @@ internal class ${t}ProgressionIterator(start: $t, val end: $t, val increment: $t
} }
class GenerateProgressionIterators(out: PrintWriter) : BuiltInsSourceGenerator(out) { class GenerateProgressionIterators(out: PrintWriter) : BuiltInsSourceGenerator(out) {
override fun getPackage() = "kotlin.ranges"
override fun generateBody() { override fun generateBody() {
for (kind in ProgressionKind.values()) { for (kind in ProgressionKind.values()) {
if (kind != FLOAT && kind != DOUBLE) { if (kind != FLOAT && kind != DOUBLE) {
@@ -23,6 +23,7 @@ import java.io.PrintWriter
class GenerateProgressions(out: PrintWriter) : BuiltInsSourceGenerator(out) { class GenerateProgressions(out: PrintWriter) : BuiltInsSourceGenerator(out) {
override fun getPackage() = "kotlin.ranges"
private fun generateDiscreteBody(kind: ProgressionKind) { private fun generateDiscreteBody(kind: ProgressionKind) {
require(kind != FLOAT && kind != DOUBLE) require(kind != FLOAT && kind != DOUBLE)
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.generators.builtins.ProgressionKind.*
import java.io.PrintWriter import java.io.PrintWriter
class GenerateRanges(out: PrintWriter) : BuiltInsSourceGenerator(out) { class GenerateRanges(out: PrintWriter) : BuiltInsSourceGenerator(out) {
override fun getPackage() = "kotlin.ranges"
override fun generateBody() { override fun generateBody() {
for (kind in ProgressionKind.values()) { for (kind in ProgressionKind.values()) {
val t = kind.capitalized val t = kind.capitalized
@@ -24,7 +24,8 @@ import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.Computable;
import com.intellij.psi.PsiElement; import com.intellij.psi.PsiElement;
import com.intellij.xdebugger.impl.XSourcePositionImpl; import com.intellij.xdebugger.impl.XSourcePositionImpl;
import kotlin.IntRange; import kotlin.*;
import kotlin.ranges.*;
import org.jetbrains.kotlin.psi.KtFile; import org.jetbrains.kotlin.psi.KtFile;
import org.jetbrains.kotlin.psi.KtFunction; import org.jetbrains.kotlin.psi.KtFunction;
import org.jetbrains.kotlin.psi.KtFunctionLiteral; import org.jetbrains.kotlin.psi.KtFunctionLiteral;
@@ -18,21 +18,21 @@ package org.jetbrains.kotlin.js.descriptorUtils
import com.intellij.openapi.util.text.StringUtil import com.intellij.openapi.util.text.StringUtil
import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.utils.addToStdlib.check
val KotlinType.nameIfStandardType: Name? val KotlinType.nameIfStandardType: Name?
get() { get() {
val descriptor = constructor.declarationDescriptor return constructor.declarationDescriptor
?.check { descriptor ->
if (descriptor?.containingDeclaration == descriptor?.builtIns?.builtInsPackageFragment) { descriptor.builtIns.isBuiltInPackageFragment(descriptor.containingDeclaration as? PackageFragmentDescriptor)
return descriptor?.name }
} ?.name
return null
} }
fun KotlinType.getJetTypeFqName(printTypeArguments: Boolean): String { fun KotlinType.getJetTypeFqName(printTypeArguments: Boolean): String {
@@ -98,15 +98,15 @@ public final class StandardClasses {
if (type == PrimitiveType.CHAR || type == PrimitiveType.LONG) continue; if (type == PrimitiveType.CHAR || type == PrimitiveType.LONG) continue;
String typeName = type.getTypeName().asString(); String typeName = type.getTypeName().asString();
standardClasses.declare().forFQ("kotlin." + typeName + "Range").kotlinClass("NumberRange"); standardClasses.declare().forFQ("kotlin.ranges." + typeName + "Range").kotlinClass("NumberRange");
standardClasses.declare().forFQ("kotlin." + typeName + "Progression").kotlinClass("NumberProgression"); standardClasses.declare().forFQ("kotlin.ranges." + typeName + "Progression").kotlinClass("NumberProgression");
} }
standardClasses.declare().forFQ("kotlin.LongRange").kotlinClass("LongRange"); standardClasses.declare().forFQ("kotlin.ranges.LongRange").kotlinClass("LongRange");
standardClasses.declare().forFQ("kotlin.CharRange").kotlinClass("CharRange"); standardClasses.declare().forFQ("kotlin.ranges.CharRange").kotlinClass("CharRange");
standardClasses.declare().forFQ("kotlin.LongProgression").kotlinClass("LongProgression"); standardClasses.declare().forFQ("kotlin.ranges.LongProgression").kotlinClass("LongProgression");
standardClasses.declare().forFQ("kotlin.CharProgression").kotlinClass("CharProgression"); standardClasses.declare().forFQ("kotlin.ranges.CharProgression").kotlinClass("CharProgression");
standardClasses.declare().forFQ("kotlin.Enum").kotlinClass("Enum"); standardClasses.declare().forFQ("kotlin.Enum").kotlinClass("Enum");
@@ -34,7 +34,7 @@ object ProgressionCompanionFIF : CompositeFIF() {
add(methodPattern("CharProgression"), CallProgressionConstructorIntrinsic("CharProgression")) add(methodPattern("CharProgression"), CallProgressionConstructorIntrinsic("CharProgression"))
} }
private fun methodPattern(builtinProgressionName: String) = pattern("kotlin", builtinProgressionName, "Companion", "fromClosedRange") private fun methodPattern(builtinProgressionName: String) = pattern("kotlin.ranges", builtinProgressionName, "Companion", "fromClosedRange")
private class CallProgressionConstructorIntrinsic(val libraryProgressionName: String) : FunctionIntrinsic() { private class CallProgressionConstructorIntrinsic(val libraryProgressionName: String) : FunctionIntrinsic() {
override fun apply(receiver: JsExpression?, arguments: MutableList<JsExpression>, context: TranslationContext): JsExpression override fun apply(receiver: JsExpression?, arguments: MutableList<JsExpression>, context: TranslationContext): JsExpression
@@ -156,7 +156,7 @@ public final class JsDescriptorUtils {
public static boolean isBuiltin(@NotNull DeclarationDescriptor descriptor) { public static boolean isBuiltin(@NotNull DeclarationDescriptor descriptor) {
PackageFragmentDescriptor containingPackageFragment = DescriptorUtils.getParentOfType(descriptor, PackageFragmentDescriptor.class); PackageFragmentDescriptor containingPackageFragment = DescriptorUtils.getParentOfType(descriptor, PackageFragmentDescriptor.class);
return containingPackageFragment == org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt.getBuiltIns(descriptor).getBuiltInsPackageFragment(); return org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt.getBuiltIns(descriptor).isBuiltInPackageFragment(containingPackageFragment);
} }
@Nullable @Nullable
+3 -3
View File
@@ -888,7 +888,7 @@
lazyInitClasses.NumberRange = Kotlin.createClass( lazyInitClasses.NumberRange = Kotlin.createClass(
function() { function() {
return [Kotlin.modules['builtins'].kotlin.ClosedRange, Kotlin.NumberProgression] return [Kotlin.modules['builtins'].kotlin.ranges.ClosedRange, Kotlin.NumberProgression]
}, },
function $fun(start, endInclusive) { function $fun(start, endInclusive) {
$fun.baseInitializer.call(this, start, endInclusive, 1); $fun.baseInitializer.call(this, start, endInclusive, 1);
@@ -976,7 +976,7 @@
lazyInitClasses.LongRange = Kotlin.createClass( lazyInitClasses.LongRange = Kotlin.createClass(
function () { function () {
return [Kotlin.modules['builtins'].kotlin.ClosedRange, Kotlin.LongProgression]; return [Kotlin.modules['builtins'].kotlin.ranges.ClosedRange, Kotlin.LongProgression];
}, },
function $fun(start, endInclusive) { function $fun(start, endInclusive) {
$fun.baseInitializer.call(this, start, endInclusive, Kotlin.Long.ONE); $fun.baseInitializer.call(this, start, endInclusive, Kotlin.Long.ONE);
@@ -1058,7 +1058,7 @@
lazyInitClasses.CharRange = Kotlin.createClass( lazyInitClasses.CharRange = Kotlin.createClass(
function() { function() {
return [Kotlin.modules['builtins'].kotlin.ClosedRange, Kotlin.CharProgression] return [Kotlin.modules['builtins'].kotlin.ranges.ClosedRange, Kotlin.CharProgression]
}, },
function $fun(start, endInclusive) { function $fun(start, endInclusive) {
$fun.baseInitializer.call(this, start, endInclusive, 1); $fun.baseInitializer.call(this, start, endInclusive, 1);