Skip to content

Instantly share code, notes, and snippets.

View szarnekow's full-sized avatar

Sebastian Zarnekow szarnekow

View GitHub Profile
@szarnekow
szarnekow / Sample.java
Created October 27, 2012 16:12
Xtext syntactic predicates example
if (condition)
if (condition)
someAction();
else
otherAction();
// or
if (condition)
if (condition)
@szarnekow
szarnekow / gist:3965231
Created October 27, 2012 16:23
Xtext syntactic predicates example
=>(target=ID '.' feature=ID '=') value=Expression
@szarnekow
szarnekow / Benchmark.java
Created November 27, 2012 09:41
Caliper Benchmark for getContainerOfType
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.xbase.XAbstractFeatureCall;
import org.eclipse.xtext.xbase.XFeatureCall;
import org.eclipse.xtext.xbase.XMemberFeatureCall;
import org.eclipse.xtext.xbase.XNullLiteral;
import org.eclipse.xtext.xbase.XUnaryOperation;
import org.eclipse.xtext.xbase.XbaseFactory;
import com.google.caliper.Param;
import com.google.caliper.Runner;
@szarnekow
szarnekow / Client.xtend
Created December 13, 2012 20:35
Musings about checked exceptions in Xtend
import static extension Throwables.*
val uri = [| new URI(requestURI) ].onException [
new IllegalArgumentException(it)
]
@szarnekow
szarnekow / Doh.java
Last active December 10, 2015 23:28
Modify final fields
public class Doh {
public static void main(String[] args) throws Exception {
Person p = new Person("Name");
setName(p, "New Name");
setDefault("Bob");
System.out.println(p.getName());
System.out.println(Person.DEFAULT);
}
/**
@szarnekow
szarnekow / CarElement.xtend
Last active December 15, 2015 06:09
Illustration of the visitor pattern with Active Annotations.
@Visitable
abstract class CarElement {
// placeholder
def void accept(CarElementVisitor visitor)
}
@Data
class Wheel extends CarElement {
String name;
}
class Engine extends CarElement {}
package annotations
import java.lang.annotation.Documented
import java.lang.annotation.ElementType
import java.lang.annotation.Target
import java.util.List
import java.util.Set
import org.eclipse.xtend.lib.macro.Active
import org.eclipse.xtend.lib.macro.RegisterGlobalsContext
import org.eclipse.xtend.lib.macro.RegisterGlobalsParticipant
import com.google.caliper.Benchmark;
import com.google.caliper.Param;
import com.google.caliper.api.Macrobenchmark;
import com.google.caliper.runner.CaliperMain;
import java.util.AbstractList;
import java.util.Arrays;
import java.util.List;
public class IntArraySumBenchmark extends Benchmark {
import java.util.Arrays;
import java.util.stream.IntStream;
public class C {
public int parallelSumJava8(int reps) {
int result = 0;
for (int i = 0; i < reps; i++) {
final int i_ = i;
result += Arrays.stream(array).parallel().map(e -> e * 5 * i_).sum();
@szarnekow
szarnekow / gist:ea256af86126b9718627
Created June 26, 2014 06:39
Multiple inheritance in Xtext
A: // not necessarily called anywhere
SomeA | AB
;
B: // not necessarily called anywhere
SomeB | AB
;
AB:
a='a' b='b'
;