Examples fixed, some bugs found
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
fun foo() {
|
||||
|
||||
addMouseListener(object MouseAdapter() {
|
||||
|
||||
private var clickCount = 0;
|
||||
@@ -19,5 +21,4 @@ val GOD = object {
|
||||
};
|
||||
|
||||
|
||||
// Groovy like syntax: too many things to assume
|
||||
addMouseListener([mouseClicked : {e => doFoo()}]);
|
||||
}
|
||||
@@ -11,16 +11,16 @@ class BinaryTree<T> : IMutableSet<T> {
|
||||
private var root : TreeNode
|
||||
private var version = 0
|
||||
|
||||
override var size : Int { get; private set; }
|
||||
// override var size : Int { get; private set; }
|
||||
|
||||
this(compare : Comparison<T>) {
|
||||
this.compare = asMatchableComparison(comparison)
|
||||
}
|
||||
|
||||
this() : this(naturalOrder<T>) {
|
||||
this() : this(naturalOrder<T>()) {
|
||||
}
|
||||
|
||||
private extension [operator] fun T.compareTo(other : T) : Int = compare(this, other)
|
||||
private [operator] fun T.compareTo(other : T) : Int = compare(this, other)
|
||||
|
||||
override fun contains(item : T) : Boolean {
|
||||
return contains(root, item)
|
||||
@@ -129,7 +129,7 @@ class BinaryTree<T> : IMutableSet<T> {
|
||||
|
||||
override fun iterator() : IIterator<T> = mutableIterator()
|
||||
|
||||
override fun mutableIterator() : IMutableIterator<T> = new IMutableIterator() {
|
||||
override fun mutableIterator() : IMutableIterator<T> = object IMutableIterator {
|
||||
val version = BinaryTree.this.version
|
||||
val down = Stack<TreeNode>()
|
||||
val up = Stack<TreeNode>()
|
||||
@@ -172,9 +172,9 @@ class BinaryTree<T> : IMutableSet<T> {
|
||||
}
|
||||
}
|
||||
|
||||
override val hasNext : Boolean {
|
||||
override val hasNext : Boolean
|
||||
get() = !down.isEmpty || !up.isEmpty
|
||||
}
|
||||
|
||||
|
||||
override fun remove() {
|
||||
checkVersion()
|
||||
|
||||
@@ -19,11 +19,11 @@ fun mostSignificantBit(x : INumber) = (x and oneBit(x.bits - 1) != 0) as Int
|
||||
|
||||
fun countOnes(x : INumber) = if (x == 0) 0 else mostSignificantBit(x) + countOnes(x shl 1)
|
||||
|
||||
extension fun Int.matchMask(mask : Int) = this and mask == mask
|
||||
fun Int.matchMask(mask : Int) = this and mask == mask
|
||||
|
||||
interface class INumber<T : this> : IComparable<T> {
|
||||
virtual class INumber<T : this> : IComparable<T> {
|
||||
val bits : Int
|
||||
[operator] fun plus(other : T) : T
|
||||
[operator] fun shl(bits : Int) : T
|
||||
...
|
||||
// ...
|
||||
}
|
||||
@@ -22,22 +22,22 @@ class AntBuilder {
|
||||
abstract class ClassPathEntry {}
|
||||
|
||||
class Module : ClassPathEntry {
|
||||
fun classpath(entries : ClassPathEntry...) { ... }
|
||||
fun classpath(entries : ClassPathEntry/*...*/) { /*...*/ }
|
||||
var targetLevel : String
|
||||
fun src(src : String) { ... }
|
||||
fun src(src : String) { /*...*/ }
|
||||
}
|
||||
|
||||
class Library : ClassPathEntry {
|
||||
fun classpath(entries : ClassPathEntry...) { ... }
|
||||
fun classpath(entries : ClassPathEntry/*...*/) { /*...*/ }
|
||||
}
|
||||
|
||||
fun library(initializer : Library.{ () : Library}) {
|
||||
fun library(initializer : { Library.() : Library}) {
|
||||
val lib = new Library()
|
||||
lib.initializer()
|
||||
return lib
|
||||
}
|
||||
|
||||
fun classpath...
|
||||
fun classpath(/*...*/)
|
||||
|
||||
fun module...
|
||||
fun module(/*...*/)
|
||||
}
|
||||
@@ -6,7 +6,7 @@ type f_tuple = {((T, E)) : X}
|
||||
//type f_tuple = {((T, E)) => X}
|
||||
type hof = { (X) : {(T) : Y} }
|
||||
//type hof = { (X) => {(T) => Y} }
|
||||
type hof2 = { {(X) : Y} : {(Y) : Z} }
|
||||
type hof2 = { ({(X) : Y}) : {(Y) : Z} }
|
||||
//type hof2 = { {(X) => Y} => {(Y) => Z} }
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
sealed class Vertex<V>(val data : V)
|
||||
class Vertex<V>(val data : V)
|
||||
|
||||
sealed class Edge<V, E>(val from : V, val data : E, val to : V)
|
||||
class Edge<V, E>(val from : V, val data : E, val to : V)
|
||||
|
||||
class Graph<V, E> {
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
interface class IPushPop<T> {
|
||||
virtual class IPushPop<T> {
|
||||
val isEmpty : Boolean
|
||||
fun push(item : T)
|
||||
fun pop() : T
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
l filter {it.x} map {it.foo} aggregate {a, b => a + b}
|
||||
|
||||
fun foo() {
|
||||
l filter {it.x} map {it.foo} aggregate {(a, b) => a + b}
|
||||
}
|
||||
@@ -16,10 +16,10 @@ class List<T> {
|
||||
|
||||
}
|
||||
|
||||
extension Map<E> for T
|
||||
extension Map<E, T>
|
||||
where
|
||||
T : Iterable<E>,
|
||||
class object T : Buildable<E, T> {
|
||||
class object T : Buildable<E, T> for T {
|
||||
|
||||
fun map<R>(f : {(E) : R}) : T<R> = {
|
||||
val builder = T.newBuilder()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
sealed class Queue<T> : IPushPop<T> {
|
||||
class Queue<T> : IPushPop<T> {
|
||||
private class Item<T>(val data : T, var next : Item<T>)
|
||||
|
||||
private var head : Item<T> = null
|
||||
@@ -26,8 +26,8 @@ sealed class Queue<T> : IPushPop<T> {
|
||||
result
|
||||
}
|
||||
|
||||
override val isEmpty {
|
||||
override val isEmpty
|
||||
get() = head == null
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
sealed class Stack<T> : IPushPop<T> {
|
||||
class Stack<T> : IPushPop<T> {
|
||||
private val data = new ArrayList<T>();
|
||||
|
||||
override fun push(item : T) {
|
||||
@@ -7,7 +7,7 @@ sealed class Stack<T> : IPushPop<T> {
|
||||
|
||||
override fun pop() = data.removeLast()
|
||||
|
||||
override val isEmpty { // TODO: This is UGLY :(
|
||||
override val isEmpty
|
||||
get() = data.isEmpty
|
||||
}
|
||||
|
||||
}
|
||||
@@ -29,6 +29,5 @@ class UnionFind {
|
||||
}
|
||||
}
|
||||
|
||||
extension val Int.isOdd : Boolean {
|
||||
val Int.isOdd : Boolean
|
||||
get() = this % 2 != 0
|
||||
}
|
||||
@@ -2,12 +2,12 @@
|
||||
These declarations are "shallow" in the sense that they are not really compiled, only the type-checker uses them
|
||||
*/
|
||||
|
||||
interface class ReadOnlyArray<out T> : ISized {
|
||||
virtual class ReadOnlyArray<out T> : ISized {
|
||||
[operator] fun get(index : Int) : T
|
||||
}
|
||||
|
||||
interface class WriteOnlyArray<in T> : ISized { // This is needed to keep IIterator's <T> covariant
|
||||
virtual class WriteOnlyArray<in T> : ISized { // This is needed to keep IIterator's <T> covariant
|
||||
[operator] fun set(index : Int, value : T)
|
||||
}
|
||||
|
||||
class MutableArray<T> : ReadOnlyArray<T>, WriteOnlyArray<T> {...}
|
||||
class MutableArray<T> : ReadOnlyArray<T>, WriteOnlyArray<T> {/*...*/}
|
||||
@@ -5,7 +5,7 @@ class ArrayList<T> : IMutableList<T> {
|
||||
|
||||
override fun iterator() : IIterator<T> = mutableIterator()
|
||||
|
||||
override fun mutableIterator() : IMutableIterator<T> = new IMutableIterator() { // T is inferred
|
||||
override fun mutableIterator() : IMutableIterator<T> = object IMutableIterator() { // T is inferred
|
||||
private val index = 0
|
||||
private var myVersion = version
|
||||
|
||||
@@ -21,9 +21,9 @@ class ArrayList<T> : IMutableList<T> {
|
||||
data[index++]
|
||||
}
|
||||
|
||||
override val hasNext {
|
||||
override val hasNext
|
||||
get() = index < used
|
||||
}
|
||||
|
||||
|
||||
override fun remove() {
|
||||
checkVersion()
|
||||
@@ -43,13 +43,13 @@ class ArrayList<T> : IMutableList<T> {
|
||||
throw new IndexOutOfBoundsException(index)
|
||||
}
|
||||
|
||||
override val isEmpty {
|
||||
override val isEmpty
|
||||
get() = used == 0
|
||||
}
|
||||
|
||||
override val size {
|
||||
|
||||
override val size
|
||||
get() = used
|
||||
}
|
||||
|
||||
|
||||
override fun set(index : Int, value : T) {
|
||||
checkIndex(index)
|
||||
|
||||
@@ -4,9 +4,9 @@ virtual class IEquality {
|
||||
}
|
||||
|
||||
virtual class IHashable : IEquality {
|
||||
val hashCode() : Integer {
|
||||
val hashCode : Integer
|
||||
get() = (this as java.lang.Object).hashCode()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
virtual class IMap<K, V> {
|
||||
@@ -16,7 +16,7 @@ virtual class IMap<K, V> {
|
||||
fun containsKey(key : K) : Boolean
|
||||
}
|
||||
|
||||
class HashableWrapper(wraps val obj : Any) : IHashable
|
||||
class HashableWrapper wraps (val obj : Any) : IHashable
|
||||
// equals and hashCode implementations are inherited
|
||||
|
||||
[inline] fun Any.hashable() : HashableWrapper = new HashableWrapper(this)
|
||||
@@ -48,11 +48,11 @@ class HashMap<K, V> : IMap<K, V> {
|
||||
|
||||
class StrategyHashMap<K, V>(hashingStrategy : IHashingStrategy<K>) : IMap<K, V> {
|
||||
|
||||
this() where (K : IHashable) : this(new DefaultHashingStrategy<K>()) {}
|
||||
|
||||
// where !(K : IHashable)
|
||||
// where !(K : IHashable)
|
||||
this() : this(new JavaObjectHashingStrategy<K>()) {}
|
||||
|
||||
this() where (K : IHashable) : this(new DefaultHashingStrategy<K>()) {}
|
||||
//...
|
||||
|
||||
}
|
||||
@@ -40,6 +40,7 @@ public class JetExpressionParsing extends AbstractJetParsing {
|
||||
}
|
||||
},
|
||||
|
||||
// TODO: wrong priority for call: Random.nextInt().isOdd
|
||||
POSTFIX(PLUSPLUS, MINUSMINUS), // typeArguments? valueArguments : arrayAccess
|
||||
|
||||
PREFIX(MINUS, PLUS, MINUSMINUS, PLUSPLUS, EXCL) { // attributes
|
||||
@@ -61,11 +62,13 @@ public class JetExpressionParsing extends AbstractJetParsing {
|
||||
RANGE(JetTokens.RANGE),
|
||||
SIMPLE_NAME(IDENTIFIER),
|
||||
ELVIS(JetTokens.ELVIS),
|
||||
// TODO: RHS (type parameters)
|
||||
NAMED_INFIX_OR_TYPE(IN_KEYWORD, NOT_IN, IS_KEYWORD, NOT_IS, AS_KEYWORD, COLON),
|
||||
COMPARISON(LT, GT, LTEQ, GTEQ),
|
||||
EQUALITY(EQEQ, EXCLEQ, EQEQEQ, EXCLEQEQEQ),
|
||||
CONJUNCTION(ANDAND),
|
||||
DISJUNCTION(OROR),
|
||||
// TODO: RHS
|
||||
MATCH(MATCH_KEYWORD),
|
||||
// TODO: don't build a binary tree, build a tuple
|
||||
ARROW(JetTokens.ARROW),
|
||||
@@ -170,6 +173,7 @@ public class JetExpressionParsing extends AbstractJetParsing {
|
||||
*/
|
||||
private void parsePostfixExpression() {
|
||||
// System.out.println("post at " + tt());
|
||||
// TODO: call with a closure outside parentheses
|
||||
|
||||
PsiBuilder.Marker expression = mark();
|
||||
parseBinaryExpression(Precedence.MEMBER_ACCESS);
|
||||
|
||||
@@ -702,6 +702,7 @@ public class JetParsing extends AbstractJetParsing {
|
||||
*/
|
||||
public JetNodeType parseProperty() {
|
||||
// TODO: var foo : Int { get; private set }
|
||||
// TODO: accessors for local variables
|
||||
|
||||
assert at(VAL_KEYWORD) || at(VAR_KEYWORD);
|
||||
|
||||
@@ -1167,6 +1168,7 @@ public class JetParsing extends AbstractJetParsing {
|
||||
* ;
|
||||
*/
|
||||
public void parseTypeRef() {
|
||||
// TODO: Self type
|
||||
PsiBuilder.Marker type = mark();
|
||||
|
||||
parseAttributeList();
|
||||
@@ -1341,6 +1343,8 @@ public class JetParsing extends AbstractJetParsing {
|
||||
* ;
|
||||
*/
|
||||
public void parseValueParameterList(boolean isFunctionTypeContents, TokenSet recoverySet) {
|
||||
// TODO: val a, b, c : Int
|
||||
|
||||
PsiBuilder.Marker parameters = mark();
|
||||
|
||||
myBuilder.disableEols();
|
||||
|
||||
Reference in New Issue
Block a user