Rewrite built-in primitive iterators to Kotlin

This commit is contained in:
Alexander Udalov
2013-12-20 21:03:03 +04:00
parent 0e7ccec9d4
commit f9f1065294
10 changed files with 106 additions and 291 deletions
@@ -0,0 +1,54 @@
/*
* Copyright 2010-2013 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 org.jetbrains.jet.generators.runtime.iterators
import org.jetbrains.jet.generators.runtime.*
import java.io.PrintWriter
enum class IteratorKind {
BYTE
CHAR
SHORT
INT
LONG
FLOAT
DOUBLE
BOOLEAN
val capitalized: String get() = name().toLowerCase().capitalize()
}
class GenerateIterators(val out: PrintWriter) {
fun generate() {
generatedBy(out, javaClass.getName())
for (kind in IteratorKind.values()) {
val s = kind.capitalized
out.println("public abstract class ${s}Iterator : Iterator<$s> {")
out.println(" override final fun next() = next$s()")
out.println()
out.println(" public abstract fun next$s(): $s")
out.println("}")
out.println()
}
}
}
fun main(args: Array<String>) {
generateRuntimeFile("Iterators.kt") {
GenerateIterators(it).generate()
}
}
+52
View File
@@ -0,0 +1,52 @@
// Generated by org.jetbrains.jet.generators.runtime.iterators.GenerateIterators
package jet
public abstract class ByteIterator : Iterator<Byte> {
override final fun next() = nextByte()
public abstract fun nextByte(): Byte
}
public abstract class CharIterator : Iterator<Char> {
override final fun next() = nextChar()
public abstract fun nextChar(): Char
}
public abstract class ShortIterator : Iterator<Short> {
override final fun next() = nextShort()
public abstract fun nextShort(): Short
}
public abstract class IntIterator : Iterator<Int> {
override final fun next() = nextInt()
public abstract fun nextInt(): Int
}
public abstract class LongIterator : Iterator<Long> {
override final fun next() = nextLong()
public abstract fun nextLong(): Long
}
public abstract class FloatIterator : Iterator<Float> {
override final fun next() = nextFloat()
public abstract fun nextFloat(): Float
}
public abstract class DoubleIterator : Iterator<Double> {
override final fun next() = nextDouble()
public abstract fun nextDouble(): Double
}
public abstract class BooleanIterator : Iterator<Boolean> {
override final fun next() = nextBoolean()
public abstract fun nextBoolean(): Boolean
}
-36
View File
@@ -1,36 +0,0 @@
/*
* Copyright 2010-2013 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 jet;
import org.jetbrains.jet.rt.annotation.AssertInvisibleInResolver;
import java.util.Iterator;
@AssertInvisibleInResolver
public abstract class BooleanIterator implements Iterator<Boolean> {
@Override
public final Boolean next() {
return nextBoolean();
}
public abstract boolean nextBoolean();
@Override
public void remove() {
throw new UnsupportedOperationException("Mutating method called on a Kotlin Iterator");
}
}
-36
View File
@@ -1,36 +0,0 @@
/*
* Copyright 2010-2013 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 jet;
import org.jetbrains.jet.rt.annotation.AssertInvisibleInResolver;
import java.util.Iterator;
@AssertInvisibleInResolver
public abstract class ByteIterator implements Iterator<Byte> {
@Override
public final Byte next() {
return nextByte();
}
public abstract byte nextByte();
@Override
public void remove() {
throw new UnsupportedOperationException("Mutating method called on a Kotlin Iterator");
}
}
-36
View File
@@ -1,36 +0,0 @@
/*
* Copyright 2010-2013 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 jet;
import org.jetbrains.jet.rt.annotation.AssertInvisibleInResolver;
import java.util.Iterator;
@AssertInvisibleInResolver
public abstract class CharIterator implements Iterator<Character> {
@Override
public final Character next() {
return nextChar();
}
public abstract char nextChar();
@Override
public void remove() {
throw new UnsupportedOperationException("Mutating method called on a Kotlin Iterator");
}
}
-36
View File
@@ -1,36 +0,0 @@
/*
* Copyright 2010-2013 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 jet;
import org.jetbrains.jet.rt.annotation.AssertInvisibleInResolver;
import java.util.Iterator;
@AssertInvisibleInResolver
public abstract class DoubleIterator implements Iterator<Double> {
@Override
public final Double next() {
return nextDouble();
}
public abstract double nextDouble();
@Override
public void remove() {
throw new UnsupportedOperationException("Mutating method called on a Kotlin Iterator");
}
}
-37
View File
@@ -1,37 +0,0 @@
/*
* Copyright 2010-2013 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 jet;
import org.jetbrains.jet.rt.annotation.AssertInvisibleInResolver;
import java.util.Iterator;
@AssertInvisibleInResolver
public abstract class FloatIterator implements Iterator<Float> {
@Override
public final Float next() {
return nextFloat();
}
public abstract float nextFloat();
@Override
public void remove() {
throw new UnsupportedOperationException("Mutating method called on a Kotlin Iterator");
}
}
-37
View File
@@ -1,37 +0,0 @@
/*
* Copyright 2010-2013 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 jet;
import org.jetbrains.jet.rt.annotation.AssertInvisibleInResolver;
import java.util.Iterator;
@AssertInvisibleInResolver
public abstract class IntIterator implements Iterator<Integer> {
@Override
public final Integer next() {
return nextInt();
}
public abstract int nextInt();
@Override
public void remove() {
throw new UnsupportedOperationException("Mutating method called on a Kotlin Iterator");
}
}
-36
View File
@@ -1,36 +0,0 @@
/*
* Copyright 2010-2013 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 jet;
import org.jetbrains.jet.rt.annotation.AssertInvisibleInResolver;
import java.util.Iterator;
@AssertInvisibleInResolver
public abstract class LongIterator implements Iterator<Long> {
@Override
public final Long next() {
return nextLong();
}
public abstract long nextLong();
@Override
public void remove() {
throw new UnsupportedOperationException("Mutating method called on a Kotlin Iterator");
}
}
-37
View File
@@ -1,37 +0,0 @@
/*
* Copyright 2010-2013 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 jet;
import org.jetbrains.jet.rt.annotation.AssertInvisibleInResolver;
import java.util.Iterator;
@AssertInvisibleInResolver
public abstract class ShortIterator implements Iterator<Short> {
@Override
public final Short next() {
return nextShort();
}
public abstract short nextShort();
@Override
public void remove() {
throw new UnsupportedOperationException("Mutating method called on a Kotlin Iterator");
}
}