generate also the Char class

This commit is contained in:
Dmitry Jemerov
2015-03-06 21:25:38 +01:00
parent 26e452383e
commit 89398796c6
3 changed files with 86 additions and 95 deletions
-86
View File
@@ -1,86 +0,0 @@
/*
* 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 singe 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<Char> {
public fun compareTo(other: Double): Int
public fun compareTo(other: Float) : Int
public fun compareTo(other: Long) : Int
public fun compareTo(other: Int) : Int
public fun compareTo(other: Short) : Int
public override fun compareTo(other: Char): Int
public fun compareTo(other: Byte) : Int
public fun plus(other: Double): Double
public fun plus(other: Float) : Float
public fun plus(other: Long) : Long
public fun plus(other: Int) : Int
public fun plus(other: Short) : Int
public fun plus(other: Byte) : Int
// public fun plus(other: Char) : Int
public fun minus(other: Double): Double
public fun minus(other: Float) : Float
public fun minus(other: Long) : Long
public fun minus(other: Int) : Int
public fun minus(other: Short) : Int
public fun minus(other: Byte) : Int
public fun minus(other: Char) : Int
public fun times(other: Double): Double
public fun times(other: Float) : Float
public fun times(other: Long) : Long
public fun times(other: Int) : Int
public fun times(other: Short) : Int
public fun times(other: Byte) : Int
// public fun times(other: Char) : Int
public fun div(other: Double): Double
public fun div(other: Float) : Float
public fun div(other: Long) : Long
public fun div(other: Int) : Int
public fun div(other: Short) : Int
public fun div(other: Byte) : Int
// public fun div(other: Char) : Int
public fun mod(other: Double): Double
public fun mod(other: Float) : Float
public fun mod(other: Long) : Long
public fun mod(other: Int) : Int
public fun mod(other: Short) : Int
public fun mod(other: Byte) : Int
// public fun mod(other: Char) : Int
public fun rangeTo(other: Char): CharRange
public fun inc(): Char
public fun dec(): Char
public fun plus(): Int
public fun minus(): Int
public fun toDouble(): Double
public fun toFloat(): Float
public fun toLong(): Long
public fun toInt(): Int
public fun toChar(): Char
public fun toShort(): Short
public fun toByte(): Byte
}
+67
View File
@@ -95,6 +95,73 @@ public class Byte private () : Number, Comparable<Byte> {
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<Char> {
class object {}
public fun compareTo(other: Byte): Int
public override fun compareTo(other: Char): Int
public fun compareTo(other: Short): Int
public fun compareTo(other: Int): Int
public fun compareTo(other: Long): Int
public fun compareTo(other: Float): Int
public fun compareTo(other: Double): Int
public fun plus(other: Byte): Int
public fun plus(other: Short): Int
public fun plus(other: Int): Int
public fun plus(other: Long): Long
public fun plus(other: Float): Float
public fun plus(other: Double): Double
public fun minus(other: Byte): Int
public fun minus(other: Char): Int
public fun minus(other: Short): Int
public fun minus(other: Int): Int
public fun minus(other: Long): Long
public fun minus(other: Float): Float
public fun minus(other: Double): Double
public fun times(other: Byte): Int
public fun times(other: Short): Int
public fun times(other: Int): Int
public fun times(other: Long): Long
public fun times(other: Float): Float
public fun times(other: Double): Double
public fun div(other: Byte): Int
public fun div(other: Short): Int
public fun div(other: Int): Int
public fun div(other: Long): Long
public fun div(other: Float): Float
public fun div(other: Double): Double
public fun mod(other: Byte): Int
public fun mod(other: Short): Int
public fun mod(other: Int): Int
public fun mod(other: Long): Long
public fun mod(other: Float): Float
public fun mod(other: Double): Double
public fun inc(): Char
public fun dec(): Char
public fun plus(): Int
public fun minus(): Int
public fun rangeTo(other: Char): CharRange
public override fun toByte(): Byte
public override fun toChar(): Char
public override fun toShort(): Short
public override fun toInt(): Int
public override fun toLong(): Long
public override fun toFloat(): Float
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`.
@@ -31,16 +31,19 @@ class GenerateNumbers(out: PrintWriter) : BuiltInsSourceGenerator(out) {
PrimitiveType.LONG to "64-bit signed integer",
PrimitiveType.INT to "32-bit signed integer",
PrimitiveType.SHORT to "16-bit signed integer",
PrimitiveType.BYTE to "8-bit signed integer"
PrimitiveType.BYTE to "8-bit signed integer",
PrimitiveType.CHAR to "16-bit Unicode character"
)
override fun generateBody() {
for (kind in PrimitiveType.values()) {
if (kind == PrimitiveType.BOOLEAN || kind == PrimitiveType.CHAR) continue
for (kind in PrimitiveType.exceptBoolean) {
val className = kind.capitalized
generateDoc(kind)
out.println("public class $className private () : Number, Comparable<$className> {")
out.print("public class $className private () : ")
if (kind != PrimitiveType.CHAR) {
out.print("Number, ")
}
out.println("Comparable<$className> {")
out.print(" default object")
if (kind == PrimitiveType.FLOAT || kind == PrimitiveType.DOUBLE) {
@@ -88,6 +91,9 @@ class GenerateNumbers(out: PrintWriter) : BuiltInsSourceGenerator(out) {
private fun generateOperator(name: 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(" public fun $name(other: ${otherKind.capitalized}): $returnType")
}
@@ -95,9 +101,13 @@ class GenerateNumbers(out: PrintWriter) : BuiltInsSourceGenerator(out) {
}
private fun generateRangeTo(thisKind: PrimitiveType) {
for (otherKind in PrimitiveType.exceptBoolean) {
val returnType = if (otherKind.ordinal() > thisKind.ordinal()) otherKind else thisKind
out.println(" public fun rangeTo(other: ${otherKind.capitalized}): ${returnType.capitalized}Range")
if (thisKind == PrimitiveType.CHAR) {
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(" public fun rangeTo(other: ${otherKind.capitalized}): ${returnType.capitalized}Range")
}
}
out.println()
@@ -105,7 +115,7 @@ class GenerateNumbers(out: PrintWriter) : BuiltInsSourceGenerator(out) {
private fun generateUnaryOperators(kind: PrimitiveType) {
for (name in unaryOperators) {
val returnType = if (kind in listOf(PrimitiveType.SHORT, PrimitiveType.BYTE) &&
val returnType = if (kind in listOf(PrimitiveType.SHORT, PrimitiveType.BYTE, PrimitiveType.CHAR) &&
name in listOf("plus", "minus")) "Int" else kind.capitalized
out.println(" public fun $name(): $returnType")
}