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
@@ -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")
}
}