Anonymous Objects
This commit is contained in:
@@ -0,0 +1,21 @@
|
|||||||
|
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)
|
||||||
|
};
|
||||||
|
|
||||||
|
addMouseListener([mouseClicked : {e => doFoo()}]);
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
class ConcreteClass {
|
||||||
|
|
||||||
|
this() {}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Implicitly generated a factory for ConcreteClass with a no-argument factory method
|
||||||
|
|
||||||
|
interface class IFooBarInterface {
|
||||||
|
new () { }
|
||||||
|
}
|
||||||
|
|
||||||
|
factory
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
l filter {it.x} map {it.foo} aggregate {a, b => a + b}
|
||||||
|
|
||||||
@@ -16,7 +16,11 @@ class
|
|||||||
("(" defaultConstructorParameter{","} ")")?
|
("(" defaultConstructorParameter{","} ")")?
|
||||||
(":" delegationSpecifier{","})?
|
(":" delegationSpecifier{","})?
|
||||||
("where" typeConstraint{","})? // Syntax is questionable
|
("where" typeConstraint{","})? // Syntax is questionable
|
||||||
("{" memberDeclaration{","} "}"?
|
classBody?
|
||||||
|
;
|
||||||
|
|
||||||
|
classBody
|
||||||
|
: ("{" memberDeclaration{","} "}"
|
||||||
;
|
;
|
||||||
|
|
||||||
classModifier
|
classModifier
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ match
|
|||||||
|
|
||||||
matchEntry
|
matchEntry
|
||||||
: "case" pattern "=>" expression // TODO: Consider other options than "=>"
|
: "case" pattern "=>" expression // TODO: Consider other options than "=>"
|
||||||
|
: "else" "=>" expression // TODO: keyword
|
||||||
;
|
;
|
||||||
|
|
||||||
for
|
for
|
||||||
|
|||||||
+27
-10
@@ -8,11 +8,7 @@ expression
|
|||||||
: "null"
|
: "null"
|
||||||
: "this"
|
: "this"
|
||||||
: memberAccessExpression
|
: memberAccessExpression
|
||||||
: infixFunctionCall
|
: expressionWithPrecedences
|
||||||
: binOpExpression
|
|
||||||
: assignment
|
|
||||||
: unOpExpression
|
|
||||||
: castExpression
|
|
||||||
: match
|
: match
|
||||||
: if
|
: if
|
||||||
: "new" constructorInvocation
|
: "new" constructorInvocation
|
||||||
@@ -21,8 +17,21 @@ expression
|
|||||||
: jump
|
: jump
|
||||||
;
|
;
|
||||||
|
|
||||||
castExpression
|
expressionWithPrecedences // See the precedence table, everything associates to the left
|
||||||
: expression "as" type
|
: infixFunctionCall
|
||||||
|
: binOpExpression
|
||||||
|
: assignment
|
||||||
|
: unOpExpression
|
||||||
|
: castExpression
|
||||||
|
: typingExpression
|
||||||
|
;
|
||||||
|
|
||||||
|
typingExpression
|
||||||
|
: expression typingOperation type
|
||||||
|
;
|
||||||
|
|
||||||
|
typingOperation
|
||||||
|
: "as" : "is" : "isnot"
|
||||||
;
|
;
|
||||||
|
|
||||||
binOpExpression
|
binOpExpression
|
||||||
@@ -35,14 +44,18 @@ unOpExpression
|
|||||||
;
|
;
|
||||||
|
|
||||||
binaryOperation // Decreasing precedence
|
binaryOperation // Decreasing precedence
|
||||||
: "*" : "/" // No %
|
// .
|
||||||
|
// unary
|
||||||
|
: "*" : "/" : "%"
|
||||||
: "+" : "-"
|
: "+" : "-"
|
||||||
// No << >> >>>
|
// No << >> >>>
|
||||||
: "<" : ">" : ">=" : "<=" : "is" : "isnot" : "in" // TODO: Check the precedence for in carefully
|
// named functions in infix form
|
||||||
: "!=" : "==" : "==="
|
: "<" : ">" : ">=" : "<=" : "in" // is isnot as // TODO: Check the precedence for in carefully
|
||||||
|
: "!=" : "==" : "===" : "!=="
|
||||||
// No | & ^ ~
|
// No | & ^ ~
|
||||||
: "&&"
|
: "&&"
|
||||||
: "||"
|
: "||"
|
||||||
|
// assignments
|
||||||
;
|
;
|
||||||
|
|
||||||
assignmentOperator
|
assignmentOperator
|
||||||
@@ -145,3 +158,7 @@ fieldOrPropertyAccess
|
|||||||
arrayAccess
|
arrayAccess
|
||||||
: "[" expression "]"
|
: "[" expression "]"
|
||||||
;
|
;
|
||||||
|
|
||||||
|
anonymousInnerClassInstantiation
|
||||||
|
: "object" delegationSpecifier{","} classBody
|
||||||
|
;
|
||||||
Reference in New Issue
Block a user