Do not generate primitive type definition for Char, place it in a file beside.

This commit is contained in:
Ilya Gorbunov
2015-05-22 17:26:52 +03:00
parent 5f319e69d8
commit c6abf75856
4 changed files with 171 additions and 169 deletions
+163
View File
@@ -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<Char> {
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
}
-145
View File
@@ -176,151 +176,6 @@ 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> {
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`.
@@ -31,7 +31,8 @@ enum class PrimitiveType {
val capitalized: String get() = name().toLowerCase().capitalize()
companion object {
val exceptBoolean: Iterable<PrimitiveType> by Delegates.lazy { PrimitiveType.values().filterNot { it == BOOLEAN } }
val exceptBoolean: List<PrimitiveType> by Delegates.lazy { PrimitiveType.values().filterNot { it == BOOLEAN } }
val onlyNumeric: List<PrimitiveType> by Delegates.lazy { PrimitiveType.values().filterNot { it == BOOLEAN || it == CHAR }}
}
}
@@ -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")
}
}