diff --git a/core/builtins/native/kotlin/Char.kt b/core/builtins/native/kotlin/Char.kt new file mode 100644 index 00000000000..a88ef3ed831 --- /dev/null +++ b/core/builtins/native/kotlin/Char.kt @@ -0,0 +1,163 @@ +/* + * 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 + +/** + * Represents a 16-bit Unicode character. + * On the JVM, non-nullable values of this type are represented as values of the primitive type `char`. + */ +public class Char private () : Comparable { + companion object {} + + /** + * Compares the character code of this character with the specified value for order. + * Returns zero if this value is equal to the specified other value, a negative number if its less than other, + * or a positive number if its greater than other. + */ + public fun compareTo(other: Byte): Int + /** + * Compares this value with the specified value for order. + * Returns zero if this value is equal to the specified other value, a negative number if its less than other, + * or a positive number if its greater than other. + */ + public override fun compareTo(other: Char): Int + /** + * Compares the character code of this character with the specified value for order. + * Returns zero if this value is equal to the specified other value, a negative number if its less than other, + * or a positive number if its greater than other. + */ + public fun compareTo(other: Short): Int + /** + * Compares the character code of this character with the specified value for order. + * Returns zero if this value is equal to the specified other value, a negative number if its less than other, + * or a positive number if its greater than other. + */ + public fun compareTo(other: Int): Int + /** + * Compares the character code of this character with the specified value for order. + * Returns zero if this value is equal to the specified other value, a negative number if its less than other, + * or a positive number if its greater than other. + */ + public fun compareTo(other: Long): Int + /** + * Compares the character code of this character with the specified value for order. + * Returns zero if this value is equal to the specified other value, a negative number if its less than other, + * or a positive number if its greater than other. + */ + public fun compareTo(other: Float): Int + /** + * Compares the character code of this character with the specified value for order. + * Returns zero if this value is equal to the specified other value, a negative number if its less than other, + * or a positive number if its greater than other. + */ + public fun compareTo(other: Double): Int + + /** Adds the other value to this value. */ + public fun plus(other: Byte): Int + /** Adds the other value to this value. */ + public fun plus(other: Short): Int + /** Adds the other value to this value. */ + public fun plus(other: Int): Int + /** Adds the other value to this value. */ + public fun plus(other: Long): Long + /** Adds the other value to this value. */ + public fun plus(other: Float): Float + /** Adds the other value to this value. */ + public fun plus(other: Double): Double + + /** Subtracts the other value from this value. */ + public fun minus(other: Byte): Int + /** Subtracts the other value from this value. */ + public fun minus(other: Char): Int + /** Subtracts the other value from this value. */ + public fun minus(other: Short): Int + /** Subtracts the other value from this value. */ + public fun minus(other: Int): Int + /** Subtracts the other value from this value. */ + public fun minus(other: Long): Long + /** Subtracts the other value from this value. */ + public fun minus(other: Float): Float + /** Subtracts the other value from this value. */ + public fun minus(other: Double): Double + + /** Multiplies this value by the other value. */ + public fun times(other: Byte): Int + /** Multiplies this value by the other value. */ + public fun times(other: Short): Int + /** Multiplies this value by the other value. */ + public fun times(other: Int): Int + /** Multiplies this value by the other value. */ + public fun times(other: Long): Long + /** Multiplies this value by the other value. */ + public fun times(other: Float): Float + /** Multiplies this value by the other value. */ + public fun times(other: Double): Double + + /** Divides this value by the other value. */ + public fun div(other: Byte): Int + /** Divides this value by the other value. */ + public fun div(other: Short): Int + /** Divides this value by the other value. */ + public fun div(other: Int): Int + /** Divides this value by the other value. */ + public fun div(other: Long): Long + /** Divides this value by the other value. */ + public fun div(other: Float): Float + /** Divides this value by the other value. */ + public fun div(other: Double): Double + + /** Calculates the remainder of dividing this value by the other value. */ + public fun mod(other: Byte): Int + /** Calculates the remainder of dividing this value by the other value. */ + public fun mod(other: Short): Int + /** Calculates the remainder of dividing this value by the other value. */ + public fun mod(other: Int): Int + /** Calculates the remainder of dividing this value by the other value. */ + public fun mod(other: Long): Long + /** Calculates the remainder of dividing this value by the other value. */ + public fun mod(other: Float): Float + /** Calculates the remainder of dividing this value by the other value. */ + public fun mod(other: Double): Double + + /** Increments this value. */ + public fun inc(): Char + /** Decrements this value. */ + public fun dec(): Char + /** Returns this value. */ + public fun plus(): Int + /** Returns the negative of this value. */ + public fun minus(): Int + + /** Creates a range from this value to the specified [other] value. */ + public fun rangeTo(other: Char): CharRange + + /** Returns the value of this character as a `Byte`. */ + public override fun toByte(): Byte + /** Returns the value of this character as a `Char`. */ + public override fun toChar(): Char + /** Returns the value of this character as a `Short`. */ + public override fun toShort(): Short + /** Returns the value of this character as a `Int`. */ + public override fun toInt(): Int + /** Returns the value of this character as a `Long`. */ + public override fun toLong(): Long + /** Returns the value of this character as a `Float`. */ + public override fun toFloat(): Float + /** Returns the value of this character as a `Double`. */ + public override fun toDouble(): Double +} + diff --git a/core/builtins/native/kotlin/Primitives.kt b/core/builtins/native/kotlin/Primitives.kt index 86ba4ebf318..a07f4c7dd43 100644 --- a/core/builtins/native/kotlin/Primitives.kt +++ b/core/builtins/native/kotlin/Primitives.kt @@ -176,151 +176,6 @@ public class Byte private () : Number, Comparable { public override fun toDouble(): Double } -/** - * Represents a 16-bit Unicode character. - * On the JVM, non-nullable values of this type are represented as values of the primitive type `char`. - */ -public class Char private () : Comparable { - companion object {} - -/** - * Compares the character code of this character with the specified value for order. - * Returns zero if this value is equal to the specified other value, a negative number if its less than other, - * or a positive number if its greater than other. - */ - public fun compareTo(other: Byte): Int -/** - * Compares this value with the specified value for order. - * Returns zero if this value is equal to the specified other value, a negative number if its less than other, - * or a positive number if its greater than other. - */ - public override fun compareTo(other: Char): Int -/** - * Compares the character code of this character with the specified value for order. - * Returns zero if this value is equal to the specified other value, a negative number if its less than other, - * or a positive number if its greater than other. - */ - public fun compareTo(other: Short): Int -/** - * Compares the character code of this character with the specified value for order. - * Returns zero if this value is equal to the specified other value, a negative number if its less than other, - * or a positive number if its greater than other. - */ - public fun compareTo(other: Int): Int -/** - * Compares the character code of this character with the specified value for order. - * Returns zero if this value is equal to the specified other value, a negative number if its less than other, - * or a positive number if its greater than other. - */ - public fun compareTo(other: Long): Int -/** - * Compares the character code of this character with the specified value for order. - * Returns zero if this value is equal to the specified other value, a negative number if its less than other, - * or a positive number if its greater than other. - */ - public fun compareTo(other: Float): Int -/** - * Compares the character code of this character with the specified value for order. - * Returns zero if this value is equal to the specified other value, a negative number if its less than other, - * or a positive number if its greater than other. - */ - public fun compareTo(other: Double): Int - - /** Adds the other value to this value. */ - public fun plus(other: Byte): Int - /** Adds the other value to this value. */ - public fun plus(other: Short): Int - /** Adds the other value to this value. */ - public fun plus(other: Int): Int - /** Adds the other value to this value. */ - public fun plus(other: Long): Long - /** Adds the other value to this value. */ - public fun plus(other: Float): Float - /** Adds the other value to this value. */ - public fun plus(other: Double): Double - - /** Subtracts the other value from this value. */ - public fun minus(other: Byte): Int - /** Subtracts the other value from this value. */ - public fun minus(other: Char): Int - /** Subtracts the other value from this value. */ - public fun minus(other: Short): Int - /** Subtracts the other value from this value. */ - public fun minus(other: Int): Int - /** Subtracts the other value from this value. */ - public fun minus(other: Long): Long - /** Subtracts the other value from this value. */ - public fun minus(other: Float): Float - /** Subtracts the other value from this value. */ - public fun minus(other: Double): Double - - /** Multiplies this value by the other value. */ - public fun times(other: Byte): Int - /** Multiplies this value by the other value. */ - public fun times(other: Short): Int - /** Multiplies this value by the other value. */ - public fun times(other: Int): Int - /** Multiplies this value by the other value. */ - public fun times(other: Long): Long - /** Multiplies this value by the other value. */ - public fun times(other: Float): Float - /** Multiplies this value by the other value. */ - public fun times(other: Double): Double - - /** Divides this value by the other value. */ - public fun div(other: Byte): Int - /** Divides this value by the other value. */ - public fun div(other: Short): Int - /** Divides this value by the other value. */ - public fun div(other: Int): Int - /** Divides this value by the other value. */ - public fun div(other: Long): Long - /** Divides this value by the other value. */ - public fun div(other: Float): Float - /** Divides this value by the other value. */ - public fun div(other: Double): Double - - /** Calculates the remainder of dividing this value by the other value. */ - public fun mod(other: Byte): Int - /** Calculates the remainder of dividing this value by the other value. */ - public fun mod(other: Short): Int - /** Calculates the remainder of dividing this value by the other value. */ - public fun mod(other: Int): Int - /** Calculates the remainder of dividing this value by the other value. */ - public fun mod(other: Long): Long - /** Calculates the remainder of dividing this value by the other value. */ - public fun mod(other: Float): Float - /** Calculates the remainder of dividing this value by the other value. */ - public fun mod(other: Double): Double - - /** Increments this value. */ - public fun inc(): Char - /** Decrements this value. */ - public fun dec(): Char - /** Returns this value. */ - public fun plus(): Int - /** Returns the negative of this value. */ - public fun minus(): Int - - /** Creates a range from this value to the specified [other] value. */ - public fun rangeTo(other: Char): CharRange - - /** Returns the value of this character as a `Byte`. */ - public override fun toByte(): Byte - /** Returns the value of this character as a `Char`. */ - public override fun toChar(): Char - /** Returns the value of this character as a `Short`. */ - public override fun toShort(): Short - /** Returns the value of this character as a `Int`. */ - public override fun toInt(): Int - /** Returns the value of this character as a `Long`. */ - public override fun toLong(): Long - /** Returns the value of this character as a `Float`. */ - public override fun toFloat(): Float - /** Returns the value of this character as a `Double`. */ - public override fun toDouble(): Double -} - /** * Represents a 16-bit signed integer. * On the JVM, non-nullable values of this type are represented as values of the primitive type `short`. diff --git a/generators/src/org/jetbrains/kotlin/generators/builtins/common.kt b/generators/src/org/jetbrains/kotlin/generators/builtins/common.kt index 5951dbb632d..736282866aa 100644 --- a/generators/src/org/jetbrains/kotlin/generators/builtins/common.kt +++ b/generators/src/org/jetbrains/kotlin/generators/builtins/common.kt @@ -31,7 +31,8 @@ enum class PrimitiveType { val capitalized: String get() = name().toLowerCase().capitalize() companion object { - val exceptBoolean: Iterable by Delegates.lazy { PrimitiveType.values().filterNot { it == BOOLEAN } } + val exceptBoolean: List by Delegates.lazy { PrimitiveType.values().filterNot { it == BOOLEAN } } + val onlyNumeric: List by Delegates.lazy { PrimitiveType.values().filterNot { it == BOOLEAN || it == CHAR }} } } diff --git a/generators/src/org/jetbrains/kotlin/generators/builtins/primitives.kt b/generators/src/org/jetbrains/kotlin/generators/builtins/primitives.kt index f26cde9d480..b06964c0dad 100644 --- a/generators/src/org/jetbrains/kotlin/generators/builtins/primitives.kt +++ b/generators/src/org/jetbrains/kotlin/generators/builtins/primitives.kt @@ -52,14 +52,10 @@ class GeneratePrimitives(out: PrintWriter) : BuiltInsSourceGenerator(out) { ) override fun generateBody() { - for (kind in PrimitiveType.exceptBoolean) { + for (kind in PrimitiveType.onlyNumeric) { val className = kind.capitalized generateDoc(kind) - out.print("public class $className private () : ") - if (kind != PrimitiveType.CHAR) { - out.print("Number, ") - } - out.println("Comparable<$className> {") + out.println("public class $className private () : Number, Comparable<$className> {") out.print(" companion object") if (kind == PrimitiveType.FLOAT || kind == PrimitiveType.DOUBLE) { @@ -96,9 +92,7 @@ class GeneratePrimitives(out: PrintWriter) : BuiltInsSourceGenerator(out) { private fun generateCompareTo(thisKind: PrimitiveType) { for (otherKind in PrimitiveType.exceptBoolean) { out.println("/**") - if (thisKind == PrimitiveType.CHAR && otherKind != PrimitiveType.CHAR) { - out.println(" * Compares the character code of this character with the specified value for order.") - } else if (thisKind != PrimitiveType.CHAR && otherKind == PrimitiveType.CHAR) { + if (otherKind == PrimitiveType.CHAR) { out.println(" * Compares this value with the character code of the specified character for order.") } else { out.println(" * Compares this value with the specified value for order.") @@ -121,9 +115,6 @@ class GeneratePrimitives(out: PrintWriter) : BuiltInsSourceGenerator(out) { private fun generateOperator(name: String, doc: String, thisKind: PrimitiveType) { for (otherKind in PrimitiveType.exceptBoolean) { - if (thisKind == PrimitiveType.CHAR && otherKind == PrimitiveType.CHAR && name != "minus") { - continue - } val returnType = getOperatorReturnType(thisKind, otherKind) out.println(" /** $doc */") out.println(" public fun $name(other: ${otherKind.capitalized}): $returnType") @@ -132,15 +123,10 @@ class GeneratePrimitives(out: PrintWriter) : BuiltInsSourceGenerator(out) { } private fun generateRangeTo(thisKind: PrimitiveType) { - if (thisKind == PrimitiveType.CHAR) { + for (otherKind in PrimitiveType.exceptBoolean) { + val returnType = if (otherKind.ordinal() > thisKind.ordinal()) otherKind else thisKind out.println(" /** Creates a range from this value to the specified [other] value. */") - out.println(" public fun rangeTo(other: Char): CharRange") - } else { - for (otherKind in PrimitiveType.exceptBoolean) { - val returnType = if (otherKind.ordinal() > thisKind.ordinal()) otherKind else thisKind - out.println(" /** Creates a range from this value to the specified [other] value. */") - out.println(" public fun rangeTo(other: ${otherKind.capitalized}): ${returnType.capitalized}Range") - } + out.println(" public fun rangeTo(other: ${otherKind.capitalized}): ${returnType.capitalized}Range") } out.println() @@ -173,9 +159,6 @@ class GeneratePrimitives(out: PrintWriter) : BuiltInsSourceGenerator(out) { private fun generateConversions(kind: PrimitiveType) { for (otherKind in PrimitiveType.exceptBoolean) { val name = otherKind.capitalized - if (kind == PrimitiveType.CHAR) { // Char is not a Number and does not inherit Number's javadocs - out.println(" /** Returns the value of this character as a `$name`. */") - } out.println(" public override fun to$name(): $name") } }