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