Skip to content

Instantly share code, notes, and snippets.

View erokhins's full-sized avatar

Stanislav Erokhin erokhins

  • JetBrains
  • Amsterdam
View GitHub Profile
package kara.test
public enum class Shape(override val value: String) : EnumValues<Shape> {
circle: Shape("circle")
default: Shape("default")
poly: Shape("poly")
rect: Shape("rect")
}
open class A
val A.name = "A"
class B: A()
val B.name = "B"
fun main(args: Array<String>) {
println(A().name)
println(B().name)
}
trait A {
var foo: Int
}
var A.foo = 4
class B: A // no impl foo
@erokhins
erokhins / gist:5949535
Last active December 19, 2015 11:39
attr val example
class B {
val attr = Attr()
class Attr {
var name: String = ""
var width: Int = 0
fun invoke(f: Attr.() -> Unit) {
this.f()
}
}
}
@erokhins
erokhins / gist:5964612
Created July 10, 2013 08:55
Kara.attr
open class Attributes {
var name = "No name"
var time = "10:00"
}
class A {
val attr = object: Attributes() {
var href = ""
}
}
open class Attributes {
var name = "No name"
var time = "10:00"
fun invoke(f : Attributes.() -> Unit) {
this.f()
}
}
class A {
class A_ATTR: Attributes() {
@erokhins
erokhins / gist:5976177
Last active December 19, 2015 15:29
kara.attributes
abstract class Attributes<T> {
var name = "No name"
var time = "10:00"
fun invoke(f: T.() -> Unit) {
(this as T).f()
}
}
class CommonAttributes: Attributes<CommonAttributes>()
@erokhins
erokhins / gist:5977265
Created July 11, 2013 17:04
Kara.StrEnum
val autocomplete = StrEnumAttribute("autocomplete", javaClass<Autocomplete>())
public class Autocomplete(override val value: String): StrEnumValues<Autocomplete> {
val off = Autocomplete("off")
val on = Autocomplete("on")
}
@erokhins
erokhins / gist:5983361
Created July 12, 2013 10:15
C.foo D.foo
open class A {
val c1 = 1
}
class B: A() {
val c2 = 2
}
open class C
open class D: C()
trait I<T> {
public fun invoke(f: T.() -> Unit) {}
}
open class A: I<A> {
val c1 = 1
}
class B: I<B> {