提交 4d4e9cc3 编写于 作者: A Andrey Breslav

Better testing framework, examples added as tests

上级 b8046074
......@@ -6,7 +6,7 @@ class LinkedList<T> : IMutableList<T> {
private var head : Item = null
private var tail : Item = null
override var size get private set;
override var size get private set
override fun add(index : Int, value : T) {
size++
......
......@@ -6,9 +6,11 @@ enum class List<out T>(theSize : Int) : IList<T> {
override val size : Int
get() = theSize
override val isEmpty : Boolean
get() = this == Nil
override fun iterator() = new IIterator() {
private var current = List.this
......
......@@ -28,18 +28,19 @@ class FileInput : IIterator<Byte>, JavaCloseableWrapper {
}
return
}
override val hasNext
get() { // implicitly throws IOException
if (nextUsed && next != -1) {
nextUsed = false
next = stream.read() // throws IOException
}
return next != -1
return next != -1
}
}
class FileOutput throws IOException : IAdder<Byte>, JavaCloseableWrapper {
class FileOutput : IAdder<Byte>, JavaCloseableWrapper {
private val stream : OutputStream
this(file : File) : JavaCloseableWrapper(stream) {
......@@ -53,8 +54,8 @@ class FileOutput throws IOException : IAdder<Byte>, JavaCloseableWrapper {
fun example() { // this does not rethrow, no appropriate parameters given
val f1 : File = ...
val f2 : File = ...
val f1 : File //= ...
val f2 : File //= ...
streamCopy(FileInput(f1), f2) // throws IOException, you must catch or rethrow explicitly
......
......@@ -5,12 +5,12 @@ class BinaryHeap<T> : IPriorityQueue<T> {
this(data : IIterable<T>, compare : Comparison<T> = naturalOrder<T>) {
this.compare = compare
this.data = ArrayList(data)
siftDown(* this.data.size / 2 .. 0)
/*
// siftDown(* this.data.size / 2 .. 0)
for (val i in data.size / 2 .. 0) {
siftDown(i)
}
*/
}
this(compare : Comparison<T>) {
......
class PriorityQueueAsPushPop<T> wraps(wrapped : IPriorityQueue<T>) : IPushPop<T> {
override fun pop() = wrapped.extract()
override fun push(item : T) = wrapped.add(item)
override val isEmpty
override val isEmpty
get() = wrapped.isEmpty
}
\ No newline at end of file
......@@ -5,7 +5,7 @@ fun naturalOrder<in T : IComparable<T>>(a : T, b : T) : Int = a.compareTo(b)
fun castingNaturalOrder(a : Object, b : Object) : Int = (a as Comparable<Object>).compareTo(b as Comparable<Object>)
enum class ComparisonResult {
LS, EQ, GR
LS; EQ; GR
}
type MatchableComparison<in T> = {(T, T) : ComparisonResult}
......
fun foo() {
addMouseListener(object MouseAdapter() {
private var clickCount = 0;
override fun mouseClicked(e : MouseEvent) {
clickCount++;
if (clickCount > 3) GOD.sendMessage(GodMEssages.TOO_MANY_CLICKS);
}
})
enum class GodMessages {
TOO_MANY_CLICKS
ONE_MORE_MESSAGE
}
// Type of this variable is GOD_AnonymousClass
val GOD = object {
fun sendMessage(message : GodMEssage) = throw new RuntimeException(message.name)
};
}
\ No newline at end of file
JetFile: AnonymousObjects.jet
NAMESPACE
FUN
PsiElement(fun)('fun')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('foo')
TYPE_PARAMETER_LIST
<empty list>
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
BLOCK
PsiElement(LBRACE)('{')
PsiWhiteSpace('\n\n')
CALL_EXPRESSION
PsiElement(IDENTIFIER)('addMouseListener')
VALUE_ARGUMENT_LIST
PsiElement(LPAR)('(')
VALUE_ARGUMENT
PsiElement(object)('object')
PsiWhiteSpace(' ')
DELEGATION_SPECIFIER_LIST
DELEGATION_SPECIFIER
DELEGATOR_SUPER_CALL
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('MouseAdapter')
VALUE_ARGUMENT_LIST
PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
CLASS_BODY
PsiElement(LBRACE)('{')
PsiWhiteSpace('\n\n ')
PROPERTY
MODIFIER_LIST
PsiElement(private)('private')
PsiWhiteSpace(' ')
PsiElement(var)('var')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('clickCount')
PsiWhiteSpace(' ')
PsiElement(EQ)('=')
PsiWhiteSpace(' ')
INTEGER_CONSTANT
PsiElement(INTEGER_LITERAL)('0')
PsiElement(SEMICOLON)(';')
PsiWhiteSpace('\n\n ')
FUN
MODIFIER_LIST
PsiElement(override)('override')
PsiWhiteSpace(' ')
PsiElement(fun)('fun')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('mouseClicked')
TYPE_PARAMETER_LIST
<empty list>
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
PsiElement(IDENTIFIER)('e')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('MouseEvent')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
BLOCK
PsiElement(LBRACE)('{')
PsiWhiteSpace('\n ')
POSTFIX_EXPRESSION
PsiElement(IDENTIFIER)('clickCount')
PsiElement(PLUSPLUS)('++')
PsiElement(SEMICOLON)(';')
PsiWhiteSpace('\n ')
IF
PsiElement(if)('if')
PsiWhiteSpace(' ')
PsiElement(LPAR)('(')
CONDITION
BINARY_EXPRESSION
PsiElement(IDENTIFIER)('clickCount')
PsiWhiteSpace(' ')
PsiElement(GT)('>')
PsiWhiteSpace(' ')
INTEGER_CONSTANT
PsiElement(INTEGER_LITERAL)('3')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
THEN
CALL_EXPRESSION
DOT_QIALIFIED_EXPRESSION
PsiElement(IDENTIFIER)('GOD')
PsiElement(DOT)('.')
PsiElement(IDENTIFIER)('sendMessage')
VALUE_ARGUMENT_LIST
PsiElement(LPAR)('(')
VALUE_ARGUMENT
DOT_QIALIFIED_EXPRESSION
PsiElement(IDENTIFIER)('GodMEssages')
PsiElement(DOT)('.')
PsiElement(IDENTIFIER)('TOO_MANY_CLICKS')
PsiElement(RPAR)(')')
PsiElement(SEMICOLON)(';')
PsiWhiteSpace('\n ')
PsiElement(RBRACE)('}')
PsiWhiteSpace('\n')
PsiElement(RBRACE)('}')
PsiElement(RPAR)(')')
PsiWhiteSpace('\n\n')
CLASS
MODIFIER_LIST
PsiElement(enum)('enum')
PsiWhiteSpace(' ')
PsiElement(class)('class')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('GodMessages')
PsiWhiteSpace(' ')
TYPE_PARAMETER_LIST
<empty list>
CLASS_BODY
PsiElement(LBRACE)('{')
PsiWhiteSpace('\n ')
ENUM_ENTRY
PsiElement(IDENTIFIER)('TOO_MANY_CLICKS')
PsiWhiteSpace('\n ')
TYPE_PARAMETER_LIST
<empty list>
ENUM_ENTRY
PsiElement(IDENTIFIER)('ONE_MORE_MESSAGE')
PsiWhiteSpace('\n')
TYPE_PARAMETER_LIST
<empty list>
PsiElement(RBRACE)('}')
PsiWhiteSpace('\n\n')
PsiComment(EOL_COMMENT)('// Type of this variable is GOD_AnonymousClass')
PsiWhiteSpace('\n')
PROPERTY
PsiElement(val)('val')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('GOD')
PsiWhiteSpace(' ')
PsiElement(EQ)('=')
PsiWhiteSpace(' ')
PsiElement(object)('object')
PsiWhiteSpace(' ')
CLASS_BODY
PsiElement(LBRACE)('{')
PsiWhiteSpace('\n ')
FUN
PsiElement(fun)('fun')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('sendMessage')
TYPE_PARAMETER_LIST
<empty list>
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
PsiElement(IDENTIFIER)('message')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('GodMEssage')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(EQ)('=')
PsiWhiteSpace(' ')
THROW
PsiElement(throw)('throw')
PsiWhiteSpace(' ')
NEW
PsiElement(new)('new')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('RuntimeException')
VALUE_ARGUMENT_LIST
PsiElement(LPAR)('(')
VALUE_ARGUMENT
DOT_QIALIFIED_EXPRESSION
PsiElement(IDENTIFIER)('message')
PsiElement(DOT)('.')
PsiElement(IDENTIFIER)('name')
PsiElement(RPAR)(')')
PsiWhiteSpace('\n')
PsiElement(RBRACE)('}')
PsiElement(SEMICOLON)(';')
PsiWhiteSpace('\n\n\n')
PsiElement(RBRACE)('}')
\ No newline at end of file
class BinaryTree<T> : IMutableSet<T> {
private class TreeNode(
var value : T, var parent : TreeNode
) {
var left : TreeNode
var right : TreeNode
}
private val compare : MatchableComparison<T>
private var root : TreeNode
private var version = 0
// override var size : Int { get; private set; }
this(compare : Comparison<T>) {
this.compare = asMatchableComparison(comparison)
}
this() : this(naturalOrder<T>()) {
}
private [operator] fun T.compareTo(other : T) : Int = compare(this, other)
override fun contains(item : T) : Boolean {
return contains(root, item)
fun contains(node : TreeNode, item : T) : Boolean {
if (node == null) return false
compare(item, node.value) match {
case EQ => true
case LS => contains(node.left, item)
case GT => contains(node.right, item)
}
}
}
override fun add(item : T) : Boolean {
if (add(ref root, null)) {
size++
version++
return true
}
return false
// In principle, this has access to item anyway, but then it's unreachable code
// BAD: the naive implementation of ref will create H(T) ref objects, but can be optimized to create only one
fun add(ref node : TreeNode, parent : TreeNode) : Boolean {
if (node == null) {
node = TreeNode(item, parent)
return true
}
compare(item, node.value) match {
case EQ => false
case LS => add(ref node.left, node)
case GT => add(ref node.right, node)
}
}
// In principle, this has access to item anyway
fun addNoRef(node : TreeNode) : Boolean {
if (node == null) {
root = TreeNode(item, null)
return true
}
compare(item, node.value) match {
case EQ => return false
case LS =>
if (node.left == null) {
node.left = TreeNode(item, node)
return true
} else return add(node.left)
case GT =>
if (node.right == null) {
node.right = TreeNode(item, node)
return true
} else return add(node.right)
}
}
}
override fun remove(item : T) : Boolean {
val toRemove = find(root, item)
if (toRemove == null) return false
remove(toRemove)
size--
version++
return true
fun find(node : TreeNode) : TreeNode {
if (node == null) return null
compare(item, node.value) match {
case EQ => node
case LS => find(node.left)
case GT => find(node.right)
}
}
}
private fun remove(node : TreeNode) {
node match {
case TreeNode(null, null) => replace(node, null)
case TreeNode(null, right) => replace(node, right)
case TreeNode(left, null) => replace(node, left)
case TreeNode(left, right) => {
val min = min(node.right)
node.value = min.value
remove(min)
}
}
fun replace(node : TreeNode, replace : TreeNode) {
if (node == root) {
root = replace
return
}
if (node.parent.left == node) {
node.parent.left = replace
} else if (node.parent.right == node) {
node.parent.right = replace
} else Assert(false)
}
}
// Relies on tail-recursion optimization
private fun min(node : TreeNode) {
if (node.left == null) node else min(node.left)
}
override fun iterator() : IIterator<T> = mutableIterator()
override fun mutableIterator() : IMutableIterator<T> = object IMutableIterator {
val version = BinaryTree.this.version
val down = Stack<TreeNode>()
val up = Stack<TreeNode>()
var lastNode : TreeNode
this() {
if (root != null)
down.push(root)
}
override fun next() : T {
if (!hasNext)
throw NoMoreElementsException()
checkVersion()
lastNode = nextNode()
return lastNode.value
}
private fun nextNode() : TreeNode {
while (true) {
if (!down.isEmpty) {
val curNode = down.pop()
if (curNode.left != null) {
up.push(curNode)
down.push(curNode.left)
} else {
if (curNode.right != null) {
down.push(curNode.right)
}
return curNode;
}
} else {
val curNode = up.pop()
if (curNode.right != null) {
down.push(curNode.right)
}
return curNode
}
}
}
override val hasNext : Boolean
get() = !down.isEmpty || !up.isEmpty
override fun remove() {
checkVersion()
if (lastNode == null)
throw IterationException("Nothing to remove")
remove(lastNode)
version++
BinaryTree.this.version = version
}
private fun checkVersion() {
if (version != BinaryTree.this.version) {
throw ConcurrentModificationException()
}
}
}
}
\ No newline at end of file
此差异已折叠。
fun oneBit(index : Int) = 1 shl index
fun setBit(x : Int, index : Int) = x or oneBit(index)
fun unsetBit(x : Int, index : Int) = x and not(oneBit(index))
fun getBit(x : Int, index : Int) = x and oneBit(index) != 0
fun getBit(x : Int, index : Int) = (x shr index) shl 31 != 0
fun countOnes(x : INumber) {
var result = 0
while (x != 0) {
result += x and 1
x = x ushr 1
}
result
}
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)
fun Int.matchMask(mask : Int) = this and mask == mask
virtual class INumber<T : this> : IComparable<T> {
val bits : Int
[operator] fun plus(other : T) : T
[operator] fun shl(bits : Int) : T
// ...
}
\ No newline at end of file
JetFile: BitArith.jet
NAMESPACE
FUN
PsiElement(fun)('fun')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('oneBit')
TYPE_PARAMETER_LIST
<empty list>
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
PsiElement(IDENTIFIER)('index')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('Int')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(EQ)('=')
PsiWhiteSpace(' ')
BINARY_EXPRESSION
INTEGER_CONSTANT
PsiElement(INTEGER_LITERAL)('1')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('shl')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('index')
PsiWhiteSpace('\n\n')
FUN
PsiElement(fun)('fun')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('setBit')
TYPE_PARAMETER_LIST
<empty list>
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
PsiElement(IDENTIFIER)('x')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('Int')
PsiElement(COMMA)(',')
PsiWhiteSpace(' ')
VALUE_PARAMETER
PsiElement(IDENTIFIER)('index')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('Int')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(EQ)('=')
PsiWhiteSpace(' ')
BINARY_EXPRESSION
PsiElement(IDENTIFIER)('x')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('or')
PsiWhiteSpace(' ')
CALL_EXPRESSION
PsiElement(IDENTIFIER)('oneBit')
VALUE_ARGUMENT_LIST
PsiElement(LPAR)('(')
VALUE_ARGUMENT
PsiElement(IDENTIFIER)('index')
PsiElement(RPAR)(')')
PsiWhiteSpace('\n')
FUN
PsiElement(fun)('fun')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('unsetBit')
TYPE_PARAMETER_LIST
<empty list>
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
PsiElement(IDENTIFIER)('x')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('Int')
PsiElement(COMMA)(',')
PsiWhiteSpace(' ')
VALUE_PARAMETER
PsiElement(IDENTIFIER)('index')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('Int')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(EQ)('=')
PsiWhiteSpace(' ')
BINARY_EXPRESSION
PsiElement(IDENTIFIER)('x')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('and')
PsiWhiteSpace(' ')
CALL_EXPRESSION
PsiElement(IDENTIFIER)('not')
VALUE_ARGUMENT_LIST
PsiElement(LPAR)('(')
VALUE_ARGUMENT
CALL_EXPRESSION
PsiElement(IDENTIFIER)('oneBit')
VALUE_ARGUMENT_LIST
PsiElement(LPAR)('(')
VALUE_ARGUMENT
PsiElement(IDENTIFIER)('index')
PsiElement(RPAR)(')')
PsiElement(RPAR)(')')
PsiWhiteSpace('\n\n')
FUN
PsiElement(fun)('fun')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('getBit')
TYPE_PARAMETER_LIST
<empty list>
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
PsiElement(IDENTIFIER)('x')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('Int')
PsiElement(COMMA)(',')
PsiWhiteSpace(' ')
VALUE_PARAMETER
PsiElement(IDENTIFIER)('index')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('Int')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(EQ)('=')
PsiWhiteSpace(' ')
BINARY_EXPRESSION
BINARY_EXPRESSION
PsiElement(IDENTIFIER)('x')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('and')
PsiWhiteSpace(' ')
CALL_EXPRESSION
PsiElement(IDENTIFIER)('oneBit')
VALUE_ARGUMENT_LIST
PsiElement(LPAR)('(')
VALUE_ARGUMENT
PsiElement(IDENTIFIER)('index')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(EXCLEQ)('!=')
PsiWhiteSpace(' ')
INTEGER_CONSTANT
PsiElement(INTEGER_LITERAL)('0')
PsiWhiteSpace('\n')
FUN
PsiElement(fun)('fun')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('getBit')
TYPE_PARAMETER_LIST
<empty list>
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
PsiElement(IDENTIFIER)('x')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('Int')
PsiElement(COMMA)(',')
PsiWhiteSpace(' ')
VALUE_PARAMETER
PsiElement(IDENTIFIER)('index')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('Int')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(EQ)('=')
PsiWhiteSpace(' ')
BINARY_EXPRESSION
BINARY_EXPRESSION
TUPLE
PsiElement(LPAR)('(')
BINARY_EXPRESSION
PsiElement(IDENTIFIER)('x')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('shr')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('index')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('shl')
PsiWhiteSpace(' ')
INTEGER_CONSTANT
PsiElement(INTEGER_LITERAL)('31')
PsiWhiteSpace(' ')
PsiElement(EXCLEQ)('!=')
PsiWhiteSpace(' ')
INTEGER_CONSTANT
PsiElement(INTEGER_LITERAL)('0')
PsiWhiteSpace('\n\n')
FUN
PsiElement(fun)('fun')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('countOnes')
TYPE_PARAMETER_LIST
<empty list>
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
PsiElement(IDENTIFIER)('x')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('INumber')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
BLOCK
PsiElement(LBRACE)('{')
PsiWhiteSpace('\n ')
PROPERTY
PsiElement(var)('var')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('result')
PsiWhiteSpace(' ')
PsiElement(EQ)('=')
PsiWhiteSpace(' ')
INTEGER_CONSTANT
PsiElement(INTEGER_LITERAL)('0')
PsiWhiteSpace('\n ')
WHILE
PsiElement(while)('while')
PsiWhiteSpace(' ')
PsiElement(LPAR)('(')
CONDITION
BINARY_EXPRESSION
PsiElement(IDENTIFIER)('x')
PsiWhiteSpace(' ')
PsiElement(EXCLEQ)('!=')
PsiWhiteSpace(' ')
INTEGER_CONSTANT
PsiElement(INTEGER_LITERAL)('0')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
BODY
FUNCTION_LITERAL
PsiElement(LBRACE)('{')
PsiWhiteSpace('\n ')
BODY
BINARY_EXPRESSION
PsiElement(IDENTIFIER)('result')
PsiWhiteSpace(' ')
PsiElement(PLUSEQ)('+=')
PsiWhiteSpace(' ')
BINARY_EXPRESSION
PsiElement(IDENTIFIER)('x')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('and')
PsiWhiteSpace(' ')
INTEGER_CONSTANT
PsiElement(INTEGER_LITERAL)('1')
PsiWhiteSpace('\n ')
BINARY_EXPRESSION
PsiElement(IDENTIFIER)('x')
PsiWhiteSpace(' ')
PsiElement(EQ)('=')
PsiWhiteSpace(' ')
BINARY_EXPRESSION
PsiElement(IDENTIFIER)('x')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('ushr')
PsiWhiteSpace(' ')
INTEGER_CONSTANT
PsiElement(INTEGER_LITERAL)('1')
PsiWhiteSpace('\n ')
PsiElement(RBRACE)('}')
PsiWhiteSpace('\n ')
PsiElement(IDENTIFIER)('result')
PsiWhiteSpace('\n')
PsiElement(RBRACE)('}')
PsiWhiteSpace('\n\n')
FUN
PsiElement(fun)('fun')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('mostSignificantBit')
TYPE_PARAMETER_LIST
<empty list>
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
PsiElement(IDENTIFIER)('x')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('INumber')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(EQ)('=')
PsiWhiteSpace(' ')
BINARY_EXPRESSION
TUPLE
PsiElement(LPAR)('(')
BINARY_EXPRESSION
BINARY_EXPRESSION
PsiElement(IDENTIFIER)('x')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('and')
PsiWhiteSpace(' ')
CALL_EXPRESSION
PsiElement(IDENTIFIER)('oneBit')
VALUE_ARGUMENT_LIST
PsiElement(LPAR)('(')
VALUE_ARGUMENT
BINARY_EXPRESSION
DOT_QIALIFIED_EXPRESSION
PsiElement(IDENTIFIER)('x')
PsiElement(DOT)('.')
PsiElement(IDENTIFIER)('bits')
PsiWhiteSpace(' ')
PsiElement(MINUS)('-')
PsiWhiteSpace(' ')
INTEGER_CONSTANT
PsiElement(INTEGER_LITERAL)('1')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(EXCLEQ)('!=')
PsiWhiteSpace(' ')
INTEGER_CONSTANT
PsiElement(INTEGER_LITERAL)('0')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(as)('as')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('Int')
PsiWhiteSpace('\n\n')
FUN
PsiElement(fun)('fun')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('countOnes')
TYPE_PARAMETER_LIST
<empty list>
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
PsiElement(IDENTIFIER)('x')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('INumber')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(EQ)('=')
PsiWhiteSpace(' ')
IF
PsiElement(if)('if')
PsiWhiteSpace(' ')
PsiElement(LPAR)('(')
CONDITION
BINARY_EXPRESSION
PsiElement(IDENTIFIER)('x')
PsiWhiteSpace(' ')
PsiElement(EQEQ)('==')
PsiWhiteSpace(' ')
INTEGER_CONSTANT
PsiElement(INTEGER_LITERAL)('0')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
THEN
INTEGER_CONSTANT
PsiElement(INTEGER_LITERAL)('0')
PsiWhiteSpace(' ')
PsiElement(else)('else')
PsiWhiteSpace(' ')
ELSE
BINARY_EXPRESSION
CALL_EXPRESSION
PsiElement(IDENTIFIER)('mostSignificantBit')
VALUE_ARGUMENT_LIST
PsiElement(LPAR)('(')
VALUE_ARGUMENT
PsiElement(IDENTIFIER)('x')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(PLUS)('+')
PsiWhiteSpace(' ')
CALL_EXPRESSION
PsiElement(IDENTIFIER)('countOnes')
VALUE_ARGUMENT_LIST
PsiElement(LPAR)('(')
VALUE_ARGUMENT
BINARY_EXPRESSION
PsiElement(IDENTIFIER)('x')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('shl')
PsiWhiteSpace(' ')
INTEGER_CONSTANT
PsiElement(INTEGER_LITERAL)('1')
PsiElement(RPAR)(')')
PsiWhiteSpace('\n\n')
FUN
PsiElement(fun)('fun')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('Int')
PsiElement(DOT)('.')
PsiElement(IDENTIFIER)('matchMask')
TYPE_PARAMETER_LIST
<empty list>
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
PsiElement(IDENTIFIER)('mask')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('Int')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(EQ)('=')
PsiWhiteSpace(' ')
BINARY_EXPRESSION
BINARY_EXPRESSION
PsiElement(this)('this')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('and')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('mask')
PsiWhiteSpace(' ')
PsiElement(EQEQ)('==')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('mask')
PsiWhiteSpace('\n\n')
CLASS
MODIFIER_LIST
PsiElement(virtual)('virtual')
PsiWhiteSpace(' ')
PsiElement(class)('class')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('INumber')
TYPE_PARAMETER_LIST
PsiElement(LT)('<')
TYPE_PARAMETER
PsiElement(IDENTIFIER)('T')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
PsiErrorElement:Type expected
PsiElement(this)('this')
PsiElement(GT)('>')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
DELEGATION_SPECIFIER_LIST
DELEGATION_SPECIFIER
DELEGATOR_SUPER_CLASS
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('IComparable')
TYPE_ARGUMENT_LIST
PsiElement(LT)('<')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('T')
PsiElement(GT)('>')
PsiWhiteSpace(' ')
CLASS_BODY
PsiElement(LBRACE)('{')
PsiWhiteSpace('\n ')
PROPERTY
PsiElement(val)('val')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('bits')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('Int')
PsiWhiteSpace('\n ')
FUN
MODIFIER_LIST
ATTRIBUTE_ANNOTATION
PsiElement(LBRACKET)('[')
ATTRIBUTE
USER_TYPE
PsiElement(IDENTIFIER)('operator')
PsiElement(RBRACKET)(']')
PsiWhiteSpace(' ')
PsiElement(fun)('fun')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('plus')
TYPE_PARAMETER_LIST
<empty list>
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
PsiElement(IDENTIFIER)('other')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('T')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('T')
PsiWhiteSpace('\n ')
FUN
MODIFIER_LIST
ATTRIBUTE_ANNOTATION
PsiElement(LBRACKET)('[')
ATTRIBUTE
USER_TYPE
PsiElement(IDENTIFIER)('operator')
PsiElement(RBRACKET)(']')
PsiWhiteSpace(' ')
PsiElement(fun)('fun')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('shl')
TYPE_PARAMETER_LIST
<empty list>
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
PsiElement(IDENTIFIER)('bits')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('Int')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('T')
PsiWhiteSpace('\n ')
PsiComment(EOL_COMMENT)('// ...')
PsiWhiteSpace('\n')
PsiElement(RBRACE)('}')
\ No newline at end of file
val foo = object AntBuilder() {
lazy val groovy = library {
classpath("$libs/groovy-...")
}
lazy val gant = library {
new File("$gantHome/lib").files.each {
classpath(it)
}
}
lazy val JPS = module {
targetLevel = "1.5"
classpath(antLayout, gant, groovy)
src("$projectHome/antLayout/src")
}
}.build()
class AntBuilder {
abstract class ClassPathEntry {}
class Module : ClassPathEntry {
fun classpath(entries : ClassPathEntry/*...*/) { /*...*/ }
var targetLevel : String
fun src(src : String) { /*...*/ }
}
class Library : ClassPathEntry {
fun classpath(entries : ClassPathEntry/*...*/) { /*...*/ }
}
fun library(initializer : { Library.() : Library}) {
val lib = new Library()
lib.initializer()
return lib
}
fun classpath(/*...*/)
fun module(/*...*/)
}
\ No newline at end of file
JetFile: Builder.jet
NAMESPACE
PROPERTY
PsiElement(val)('val')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('foo')
PsiWhiteSpace(' ')
PsiElement(EQ)('=')
PsiWhiteSpace(' ')
CALL_EXPRESSION
DOT_QIALIFIED_EXPRESSION
PsiElement(object)('object')
PsiWhiteSpace(' ')
DELEGATION_SPECIFIER_LIST
DELEGATION_SPECIFIER
DELEGATOR_SUPER_CALL
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('AntBuilder')
VALUE_ARGUMENT_LIST
PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
CLASS_BODY
PsiElement(LBRACE)('{')
PsiWhiteSpace('\n\n ')
PROPERTY
MODIFIER_LIST
PsiElement(lazy)('lazy')
PsiWhiteSpace(' ')
PsiElement(val)('val')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('groovy')
PsiWhiteSpace(' ')
PsiElement(EQ)('=')
PsiWhiteSpace(' ')
CALL_EXPRESSION
PsiElement(IDENTIFIER)('library')
PsiWhiteSpace(' ')
FUNCTION_LITERAL
PsiElement(LBRACE)('{')
PsiWhiteSpace('\n ')
BODY
CALL_EXPRESSION
PsiElement(IDENTIFIER)('classpath')
VALUE_ARGUMENT_LIST
PsiElement(LPAR)('(')
VALUE_ARGUMENT
STRING_CONSTANT
PsiElement(STRING_LITERAL)('"$libs/groovy-..."')
PsiElement(RPAR)(')')
PsiWhiteSpace('\n ')
PsiElement(RBRACE)('}')
PsiWhiteSpace('\n\n ')
PROPERTY
MODIFIER_LIST
PsiElement(lazy)('lazy')
PsiWhiteSpace(' ')
PsiElement(val)('val')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('gant')
PsiWhiteSpace(' ')
PsiElement(EQ)('=')
PsiWhiteSpace(' ')
CALL_EXPRESSION
PsiElement(IDENTIFIER)('library')
PsiWhiteSpace(' ')
FUNCTION_LITERAL
PsiElement(LBRACE)('{')
PsiWhiteSpace('\n ')
BODY
CALL_EXPRESSION
DOT_QIALIFIED_EXPRESSION
DOT_QIALIFIED_EXPRESSION
NEW
PsiElement(new)('new')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('File')
VALUE_ARGUMENT_LIST
PsiElement(LPAR)('(')
VALUE_ARGUMENT
STRING_CONSTANT
PsiElement(STRING_LITERAL)('"$gantHome/lib"')
PsiElement(RPAR)(')')
PsiElement(DOT)('.')
PsiElement(IDENTIFIER)('files')
PsiElement(DOT)('.')
PsiElement(IDENTIFIER)('each')
PsiWhiteSpace(' ')
FUNCTION_LITERAL
PsiElement(LBRACE)('{')
PsiWhiteSpace('\n ')
BODY
CALL_EXPRESSION
PsiElement(IDENTIFIER)('classpath')
VALUE_ARGUMENT_LIST
PsiElement(LPAR)('(')
VALUE_ARGUMENT
PsiElement(IDENTIFIER)('it')
PsiElement(RPAR)(')')
PsiWhiteSpace('\n ')
PsiElement(RBRACE)('}')
PsiWhiteSpace('\n ')
PsiElement(RBRACE)('}')
PsiWhiteSpace('\n\n ')
PROPERTY
MODIFIER_LIST
PsiElement(lazy)('lazy')
PsiWhiteSpace(' ')
PsiElement(val)('val')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('JPS')
PsiWhiteSpace(' ')
PsiElement(EQ)('=')
PsiWhiteSpace(' ')
CALL_EXPRESSION
PsiElement(IDENTIFIER)('module')
PsiWhiteSpace(' ')
FUNCTION_LITERAL
PsiElement(LBRACE)('{')
PsiWhiteSpace('\n ')
BODY
BINARY_EXPRESSION
PsiElement(IDENTIFIER)('targetLevel')
PsiWhiteSpace(' ')
PsiElement(EQ)('=')
PsiWhiteSpace(' ')
STRING_CONSTANT
PsiElement(STRING_LITERAL)('"1.5"')
PsiWhiteSpace('\n ')
CALL_EXPRESSION
PsiElement(IDENTIFIER)('classpath')
VALUE_ARGUMENT_LIST
PsiElement(LPAR)('(')
VALUE_ARGUMENT
PsiElement(IDENTIFIER)('antLayout')
PsiElement(COMMA)(',')
PsiWhiteSpace(' ')
VALUE_ARGUMENT
PsiElement(IDENTIFIER)('gant')
PsiElement(COMMA)(',')
PsiWhiteSpace(' ')
VALUE_ARGUMENT
PsiElement(IDENTIFIER)('groovy')
PsiElement(RPAR)(')')
PsiWhiteSpace('\n ')
CALL_EXPRESSION
PsiElement(IDENTIFIER)('src')
VALUE_ARGUMENT_LIST
PsiElement(LPAR)('(')
VALUE_ARGUMENT
STRING_CONSTANT
PsiElement(STRING_LITERAL)('"$projectHome/antLayout/src"')
PsiElement(RPAR)(')')
PsiWhiteSpace('\n ')
PsiElement(RBRACE)('}')
PsiWhiteSpace('\n\n')
PsiElement(RBRACE)('}')
PsiElement(DOT)('.')
PsiElement(IDENTIFIER)('build')
VALUE_ARGUMENT_LIST
PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
PsiWhiteSpace('\n\n')
CLASS
PsiElement(class)('class')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('AntBuilder')
PsiWhiteSpace(' ')
TYPE_PARAMETER_LIST
<empty list>
CLASS_BODY
PsiElement(LBRACE)('{')
PsiWhiteSpace('\n ')
CLASS
MODIFIER_LIST
PsiElement(abstract)('abstract')
PsiWhiteSpace(' ')
PsiElement(class)('class')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('ClassPathEntry')
PsiWhiteSpace(' ')
TYPE_PARAMETER_LIST
<empty list>
CLASS_BODY
PsiElement(LBRACE)('{')
PsiElement(RBRACE)('}')
PsiWhiteSpace('\n\n ')
CLASS
PsiElement(class)('class')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('Module')
PsiWhiteSpace(' ')
TYPE_PARAMETER_LIST
<empty list>
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
DELEGATION_SPECIFIER_LIST
DELEGATION_SPECIFIER
DELEGATOR_SUPER_CLASS
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('ClassPathEntry')
PsiWhiteSpace(' ')
CLASS_BODY
PsiElement(LBRACE)('{')
PsiWhiteSpace('\n ')
FUN
PsiElement(fun)('fun')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('classpath')
TYPE_PARAMETER_LIST
<empty list>
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
PsiElement(IDENTIFIER)('entries')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('ClassPathEntry')
PsiComment(BLOCK_COMMENT)('/*...*/')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
BLOCK
PsiElement(LBRACE)('{')
PsiWhiteSpace(' ')
PsiComment(BLOCK_COMMENT)('/*...*/')
PsiWhiteSpace(' ')
PsiElement(RBRACE)('}')
PsiWhiteSpace('\n ')
PROPERTY
PsiElement(var)('var')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('targetLevel')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('String')
PsiWhiteSpace('\n ')
FUN
PsiElement(fun)('fun')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('src')
TYPE_PARAMETER_LIST
<empty list>
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
PsiElement(IDENTIFIER)('src')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('String')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
BLOCK
PsiElement(LBRACE)('{')
PsiWhiteSpace(' ')
PsiComment(BLOCK_COMMENT)('/*...*/')
PsiWhiteSpace(' ')
PsiElement(RBRACE)('}')
PsiWhiteSpace('\n ')
PsiElement(RBRACE)('}')
PsiWhiteSpace('\n\n ')
CLASS
PsiElement(class)('class')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('Library')
PsiWhiteSpace(' ')
TYPE_PARAMETER_LIST
<empty list>
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
DELEGATION_SPECIFIER_LIST
DELEGATION_SPECIFIER
DELEGATOR_SUPER_CLASS
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('ClassPathEntry')
PsiWhiteSpace(' ')
CLASS_BODY
PsiElement(LBRACE)('{')
PsiWhiteSpace('\n ')
FUN
PsiElement(fun)('fun')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('classpath')
TYPE_PARAMETER_LIST
<empty list>
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
PsiElement(IDENTIFIER)('entries')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('ClassPathEntry')
PsiComment(BLOCK_COMMENT)('/*...*/')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
BLOCK
PsiElement(LBRACE)('{')
PsiWhiteSpace(' ')
PsiComment(BLOCK_COMMENT)('/*...*/')
PsiWhiteSpace(' ')
PsiElement(RBRACE)('}')
PsiWhiteSpace('\n ')
PsiElement(RBRACE)('}')
PsiWhiteSpace('\n\n ')
FUN
PsiElement(fun)('fun')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('library')
TYPE_PARAMETER_LIST
<empty list>
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
PsiElement(IDENTIFIER)('initializer')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
FUNCTION_TYPE
PsiElement(LBRACE)('{')
PsiWhiteSpace(' ')
RECEIVER_TYPE
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('Library')
PsiElement(DOT)('.')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('Library')
PsiElement(RBRACE)('}')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
BLOCK
PsiElement(LBRACE)('{')
PsiWhiteSpace('\n ')
PROPERTY
PsiElement(val)('val')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('lib')
PsiWhiteSpace(' ')
PsiElement(EQ)('=')
PsiWhiteSpace(' ')
NEW
PsiElement(new)('new')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('Library')
VALUE_ARGUMENT_LIST
PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
PsiWhiteSpace('\n ')
CALL_EXPRESSION
DOT_QIALIFIED_EXPRESSION
PsiElement(IDENTIFIER)('lib')
PsiElement(DOT)('.')
PsiElement(IDENTIFIER)('initializer')
VALUE_ARGUMENT_LIST
PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
PsiWhiteSpace('\n ')
RETURN
PsiElement(return)('return')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('lib')
PsiWhiteSpace('\n ')
PsiElement(RBRACE)('}')
PsiWhiteSpace('\n\n ')
FUN
PsiElement(fun)('fun')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('classpath')
TYPE_PARAMETER_LIST
<empty list>
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
PsiComment(BLOCK_COMMENT)('/*...*/')
PsiElement(RPAR)(')')
PsiWhiteSpace('\n\n ')
FUN
PsiElement(fun)('fun')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('module')
TYPE_PARAMETER_LIST
<empty list>
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
PsiComment(BLOCK_COMMENT)('/*...*/')
PsiElement(RPAR)(')')
PsiWhiteSpace('\n')
PsiElement(RBRACE)('}')
\ No newline at end of file
enum class Color(val r : Int, val g : Int, val sb : Int) {
RED : Color(255, 0, 0)
GREEN : Color(0, 255, 0)
BLUE : Color(0, 0, 255)
}
\ No newline at end of file
JetFile: Color.jet
NAMESPACE
CLASS
MODIFIER_LIST
PsiElement(enum)('enum')
PsiWhiteSpace(' ')
PsiElement(class)('class')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('Color')
TYPE_PARAMETER_LIST
<empty list>
PRIMARY_CONSTRUCTOR_PARAMETERS_LIST
PsiElement(LPAR)('(')
PRIMARY_CONSTRUCTOR_PARAMETER
PsiElement(val)('val')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('r')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('Int')
PsiElement(COMMA)(',')
PsiWhiteSpace(' ')
PRIMARY_CONSTRUCTOR_PARAMETER
PsiElement(val)('val')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('g')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('Int')
PsiElement(COMMA)(',')
PsiWhiteSpace(' ')
PRIMARY_CONSTRUCTOR_PARAMETER
PsiElement(val)('val')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('sb')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('Int')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
CLASS_BODY
PsiElement(LBRACE)('{')
PsiWhiteSpace('\n ')
ENUM_ENTRY
PsiElement(IDENTIFIER)('RED')
PsiWhiteSpace(' ')
TYPE_PARAMETER_LIST
<empty list>
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
INITIALIZER_LIST
DELEGATOR_SUPER_CALL
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('Color')
VALUE_ARGUMENT_LIST
PsiElement(LPAR)('(')
VALUE_ARGUMENT
INTEGER_CONSTANT
PsiElement(INTEGER_LITERAL)('255')
PsiElement(COMMA)(',')
PsiWhiteSpace(' ')
VALUE_ARGUMENT
INTEGER_CONSTANT
PsiElement(INTEGER_LITERAL)('0')
PsiElement(COMMA)(',')
PsiWhiteSpace(' ')
VALUE_ARGUMENT
INTEGER_CONSTANT
PsiElement(INTEGER_LITERAL)('0')
PsiElement(RPAR)(')')
PsiWhiteSpace('\n ')
ENUM_ENTRY
PsiElement(IDENTIFIER)('GREEN')
PsiWhiteSpace(' ')
TYPE_PARAMETER_LIST
<empty list>
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
INITIALIZER_LIST
DELEGATOR_SUPER_CALL
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('Color')
VALUE_ARGUMENT_LIST
PsiElement(LPAR)('(')
VALUE_ARGUMENT
INTEGER_CONSTANT
PsiElement(INTEGER_LITERAL)('0')
PsiElement(COMMA)(',')
PsiWhiteSpace(' ')
VALUE_ARGUMENT
INTEGER_CONSTANT
PsiElement(INTEGER_LITERAL)('255')
PsiElement(COMMA)(',')
PsiWhiteSpace(' ')
VALUE_ARGUMENT
INTEGER_CONSTANT
PsiElement(INTEGER_LITERAL)('0')
PsiElement(RPAR)(')')
PsiWhiteSpace('\n ')
ENUM_ENTRY
PsiElement(IDENTIFIER)('BLUE')
PsiWhiteSpace(' ')
TYPE_PARAMETER_LIST
<empty list>
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
INITIALIZER_LIST
DELEGATOR_SUPER_CALL
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('Color')
VALUE_ARGUMENT_LIST
PsiElement(LPAR)('(')
VALUE_ARGUMENT
INTEGER_CONSTANT
PsiElement(INTEGER_LITERAL)('0')
PsiElement(COMMA)(',')
PsiWhiteSpace(' ')
VALUE_ARGUMENT
INTEGER_CONSTANT
PsiElement(INTEGER_LITERAL)('0')
PsiElement(COMMA)(',')
PsiWhiteSpace(' ')
VALUE_ARGUMENT
INTEGER_CONSTANT
PsiElement(INTEGER_LITERAL)('255')
PsiElement(RPAR)(')')
PsiWhiteSpace('\n')
PsiElement(RBRACE)('}')
\ No newline at end of file
type f1 = {(T) : X}
// type f1 = {(T) => X}
type f2 = {(T, E) : X}
// type f2 = {(T, E) => X}
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 Comparison<in T> = {(a : T, b : T) : Int}
//type Comparison<in T> = {(a : T, b : T) => Int}
type Equality<in T> = {(a : T, b : T) : Boolean}
//type Equality<in T> = {(a : T, b : T) => Boolean}
type HashFunction<in T> = {(obj : T) : Int}
//type HashFunction<in T> = {(obj : T) => Int}
type Runnable = {() : ()}
//type Runnable = {() => ()}
type Function1<in T, out R> = {(input : T) : R}
//type Function1<in T, out R> = {(input : T) => R}
val f1 = {(t : T) : X => something(t)}
fun f1(t : T) : X = something(t)
val f1 = {(t : T) => something(t)}
val f1 = {(T) : X => something(it)}
val f1 = {t => something(t)}
val f1 = {something(it)}
val f1 : {(T) : X} = {X()}
JetFile: FunctionsAndTypes.jet
NAMESPACE
TYPEDEF
PsiElement(type)('type')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('f1')
PsiWhiteSpace(' ')
TYPE_PARAMETER_LIST
<empty list>
PsiElement(EQ)('=')
PsiWhiteSpace(' ')
TYPE_REFERENCE
FUNCTION_TYPE
PsiElement(LBRACE)('{')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('T')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('X')
PsiElement(RBRACE)('}')
PsiWhiteSpace('\n')
PsiComment(EOL_COMMENT)('// type f1 = {(T) => X}')
PsiWhiteSpace('\n')
TYPEDEF
PsiElement(type)('type')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('f2')
PsiWhiteSpace(' ')
TYPE_PARAMETER_LIST
<empty list>
PsiElement(EQ)('=')
PsiWhiteSpace(' ')
TYPE_REFERENCE
FUNCTION_TYPE
PsiElement(LBRACE)('{')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('T')
PsiElement(COMMA)(',')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('E')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('X')
PsiElement(RBRACE)('}')
PsiWhiteSpace('\n')
PsiComment(EOL_COMMENT)('// type f2 = {(T, E) => X}')
PsiWhiteSpace('\n')
TYPEDEF
PsiElement(type)('type')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('f_tuple')
PsiWhiteSpace(' ')
TYPE_PARAMETER_LIST
<empty list>
PsiElement(EQ)('=')
PsiWhiteSpace(' ')
TYPE_REFERENCE
FUNCTION_TYPE
PsiElement(LBRACE)('{')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
TYPE_REFERENCE
TUPLE_TYPE
PsiElement(LPAR)('(')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('T')
PsiElement(COMMA)(',')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('E')
PsiElement(RPAR)(')')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('X')
PsiElement(RBRACE)('}')
PsiWhiteSpace('\n')
PsiComment(EOL_COMMENT)('//type f_tuple = {((T, E)) => X}')
PsiWhiteSpace('\n')
TYPEDEF
PsiElement(type)('type')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('hof')
PsiWhiteSpace(' ')
TYPE_PARAMETER_LIST
<empty list>
PsiElement(EQ)('=')
PsiWhiteSpace(' ')
TYPE_REFERENCE
FUNCTION_TYPE
PsiElement(LBRACE)('{')
PsiWhiteSpace(' ')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('X')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
FUNCTION_TYPE
PsiElement(LBRACE)('{')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('T')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('Y')
PsiElement(RBRACE)('}')
PsiWhiteSpace(' ')
PsiElement(RBRACE)('}')
PsiWhiteSpace('\n')
PsiComment(EOL_COMMENT)('//type hof = { (X) => {(T) => Y} }')
PsiWhiteSpace('\n')
TYPEDEF
PsiElement(type)('type')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('hof2')
PsiWhiteSpace(' ')
TYPE_PARAMETER_LIST
<empty list>
PsiElement(EQ)('=')
PsiWhiteSpace(' ')
TYPE_REFERENCE
FUNCTION_TYPE
PsiElement(LBRACE)('{')
PsiWhiteSpace(' ')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
TYPE_REFERENCE
FUNCTION_TYPE
PsiElement(LBRACE)('{')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('X')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('Y')
PsiElement(RBRACE)('}')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
FUNCTION_TYPE
PsiElement(LBRACE)('{')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('Y')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('Z')
PsiElement(RBRACE)('}')
PsiWhiteSpace(' ')
PsiElement(RBRACE)('}')
PsiWhiteSpace('\n')
PsiComment(EOL_COMMENT)('//type hof2 = { {(X) => Y} => {(Y) => Z} }')
PsiWhiteSpace('\n\n\n')
TYPEDEF
PsiElement(type)('type')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('Comparison')
TYPE_PARAMETER_LIST
PsiElement(LT)('<')
TYPE_PARAMETER
MODIFIER_LIST
PsiElement(in)('in')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('T')
PsiElement(GT)('>')
PsiWhiteSpace(' ')
PsiElement(EQ)('=')
PsiWhiteSpace(' ')
TYPE_REFERENCE
FUNCTION_TYPE
PsiElement(LBRACE)('{')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
PsiElement(IDENTIFIER)('a')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('T')
PsiElement(COMMA)(',')
PsiWhiteSpace(' ')
VALUE_PARAMETER
PsiElement(IDENTIFIER)('b')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('T')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('Int')
PsiElement(RBRACE)('}')
PsiWhiteSpace('\n')
PsiComment(EOL_COMMENT)('//type Comparison<in T> = {(a : T, b : T) => Int}')
PsiWhiteSpace('\n')
TYPEDEF
PsiElement(type)('type')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('Equality')
TYPE_PARAMETER_LIST
PsiElement(LT)('<')
TYPE_PARAMETER
MODIFIER_LIST
PsiElement(in)('in')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('T')
PsiElement(GT)('>')
PsiWhiteSpace(' ')
PsiElement(EQ)('=')
PsiWhiteSpace(' ')
TYPE_REFERENCE
FUNCTION_TYPE
PsiElement(LBRACE)('{')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
PsiElement(IDENTIFIER)('a')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('T')
PsiElement(COMMA)(',')
PsiWhiteSpace(' ')
VALUE_PARAMETER
PsiElement(IDENTIFIER)('b')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('T')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('Boolean')
PsiElement(RBRACE)('}')
PsiWhiteSpace('\n')
PsiComment(EOL_COMMENT)('//type Equality<in T> = {(a : T, b : T) => Boolean}')
PsiWhiteSpace('\n')
TYPEDEF
PsiElement(type)('type')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('HashFunction')
TYPE_PARAMETER_LIST
PsiElement(LT)('<')
TYPE_PARAMETER
MODIFIER_LIST
PsiElement(in)('in')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('T')
PsiElement(GT)('>')
PsiWhiteSpace(' ')
PsiElement(EQ)('=')
PsiWhiteSpace(' ')
TYPE_REFERENCE
FUNCTION_TYPE
PsiElement(LBRACE)('{')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
PsiElement(IDENTIFIER)('obj')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('T')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('Int')
PsiElement(RBRACE)('}')
PsiWhiteSpace('\n')
PsiComment(EOL_COMMENT)('//type HashFunction<in T> = {(obj : T) => Int}')
PsiWhiteSpace('\n')
TYPEDEF
PsiElement(type)('type')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('Runnable')
PsiWhiteSpace(' ')
TYPE_PARAMETER_LIST
<empty list>
PsiElement(EQ)('=')
PsiWhiteSpace(' ')
TYPE_REFERENCE
FUNCTION_TYPE
PsiElement(LBRACE)('{')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
TUPLE_TYPE
PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
PsiElement(RBRACE)('}')
PsiWhiteSpace('\n')
PsiComment(EOL_COMMENT)('//type Runnable = {() => ()}')
PsiWhiteSpace('\n')
TYPEDEF
PsiElement(type)('type')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('Function1')
TYPE_PARAMETER_LIST
PsiElement(LT)('<')
TYPE_PARAMETER
MODIFIER_LIST
PsiElement(in)('in')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('T')
PsiElement(COMMA)(',')
PsiWhiteSpace(' ')
TYPE_PARAMETER
MODIFIER_LIST
PsiElement(out)('out')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('R')
PsiElement(GT)('>')
PsiWhiteSpace(' ')
PsiElement(EQ)('=')
PsiWhiteSpace(' ')
TYPE_REFERENCE
FUNCTION_TYPE
PsiElement(LBRACE)('{')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
PsiElement(IDENTIFIER)('input')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('T')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('R')
PsiElement(RBRACE)('}')
PsiWhiteSpace('\n')
PsiComment(EOL_COMMENT)('//type Function1<in T, out R> = {(input : T) => R}')
PsiWhiteSpace('\n\n\n')
PROPERTY
PsiElement(val)('val')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('f1')
PsiWhiteSpace(' ')
PsiElement(EQ)('=')
PsiWhiteSpace(' ')
FUNCTION_LITERAL
PsiElement(LBRACE)('{')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
PsiElement(IDENTIFIER)('t')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('T')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('X')
PsiWhiteSpace(' ')
PsiElement(DOUBLE_ARROW)('=>')
PsiWhiteSpace(' ')
BODY
CALL_EXPRESSION
PsiElement(IDENTIFIER)('something')
VALUE_ARGUMENT_LIST
PsiElement(LPAR)('(')
VALUE_ARGUMENT
PsiElement(IDENTIFIER)('t')
PsiElement(RPAR)(')')
PsiElement(RBRACE)('}')
PsiWhiteSpace('\n')
FUN
PsiElement(fun)('fun')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('f1')
TYPE_PARAMETER_LIST
<empty list>
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
PsiElement(IDENTIFIER)('t')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('T')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('X')
PsiWhiteSpace(' ')
PsiElement(EQ)('=')
PsiWhiteSpace(' ')
CALL_EXPRESSION
PsiElement(IDENTIFIER)('something')
VALUE_ARGUMENT_LIST
PsiElement(LPAR)('(')
VALUE_ARGUMENT
PsiElement(IDENTIFIER)('t')
PsiElement(RPAR)(')')
PsiWhiteSpace('\n\n')
PROPERTY
PsiElement(val)('val')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('f1')
PsiWhiteSpace(' ')
PsiElement(EQ)('=')
PsiWhiteSpace(' ')
FUNCTION_LITERAL
PsiElement(LBRACE)('{')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
PsiElement(IDENTIFIER)('t')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('T')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(DOUBLE_ARROW)('=>')
PsiWhiteSpace(' ')
BODY
CALL_EXPRESSION
PsiElement(IDENTIFIER)('something')
VALUE_ARGUMENT_LIST
PsiElement(LPAR)('(')
VALUE_ARGUMENT
PsiElement(IDENTIFIER)('t')
PsiElement(RPAR)(')')
PsiElement(RBRACE)('}')
PsiWhiteSpace('\n')
PROPERTY
PsiElement(val)('val')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('f1')
PsiWhiteSpace(' ')
PsiElement(EQ)('=')
PsiWhiteSpace(' ')
FUNCTION_LITERAL
PsiElement(LBRACE)('{')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
PsiElement(IDENTIFIER)('T')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('X')
PsiWhiteSpace(' ')
PsiElement(DOUBLE_ARROW)('=>')
PsiWhiteSpace(' ')
BODY
CALL_EXPRESSION
PsiElement(IDENTIFIER)('something')
VALUE_ARGUMENT_LIST
PsiElement(LPAR)('(')
VALUE_ARGUMENT
PsiElement(IDENTIFIER)('it')
PsiElement(RPAR)(')')
PsiElement(RBRACE)('}')
PsiWhiteSpace('\n')
PROPERTY
PsiElement(val)('val')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('f1')
PsiWhiteSpace(' ')
PsiElement(EQ)('=')
PsiWhiteSpace(' ')
FUNCTION_LITERAL
PsiElement(LBRACE)('{')
VALUE_PARAMETER
PsiElement(IDENTIFIER)('t')
PsiWhiteSpace(' ')
PsiElement(DOUBLE_ARROW)('=>')
PsiWhiteSpace(' ')
BODY
CALL_EXPRESSION
PsiElement(IDENTIFIER)('something')
VALUE_ARGUMENT_LIST
PsiElement(LPAR)('(')
VALUE_ARGUMENT
PsiElement(IDENTIFIER)('t')
PsiElement(RPAR)(')')
PsiElement(RBRACE)('}')
PsiWhiteSpace('\n')
PROPERTY
PsiElement(val)('val')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('f1')
PsiWhiteSpace(' ')
PsiElement(EQ)('=')
PsiWhiteSpace(' ')
FUNCTION_LITERAL
PsiElement(LBRACE)('{')
BODY
CALL_EXPRESSION
PsiElement(IDENTIFIER)('something')
VALUE_ARGUMENT_LIST
PsiElement(LPAR)('(')
VALUE_ARGUMENT
PsiElement(IDENTIFIER)('it')
PsiElement(RPAR)(')')
PsiElement(RBRACE)('}')
PsiWhiteSpace('\n\n')
PROPERTY
PsiElement(val)('val')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('f1')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
FUNCTION_TYPE
PsiElement(LBRACE)('{')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('T')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('X')
PsiElement(RBRACE)('}')
PsiWhiteSpace(' ')
PsiElement(EQ)('=')
PsiWhiteSpace(' ')
FUNCTION_LITERAL
PsiElement(LBRACE)('{')
BODY
CALL_EXPRESSION
PsiElement(IDENTIFIER)('X')
VALUE_ARGUMENT_LIST
PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
PsiElement(RBRACE)('}')
\ No newline at end of file
class Vertex<V>(val data : V)
class Edge<V, E>(val from : V, val data : E, val to : V)
class Graph<V, E> {
private val mutableEdges = new ArrayList<Edge<V, E>>() // type is ArrayList, but I want IMutableList
/* options:
private val edges : IMutableList<Edge<V, E>> = new ArrayList<Edge<V, E>>()
private val edges : IMutableList<Edge<V, E>> = new ArrayList() // not an erasure, but a request to infer parameters
*/
private val mutableVertices = new HashSet<Vertex<V>>()
val edges : IList<Edge<V, E>> = mutableEdges;
val vertices : ISet<Edge<V, E>> = mutableVertices;
fun addEdge(from : V, data : E, to : V) {
mutableEdges.add(new Edge(from, data, to)) // constructor parameters are inferred
}
fun addVertex(v : V) {
mutableEdges.add(new Edge(from, data, to)) // constructor parameters are inferred
}
fun neighbours(v : Vertex<V>) = edges.filter{it.from == v}.map{it.to} // type is IIterable<Vertex<V>>
fun dfs(handler : {(V) : Unit}) {
val visited = new HashSet<Vertex<V>>()
vertices.foreach{dfs(it, visited, handler)}
fun dfs(current : Vertex<V>, visited : ISet<Vertex<V>>, handler : {(V) : Unit}) {
if (!visited.add(current))
return
handler(current)
neighbours(current).foreach{dfs(it, visited, handler)}
}
}
public fun traverse(pending : IPushPop<Vertex<V>>, visited : ISet<Vertex<V>>, handler : {(V) : Unit}) {
vertices.foreach {
if (!visited.add(it))
continue
pending.push(it)
while (!pending.isEmpty) {
val current = pending.pop()
handler(current);
neighbours(current).foreach { n =>
if (visited.add(n)) {
pending.push(n)
}
}
/* alternative
pending->push(neighbours(current).filter{n => !visited[n])})
// -> means that if push(x : T) and actual parameter y is IIterable<T>, this compiles into
y.foreach{ n => push(n) }
*/
}
}
}
}
此差异已折叠。
virtual class IPushPop<T> {
val isEmpty : Boolean
fun push(item : T)
fun pop() : T
}
\ No newline at end of file
JetFile: IPushPop.jet
NAMESPACE
CLASS
MODIFIER_LIST
PsiElement(virtual)('virtual')
PsiWhiteSpace(' ')
PsiElement(class)('class')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('IPushPop')
TYPE_PARAMETER_LIST
PsiElement(LT)('<')
TYPE_PARAMETER
PsiElement(IDENTIFIER)('T')
PsiElement(GT)('>')
PsiWhiteSpace(' ')
CLASS_BODY
PsiElement(LBRACE)('{')
PsiWhiteSpace('\n ')
PROPERTY
PsiElement(val)('val')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('isEmpty')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('Boolean')
PsiWhiteSpace('\n ')
FUN
PsiElement(fun)('fun')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('push')
TYPE_PARAMETER_LIST
<empty list>
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
PsiElement(IDENTIFIER)('item')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('T')
PsiElement(RPAR)(')')
PsiWhiteSpace('\n ')
FUN
PsiElement(fun)('fun')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('pop')
TYPE_PARAMETER_LIST
<empty list>
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
PsiElement(IDENTIFIER)('T')
PsiWhiteSpace('\n')
PsiElement(RBRACE)('}')
\ No newline at end of file
fun foo() {
l filter {it.x} map {it.foo} aggregate {(a, b) => a + b}
}
\ No newline at end of file
JetFile: LINQ.jet
NAMESPACE
FUN
PsiElement(fun)('fun')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('foo')
TYPE_PARAMETER_LIST
<empty list>
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
BLOCK
PsiElement(LBRACE)('{')
PsiWhiteSpace('\n ')
BINARY_EXPRESSION
BINARY_EXPRESSION
BINARY_EXPRESSION
PsiElement(IDENTIFIER)('l')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('filter')
PsiWhiteSpace(' ')
FUNCTION_LITERAL
PsiElement(LBRACE)('{')
BODY
DOT_QIALIFIED_EXPRESSION
PsiElement(IDENTIFIER)('it')
PsiElement(DOT)('.')
PsiElement(IDENTIFIER)('x')
PsiElement(RBRACE)('}')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('map')
PsiWhiteSpace(' ')
FUNCTION_LITERAL
PsiElement(LBRACE)('{')
BODY
DOT_QIALIFIED_EXPRESSION
PsiElement(IDENTIFIER)('it')
PsiElement(DOT)('.')
PsiElement(IDENTIFIER)('foo')
PsiElement(RBRACE)('}')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('aggregate')
PsiWhiteSpace(' ')
FUNCTION_LITERAL
PsiElement(LBRACE)('{')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
PsiElement(IDENTIFIER)('a')
PsiElement(COMMA)(',')
PsiWhiteSpace(' ')
VALUE_PARAMETER
PsiElement(IDENTIFIER)('b')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(DOUBLE_ARROW)('=>')
PsiWhiteSpace(' ')
BODY
BINARY_EXPRESSION
PsiElement(IDENTIFIER)('a')
PsiWhiteSpace(' ')
PsiElement(PLUS)('+')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('b')
PsiElement(RBRACE)('}')
PsiWhiteSpace('\n')
PsiElement(RBRACE)('}')
\ No newline at end of file
virtual class Builder<E, R> {
[operator] fun plusAssign(item : E)
fun result() : R
}
virtual class Buildable {
fun newBuilder<E, R>() : Builder<E, R>
}
class List<T> {
class object Buildable {
override fun newBuilder<E, R>() : Builder<E, R>
}
}
extension Map<E, T>
where
T : Iterable<E>,
class object T : Buildable<E, T> for T {
fun map<R>(f : {(E) : R}) : T<R> = {
val builder = T.newBuilder()
for (e in this) {
builder += f(e)
}
builder.result()
}
}
\ No newline at end of file
此差异已折叠。
class Queue<T> : IPushPop<T> {
private class Item<T>(val data : T, var next : Item<T>)
private var head : Item<T> = null
private var tail : Item<T> = null
override fun push(item : T) {
val i = new Item(item)
if (tail == null) {
head = i
tail = head
} else {
tail.next = i
tail = i
}
}
override fun pop() =
if (head == null)
throw new UnderflowException()
else {
val result = head.data
head = head.next
if (head == null)
tail = null
result
}
override val isEmpty
get() = head == null
}
\ No newline at end of file
此差异已折叠。
class Stack<T> : IPushPop<T> {
private val data = new ArrayList<T>();
override fun push(item : T) {
data.add(item) // Problem: I would like to write push(...) = data.add(...), but the types do not match
}
override fun pop() = data.removeLast()
override val isEmpty
get() = data.isEmpty
}
\ No newline at end of file
此差异已折叠。
class UnionFind {
private val data = IMutableList<Int>()
fun add() : Int {
val size = data.size
data.add(size)
size
}
private fun parent(x : Int) : Int {
val p = data[x];
if (p == x) {
return x;
}
val result = parent(p);
data[x] = result;
}
fun union(a : Int, b : Int) {
val pa = parent(a)
val pb = parent(b)
if (pa != pb) {
if (Random.nextInt().isOdd) {
data[pb] = pa
} else {
data[pa] = pb
}
}
}
}
val Int.isOdd : Boolean
get() = this % 2 != 0
此差异已折叠。
class Pair(x : Int, y : Int) {
class object {
fun copy(from : Pair, x : Int = from.x, y : Int = from.y) = new Pair(x, y)
}
}
// One can say:
val p = new Point(1, 2)
val p1 = Point.Copy(p, x = 2)
val p2 = Point.Copy(p1, y = -1)
val p3 = Point.Copy(p)
// Such copy(...) methods can be automatically generated by the compiler
// whenever there is a primary constructor
\ No newline at end of file
此差异已折叠。
[inline] fun with<T>(receiver : T, body : {T.() : Unit}) = receiver.body()
fun example() {
with(java.lang.System.out) {
println("foo");
print("bar");
}
System.out.{
println("foo");
print("bar");
}()
}
\ No newline at end of file
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
virtual class IIterable<out T> {
fun iterator() : IIterator<T>
}
此差异已折叠。
此差异已折叠。
此差异已折叠。
virtual class IList<out T> : IIterable<T>, ISized {
[operator] fun get(index : Int) : T
val isEmpty : Boolean
}
\ No newline at end of file
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册