Skip to content

Instantly share code, notes, and snippets.

View abreslav's full-sized avatar

Andrey Breslav abreslav

View GitHub Profile
@abreslav
abreslav / JavaKeywords.kt
Created March 27, 2012 07:45
Running functions named as Java keywords (in Kotlin)
fun assert(i : Int) = println(i)
fun abstract(i : Int) = println(i)
fun boolean(i : Int) = println(i)
fun `break`(i : Int) = println(i)
fun byte(i : Int) = println(i)
fun case(i : Int) = println(i)
fun catch(i : Int) = println(i)
fun char(i : Int) = println(i)
fun `class`(i : Int) = println(i)
fun const(i : Int) = println(i)
@abreslav
abreslav / hello.kt
Created March 29, 2012 07:53
Hello, world!
fun main(args : Array<String>) {
println("Hello, GitHub!")
}
@abreslav
abreslav / gist:2569478
Created May 1, 2012 16:37
Kotlin + JUnit
package hhh.csp
import org.junit.*
import org.junit.rules.ExpectedException
import junit.framework.TestCase
import junit.framework.TestSuite
public class IntervalTest(name :String) : TestCase(name) {
fun testIntervalPlus() {
public static void compareNamespaces(@NotNull NamespaceDescriptor nsa, @NotNull NamespaceDescriptor nsb, boolean includeObject,
@NotNull File txtFile) {
String serialized = new NamespaceComparator(includeObject).doCompareNamespaces(nsa, nsb);
try {
if (!txtFile.exists()) {
FileUtil.writeToFile(txtFile, serialized);
Assert.fail("Expected data file did not exist. Generating: " + txtFile);
}
String expected = FileUtil.loadFile(txtFile);
class A(val b : B, val c : C) {...}
fun test() {
val a = A(
b = B(),
c = C()
)
}
ModuleConfiguration moduleConfiguration = new ModuleConfiguration() {
@Override
public void addDefaultImports(@NotNull Collection<JetImportDirective> directives) {
for (ImportPath defaultJetImport : DefaultModuleConfiguration.DEFAULT_JET_IMPORTS) {
directives.add(JetPsiFactory.createImportDirective(project, defaultJetImport));
}
}
@Override
public void extendNamespaceScope(
import java.io.FileReader;
import java.io.IOException;
import java.io.StreamTokenizer;
import java.util.ArrayList;
import java.util.HashMap;
/**
* Created with IntelliJ IDEA.
* User: smevok
* Date: 05.07.12
interface Comparator<T> {
boolean lt(T left, T right);
}
static Object NULL = new Object();
static class LtInf implements Comparator<Object> {
@Override
public boolean lt(Object left, Object right) {
fun main(args: Array<String>) {
val array = Class.forName("java.util.Collection")?.getInterfaces()!!
for (c in array) {
println(c)
c!!.accept(ClassVisitor())
}
}
class ClassVisitor
@abreslav
abreslav / kotlin-2012-13.markdown
Last active July 28, 2023 10:55
Kotlin Project Theme(s) - 2012/13

The Kotlin Programming Language

Kotlin is a modern statically typed programming language targeting for the Java and JavaScript platforms. We aim at creating what we call "a modern language for industry", keeping a balance between flexibility and readability, expressiveness and safety. Kotlin is under development, and we are rapidly approaching a Beta stage.

Project Overview

A modern programming language is much more than a grammar. Principal susystems of Kotlin include

  • Compiler front-end
  • Lexer/Parser translates text into a syntax tree, reports syntax errors