diff --git a/Jnario.setup b/Jnario.setup index 923838f4a..865ac1790 100644 --- a/Jnario.setup +++ b/Jnario.setup @@ -43,9 +43,11 @@ + name="org.eclipse.xtend.sdk.feature.group" + versionRange="[2.11.0,2.12.0)"/> + name="org.eclipse.xtext.sdk.feature.group" + versionRange="[2.11.0,2.12.0)"/> + + + +Stack<String> + + + + + + + + + + + + + + + + +
+
+
+ +
+
+
+
+

Empty

+
  • subject.empty[] should be true

    +
  • subject.pop[] throws EmptyStackException

    +
+

Not empty

+
  • increases size when pushing

    +
    +subject.push("something")
    +subject.size => 1
    +
  • decreases size when popping

    +
    +subject.push("something")
    +subject.pop()
    +subject.size => 0
    +
+
+
+

Stack.spec

+

+

+/*******************************************************************************
+ * Copyright (c) 2012 BMW Car IT and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+package diverse
+
+import java.util.EmptyStackException
+import java.util.Stack
+
+describe Stack<String>{
+  context "empty"{
+    fact subject.empty() should be true
+    fact subject.pop() throws EmptyStackException
+  }
+   context "not empty"{
+    fact "increases size when pushing"{
+      subject.push("something")
+      subject.size => 1
+    }    
+    fact "decreases size when popping"{
+      subject.push("something")
+      subject.pop()
+      subject.size => 0
+    }   
+   }
+}
+
+

+
+
+
+
+
+ +
+ + + diff --git a/examples/org.jnario.examples/xtend-gen/calculator/AdditionFeatureAddTwoNumbers.java b/examples/org.jnario.examples/xtend-gen/calculator/AdditionFeatureAddTwoNumbers.java index 3451571eb..1ff838c6f 100644 --- a/examples/org.jnario.examples/xtend-gen/calculator/AdditionFeatureAddTwoNumbers.java +++ b/examples/org.jnario.examples/xtend-gen/calculator/AdditionFeatureAddTwoNumbers.java @@ -1,49 +1,45 @@ -package calculator; - -import calculator.AdditionFeature; -import calculator.Calculator; -import org.jnario.lib.Assert; -import org.jnario.lib.JnarioIterableExtensions; -import org.jnario.lib.Should; -import org.jnario.lib.StepArguments; -import org.jnario.lib.StringConversions; -import org.jnario.runner.FeatureRunner; -import org.jnario.runner.Named; -import org.jnario.runner.Order; -import org.junit.Test; -import org.junit.runner.RunWith; - -@RunWith(FeatureRunner.class) -@Named("Scenario: Add two numbers") -@SuppressWarnings("all") -public class AdditionFeatureAddTwoNumbers extends AdditionFeature { - final Calculator calculator = new Calculator(); - - int result; - - @Test - @Order(0) - @Named("When I entered \\\"50\\\" and \\\"70\\\"") - public void _whenIEntered50And70() { - final StepArguments args = new StepArguments("50", "70"); - String _first = JnarioIterableExtensions.first(args); - String _second = JnarioIterableExtensions.second(args); - int _add = this.calculator.add(_first, _second); - this.result = _add; - } - - @Test - @Order(1) - @Named("Then the result should be \\\"120\\\"") - public void _thenTheResultShouldBe120() { - final StepArguments args = new StepArguments("120"); - String _first = JnarioIterableExtensions.first(args); - int _int = StringConversions.toInt(_first); - Assert.assertTrue("\nExpected result => args.first.toInt but" - + "\n result is " + new org.hamcrest.StringDescription().appendValue(Integer.valueOf(this.result)).toString() - + "\n args.first.toInt is " + new org.hamcrest.StringDescription().appendValue(Integer.valueOf(_int)).toString() - + "\n args.first is " + new org.hamcrest.StringDescription().appendValue(_first).toString() - + "\n args is " + new org.hamcrest.StringDescription().appendValue(args).toString() + "\n", Should.operator_doubleArrow(Integer.valueOf(this.result), Integer.valueOf(_int))); - - } -} +package calculator; + +import calculator.AdditionFeature; +import calculator.Calculator; +import org.jnario.lib.Assert; +import org.jnario.lib.JnarioIterableExtensions; +import org.jnario.lib.Should; +import org.jnario.lib.StepArguments; +import org.jnario.lib.StringConversions; +import org.jnario.runner.FeatureRunner; +import org.jnario.runner.Named; +import org.jnario.runner.Order; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(FeatureRunner.class) +@Named("Scenario: Add two numbers") +@SuppressWarnings("all") +public class AdditionFeatureAddTwoNumbers extends AdditionFeature { + final Calculator calculator = new Calculator(); + + int result; + + @Test + @Order(0) + @Named("When I entered \\\"50\\\" and \\\"70\\\"") + public void _whenIEntered50And70() { + final StepArguments args = new StepArguments("50", "70"); + this.result = this.calculator.add(JnarioIterableExtensions.first(args), JnarioIterableExtensions.second(args)); + } + + @Test + @Order(1) + @Named("Then the result should be \\\"120\\\"") + public void _thenTheResultShouldBe120() { + final StepArguments args = new StepArguments("120"); + int _int = StringConversions.toInt(JnarioIterableExtensions.first(args)); + Assert.assertTrue("\nExpected result => args.first.toInt but" + + "\n result is " + new org.hamcrest.StringDescription().appendValue(Integer.valueOf(this.result)).toString() + + "\n args.first.toInt is " + new org.hamcrest.StringDescription().appendValue(Integer.valueOf(_int)).toString() + + "\n args.first is " + new org.hamcrest.StringDescription().appendValue(JnarioIterableExtensions.first(args)).toString() + + "\n args is " + new org.hamcrest.StringDescription().appendValue(args).toString() + "\n", Should.operator_doubleArrow(Integer.valueOf(this.result), Integer.valueOf(_int))); + + } +} diff --git a/examples/org.jnario.examples/xtend-gen/calculator/Calculator.java b/examples/org.jnario.examples/xtend-gen/calculator/Calculator.java index cf3a3ecef..51f9d7faa 100644 --- a/examples/org.jnario.examples/xtend-gen/calculator/Calculator.java +++ b/examples/org.jnario.examples/xtend-gen/calculator/Calculator.java @@ -1,34 +1,32 @@ -/** - * Copyright (c) 2012 BMW Car IT and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package calculator; - -@SuppressWarnings("all") -public class Calculator { - public int add(final String a, final String b) { - Integer _valueOf = Integer.valueOf(a); - Integer _valueOf_1 = Integer.valueOf(b); - return this.add((_valueOf).intValue(), (_valueOf_1).intValue()); - } - - public int add(final int a, final int b) { - return (a + b); - } - - public int divide(final int a, final int b) { - return (a / b); - } - - public int substract(final int a, final int b) { - return (a - b); - } - - @Override - public String toString() { - return "Calculator"; - } -} +/** + * Copyright (c) 2012 BMW Car IT and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package calculator; + +@SuppressWarnings("all") +public class Calculator { + public int add(final String a, final String b) { + return this.add((Integer.valueOf(a)).intValue(), (Integer.valueOf(b)).intValue()); + } + + public int add(final int a, final int b) { + return (a + b); + } + + public int divide(final int a, final int b) { + return (a / b); + } + + public int substract(final int a, final int b) { + return (a - b); + } + + @Override + public String toString() { + return "Calculator"; + } +} diff --git a/examples/org.jnario.examples/xtend-gen/calculator/SimpleCalculator.java b/examples/org.jnario.examples/xtend-gen/calculator/SimpleCalculator.java index 79a97ee9b..7bb65dd8a 100644 --- a/examples/org.jnario.examples/xtend-gen/calculator/SimpleCalculator.java +++ b/examples/org.jnario.examples/xtend-gen/calculator/SimpleCalculator.java @@ -1,38 +1,37 @@ -package calculator; - -import java.util.ArrayList; -import org.eclipse.xtext.xbase.lib.CollectionLiterals; -import org.eclipse.xtext.xbase.lib.Functions.Function2; -import org.eclipse.xtext.xbase.lib.IterableExtensions; - -@SuppressWarnings("all") -public class SimpleCalculator { - private final ArrayList values = CollectionLiterals.newArrayList(); - - private int result = 0; - - public boolean enter(final String string) { - Integer _valueOf = Integer.valueOf(string); - return this.values.add(_valueOf); - } - - public int add() { - final Function2 _function = new Function2() { - @Override - public Integer apply(final Integer a, final Integer b) { - return Integer.valueOf(((a).intValue() + (b).intValue())); - } - }; - Integer _fold = IterableExtensions.fold(this.values, Integer.valueOf(0), _function); - return this.result = (_fold).intValue(); - } - - public String result() { - return Integer.valueOf(this.result).toString(); - } - - @Override - public String toString() { - return "Calculator"; - } -} +package calculator; + +import java.util.ArrayList; +import org.eclipse.xtext.xbase.lib.CollectionLiterals; +import org.eclipse.xtext.xbase.lib.Functions.Function2; +import org.eclipse.xtext.xbase.lib.IterableExtensions; + +@SuppressWarnings("all") +public class SimpleCalculator { + private final ArrayList values = CollectionLiterals.newArrayList(); + + private int result = 0; + + public boolean enter(final String string) { + Integer _valueOf = Integer.valueOf(string); + return this.values.add(_valueOf); + } + + public int add() { + final Function2 _function = new Function2() { + @Override + public Integer apply(final Integer a, final Integer b) { + return Integer.valueOf(((a).intValue() + (b).intValue())); + } + }; + return this.result = (IterableExtensions.fold(this.values, Integer.valueOf(0), _function)).intValue(); + } + + public String result() { + return Integer.valueOf(this.result).toString(); + } + + @Override + public String toString() { + return "Calculator"; + } +} diff --git a/examples/org.jnario.examples/xtend-gen/diverse/AdditionFeatureAddTwoNumbers.java b/examples/org.jnario.examples/xtend-gen/diverse/AdditionFeatureAddTwoNumbers.java index 12d15a01f..9e2fb5b71 100644 --- a/examples/org.jnario.examples/xtend-gen/diverse/AdditionFeatureAddTwoNumbers.java +++ b/examples/org.jnario.examples/xtend-gen/diverse/AdditionFeatureAddTwoNumbers.java @@ -1,61 +1,59 @@ -package diverse; - -import calculator.SimpleCalculator; -import diverse.AdditionFeature; -import org.jnario.lib.Assert; -import org.jnario.lib.JnarioIterableExtensions; -import org.jnario.lib.Should; -import org.jnario.lib.StepArguments; -import org.jnario.runner.FeatureRunner; -import org.jnario.runner.Named; -import org.jnario.runner.Order; -import org.junit.Test; -import org.junit.runner.RunWith; - -@RunWith(FeatureRunner.class) -@Named("Scenario: Add two numbers") -@SuppressWarnings("all") -public class AdditionFeatureAddTwoNumbers extends AdditionFeature { - final SimpleCalculator calculator = new SimpleCalculator(); - - @Test - @Order(0) - @Named("Given I have entered \\\"50\\\" into the calculator") - public void _givenIHaveEntered50IntoTheCalculator() { - final StepArguments args = new StepArguments("50"); - String _first = JnarioIterableExtensions.first(args); - this.calculator.enter(_first); - } - - @Test - @Order(1) - @Named("And I have entered \\\"70\\\" into the calculator") - public void _andIHaveEntered70IntoTheCalculator() { - final StepArguments args = new StepArguments("70"); - String _first = JnarioIterableExtensions.first(args); - this.calculator.enter(_first); - } - - @Test - @Order(2) - @Named("When I press \\\"add\\\"") - public void _whenIPressAdd() { - final StepArguments args = new StepArguments("add"); - this.calculator.add(); - } - - @Test - @Order(3) - @Named("Then the result should be \\\"120\\\"") - public void _thenTheResultShouldBe120() { - final StepArguments args = new StepArguments("120"); - String _result = this.calculator.result(); - String _first = JnarioIterableExtensions.first(args); - Assert.assertTrue("\nExpected calculator.result => args.first but" - + "\n calculator.result is " + new org.hamcrest.StringDescription().appendValue(_result).toString() - + "\n calculator is " + new org.hamcrest.StringDescription().appendValue(this.calculator).toString() - + "\n args.first is " + new org.hamcrest.StringDescription().appendValue(_first).toString() - + "\n args is " + new org.hamcrest.StringDescription().appendValue(args).toString() + "\n", Should.operator_doubleArrow(_result, _first)); - - } -} +package diverse; + +import calculator.SimpleCalculator; +import diverse.AdditionFeature; +import org.jnario.lib.Assert; +import org.jnario.lib.JnarioIterableExtensions; +import org.jnario.lib.Should; +import org.jnario.lib.StepArguments; +import org.jnario.runner.FeatureRunner; +import org.jnario.runner.Named; +import org.jnario.runner.Order; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(FeatureRunner.class) +@Named("Scenario: Add two numbers") +@SuppressWarnings("all") +public class AdditionFeatureAddTwoNumbers extends AdditionFeature { + final SimpleCalculator calculator = new SimpleCalculator(); + + @Test + @Order(0) + @Named("Given I have entered \\\"50\\\" into the calculator") + public void _givenIHaveEntered50IntoTheCalculator() { + final StepArguments args = new StepArguments("50"); + this.calculator.enter(JnarioIterableExtensions.first(args)); + } + + @Test + @Order(1) + @Named("And I have entered \\\"70\\\" into the calculator") + public void _andIHaveEntered70IntoTheCalculator() { + final StepArguments args = new StepArguments("70"); + this.calculator.enter(JnarioIterableExtensions.first(args)); + } + + @Test + @Order(2) + @Named("When I press \\\"add\\\"") + public void _whenIPressAdd() { + final StepArguments args = new StepArguments("add"); + this.calculator.add(); + } + + @Test + @Order(3) + @Named("Then the result should be \\\"120\\\"") + public void _thenTheResultShouldBe120() { + final StepArguments args = new StepArguments("120"); + String _result = this.calculator.result(); + String _first = JnarioIterableExtensions.first(args); + Assert.assertTrue("\nExpected calculator.result => args.first but" + + "\n calculator.result is " + new org.hamcrest.StringDescription().appendValue(_result).toString() + + "\n calculator is " + new org.hamcrest.StringDescription().appendValue(this.calculator).toString() + + "\n args.first is " + new org.hamcrest.StringDescription().appendValue(_first).toString() + + "\n args is " + new org.hamcrest.StringDescription().appendValue(args).toString() + "\n", Should.operator_doubleArrow(_result, _first)); + + } +} diff --git a/examples/org.jnario.examples/xtend-gen/gameoflife/CellLocation.java b/examples/org.jnario.examples/xtend-gen/gameoflife/CellLocation.java index 90a07d979..49ba20899 100644 --- a/examples/org.jnario.examples/xtend-gen/gameoflife/CellLocation.java +++ b/examples/org.jnario.examples/xtend-gen/gameoflife/CellLocation.java @@ -1,92 +1,91 @@ -package gameoflife; - -import java.util.HashSet; -import java.util.Set; -import org.eclipse.xtend.lib.annotations.Data; -import org.eclipse.xtext.xbase.lib.CollectionLiterals; -import org.eclipse.xtext.xbase.lib.Functions.Function1; -import org.eclipse.xtext.xbase.lib.IterableExtensions; -import org.eclipse.xtext.xbase.lib.Pure; -import org.eclipse.xtext.xbase.lib.util.ToStringBuilder; - -@Data -@SuppressWarnings("all") -public class CellLocation { - private final static HashSet NEIGHBOUR_OFFSETS = CollectionLiterals.newHashSet( - CellLocation.cell(1, 0), CellLocation.cell(1, 1), CellLocation.cell(0, 1), CellLocation.cell((-1), (-1)), CellLocation.cell((-1), 0), CellLocation.cell((-1), 1), CellLocation.cell(0, (-1)), CellLocation.cell(1, (-1))); - - public static CellLocation cell(final int x, final int y) { - return new CellLocation(x, y); - } - - private final int x; - - private final int y; - - public Set neighbours() { - final Function1 _function = new Function1() { - @Override - public CellLocation apply(final CellLocation it) { - return CellLocation.this.plus(it); - } - }; - Iterable _map = IterableExtensions.map(CellLocation.NEIGHBOUR_OFFSETS, _function); - return IterableExtensions.toSet(_map); - } - - public CellLocation plus(final CellLocation other) { - return CellLocation.cell((this.x + other.x), (this.y + other.y)); - } - - public CellLocation(final int x, final int y) { - super(); - this.x = x; - this.y = y; - } - - @Override - @Pure - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + this.x; - result = prime * result + this.y; - return result; - } - - @Override - @Pure - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - CellLocation other = (CellLocation) obj; - if (other.x != this.x) - return false; - if (other.y != this.y) - return false; - return true; - } - - @Override - @Pure - public String toString() { - ToStringBuilder b = new ToStringBuilder(this); - b.add("x", this.x); - b.add("y", this.y); - return b.toString(); - } - - @Pure - public int getX() { - return this.x; - } - - @Pure - public int getY() { - return this.y; - } -} +package gameoflife; + +import java.util.HashSet; +import java.util.Set; +import org.eclipse.xtend.lib.annotations.Data; +import org.eclipse.xtext.xbase.lib.CollectionLiterals; +import org.eclipse.xtext.xbase.lib.Functions.Function1; +import org.eclipse.xtext.xbase.lib.IterableExtensions; +import org.eclipse.xtext.xbase.lib.Pure; +import org.eclipse.xtext.xbase.lib.util.ToStringBuilder; + +@Data +@SuppressWarnings("all") +public class CellLocation { + private final static HashSet NEIGHBOUR_OFFSETS = CollectionLiterals.newHashSet( + CellLocation.cell(1, 0), CellLocation.cell(1, 1), CellLocation.cell(0, 1), CellLocation.cell((-1), (-1)), CellLocation.cell((-1), 0), CellLocation.cell((-1), 1), CellLocation.cell(0, (-1)), CellLocation.cell(1, (-1))); + + public static CellLocation cell(final int x, final int y) { + return new CellLocation(x, y); + } + + private final int x; + + private final int y; + + public Set neighbours() { + final Function1 _function = new Function1() { + @Override + public CellLocation apply(final CellLocation it) { + return CellLocation.this.plus(it); + } + }; + return IterableExtensions.toSet(IterableExtensions.map(CellLocation.NEIGHBOUR_OFFSETS, _function)); + } + + public CellLocation plus(final CellLocation other) { + return CellLocation.cell((this.x + other.x), (this.y + other.y)); + } + + public CellLocation(final int x, final int y) { + super(); + this.x = x; + this.y = y; + } + + @Override + @Pure + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + this.x; + result = prime * result + this.y; + return result; + } + + @Override + @Pure + public boolean equals(final Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + CellLocation other = (CellLocation) obj; + if (other.x != this.x) + return false; + if (other.y != this.y) + return false; + return true; + } + + @Override + @Pure + public String toString() { + ToStringBuilder b = new ToStringBuilder(this); + b.add("x", this.x); + b.add("y", this.y); + return b.toString(); + } + + @Pure + public int getX() { + return this.x; + } + + @Pure + public int getY() { + return this.y; + } +} diff --git a/examples/org.jnario.examples/xtend-gen/gameoflife/Evolution.java b/examples/org.jnario.examples/xtend-gen/gameoflife/Evolution.java index 5799c884d..6a5baf333 100644 --- a/examples/org.jnario.examples/xtend-gen/gameoflife/Evolution.java +++ b/examples/org.jnario.examples/xtend-gen/gameoflife/Evolution.java @@ -1,114 +1,108 @@ -package gameoflife; - -import com.google.common.collect.Iterables; -import gameoflife.CellLocation; -import gameoflife.EvolveDeadCells; -import gameoflife.EvolveLiveCells; -import gameoflife.Rule; -import gameoflife.World; -import java.util.Set; -import org.eclipse.xtend.lib.annotations.Data; -import org.eclipse.xtext.xbase.lib.Functions.Function1; -import org.eclipse.xtext.xbase.lib.IterableExtensions; -import org.eclipse.xtext.xbase.lib.Pure; -import org.eclipse.xtext.xbase.lib.util.ToStringBuilder; - -@Data -@SuppressWarnings("all") -public class Evolution { - public static Evolution gameOfLife() { - EvolveLiveCells _evolveLiveCells = new EvolveLiveCells(); - EvolveDeadCells _evolveDeadCells = new EvolveDeadCells(); - return new Evolution(_evolveLiveCells, _evolveDeadCells); - } - - private final Rule staysAlive; - - private final Rule becomesAlive; - - public World evolve(final World world) { - Set _livingCells = world.getLivingCells(); - final Function1 _function = new Function1() { - @Override - public Boolean apply(final CellLocation it) { - Rule _staysAlive = Evolution.this.getStaysAlive(); - return Boolean.valueOf(Evolution.this.apply(_staysAlive, world, it)); - } - }; - Iterable _filter = IterableExtensions.filter(_livingCells, _function); - Set _deadCells = world.deadCells(); - final Function1 _function_1 = new Function1() { - @Override - public Boolean apply(final CellLocation it) { - Rule _becomesAlive = Evolution.this.getBecomesAlive(); - return Boolean.valueOf(Evolution.this.apply(_becomesAlive, world, it)); - } - }; - Iterable _filter_1 = IterableExtensions.filter(_deadCells, _function_1); - Iterable _plus = Iterables.concat(_filter, _filter_1); - return World.worldWith(_plus); - } - - private boolean apply(final Rule rule, final World world, final CellLocation cell) { - int _livingNeighbours = world.livingNeighbours(cell); - return rule.becomesAlive(_livingNeighbours); - } - - public Evolution(final Rule staysAlive, final Rule becomesAlive) { - super(); - this.staysAlive = staysAlive; - this.becomesAlive = becomesAlive; - } - - @Override - @Pure - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((this.staysAlive== null) ? 0 : this.staysAlive.hashCode()); - result = prime * result + ((this.becomesAlive== null) ? 0 : this.becomesAlive.hashCode()); - return result; - } - - @Override - @Pure - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - Evolution other = (Evolution) obj; - if (this.staysAlive == null) { - if (other.staysAlive != null) - return false; - } else if (!this.staysAlive.equals(other.staysAlive)) - return false; - if (this.becomesAlive == null) { - if (other.becomesAlive != null) - return false; - } else if (!this.becomesAlive.equals(other.becomesAlive)) - return false; - return true; - } - - @Override - @Pure - public String toString() { - ToStringBuilder b = new ToStringBuilder(this); - b.add("staysAlive", this.staysAlive); - b.add("becomesAlive", this.becomesAlive); - return b.toString(); - } - - @Pure - public Rule getStaysAlive() { - return this.staysAlive; - } - - @Pure - public Rule getBecomesAlive() { - return this.becomesAlive; - } -} +package gameoflife; + +import com.google.common.collect.Iterables; +import gameoflife.CellLocation; +import gameoflife.EvolveDeadCells; +import gameoflife.EvolveLiveCells; +import gameoflife.Rule; +import gameoflife.World; +import org.eclipse.xtend.lib.annotations.Data; +import org.eclipse.xtext.xbase.lib.Functions.Function1; +import org.eclipse.xtext.xbase.lib.IterableExtensions; +import org.eclipse.xtext.xbase.lib.Pure; +import org.eclipse.xtext.xbase.lib.util.ToStringBuilder; + +@Data +@SuppressWarnings("all") +public class Evolution { + public static Evolution gameOfLife() { + EvolveLiveCells _evolveLiveCells = new EvolveLiveCells(); + EvolveDeadCells _evolveDeadCells = new EvolveDeadCells(); + return new Evolution(_evolveLiveCells, _evolveDeadCells); + } + + private final Rule staysAlive; + + private final Rule becomesAlive; + + public World evolve(final World world) { + final Function1 _function = new Function1() { + @Override + public Boolean apply(final CellLocation it) { + return Boolean.valueOf(Evolution.this.apply(Evolution.this.getStaysAlive(), world, it)); + } + }; + Iterable _filter = IterableExtensions.filter(world.getLivingCells(), _function); + final Function1 _function_1 = new Function1() { + @Override + public Boolean apply(final CellLocation it) { + return Boolean.valueOf(Evolution.this.apply(Evolution.this.getBecomesAlive(), world, it)); + } + }; + Iterable _filter_1 = IterableExtensions.filter(world.deadCells(), _function_1); + Iterable _plus = Iterables.concat(_filter, _filter_1); + return World.worldWith(_plus); + } + + private boolean apply(final Rule rule, final World world, final CellLocation cell) { + return rule.becomesAlive(world.livingNeighbours(cell)); + } + + public Evolution(final Rule staysAlive, final Rule becomesAlive) { + super(); + this.staysAlive = staysAlive; + this.becomesAlive = becomesAlive; + } + + @Override + @Pure + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((this.staysAlive== null) ? 0 : this.staysAlive.hashCode()); + result = prime * result + ((this.becomesAlive== null) ? 0 : this.becomesAlive.hashCode()); + return result; + } + + @Override + @Pure + public boolean equals(final Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Evolution other = (Evolution) obj; + if (this.staysAlive == null) { + if (other.staysAlive != null) + return false; + } else if (!this.staysAlive.equals(other.staysAlive)) + return false; + if (this.becomesAlive == null) { + if (other.becomesAlive != null) + return false; + } else if (!this.becomesAlive.equals(other.becomesAlive)) + return false; + return true; + } + + @Override + @Pure + public String toString() { + ToStringBuilder b = new ToStringBuilder(this); + b.add("staysAlive", this.staysAlive); + b.add("becomesAlive", this.becomesAlive); + return b.toString(); + } + + @Pure + public Rule getStaysAlive() { + return this.staysAlive; + } + + @Pure + public Rule getBecomesAlive() { + return this.becomesAlive; + } +} diff --git a/examples/org.jnario.examples/xtend-gen/gameoflife/EvolveDeadCells.java b/examples/org.jnario.examples/xtend-gen/gameoflife/EvolveDeadCells.java index f27feb8e8..5290168a9 100644 --- a/examples/org.jnario.examples/xtend-gen/gameoflife/EvolveDeadCells.java +++ b/examples/org.jnario.examples/xtend-gen/gameoflife/EvolveDeadCells.java @@ -1,11 +1,11 @@ -package gameoflife; - -import gameoflife.Rule; - -@SuppressWarnings("all") -public class EvolveDeadCells implements Rule { - @Override - public boolean becomesAlive(final int neighbourCount) { - return (neighbourCount == 3); - } -} +package gameoflife; + +import gameoflife.Rule; + +@SuppressWarnings("all") +public class EvolveDeadCells implements Rule { + @Override + public boolean becomesAlive(final int neighbourCount) { + return (neighbourCount == 3); + } +} diff --git a/examples/org.jnario.examples/xtend-gen/gameoflife/EvolveLiveCells.java b/examples/org.jnario.examples/xtend-gen/gameoflife/EvolveLiveCells.java index 48b250c6f..b5642a6e3 100644 --- a/examples/org.jnario.examples/xtend-gen/gameoflife/EvolveLiveCells.java +++ b/examples/org.jnario.examples/xtend-gen/gameoflife/EvolveLiveCells.java @@ -1,19 +1,19 @@ -package gameoflife; - -import gameoflife.Rule; - -@SuppressWarnings("all") -public class EvolveLiveCells implements Rule { - @Override - public boolean becomesAlive(final int neighbourCount) { - return ((!this.underPopulated(neighbourCount)) && (!this.overPopulated(neighbourCount))); - } - - public boolean underPopulated(final int neighbourCount) { - return (neighbourCount < 2); - } - - public boolean overPopulated(final int neighbourCount) { - return (neighbourCount > 3); - } -} +package gameoflife; + +import gameoflife.Rule; + +@SuppressWarnings("all") +public class EvolveLiveCells implements Rule { + @Override + public boolean becomesAlive(final int neighbourCount) { + return ((!this.underPopulated(neighbourCount)) && (!this.overPopulated(neighbourCount))); + } + + public boolean underPopulated(final int neighbourCount) { + return (neighbourCount < 2); + } + + public boolean overPopulated(final int neighbourCount) { + return (neighbourCount > 3); + } +} diff --git a/examples/org.jnario.examples/xtend-gen/gameoflife/World.java b/examples/org.jnario.examples/xtend-gen/gameoflife/World.java index 5f18beebd..0ceefffa0 100644 --- a/examples/org.jnario.examples/xtend-gen/gameoflife/World.java +++ b/examples/org.jnario.examples/xtend-gen/gameoflife/World.java @@ -1,133 +1,124 @@ -package gameoflife; - -import com.google.common.base.Objects; -import com.google.common.collect.Iterables; -import gameoflife.CellLocation; -import java.util.ArrayList; -import java.util.Set; -import org.eclipse.xtend.lib.annotations.Data; -import org.eclipse.xtext.xbase.lib.CollectionLiterals; -import org.eclipse.xtext.xbase.lib.Conversions; -import org.eclipse.xtext.xbase.lib.Functions.Function1; -import org.eclipse.xtext.xbase.lib.IterableExtensions; -import org.eclipse.xtext.xbase.lib.Procedures.Procedure2; -import org.eclipse.xtext.xbase.lib.Pure; -import org.eclipse.xtext.xbase.lib.util.ToStringBuilder; - -@Data -@SuppressWarnings("all") -public class World { - private final Set livingCells; - - public static World parseWorld(final CharSequence grid) { - World _xblockexpression = null; - { - final ArrayList cells = CollectionLiterals.newArrayList(); - String _string = grid.toString(); - String[] _split = _string.split("\r?\n"); - final Procedure2 _function = new Procedure2() { - @Override - public void apply(final String line, final Integer x) { - char[] _charArray = line.toCharArray(); - final Procedure2 _function = new Procedure2() { - @Override - public void apply(final Character c, final Integer y) { - String _string = c.toString(); - boolean _equals = Objects.equal(_string, "X"); - if (_equals) { - CellLocation _cell = CellLocation.cell((x).intValue(), (y).intValue()); - cells.add(_cell); - } - } - }; - IterableExtensions.forEach(((Iterable)Conversions.doWrapArray(_charArray)), _function); - } - }; - IterableExtensions.forEach(((Iterable)Conversions.doWrapArray(_split)), _function); - _xblockexpression = World.worldWith(cells); - } - return _xblockexpression; - } - - public static World worldWith(final Iterable cells) { - Set _set = IterableExtensions.toSet(cells); - return new World(_set); - } - - public Set deadCells() { - final Function1> _function = new Function1>() { - @Override - public Set apply(final CellLocation it) { - return it.neighbours(); - } - }; - Iterable> _map = IterableExtensions.>map(this.livingCells, _function); - Iterable _flatten = Iterables.concat(_map); - final Function1 _function_1 = new Function1() { - @Override - public Boolean apply(final CellLocation it) { - boolean _contains = World.this.livingCells.contains(it); - return Boolean.valueOf((!_contains)); - } - }; - Iterable _filter = IterableExtensions.filter(_flatten, _function_1); - return IterableExtensions.toSet(_filter); - } - - public int livingNeighbours(final CellLocation cell) { - Set _neighbours = cell.neighbours(); - final Function1 _function = new Function1() { - @Override - public Boolean apply(final CellLocation it) { - return Boolean.valueOf(World.this.livingCells.contains(it)); - } - }; - Iterable _filter = IterableExtensions.filter(_neighbours, _function); - return IterableExtensions.size(_filter); - } - - public World(final Set livingCells) { - super(); - this.livingCells = livingCells; - } - - @Override - @Pure - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((this.livingCells== null) ? 0 : this.livingCells.hashCode()); - return result; - } - - @Override - @Pure - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - World other = (World) obj; - if (this.livingCells == null) { - if (other.livingCells != null) - return false; - } else if (!this.livingCells.equals(other.livingCells)) - return false; - return true; - } - - @Override - @Pure - public String toString() { - ToStringBuilder b = new ToStringBuilder(this); - b.add("livingCells", this.livingCells); - return b.toString(); - } - - @Pure - public Set getLivingCells() { - return this.livingCells; - } -} +package gameoflife; + +import com.google.common.base.Objects; +import com.google.common.collect.Iterables; +import gameoflife.CellLocation; +import java.util.ArrayList; +import java.util.Set; +import org.eclipse.xtend.lib.annotations.Data; +import org.eclipse.xtext.xbase.lib.CollectionLiterals; +import org.eclipse.xtext.xbase.lib.Conversions; +import org.eclipse.xtext.xbase.lib.Functions.Function1; +import org.eclipse.xtext.xbase.lib.IterableExtensions; +import org.eclipse.xtext.xbase.lib.Procedures.Procedure2; +import org.eclipse.xtext.xbase.lib.Pure; +import org.eclipse.xtext.xbase.lib.util.ToStringBuilder; + +@Data +@SuppressWarnings("all") +public class World { + private final Set livingCells; + + public static World parseWorld(final CharSequence grid) { + World _xblockexpression = null; + { + final ArrayList cells = CollectionLiterals.newArrayList(); + final Procedure2 _function = new Procedure2() { + @Override + public void apply(final String line, final Integer x) { + final Procedure2 _function = new Procedure2() { + @Override + public void apply(final Character c, final Integer y) { + String _string = c.toString(); + boolean _equals = Objects.equal(_string, "X"); + if (_equals) { + cells.add(CellLocation.cell((x).intValue(), (y).intValue())); + } + } + }; + IterableExtensions.forEach(((Iterable)Conversions.doWrapArray(line.toCharArray())), _function); + } + }; + IterableExtensions.forEach(((Iterable)Conversions.doWrapArray(grid.toString().split("\r?\n"))), _function); + _xblockexpression = World.worldWith(cells); + } + return _xblockexpression; + } + + public static World worldWith(final Iterable cells) { + Set _set = IterableExtensions.toSet(cells); + return new World(_set); + } + + public Set deadCells() { + final Function1> _function = new Function1>() { + @Override + public Set apply(final CellLocation it) { + return it.neighbours(); + } + }; + final Function1 _function_1 = new Function1() { + @Override + public Boolean apply(final CellLocation it) { + boolean _contains = World.this.livingCells.contains(it); + return Boolean.valueOf((!_contains)); + } + }; + return IterableExtensions.toSet(IterableExtensions.filter(Iterables.concat(IterableExtensions.>map(this.livingCells, _function)), _function_1)); + } + + public int livingNeighbours(final CellLocation cell) { + final Function1 _function = new Function1() { + @Override + public Boolean apply(final CellLocation it) { + return Boolean.valueOf(World.this.livingCells.contains(it)); + } + }; + return IterableExtensions.size(IterableExtensions.filter(cell.neighbours(), _function)); + } + + public World(final Set livingCells) { + super(); + this.livingCells = livingCells; + } + + @Override + @Pure + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((this.livingCells== null) ? 0 : this.livingCells.hashCode()); + return result; + } + + @Override + @Pure + public boolean equals(final Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + World other = (World) obj; + if (this.livingCells == null) { + if (other.livingCells != null) + return false; + } else if (!this.livingCells.equals(other.livingCells)) + return false; + return true; + } + + @Override + @Pure + public String toString() { + ToStringBuilder b = new ToStringBuilder(this); + b.add("livingCells", this.livingCells); + return b.toString(); + } + + @Pure + public Set getLivingCells() { + return this.livingCells; + } +} diff --git a/examples/org.jnario.examples/xtend-gen/gameoflife/features/PlayingGameOfLifeFeatureBlinker1.java b/examples/org.jnario.examples/xtend-gen/gameoflife/features/PlayingGameOfLifeFeatureBlinker1.java index 610a198de..b719c6e36 100644 --- a/examples/org.jnario.examples/xtend-gen/gameoflife/features/PlayingGameOfLifeFeatureBlinker1.java +++ b/examples/org.jnario.examples/xtend-gen/gameoflife/features/PlayingGameOfLifeFeatureBlinker1.java @@ -1,43 +1,38 @@ -package gameoflife.features; - -import gameoflife.Evolution; -import gameoflife.World; -import gameoflife.features.PlayingGameOfLifeFeature; -import org.jnario.lib.JnarioIterableExtensions; -import org.jnario.lib.Should; -import org.jnario.lib.StepArguments; -import org.jnario.runner.FeatureRunner; -import org.jnario.runner.Named; -import org.jnario.runner.Order; -import org.junit.Test; -import org.junit.runner.RunWith; - -@RunWith(FeatureRunner.class) -@Named("Scenario: Blinker 1") -@SuppressWarnings("all") -public class PlayingGameOfLifeFeatureBlinker1 extends PlayingGameOfLifeFeature { - World world; - - @Test - @Order(0) - @Named("Given a world") - public void _givenAWorld() { - final StepArguments args = new StepArguments("-----\n--X--\n--X--\n--X--\n-----\n"); - String _first = JnarioIterableExtensions.first(args); - World _parseWorld = World.parseWorld(_first); - this.world = _parseWorld; - } - - @Test - @Order(1) - @Named("Then the world evolves into") - public void _thenTheWorldEvolvesInto() { - final StepArguments args = new StepArguments("-----\n-----\n-XXX-\n-----\n-----\n"); - Evolution _gameOfLife = Evolution.gameOfLife(); - World _evolve = _gameOfLife.evolve(this.world); - this.world = _evolve; - String _first = JnarioIterableExtensions.first(args); - World _parseWorld = World.parseWorld(_first); - Should.operator_doubleArrow(this.world, _parseWorld); - } -} +package gameoflife.features; + +import gameoflife.Evolution; +import gameoflife.World; +import gameoflife.features.PlayingGameOfLifeFeature; +import org.jnario.lib.JnarioIterableExtensions; +import org.jnario.lib.Should; +import org.jnario.lib.StepArguments; +import org.jnario.runner.FeatureRunner; +import org.jnario.runner.Named; +import org.jnario.runner.Order; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(FeatureRunner.class) +@Named("Scenario: Blinker 1") +@SuppressWarnings("all") +public class PlayingGameOfLifeFeatureBlinker1 extends PlayingGameOfLifeFeature { + World world; + + @Test + @Order(0) + @Named("Given a world") + public void _givenAWorld() { + final StepArguments args = new StepArguments("-----\n--X--\n--X--\n--X--\n-----\n"); + this.world = World.parseWorld(JnarioIterableExtensions.first(args)); + } + + @Test + @Order(1) + @Named("Then the world evolves into") + public void _thenTheWorldEvolvesInto() { + final StepArguments args = new StepArguments("-----\n-----\n-XXX-\n-----\n-----\n"); + this.world = Evolution.gameOfLife().evolve(this.world); + World _parseWorld = World.parseWorld(JnarioIterableExtensions.first(args)); + Should.operator_doubleArrow(this.world, _parseWorld); + } +} diff --git a/examples/org.jnario.examples/xtend-gen/gameoflife/features/PlayingGameOfLifeFeatureBlinker2.java b/examples/org.jnario.examples/xtend-gen/gameoflife/features/PlayingGameOfLifeFeatureBlinker2.java index ba1f507b1..7f4d4900d 100644 --- a/examples/org.jnario.examples/xtend-gen/gameoflife/features/PlayingGameOfLifeFeatureBlinker2.java +++ b/examples/org.jnario.examples/xtend-gen/gameoflife/features/PlayingGameOfLifeFeatureBlinker2.java @@ -1,43 +1,38 @@ -package gameoflife.features; - -import gameoflife.Evolution; -import gameoflife.World; -import gameoflife.features.PlayingGameOfLifeFeature; -import org.jnario.lib.JnarioIterableExtensions; -import org.jnario.lib.Should; -import org.jnario.lib.StepArguments; -import org.jnario.runner.FeatureRunner; -import org.jnario.runner.Named; -import org.jnario.runner.Order; -import org.junit.Test; -import org.junit.runner.RunWith; - -@RunWith(FeatureRunner.class) -@Named("Scenario: Blinker 2") -@SuppressWarnings("all") -public class PlayingGameOfLifeFeatureBlinker2 extends PlayingGameOfLifeFeature { - World world; - - @Test - @Order(0) - @Named("Given a world") - public void _givenAWorld() { - final StepArguments args = new StepArguments("-----\n-----\n-XXX-\n-----\n-----\n"); - String _first = JnarioIterableExtensions.first(args); - World _parseWorld = World.parseWorld(_first); - this.world = _parseWorld; - } - - @Test - @Order(1) - @Named("Then the world evolves into") - public void _thenTheWorldEvolvesInto() { - final StepArguments args = new StepArguments("-----\n--X--\n--X--\n--X--\n-----\n"); - Evolution _gameOfLife = Evolution.gameOfLife(); - World _evolve = _gameOfLife.evolve(this.world); - this.world = _evolve; - String _first = JnarioIterableExtensions.first(args); - World _parseWorld = World.parseWorld(_first); - Should.operator_doubleArrow(this.world, _parseWorld); - } -} +package gameoflife.features; + +import gameoflife.Evolution; +import gameoflife.World; +import gameoflife.features.PlayingGameOfLifeFeature; +import org.jnario.lib.JnarioIterableExtensions; +import org.jnario.lib.Should; +import org.jnario.lib.StepArguments; +import org.jnario.runner.FeatureRunner; +import org.jnario.runner.Named; +import org.jnario.runner.Order; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(FeatureRunner.class) +@Named("Scenario: Blinker 2") +@SuppressWarnings("all") +public class PlayingGameOfLifeFeatureBlinker2 extends PlayingGameOfLifeFeature { + World world; + + @Test + @Order(0) + @Named("Given a world") + public void _givenAWorld() { + final StepArguments args = new StepArguments("-----\n-----\n-XXX-\n-----\n-----\n"); + this.world = World.parseWorld(JnarioIterableExtensions.first(args)); + } + + @Test + @Order(1) + @Named("Then the world evolves into") + public void _thenTheWorldEvolvesInto() { + final StepArguments args = new StepArguments("-----\n--X--\n--X--\n--X--\n-----\n"); + this.world = Evolution.gameOfLife().evolve(this.world); + World _parseWorld = World.parseWorld(JnarioIterableExtensions.first(args)); + Should.operator_doubleArrow(this.world, _parseWorld); + } +} diff --git a/examples/org.jnario.examples/xtend-gen/gameoflife/features/PlayingGameOfLifeFeatureBox.java b/examples/org.jnario.examples/xtend-gen/gameoflife/features/PlayingGameOfLifeFeatureBox.java index fd604f284..033785d0c 100644 --- a/examples/org.jnario.examples/xtend-gen/gameoflife/features/PlayingGameOfLifeFeatureBox.java +++ b/examples/org.jnario.examples/xtend-gen/gameoflife/features/PlayingGameOfLifeFeatureBox.java @@ -1,50 +1,45 @@ -package gameoflife.features; - -import gameoflife.Evolution; -import gameoflife.World; -import gameoflife.features.PlayingGameOfLifeFeature; -import org.jnario.lib.Assert; -import org.jnario.lib.JnarioIterableExtensions; -import org.jnario.lib.Should; -import org.jnario.lib.StepArguments; -import org.jnario.runner.FeatureRunner; -import org.jnario.runner.Named; -import org.jnario.runner.Order; -import org.junit.Test; -import org.junit.runner.RunWith; - -@RunWith(FeatureRunner.class) -@Named("Scenario: Box") -@SuppressWarnings("all") -public class PlayingGameOfLifeFeatureBox extends PlayingGameOfLifeFeature { - World world; - - @Test - @Order(0) - @Named("Given a world") - public void _givenAWorld() { - final StepArguments args = new StepArguments("------\n--XX--\n--XX--\n------ \n"); - String _first = JnarioIterableExtensions.first(args); - World _parseWorld = World.parseWorld(_first); - this.world = _parseWorld; - } - - @Test - @Order(1) - @Named("Then the world evolves into") - public void _thenTheWorldEvolvesInto() { - final StepArguments args = new StepArguments("------\n--XX--\n--XX--\n------\n"); - Evolution _gameOfLife = Evolution.gameOfLife(); - World _evolve = _gameOfLife.evolve(this.world); - this.world = _evolve; - String _first = JnarioIterableExtensions.first(args); - World _parseWorld = World.parseWorld(_first); - Assert.assertTrue("\nExpected world => parseWorld(args.first) but" - + "\n world is " + new org.hamcrest.StringDescription().appendValue(this.world).toString() - + "\n parseWorld(args.first) is " + new org.hamcrest.StringDescription().appendValue(_parseWorld).toString() - + "\n args.first is " + new org.hamcrest.StringDescription().appendValue(_first).toString() - + "\n args is " + new org.hamcrest.StringDescription().appendValue(args).toString() + "\n", Should.operator_doubleArrow( - this.world, _parseWorld)); - - } -} +package gameoflife.features; + +import gameoflife.Evolution; +import gameoflife.World; +import gameoflife.features.PlayingGameOfLifeFeature; +import org.jnario.lib.Assert; +import org.jnario.lib.JnarioIterableExtensions; +import org.jnario.lib.Should; +import org.jnario.lib.StepArguments; +import org.jnario.runner.FeatureRunner; +import org.jnario.runner.Named; +import org.jnario.runner.Order; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(FeatureRunner.class) +@Named("Scenario: Box") +@SuppressWarnings("all") +public class PlayingGameOfLifeFeatureBox extends PlayingGameOfLifeFeature { + World world; + + @Test + @Order(0) + @Named("Given a world") + public void _givenAWorld() { + final StepArguments args = new StepArguments("------\n--XX--\n--XX--\n------ \n"); + this.world = World.parseWorld(JnarioIterableExtensions.first(args)); + } + + @Test + @Order(1) + @Named("Then the world evolves into") + public void _thenTheWorldEvolvesInto() { + final StepArguments args = new StepArguments("------\n--XX--\n--XX--\n------\n"); + this.world = Evolution.gameOfLife().evolve(this.world); + World _parseWorld = World.parseWorld(JnarioIterableExtensions.first(args)); + Assert.assertTrue("\nExpected world => parseWorld(args.first) but" + + "\n world is " + new org.hamcrest.StringDescription().appendValue(this.world).toString() + + "\n parseWorld(args.first) is " + new org.hamcrest.StringDescription().appendValue(_parseWorld).toString() + + "\n args.first is " + new org.hamcrest.StringDescription().appendValue(JnarioIterableExtensions.first(args)).toString() + + "\n args is " + new org.hamcrest.StringDescription().appendValue(args).toString() + "\n", Should.operator_doubleArrow( + this.world, _parseWorld)); + + } +} diff --git a/examples/org.jnario.examples/xtend-gen/gameoflife/specs/CellLocationCalculatingRelativeCellLocationsSpec.java b/examples/org.jnario.examples/xtend-gen/gameoflife/specs/CellLocationCalculatingRelativeCellLocationsSpec.java index ae97b1f52..9423df661 100644 --- a/examples/org.jnario.examples/xtend-gen/gameoflife/specs/CellLocationCalculatingRelativeCellLocationsSpec.java +++ b/examples/org.jnario.examples/xtend-gen/gameoflife/specs/CellLocationCalculatingRelativeCellLocationsSpec.java @@ -1,34 +1,32 @@ -package gameoflife.specs; - -import gameoflife.CellLocation; -import gameoflife.specs.CellLocationSpec; -import org.jnario.lib.Assert; -import org.jnario.lib.Should; -import org.jnario.runner.ExampleGroupRunner; -import org.jnario.runner.Named; -import org.jnario.runner.Order; -import org.junit.Test; -import org.junit.runner.RunWith; - -@Named("Calculating relative cell locations") -@RunWith(ExampleGroupRunner.class) -@SuppressWarnings("all") -public class CellLocationCalculatingRelativeCellLocationsSpec extends CellLocationSpec { - @Test - @Named("cell[-1, 1].plus[cell[3,4]] => cell[2,5]") - @Order(1) - public void _cell11PlusCell34Cell25() throws Exception { - CellLocation _cell = CellLocation.cell((-1), 1); - CellLocation _cell_1 = CellLocation.cell(3, 4); - CellLocation _plus = _cell.plus(_cell_1); - CellLocation _cell_2 = CellLocation.cell(2, 5); - boolean _doubleArrow = Should.operator_doubleArrow(_plus, _cell_2); - Assert.assertTrue("\nExpected cell(-1, 1).plus(cell(3,4)) => cell(2,5) but" - + "\n cell(-1, 1).plus(cell(3,4)) is " + new org.hamcrest.StringDescription().appendValue(_plus).toString() - + "\n cell(-1, 1) is " + new org.hamcrest.StringDescription().appendValue(_cell).toString() - + "\n -1 is " + new org.hamcrest.StringDescription().appendValue((-1)).toString() - + "\n cell(3,4) is " + new org.hamcrest.StringDescription().appendValue(_cell_1).toString() - + "\n cell(2,5) is " + new org.hamcrest.StringDescription().appendValue(_cell_2).toString() + "\n", _doubleArrow); - - } -} +package gameoflife.specs; + +import gameoflife.CellLocation; +import gameoflife.specs.CellLocationSpec; +import org.jnario.lib.Assert; +import org.jnario.lib.Should; +import org.jnario.runner.ExampleGroupRunner; +import org.jnario.runner.Named; +import org.jnario.runner.Order; +import org.junit.Test; +import org.junit.runner.RunWith; + +@Named("Calculating relative cell locations") +@RunWith(ExampleGroupRunner.class) +@SuppressWarnings("all") +public class CellLocationCalculatingRelativeCellLocationsSpec extends CellLocationSpec { + @Test + @Named("cell[-1, 1].plus[cell[3,4]] => cell[2,5]") + @Order(1) + public void _cell11PlusCell34Cell25() throws Exception { + CellLocation _plus = CellLocation.cell((-1), 1).plus(CellLocation.cell(3, 4)); + CellLocation _cell = CellLocation.cell(2, 5); + boolean _doubleArrow = Should.operator_doubleArrow(_plus, _cell); + Assert.assertTrue("\nExpected cell(-1, 1).plus(cell(3,4)) => cell(2,5) but" + + "\n cell(-1, 1).plus(cell(3,4)) is " + new org.hamcrest.StringDescription().appendValue(_plus).toString() + + "\n cell(-1, 1) is " + new org.hamcrest.StringDescription().appendValue(CellLocation.cell((-1), 1)).toString() + + "\n -1 is " + new org.hamcrest.StringDescription().appendValue((-1)).toString() + + "\n cell(3,4) is " + new org.hamcrest.StringDescription().appendValue(CellLocation.cell(3, 4)).toString() + + "\n cell(2,5) is " + new org.hamcrest.StringDescription().appendValue(_cell).toString() + "\n", _doubleArrow); + + } +} diff --git a/examples/org.jnario.examples/xtend-gen/gameoflife/specs/CellLocationCellNeighboursSpec.java b/examples/org.jnario.examples/xtend-gen/gameoflife/specs/CellLocationCellNeighboursSpec.java index aeaa54645..f51fc2bd0 100644 --- a/examples/org.jnario.examples/xtend-gen/gameoflife/specs/CellLocationCellNeighboursSpec.java +++ b/examples/org.jnario.examples/xtend-gen/gameoflife/specs/CellLocationCellNeighboursSpec.java @@ -1,40 +1,35 @@ -package gameoflife.specs; - -import gameoflife.CellLocation; -import gameoflife.specs.CellLocationSpec; -import java.util.Set; -import org.jnario.lib.Assert; -import org.jnario.lib.JnarioCollectionLiterals; -import org.jnario.lib.Should; -import org.jnario.runner.ExampleGroupRunner; -import org.jnario.runner.Named; -import org.jnario.runner.Order; -import org.junit.Test; -import org.junit.runner.RunWith; - -@Named("cell neighbours") -@RunWith(ExampleGroupRunner.class) -@SuppressWarnings("all") -public class CellLocationCellNeighboursSpec extends CellLocationSpec { - @Test - @Named("are adjacent cells") - @Order(1) - public void _areAdjacentCells() throws Exception { - final CellLocation cell = CellLocation.cell(5, 5); - CellLocation _cell = CellLocation.cell(4, 6); - CellLocation _cell_1 = CellLocation.cell(5, 6); - CellLocation _cell_2 = CellLocation.cell(6, 6); - CellLocation _cell_3 = CellLocation.cell(4, 5); - CellLocation _cell_4 = CellLocation.cell(6, 5); - CellLocation _cell_5 = CellLocation.cell(4, 4); - CellLocation _cell_6 = CellLocation.cell(5, 4); - CellLocation _cell_7 = CellLocation.cell(6, 4); - final Set expectedNeighbours = JnarioCollectionLiterals.set(_cell, _cell_1, _cell_2, _cell_3, _cell_4, _cell_5, _cell_6, _cell_7); - Set _neighbours = cell.neighbours(); - Assert.assertTrue("\nExpected cell.neighbours => expectedNeighbours but" - + "\n cell.neighbours is " + new org.hamcrest.StringDescription().appendValue(_neighbours).toString() - + "\n cell is " + new org.hamcrest.StringDescription().appendValue(cell).toString() - + "\n expectedNeighbours is " + new org.hamcrest.StringDescription().appendValue(expectedNeighbours).toString() + "\n", Should.>operator_doubleArrow(_neighbours, expectedNeighbours)); - - } -} +package gameoflife.specs; + +import gameoflife.CellLocation; +import gameoflife.specs.CellLocationSpec; +import java.util.Set; +import org.jnario.lib.Assert; +import org.jnario.lib.JnarioCollectionLiterals; +import org.jnario.lib.Should; +import org.jnario.runner.ExampleGroupRunner; +import org.jnario.runner.Named; +import org.jnario.runner.Order; +import org.junit.Test; +import org.junit.runner.RunWith; + +@Named("cell neighbours") +@RunWith(ExampleGroupRunner.class) +@SuppressWarnings("all") +public class CellLocationCellNeighboursSpec extends CellLocationSpec { + @Test + @Named("are adjacent cells") + @Order(1) + public void _areAdjacentCells() throws Exception { + final CellLocation cell = CellLocation.cell(5, 5); + final Set expectedNeighbours = JnarioCollectionLiterals.set( + CellLocation.cell(4, 6), CellLocation.cell(5, 6), CellLocation.cell(6, 6), + CellLocation.cell(4, 5), CellLocation.cell(6, 5), + CellLocation.cell(4, 4), CellLocation.cell(5, 4), CellLocation.cell(6, 4)); + Set _neighbours = cell.neighbours(); + Assert.assertTrue("\nExpected cell.neighbours => expectedNeighbours but" + + "\n cell.neighbours is " + new org.hamcrest.StringDescription().appendValue(_neighbours).toString() + + "\n cell is " + new org.hamcrest.StringDescription().appendValue(cell).toString() + + "\n expectedNeighbours is " + new org.hamcrest.StringDescription().appendValue(expectedNeighbours).toString() + "\n", Should.>operator_doubleArrow(_neighbours, expectedNeighbours)); + + } +} diff --git a/examples/org.jnario.examples/xtend-gen/gameoflife/specs/EvolutionDeadCellsSpec.java b/examples/org.jnario.examples/xtend-gen/gameoflife/specs/EvolutionDeadCellsSpec.java index 7af0b6bd4..3f692808f 100644 --- a/examples/org.jnario.examples/xtend-gen/gameoflife/specs/EvolutionDeadCellsSpec.java +++ b/examples/org.jnario.examples/xtend-gen/gameoflife/specs/EvolutionDeadCellsSpec.java @@ -1,45 +1,43 @@ -package gameoflife.specs; - -import gameoflife.CellLocation; -import gameoflife.Evolution; -import gameoflife.Rule; -import gameoflife.World; -import gameoflife.specs.EvolutionSpec; -import java.util.Set; -import org.jnario.lib.Assert; -import org.jnario.lib.Should; -import org.jnario.runner.ExampleGroupRunner; -import org.jnario.runner.Named; -import org.jnario.runner.Order; -import org.junit.Test; -import org.junit.runner.RunWith; - -@Named("dead cells") -@RunWith(ExampleGroupRunner.class) -@SuppressWarnings("all") -public class EvolutionDeadCellsSpec extends EvolutionSpec { - final Rule allDeadLive = new Rule() { - @Override - public boolean becomesAlive(final int it) { - return true; - } - }; - - @Test - @Named("become alive if rule says so") - @Order(1) - public void _becomeAliveIfRuleSaysSo() throws Exception { - final Evolution evolution = new Evolution(this.dontCare, this.allDeadLive); - World _evolve = evolution.evolve(this.worldWithLiveCell); - Set _livingCells = _evolve.getLivingCells(); - Set _neighbours = this.livingCell.neighbours(); - Assert.assertTrue("\nExpected evolution.evolve(worldWithLiveCell).livingCells => livingCell.neighbours but" - + "\n evolution.evolve(worldWithLiveCell).livingCells is " + new org.hamcrest.StringDescription().appendValue(_livingCells).toString() - + "\n evolution.evolve(worldWithLiveCell) is " + new org.hamcrest.StringDescription().appendValue(_evolve).toString() - + "\n evolution is " + new org.hamcrest.StringDescription().appendValue(evolution).toString() - + "\n worldWithLiveCell is " + new org.hamcrest.StringDescription().appendValue(this.worldWithLiveCell).toString() - + "\n livingCell.neighbours is " + new org.hamcrest.StringDescription().appendValue(_neighbours).toString() - + "\n livingCell is " + new org.hamcrest.StringDescription().appendValue(this.livingCell).toString() + "\n", Should.>operator_doubleArrow(_livingCells, _neighbours)); - - } -} +package gameoflife.specs; + +import gameoflife.CellLocation; +import gameoflife.Evolution; +import gameoflife.Rule; +import gameoflife.specs.EvolutionSpec; +import java.util.Set; +import org.jnario.lib.Assert; +import org.jnario.lib.Should; +import org.jnario.runner.ExampleGroupRunner; +import org.jnario.runner.Named; +import org.jnario.runner.Order; +import org.junit.Test; +import org.junit.runner.RunWith; + +@Named("dead cells") +@RunWith(ExampleGroupRunner.class) +@SuppressWarnings("all") +public class EvolutionDeadCellsSpec extends EvolutionSpec { + final Rule allDeadLive = new Rule() { + @Override + public boolean becomesAlive(final int it) { + return true; + } + }; + + @Test + @Named("become alive if rule says so") + @Order(1) + public void _becomeAliveIfRuleSaysSo() throws Exception { + final Evolution evolution = new Evolution(this.dontCare, this.allDeadLive); + Set _livingCells = evolution.evolve(this.worldWithLiveCell).getLivingCells(); + Set _neighbours = this.livingCell.neighbours(); + Assert.assertTrue("\nExpected evolution.evolve(worldWithLiveCell).livingCells => livingCell.neighbours but" + + "\n evolution.evolve(worldWithLiveCell).livingCells is " + new org.hamcrest.StringDescription().appendValue(_livingCells).toString() + + "\n evolution.evolve(worldWithLiveCell) is " + new org.hamcrest.StringDescription().appendValue(evolution.evolve(this.worldWithLiveCell)).toString() + + "\n evolution is " + new org.hamcrest.StringDescription().appendValue(evolution).toString() + + "\n worldWithLiveCell is " + new org.hamcrest.StringDescription().appendValue(this.worldWithLiveCell).toString() + + "\n livingCell.neighbours is " + new org.hamcrest.StringDescription().appendValue(_neighbours).toString() + + "\n livingCell is " + new org.hamcrest.StringDescription().appendValue(this.livingCell).toString() + "\n", Should.>operator_doubleArrow(_livingCells, _neighbours)); + + } +} diff --git a/examples/org.jnario.examples/xtend-gen/gameoflife/specs/EvolutionLiveCellsSpec.java b/examples/org.jnario.examples/xtend-gen/gameoflife/specs/EvolutionLiveCellsSpec.java index 6bd57899e..bdc73e8cc 100644 --- a/examples/org.jnario.examples/xtend-gen/gameoflife/specs/EvolutionLiveCellsSpec.java +++ b/examples/org.jnario.examples/xtend-gen/gameoflife/specs/EvolutionLiveCellsSpec.java @@ -1,46 +1,44 @@ -package gameoflife.specs; - -import gameoflife.CellLocation; -import gameoflife.Evolution; -import gameoflife.Rule; -import gameoflife.World; -import gameoflife.specs.EvolutionSpec; -import java.util.Set; -import org.jnario.lib.Assert; -import org.jnario.lib.JnarioCollectionLiterals; -import org.jnario.lib.Should; -import org.jnario.runner.ExampleGroupRunner; -import org.jnario.runner.Named; -import org.jnario.runner.Order; -import org.junit.Test; -import org.junit.runner.RunWith; - -@Named("live cells") -@RunWith(ExampleGroupRunner.class) -@SuppressWarnings("all") -public class EvolutionLiveCellsSpec extends EvolutionSpec { - final Rule allLiveStayAlive = new Rule() { - @Override - public boolean becomesAlive(final int it) { - return true; - } - }; - - @Test - @Named("stay alive if rule says so") - @Order(1) - public void _stayAliveIfRuleSaysSo() throws Exception { - final Evolution evolution = new Evolution(this.allLiveStayAlive, this.dontCare); - World _evolve = evolution.evolve(this.worldWithLiveCell); - Set _livingCells = _evolve.getLivingCells(); - Set _set = JnarioCollectionLiterals.set(this.livingCell); - Assert.assertTrue("\nExpected evolution.evolve(worldWithLiveCell).livingCells => set(livingCell) but" - + "\n evolution.evolve(worldWithLiveCell).livingCells is " + new org.hamcrest.StringDescription().appendValue(_livingCells).toString() - + "\n evolution.evolve(worldWithLiveCell) is " + new org.hamcrest.StringDescription().appendValue(_evolve).toString() - + "\n evolution is " + new org.hamcrest.StringDescription().appendValue(evolution).toString() - + "\n worldWithLiveCell is " + new org.hamcrest.StringDescription().appendValue(this.worldWithLiveCell).toString() - + "\n set(livingCell) is " + new org.hamcrest.StringDescription().appendValue(_set).toString() - + "\n livingCell is " + new org.hamcrest.StringDescription().appendValue(this.livingCell).toString() + "\n", Should.>operator_doubleArrow(_livingCells, _set)); - - } -} +package gameoflife.specs; + +import gameoflife.CellLocation; +import gameoflife.Evolution; +import gameoflife.Rule; +import gameoflife.specs.EvolutionSpec; +import java.util.Set; +import org.jnario.lib.Assert; +import org.jnario.lib.JnarioCollectionLiterals; +import org.jnario.lib.Should; +import org.jnario.runner.ExampleGroupRunner; +import org.jnario.runner.Named; +import org.jnario.runner.Order; +import org.junit.Test; +import org.junit.runner.RunWith; + +@Named("live cells") +@RunWith(ExampleGroupRunner.class) +@SuppressWarnings("all") +public class EvolutionLiveCellsSpec extends EvolutionSpec { + final Rule allLiveStayAlive = new Rule() { + @Override + public boolean becomesAlive(final int it) { + return true; + } + }; + + @Test + @Named("stay alive if rule says so") + @Order(1) + public void _stayAliveIfRuleSaysSo() throws Exception { + final Evolution evolution = new Evolution(this.allLiveStayAlive, this.dontCare); + Set _livingCells = evolution.evolve(this.worldWithLiveCell).getLivingCells(); + Set _set = JnarioCollectionLiterals.set(this.livingCell); + Assert.assertTrue("\nExpected evolution.evolve(worldWithLiveCell).livingCells => set(livingCell) but" + + "\n evolution.evolve(worldWithLiveCell).livingCells is " + new org.hamcrest.StringDescription().appendValue(_livingCells).toString() + + "\n evolution.evolve(worldWithLiveCell) is " + new org.hamcrest.StringDescription().appendValue(evolution.evolve(this.worldWithLiveCell)).toString() + + "\n evolution is " + new org.hamcrest.StringDescription().appendValue(evolution).toString() + + "\n worldWithLiveCell is " + new org.hamcrest.StringDescription().appendValue(this.worldWithLiveCell).toString() + + "\n set(livingCell) is " + new org.hamcrest.StringDescription().appendValue(_set).toString() + + "\n livingCell is " + new org.hamcrest.StringDescription().appendValue(this.livingCell).toString() + "\n", Should.>operator_doubleArrow(_livingCells, _set)); + + } +} diff --git a/examples/org.jnario.examples/xtend-gen/gameoflife/specs/RulesEvolveDeadCellsSpec.java b/examples/org.jnario.examples/xtend-gen/gameoflife/specs/RulesEvolveDeadCellsSpec.java index 471f1c271..be070b4b3 100644 --- a/examples/org.jnario.examples/xtend-gen/gameoflife/specs/RulesEvolveDeadCellsSpec.java +++ b/examples/org.jnario.examples/xtend-gen/gameoflife/specs/RulesEvolveDeadCellsSpec.java @@ -1,81 +1,80 @@ -package gameoflife.specs; - -import gameoflife.EvolveDeadCells; -import gameoflife.specs.RulesEvolveDeadCellsSpecDeadcells; -import gameoflife.specs.RulesSpec; -import java.util.Arrays; -import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; -import org.jnario.lib.Assert; -import org.jnario.lib.Each; -import org.jnario.lib.ExampleTable; -import org.jnario.lib.Should; -import org.jnario.runner.ExampleGroupRunner; -import org.jnario.runner.Named; -import org.jnario.runner.Order; -import org.jnario.runner.Subject; -import org.junit.Test; -import org.junit.runner.RunWith; - -@Named("EvolveDeadCells") -@RunWith(ExampleGroupRunner.class) -@SuppressWarnings("all") -public class RulesEvolveDeadCellsSpec extends RulesSpec { - @Subject - public EvolveDeadCells subject; - - public ExampleTable _initRulesEvolveDeadCellsSpecDeadcells() { - return ExampleTable.create("deadcells", - Arrays.asList("liveNeighbourCount", "result"), - new RulesEvolveDeadCellsSpecDeadcells( Arrays.asList("2", "false"), _initRulesEvolveDeadCellsSpecDeadcellsCell0(), _initRulesEvolveDeadCellsSpecDeadcellsCell1()), - new RulesEvolveDeadCellsSpecDeadcells( Arrays.asList("3", "true"), _initRulesEvolveDeadCellsSpecDeadcellsCell2(), _initRulesEvolveDeadCellsSpecDeadcellsCell3()), - new RulesEvolveDeadCellsSpecDeadcells( Arrays.asList("4", "false"), _initRulesEvolveDeadCellsSpecDeadcellsCell4(), _initRulesEvolveDeadCellsSpecDeadcellsCell5()) - ); - } - - protected ExampleTable deadcells = _initRulesEvolveDeadCellsSpecDeadcells(); - - public int _initRulesEvolveDeadCellsSpecDeadcellsCell0() { - return 2; - } - - public boolean _initRulesEvolveDeadCellsSpecDeadcellsCell1() { - return false; - } - - public int _initRulesEvolveDeadCellsSpecDeadcellsCell2() { - return 3; - } - - public boolean _initRulesEvolveDeadCellsSpecDeadcellsCell3() { - return true; - } - - public int _initRulesEvolveDeadCellsSpecDeadcellsCell4() { - return 4; - } - - public boolean _initRulesEvolveDeadCellsSpecDeadcellsCell5() { - return false; - } - - @Test - @Named("deadcells.forEach[ subject.becomesAlive[liveNeighbourCount] => result ]") - @Order(1) - public void _deadcellsForEachSubjectBecomesAliveLiveNeighbourCountResult() throws Exception { - final Procedure1 _function = new Procedure1() { - @Override - public void apply(final RulesEvolveDeadCellsSpecDeadcells it) { - int _liveNeighbourCount = it.getLiveNeighbourCount(); - boolean _becomesAlive = RulesEvolveDeadCellsSpec.this.subject.becomesAlive(_liveNeighbourCount); - boolean _result = it.getResult(); - Assert.assertTrue("\nExpected subject.becomesAlive(liveNeighbourCount) => result but" - + "\n subject.becomesAlive(liveNeighbourCount) is " + new org.hamcrest.StringDescription().appendValue(Boolean.valueOf(_becomesAlive)).toString() - + "\n subject is " + new org.hamcrest.StringDescription().appendValue(RulesEvolveDeadCellsSpec.this.subject).toString() - + "\n liveNeighbourCount is " + new org.hamcrest.StringDescription().appendValue(_liveNeighbourCount).toString() - + "\n result is " + new org.hamcrest.StringDescription().appendValue(_result).toString() + "\n", Should.operator_doubleArrow(Boolean.valueOf(_becomesAlive), _result)); - - } - }; - Each.forEach(this.deadcells, _function); - } -} +package gameoflife.specs; + +import gameoflife.EvolveDeadCells; +import gameoflife.specs.RulesEvolveDeadCellsSpecDeadcells; +import gameoflife.specs.RulesSpec; +import java.util.Arrays; +import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; +import org.jnario.lib.Assert; +import org.jnario.lib.Each; +import org.jnario.lib.ExampleTable; +import org.jnario.lib.Should; +import org.jnario.runner.ExampleGroupRunner; +import org.jnario.runner.Named; +import org.jnario.runner.Order; +import org.jnario.runner.Subject; +import org.junit.Test; +import org.junit.runner.RunWith; + +@Named("EvolveDeadCells") +@RunWith(ExampleGroupRunner.class) +@SuppressWarnings("all") +public class RulesEvolveDeadCellsSpec extends RulesSpec { + @Subject + public EvolveDeadCells subject; + + public ExampleTable _initRulesEvolveDeadCellsSpecDeadcells() { + return ExampleTable.create("deadcells", + Arrays.asList("liveNeighbourCount", "result"), + new RulesEvolveDeadCellsSpecDeadcells( Arrays.asList("2", "false"), _initRulesEvolveDeadCellsSpecDeadcellsCell0(), _initRulesEvolveDeadCellsSpecDeadcellsCell1()), + new RulesEvolveDeadCellsSpecDeadcells( Arrays.asList("3", "true"), _initRulesEvolveDeadCellsSpecDeadcellsCell2(), _initRulesEvolveDeadCellsSpecDeadcellsCell3()), + new RulesEvolveDeadCellsSpecDeadcells( Arrays.asList("4", "false"), _initRulesEvolveDeadCellsSpecDeadcellsCell4(), _initRulesEvolveDeadCellsSpecDeadcellsCell5()) + ); + } + + protected ExampleTable deadcells = _initRulesEvolveDeadCellsSpecDeadcells(); + + public int _initRulesEvolveDeadCellsSpecDeadcellsCell0() { + return 2; + } + + public boolean _initRulesEvolveDeadCellsSpecDeadcellsCell1() { + return false; + } + + public int _initRulesEvolveDeadCellsSpecDeadcellsCell2() { + return 3; + } + + public boolean _initRulesEvolveDeadCellsSpecDeadcellsCell3() { + return true; + } + + public int _initRulesEvolveDeadCellsSpecDeadcellsCell4() { + return 4; + } + + public boolean _initRulesEvolveDeadCellsSpecDeadcellsCell5() { + return false; + } + + @Test + @Named("deadcells.forEach[ subject.becomesAlive[liveNeighbourCount] => result ]") + @Order(1) + public void _deadcellsForEachSubjectBecomesAliveLiveNeighbourCountResult() throws Exception { + final Procedure1 _function = new Procedure1() { + @Override + public void apply(final RulesEvolveDeadCellsSpecDeadcells it) { + boolean _becomesAlive = RulesEvolveDeadCellsSpec.this.subject.becomesAlive(it.getLiveNeighbourCount()); + boolean _result = it.getResult(); + Assert.assertTrue("\nExpected subject.becomesAlive(liveNeighbourCount) => result but" + + "\n subject.becomesAlive(liveNeighbourCount) is " + new org.hamcrest.StringDescription().appendValue(Boolean.valueOf(_becomesAlive)).toString() + + "\n subject is " + new org.hamcrest.StringDescription().appendValue(RulesEvolveDeadCellsSpec.this.subject).toString() + + "\n liveNeighbourCount is " + new org.hamcrest.StringDescription().appendValue(it.getLiveNeighbourCount()).toString() + + "\n result is " + new org.hamcrest.StringDescription().appendValue(_result).toString() + "\n", Should.operator_doubleArrow(Boolean.valueOf(_becomesAlive), _result)); + + } + }; + Each.forEach(this.deadcells, _function); + } +} diff --git a/examples/org.jnario.examples/xtend-gen/gameoflife/specs/RulesEvolveLiveCellsSpec.java b/examples/org.jnario.examples/xtend-gen/gameoflife/specs/RulesEvolveLiveCellsSpec.java index ac9537a28..afa5b3378 100644 --- a/examples/org.jnario.examples/xtend-gen/gameoflife/specs/RulesEvolveLiveCellsSpec.java +++ b/examples/org.jnario.examples/xtend-gen/gameoflife/specs/RulesEvolveLiveCellsSpec.java @@ -1,90 +1,89 @@ -package gameoflife.specs; - -import gameoflife.EvolveLiveCells; -import gameoflife.specs.RulesEvolveLiveCellsSpecLiveCells; -import gameoflife.specs.RulesSpec; -import java.util.Arrays; -import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; -import org.jnario.lib.Assert; -import org.jnario.lib.Each; -import org.jnario.lib.ExampleTable; -import org.jnario.lib.Should; -import org.jnario.runner.ExampleGroupRunner; -import org.jnario.runner.Named; -import org.jnario.runner.Order; -import org.jnario.runner.Subject; -import org.junit.Test; -import org.junit.runner.RunWith; - -@Named("EvolveLiveCells") -@RunWith(ExampleGroupRunner.class) -@SuppressWarnings("all") -public class RulesEvolveLiveCellsSpec extends RulesSpec { - @Subject - public EvolveLiveCells subject; - - public ExampleTable _initRulesEvolveLiveCellsSpecLiveCells() { - return ExampleTable.create("liveCells", - Arrays.asList("liveNeighbourCount", "result"), - new RulesEvolveLiveCellsSpecLiveCells( Arrays.asList("1", "false"), _initRulesEvolveLiveCellsSpecLiveCellsCell0(), _initRulesEvolveLiveCellsSpecLiveCellsCell1()), - new RulesEvolveLiveCellsSpecLiveCells( Arrays.asList("2", "true"), _initRulesEvolveLiveCellsSpecLiveCellsCell2(), _initRulesEvolveLiveCellsSpecLiveCellsCell3()), - new RulesEvolveLiveCellsSpecLiveCells( Arrays.asList("3", "true"), _initRulesEvolveLiveCellsSpecLiveCellsCell4(), _initRulesEvolveLiveCellsSpecLiveCellsCell5()), - new RulesEvolveLiveCellsSpecLiveCells( Arrays.asList("4", "false"), _initRulesEvolveLiveCellsSpecLiveCellsCell6(), _initRulesEvolveLiveCellsSpecLiveCellsCell7()) - ); - } - - protected ExampleTable liveCells = _initRulesEvolveLiveCellsSpecLiveCells(); - - public int _initRulesEvolveLiveCellsSpecLiveCellsCell0() { - return 1; - } - - public boolean _initRulesEvolveLiveCellsSpecLiveCellsCell1() { - return false; - } - - public int _initRulesEvolveLiveCellsSpecLiveCellsCell2() { - return 2; - } - - public boolean _initRulesEvolveLiveCellsSpecLiveCellsCell3() { - return true; - } - - public int _initRulesEvolveLiveCellsSpecLiveCellsCell4() { - return 3; - } - - public boolean _initRulesEvolveLiveCellsSpecLiveCellsCell5() { - return true; - } - - public int _initRulesEvolveLiveCellsSpecLiveCellsCell6() { - return 4; - } - - public boolean _initRulesEvolveLiveCellsSpecLiveCellsCell7() { - return false; - } - - @Test - @Named("liveCells.forEach[ subject.becomesAlive[liveNeighbourCount] => result ]") - @Order(1) - public void _liveCellsForEachSubjectBecomesAliveLiveNeighbourCountResult() throws Exception { - final Procedure1 _function = new Procedure1() { - @Override - public void apply(final RulesEvolveLiveCellsSpecLiveCells it) { - int _liveNeighbourCount = it.getLiveNeighbourCount(); - boolean _becomesAlive = RulesEvolveLiveCellsSpec.this.subject.becomesAlive(_liveNeighbourCount); - boolean _result = it.getResult(); - Assert.assertTrue("\nExpected subject.becomesAlive(liveNeighbourCount) => result but" - + "\n subject.becomesAlive(liveNeighbourCount) is " + new org.hamcrest.StringDescription().appendValue(Boolean.valueOf(_becomesAlive)).toString() - + "\n subject is " + new org.hamcrest.StringDescription().appendValue(RulesEvolveLiveCellsSpec.this.subject).toString() - + "\n liveNeighbourCount is " + new org.hamcrest.StringDescription().appendValue(_liveNeighbourCount).toString() - + "\n result is " + new org.hamcrest.StringDescription().appendValue(_result).toString() + "\n", Should.operator_doubleArrow(Boolean.valueOf(_becomesAlive), _result)); - - } - }; - Each.forEach(this.liveCells, _function); - } -} +package gameoflife.specs; + +import gameoflife.EvolveLiveCells; +import gameoflife.specs.RulesEvolveLiveCellsSpecLiveCells; +import gameoflife.specs.RulesSpec; +import java.util.Arrays; +import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; +import org.jnario.lib.Assert; +import org.jnario.lib.Each; +import org.jnario.lib.ExampleTable; +import org.jnario.lib.Should; +import org.jnario.runner.ExampleGroupRunner; +import org.jnario.runner.Named; +import org.jnario.runner.Order; +import org.jnario.runner.Subject; +import org.junit.Test; +import org.junit.runner.RunWith; + +@Named("EvolveLiveCells") +@RunWith(ExampleGroupRunner.class) +@SuppressWarnings("all") +public class RulesEvolveLiveCellsSpec extends RulesSpec { + @Subject + public EvolveLiveCells subject; + + public ExampleTable _initRulesEvolveLiveCellsSpecLiveCells() { + return ExampleTable.create("liveCells", + Arrays.asList("liveNeighbourCount", "result"), + new RulesEvolveLiveCellsSpecLiveCells( Arrays.asList("1", "false"), _initRulesEvolveLiveCellsSpecLiveCellsCell0(), _initRulesEvolveLiveCellsSpecLiveCellsCell1()), + new RulesEvolveLiveCellsSpecLiveCells( Arrays.asList("2", "true"), _initRulesEvolveLiveCellsSpecLiveCellsCell2(), _initRulesEvolveLiveCellsSpecLiveCellsCell3()), + new RulesEvolveLiveCellsSpecLiveCells( Arrays.asList("3", "true"), _initRulesEvolveLiveCellsSpecLiveCellsCell4(), _initRulesEvolveLiveCellsSpecLiveCellsCell5()), + new RulesEvolveLiveCellsSpecLiveCells( Arrays.asList("4", "false"), _initRulesEvolveLiveCellsSpecLiveCellsCell6(), _initRulesEvolveLiveCellsSpecLiveCellsCell7()) + ); + } + + protected ExampleTable liveCells = _initRulesEvolveLiveCellsSpecLiveCells(); + + public int _initRulesEvolveLiveCellsSpecLiveCellsCell0() { + return 1; + } + + public boolean _initRulesEvolveLiveCellsSpecLiveCellsCell1() { + return false; + } + + public int _initRulesEvolveLiveCellsSpecLiveCellsCell2() { + return 2; + } + + public boolean _initRulesEvolveLiveCellsSpecLiveCellsCell3() { + return true; + } + + public int _initRulesEvolveLiveCellsSpecLiveCellsCell4() { + return 3; + } + + public boolean _initRulesEvolveLiveCellsSpecLiveCellsCell5() { + return true; + } + + public int _initRulesEvolveLiveCellsSpecLiveCellsCell6() { + return 4; + } + + public boolean _initRulesEvolveLiveCellsSpecLiveCellsCell7() { + return false; + } + + @Test + @Named("liveCells.forEach[ subject.becomesAlive[liveNeighbourCount] => result ]") + @Order(1) + public void _liveCellsForEachSubjectBecomesAliveLiveNeighbourCountResult() throws Exception { + final Procedure1 _function = new Procedure1() { + @Override + public void apply(final RulesEvolveLiveCellsSpecLiveCells it) { + boolean _becomesAlive = RulesEvolveLiveCellsSpec.this.subject.becomesAlive(it.getLiveNeighbourCount()); + boolean _result = it.getResult(); + Assert.assertTrue("\nExpected subject.becomesAlive(liveNeighbourCount) => result but" + + "\n subject.becomesAlive(liveNeighbourCount) is " + new org.hamcrest.StringDescription().appendValue(Boolean.valueOf(_becomesAlive)).toString() + + "\n subject is " + new org.hamcrest.StringDescription().appendValue(RulesEvolveLiveCellsSpec.this.subject).toString() + + "\n liveNeighbourCount is " + new org.hamcrest.StringDescription().appendValue(it.getLiveNeighbourCount()).toString() + + "\n result is " + new org.hamcrest.StringDescription().appendValue(_result).toString() + "\n", Should.operator_doubleArrow(Boolean.valueOf(_becomesAlive), _result)); + + } + }; + Each.forEach(this.liveCells, _function); + } +} diff --git a/examples/org.jnario.examples/xtend-gen/gameoflife/specs/WorldDeadCellsSpec.java b/examples/org.jnario.examples/xtend-gen/gameoflife/specs/WorldDeadCellsSpec.java index fab5463b2..ced7787fe 100644 --- a/examples/org.jnario.examples/xtend-gen/gameoflife/specs/WorldDeadCellsSpec.java +++ b/examples/org.jnario.examples/xtend-gen/gameoflife/specs/WorldDeadCellsSpec.java @@ -1,79 +1,75 @@ -package gameoflife.specs; - -import com.google.common.collect.Iterables; -import gameoflife.CellLocation; -import gameoflife.World; -import gameoflife.specs.WorldSpec; -import java.util.List; -import java.util.Set; -import org.eclipse.xtext.xbase.lib.CollectionLiterals; -import org.eclipse.xtext.xbase.lib.IterableExtensions; -import org.jnario.lib.Assert; -import org.jnario.lib.Should; -import org.jnario.runner.ExampleGroupRunner; -import org.jnario.runner.Named; -import org.jnario.runner.Order; -import org.junit.Test; -import org.junit.runner.RunWith; - -@Named("dead cells") -@RunWith(ExampleGroupRunner.class) -@SuppressWarnings("all") -public class WorldDeadCellsSpec extends WorldSpec { - @Test - @Named("with no live cells there are no dead cells") - @Order(1) - public void _withNoLiveCellsThereAreNoDeadCells() throws Exception { - List _emptyList = CollectionLiterals.emptyList(); - World _worldWith = World.worldWith(_emptyList); - Set _deadCells = _worldWith.deadCells(); - Set _emptySet = CollectionLiterals.emptySet(); - Assert.assertTrue("\nExpected worldWith(emptyList).deadCells => emptySet but" - + "\n worldWith(emptyList).deadCells is " + new org.hamcrest.StringDescription().appendValue(_deadCells).toString() - + "\n worldWith(emptyList) is " + new org.hamcrest.StringDescription().appendValue(_worldWith).toString() - + "\n emptyList is " + new org.hamcrest.StringDescription().appendValue(_emptyList).toString() - + "\n emptySet is " + new org.hamcrest.StringDescription().appendValue(_emptySet).toString() + "\n", Should.>operator_doubleArrow(_deadCells, _emptySet)); - - } - - @Test - @Named("with a live cell all neighbours are dead cells") - @Order(2) - public void _withALiveCellAllNeighboursAreDeadCells() throws Exception { - Set _deadCells = this.worldWithLiveCell.deadCells(); - Set _neighbours = this.liveCell.neighbours(); - Assert.assertTrue("\nExpected worldWithLiveCell.deadCells => liveCell.neighbours but" - + "\n worldWithLiveCell.deadCells is " + new org.hamcrest.StringDescription().appendValue(_deadCells).toString() - + "\n worldWithLiveCell is " + new org.hamcrest.StringDescription().appendValue(this.worldWithLiveCell).toString() - + "\n liveCell.neighbours is " + new org.hamcrest.StringDescription().appendValue(_neighbours).toString() - + "\n liveCell is " + new org.hamcrest.StringDescription().appendValue(this.liveCell).toString() + "\n", Should.>operator_doubleArrow(_deadCells, _neighbours)); - - } - - @Test - @Named("with a live cell all non-living neighbours are dead cells") - @Order(3) - public void _withALiveCellAllNonLivingNeighboursAreDeadCells() throws Exception { - Set _deadCells = this.worldWithTwoLiveNeighbours.deadCells(); - Set _allNonLivingNeighbours = this.allNonLivingNeighbours(); - Assert.assertTrue("\nExpected worldWithTwoLiveNeighbours.deadCells => allNonLivingNeighbours but" - + "\n worldWithTwoLiveNeighbours.deadCells is " + new org.hamcrest.StringDescription().appendValue(_deadCells).toString() - + "\n worldWithTwoLiveNeighbours is " + new org.hamcrest.StringDescription().appendValue(this.worldWithTwoLiveNeighbours).toString() - + "\n allNonLivingNeighbours is " + new org.hamcrest.StringDescription().appendValue(_allNonLivingNeighbours).toString() + "\n", Should.>operator_doubleArrow(_deadCells, _allNonLivingNeighbours)); - - } - - public Set allNonLivingNeighbours() { - Set _xblockexpression = null; - { - Set _neighbours = this.liveCell.neighbours(); - Set _neighbours_1 = this.anotherLivingCell.neighbours(); - Iterable _plus = Iterables.concat(_neighbours, _neighbours_1); - final Set allNonLivingNeighbours = IterableExtensions.toSet(_plus); - allNonLivingNeighbours.remove(this.anotherLivingCell); - allNonLivingNeighbours.remove(this.liveCell); - _xblockexpression = allNonLivingNeighbours; - } - return _xblockexpression; - } -} +package gameoflife.specs; + +import com.google.common.collect.Iterables; +import gameoflife.CellLocation; +import gameoflife.World; +import gameoflife.specs.WorldSpec; +import java.util.Set; +import org.eclipse.xtext.xbase.lib.CollectionLiterals; +import org.eclipse.xtext.xbase.lib.IterableExtensions; +import org.jnario.lib.Assert; +import org.jnario.lib.Should; +import org.jnario.runner.ExampleGroupRunner; +import org.jnario.runner.Named; +import org.jnario.runner.Order; +import org.junit.Test; +import org.junit.runner.RunWith; + +@Named("dead cells") +@RunWith(ExampleGroupRunner.class) +@SuppressWarnings("all") +public class WorldDeadCellsSpec extends WorldSpec { + @Test + @Named("with no live cells there are no dead cells") + @Order(1) + public void _withNoLiveCellsThereAreNoDeadCells() throws Exception { + Set _deadCells = World.worldWith(CollectionLiterals.emptyList()).deadCells(); + Set _emptySet = CollectionLiterals.emptySet(); + Assert.assertTrue("\nExpected worldWith(emptyList).deadCells => emptySet but" + + "\n worldWith(emptyList).deadCells is " + new org.hamcrest.StringDescription().appendValue(_deadCells).toString() + + "\n worldWith(emptyList) is " + new org.hamcrest.StringDescription().appendValue(World.worldWith(CollectionLiterals.emptyList())).toString() + + "\n emptyList is " + new org.hamcrest.StringDescription().appendValue(CollectionLiterals.emptyList()).toString() + + "\n emptySet is " + new org.hamcrest.StringDescription().appendValue(_emptySet).toString() + "\n", Should.>operator_doubleArrow(_deadCells, _emptySet)); + + } + + @Test + @Named("with a live cell all neighbours are dead cells") + @Order(2) + public void _withALiveCellAllNeighboursAreDeadCells() throws Exception { + Set _deadCells = this.worldWithLiveCell.deadCells(); + Set _neighbours = this.liveCell.neighbours(); + Assert.assertTrue("\nExpected worldWithLiveCell.deadCells => liveCell.neighbours but" + + "\n worldWithLiveCell.deadCells is " + new org.hamcrest.StringDescription().appendValue(_deadCells).toString() + + "\n worldWithLiveCell is " + new org.hamcrest.StringDescription().appendValue(this.worldWithLiveCell).toString() + + "\n liveCell.neighbours is " + new org.hamcrest.StringDescription().appendValue(_neighbours).toString() + + "\n liveCell is " + new org.hamcrest.StringDescription().appendValue(this.liveCell).toString() + "\n", Should.>operator_doubleArrow(_deadCells, _neighbours)); + + } + + @Test + @Named("with a live cell all non-living neighbours are dead cells") + @Order(3) + public void _withALiveCellAllNonLivingNeighboursAreDeadCells() throws Exception { + Set _deadCells = this.worldWithTwoLiveNeighbours.deadCells(); + Set _allNonLivingNeighbours = this.allNonLivingNeighbours(); + Assert.assertTrue("\nExpected worldWithTwoLiveNeighbours.deadCells => allNonLivingNeighbours but" + + "\n worldWithTwoLiveNeighbours.deadCells is " + new org.hamcrest.StringDescription().appendValue(_deadCells).toString() + + "\n worldWithTwoLiveNeighbours is " + new org.hamcrest.StringDescription().appendValue(this.worldWithTwoLiveNeighbours).toString() + + "\n allNonLivingNeighbours is " + new org.hamcrest.StringDescription().appendValue(_allNonLivingNeighbours).toString() + "\n", Should.>operator_doubleArrow(_deadCells, _allNonLivingNeighbours)); + + } + + public Set allNonLivingNeighbours() { + Set _xblockexpression = null; + { + Set _neighbours = this.liveCell.neighbours(); + Set _neighbours_1 = this.anotherLivingCell.neighbours(); + final Set allNonLivingNeighbours = IterableExtensions.toSet(Iterables.concat(_neighbours, _neighbours_1)); + allNonLivingNeighbours.remove(this.anotherLivingCell); + allNonLivingNeighbours.remove(this.liveCell); + _xblockexpression = allNonLivingNeighbours; + } + return _xblockexpression; + } +} diff --git a/examples/org.jnario.examples/xtend-gen/introduction/JnarioSpecsFactsForJavaSpec.java b/examples/org.jnario.examples/xtend-gen/introduction/JnarioSpecsFactsForJavaSpec.java index a042c2ce9..9ff2fc1f7 100644 --- a/examples/org.jnario.examples/xtend-gen/introduction/JnarioSpecsFactsForJavaSpec.java +++ b/examples/org.jnario.examples/xtend-gen/introduction/JnarioSpecsFactsForJavaSpec.java @@ -1,119 +1,156 @@ -/** - * Copyright (c) 2012 BMW Car IT and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package introduction; - -import com.google.inject.Inject; -import org.eclipse.xtext.xbase.lib.Extension; -import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; -import org.jnario.jnario.test.util.Helpers; -import org.jnario.jnario.test.util.SpecExecutor; -import org.jnario.jnario.test.util.SpecTestCreator; -import org.jnario.lib.Assert; -import org.jnario.lib.Should; -import org.jnario.runner.CreateWith; -import org.jnario.runner.ExampleGroupRunner; -import org.jnario.runner.Named; -import org.jnario.runner.Order; -import org.junit.Test; -import org.junit.runner.RunWith; - -/** - *

- * - * *Jnario* is a framework helping you write executable software specifications. - * It leverages the expressiveness of [Xtend](http://www.xtend-lang.org) and is easy to - * integrate, as it compiles to plain [JUnit](http://www.junit.org/) tests. - * In our other [presentation](http://www.eclipsecon.org/2012/sessions/program-thou-shalt-behave) - * at this EclipseCon, we demonstrate how to use Jnario for writing executable acceptance - * specifications in a business readable fashion. - * This session introduces you to *Jnario Specs* fact another language of Jnario allowing - * software behavior specification on a unit level. We demonstrate how you can design and document - * your software at the same time. - * For example, this document is actually generated from a [spec](https://gist.github.com/1762405) written - * with *Jnario Specs*. - */ -@CreateWith(SpecTestCreator.class) -@Named("Jnario Specs - facts for Java") -@RunWith(ExampleGroupRunner.class) -@SuppressWarnings("all") -public class JnarioSpecsFactsForJavaSpec { - @Extension - @org.jnario.runner.Extension - @Inject - public SpecExecutor _specExecutor; - - /** - * Jnario improves the readability of tests by providing assertion methods which can extend - * any object (making use of Xtend's [extension methods](http://www.eclipse.org/xtend/#extensionmethods)). - * These assertions help you express how an object should behave. They can be combined with any - * [Hamcrest](http://code.google.com/p/hamcrest/) matcher, giving you the freedom to choose from - * a wide range of existing matchers. - */ - @Test - @Named("Should-style Assertions") - @Order(1) - public void _shouldStyleAssertions() throws Exception { - boolean _should_be = Should.should_be( - "hello", "hello"); - Assert.assertTrue("\nExpected \"hello\" should be \"hello\" but" - + "\n \"hello\" should be \"hello\" is " + new org.hamcrest.StringDescription().appendValue(true).toString() + "\n", _should_be); - - boolean _should_be_1 = Should.should_be( - Boolean.valueOf(true), false); - Assert.assertFalse("\nExpected true should not be false but" - + "\n true should not be false is " + new org.hamcrest.StringDescription().appendValue(true).toString() + "\n", _should_be_1); - - Assert.assertTrue("\nExpected \"hello\" should be typeof(String) but" - + "\n \"hello\" should be typeof(String) is " + new org.hamcrest.StringDescription().appendValue(true).toString() + "\n", Should.should_be( - "hello", String.class)); - - } - - /** - * With Jnario, debugging a failing test to discover the reason for its failure becomes - * a thing of the past. Jnario provides a special assert statement that reports, when the assertion fails, - * the value of all involved expressions. - */ - @Test - @Named("Self-explaining Assertions") - @Order(2) - public void _selfExplainingAssertions() throws Exception { - final int x = 0; - final int y = 1; - final Procedure1 _function = new Procedure1() { - @Override - public void apply(final Boolean it) { - Assert.assertTrue("\nExpected x == 1 && y == 0 but" - + "\n x == 1 is " + new org.hamcrest.StringDescription().appendValue((x == 1)).toString() - + "\n x is " + new org.hamcrest.StringDescription().appendValue(x).toString() - + "\n y == 0 is " + new org.hamcrest.StringDescription().appendValue((y == 0)).toString() - + "\n y is " + new org.hamcrest.StringDescription().appendValue(y).toString() + "\n", ((x == 1) && (y == 0))); - - } - }; - String _errorMessage = Helpers.errorMessage(_function); - Helpers.is(_errorMessage, "Expected x == 1 && y == 0 but\r\n x == 1 is \r\n x is <0>\r\n y == 0 is \r\n y is <1>"); - } - - /** - * *Jnario Specs* helps you write less boilerplate code in your - * specifications. In the following example, `describe Calculator` - * references the existing Java type `Calculator`. - * Using this information Jnario will automatically create and instantiate a field `subject`, - * which you can use in your specification. It is even possible to use - * [Google Guice](http://code.google.com/p/google-guice/) to instantiate your subjects. - * - * @filter(\.executesSuccessfully|''') - */ - @Test - @Named("Implicit subject creation") - @Order(3) - public void _implicitSubjectCreation() throws Exception { - this._specExecutor.executesSuccessfully("package bootstrap\r\n\r\nimport java.util.ArrayList\r\n\r\ndescribe ArrayList{\r\n\r\n fact \"should automatically create an instance of ArrayList called subject\"{\r\n subject should be typeof(ArrayList)\r\n }\r\n\r\n}\r\n"); - } -} +/** + * Copyright (c) 2012 BMW Car IT and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package introduction; + +import com.google.inject.Inject; +import org.eclipse.xtend2.lib.StringConcatenation; +import org.eclipse.xtext.xbase.lib.Extension; +import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; +import org.jnario.jnario.test.util.Helpers; +import org.jnario.jnario.test.util.SpecExecutor; +import org.jnario.jnario.test.util.SpecTestCreator; +import org.jnario.lib.Assert; +import org.jnario.lib.Should; +import org.jnario.runner.CreateWith; +import org.jnario.runner.ExampleGroupRunner; +import org.jnario.runner.Named; +import org.jnario.runner.Order; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + *

+ * + * *Jnario* is a framework helping you write executable software specifications. + * It leverages the expressiveness of [Xtend](http://www.xtend-lang.org) and is easy to + * integrate, as it compiles to plain [JUnit](http://www.junit.org/) tests. + * In our other [presentation](http://www.eclipsecon.org/2012/sessions/program-thou-shalt-behave) + * at this EclipseCon, we demonstrate how to use Jnario for writing executable acceptance + * specifications in a business readable fashion. + * This session introduces you to *Jnario Specs* fact another language of Jnario allowing + * software behavior specification on a unit level. We demonstrate how you can design and document + * your software at the same time. + * For example, this document is actually generated from a [spec](https://gist.github.com/1762405) written + * with *Jnario Specs*. + */ +@CreateWith(SpecTestCreator.class) +@Named("Jnario Specs - facts for Java") +@RunWith(ExampleGroupRunner.class) +@SuppressWarnings("all") +public class JnarioSpecsFactsForJavaSpec { + @Extension + @org.jnario.runner.Extension + @Inject + public SpecExecutor _specExecutor; + + /** + * Jnario improves the readability of tests by providing assertion methods which can extend + * any object (making use of Xtend's [extension methods](http://www.eclipse.org/xtend/#extensionmethods)). + * These assertions help you express how an object should behave. They can be combined with any + * [Hamcrest](http://code.google.com/p/hamcrest/) matcher, giving you the freedom to choose from + * a wide range of existing matchers. + */ + @Test + @Named("Should-style Assertions") + @Order(1) + public void _shouldStyleAssertions() throws Exception { + boolean _should_be = Should.should_be( + "hello", "hello"); + Assert.assertTrue("\nExpected \"hello\" should be \"hello\" but" + + "\n \"hello\" should be \"hello\" is " + new org.hamcrest.StringDescription().appendValue(true).toString() + "\n", _should_be); + + boolean _should_be_1 = Should.should_be( + Boolean.valueOf(true), false); + Assert.assertFalse("\nExpected true should not be false but" + + "\n true should not be false is " + new org.hamcrest.StringDescription().appendValue(true).toString() + "\n", _should_be_1); + + Assert.assertTrue("\nExpected \"hello\" should be typeof(String) but" + + "\n \"hello\" should be typeof(String) is " + new org.hamcrest.StringDescription().appendValue(true).toString() + "\n", Should.should_be( + "hello", String.class)); + + } + + /** + * With Jnario, debugging a failing test to discover the reason for its failure becomes + * a thing of the past. Jnario provides a special assert statement that reports, when the assertion fails, + * the value of all involved expressions. + */ + @Test + @Named("Self-explaining Assertions") + @Order(2) + public void _selfExplainingAssertions() throws Exception { + final int x = 0; + final int y = 1; + final Procedure1 _function = new Procedure1() { + @Override + public void apply(final Boolean it) { + Assert.assertTrue("\nExpected x == 1 && y == 0 but" + + "\n x == 1 is " + new org.hamcrest.StringDescription().appendValue((x == 1)).toString() + + "\n x is " + new org.hamcrest.StringDescription().appendValue(x).toString() + + "\n y == 0 is " + new org.hamcrest.StringDescription().appendValue((y == 0)).toString() + + "\n y is " + new org.hamcrest.StringDescription().appendValue(y).toString() + "\n", ((x == 1) && (y == 0))); + + } + }; + String _errorMessage = Helpers.errorMessage(_function); + StringConcatenation _builder = new StringConcatenation(); + _builder.append("Expected x == 1 && y == 0 but"); + _builder.newLine(); + _builder.append(" "); + _builder.append("x == 1 is "); + _builder.newLine(); + _builder.append(" "); + _builder.append("x is <0>"); + _builder.newLine(); + _builder.append(" "); + _builder.append("y == 0 is "); + _builder.newLine(); + _builder.append(" "); + _builder.append("y is <1>"); + Helpers.is(_errorMessage, _builder); + } + + /** + * *Jnario Specs* helps you write less boilerplate code in your + * specifications. In the following example, `describe Calculator` + * references the existing Java type `Calculator`. + * Using this information Jnario will automatically create and instantiate a field `subject`, + * which you can use in your specification. It is even possible to use + * [Google Guice](http://code.google.com/p/google-guice/) to instantiate your subjects. + * + * @filter(\.executesSuccessfully|''') + */ + @Test + @Named("Implicit subject creation") + @Order(3) + public void _implicitSubjectCreation() throws Exception { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("package bootstrap"); + _builder.newLine(); + _builder.newLine(); + _builder.append("import java.util.ArrayList"); + _builder.newLine(); + _builder.newLine(); + _builder.append("describe ArrayList{"); + _builder.newLine(); + _builder.newLine(); + _builder.append(" "); + _builder.append("fact \"should automatically create an instance of ArrayList called subject\"{"); + _builder.newLine(); + _builder.append(" "); + _builder.append("subject should be typeof(ArrayList)"); + _builder.newLine(); + _builder.append(" "); + _builder.append("}"); + _builder.newLine(); + _builder.newLine(); + _builder.append("}"); + _builder.newLine(); + this._specExecutor.executesSuccessfully(_builder); + } +} diff --git a/examples/org.jnario.examples/xtend-gen/matchers/Person.java b/examples/org.jnario.examples/xtend-gen/matchers/Person.java index 2fcf0b67c..a1f286fd9 100644 --- a/examples/org.jnario.examples/xtend-gen/matchers/Person.java +++ b/examples/org.jnario.examples/xtend-gen/matchers/Person.java @@ -1,67 +1,67 @@ -package matchers; - -import org.eclipse.xtend.lib.Data; -import org.eclipse.xtext.xbase.lib.Pure; - -@Data -@SuppressWarnings("all") -public class Person { - private final String _name; - - private final int _age; - - @Override - public String toString() { - String _name = this.getName(); - String _plus = (_name + "("); - int _age = this.getAge(); - String _plus_1 = (_plus + Integer.valueOf(_age)); - return (_plus_1 + ")"); - } - - public Person(final String name, final int age) { - super(); - this._name = name; - this._age = age; - } - - @Override - @Pure - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((this._name== null) ? 0 : this._name.hashCode()); - result = prime * result + this._age; - return result; - } - - @Override - @Pure - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - Person other = (Person) obj; - if (this._name == null) { - if (other._name != null) - return false; - } else if (!this._name.equals(other._name)) - return false; - if (other._age != this._age) - return false; - return true; - } - - @Pure - public String getName() { - return this._name; - } - - @Pure - public int getAge() { - return this._age; - } -} +package matchers; + +import org.eclipse.xtend.lib.Data; +import org.eclipse.xtext.xbase.lib.Pure; + +@Data +@SuppressWarnings("all") +public class Person { + private final String _name; + + private final int _age; + + @Override + public String toString() { + String _name = this.getName(); + String _plus = (_name + "("); + int _age = this.getAge(); + String _plus_1 = (_plus + Integer.valueOf(_age)); + return (_plus_1 + ")"); + } + + public Person(final String name, final int age) { + super(); + this._name = name; + this._age = age; + } + + @Override + @Pure + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((this._name== null) ? 0 : this._name.hashCode()); + result = prime * result + this._age; + return result; + } + + @Override + @Pure + public boolean equals(final Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Person other = (Person) obj; + if (this._name == null) { + if (other._name != null) + return false; + } else if (!this._name.equals(other._name)) + return false; + if (other._age != this._age) + return false; + return true; + } + + @Pure + public String getName() { + return this._name; + } + + @Pure + public int getAge() { + return this._age; + } +} diff --git a/examples/org.jnario.maven.example/src/test/jnario-gen/demo/AdditionFeature.java b/examples/org.jnario.maven.example/src/test/jnario-gen/demo/AdditionFeature.java index f2d372f6e..5ff5fc594 100644 --- a/examples/org.jnario.maven.example/src/test/jnario-gen/demo/AdditionFeature.java +++ b/examples/org.jnario.maven.example/src/test/jnario-gen/demo/AdditionFeature.java @@ -1,21 +1,21 @@ -/** - * Copyright (c) 2012 BMW Car IT and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package demo; - -import demo.AdditionFeatureAddTwoNumbers; -import org.jnario.runner.Contains; -import org.jnario.runner.FeatureRunner; -import org.jnario.runner.Named; -import org.junit.runner.RunWith; - -@Contains(AdditionFeatureAddTwoNumbers.class) -@Named("Addition") -@RunWith(FeatureRunner.class) -@SuppressWarnings("all") -public class AdditionFeature { -} +/** + * Copyright (c) 2012 BMW Car IT and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package demo; + +import demo.AdditionFeatureAddTwoNumbers; +import org.jnario.runner.Contains; +import org.jnario.runner.FeatureRunner; +import org.jnario.runner.Named; +import org.junit.runner.RunWith; + +@Contains(AdditionFeatureAddTwoNumbers.class) +@Named("Addition") +@RunWith(FeatureRunner.class) +@SuppressWarnings("all") +public class AdditionFeature { +} diff --git a/examples/org.jnario.maven.example/src/test/jnario-gen/demo/AdditionFeatureAddTwoNumbers.java b/examples/org.jnario.maven.example/src/test/jnario-gen/demo/AdditionFeatureAddTwoNumbers.java index 736db2a62..401faeb46 100644 --- a/examples/org.jnario.maven.example/src/test/jnario-gen/demo/AdditionFeatureAddTwoNumbers.java +++ b/examples/org.jnario.maven.example/src/test/jnario-gen/demo/AdditionFeatureAddTwoNumbers.java @@ -1,61 +1,61 @@ -/** - * Copyright (c) 2012 BMW Car IT and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package demo; - -import demo.AdditionFeature; -import demo.Calculator; -import org.jnario.lib.Assert; -import org.jnario.lib.JnarioIterableExtensions; -import org.jnario.lib.Should; -import org.jnario.lib.StepArguments; -import org.jnario.lib.StringConversions; -import org.jnario.runner.FeatureRunner; -import org.jnario.runner.Named; -import org.jnario.runner.Order; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; - -@RunWith(FeatureRunner.class) -@Named("Scenario: Add two numbers") -@SuppressWarnings("all") -public class AdditionFeatureAddTwoNumbers extends AdditionFeature { - final Calculator calculator = new Calculator(); - - int result; - - @Test - @Order(0) - @Named("When I entered \\\"50\\\" and \\\"70\\\"") - public void _whenIEntered50And70() { - final StepArguments args = new StepArguments("50", "70"); - this.result = this.calculator.add(StringConversions.toInt(JnarioIterableExtensions.first(args)), StringConversions.toInt(JnarioIterableExtensions.second(args))); - } - - @Test - @Order(1) - @Named("Then the result should be \\\"120\\\"") - public void _thenTheResultShouldBe120() { - final StepArguments args = new StepArguments("120"); - int _int = StringConversions.toInt(JnarioIterableExtensions.first(args)); - Assert.assertTrue("\nExpected result => args.first.toInt but" - + "\n result is " + new org.hamcrest.StringDescription().appendValue(Integer.valueOf(this.result)).toString() - + "\n args.first.toInt is " + new org.hamcrest.StringDescription().appendValue(Integer.valueOf(_int)).toString() - + "\n args.first is " + new org.hamcrest.StringDescription().appendValue(JnarioIterableExtensions.first(args)).toString() - + "\n args is " + new org.hamcrest.StringDescription().appendValue(args).toString() + "\n", Should.operator_doubleArrow(Integer.valueOf(this.result), Integer.valueOf(_int))); - - } - - @Test - @Order(2) - @Ignore - @Named("And is pending [PENDING]") - public void _andIsPending() { - - } -} +/** + * Copyright (c) 2012 BMW Car IT and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package demo; + +import demo.AdditionFeature; +import demo.Calculator; +import org.jnario.lib.Assert; +import org.jnario.lib.JnarioIterableExtensions; +import org.jnario.lib.Should; +import org.jnario.lib.StepArguments; +import org.jnario.lib.StringConversions; +import org.jnario.runner.FeatureRunner; +import org.jnario.runner.Named; +import org.jnario.runner.Order; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(FeatureRunner.class) +@Named("Scenario: Add two numbers") +@SuppressWarnings("all") +public class AdditionFeatureAddTwoNumbers extends AdditionFeature { + final Calculator calculator = new Calculator(); + + int result; + + @Test + @Order(0) + @Named("When I entered \\\"50\\\" and \\\"70\\\"") + public void _whenIEntered50And70() { + final StepArguments args = new StepArguments("50", "70"); + this.result = this.calculator.add(StringConversions.toInt(JnarioIterableExtensions.first(args)), StringConversions.toInt(JnarioIterableExtensions.second(args))); + } + + @Test + @Order(1) + @Named("Then the result should be \\\"120\\\"") + public void _thenTheResultShouldBe120() { + final StepArguments args = new StepArguments("120"); + int _int = StringConversions.toInt(JnarioIterableExtensions.first(args)); + Assert.assertTrue("\nExpected result => args.first.toInt but" + + "\n result is " + new org.hamcrest.StringDescription().appendValue(Integer.valueOf(this.result)).toString() + + "\n args.first.toInt is " + new org.hamcrest.StringDescription().appendValue(Integer.valueOf(_int)).toString() + + "\n args.first is " + new org.hamcrest.StringDescription().appendValue(JnarioIterableExtensions.first(args)).toString() + + "\n args is " + new org.hamcrest.StringDescription().appendValue(args).toString() + "\n", Should.operator_doubleArrow(Integer.valueOf(this.result), Integer.valueOf(_int))); + + } + + @Test + @Order(2) + @Ignore + @Named("And is pending [PENDING]") + public void _andIsPending() { + + } +} diff --git a/examples/org.jnario.maven.example/src/test/jnario-gen/demo/AllTestsSuite.java b/examples/org.jnario.maven.example/src/test/jnario-gen/demo/AllTestsSuite.java index b4e82ff0c..f2c1a341e 100644 --- a/examples/org.jnario.maven.example/src/test/jnario-gen/demo/AllTestsSuite.java +++ b/examples/org.jnario.maven.example/src/test/jnario-gen/demo/AllTestsSuite.java @@ -1,16 +1,16 @@ -package demo; - -import demo.AdditionFeature; -import demo.CalculatorSpec; -import demo.TestSuiteSuite; -import org.jnario.runner.Contains; -import org.jnario.runner.ExampleGroupRunner; -import org.jnario.runner.Named; -import org.junit.runner.RunWith; - -@Named("AllTests") -@Contains({ AdditionFeature.class, CalculatorSpec.class, TestSuiteSuite.class }) -@RunWith(ExampleGroupRunner.class) -@SuppressWarnings("all") -public class AllTestsSuite { -} +package demo; + +import demo.AdditionFeature; +import demo.CalculatorSpec; +import demo.TestSuiteSuite; +import org.jnario.runner.Contains; +import org.jnario.runner.ExampleGroupRunner; +import org.jnario.runner.Named; +import org.junit.runner.RunWith; + +@Named("AllTests") +@Contains({ AdditionFeature.class, CalculatorSpec.class, TestSuiteSuite.class }) +@RunWith(ExampleGroupRunner.class) +@SuppressWarnings("all") +public class AllTestsSuite { +} diff --git a/examples/org.jnario.maven.example/src/test/jnario-gen/demo/CalculatorSpec.java b/examples/org.jnario.maven.example/src/test/jnario-gen/demo/CalculatorSpec.java index 4fb3cf0ba..bee997220 100644 --- a/examples/org.jnario.maven.example/src/test/jnario-gen/demo/CalculatorSpec.java +++ b/examples/org.jnario.maven.example/src/test/jnario-gen/demo/CalculatorSpec.java @@ -1,93 +1,93 @@ -/** - * Copyright (c) 2012 BMW Car IT and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package demo; - -import demo.Calculator; -import demo.CalculatorSpecExamples; -import java.util.Arrays; -import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; -import org.jnario.lib.Assert; -import org.jnario.lib.Each; -import org.jnario.lib.ExampleTable; -import org.jnario.lib.Should; -import org.jnario.runner.ExampleGroupRunner; -import org.jnario.runner.Named; -import org.jnario.runner.Order; -import org.junit.Test; -import org.junit.runner.RunWith; - -@Named("Calculator") -@RunWith(ExampleGroupRunner.class) -@SuppressWarnings("all") -public class CalculatorSpec { - @Test - @Named("should add two values") - @Order(1) - public void _shouldAddTwoValues() throws Exception { - int _add = new Calculator().add(1, 2); - Assert.assertTrue("\nExpected new Calculator().add(1, 2) should be 3 but" - + "\n new Calculator().add(1, 2) is " + new org.hamcrest.StringDescription().appendValue(Integer.valueOf(_add)).toString() - + "\n new Calculator() is " + new org.hamcrest.StringDescription().appendValue(new Calculator()).toString() + "\n", Should.should_be(Integer.valueOf(_add), Integer.valueOf(3))); - - } - - public ExampleTable _initCalculatorSpecExamples() { - return ExampleTable.create("examples", - Arrays.asList("a", "b", "sum"), - new CalculatorSpecExamples( Arrays.asList("1", "2", "3"), _initCalculatorSpecExamplesCell0(), _initCalculatorSpecExamplesCell1(), _initCalculatorSpecExamplesCell2()), - new CalculatorSpecExamples( Arrays.asList("1", "3", "4"), _initCalculatorSpecExamplesCell3(), _initCalculatorSpecExamplesCell4(), _initCalculatorSpecExamplesCell5()) - ); - } - - protected ExampleTable examples = _initCalculatorSpecExamples(); - - public int _initCalculatorSpecExamplesCell0() { - return 1; - } - - public int _initCalculatorSpecExamplesCell1() { - return 2; - } - - public int _initCalculatorSpecExamplesCell2() { - return 3; - } - - public int _initCalculatorSpecExamplesCell3() { - return 1; - } - - public int _initCalculatorSpecExamplesCell4() { - return 3; - } - - public int _initCalculatorSpecExamplesCell5() { - return 4; - } - - @Test - @Named("should handle tables") - @Order(2) - public void _shouldHandleTables() throws Exception { - final Procedure1 _function = new Procedure1() { - public void apply(final CalculatorSpecExamples it) { - int _a = it.getA(); - int _b = it.getB(); - int _plus = (_a + _b); - int _sum = it.getSum(); - Assert.assertTrue("\nExpected a + b => sum but" - + "\n a + b is " + new org.hamcrest.StringDescription().appendValue(Integer.valueOf(_plus)).toString() - + "\n a is " + new org.hamcrest.StringDescription().appendValue(_a).toString() - + "\n b is " + new org.hamcrest.StringDescription().appendValue(_b).toString() - + "\n sum is " + new org.hamcrest.StringDescription().appendValue(Integer.valueOf(_sum)).toString() + "\n", Should.operator_doubleArrow(Integer.valueOf(_plus), Integer.valueOf(_sum))); - - } - }; - Each.forEach(this.examples, _function); - } -} +/** + * Copyright (c) 2012 BMW Car IT and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package demo; + +import demo.Calculator; +import demo.CalculatorSpecExamples; +import java.util.Arrays; +import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; +import org.jnario.lib.Assert; +import org.jnario.lib.Each; +import org.jnario.lib.ExampleTable; +import org.jnario.lib.Should; +import org.jnario.runner.ExampleGroupRunner; +import org.jnario.runner.Named; +import org.jnario.runner.Order; +import org.junit.Test; +import org.junit.runner.RunWith; + +@Named("Calculator") +@RunWith(ExampleGroupRunner.class) +@SuppressWarnings("all") +public class CalculatorSpec { + @Test + @Named("should add two values") + @Order(1) + public void _shouldAddTwoValues() throws Exception { + int _add = new Calculator().add(1, 2); + Assert.assertTrue("\nExpected new Calculator().add(1, 2) should be 3 but" + + "\n new Calculator().add(1, 2) is " + new org.hamcrest.StringDescription().appendValue(Integer.valueOf(_add)).toString() + + "\n new Calculator() is " + new org.hamcrest.StringDescription().appendValue(new Calculator()).toString() + "\n", Should.should_be(Integer.valueOf(_add), Integer.valueOf(3))); + + } + + public ExampleTable _initCalculatorSpecExamples() { + return ExampleTable.create("examples", + Arrays.asList("a", "b", "sum"), + new CalculatorSpecExamples( Arrays.asList("1", "2", "3"), _initCalculatorSpecExamplesCell0(), _initCalculatorSpecExamplesCell1(), _initCalculatorSpecExamplesCell2()), + new CalculatorSpecExamples( Arrays.asList("1", "3", "4"), _initCalculatorSpecExamplesCell3(), _initCalculatorSpecExamplesCell4(), _initCalculatorSpecExamplesCell5()) + ); + } + + protected ExampleTable examples = _initCalculatorSpecExamples(); + + public int _initCalculatorSpecExamplesCell0() { + return 1; + } + + public int _initCalculatorSpecExamplesCell1() { + return 2; + } + + public int _initCalculatorSpecExamplesCell2() { + return 3; + } + + public int _initCalculatorSpecExamplesCell3() { + return 1; + } + + public int _initCalculatorSpecExamplesCell4() { + return 3; + } + + public int _initCalculatorSpecExamplesCell5() { + return 4; + } + + @Test + @Named("should handle tables") + @Order(2) + public void _shouldHandleTables() throws Exception { + final Procedure1 _function = new Procedure1() { + public void apply(final CalculatorSpecExamples it) { + int _a = it.getA(); + int _b = it.getB(); + int _plus = (_a + _b); + int _sum = it.getSum(); + Assert.assertTrue("\nExpected a + b => sum but" + + "\n a + b is " + new org.hamcrest.StringDescription().appendValue(Integer.valueOf(_plus)).toString() + + "\n a is " + new org.hamcrest.StringDescription().appendValue(_a).toString() + + "\n b is " + new org.hamcrest.StringDescription().appendValue(_b).toString() + + "\n sum is " + new org.hamcrest.StringDescription().appendValue(Integer.valueOf(_sum)).toString() + "\n", Should.operator_doubleArrow(Integer.valueOf(_plus), Integer.valueOf(_sum))); + + } + }; + Each.forEach(this.examples, _function); + } +} diff --git a/examples/org.jnario.maven.example/src/test/jnario-gen/demo/CalculatorSpecExamples.java b/examples/org.jnario.maven.example/src/test/jnario-gen/demo/CalculatorSpecExamples.java index bfef6e289..0c048a845 100644 --- a/examples/org.jnario.maven.example/src/test/jnario-gen/demo/CalculatorSpecExamples.java +++ b/examples/org.jnario.maven.example/src/test/jnario-gen/demo/CalculatorSpecExamples.java @@ -1,33 +1,33 @@ -package demo; - -import java.util.List; -import org.jnario.lib.ExampleTableRow; - -@SuppressWarnings("all") -public class CalculatorSpecExamples extends ExampleTableRow { - public CalculatorSpecExamples(final List cellNames, final int a, final int b, final int sum) { - super(cellNames); - this.a = a; - this.b = b; - this.sum = sum; - - } - - private int a; - - public int getA() { - return this.a; - } - - private int b; - - public int getB() { - return this.b; - } - - private int sum; - - public int getSum() { - return this.sum; - } -} +package demo; + +import java.util.List; +import org.jnario.lib.ExampleTableRow; + +@SuppressWarnings("all") +public class CalculatorSpecExamples extends ExampleTableRow { + public CalculatorSpecExamples(final List cellNames, final int a, final int b, final int sum) { + super(cellNames); + this.a = a; + this.b = b; + this.sum = sum; + + } + + private int a; + + public int getA() { + return this.a; + } + + private int b; + + public int getB() { + return this.b; + } + + private int sum; + + public int getSum() { + return this.sum; + } +} diff --git a/examples/org.jnario.maven.example/src/test/jnario-gen/demo/TestSuiteSuite.java b/examples/org.jnario.maven.example/src/test/jnario-gen/demo/TestSuiteSuite.java index 52fa8202a..b6e5009b0 100644 --- a/examples/org.jnario.maven.example/src/test/jnario-gen/demo/TestSuiteSuite.java +++ b/examples/org.jnario.maven.example/src/test/jnario-gen/demo/TestSuiteSuite.java @@ -1,14 +1,14 @@ -package demo; - -import demo.CalculatorSpec; -import org.jnario.runner.Contains; -import org.jnario.runner.ExampleGroupRunner; -import org.jnario.runner.Named; -import org.junit.runner.RunWith; - -@Named("Test Suite") -@Contains(CalculatorSpec.class) -@RunWith(ExampleGroupRunner.class) -@SuppressWarnings("all") -public class TestSuiteSuite { -} +package demo; + +import demo.CalculatorSpec; +import org.jnario.runner.Contains; +import org.jnario.runner.ExampleGroupRunner; +import org.jnario.runner.Named; +import org.junit.runner.RunWith; + +@Named("Test Suite") +@Contains(CalculatorSpec.class) +@RunWith(ExampleGroupRunner.class) +@SuppressWarnings("all") +public class TestSuiteSuite { +} diff --git a/examples/selenium-example/src/test/xtend-gen/selenium/WebDriverExtension.java b/examples/selenium-example/src/test/xtend-gen/selenium/WebDriverExtension.java index 8e95133a9..1e508666f 100644 --- a/examples/selenium-example/src/test/xtend-gen/selenium/WebDriverExtension.java +++ b/examples/selenium-example/src/test/xtend-gen/selenium/WebDriverExtension.java @@ -1,49 +1,48 @@ -package selenium; - -import com.google.common.base.Function; -import org.junit.After; -import org.openqa.selenium.By; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.firefox.FirefoxDriver; -import org.openqa.selenium.support.ui.Wait; -import org.openqa.selenium.support.ui.WebDriverWait; - -@SuppressWarnings("all") -public class WebDriverExtension { - private WebDriver driver; - - private Wait wait; - - public WebDriverExtension() { - this(new FirefoxDriver()); - } - - public WebDriverExtension(final WebDriver driver) { - this.driver = driver; - WebDriverWait _webDriverWait = new WebDriverWait(driver, 30); - this.wait = _webDriverWait; - } - - public void get(final String url) { - this.driver.get(url); - } - - public WebElement findElement(final String name) { - By _name = By.name(name); - return this.driver.findElement(_name); - } - - public WebElement findElement(final By by) { - return this.driver.findElement(by); - } - - public Boolean waitUntil(final Function predicate) { - return this.wait.until(predicate); - } - - @After - public void tearDown() { - this.driver.close(); - } -} +package selenium; + +import com.google.common.base.Function; +import org.junit.After; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.openqa.selenium.support.ui.Wait; +import org.openqa.selenium.support.ui.WebDriverWait; + +@SuppressWarnings("all") +public class WebDriverExtension { + private WebDriver driver; + + private Wait wait; + + public WebDriverExtension() { + this(new FirefoxDriver()); + } + + public WebDriverExtension(final WebDriver driver) { + this.driver = driver; + WebDriverWait _webDriverWait = new WebDriverWait(driver, 30); + this.wait = _webDriverWait; + } + + public void get(final String url) { + this.driver.get(url); + } + + public WebElement findElement(final String name) { + return this.driver.findElement(By.name(name)); + } + + public WebElement findElement(final By by) { + return this.driver.findElement(by); + } + + public Boolean waitUntil(final Function predicate) { + return this.wait.until(predicate); + } + + @After + public void tearDown() { + this.driver.close(); + } +} diff --git a/plugins/org.jnario.feature.ui/xtend-gen/org/jnario/feature/ui/hover/FeatureHoverProvider.java b/plugins/org.jnario.feature.ui/xtend-gen/org/jnario/feature/ui/hover/FeatureHoverProvider.java index 84ec2650e..75827c3d7 100644 --- a/plugins/org.jnario.feature.ui/xtend-gen/org/jnario/feature/ui/hover/FeatureHoverProvider.java +++ b/plugins/org.jnario.feature.ui/xtend-gen/org/jnario/feature/ui/hover/FeatureHoverProvider.java @@ -1,51 +1,48 @@ -package org.jnario.feature.ui.hover; - -import com.google.inject.Inject; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.xtend2.lib.StringConcatenation; -import org.eclipse.xtext.nodemodel.ICompositeNode; -import org.eclipse.xtext.nodemodel.util.NodeModelUtils; -import org.eclipse.xtext.xbase.XExpression; -import org.eclipse.xtext.xbase.lib.Extension; -import org.jnario.doc.WhiteSpaceNormalizer; -import org.jnario.feature.feature.Step; -import org.jnario.ui.doc.JnarioHoverProvider; - -@SuppressWarnings("all") -public class FeatureHoverProvider extends JnarioHoverProvider { - @Inject - @Extension - private WhiteSpaceNormalizer normalizer; - - @Override - protected String getDocumentation(final EObject o) { - String _switchResult = null; - boolean _matched = false; - if (o instanceof Step) { - _matched=true; - _switchResult = this.getDocumentation(((Step)o)); - } - if (!_matched) { - _switchResult = super.getDocumentation(o); - } - return _switchResult; - } - - public String getDocumentation(final Step step) { - String _xblockexpression = null; - { - XExpression _expression = step.getExpression(); - final ICompositeNode node = NodeModelUtils.getNode(_expression); - StringConcatenation _builder = new StringConcatenation(); - _builder.append("
");
-      _builder.newLine();
-      String _text = node.getText();
-      String _normalize = this.normalizer.normalize(_text);
-      _builder.append(_normalize, "");
-      _builder.newLineIfNotEmpty();
-      _builder.append("
"); - _xblockexpression = _builder.toString(); - } - return _xblockexpression; - } -} +package org.jnario.feature.ui.hover; + +import com.google.inject.Inject; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.xtend2.lib.StringConcatenation; +import org.eclipse.xtext.nodemodel.ICompositeNode; +import org.eclipse.xtext.nodemodel.util.NodeModelUtils; +import org.eclipse.xtext.xbase.lib.Extension; +import org.jnario.doc.WhiteSpaceNormalizer; +import org.jnario.feature.feature.Step; +import org.jnario.ui.doc.JnarioHoverProvider; + +@SuppressWarnings("all") +public class FeatureHoverProvider extends JnarioHoverProvider { + @Inject + @Extension + private WhiteSpaceNormalizer normalizer; + + @Override + protected String getDocumentation(final EObject o) { + String _switchResult = null; + boolean _matched = false; + if (o instanceof Step) { + _matched=true; + _switchResult = this.getDocumentation(((Step)o)); + } + if (!_matched) { + _switchResult = super.getDocumentation(o); + } + return _switchResult; + } + + public String getDocumentation(final Step step) { + String _xblockexpression = null; + { + final ICompositeNode node = NodeModelUtils.getNode(step.getExpression()); + StringConcatenation _builder = new StringConcatenation(); + _builder.append("
");
+      _builder.newLine();
+      String _normalize = this.normalizer.normalize(node.getText());
+      _builder.append(_normalize);
+      _builder.newLineIfNotEmpty();
+      _builder.append("
"); + _xblockexpression = _builder.toString(); + } + return _xblockexpression; + } +} diff --git a/plugins/org.jnario.feature/xtend-gen/org/jnario/feature/doc/FeatureDocGenerator.java b/plugins/org.jnario.feature/xtend-gen/org/jnario/feature/doc/FeatureDocGenerator.java index f66e7e63f..a86d715a9 100644 --- a/plugins/org.jnario.feature/xtend-gen/org/jnario/feature/doc/FeatureDocGenerator.java +++ b/plugins/org.jnario.feature/xtend-gen/org/jnario/feature/doc/FeatureDocGenerator.java @@ -1,204 +1,184 @@ -/** - * Copyright (c) 2012 BMW Car IT and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.jnario.feature.doc; - -import com.google.inject.Inject; -import java.util.Arrays; -import java.util.regex.Matcher; -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.xtend2.lib.StringConcatenation; -import org.eclipse.xtext.util.Strings; -import org.eclipse.xtext.xbase.lib.Extension; -import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; -import org.jnario.JnarioClass; -import org.jnario.JnarioMember; -import org.jnario.doc.AbstractDocGenerator; -import org.jnario.doc.HtmlFile; -import org.jnario.feature.feature.Feature; -import org.jnario.feature.feature.Scenario; -import org.jnario.feature.feature.Step; -import org.jnario.feature.jvmmodel.StepArgumentsProvider; -import org.jnario.feature.naming.FeatureClassNameProvider; -import org.jnario.feature.naming.StepNameProvider; - -@SuppressWarnings("all") -public class FeatureDocGenerator extends AbstractDocGenerator { - @Inject - @Extension - private FeatureClassNameProvider _featureClassNameProvider; - - @Inject - @Extension - private StepNameProvider _stepNameProvider; - - @Override - public HtmlFile createHtmlFile(final JnarioClass xtendClass) { - if ((!(xtendClass instanceof Feature))) { - return HtmlFile.EMPTY_FILE; - } - final Feature feature = ((Feature) xtendClass); - final Procedure1 _function = new Procedure1() { - @Override - public void apply(final HtmlFile it) { - String _javaClassName = FeatureDocGenerator.this._featureClassNameProvider.toJavaClassName(feature); - it.setName(_javaClassName); - String _name = feature.getName(); - it.setTitle(_name); - CharSequence _generateContent = FeatureDocGenerator.this.generateContent(feature); - it.setContent(_generateContent); - String _root = FeatureDocGenerator.this.root(feature); - it.setRootFolder(_root); - EObject _eContainer = feature.eContainer(); - CharSequence _pre = FeatureDocGenerator.this.pre(_eContainer, "lang-feature"); - it.setSourceCode(_pre); - String _fileName = FeatureDocGenerator.this.fileName(feature); - it.setFileName(_fileName); - String _executionStateClass = FeatureDocGenerator.this.executionStateClass(feature); - it.setExecutionStatus(_executionStateClass); - } - }; - return HtmlFile.newHtmlFile(_function); - } - - public CharSequence generateContent(final Feature feature) { - StringConcatenation _builder = new StringConcatenation(); - String _description = feature.getDescription(); - String _markdown2Html = null; - if (_description!=null) { - _markdown2Html=this.markdown2Html(_description); - } - _builder.append(_markdown2Html, ""); - _builder.newLineIfNotEmpty(); - { - EList _members = feature.getMembers(); - for(final JnarioMember member : _members) { - CharSequence _generate = this.generate(member); - _builder.append(_generate, ""); - _builder.newLineIfNotEmpty(); - } - } - return _builder; - } - - protected CharSequence _generate(final Scenario scenario) { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("

"); - String _name_1 = scenario.getName(); - _builder.append(_name_1, ""); - _builder.append("

"); - _builder.newLineIfNotEmpty(); - EList _steps = scenario.getSteps(); - CharSequence _generate = this.generate(_steps); - _builder.append(_generate, ""); - _builder.append("
"); - _builder.newLineIfNotEmpty(); - return _builder; - } - - protected CharSequence _generate(final Iterable steps) { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("
    "); - _builder.newLine(); - { - for(final Step step : steps) { - _builder.append("
  • "); - Object _generate = this.generate(step); - _builder.append(_generate, ""); - _builder.append("
  • "); - _builder.newLineIfNotEmpty(); - } - } - _builder.append("
"); - _builder.newLine(); - return _builder; - } - - protected CharSequence _generate(final Step step) { - StringConcatenation _builder = new StringConcatenation(); - _builder.append(""); - String _format = this.format(step); - _builder.append(_format, ""); - _builder.append(""); - _builder.newLineIfNotEmpty(); - String _errorMessage = this.errorMessage(step); - _builder.append(_errorMessage, ""); - _builder.newLineIfNotEmpty(); - return _builder; - } - - private String format(final Step step) { - String _describe = this._stepNameProvider.describe(step); - String result = Strings.convertFromJavaString(_describe, true); - String _highlighFirstWord = this.highlighFirstWord(result); - result = _highlighFirstWord; - String _highlightArguments = this.highlightArguments(result); - result = _highlightArguments; - String _markdown2Html = this.markdown2Html(result); - result = _markdown2Html; - String _addCodeBlock = this.addCodeBlock(step); - String _plus = (result + _addCodeBlock); - result = _plus; - return result; - } - - private String highlightArguments(final String s) { - Matcher _matcher = StepArgumentsProvider.ARG_PATTERN.matcher((" " + s)); - return _matcher.replaceAll("$0"); - } - - private String highlighFirstWord(final String s) { - return s; - } - - private String addCodeBlock(final Step step) { - final String text = this._stepNameProvider.nameOf(step); - final int multiLineStart = text.indexOf("\n"); - if ((multiLineStart == (-1))) { - return ""; - } - String _substring = text.substring(multiLineStart); - String codeBlock = _substring.trim(); - int _length = StepArgumentsProvider.MULTILINE_STRING.length(); - int _length_1 = codeBlock.length(); - int _length_2 = StepArgumentsProvider.MULTILINE_STRING.length(); - int _minus = (_length_1 - _length_2); - String _substring_1 = codeBlock.substring(_length, _minus); - codeBlock = _substring_1; - String _codeToHtml = this.codeToHtml(codeBlock); - codeBlock = _codeToHtml; - StringConcatenation _builder = new StringConcatenation(); - _builder.append("
");
-    _builder.append(codeBlock, "");
-    _builder.append("
"); - return _builder.toString(); - } - - public CharSequence generate(final Object scenario) { - if (scenario instanceof Scenario) { - return _generate((Scenario)scenario); - } else if (scenario instanceof Step) { - return _generate((Step)scenario); - } else if (scenario instanceof Iterable) { - return _generate((Iterable)scenario); - } else { - throw new IllegalArgumentException("Unhandled parameter types: " + - Arrays.asList(scenario).toString()); - } - } -} +/** + * Copyright (c) 2012 BMW Car IT and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.jnario.feature.doc; + +import com.google.inject.Inject; +import java.util.Arrays; +import org.eclipse.emf.common.util.EList; +import org.eclipse.xtend2.lib.StringConcatenation; +import org.eclipse.xtext.util.Strings; +import org.eclipse.xtext.xbase.lib.Extension; +import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; +import org.jnario.JnarioClass; +import org.jnario.JnarioMember; +import org.jnario.doc.AbstractDocGenerator; +import org.jnario.doc.HtmlFile; +import org.jnario.feature.feature.Feature; +import org.jnario.feature.feature.Scenario; +import org.jnario.feature.feature.Step; +import org.jnario.feature.jvmmodel.StepArgumentsProvider; +import org.jnario.feature.naming.FeatureClassNameProvider; +import org.jnario.feature.naming.StepNameProvider; + +@SuppressWarnings("all") +public class FeatureDocGenerator extends AbstractDocGenerator { + @Inject + @Extension + private FeatureClassNameProvider _featureClassNameProvider; + + @Inject + @Extension + private StepNameProvider _stepNameProvider; + + @Override + public HtmlFile createHtmlFile(final JnarioClass xtendClass) { + if ((!(xtendClass instanceof Feature))) { + return HtmlFile.EMPTY_FILE; + } + final Feature feature = ((Feature) xtendClass); + final Procedure1 _function = new Procedure1() { + @Override + public void apply(final HtmlFile it) { + it.setName(FeatureDocGenerator.this._featureClassNameProvider.toJavaClassName(feature)); + it.setTitle(feature.getName()); + it.setContent(FeatureDocGenerator.this.generateContent(feature)); + it.setRootFolder(FeatureDocGenerator.this.root(feature)); + it.setSourceCode(FeatureDocGenerator.this.pre(feature.eContainer(), "lang-feature")); + it.setFileName(FeatureDocGenerator.this.fileName(feature)); + it.setExecutionStatus(FeatureDocGenerator.this.executionStateClass(feature)); + } + }; + return HtmlFile.newHtmlFile(_function); + } + + public CharSequence generateContent(final Feature feature) { + StringConcatenation _builder = new StringConcatenation(); + String _description = feature.getDescription(); + String _markdown2Html = null; + if (_description!=null) { + _markdown2Html=this.markdown2Html(_description); + } + _builder.append(_markdown2Html); + _builder.newLineIfNotEmpty(); + { + EList _members = feature.getMembers(); + for(final JnarioMember member : _members) { + CharSequence _generate = this.generate(member); + _builder.append(_generate); + _builder.newLineIfNotEmpty(); + } + } + return _builder; + } + + protected CharSequence _generate(final Scenario scenario) { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("

"); + String _name = scenario.getName(); + _builder.append(_name); + _builder.append("

"); + _builder.newLineIfNotEmpty(); + CharSequence _generate = this.generate(scenario.getSteps()); + _builder.append(_generate); + _builder.append("
"); + _builder.newLineIfNotEmpty(); + return _builder; + } + + protected CharSequence _generate(final Iterable steps) { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("
    "); + _builder.newLine(); + { + for(final Step step : steps) { + _builder.append("
  • "); + Object _generate = this.generate(step); + _builder.append(_generate); + _builder.append("
  • "); + _builder.newLineIfNotEmpty(); + } + } + _builder.append("
"); + _builder.newLine(); + return _builder; + } + + protected CharSequence _generate(final Step step) { + StringConcatenation _builder = new StringConcatenation(); + _builder.append(""); + String _format = this.format(step); + _builder.append(_format); + _builder.append(""); + _builder.newLineIfNotEmpty(); + String _errorMessage = this.errorMessage(step); + _builder.append(_errorMessage); + _builder.newLineIfNotEmpty(); + return _builder; + } + + private String format(final Step step) { + String result = Strings.convertFromJavaString(this._stepNameProvider.describe(step), true); + result = this.highlighFirstWord(result); + result = this.highlightArguments(result); + result = this.markdown2Html(result); + String _addCodeBlock = this.addCodeBlock(step); + String _plus = (result + _addCodeBlock); + result = _plus; + return result; + } + + private String highlightArguments(final String s) { + return StepArgumentsProvider.ARG_PATTERN.matcher((" " + s)).replaceAll("$0"); + } + + private String highlighFirstWord(final String s) { + return s; + } + + private String addCodeBlock(final Step step) { + final String text = this._stepNameProvider.nameOf(step); + final int multiLineStart = text.indexOf("\n"); + if ((multiLineStart == (-1))) { + return ""; + } + String codeBlock = text.substring(multiLineStart).trim(); + int _length = StepArgumentsProvider.MULTILINE_STRING.length(); + int _length_1 = codeBlock.length(); + int _length_2 = StepArgumentsProvider.MULTILINE_STRING.length(); + int _minus = (_length_1 - _length_2); + codeBlock = codeBlock.substring(_length, _minus); + codeBlock = this.codeToHtml(codeBlock); + StringConcatenation _builder = new StringConcatenation(); + _builder.append("
");
+    _builder.append(codeBlock);
+    _builder.append("
"); + return _builder.toString(); + } + + public CharSequence generate(final Object scenario) { + if (scenario instanceof Scenario) { + return _generate((Scenario)scenario); + } else if (scenario instanceof Step) { + return _generate((Step)scenario); + } else if (scenario instanceof Iterable) { + return _generate((Iterable)scenario); + } else { + throw new IllegalArgumentException("Unhandled parameter types: " + + Arrays.asList(scenario).toString()); + } + } +} diff --git a/plugins/org.jnario.feature/xtend-gen/org/jnario/feature/formatting/FeatureFormatter2.java b/plugins/org.jnario.feature/xtend-gen/org/jnario/feature/formatting/FeatureFormatter2.java index 13ef8499f..6632ab91e 100644 --- a/plugins/org.jnario.feature/xtend-gen/org/jnario/feature/formatting/FeatureFormatter2.java +++ b/plugins/org.jnario.feature/xtend-gen/org/jnario/feature/formatting/FeatureFormatter2.java @@ -1,13 +1,13 @@ -package org.jnario.feature.formatting; - -import com.google.inject.Inject; -import org.eclipse.xtext.xbase.lib.Extension; -import org.jnario.feature.services.FeatureGrammarAccess; -import org.jnario.formatter.JnarioFormatter; - -@SuppressWarnings("all") -public class FeatureFormatter2 extends JnarioFormatter { - @Inject - @Extension - private FeatureGrammarAccess _featureGrammarAccess; -} +package org.jnario.feature.formatting; + +import com.google.inject.Inject; +import org.eclipse.xtext.xbase.lib.Extension; +import org.jnario.feature.services.FeatureGrammarAccess; +import org.jnario.formatter.JnarioFormatter; + +@SuppressWarnings("all") +public class FeatureFormatter2 extends JnarioFormatter { + @Inject + @Extension + private FeatureGrammarAccess _featureGrammarAccess; +} diff --git a/plugins/org.jnario.feature/xtend-gen/org/jnario/feature/formatting2/FeatureFormatter.java b/plugins/org.jnario.feature/xtend-gen/org/jnario/feature/formatting2/FeatureFormatter.java index de6476d20..b08175433 100644 --- a/plugins/org.jnario.feature/xtend-gen/org/jnario/feature/formatting2/FeatureFormatter.java +++ b/plugins/org.jnario.feature/xtend-gen/org/jnario/feature/formatting2/FeatureFormatter.java @@ -1,391 +1,368 @@ -/** - * generated by Xtext - */ -package org.jnario.feature.formatting2; - -import com.google.inject.Inject; -import java.util.Arrays; -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.xtext.common.types.JvmFormalParameter; -import org.eclipse.xtext.common.types.JvmGenericArrayTypeReference; -import org.eclipse.xtext.common.types.JvmParameterizedTypeReference; -import org.eclipse.xtext.common.types.JvmTypeConstraint; -import org.eclipse.xtext.common.types.JvmTypeParameter; -import org.eclipse.xtext.common.types.JvmTypeReference; -import org.eclipse.xtext.common.types.JvmWildcardTypeReference; -import org.eclipse.xtext.formatting2.IFormattableDocument; -import org.eclipse.xtext.resource.XtextResource; -import org.eclipse.xtext.xbase.XAssignment; -import org.eclipse.xtext.xbase.XBasicForLoopExpression; -import org.eclipse.xtext.xbase.XBinaryOperation; -import org.eclipse.xtext.xbase.XBlockExpression; -import org.eclipse.xtext.xbase.XCastedExpression; -import org.eclipse.xtext.xbase.XClosure; -import org.eclipse.xtext.xbase.XCollectionLiteral; -import org.eclipse.xtext.xbase.XConstructorCall; -import org.eclipse.xtext.xbase.XDoWhileExpression; -import org.eclipse.xtext.xbase.XExpression; -import org.eclipse.xtext.xbase.XFeatureCall; -import org.eclipse.xtext.xbase.XForLoopExpression; -import org.eclipse.xtext.xbase.XIfExpression; -import org.eclipse.xtext.xbase.XInstanceOfExpression; -import org.eclipse.xtext.xbase.XMemberFeatureCall; -import org.eclipse.xtext.xbase.XPostfixOperation; -import org.eclipse.xtext.xbase.XReturnExpression; -import org.eclipse.xtext.xbase.XSwitchExpression; -import org.eclipse.xtext.xbase.XSynchronizedExpression; -import org.eclipse.xtext.xbase.XThrowExpression; -import org.eclipse.xtext.xbase.XTryCatchFinallyExpression; -import org.eclipse.xtext.xbase.XTypeLiteral; -import org.eclipse.xtext.xbase.XVariableDeclaration; -import org.eclipse.xtext.xbase.XWhileExpression; -import org.eclipse.xtext.xbase.annotations.formatting2.XbaseWithAnnotationsFormatter; -import org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation; -import org.eclipse.xtext.xbase.lib.Extension; -import org.eclipse.xtext.xtype.XFunctionTypeRef; -import org.eclipse.xtext.xtype.XImportDeclaration; -import org.eclipse.xtext.xtype.XImportSection; -import org.jnario.Assertion; -import org.jnario.JnarioAnnotationTarget; -import org.jnario.JnarioField; -import org.jnario.JnarioFunction; -import org.jnario.JnarioMember; -import org.jnario.JnarioParameter; -import org.jnario.JnarioTypeDeclaration; -import org.jnario.Should; -import org.jnario.ShouldThrow; -import org.jnario.feature.feature.And; -import org.jnario.feature.feature.Background; -import org.jnario.feature.feature.But; -import org.jnario.feature.feature.Feature; -import org.jnario.feature.feature.FeatureFile; -import org.jnario.feature.feature.Given; -import org.jnario.feature.feature.Scenario; -import org.jnario.feature.feature.Then; -import org.jnario.feature.feature.When; -import org.jnario.feature.services.FeatureGrammarAccess; - -@SuppressWarnings("all") -public class FeatureFormatter extends XbaseWithAnnotationsFormatter { - @Inject - @Extension - private FeatureGrammarAccess _featureGrammarAccess; - - protected void _format(final FeatureFile featurefile, @Extension final IFormattableDocument document) { - XImportSection _importSection = featurefile.getImportSection(); - this.format(_importSection, document); - EList _xtendTypes = featurefile.getXtendTypes(); - for (final JnarioTypeDeclaration xtendTypes : _xtendTypes) { - this.format(xtendTypes, document); - } - } - - protected void _format(final Feature feature, @Extension final IFormattableDocument document) { - EList _annotations = feature.getAnnotations(); - for (final XAnnotation annotations : _annotations) { - this.format(annotations, document); - } - EList _members = feature.getMembers(); - for (final JnarioMember members : _members) { - this.format(members, document); - } - } - - protected void _format(final Background background, @Extension final IFormattableDocument document) { - EList _members = background.getMembers(); - for (final JnarioMember members : _members) { - this.format(members, document); - } - } - - protected void _format(final Scenario scenario, @Extension final IFormattableDocument document) { - EList _members = scenario.getMembers(); - for (final JnarioMember members : _members) { - this.format(members, document); - } - } - - protected void _format(final JnarioMember jnariomember, @Extension final IFormattableDocument document) { - EList _annotations = jnariomember.getAnnotations(); - for (final XAnnotation annotations : _annotations) { - this.format(annotations, document); - } - } - - protected void _format(final JnarioField jnariofield, @Extension final IFormattableDocument document) { - JvmTypeReference _type = jnariofield.getType(); - this.format(_type, document); - XExpression _initialValue = jnariofield.getInitialValue(); - this.format(_initialValue, document); - JnarioAnnotationTarget _annotationInfo = jnariofield.getAnnotationInfo(); - this.format(_annotationInfo, document); - } - - protected void _format(final Given given, @Extension final IFormattableDocument document) { - XExpression _expression = given.getExpression(); - this.format(_expression, document); - } - - protected void _format(final When when, @Extension final IFormattableDocument document) { - XExpression _expression = when.getExpression(); - this.format(_expression, document); - } - - protected void _format(final Then then, @Extension final IFormattableDocument document) { - XExpression _expression = then.getExpression(); - this.format(_expression, document); - } - - protected void _format(final And and, @Extension final IFormattableDocument document) { - XExpression _expression = and.getExpression(); - this.format(_expression, document); - } - - protected void _format(final But but, @Extension final IFormattableDocument document) { - XExpression _expression = but.getExpression(); - this.format(_expression, document); - } - - @Override - protected void _format(final XBlockExpression xblockexpression, @Extension final IFormattableDocument document) { - EList _expressions = xblockexpression.getExpressions(); - for (final XExpression expressions : _expressions) { - this.format(expressions, document); - } - } - - protected void _format(final Should should, @Extension final IFormattableDocument document) { - XExpression _rightOperand = should.getRightOperand(); - this.format(_rightOperand, document); - XExpression _leftOperand = should.getLeftOperand(); - this.format(_leftOperand, document); - } - - protected void _format(final ShouldThrow shouldthrow, @Extension final IFormattableDocument document) { - JvmTypeReference _type = shouldthrow.getType(); - this.format(_type, document); - XExpression _expression = shouldthrow.getExpression(); - this.format(_expression, document); - } - - @Override - protected void _format(final XInstanceOfExpression xinstanceofexpression, @Extension final IFormattableDocument document) { - JvmTypeReference _type = xinstanceofexpression.getType(); - this.format(_type, document); - XExpression _expression = xinstanceofexpression.getExpression(); - this.format(_expression, document); - } - - @Override - protected void _format(final XBinaryOperation xbinaryoperation, @Extension final IFormattableDocument document) { - XExpression _rightOperand = xbinaryoperation.getRightOperand(); - this.format(_rightOperand, document); - XExpression _leftOperand = xbinaryoperation.getLeftOperand(); - this.format(_leftOperand, document); - } - - protected void _format(final Assertion assertion, @Extension final IFormattableDocument document) { - XExpression _expression = assertion.getExpression(); - this.format(_expression, document); - } - - protected void _format(final JnarioFunction jnariofunction, @Extension final IFormattableDocument document) { - EList _typeParameters = jnariofunction.getTypeParameters(); - for (final JvmTypeParameter typeParameters : _typeParameters) { - this.format(typeParameters, document); - } - JvmTypeReference _returnType = jnariofunction.getReturnType(); - this.format(_returnType, document); - EList _parameters = jnariofunction.getParameters(); - for (final JnarioParameter parameters : _parameters) { - this.format(parameters, document); - } - EList _exceptions = jnariofunction.getExceptions(); - for (final JvmTypeReference exceptions : _exceptions) { - this.format(exceptions, document); - } - XExpression _expression = jnariofunction.getExpression(); - this.format(_expression, document); - JnarioAnnotationTarget _annotationInfo = jnariofunction.getAnnotationInfo(); - this.format(_annotationInfo, document); - } - - protected void _format(final JnarioParameter jnarioparameter, @Extension final IFormattableDocument document) { - EList _annotations = jnarioparameter.getAnnotations(); - for (final XAnnotation annotations : _annotations) { - this.format(annotations, document); - } - JvmTypeReference _parameterType = jnarioparameter.getParameterType(); - this.format(_parameterType, document); - } - - public void format(final Object and, final IFormattableDocument document) { - if (and instanceof And) { - _format((And)and, document); - return; - } else if (and instanceof Background) { - _format((Background)and, document); - return; - } else if (and instanceof But) { - _format((But)and, document); - return; - } else if (and instanceof Feature) { - _format((Feature)and, document); - return; - } else if (and instanceof Given) { - _format((Given)and, document); - return; - } else if (and instanceof Then) { - _format((Then)and, document); - return; - } else if (and instanceof When) { - _format((When)and, document); - return; - } else if (and instanceof Scenario) { - _format((Scenario)and, document); - return; - } else if (and instanceof JvmTypeParameter) { - _format((JvmTypeParameter)and, document); - return; - } else if (and instanceof Should) { - _format((Should)and, document); - return; - } else if (and instanceof JvmFormalParameter) { - _format((JvmFormalParameter)and, document); - return; - } else if (and instanceof XtextResource) { - _format((XtextResource)and, document); - return; - } else if (and instanceof XAssignment) { - _format((XAssignment)and, document); - return; - } else if (and instanceof XBinaryOperation) { - _format((XBinaryOperation)and, document); - return; - } else if (and instanceof XDoWhileExpression) { - _format((XDoWhileExpression)and, document); - return; - } else if (and instanceof XFeatureCall) { - _format((XFeatureCall)and, document); - return; - } else if (and instanceof XMemberFeatureCall) { - _format((XMemberFeatureCall)and, document); - return; - } else if (and instanceof XPostfixOperation) { - _format((XPostfixOperation)and, document); - return; - } else if (and instanceof XWhileExpression) { - _format((XWhileExpression)and, document); - return; - } else if (and instanceof XFunctionTypeRef) { - _format((XFunctionTypeRef)and, document); - return; - } else if (and instanceof JnarioField) { - _format((JnarioField)and, document); - return; - } else if (and instanceof JnarioFunction) { - _format((JnarioFunction)and, document); - return; - } else if (and instanceof JvmGenericArrayTypeReference) { - _format((JvmGenericArrayTypeReference)and, document); - return; - } else if (and instanceof JvmParameterizedTypeReference) { - _format((JvmParameterizedTypeReference)and, document); - return; - } else if (and instanceof JvmWildcardTypeReference) { - _format((JvmWildcardTypeReference)and, document); - return; - } else if (and instanceof XBasicForLoopExpression) { - _format((XBasicForLoopExpression)and, document); - return; - } else if (and instanceof XBlockExpression) { - _format((XBlockExpression)and, document); - return; - } else if (and instanceof XCastedExpression) { - _format((XCastedExpression)and, document); - return; - } else if (and instanceof XClosure) { - _format((XClosure)and, document); - return; - } else if (and instanceof XCollectionLiteral) { - _format((XCollectionLiteral)and, document); - return; - } else if (and instanceof XConstructorCall) { - _format((XConstructorCall)and, document); - return; - } else if (and instanceof XForLoopExpression) { - _format((XForLoopExpression)and, document); - return; - } else if (and instanceof XIfExpression) { - _format((XIfExpression)and, document); - return; - } else if (and instanceof XInstanceOfExpression) { - _format((XInstanceOfExpression)and, document); - return; - } else if (and instanceof XReturnExpression) { - _format((XReturnExpression)and, document); - return; - } else if (and instanceof XSwitchExpression) { - _format((XSwitchExpression)and, document); - return; - } else if (and instanceof XSynchronizedExpression) { - _format((XSynchronizedExpression)and, document); - return; - } else if (and instanceof XThrowExpression) { - _format((XThrowExpression)and, document); - return; - } else if (and instanceof XTryCatchFinallyExpression) { - _format((XTryCatchFinallyExpression)and, document); - return; - } else if (and instanceof XTypeLiteral) { - _format((XTypeLiteral)and, document); - return; - } else if (and instanceof XVariableDeclaration) { - _format((XVariableDeclaration)and, document); - return; - } else if (and instanceof XAnnotation) { - _format((XAnnotation)and, document); - return; - } else if (and instanceof Assertion) { - _format((Assertion)and, document); - return; - } else if (and instanceof JnarioMember) { - _format((JnarioMember)and, document); - return; - } else if (and instanceof JnarioParameter) { - _format((JnarioParameter)and, document); - return; - } else if (and instanceof ShouldThrow) { - _format((ShouldThrow)and, document); - return; - } else if (and instanceof FeatureFile) { - _format((FeatureFile)and, document); - return; - } else if (and instanceof JvmTypeConstraint) { - _format((JvmTypeConstraint)and, document); - return; - } else if (and instanceof XExpression) { - _format((XExpression)and, document); - return; - } else if (and instanceof XImportDeclaration) { - _format((XImportDeclaration)and, document); - return; - } else if (and instanceof XImportSection) { - _format((XImportSection)and, document); - return; - } else if (and instanceof EObject) { - _format((EObject)and, document); - return; - } else if (and == null) { - _format((Void)null, document); - return; - } else if (and != null) { - _format(and, document); - return; - } else { - throw new IllegalArgumentException("Unhandled parameter types: " + - Arrays.asList(and, document).toString()); - } - } -} +/** + * generated by Xtext + */ +package org.jnario.feature.formatting2; + +import com.google.inject.Inject; +import java.util.Arrays; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.xtext.common.types.JvmFormalParameter; +import org.eclipse.xtext.common.types.JvmGenericArrayTypeReference; +import org.eclipse.xtext.common.types.JvmParameterizedTypeReference; +import org.eclipse.xtext.common.types.JvmTypeConstraint; +import org.eclipse.xtext.common.types.JvmTypeParameter; +import org.eclipse.xtext.common.types.JvmTypeReference; +import org.eclipse.xtext.common.types.JvmWildcardTypeReference; +import org.eclipse.xtext.formatting2.IFormattableDocument; +import org.eclipse.xtext.resource.XtextResource; +import org.eclipse.xtext.xbase.XAssignment; +import org.eclipse.xtext.xbase.XBasicForLoopExpression; +import org.eclipse.xtext.xbase.XBinaryOperation; +import org.eclipse.xtext.xbase.XBlockExpression; +import org.eclipse.xtext.xbase.XCastedExpression; +import org.eclipse.xtext.xbase.XClosure; +import org.eclipse.xtext.xbase.XCollectionLiteral; +import org.eclipse.xtext.xbase.XConstructorCall; +import org.eclipse.xtext.xbase.XDoWhileExpression; +import org.eclipse.xtext.xbase.XExpression; +import org.eclipse.xtext.xbase.XFeatureCall; +import org.eclipse.xtext.xbase.XForLoopExpression; +import org.eclipse.xtext.xbase.XIfExpression; +import org.eclipse.xtext.xbase.XInstanceOfExpression; +import org.eclipse.xtext.xbase.XMemberFeatureCall; +import org.eclipse.xtext.xbase.XPostfixOperation; +import org.eclipse.xtext.xbase.XReturnExpression; +import org.eclipse.xtext.xbase.XSwitchExpression; +import org.eclipse.xtext.xbase.XSynchronizedExpression; +import org.eclipse.xtext.xbase.XThrowExpression; +import org.eclipse.xtext.xbase.XTryCatchFinallyExpression; +import org.eclipse.xtext.xbase.XTypeLiteral; +import org.eclipse.xtext.xbase.XVariableDeclaration; +import org.eclipse.xtext.xbase.XWhileExpression; +import org.eclipse.xtext.xbase.annotations.formatting2.XbaseWithAnnotationsFormatter; +import org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation; +import org.eclipse.xtext.xbase.lib.Extension; +import org.eclipse.xtext.xtype.XFunctionTypeRef; +import org.eclipse.xtext.xtype.XImportDeclaration; +import org.eclipse.xtext.xtype.XImportSection; +import org.jnario.Assertion; +import org.jnario.JnarioField; +import org.jnario.JnarioFunction; +import org.jnario.JnarioMember; +import org.jnario.JnarioParameter; +import org.jnario.JnarioTypeDeclaration; +import org.jnario.Should; +import org.jnario.ShouldThrow; +import org.jnario.feature.feature.And; +import org.jnario.feature.feature.Background; +import org.jnario.feature.feature.But; +import org.jnario.feature.feature.Feature; +import org.jnario.feature.feature.FeatureFile; +import org.jnario.feature.feature.Given; +import org.jnario.feature.feature.Scenario; +import org.jnario.feature.feature.Then; +import org.jnario.feature.feature.When; +import org.jnario.feature.services.FeatureGrammarAccess; + +@SuppressWarnings("all") +public class FeatureFormatter extends XbaseWithAnnotationsFormatter { + @Inject + @Extension + private FeatureGrammarAccess _featureGrammarAccess; + + protected void _format(final FeatureFile featurefile, @Extension final IFormattableDocument document) { + this.format(featurefile.getImportSection(), document); + EList _xtendTypes = featurefile.getXtendTypes(); + for (final JnarioTypeDeclaration xtendTypes : _xtendTypes) { + this.format(xtendTypes, document); + } + } + + protected void _format(final Feature feature, @Extension final IFormattableDocument document) { + EList _annotations = feature.getAnnotations(); + for (final XAnnotation annotations : _annotations) { + this.format(annotations, document); + } + EList _members = feature.getMembers(); + for (final JnarioMember members : _members) { + this.format(members, document); + } + } + + protected void _format(final Background background, @Extension final IFormattableDocument document) { + EList _members = background.getMembers(); + for (final JnarioMember members : _members) { + this.format(members, document); + } + } + + protected void _format(final Scenario scenario, @Extension final IFormattableDocument document) { + EList _members = scenario.getMembers(); + for (final JnarioMember members : _members) { + this.format(members, document); + } + } + + protected void _format(final JnarioMember jnariomember, @Extension final IFormattableDocument document) { + EList _annotations = jnariomember.getAnnotations(); + for (final XAnnotation annotations : _annotations) { + this.format(annotations, document); + } + } + + protected void _format(final JnarioField jnariofield, @Extension final IFormattableDocument document) { + this.format(jnariofield.getType(), document); + this.format(jnariofield.getInitialValue(), document); + this.format(jnariofield.getAnnotationInfo(), document); + } + + protected void _format(final Given given, @Extension final IFormattableDocument document) { + this.format(given.getExpression(), document); + } + + protected void _format(final When when, @Extension final IFormattableDocument document) { + this.format(when.getExpression(), document); + } + + protected void _format(final Then then, @Extension final IFormattableDocument document) { + this.format(then.getExpression(), document); + } + + protected void _format(final And and, @Extension final IFormattableDocument document) { + this.format(and.getExpression(), document); + } + + protected void _format(final But but, @Extension final IFormattableDocument document) { + this.format(but.getExpression(), document); + } + + @Override + protected void _format(final XBlockExpression xblockexpression, @Extension final IFormattableDocument document) { + EList _expressions = xblockexpression.getExpressions(); + for (final XExpression expressions : _expressions) { + this.format(expressions, document); + } + } + + protected void _format(final Should should, @Extension final IFormattableDocument document) { + this.format(should.getRightOperand(), document); + this.format(should.getLeftOperand(), document); + } + + protected void _format(final ShouldThrow shouldthrow, @Extension final IFormattableDocument document) { + this.format(shouldthrow.getType(), document); + this.format(shouldthrow.getExpression(), document); + } + + @Override + protected void _format(final XInstanceOfExpression xinstanceofexpression, @Extension final IFormattableDocument document) { + this.format(xinstanceofexpression.getType(), document); + this.format(xinstanceofexpression.getExpression(), document); + } + + @Override + protected void _format(final XBinaryOperation xbinaryoperation, @Extension final IFormattableDocument document) { + this.format(xbinaryoperation.getRightOperand(), document); + this.format(xbinaryoperation.getLeftOperand(), document); + } + + protected void _format(final Assertion assertion, @Extension final IFormattableDocument document) { + this.format(assertion.getExpression(), document); + } + + protected void _format(final JnarioFunction jnariofunction, @Extension final IFormattableDocument document) { + EList _typeParameters = jnariofunction.getTypeParameters(); + for (final JvmTypeParameter typeParameters : _typeParameters) { + this.format(typeParameters, document); + } + this.format(jnariofunction.getReturnType(), document); + EList _parameters = jnariofunction.getParameters(); + for (final JnarioParameter parameters : _parameters) { + this.format(parameters, document); + } + EList _exceptions = jnariofunction.getExceptions(); + for (final JvmTypeReference exceptions : _exceptions) { + this.format(exceptions, document); + } + this.format(jnariofunction.getExpression(), document); + this.format(jnariofunction.getAnnotationInfo(), document); + } + + protected void _format(final JnarioParameter jnarioparameter, @Extension final IFormattableDocument document) { + EList _annotations = jnarioparameter.getAnnotations(); + for (final XAnnotation annotations : _annotations) { + this.format(annotations, document); + } + this.format(jnarioparameter.getParameterType(), document); + } + + public void format(final Object and, final IFormattableDocument document) { + if (and instanceof And) { + _format((And)and, document); + return; + } else if (and instanceof Background) { + _format((Background)and, document); + return; + } else if (and instanceof But) { + _format((But)and, document); + return; + } else if (and instanceof Feature) { + _format((Feature)and, document); + return; + } else if (and instanceof Given) { + _format((Given)and, document); + return; + } else if (and instanceof Then) { + _format((Then)and, document); + return; + } else if (and instanceof When) { + _format((When)and, document); + return; + } else if (and instanceof Scenario) { + _format((Scenario)and, document); + return; + } else if (and instanceof JvmTypeParameter) { + _format((JvmTypeParameter)and, document); + return; + } else if (and instanceof Should) { + _format((Should)and, document); + return; + } else if (and instanceof JvmFormalParameter) { + _format((JvmFormalParameter)and, document); + return; + } else if (and instanceof XtextResource) { + _format((XtextResource)and, document); + return; + } else if (and instanceof XAssignment) { + _format((XAssignment)and, document); + return; + } else if (and instanceof XBinaryOperation) { + _format((XBinaryOperation)and, document); + return; + } else if (and instanceof XDoWhileExpression) { + _format((XDoWhileExpression)and, document); + return; + } else if (and instanceof XFeatureCall) { + _format((XFeatureCall)and, document); + return; + } else if (and instanceof XMemberFeatureCall) { + _format((XMemberFeatureCall)and, document); + return; + } else if (and instanceof XPostfixOperation) { + _format((XPostfixOperation)and, document); + return; + } else if (and instanceof XWhileExpression) { + _format((XWhileExpression)and, document); + return; + } else if (and instanceof XFunctionTypeRef) { + _format((XFunctionTypeRef)and, document); + return; + } else if (and instanceof JnarioField) { + _format((JnarioField)and, document); + return; + } else if (and instanceof JnarioFunction) { + _format((JnarioFunction)and, document); + return; + } else if (and instanceof JvmGenericArrayTypeReference) { + _format((JvmGenericArrayTypeReference)and, document); + return; + } else if (and instanceof JvmParameterizedTypeReference) { + _format((JvmParameterizedTypeReference)and, document); + return; + } else if (and instanceof JvmWildcardTypeReference) { + _format((JvmWildcardTypeReference)and, document); + return; + } else if (and instanceof XBasicForLoopExpression) { + _format((XBasicForLoopExpression)and, document); + return; + } else if (and instanceof XBlockExpression) { + _format((XBlockExpression)and, document); + return; + } else if (and instanceof XCastedExpression) { + _format((XCastedExpression)and, document); + return; + } else if (and instanceof XClosure) { + _format((XClosure)and, document); + return; + } else if (and instanceof XCollectionLiteral) { + _format((XCollectionLiteral)and, document); + return; + } else if (and instanceof XConstructorCall) { + _format((XConstructorCall)and, document); + return; + } else if (and instanceof XForLoopExpression) { + _format((XForLoopExpression)and, document); + return; + } else if (and instanceof XIfExpression) { + _format((XIfExpression)and, document); + return; + } else if (and instanceof XInstanceOfExpression) { + _format((XInstanceOfExpression)and, document); + return; + } else if (and instanceof XReturnExpression) { + _format((XReturnExpression)and, document); + return; + } else if (and instanceof XSwitchExpression) { + _format((XSwitchExpression)and, document); + return; + } else if (and instanceof XSynchronizedExpression) { + _format((XSynchronizedExpression)and, document); + return; + } else if (and instanceof XThrowExpression) { + _format((XThrowExpression)and, document); + return; + } else if (and instanceof XTryCatchFinallyExpression) { + _format((XTryCatchFinallyExpression)and, document); + return; + } else if (and instanceof XTypeLiteral) { + _format((XTypeLiteral)and, document); + return; + } else if (and instanceof XVariableDeclaration) { + _format((XVariableDeclaration)and, document); + return; + } else if (and instanceof XAnnotation) { + _format((XAnnotation)and, document); + return; + } else if (and instanceof Assertion) { + _format((Assertion)and, document); + return; + } else if (and instanceof JnarioMember) { + _format((JnarioMember)and, document); + return; + } else if (and instanceof JnarioParameter) { + _format((JnarioParameter)and, document); + return; + } else if (and instanceof ShouldThrow) { + _format((ShouldThrow)and, document); + return; + } else if (and instanceof FeatureFile) { + _format((FeatureFile)and, document); + return; + } else if (and instanceof JvmTypeConstraint) { + _format((JvmTypeConstraint)and, document); + return; + } else if (and instanceof XExpression) { + _format((XExpression)and, document); + return; + } else if (and instanceof XImportDeclaration) { + _format((XImportDeclaration)and, document); + return; + } else if (and instanceof XImportSection) { + _format((XImportSection)and, document); + return; + } else if (and instanceof EObject) { + _format((EObject)and, document); + return; + } else if (and == null) { + _format((Void)null, document); + return; + } else if (and != null) { + _format(and, document); + return; + } else { + throw new IllegalArgumentException("Unhandled parameter types: " + + Arrays.asList(and, document).toString()); + } + } +} diff --git a/plugins/org.jnario.feature/xtend-gen/org/jnario/feature/jvmmodel/FeatureExecutableProvider.java b/plugins/org.jnario.feature/xtend-gen/org/jnario/feature/jvmmodel/FeatureExecutableProvider.java index 5cdfd1dda..e66878569 100644 --- a/plugins/org.jnario.feature/xtend-gen/org/jnario/feature/jvmmodel/FeatureExecutableProvider.java +++ b/plugins/org.jnario.feature/xtend-gen/org/jnario/feature/jvmmodel/FeatureExecutableProvider.java @@ -1,59 +1,56 @@ -package org.jnario.feature.jvmmodel; - -import com.google.common.base.Objects; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import org.eclipse.emf.common.util.EList; -import org.eclipse.xtext.xbase.lib.CollectionLiterals; -import org.jnario.Executable; -import org.jnario.feature.feature.Background; -import org.jnario.feature.feature.Feature; -import org.jnario.feature.feature.Scenario; -import org.jnario.jvmmodel.ExecutableProvider; - -@SuppressWarnings("all") -public class FeatureExecutableProvider implements ExecutableProvider { - @Override - public List getExecutables(final Executable specification) { - return this.doGetExecutables(specification); - } - - protected List _doGetExecutables(final Scenario scenario) { - return scenario.getSteps(); - } - - protected List _doGetExecutables(final Executable e) { - return CollectionLiterals.emptyList(); - } - - protected List _doGetExecutables(final Feature feature) { - ArrayList _xblockexpression = null; - { - Background _background = feature.getBackground(); - boolean _equals = Objects.equal(_background, null); - if (_equals) { - return feature.getScenarios(); - } - Background _background_1 = feature.getBackground(); - final ArrayList result = CollectionLiterals.newArrayList(_background_1); - EList _scenarios = feature.getScenarios(); - result.addAll(_scenarios); - _xblockexpression = result; - } - return _xblockexpression; - } - - public List doGetExecutables(final Executable feature) { - if (feature instanceof Feature) { - return _doGetExecutables((Feature)feature); - } else if (feature instanceof Scenario) { - return _doGetExecutables((Scenario)feature); - } else if (feature != null) { - return _doGetExecutables(feature); - } else { - throw new IllegalArgumentException("Unhandled parameter types: " + - Arrays.asList(feature).toString()); - } - } -} +package org.jnario.feature.jvmmodel; + +import com.google.common.base.Objects; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import org.eclipse.xtext.xbase.lib.CollectionLiterals; +import org.jnario.Executable; +import org.jnario.feature.feature.Background; +import org.jnario.feature.feature.Feature; +import org.jnario.feature.feature.Scenario; +import org.jnario.jvmmodel.ExecutableProvider; + +@SuppressWarnings("all") +public class FeatureExecutableProvider implements ExecutableProvider { + @Override + public List getExecutables(final Executable specification) { + return this.doGetExecutables(specification); + } + + protected List _doGetExecutables(final Scenario scenario) { + return scenario.getSteps(); + } + + protected List _doGetExecutables(final Executable e) { + return CollectionLiterals.emptyList(); + } + + protected List _doGetExecutables(final Feature feature) { + ArrayList _xblockexpression = null; + { + Background _background = feature.getBackground(); + boolean _equals = Objects.equal(_background, null); + if (_equals) { + return feature.getScenarios(); + } + final ArrayList result = CollectionLiterals.newArrayList(feature.getBackground()); + result.addAll(feature.getScenarios()); + _xblockexpression = result; + } + return _xblockexpression; + } + + public List doGetExecutables(final Executable feature) { + if (feature instanceof Feature) { + return _doGetExecutables((Feature)feature); + } else if (feature instanceof Scenario) { + return _doGetExecutables((Scenario)feature); + } else if (feature != null) { + return _doGetExecutables(feature); + } else { + throw new IllegalArgumentException("Unhandled parameter types: " + + Arrays.asList(feature).toString()); + } + } +} diff --git a/plugins/org.jnario.feature/xtend-gen/org/jnario/feature/jvmmodel/FeatureJvmModelInferrer.java b/plugins/org.jnario.feature/xtend-gen/org/jnario/feature/jvmmodel/FeatureJvmModelInferrer.java index b9d2ee234..78d42307e 100644 --- a/plugins/org.jnario.feature/xtend-gen/org/jnario/feature/jvmmodel/FeatureJvmModelInferrer.java +++ b/plugins/org.jnario.feature/xtend-gen/org/jnario/feature/jvmmodel/FeatureJvmModelInferrer.java @@ -1,605 +1,550 @@ -/** - * Copyright (c) 2012 BMW Car IT and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.jnario.feature.jvmmodel; - -import com.google.common.base.Objects; -import com.google.common.base.Strings; -import com.google.common.collect.Iterables; -import com.google.common.collect.Iterators; -import com.google.common.collect.UnmodifiableIterator; -import com.google.inject.Inject; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; -import java.util.Set; -import java.util.function.Consumer; -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.common.util.TreeIterator; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.xtext.EcoreUtil2; -import org.eclipse.xtext.common.types.JvmAnnotationReference; -import org.eclipse.xtext.common.types.JvmAnnotationValue; -import org.eclipse.xtext.common.types.JvmConstructor; -import org.eclipse.xtext.common.types.JvmGenericType; -import org.eclipse.xtext.common.types.JvmIntAnnotationValue; -import org.eclipse.xtext.common.types.JvmMember; -import org.eclipse.xtext.common.types.JvmOperation; -import org.eclipse.xtext.common.types.JvmParameterizedTypeReference; -import org.eclipse.xtext.common.types.JvmType; -import org.eclipse.xtext.common.types.JvmTypeReference; -import org.eclipse.xtext.common.types.JvmVisibility; -import org.eclipse.xtext.common.types.TypesFactory; -import org.eclipse.xtext.common.types.util.TypeReferences; -import org.eclipse.xtext.xbase.XConstructorCall; -import org.eclipse.xtext.xbase.XExpression; -import org.eclipse.xtext.xbase.XStringLiteral; -import org.eclipse.xtext.xbase.XVariableDeclaration; -import org.eclipse.xtext.xbase.XbaseFactory; -import org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation; -import org.eclipse.xtext.xbase.compiler.output.ITreeAppendable; -import org.eclipse.xtext.xbase.jvmmodel.IJvmDeclaredTypeAcceptor; -import org.eclipse.xtext.xbase.jvmmodel.IJvmModelAssociations; -import org.eclipse.xtext.xbase.jvmmodel.IJvmModelAssociator; -import org.eclipse.xtext.xbase.lib.CollectionLiterals; -import org.eclipse.xtext.xbase.lib.Extension; -import org.eclipse.xtext.xbase.lib.Functions.Function1; -import org.eclipse.xtext.xbase.lib.IterableExtensions; -import org.eclipse.xtext.xbase.lib.IteratorExtensions; -import org.eclipse.xtext.xbase.lib.ListExtensions; -import org.eclipse.xtext.xbase.lib.ObjectExtensions; -import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; -import org.jnario.JnarioClass; -import org.jnario.JnarioField; -import org.jnario.JnarioFile; -import org.jnario.JnarioMember; -import org.jnario.JnarioTypeDeclaration; -import org.jnario.feature.feature.Background; -import org.jnario.feature.feature.Feature; -import org.jnario.feature.feature.FeatureFile; -import org.jnario.feature.feature.Scenario; -import org.jnario.feature.feature.Step; -import org.jnario.feature.feature.StepImplementation; -import org.jnario.feature.feature.StepReference; -import org.jnario.feature.jvmmodel.JvmFieldReferenceUpdater; -import org.jnario.feature.jvmmodel.StepArgumentsProvider; -import org.jnario.feature.jvmmodel.StepExpressionProvider; -import org.jnario.feature.jvmmodel.StepReferenceFieldCreator; -import org.jnario.feature.naming.StepNameProvider; -import org.jnario.jvmmodel.ExtendedJvmTypesBuilder; -import org.jnario.jvmmodel.JnarioJvmModelInferrer; -import org.jnario.jvmmodel.TestRuntimeSupport; -import org.jnario.lib.StepArguments; -import org.jnario.runner.Named; -import org.jnario.runner.Order; -import org.jnario.util.SourceAdapter; - -/** - * @author Birgit Engelmann - Initial contribution and API - * @author Sebastian Benz - */ -@SuppressWarnings("all") -public class FeatureJvmModelInferrer extends JnarioJvmModelInferrer { - public final static String STEP_VALUES = "args"; - - @Inject - @Extension - private ExtendedJvmTypesBuilder _extendedJvmTypesBuilder; - - @Inject - @Extension - private TypeReferences _typeReferences; - - @Inject - @Extension - private StepNameProvider _stepNameProvider; - - @Inject - @Extension - private StepExpressionProvider _stepExpressionProvider; - - @Inject - @Extension - private StepReferenceFieldCreator _stepReferenceFieldCreator; - - @Inject - @Extension - private StepArgumentsProvider stepArgumentsProvider; - - @Inject - @Extension - private IJvmModelAssociator _iJvmModelAssociator; - - @Inject - @Extension - private IJvmModelAssociations _iJvmModelAssociations; - - @Inject - @Extension - private JvmFieldReferenceUpdater _jvmFieldReferenceUpdater; - - @Inject - @Extension - private TypesFactory typesFactory; - - @Override - public void doInfer(final EObject object, final IJvmDeclaredTypeAcceptor acceptor, final boolean preIndexingPhase) { - if ((!(object instanceof JnarioFile))) { - return; - } - final ArrayList doLater = CollectionLiterals.newArrayList(); - final Feature feature = this.resolveFeature(object); - if ((Objects.equal(feature, null) || Strings.isNullOrEmpty(feature.getName()))) { - return; - } - Background _background = feature.getBackground(); - final JvmGenericType background = this.toClass(_background, acceptor, doLater, preIndexingPhase); - EList _scenarios = feature.getScenarios(); - final ArrayList scenarios = this.toClass(_scenarios, acceptor, background, doLater, preIndexingPhase); - this.toClass(feature, acceptor, scenarios, background, doLater, preIndexingPhase); - if ((!preIndexingPhase)) { - for (final Runnable runnable : doLater) { - runnable.run(); - } - } - } - - public Feature resolveFeature(final EObject root) { - final FeatureFile featureFile = ((FeatureFile) root); - EList _xtendTypes = featureFile.getXtendTypes(); - boolean _isEmpty = _xtendTypes.isEmpty(); - if (_isEmpty) { - return null; - } - EList _xtendTypes_1 = featureFile.getXtendTypes(); - final JnarioTypeDeclaration xtendClass = _xtendTypes_1.get(0); - return ((Feature) xtendClass); - } - - public JvmGenericType toClass(final Background background, final IJvmDeclaredTypeAcceptor acceptor, final List doLater, final boolean preIndexingPhase) { - JvmGenericType _xblockexpression = null; - { - boolean _equals = Objects.equal(background, null); - if (_equals) { - return null; - } - List _emptyList = CollectionLiterals.emptyList(); - _xblockexpression = this.toClass(background, _emptyList, acceptor, doLater, preIndexingPhase); - } - return _xblockexpression; - } - - public ArrayList toClass(final List scenarios, final IJvmDeclaredTypeAcceptor acceptor, final JvmGenericType backgroundType, final List doLater, final boolean preIndexingPhase) { - final ArrayList result = CollectionLiterals.newArrayList(); - final Consumer _function = new Consumer() { - @Override - public void accept(final Scenario it) { - List _emptyList = CollectionLiterals.emptyList(); - final JvmGenericType inferredJvmType = FeatureJvmModelInferrer.this.toClass(it, _emptyList, acceptor, doLater, preIndexingPhase); - result.add(inferredJvmType); - } - }; - scenarios.forEach(_function); - return result; - } - - public void toClass(final Feature feature, final IJvmDeclaredTypeAcceptor acceptor, final List scenarios, final JvmGenericType background, final List doLater, final boolean preIndexingPhase) { - this.addSuperClass(feature); - final JvmGenericType inferredJvmType = this.toClass(feature, scenarios, acceptor, doLater, preIndexingPhase); - boolean _equals = Objects.equal(background, null); - if (_equals) { - final Consumer _function = new Consumer() { - @Override - public void accept(final JvmGenericType it) { - EList _superTypes = it.getSuperTypes(); - JvmParameterizedTypeReference _createTypeRef = FeatureJvmModelInferrer.this._typeReferences.createTypeRef(inferredJvmType); - FeatureJvmModelInferrer.this._extendedJvmTypesBuilder.operator_add(_superTypes, _createTypeRef); - } - }; - scenarios.forEach(_function); - } else { - EList _superTypes = background.getSuperTypes(); - JvmParameterizedTypeReference _createTypeRef = this._typeReferences.createTypeRef(inferredJvmType); - this._extendedJvmTypesBuilder.operator_add(_superTypes, _createTypeRef); - final Consumer _function_1 = new Consumer() { - @Override - public void accept(final JvmGenericType it) { - EList _superTypes = it.getSuperTypes(); - JvmParameterizedTypeReference _createTypeRef = FeatureJvmModelInferrer.this._typeReferences.createTypeRef(background); - FeatureJvmModelInferrer.this._extendedJvmTypesBuilder.operator_add(_superTypes, _createTypeRef); - } - }; - scenarios.forEach(_function_1); - } - } - - public boolean register(final IJvmDeclaredTypeAcceptor acceptor, final JnarioClass source, final JvmGenericType inferredJvmType, final List scenarios, final List doLater, final boolean preIndexingPhase) { - boolean _xifexpression = false; - if ((!preIndexingPhase)) { - final Runnable _function = new Runnable() { - @Override - public void run() { - FeatureJvmModelInferrer.this.init(source, inferredJvmType, scenarios); - } - }; - _xifexpression = doLater.add(_function); - } - return _xifexpression; - } - - public JvmGenericType toClass(final JnarioClass xtendClass, final List scenarios, final IJvmDeclaredTypeAcceptor acceptor, final List doLater, final boolean preIndexingPhase) { - JvmGenericType _xblockexpression = null; - { - final JvmGenericType javaType = this.typesFactory.createJvmGenericType(); - Resource _eResource = xtendClass.eResource(); - EList _contents = _eResource.getContents(); - this._extendedJvmTypesBuilder.operator_add(_contents, javaType); - JnarioFile _jnarioFile = this.jnarioFile(xtendClass); - this.setNameAndAssociate(_jnarioFile, xtendClass, javaType); - acceptor.accept(javaType); - if ((!preIndexingPhase)) { - final Runnable _function = new Runnable() { - @Override - public void run() { - FeatureJvmModelInferrer.this.init(xtendClass, javaType, scenarios); - } - }; - doLater.add(_function); - } - _xblockexpression = javaType; - } - return _xblockexpression; - } - - protected void _init(final Feature feature, final JvmGenericType inferredJvmType, final List scenarios) { - final EList annotations = inferredJvmType.getAnnotations(); - boolean _isEmpty = scenarios.isEmpty(); - boolean _not = (!_isEmpty); - if (_not) { - TestRuntimeSupport _testRuntime = this.getTestRuntime(); - final Function1 _function = new Function1() { - @Override - public JvmTypeReference apply(final JvmGenericType it) { - return FeatureJvmModelInferrer.this._typeReferences.createTypeRef(it); - } - }; - List _map = ListExtensions.map(scenarios, _function); - _testRuntime.addChildren(feature, inferredJvmType, _map); - } - String _describe = this._stepNameProvider.describe(feature); - JvmAnnotationReference _annotationRef = this._annotationTypesBuilder.annotationRef(Named.class, _describe); - this._extendedJvmTypesBuilder.operator_add(annotations, _annotationRef); - final Procedure1 _function_1 = new Procedure1() { - @Override - public void apply(final JvmGenericType it) { - it.setVisibility(JvmVisibility.PUBLIC); - boolean _isStatic = feature.isStatic(); - it.setStatic(_isStatic); - } - }; - ObjectExtensions.operator_doubleArrow(inferredJvmType, _function_1); - EList _annotations = feature.getAnnotations(); - this.translateAnnotations(inferredJvmType, _annotations); - this._extendedJvmTypesBuilder.copyDocumentationTo(feature, inferredJvmType); - TestRuntimeSupport _testRuntime_1 = this.getTestRuntime(); - final Function1 _function_2 = new Function1() { - @Override - public JvmTypeReference apply(final JvmGenericType it) { - return FeatureJvmModelInferrer.this._typeReferences.createTypeRef(it); - } - }; - List _map_1 = ListExtensions.map(scenarios, _function_2); - _testRuntime_1.updateFeature(feature, inferredJvmType, _map_1); - } - - protected void _init(final Scenario scenario, final JvmGenericType inferredJvmType, final List scenarios) { - this._stepReferenceFieldCreator.copyJnarioMemberForReferences(scenario); - EList _members = scenario.getMembers(); - Iterable _filter = Iterables.filter(_members, JnarioField.class); - final Consumer _function = new Consumer() { - @Override - public void accept(final JnarioField it) { - FeatureJvmModelInferrer.this.transform(it, inferredJvmType); - } - }; - _filter.forEach(_function); - final EList annotations = inferredJvmType.getAnnotations(); - TestRuntimeSupport _testRuntime = this.getTestRuntime(); - _testRuntime.updateScenario(scenario, inferredJvmType); - String _describe = this._stepNameProvider.describe(scenario); - JvmAnnotationReference _annotationRef = this._annotationTypesBuilder.annotationRef(Named.class, _describe); - this._extendedJvmTypesBuilder.operator_add(annotations, _annotationRef); - final Feature feature = this.feature(scenario); - int start = 0; - EList _annotations = feature.getAnnotations(); - this.translateAnnotations(inferredJvmType, _annotations); - final Background background = feature.getBackground(); - if (((!(scenario instanceof Background)) && (!Objects.equal(background, null)))) { - EList _steps = background.getSteps(); - int _generateBackgroundStepCalls = this.generateBackgroundStepCalls(_steps, inferredJvmType, scenario); - start = _generateBackgroundStepCalls; - } - EList _steps_1 = scenario.getSteps(); - this.generateSteps(_steps_1, inferredJvmType, start, scenario); - EList _steps_2 = scenario.getSteps(); - Iterable _filter_1 = Iterables.filter(_steps_2, StepReference.class); - final Consumer _function_1 = new Consumer() { - @Override - public void accept(final StepReference it) { - StepImplementation _reference = it.getReference(); - boolean _equals = Objects.equal(_reference, null); - if (_equals) { - return; - } - StepImplementation _reference_1 = it.getReference(); - final Scenario original = EcoreUtil2.getContainerOfType(_reference_1, Scenario.class); - boolean _equals_1 = Objects.equal(original, null); - if (_equals_1) { - return; - } - final XExpression expr = FeatureJvmModelInferrer.this._stepExpressionProvider.expressionOf(it); - FeatureJvmModelInferrer.this.updateReferences(original, expr, inferredJvmType); - } - }; - _filter_1.forEach(_function_1); - EList _members_1 = scenario.getMembers(); - Iterable _filter_2 = Iterables.filter(_members_1, JnarioField.class); - final Function1 _function_2 = new Function1() { - @Override - public Boolean apply(final JnarioField it) { - XExpression _initialValue = it.getInitialValue(); - return Boolean.valueOf((!Objects.equal(_initialValue, null))); - } - }; - Iterable _filter_3 = IterableExtensions.filter(_filter_2, _function_2); - final Consumer _function_3 = new Consumer() { - @Override - public void accept(final JnarioField it) { - final EObject source = SourceAdapter.find(it); - boolean _equals = Objects.equal(source, null); - if (_equals) { - return; - } - final Scenario original = EcoreUtil2.getContainerOfType(source, Scenario.class); - XExpression _initialValue = it.getInitialValue(); - FeatureJvmModelInferrer.this.updateReferences(original, _initialValue, inferredJvmType); - } - }; - _filter_3.forEach(_function_3); - } - - public void updateReferences(final Scenario original, final XExpression expr, final JvmGenericType inferredJvmType) { - Set _jvmElements = this._iJvmModelAssociations.getJvmElements(original); - Iterable _filter = Iterables.filter(_jvmElements, JvmGenericType.class); - final Function1 _function = new Function1() { - @Override - public Boolean apply(final JvmGenericType it) { - EObject _primarySourceElement = FeatureJvmModelInferrer.this._iJvmModelAssociations.getPrimarySourceElement(it); - return Boolean.valueOf(Objects.equal(_primarySourceElement, original)); - } - }; - final JvmGenericType originalType = IterableExtensions.findFirst(_filter, _function); - this._jvmFieldReferenceUpdater.updateReferences(expr, originalType, inferredJvmType); - } - - public void generateStepValues(final Step step) { - final List arguments = this.stepArgumentsProvider.findStepArguments(step); - final XExpression stepExpression = step.getExpression(); - if ((arguments.isEmpty() || Objects.equal(stepExpression, null))) { - return; - } - TreeIterator _eAllContents = stepExpression.eAllContents(); - Iterator _filter = Iterators.filter(_eAllContents, XVariableDeclaration.class); - final Function1 _function = new Function1() { - @Override - public Boolean apply(final XVariableDeclaration it) { - String _name = it.getName(); - return Boolean.valueOf(Objects.equal(_name, FeatureJvmModelInferrer.STEP_VALUES)); - } - }; - Iterator decs = IteratorExtensions.filter(_filter, _function); - boolean _isEmpty = IteratorExtensions.isEmpty(decs); - if (_isEmpty) { - return; - } - final XVariableDeclaration dec = IteratorExtensions.head(decs); - this.setStepValueType(dec, ((Step) step)); - if ((step instanceof StepImplementation)) { - return; - } - TreeIterator _eAllContents_1 = stepExpression.eAllContents(); - Iterator calls = Iterators.filter(_eAllContents_1, XConstructorCall.class); - final XConstructorCall argsConstructor = IteratorExtensions.head(calls); - EList _arguments = argsConstructor.getArguments(); - _arguments.clear(); - final Consumer _function_1 = new Consumer() { - @Override - public void accept(final String it) { - final XStringLiteral arg = XbaseFactory.eINSTANCE.createXStringLiteral(); - arg.setValue(it); - EList _arguments = argsConstructor.getArguments(); - FeatureJvmModelInferrer.this._extendedJvmTypesBuilder.operator_add(_arguments, arg); - } - }; - arguments.forEach(_function_1); - } - - public void setStepValueType(final XVariableDeclaration variableDec, final Step step) { - JvmTypeReference typeRef = this._typeReferences.getTypeForName(StepArguments.class, step); - if ((Objects.equal(typeRef, null) || typeRef.eIsProxy())) { - return; - } - variableDec.setType(typeRef); - JvmType _type = typeRef.getType(); - final JvmGenericType type = ((JvmGenericType) _type); - if ((Objects.equal(type, null) || type.eIsProxy())) { - return; - } - XExpression _right = variableDec.getRight(); - XConstructorCall constructor = ((XConstructorCall) _right); - EList _members = type.getMembers(); - Iterator _iterator = _members.iterator(); - final UnmodifiableIterator constructors = Iterators.filter(_iterator, JvmConstructor.class); - JvmConstructor _next = constructors.next(); - constructor.setConstructor(_next); - } - - public int generateBackgroundStepCalls(final Iterable steps, final JvmGenericType inferredJvmType, final Scenario scenario) { - int _xblockexpression = (int) 0; - { - int order = 0; - for (final Step step : steps) { - int _transformCalls = this.transformCalls(step, inferredJvmType, order, scenario); - order = _transformCalls; - } - _xblockexpression = order; - } - return _xblockexpression; - } - - public int transformCalls(final Step step, final JvmGenericType inferredJvmType, final int order, final Scenario scenario) { - int _xblockexpression = (int) 0; - { - final String methodName = this._stepNameProvider.getMethodName(step); - EList _members = inferredJvmType.getMembers(); - JvmTypeReference _typeForName = this._typeReferences.getTypeForName(Void.TYPE, step); - final Procedure1 _function = new Procedure1() { - @Override - public void apply(final JvmOperation it) { - final Procedure1 _function = new Procedure1() { - @Override - public void apply(final ITreeAppendable a) { - a.append((("super." + methodName) + "();")); - } - }; - FeatureJvmModelInferrer.this._extendedJvmTypesBuilder.setBody(it, _function); - FeatureJvmModelInferrer.this.markAsPending(it, step, scenario); - FeatureJvmModelInferrer.this._iJvmModelAssociator.associatePrimary(step, it); - TestRuntimeSupport _testRuntime = FeatureJvmModelInferrer.this.getTestRuntime(); - _testRuntime.markAsTestMethod(step, it); - EList _annotations = it.getAnnotations(); - JvmAnnotationReference _annotationRef = FeatureJvmModelInferrer.this._annotationTypesBuilder.annotationRef(Order.class); - final Procedure1 _function_1 = new Procedure1() { - @Override - public void apply(final JvmAnnotationReference it) { - EList _explicitValues = it.getExplicitValues(); - JvmIntAnnotationValue _createJvmIntAnnotationValue = FeatureJvmModelInferrer.this.typesFactory.createJvmIntAnnotationValue(); - final Procedure1 _function = new Procedure1() { - @Override - public void apply(final JvmIntAnnotationValue it) { - EList _values = it.getValues(); - int _intValue = Integer.valueOf(order).intValue(); - FeatureJvmModelInferrer.this._extendedJvmTypesBuilder.operator_add(_values, Integer.valueOf(_intValue)); - } - }; - JvmIntAnnotationValue _doubleArrow = ObjectExtensions.operator_doubleArrow(_createJvmIntAnnotationValue, _function); - FeatureJvmModelInferrer.this._extendedJvmTypesBuilder.operator_add(_explicitValues, _doubleArrow); - } - }; - JvmAnnotationReference _doubleArrow = ObjectExtensions.operator_doubleArrow(_annotationRef, _function_1); - FeatureJvmModelInferrer.this._extendedJvmTypesBuilder.operator_add(_annotations, _doubleArrow); - EList _annotations_1 = it.getAnnotations(); - String _describe = FeatureJvmModelInferrer.this._stepNameProvider.describe(step); - JvmAnnotationReference _annotationRef_1 = FeatureJvmModelInferrer.this._annotationTypesBuilder.annotationRef(Named.class, _describe); - FeatureJvmModelInferrer.this._extendedJvmTypesBuilder.operator_add(_annotations_1, _annotationRef_1); - } - }; - JvmOperation _method = this._extendedJvmTypesBuilder.toMethod(step, methodName, _typeForName, _function); - this._extendedJvmTypesBuilder.operator_add(_members, _method); - _xblockexpression = (order + 1); - } - return _xblockexpression; - } - - public void generateSteps(final Iterable steps, final JvmGenericType inferredJvmType, final int start, final Scenario scenario) { - int order = start; - for (final Step step : steps) { - int _transform = this.transform(step, inferredJvmType, order, scenario); - order = _transform; - } - } - - public int transform(final Step step, final JvmGenericType inferredJvmType, final int order, final Scenario scenario) { - int _xblockexpression = (int) 0; - { - EList _members = inferredJvmType.getMembers(); - String _methodName = this._stepNameProvider.getMethodName(step); - JvmTypeReference _typeForName = this._typeReferences.getTypeForName(Void.TYPE, step); - final Procedure1 _function = new Procedure1() { - @Override - public void apply(final JvmOperation it) { - it.setDeclaringType(inferredJvmType); - final XExpression stepExpression = FeatureJvmModelInferrer.this._stepExpressionProvider.expressionOf(step); - FeatureJvmModelInferrer.this._iJvmModelAssociator.associatePrimary(step, it); - FeatureJvmModelInferrer.this.generateStepValues(step); - FeatureJvmModelInferrer.this._extendedJvmTypesBuilder.setBody(it, stepExpression); - TestRuntimeSupport _testRuntime = FeatureJvmModelInferrer.this.getTestRuntime(); - _testRuntime.markAsTestMethod(step, it); - EList _annotations = it.getAnnotations(); - JvmAnnotationReference _annotationRef = FeatureJvmModelInferrer.this._annotationTypesBuilder.annotationRef(Order.class); - final Procedure1 _function = new Procedure1() { - @Override - public void apply(final JvmAnnotationReference it) { - EList _explicitValues = it.getExplicitValues(); - JvmIntAnnotationValue _createJvmIntAnnotationValue = FeatureJvmModelInferrer.this.typesFactory.createJvmIntAnnotationValue(); - final Procedure1 _function = new Procedure1() { - @Override - public void apply(final JvmIntAnnotationValue it) { - EList _values = it.getValues(); - int _intValue = Integer.valueOf(order).intValue(); - FeatureJvmModelInferrer.this._extendedJvmTypesBuilder.operator_add(_values, Integer.valueOf(_intValue)); - } - }; - JvmIntAnnotationValue _doubleArrow = ObjectExtensions.operator_doubleArrow(_createJvmIntAnnotationValue, _function); - FeatureJvmModelInferrer.this._extendedJvmTypesBuilder.operator_add(_explicitValues, _doubleArrow); - } - }; - JvmAnnotationReference _doubleArrow = ObjectExtensions.operator_doubleArrow(_annotationRef, _function); - FeatureJvmModelInferrer.this._extendedJvmTypesBuilder.operator_add(_annotations, _doubleArrow); - String name = FeatureJvmModelInferrer.this._stepNameProvider.describe(step); - FeatureJvmModelInferrer.this._iJvmModelAssociator.associatePrimary(step, it); - FeatureJvmModelInferrer.this.markAsPending(it, step, scenario); - EList _annotations_1 = it.getAnnotations(); - JvmAnnotationReference _annotationRef_1 = FeatureJvmModelInferrer.this._annotationTypesBuilder.annotationRef(Named.class, name); - FeatureJvmModelInferrer.this._extendedJvmTypesBuilder.operator_add(_annotations_1, _annotationRef_1); - } - }; - JvmOperation _method = this._extendedJvmTypesBuilder.toMethod(step, _methodName, _typeForName, _function); - this._extendedJvmTypesBuilder.operator_add(_members, _method); - _xblockexpression = (order + 1); - } - return _xblockexpression; - } - - public Feature feature(final EObject context) { - return EcoreUtil2.getContainerOfType(context, Feature.class); - } - - public void markAsPending(final JvmOperation operation, final Step step, final Scenario scenario) { - EList _pendingSteps = scenario.getPendingSteps(); - boolean _contains = _pendingSteps.contains(step); - if (_contains) { - TestRuntimeSupport _testRuntime = this.getTestRuntime(); - _testRuntime.markAsPending(step, operation); - } - } - - public void init(final EObject feature, final JvmGenericType inferredJvmType, final List scenarios) { - if (feature instanceof Feature) { - _init((Feature)feature, inferredJvmType, scenarios); - return; - } else if (feature instanceof Scenario) { - _init((Scenario)feature, inferredJvmType, scenarios); - return; - } else { - throw new IllegalArgumentException("Unhandled parameter types: " + - Arrays.asList(feature, inferredJvmType, scenarios).toString()); - } - } -} +/** + * Copyright (c) 2012 BMW Car IT and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.jnario.feature.jvmmodel; + +import com.google.common.base.Objects; +import com.google.common.base.Strings; +import com.google.common.collect.Iterables; +import com.google.common.collect.Iterators; +import com.google.common.collect.UnmodifiableIterator; +import com.google.inject.Inject; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; +import java.util.function.Consumer; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.xtext.EcoreUtil2; +import org.eclipse.xtext.common.types.JvmAnnotationReference; +import org.eclipse.xtext.common.types.JvmAnnotationValue; +import org.eclipse.xtext.common.types.JvmConstructor; +import org.eclipse.xtext.common.types.JvmGenericType; +import org.eclipse.xtext.common.types.JvmIntAnnotationValue; +import org.eclipse.xtext.common.types.JvmMember; +import org.eclipse.xtext.common.types.JvmOperation; +import org.eclipse.xtext.common.types.JvmParameterizedTypeReference; +import org.eclipse.xtext.common.types.JvmType; +import org.eclipse.xtext.common.types.JvmTypeReference; +import org.eclipse.xtext.common.types.JvmVisibility; +import org.eclipse.xtext.common.types.TypesFactory; +import org.eclipse.xtext.common.types.util.TypeReferences; +import org.eclipse.xtext.xbase.XConstructorCall; +import org.eclipse.xtext.xbase.XExpression; +import org.eclipse.xtext.xbase.XStringLiteral; +import org.eclipse.xtext.xbase.XVariableDeclaration; +import org.eclipse.xtext.xbase.XbaseFactory; +import org.eclipse.xtext.xbase.compiler.output.ITreeAppendable; +import org.eclipse.xtext.xbase.jvmmodel.IJvmDeclaredTypeAcceptor; +import org.eclipse.xtext.xbase.jvmmodel.IJvmModelAssociations; +import org.eclipse.xtext.xbase.jvmmodel.IJvmModelAssociator; +import org.eclipse.xtext.xbase.lib.CollectionLiterals; +import org.eclipse.xtext.xbase.lib.Extension; +import org.eclipse.xtext.xbase.lib.Functions.Function1; +import org.eclipse.xtext.xbase.lib.IterableExtensions; +import org.eclipse.xtext.xbase.lib.IteratorExtensions; +import org.eclipse.xtext.xbase.lib.ListExtensions; +import org.eclipse.xtext.xbase.lib.ObjectExtensions; +import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; +import org.jnario.JnarioClass; +import org.jnario.JnarioField; +import org.jnario.JnarioFile; +import org.jnario.JnarioTypeDeclaration; +import org.jnario.feature.feature.Background; +import org.jnario.feature.feature.Feature; +import org.jnario.feature.feature.FeatureFile; +import org.jnario.feature.feature.Scenario; +import org.jnario.feature.feature.Step; +import org.jnario.feature.feature.StepImplementation; +import org.jnario.feature.feature.StepReference; +import org.jnario.feature.jvmmodel.JvmFieldReferenceUpdater; +import org.jnario.feature.jvmmodel.StepArgumentsProvider; +import org.jnario.feature.jvmmodel.StepExpressionProvider; +import org.jnario.feature.jvmmodel.StepReferenceFieldCreator; +import org.jnario.feature.naming.StepNameProvider; +import org.jnario.jvmmodel.ExtendedJvmTypesBuilder; +import org.jnario.jvmmodel.JnarioJvmModelInferrer; +import org.jnario.lib.StepArguments; +import org.jnario.runner.Named; +import org.jnario.runner.Order; +import org.jnario.util.SourceAdapter; + +/** + * @author Birgit Engelmann - Initial contribution and API + * @author Sebastian Benz + */ +@SuppressWarnings("all") +public class FeatureJvmModelInferrer extends JnarioJvmModelInferrer { + public final static String STEP_VALUES = "args"; + + @Inject + @Extension + private ExtendedJvmTypesBuilder _extendedJvmTypesBuilder; + + @Inject + @Extension + private TypeReferences _typeReferences; + + @Inject + @Extension + private StepNameProvider _stepNameProvider; + + @Inject + @Extension + private StepExpressionProvider _stepExpressionProvider; + + @Inject + @Extension + private StepReferenceFieldCreator _stepReferenceFieldCreator; + + @Inject + @Extension + private StepArgumentsProvider stepArgumentsProvider; + + @Inject + @Extension + private IJvmModelAssociator _iJvmModelAssociator; + + @Inject + @Extension + private IJvmModelAssociations _iJvmModelAssociations; + + @Inject + @Extension + private JvmFieldReferenceUpdater _jvmFieldReferenceUpdater; + + @Inject + @Extension + private TypesFactory typesFactory; + + @Override + public void doInfer(final EObject object, final IJvmDeclaredTypeAcceptor acceptor, final boolean preIndexingPhase) { + if ((!(object instanceof JnarioFile))) { + return; + } + final ArrayList doLater = CollectionLiterals.newArrayList(); + final Feature feature = this.resolveFeature(object); + if ((Objects.equal(feature, null) || Strings.isNullOrEmpty(feature.getName()))) { + return; + } + final JvmGenericType background = this.toClass(feature.getBackground(), acceptor, doLater, preIndexingPhase); + final ArrayList scenarios = this.toClass(feature.getScenarios(), acceptor, background, doLater, preIndexingPhase); + this.toClass(feature, acceptor, scenarios, background, doLater, preIndexingPhase); + if ((!preIndexingPhase)) { + for (final Runnable runnable : doLater) { + runnable.run(); + } + } + } + + public Feature resolveFeature(final EObject root) { + final FeatureFile featureFile = ((FeatureFile) root); + boolean _isEmpty = featureFile.getXtendTypes().isEmpty(); + if (_isEmpty) { + return null; + } + final JnarioTypeDeclaration xtendClass = featureFile.getXtendTypes().get(0); + return ((Feature) xtendClass); + } + + public JvmGenericType toClass(final Background background, final IJvmDeclaredTypeAcceptor acceptor, final List doLater, final boolean preIndexingPhase) { + JvmGenericType _xblockexpression = null; + { + boolean _equals = Objects.equal(background, null); + if (_equals) { + return null; + } + _xblockexpression = this.toClass(background, CollectionLiterals.emptyList(), acceptor, doLater, preIndexingPhase); + } + return _xblockexpression; + } + + public ArrayList toClass(final List scenarios, final IJvmDeclaredTypeAcceptor acceptor, final JvmGenericType backgroundType, final List doLater, final boolean preIndexingPhase) { + final ArrayList result = CollectionLiterals.newArrayList(); + final Consumer _function = new Consumer() { + @Override + public void accept(final Scenario it) { + final JvmGenericType inferredJvmType = FeatureJvmModelInferrer.this.toClass(it, CollectionLiterals.emptyList(), acceptor, doLater, preIndexingPhase); + result.add(inferredJvmType); + } + }; + scenarios.forEach(_function); + return result; + } + + public void toClass(final Feature feature, final IJvmDeclaredTypeAcceptor acceptor, final List scenarios, final JvmGenericType background, final List doLater, final boolean preIndexingPhase) { + this.addSuperClass(feature); + final JvmGenericType inferredJvmType = this.toClass(feature, scenarios, acceptor, doLater, preIndexingPhase); + boolean _equals = Objects.equal(background, null); + if (_equals) { + final Consumer _function = new Consumer() { + @Override + public void accept(final JvmGenericType it) { + EList _superTypes = it.getSuperTypes(); + JvmParameterizedTypeReference _createTypeRef = FeatureJvmModelInferrer.this._typeReferences.createTypeRef(inferredJvmType); + FeatureJvmModelInferrer.this._extendedJvmTypesBuilder.operator_add(_superTypes, _createTypeRef); + } + }; + scenarios.forEach(_function); + } else { + EList _superTypes = background.getSuperTypes(); + JvmParameterizedTypeReference _createTypeRef = this._typeReferences.createTypeRef(inferredJvmType); + this._extendedJvmTypesBuilder.operator_add(_superTypes, _createTypeRef); + final Consumer _function_1 = new Consumer() { + @Override + public void accept(final JvmGenericType it) { + EList _superTypes = it.getSuperTypes(); + JvmParameterizedTypeReference _createTypeRef = FeatureJvmModelInferrer.this._typeReferences.createTypeRef(background); + FeatureJvmModelInferrer.this._extendedJvmTypesBuilder.operator_add(_superTypes, _createTypeRef); + } + }; + scenarios.forEach(_function_1); + } + } + + public boolean register(final IJvmDeclaredTypeAcceptor acceptor, final JnarioClass source, final JvmGenericType inferredJvmType, final List scenarios, final List doLater, final boolean preIndexingPhase) { + boolean _xifexpression = false; + if ((!preIndexingPhase)) { + final Runnable _function = new Runnable() { + @Override + public void run() { + FeatureJvmModelInferrer.this.init(source, inferredJvmType, scenarios); + } + }; + _xifexpression = doLater.add(_function); + } + return _xifexpression; + } + + public JvmGenericType toClass(final JnarioClass xtendClass, final List scenarios, final IJvmDeclaredTypeAcceptor acceptor, final List doLater, final boolean preIndexingPhase) { + JvmGenericType _xblockexpression = null; + { + final JvmGenericType javaType = this.typesFactory.createJvmGenericType(); + EList _contents = xtendClass.eResource().getContents(); + this._extendedJvmTypesBuilder.operator_add(_contents, javaType); + this.setNameAndAssociate(this.jnarioFile(xtendClass), xtendClass, javaType); + acceptor.accept(javaType); + if ((!preIndexingPhase)) { + final Runnable _function = new Runnable() { + @Override + public void run() { + FeatureJvmModelInferrer.this.init(xtendClass, javaType, scenarios); + } + }; + doLater.add(_function); + } + _xblockexpression = javaType; + } + return _xblockexpression; + } + + protected void _init(final Feature feature, final JvmGenericType inferredJvmType, final List scenarios) { + final EList annotations = inferredJvmType.getAnnotations(); + boolean _isEmpty = scenarios.isEmpty(); + boolean _not = (!_isEmpty); + if (_not) { + final Function1 _function = new Function1() { + @Override + public JvmTypeReference apply(final JvmGenericType it) { + return FeatureJvmModelInferrer.this._typeReferences.createTypeRef(it); + } + }; + this.getTestRuntime().addChildren(feature, inferredJvmType, ListExtensions.map(scenarios, _function)); + } + JvmAnnotationReference _annotationRef = this._annotationTypesBuilder.annotationRef(Named.class, this._stepNameProvider.describe(feature)); + this._extendedJvmTypesBuilder.operator_add(annotations, _annotationRef); + final Procedure1 _function_1 = new Procedure1() { + @Override + public void apply(final JvmGenericType it) { + it.setVisibility(JvmVisibility.PUBLIC); + it.setStatic(feature.isStatic()); + } + }; + ObjectExtensions.operator_doubleArrow(inferredJvmType, _function_1); + this.translateAnnotations(inferredJvmType, feature.getAnnotations()); + this._extendedJvmTypesBuilder.copyDocumentationTo(feature, inferredJvmType); + final Function1 _function_2 = new Function1() { + @Override + public JvmTypeReference apply(final JvmGenericType it) { + return FeatureJvmModelInferrer.this._typeReferences.createTypeRef(it); + } + }; + this.getTestRuntime().updateFeature(feature, inferredJvmType, ListExtensions.map(scenarios, _function_2)); + } + + protected void _init(final Scenario scenario, final JvmGenericType inferredJvmType, final List scenarios) { + this._stepReferenceFieldCreator.copyJnarioMemberForReferences(scenario); + final Consumer _function = new Consumer() { + @Override + public void accept(final JnarioField it) { + FeatureJvmModelInferrer.this.transform(it, inferredJvmType); + } + }; + Iterables.filter(scenario.getMembers(), JnarioField.class).forEach(_function); + final EList annotations = inferredJvmType.getAnnotations(); + this.getTestRuntime().updateScenario(scenario, inferredJvmType); + JvmAnnotationReference _annotationRef = this._annotationTypesBuilder.annotationRef(Named.class, this._stepNameProvider.describe(scenario)); + this._extendedJvmTypesBuilder.operator_add(annotations, _annotationRef); + final Feature feature = this.feature(scenario); + int start = 0; + this.translateAnnotations(inferredJvmType, feature.getAnnotations()); + final Background background = feature.getBackground(); + if (((!(scenario instanceof Background)) && (!Objects.equal(background, null)))) { + start = this.generateBackgroundStepCalls(background.getSteps(), inferredJvmType, scenario); + } + this.generateSteps(scenario.getSteps(), inferredJvmType, start, scenario); + final Consumer _function_1 = new Consumer() { + @Override + public void accept(final StepReference it) { + StepImplementation _reference = it.getReference(); + boolean _equals = Objects.equal(_reference, null); + if (_equals) { + return; + } + final Scenario original = EcoreUtil2.getContainerOfType(it.getReference(), Scenario.class); + boolean _equals_1 = Objects.equal(original, null); + if (_equals_1) { + return; + } + final XExpression expr = FeatureJvmModelInferrer.this._stepExpressionProvider.expressionOf(it); + FeatureJvmModelInferrer.this.updateReferences(original, expr, inferredJvmType); + } + }; + Iterables.filter(scenario.getSteps(), StepReference.class).forEach(_function_1); + final Function1 _function_2 = new Function1() { + @Override + public Boolean apply(final JnarioField it) { + XExpression _initialValue = it.getInitialValue(); + return Boolean.valueOf((!Objects.equal(_initialValue, null))); + } + }; + final Consumer _function_3 = new Consumer() { + @Override + public void accept(final JnarioField it) { + final EObject source = SourceAdapter.find(it); + boolean _equals = Objects.equal(source, null); + if (_equals) { + return; + } + final Scenario original = EcoreUtil2.getContainerOfType(source, Scenario.class); + FeatureJvmModelInferrer.this.updateReferences(original, it.getInitialValue(), inferredJvmType); + } + }; + IterableExtensions.filter(Iterables.filter(scenario.getMembers(), JnarioField.class), _function_2).forEach(_function_3); + } + + public void updateReferences(final Scenario original, final XExpression expr, final JvmGenericType inferredJvmType) { + final Function1 _function = new Function1() { + @Override + public Boolean apply(final JvmGenericType it) { + EObject _primarySourceElement = FeatureJvmModelInferrer.this._iJvmModelAssociations.getPrimarySourceElement(it); + return Boolean.valueOf(Objects.equal(_primarySourceElement, original)); + } + }; + final JvmGenericType originalType = IterableExtensions.findFirst(Iterables.filter(this._iJvmModelAssociations.getJvmElements(original), JvmGenericType.class), _function); + this._jvmFieldReferenceUpdater.updateReferences(expr, originalType, inferredJvmType); + } + + public void generateStepValues(final Step step) { + final List arguments = this.stepArgumentsProvider.findStepArguments(step); + final XExpression stepExpression = step.getExpression(); + if ((arguments.isEmpty() || Objects.equal(stepExpression, null))) { + return; + } + final Function1 _function = new Function1() { + @Override + public Boolean apply(final XVariableDeclaration it) { + String _name = it.getName(); + return Boolean.valueOf(Objects.equal(_name, FeatureJvmModelInferrer.STEP_VALUES)); + } + }; + Iterator decs = IteratorExtensions.filter(Iterators.filter(stepExpression.eAllContents(), XVariableDeclaration.class), _function); + boolean _isEmpty = IteratorExtensions.isEmpty(decs); + if (_isEmpty) { + return; + } + final XVariableDeclaration dec = IteratorExtensions.head(decs); + this.setStepValueType(dec, ((Step) step)); + if ((step instanceof StepImplementation)) { + return; + } + Iterator calls = Iterators.filter(stepExpression.eAllContents(), XConstructorCall.class); + final XConstructorCall argsConstructor = IteratorExtensions.head(calls); + argsConstructor.getArguments().clear(); + final Consumer _function_1 = new Consumer() { + @Override + public void accept(final String it) { + final XStringLiteral arg = XbaseFactory.eINSTANCE.createXStringLiteral(); + arg.setValue(it); + EList _arguments = argsConstructor.getArguments(); + FeatureJvmModelInferrer.this._extendedJvmTypesBuilder.operator_add(_arguments, arg); + } + }; + arguments.forEach(_function_1); + } + + public void setStepValueType(final XVariableDeclaration variableDec, final Step step) { + JvmTypeReference typeRef = this._typeReferences.getTypeForName(StepArguments.class, step); + if ((Objects.equal(typeRef, null) || typeRef.eIsProxy())) { + return; + } + variableDec.setType(typeRef); + JvmType _type = typeRef.getType(); + final JvmGenericType type = ((JvmGenericType) _type); + if ((Objects.equal(type, null) || type.eIsProxy())) { + return; + } + XExpression _right = variableDec.getRight(); + XConstructorCall constructor = ((XConstructorCall) _right); + final UnmodifiableIterator constructors = Iterators.filter(type.getMembers().iterator(), JvmConstructor.class); + constructor.setConstructor(constructors.next()); + } + + public int generateBackgroundStepCalls(final Iterable steps, final JvmGenericType inferredJvmType, final Scenario scenario) { + int _xblockexpression = (int) 0; + { + int order = 0; + for (final Step step : steps) { + order = this.transformCalls(step, inferredJvmType, order, scenario); + } + _xblockexpression = order; + } + return _xblockexpression; + } + + public int transformCalls(final Step step, final JvmGenericType inferredJvmType, final int order, final Scenario scenario) { + int _xblockexpression = (int) 0; + { + final String methodName = this._stepNameProvider.getMethodName(step); + EList _members = inferredJvmType.getMembers(); + final Procedure1 _function = new Procedure1() { + @Override + public void apply(final JvmOperation it) { + final Procedure1 _function = new Procedure1() { + @Override + public void apply(final ITreeAppendable a) { + a.append((("super." + methodName) + "();")); + } + }; + FeatureJvmModelInferrer.this._extendedJvmTypesBuilder.setBody(it, _function); + FeatureJvmModelInferrer.this.markAsPending(it, step, scenario); + FeatureJvmModelInferrer.this._iJvmModelAssociator.associatePrimary(step, it); + FeatureJvmModelInferrer.this.getTestRuntime().markAsTestMethod(step, it); + EList _annotations = it.getAnnotations(); + JvmAnnotationReference _annotationRef = FeatureJvmModelInferrer.this._annotationTypesBuilder.annotationRef(Order.class); + final Procedure1 _function_1 = new Procedure1() { + @Override + public void apply(final JvmAnnotationReference it) { + EList _explicitValues = it.getExplicitValues(); + JvmIntAnnotationValue _createJvmIntAnnotationValue = FeatureJvmModelInferrer.this.typesFactory.createJvmIntAnnotationValue(); + final Procedure1 _function = new Procedure1() { + @Override + public void apply(final JvmIntAnnotationValue it) { + EList _values = it.getValues(); + int _intValue = Integer.valueOf(order).intValue(); + FeatureJvmModelInferrer.this._extendedJvmTypesBuilder.operator_add(_values, Integer.valueOf(_intValue)); + } + }; + JvmIntAnnotationValue _doubleArrow = ObjectExtensions.operator_doubleArrow(_createJvmIntAnnotationValue, _function); + FeatureJvmModelInferrer.this._extendedJvmTypesBuilder.operator_add(_explicitValues, _doubleArrow); + } + }; + JvmAnnotationReference _doubleArrow = ObjectExtensions.operator_doubleArrow(_annotationRef, _function_1); + FeatureJvmModelInferrer.this._extendedJvmTypesBuilder.operator_add(_annotations, _doubleArrow); + EList _annotations_1 = it.getAnnotations(); + JvmAnnotationReference _annotationRef_1 = FeatureJvmModelInferrer.this._annotationTypesBuilder.annotationRef(Named.class, FeatureJvmModelInferrer.this._stepNameProvider.describe(step)); + FeatureJvmModelInferrer.this._extendedJvmTypesBuilder.operator_add(_annotations_1, _annotationRef_1); + } + }; + JvmOperation _method = this._extendedJvmTypesBuilder.toMethod(step, methodName, this._typeReferences.getTypeForName(Void.TYPE, step), _function); + this._extendedJvmTypesBuilder.operator_add(_members, _method); + _xblockexpression = (order + 1); + } + return _xblockexpression; + } + + public void generateSteps(final Iterable steps, final JvmGenericType inferredJvmType, final int start, final Scenario scenario) { + int order = start; + for (final Step step : steps) { + order = this.transform(step, inferredJvmType, order, scenario); + } + } + + public int transform(final Step step, final JvmGenericType inferredJvmType, final int order, final Scenario scenario) { + int _xblockexpression = (int) 0; + { + EList _members = inferredJvmType.getMembers(); + final Procedure1 _function = new Procedure1() { + @Override + public void apply(final JvmOperation it) { + it.setDeclaringType(inferredJvmType); + final XExpression stepExpression = FeatureJvmModelInferrer.this._stepExpressionProvider.expressionOf(step); + FeatureJvmModelInferrer.this._iJvmModelAssociator.associatePrimary(step, it); + FeatureJvmModelInferrer.this.generateStepValues(step); + FeatureJvmModelInferrer.this._extendedJvmTypesBuilder.setBody(it, stepExpression); + FeatureJvmModelInferrer.this.getTestRuntime().markAsTestMethod(step, it); + EList _annotations = it.getAnnotations(); + JvmAnnotationReference _annotationRef = FeatureJvmModelInferrer.this._annotationTypesBuilder.annotationRef(Order.class); + final Procedure1 _function = new Procedure1() { + @Override + public void apply(final JvmAnnotationReference it) { + EList _explicitValues = it.getExplicitValues(); + JvmIntAnnotationValue _createJvmIntAnnotationValue = FeatureJvmModelInferrer.this.typesFactory.createJvmIntAnnotationValue(); + final Procedure1 _function = new Procedure1() { + @Override + public void apply(final JvmIntAnnotationValue it) { + EList _values = it.getValues(); + int _intValue = Integer.valueOf(order).intValue(); + FeatureJvmModelInferrer.this._extendedJvmTypesBuilder.operator_add(_values, Integer.valueOf(_intValue)); + } + }; + JvmIntAnnotationValue _doubleArrow = ObjectExtensions.operator_doubleArrow(_createJvmIntAnnotationValue, _function); + FeatureJvmModelInferrer.this._extendedJvmTypesBuilder.operator_add(_explicitValues, _doubleArrow); + } + }; + JvmAnnotationReference _doubleArrow = ObjectExtensions.operator_doubleArrow(_annotationRef, _function); + FeatureJvmModelInferrer.this._extendedJvmTypesBuilder.operator_add(_annotations, _doubleArrow); + String name = FeatureJvmModelInferrer.this._stepNameProvider.describe(step); + FeatureJvmModelInferrer.this._iJvmModelAssociator.associatePrimary(step, it); + FeatureJvmModelInferrer.this.markAsPending(it, step, scenario); + EList _annotations_1 = it.getAnnotations(); + JvmAnnotationReference _annotationRef_1 = FeatureJvmModelInferrer.this._annotationTypesBuilder.annotationRef(Named.class, name); + FeatureJvmModelInferrer.this._extendedJvmTypesBuilder.operator_add(_annotations_1, _annotationRef_1); + } + }; + JvmOperation _method = this._extendedJvmTypesBuilder.toMethod(step, this._stepNameProvider.getMethodName(step), this._typeReferences.getTypeForName(Void.TYPE, step), _function); + this._extendedJvmTypesBuilder.operator_add(_members, _method); + _xblockexpression = (order + 1); + } + return _xblockexpression; + } + + public Feature feature(final EObject context) { + return EcoreUtil2.getContainerOfType(context, Feature.class); + } + + public void markAsPending(final JvmOperation operation, final Step step, final Scenario scenario) { + boolean _contains = scenario.getPendingSteps().contains(step); + if (_contains) { + this.getTestRuntime().markAsPending(step, operation); + } + } + + public void init(final EObject feature, final JvmGenericType inferredJvmType, final List scenarios) { + if (feature instanceof Feature) { + _init((Feature)feature, inferredJvmType, scenarios); + return; + } else if (feature instanceof Scenario) { + _init((Scenario)feature, inferredJvmType, scenarios); + return; + } else { + throw new IllegalArgumentException("Unhandled parameter types: " + + Arrays.asList(feature, inferredJvmType, scenarios).toString()); + } + } +} diff --git a/plugins/org.jnario.feature/xtend-gen/org/jnario/feature/jvmmodel/StepContextProvider.java b/plugins/org.jnario.feature/xtend-gen/org/jnario/feature/jvmmodel/StepContextProvider.java index 637054ee5..97c800bf4 100644 --- a/plugins/org.jnario.feature/xtend-gen/org/jnario/feature/jvmmodel/StepContextProvider.java +++ b/plugins/org.jnario.feature/xtend-gen/org/jnario/feature/jvmmodel/StepContextProvider.java @@ -1,67 +1,56 @@ -package org.jnario.feature.jvmmodel; - -import com.google.common.collect.Iterables; -import com.google.inject.Inject; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.Set; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.xtext.common.types.JvmField; -import org.eclipse.xtext.xbase.XExpression; -import org.eclipse.xtext.xbase.jvmmodel.IJvmModelAssociations; -import org.eclipse.xtext.xbase.lib.CollectionLiterals; -import org.eclipse.xtext.xbase.lib.Extension; -import org.eclipse.xtext.xbase.lib.Functions.Function1; -import org.eclipse.xtext.xbase.lib.IterableExtensions; -import org.eclipse.xtext.xbase.util.XbaseUsageCrossReferencer; -import org.jnario.JnarioField; -import org.jnario.JnarioMember; -import org.jnario.feature.feature.Step; -import org.jnario.feature.jvmmodel.StepExpressionProvider; -import org.jnario.feature.jvmmodel.VisibleMembersCalculator; - -@SuppressWarnings("all") -public class StepContextProvider { - @Inject - @Extension - private StepExpressionProvider _stepExpressionProvider; - - @Inject - @Extension - private IJvmModelAssociations _iJvmModelAssociations; - - @Inject - @Extension - private VisibleMembersCalculator _visibleMembersCalculator; - - public Set usedFields(final Step step) { - Set _xblockexpression = null; - { - final XExpression expr = this._stepExpressionProvider.expressionOf(step); - Iterable _allVisibleMembers = this._visibleMembersCalculator.allVisibleMembers(step); - Iterable _filter = Iterables.filter(_allVisibleMembers, JnarioField.class); - final Function1 _function = new Function1() { - @Override - public Boolean apply(final JnarioField it) { - boolean _xblockexpression = false; - { - Set _jvmElements = StepContextProvider.this._iJvmModelAssociations.getJvmElements(it); - Iterable _filter = Iterables.filter(_jvmElements, JvmField.class); - Iterator _iterator = _filter.iterator(); - final JvmField field = _iterator.next(); - ArrayList _newArrayList = CollectionLiterals.newArrayList(expr); - final Collection usages = XbaseUsageCrossReferencer.find(field, _newArrayList); - boolean _isEmpty = usages.isEmpty(); - _xblockexpression = (!_isEmpty); - } - return Boolean.valueOf(_xblockexpression); - } - }; - Iterable _filter_1 = IterableExtensions.filter(_filter, _function); - _xblockexpression = IterableExtensions.toSet(_filter_1); - } - return _xblockexpression; - } -} +package org.jnario.feature.jvmmodel; + +import com.google.common.collect.Iterables; +import com.google.inject.Inject; +import java.util.Collection; +import java.util.Set; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.xtext.common.types.JvmField; +import org.eclipse.xtext.xbase.XExpression; +import org.eclipse.xtext.xbase.jvmmodel.IJvmModelAssociations; +import org.eclipse.xtext.xbase.lib.CollectionLiterals; +import org.eclipse.xtext.xbase.lib.Extension; +import org.eclipse.xtext.xbase.lib.Functions.Function1; +import org.eclipse.xtext.xbase.lib.IterableExtensions; +import org.eclipse.xtext.xbase.util.XbaseUsageCrossReferencer; +import org.jnario.JnarioField; +import org.jnario.feature.feature.Step; +import org.jnario.feature.jvmmodel.StepExpressionProvider; +import org.jnario.feature.jvmmodel.VisibleMembersCalculator; + +@SuppressWarnings("all") +public class StepContextProvider { + @Inject + @Extension + private StepExpressionProvider _stepExpressionProvider; + + @Inject + @Extension + private IJvmModelAssociations _iJvmModelAssociations; + + @Inject + @Extension + private VisibleMembersCalculator _visibleMembersCalculator; + + public Set usedFields(final Step step) { + Set _xblockexpression = null; + { + final XExpression expr = this._stepExpressionProvider.expressionOf(step); + final Function1 _function = new Function1() { + @Override + public Boolean apply(final JnarioField it) { + boolean _xblockexpression = false; + { + final JvmField field = Iterables.filter(StepContextProvider.this._iJvmModelAssociations.getJvmElements(it), JvmField.class).iterator().next(); + final Collection usages = XbaseUsageCrossReferencer.find(field, CollectionLiterals.newArrayList(expr)); + boolean _isEmpty = usages.isEmpty(); + _xblockexpression = (!_isEmpty); + } + return Boolean.valueOf(_xblockexpression); + } + }; + _xblockexpression = IterableExtensions.toSet(IterableExtensions.filter(Iterables.filter(this._visibleMembersCalculator.allVisibleMembers(step), JnarioField.class), _function)); + } + return _xblockexpression; + } +} diff --git a/plugins/org.jnario.feature/xtend-gen/org/jnario/feature/jvmmodel/StepExpressionProvider.java b/plugins/org.jnario.feature/xtend-gen/org/jnario/feature/jvmmodel/StepExpressionProvider.java index 6e7fbe528..3d9974123 100644 --- a/plugins/org.jnario.feature/xtend-gen/org/jnario/feature/jvmmodel/StepExpressionProvider.java +++ b/plugins/org.jnario.feature/xtend-gen/org/jnario/feature/jvmmodel/StepExpressionProvider.java @@ -1,55 +1,54 @@ -/** - * Copyright (c) 2012 BMW Car IT and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.jnario.feature.jvmmodel; - -import com.google.common.base.Objects; -import com.google.inject.Inject; -import org.eclipse.xtext.xbase.XExpression; -import org.eclipse.xtext.xbase.lib.Extension; -import org.jnario.feature.feature.Step; -import org.jnario.feature.feature.StepImplementation; -import org.jnario.feature.feature.StepReference; -import org.jnario.feature.jvmmodel.ExpressionCopier; - -/** - * @author Sebastian Benz - Initial contribution and API - */ -@SuppressWarnings("all") -public class StepExpressionProvider { - @Inject - @Extension - private ExpressionCopier _expressionCopier; - - public XExpression expressionOf(final Step step) { - if ((step instanceof StepReference)) { - this.getOrCreateExpression(((StepReference) step)); - } - return step.getExpression(); - } - - private XExpression getOrCreateExpression(final StepReference ref) { - XExpression _expression = ref.getExpression(); - boolean _notEquals = (!Objects.equal(_expression, null)); - if (_notEquals) { - return ref.getExpression(); - } - StepImplementation _reference = null; - if (ref!=null) { - _reference=ref.getReference(); - } - final StepImplementation step = _reference; - if ((Objects.equal(step, null) || step.eIsProxy())) { - return null; - } - XExpression _expression_1 = step.getExpression(); - XExpression _cloneWithProxies = this._expressionCopier.cloneWithProxies(_expression_1); - final XExpression expr = ((XExpression) _cloneWithProxies); - ref.setExpression(expr); - return expr; - } -} +/** + * Copyright (c) 2012 BMW Car IT and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.jnario.feature.jvmmodel; + +import com.google.common.base.Objects; +import com.google.inject.Inject; +import org.eclipse.xtext.xbase.XExpression; +import org.eclipse.xtext.xbase.lib.Extension; +import org.jnario.feature.feature.Step; +import org.jnario.feature.feature.StepImplementation; +import org.jnario.feature.feature.StepReference; +import org.jnario.feature.jvmmodel.ExpressionCopier; + +/** + * @author Sebastian Benz - Initial contribution and API + */ +@SuppressWarnings("all") +public class StepExpressionProvider { + @Inject + @Extension + private ExpressionCopier _expressionCopier; + + public XExpression expressionOf(final Step step) { + if ((step instanceof StepReference)) { + this.getOrCreateExpression(((StepReference) step)); + } + return step.getExpression(); + } + + private XExpression getOrCreateExpression(final StepReference ref) { + XExpression _expression = ref.getExpression(); + boolean _notEquals = (!Objects.equal(_expression, null)); + if (_notEquals) { + return ref.getExpression(); + } + StepImplementation _reference = null; + if (ref!=null) { + _reference=ref.getReference(); + } + final StepImplementation step = _reference; + if ((Objects.equal(step, null) || step.eIsProxy())) { + return null; + } + XExpression _cloneWithProxies = this._expressionCopier.cloneWithProxies(step.getExpression()); + final XExpression expr = ((XExpression) _cloneWithProxies); + ref.setExpression(expr); + return expr; + } +} diff --git a/plugins/org.jnario.feature/xtend-gen/org/jnario/feature/jvmmodel/StepReferenceFieldCreator.java b/plugins/org.jnario.feature/xtend-gen/org/jnario/feature/jvmmodel/StepReferenceFieldCreator.java index 9b531a78c..ad70fb0c8 100644 --- a/plugins/org.jnario.feature/xtend-gen/org/jnario/feature/jvmmodel/StepReferenceFieldCreator.java +++ b/plugins/org.jnario.feature/xtend-gen/org/jnario/feature/jvmmodel/StepReferenceFieldCreator.java @@ -1,117 +1,106 @@ -/** - * Copyright (c) 2012 BMW Car IT and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.jnario.feature.jvmmodel; - -import com.google.common.base.Objects; -import com.google.common.collect.Iterables; -import com.google.inject.Inject; -import java.util.ArrayList; -import java.util.Set; -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.xtext.xbase.XExpression; -import org.eclipse.xtext.xbase.lib.CollectionLiterals; -import org.eclipse.xtext.xbase.lib.Extension; -import org.eclipse.xtext.xbase.lib.Functions.Function1; -import org.eclipse.xtext.xbase.lib.IterableExtensions; -import org.jnario.JnarioClass; -import org.jnario.JnarioField; -import org.jnario.JnarioMember; -import org.jnario.feature.feature.Scenario; -import org.jnario.feature.feature.Step; -import org.jnario.feature.feature.StepImplementation; -import org.jnario.feature.feature.StepReference; -import org.jnario.feature.jvmmodel.ExpressionCopier; -import org.jnario.feature.jvmmodel.VisibleMembersCalculator; -import org.jnario.util.SourceAdapter; - -/** - * @author Birgit Engelmann - Initial contribution and API - */ -@SuppressWarnings("all") -public class StepReferenceFieldCreator { - @Inject - @Extension - private VisibleMembersCalculator _visibleMembersCalculator; - - @Inject - @Extension - private ExpressionCopier _expressionCopier; - - public void copyJnarioMemberForReferences(final Scenario scenario) { - EList _steps = scenario.getSteps(); - Iterable _filter = Iterables.filter(_steps, StepReference.class); - final Function1 _function = new Function1() { - @Override - public Boolean apply(final StepReference it) { - StepImplementation _reference = it.getReference(); - XExpression _expression = null; - if (_reference!=null) { - _expression=_reference.getExpression(); - } - return Boolean.valueOf((!Objects.equal(_expression, null))); - } - }; - final Iterable refs = IterableExtensions.filter(_filter, _function); - final Set fieldNames = this.getExistingFieldNamesForContainerOfStepReference(scenario); - for (final StepReference ref : refs) { - { - StepImplementation _reference = ref.getReference(); - final Iterable members = this._visibleMembersCalculator.allVisibleMembers(_reference); - this.copyFields(scenario, members, fieldNames); - } - } - } - - private Set getExistingFieldNamesForContainerOfStepReference(final Scenario scenario) { - Iterable _allVisibleMembers = this._visibleMembersCalculator.allVisibleMembers(scenario); - return this.getExistingFieldNames(_allVisibleMembers); - } - - private Set getExistingFieldNames(final Iterable members) { - Iterable _filter = Iterables.filter(members, JnarioField.class); - final Function1 _function = new Function1() { - @Override - public Boolean apply(final JnarioField it) { - return Boolean.valueOf((!Objects.equal(it, null))); - } - }; - Iterable _filter_1 = IterableExtensions.filter(_filter, _function); - final Function1 _function_1 = new Function1() { - @Override - public String apply(final JnarioField it) { - return it.getName(); - } - }; - Iterable _map = IterableExtensions.map(_filter_1, _function_1); - return IterableExtensions.toSet(_map); - } - - private void copyFields(final EObject objectWithReference, final Iterable members, final Set fieldNames) { - if ((!(objectWithReference instanceof JnarioClass))) { - return; - } - final JnarioClass type = ((JnarioClass) objectWithReference); - final ArrayList newFields = CollectionLiterals.newArrayList(); - Iterable _filter = Iterables.filter(members, JnarioField.class); - for (final JnarioField field : _filter) { - String _name = field.getName(); - boolean _contains = fieldNames.contains(_name); - boolean _not = (!_contains); - if (_not) { - final JnarioField copiedMember = this._expressionCopier.cloneWithProxies(field); - SourceAdapter.adapt(copiedMember, field); - newFields.add(((JnarioField) copiedMember)); - String _name_1 = field.getName(); - fieldNames.add(_name_1); - } - } - EList _members = type.getMembers(); - _members.addAll(newFields); - } -} +/** + * Copyright (c) 2012 BMW Car IT and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.jnario.feature.jvmmodel; + +import com.google.common.base.Objects; +import com.google.common.collect.Iterables; +import com.google.inject.Inject; +import java.util.ArrayList; +import java.util.Set; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.xtext.xbase.XExpression; +import org.eclipse.xtext.xbase.lib.CollectionLiterals; +import org.eclipse.xtext.xbase.lib.Extension; +import org.eclipse.xtext.xbase.lib.Functions.Function1; +import org.eclipse.xtext.xbase.lib.IterableExtensions; +import org.jnario.JnarioClass; +import org.jnario.JnarioField; +import org.jnario.JnarioMember; +import org.jnario.feature.feature.Scenario; +import org.jnario.feature.feature.StepImplementation; +import org.jnario.feature.feature.StepReference; +import org.jnario.feature.jvmmodel.ExpressionCopier; +import org.jnario.feature.jvmmodel.VisibleMembersCalculator; +import org.jnario.util.SourceAdapter; + +/** + * @author Birgit Engelmann - Initial contribution and API + */ +@SuppressWarnings("all") +public class StepReferenceFieldCreator { + @Inject + @Extension + private VisibleMembersCalculator _visibleMembersCalculator; + + @Inject + @Extension + private ExpressionCopier _expressionCopier; + + public void copyJnarioMemberForReferences(final Scenario scenario) { + final Function1 _function = new Function1() { + @Override + public Boolean apply(final StepReference it) { + StepImplementation _reference = it.getReference(); + XExpression _expression = null; + if (_reference!=null) { + _expression=_reference.getExpression(); + } + return Boolean.valueOf((!Objects.equal(_expression, null))); + } + }; + final Iterable refs = IterableExtensions.filter(Iterables.filter(scenario.getSteps(), StepReference.class), _function); + final Set fieldNames = this.getExistingFieldNamesForContainerOfStepReference(scenario); + for (final StepReference ref : refs) { + { + final Iterable members = this._visibleMembersCalculator.allVisibleMembers(ref.getReference()); + this.copyFields(scenario, members, fieldNames); + } + } + } + + private Set getExistingFieldNamesForContainerOfStepReference(final Scenario scenario) { + return this.getExistingFieldNames(this._visibleMembersCalculator.allVisibleMembers(scenario)); + } + + private Set getExistingFieldNames(final Iterable members) { + final Function1 _function = new Function1() { + @Override + public Boolean apply(final JnarioField it) { + return Boolean.valueOf((!Objects.equal(it, null))); + } + }; + final Function1 _function_1 = new Function1() { + @Override + public String apply(final JnarioField it) { + return it.getName(); + } + }; + return IterableExtensions.toSet(IterableExtensions.map(IterableExtensions.filter(Iterables.filter(members, JnarioField.class), _function), _function_1)); + } + + private void copyFields(final EObject objectWithReference, final Iterable members, final Set fieldNames) { + if ((!(objectWithReference instanceof JnarioClass))) { + return; + } + final JnarioClass type = ((JnarioClass) objectWithReference); + final ArrayList newFields = CollectionLiterals.newArrayList(); + Iterable _filter = Iterables.filter(members, JnarioField.class); + for (final JnarioField field : _filter) { + boolean _contains = fieldNames.contains(field.getName()); + boolean _not = (!_contains); + if (_not) { + final JnarioField copiedMember = this._expressionCopier.cloneWithProxies(field); + SourceAdapter.adapt(copiedMember, field); + newFields.add(((JnarioField) copiedMember)); + String _name = field.getName(); + fieldNames.add(_name); + } + } + type.getMembers().addAll(newFields); + } +} diff --git a/plugins/org.jnario.feature/xtend-gen/org/jnario/feature/jvmmodel/StepTypeProvider.java b/plugins/org.jnario.feature/xtend-gen/org/jnario/feature/jvmmodel/StepTypeProvider.java index d8449fdc9..f9ed9e3e5 100644 --- a/plugins/org.jnario.feature/xtend-gen/org/jnario/feature/jvmmodel/StepTypeProvider.java +++ b/plugins/org.jnario.feature/xtend-gen/org/jnario/feature/jvmmodel/StepTypeProvider.java @@ -1,110 +1,104 @@ -package org.jnario.feature.jvmmodel; - -import java.util.Arrays; -import java.util.Collections; -import java.util.Set; -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.xtext.xbase.lib.CollectionLiterals; -import org.jnario.feature.feature.FeaturePackage; -import org.jnario.feature.feature.Given; -import org.jnario.feature.feature.GivenReference; -import org.jnario.feature.feature.Scenario; -import org.jnario.feature.feature.Step; -import org.jnario.feature.feature.Then; -import org.jnario.feature.feature.ThenReference; -import org.jnario.feature.feature.When; -import org.jnario.feature.feature.WhenReference; - -@SuppressWarnings("all") -public class StepTypeProvider { - public final static Set ANDS = Collections.unmodifiableSet(CollectionLiterals.newHashSet(FeaturePackage.eINSTANCE.getBut(), FeaturePackage.eINSTANCE.getButReference(), FeaturePackage.eINSTANCE.getAnd(), FeaturePackage.eINSTANCE.getAndReference())); - - public final static Set GIVEN = Collections.unmodifiableSet(CollectionLiterals.newHashSet(FeaturePackage.eINSTANCE.getGiven(), FeaturePackage.eINSTANCE.getGivenReference())); - - public final static Set WHEN = Collections.unmodifiableSet(CollectionLiterals.newHashSet(FeaturePackage.eINSTANCE.getWhen(), FeaturePackage.eINSTANCE.getWhenReference())); - - public final static Set THEN = Collections.unmodifiableSet(CollectionLiterals.newHashSet(FeaturePackage.eINSTANCE.getThen(), FeaturePackage.eINSTANCE.getThenReference())); - - protected Set _getExpectedTypes(final Given step) { - return StepTypeProvider.GIVEN; - } - - protected Set _getExpectedTypes(final GivenReference step) { - return StepTypeProvider.GIVEN; - } - - protected Set _getExpectedTypes(final WhenReference step) { - return StepTypeProvider.WHEN; - } - - protected Set _getExpectedTypes(final When step) { - return StepTypeProvider.WHEN; - } - - protected Set _getExpectedTypes(final Then step) { - return StepTypeProvider.THEN; - } - - protected Set _getExpectedTypes(final ThenReference step) { - return StepTypeProvider.THEN; - } - - protected Set _getExpectedTypes(final Step step) { - Step _definingStep = this.getDefiningStep(step); - return this.getExpectedTypes(_definingStep); - } - - public EClass getActualType(final Step step) { - Step _definingStep = this.getDefiningStep(step); - return _definingStep.eClass(); - } - - private Step getDefiningStep(final Step step) { - Step _xblockexpression = null; - { - EObject _eContainer = step.eContainer(); - final Scenario container = ((Scenario) _eContainer); - EList _steps = container.getSteps(); - final int index = _steps.indexOf(step); - int i = index; - while ((i >= 0)) { - { - EList _steps_1 = container.getSteps(); - final Step candidate = _steps_1.get(i); - EClass _eClass = candidate.eClass(); - boolean _contains = StepTypeProvider.ANDS.contains(_eClass); - boolean _not = (!_contains); - if (_not) { - return candidate; - } - i = (i - 1); - } - } - _xblockexpression = step; - } - return _xblockexpression; - } - - public Set getExpectedTypes(final Step step) { - if (step instanceof Given) { - return _getExpectedTypes((Given)step); - } else if (step instanceof GivenReference) { - return _getExpectedTypes((GivenReference)step); - } else if (step instanceof Then) { - return _getExpectedTypes((Then)step); - } else if (step instanceof ThenReference) { - return _getExpectedTypes((ThenReference)step); - } else if (step instanceof When) { - return _getExpectedTypes((When)step); - } else if (step instanceof WhenReference) { - return _getExpectedTypes((WhenReference)step); - } else if (step != null) { - return _getExpectedTypes(step); - } else { - throw new IllegalArgumentException("Unhandled parameter types: " + - Arrays.asList(step).toString()); - } - } -} +package org.jnario.feature.jvmmodel; + +import java.util.Arrays; +import java.util.Collections; +import java.util.Set; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.xtext.xbase.lib.CollectionLiterals; +import org.jnario.feature.feature.FeaturePackage; +import org.jnario.feature.feature.Given; +import org.jnario.feature.feature.GivenReference; +import org.jnario.feature.feature.Scenario; +import org.jnario.feature.feature.Step; +import org.jnario.feature.feature.Then; +import org.jnario.feature.feature.ThenReference; +import org.jnario.feature.feature.When; +import org.jnario.feature.feature.WhenReference; + +@SuppressWarnings("all") +public class StepTypeProvider { + public final static Set ANDS = Collections.unmodifiableSet(CollectionLiterals.newHashSet(FeaturePackage.eINSTANCE.getBut(), FeaturePackage.eINSTANCE.getButReference(), FeaturePackage.eINSTANCE.getAnd(), FeaturePackage.eINSTANCE.getAndReference())); + + public final static Set GIVEN = Collections.unmodifiableSet(CollectionLiterals.newHashSet(FeaturePackage.eINSTANCE.getGiven(), FeaturePackage.eINSTANCE.getGivenReference())); + + public final static Set WHEN = Collections.unmodifiableSet(CollectionLiterals.newHashSet(FeaturePackage.eINSTANCE.getWhen(), FeaturePackage.eINSTANCE.getWhenReference())); + + public final static Set THEN = Collections.unmodifiableSet(CollectionLiterals.newHashSet(FeaturePackage.eINSTANCE.getThen(), FeaturePackage.eINSTANCE.getThenReference())); + + protected Set _getExpectedTypes(final Given step) { + return StepTypeProvider.GIVEN; + } + + protected Set _getExpectedTypes(final GivenReference step) { + return StepTypeProvider.GIVEN; + } + + protected Set _getExpectedTypes(final WhenReference step) { + return StepTypeProvider.WHEN; + } + + protected Set _getExpectedTypes(final When step) { + return StepTypeProvider.WHEN; + } + + protected Set _getExpectedTypes(final Then step) { + return StepTypeProvider.THEN; + } + + protected Set _getExpectedTypes(final ThenReference step) { + return StepTypeProvider.THEN; + } + + protected Set _getExpectedTypes(final Step step) { + return this.getExpectedTypes(this.getDefiningStep(step)); + } + + public EClass getActualType(final Step step) { + return this.getDefiningStep(step).eClass(); + } + + private Step getDefiningStep(final Step step) { + Step _xblockexpression = null; + { + EObject _eContainer = step.eContainer(); + final Scenario container = ((Scenario) _eContainer); + final int index = container.getSteps().indexOf(step); + int i = index; + while ((i >= 0)) { + { + final Step candidate = container.getSteps().get(i); + boolean _contains = StepTypeProvider.ANDS.contains(candidate.eClass()); + boolean _not = (!_contains); + if (_not) { + return candidate; + } + i = (i - 1); + } + } + _xblockexpression = step; + } + return _xblockexpression; + } + + public Set getExpectedTypes(final Step step) { + if (step instanceof Given) { + return _getExpectedTypes((Given)step); + } else if (step instanceof GivenReference) { + return _getExpectedTypes((GivenReference)step); + } else if (step instanceof Then) { + return _getExpectedTypes((Then)step); + } else if (step instanceof ThenReference) { + return _getExpectedTypes((ThenReference)step); + } else if (step instanceof When) { + return _getExpectedTypes((When)step); + } else if (step instanceof WhenReference) { + return _getExpectedTypes((WhenReference)step); + } else if (step != null) { + return _getExpectedTypes(step); + } else { + throw new IllegalArgumentException("Unhandled parameter types: " + + Arrays.asList(step).toString()); + } + } +} diff --git a/plugins/org.jnario.feature/xtend-gen/org/jnario/feature/jvmmodel/StepsProvider.java b/plugins/org.jnario.feature/xtend-gen/org/jnario/feature/jvmmodel/StepsProvider.java index df28b2ea7..1bb98971a 100644 --- a/plugins/org.jnario.feature/xtend-gen/org/jnario/feature/jvmmodel/StepsProvider.java +++ b/plugins/org.jnario.feature/xtend-gen/org/jnario/feature/jvmmodel/StepsProvider.java @@ -1,74 +1,66 @@ -package org.jnario.feature.jvmmodel; - -import com.google.common.base.Objects; -import com.google.common.collect.Iterables; -import java.util.Collections; -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.xtext.xbase.lib.CollectionLiterals; -import org.eclipse.xtext.xbase.lib.Functions.Function1; -import org.eclipse.xtext.xbase.lib.IterableExtensions; -import org.jnario.JnarioTypeDeclaration; -import org.jnario.feature.feature.Background; -import org.jnario.feature.feature.Feature; -import org.jnario.feature.feature.FeatureFile; -import org.jnario.feature.feature.Scenario; -import org.jnario.feature.feature.Step; -import org.jnario.feature.feature.StepImplementation; - -@SuppressWarnings("all") -public class StepsProvider { - public Iterable getSteps(final EObject context) { - Iterable _xblockexpression = null; - { - Resource _eResource = context.eResource(); - boolean _equals = Objects.equal(_eResource, null); - if (_equals) { - return CollectionLiterals.emptyList(); - } - Resource _eResource_1 = context.eResource(); - EList _contents = _eResource_1.getContents(); - final Iterable featureFiles = Iterables.filter(_contents, FeatureFile.class); - final Function1> _function = new Function1>() { - @Override - public EList apply(final FeatureFile it) { - return it.getXtendTypes(); - } - }; - Iterable> _map = IterableExtensions.>map(featureFiles, _function); - Iterable _flatten = Iterables.concat(_map); - final Iterable features = Iterables.filter(_flatten, Feature.class); - final Function1> _function_1 = new Function1>() { - @Override - public Iterable apply(final Feature it) { - Iterable _xblockexpression = null; - { - Background _background = it.getBackground(); - boolean _equals = Objects.equal(_background, null); - if (_equals) { - return it.getScenarios(); - } - EList _scenarios = it.getScenarios(); - Background _background_1 = it.getBackground(); - _xblockexpression = Iterables.concat(_scenarios, Collections.unmodifiableList(CollectionLiterals.newArrayList(_background_1))); - } - return _xblockexpression; - } - }; - Iterable> _map_1 = IterableExtensions.>map(features, _function_1); - Iterable _flatten_1 = Iterables.concat(_map_1); - final Iterable scenarios = IterableExtensions.filterNull(_flatten_1); - final Function1> _function_2 = new Function1>() { - @Override - public EList apply(final Scenario it) { - return it.getSteps(); - } - }; - Iterable> _map_2 = IterableExtensions.>map(scenarios, _function_2); - Iterable _flatten_2 = Iterables.concat(_map_2); - _xblockexpression = Iterables.filter(_flatten_2, StepImplementation.class); - } - return _xblockexpression; - } -} +package org.jnario.feature.jvmmodel; + +import com.google.common.base.Objects; +import com.google.common.collect.Iterables; +import java.util.Collections; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.xtext.xbase.lib.CollectionLiterals; +import org.eclipse.xtext.xbase.lib.Functions.Function1; +import org.eclipse.xtext.xbase.lib.IterableExtensions; +import org.jnario.JnarioTypeDeclaration; +import org.jnario.feature.feature.Background; +import org.jnario.feature.feature.Feature; +import org.jnario.feature.feature.FeatureFile; +import org.jnario.feature.feature.Scenario; +import org.jnario.feature.feature.Step; +import org.jnario.feature.feature.StepImplementation; + +@SuppressWarnings("all") +public class StepsProvider { + public Iterable getSteps(final EObject context) { + Iterable _xblockexpression = null; + { + Resource _eResource = context.eResource(); + boolean _equals = Objects.equal(_eResource, null); + if (_equals) { + return CollectionLiterals.emptyList(); + } + final Iterable featureFiles = Iterables.filter(context.eResource().getContents(), FeatureFile.class); + final Function1> _function = new Function1>() { + @Override + public EList apply(final FeatureFile it) { + return it.getXtendTypes(); + } + }; + final Iterable features = Iterables.filter(Iterables.concat(IterableExtensions.>map(featureFiles, _function)), Feature.class); + final Function1> _function_1 = new Function1>() { + @Override + public Iterable apply(final Feature it) { + Iterable _xblockexpression = null; + { + Background _background = it.getBackground(); + boolean _equals = Objects.equal(_background, null); + if (_equals) { + return it.getScenarios(); + } + EList _scenarios = it.getScenarios(); + Background _background_1 = it.getBackground(); + _xblockexpression = Iterables.concat(_scenarios, Collections.unmodifiableList(CollectionLiterals.newArrayList(_background_1))); + } + return _xblockexpression; + } + }; + final Iterable scenarios = IterableExtensions.filterNull(Iterables.concat(IterableExtensions.>map(features, _function_1))); + final Function1> _function_2 = new Function1>() { + @Override + public EList apply(final Scenario it) { + return it.getSteps(); + } + }; + _xblockexpression = Iterables.filter(Iterables.concat(IterableExtensions.>map(scenarios, _function_2)), StepImplementation.class); + } + return _xblockexpression; + } +} diff --git a/plugins/org.jnario.feature/xtend-gen/org/jnario/feature/jvmmodel/VisibleMembersCalculator.java b/plugins/org.jnario.feature/xtend-gen/org/jnario/feature/jvmmodel/VisibleMembersCalculator.java index 87c6a0f04..f3610065b 100644 --- a/plugins/org.jnario.feature/xtend-gen/org/jnario/feature/jvmmodel/VisibleMembersCalculator.java +++ b/plugins/org.jnario.feature/xtend-gen/org/jnario/feature/jvmmodel/VisibleMembersCalculator.java @@ -1,44 +1,43 @@ -package org.jnario.feature.jvmmodel; - -import com.google.common.base.Objects; -import com.google.common.collect.Iterables; -import org.eclipse.emf.common.util.EList; -import org.eclipse.xtext.EcoreUtil2; -import org.eclipse.xtext.xbase.lib.CollectionLiterals; -import org.jnario.JnarioMember; -import org.jnario.feature.feature.Background; -import org.jnario.feature.feature.Feature; -import org.jnario.feature.feature.Scenario; -import org.jnario.feature.feature.Step; - -@SuppressWarnings("all") -public class VisibleMembersCalculator { - public Iterable allVisibleMembers(final Step step) { - Iterable _xblockexpression = null; - { - final Scenario scenario = EcoreUtil2.getContainerOfType(step, Scenario.class); - boolean _equals = Objects.equal(scenario, null); - if (_equals) { - return CollectionLiterals.emptyList(); - } - _xblockexpression = this.allVisibleMembers(scenario); - } - return _xblockexpression; - } - - public Iterable allVisibleMembers(final Scenario scenario) { - EList members = scenario.getMembers(); - if ((scenario instanceof Background)) { - return members; - } - final Feature feature = EcoreUtil2.getContainerOfType(scenario, Feature.class); - Background _background = feature.getBackground(); - boolean _equals = Objects.equal(_background, null); - if (_equals) { - return members; - } - Background _background_1 = feature.getBackground(); - EList _members = _background_1.getMembers(); - return Iterables.concat(members, _members); - } -} +package org.jnario.feature.jvmmodel; + +import com.google.common.base.Objects; +import com.google.common.collect.Iterables; +import org.eclipse.emf.common.util.EList; +import org.eclipse.xtext.EcoreUtil2; +import org.eclipse.xtext.xbase.lib.CollectionLiterals; +import org.jnario.JnarioMember; +import org.jnario.feature.feature.Background; +import org.jnario.feature.feature.Feature; +import org.jnario.feature.feature.Scenario; +import org.jnario.feature.feature.Step; + +@SuppressWarnings("all") +public class VisibleMembersCalculator { + public Iterable allVisibleMembers(final Step step) { + Iterable _xblockexpression = null; + { + final Scenario scenario = EcoreUtil2.getContainerOfType(step, Scenario.class); + boolean _equals = Objects.equal(scenario, null); + if (_equals) { + return CollectionLiterals.emptyList(); + } + _xblockexpression = this.allVisibleMembers(scenario); + } + return _xblockexpression; + } + + public Iterable allVisibleMembers(final Scenario scenario) { + EList members = scenario.getMembers(); + if ((scenario instanceof Background)) { + return members; + } + final Feature feature = EcoreUtil2.getContainerOfType(scenario, Feature.class); + Background _background = feature.getBackground(); + boolean _equals = Objects.equal(_background, null); + if (_equals) { + return members; + } + EList _members = feature.getBackground().getMembers(); + return Iterables.concat(members, _members); + } +} diff --git a/plugins/org.jnario.feature/xtend-gen/org/jnario/feature/naming/StepNameProvider.java b/plugins/org.jnario.feature/xtend-gen/org/jnario/feature/naming/StepNameProvider.java index cf73b7cb3..8db2059e1 100644 --- a/plugins/org.jnario.feature/xtend-gen/org/jnario/feature/naming/StepNameProvider.java +++ b/plugins/org.jnario.feature/xtend-gen/org/jnario/feature/naming/StepNameProvider.java @@ -1,115 +1,104 @@ -/** - * Copyright (c) 2012 BMW Car IT and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.jnario.feature.naming; - -import com.google.common.base.Objects; -import java.util.Arrays; -import org.eclipse.emf.ecore.EAttribute; -import org.eclipse.emf.ecore.EReference; -import org.jnario.JnarioPackage; -import org.jnario.feature.feature.Feature; -import org.jnario.feature.feature.FeaturePackage; -import org.jnario.feature.feature.Scenario; -import org.jnario.feature.feature.Step; -import org.jnario.feature.feature.StepReference; -import org.jnario.feature.naming.ArgumentsHelper; -import org.jnario.util.Nodes; -import org.jnario.util.Strings; - -/** - * @author Sebastian Benz - Initial contribution and API - * @author Birgit Engelmann - */ -@SuppressWarnings("all") -public class StepNameProvider { - protected String _nameOf(final Step step) { - String _xblockexpression = null; - { - if ((Objects.equal(step, null) || Objects.equal(step.getName(), null))) { - return null; - } - EAttribute _jnarioTypeDeclaration_Name = JnarioPackage.eINSTANCE.getJnarioTypeDeclaration_Name(); - _xblockexpression = Nodes.textForFeature(step, _jnarioTypeDeclaration_Name); - } - return _xblockexpression; - } - - protected String _nameOf(final StepReference ref) { - String _xifexpression = null; - boolean _equals = Objects.equal(ref, null); - if (_equals) { - _xifexpression = null; - } else { - EReference _stepReference_Reference = FeaturePackage.eINSTANCE.getStepReference_Reference(); - _xifexpression = Nodes.textForFeature(ref, _stepReference_Reference); - } - return _xifexpression; - } - - public String getMethodName(final Step step) { - String _nameOf = this.nameOf(step); - String _firstLine = Strings.firstLine(_nameOf); - String originalName = _firstLine.trim(); - return Strings.toMethodName(originalName); - } - - public String describe(final Feature feature) { - String _name = feature.getName(); - return Strings.makeJunitConform(_name); - } - - public String describe(final Scenario scenario) { - String _name = scenario.getName(); - return Strings.makeJunitConform(_name); - } - - public String describe(final Step step) { - String _nameOf = this.nameOf(step); - StringBuilder name = new StringBuilder(_nameOf); - boolean _isPending = step.isPending(); - if (_isPending) { - Strings.markAsPending(name); - } - String _string = name.toString(); - String _firstLine = Strings.firstLine(_string); - return Strings.makeJunitConform(_firstLine); - } - - public String removeKeywords(final String name) { - boolean _isNullOrEmpty = com.google.common.base.Strings.isNullOrEmpty(name); - if (_isNullOrEmpty) { - return ""; - } - int index = name.indexOf(" "); - if ((index == (-1))) { - return ""; - } - return name.substring((index + 1)); - } - - public String removeArguments(final String text) { - String _xblockexpression = null; - { - String name = Strings.firstLine(text); - String _removeArgumentValues = ArgumentsHelper.removeArgumentValues(name); - _xblockexpression = _removeArgumentValues.trim(); - } - return _xblockexpression; - } - - public String nameOf(final Step ref) { - if (ref instanceof StepReference) { - return _nameOf((StepReference)ref); - } else if (ref != null) { - return _nameOf(ref); - } else { - throw new IllegalArgumentException("Unhandled parameter types: " + - Arrays.asList(ref).toString()); - } - } -} +/** + * Copyright (c) 2012 BMW Car IT and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.jnario.feature.naming; + +import com.google.common.base.Objects; +import java.util.Arrays; +import org.jnario.JnarioPackage; +import org.jnario.feature.feature.Feature; +import org.jnario.feature.feature.FeaturePackage; +import org.jnario.feature.feature.Scenario; +import org.jnario.feature.feature.Step; +import org.jnario.feature.feature.StepReference; +import org.jnario.feature.naming.ArgumentsHelper; +import org.jnario.util.Nodes; +import org.jnario.util.Strings; + +/** + * @author Sebastian Benz - Initial contribution and API + * @author Birgit Engelmann + */ +@SuppressWarnings("all") +public class StepNameProvider { + protected String _nameOf(final Step step) { + String _xblockexpression = null; + { + if ((Objects.equal(step, null) || Objects.equal(step.getName(), null))) { + return null; + } + _xblockexpression = Nodes.textForFeature(step, JnarioPackage.eINSTANCE.getJnarioTypeDeclaration_Name()); + } + return _xblockexpression; + } + + protected String _nameOf(final StepReference ref) { + String _xifexpression = null; + boolean _equals = Objects.equal(ref, null); + if (_equals) { + _xifexpression = null; + } else { + _xifexpression = Nodes.textForFeature(ref, FeaturePackage.eINSTANCE.getStepReference_Reference()); + } + return _xifexpression; + } + + public String getMethodName(final Step step) { + String originalName = Strings.firstLine(this.nameOf(step)).trim(); + return Strings.toMethodName(originalName); + } + + public String describe(final Feature feature) { + return Strings.makeJunitConform(feature.getName()); + } + + public String describe(final Scenario scenario) { + return Strings.makeJunitConform(scenario.getName()); + } + + public String describe(final Step step) { + String _nameOf = this.nameOf(step); + StringBuilder name = new StringBuilder(_nameOf); + boolean _isPending = step.isPending(); + if (_isPending) { + Strings.markAsPending(name); + } + return Strings.makeJunitConform(Strings.firstLine(name.toString())); + } + + public String removeKeywords(final String name) { + boolean _isNullOrEmpty = com.google.common.base.Strings.isNullOrEmpty(name); + if (_isNullOrEmpty) { + return ""; + } + int index = name.indexOf(" "); + if ((index == (-1))) { + return ""; + } + return name.substring((index + 1)); + } + + public String removeArguments(final String text) { + String _xblockexpression = null; + { + String name = Strings.firstLine(text); + _xblockexpression = ArgumentsHelper.removeArgumentValues(name).trim(); + } + return _xblockexpression; + } + + public String nameOf(final Step ref) { + if (ref instanceof StepReference) { + return _nameOf((StepReference)ref); + } else if (ref != null) { + return _nameOf(ref); + } else { + throw new IllegalArgumentException("Unhandled parameter types: " + + Arrays.asList(ref).toString()); + } + } +} diff --git a/plugins/org.jnario.lib/xtend-gen/org/jnario/lib/TimeoutError.java b/plugins/org.jnario.lib/xtend-gen/org/jnario/lib/TimeoutError.java index 6f2d0742c..18b9775dc 100644 --- a/plugins/org.jnario.lib/xtend-gen/org/jnario/lib/TimeoutError.java +++ b/plugins/org.jnario.lib/xtend-gen/org/jnario/lib/TimeoutError.java @@ -1,8 +1,8 @@ -package org.jnario.lib; - -@SuppressWarnings("all") -public class TimeoutError extends AssertionError { - public TimeoutError(final String message) { - super(message); - } -} +package org.jnario.lib; + +@SuppressWarnings("all") +public class TimeoutError extends AssertionError { + public TimeoutError(final String message) { + super(message); + } +} diff --git a/plugins/org.jnario.lib/xtend-gen/org/jnario/lib/Wait.java b/plugins/org.jnario.lib/xtend-gen/org/jnario/lib/Wait.java index 18d44b6ad..ac7ba5171 100644 --- a/plugins/org.jnario.lib/xtend-gen/org/jnario/lib/Wait.java +++ b/plugins/org.jnario.lib/xtend-gen/org/jnario/lib/Wait.java @@ -1,92 +1,92 @@ -package org.jnario.lib; - -import org.eclipse.xtext.xbase.lib.Exceptions; -import org.eclipse.xtext.xbase.lib.Functions.Function0; -import org.eclipse.xtext.xbase.lib.Functions.Function1; -import org.jnario.lib.Clock; -import org.jnario.lib.Sleeper; -import org.jnario.lib.TimeoutError; - -/** - * A helper for automatically waiting until a condition turns true. Use it like this: - * - * - * fact "Wait for something"{ - * // define wait condition using lambdas - * waitUntil[1 > 0] - * // configuration options - * waitUntil[ - * message = "Custom error message" - * duration = 100 - * pollingInterval = 10 - * 1 > 0 - * ] - * } - * - */ -@SuppressWarnings("all") -public class Wait { - /** - * Wait until the provided function evaluates to true. - */ - public static void waitUntil(final Function1 initializer) { - final Wait wait = new Wait(Sleeper.SYSTEM_SLEEPER, Clock.SYSTEM_CLOCK); - final Function0 _function = new Function0() { - @Override - public Boolean apply() { - return initializer.apply(wait); - } - }; - final Function0 condition = _function; - wait.until(condition); - } - - private final Sleeper sleeper; - - private final Clock clock; - - private String message = "Timeout occurred"; - - private long duration = 500l; - - private long pollingInterval = 50l; - - public Wait(final Sleeper sleeper, final Clock clock) { - this.sleeper = sleeper; - this.clock = clock; - } - - public void until(final Function0 condition) { - try { - final long start = this.clock.currentTime(); - while ((!(condition.apply()).booleanValue())) { - { - boolean _timeOut = this.timeOut(start); - if (_timeOut) { - throw new TimeoutError(this.message); - } - this.sleeper.sleep(this.pollingInterval); - } - } - } catch (Throwable _e) { - throw Exceptions.sneakyThrow(_e); - } - } - - public boolean timeOut(final long start) { - long _currentTime = this.clock.currentTime(); - return (_currentTime > (start + this.duration)); - } - - public String setMessage(final String message) { - return this.message = message; - } - - public long setDuration(final long duration) { - return this.duration = duration; - } - - public long setPollingInterval(final long pollingInterval) { - return this.pollingInterval = pollingInterval; - } -} +package org.jnario.lib; + +import org.eclipse.xtext.xbase.lib.Exceptions; +import org.eclipse.xtext.xbase.lib.Functions.Function0; +import org.eclipse.xtext.xbase.lib.Functions.Function1; +import org.jnario.lib.Clock; +import org.jnario.lib.Sleeper; +import org.jnario.lib.TimeoutError; + +/** + * A helper for automatically waiting until a condition turns true. Use it like this: + * + * + * fact "Wait for something"{ + * // define wait condition using lambdas + * waitUntil[1 > 0] + * // configuration options + * waitUntil[ + * message = "Custom error message" + * duration = 100 + * pollingInterval = 10 + * 1 > 0 + * ] + * } + * + */ +@SuppressWarnings("all") +public class Wait { + /** + * Wait until the provided function evaluates to true. + */ + public static void waitUntil(final Function1 initializer) { + final Wait wait = new Wait(Sleeper.SYSTEM_SLEEPER, Clock.SYSTEM_CLOCK); + final Function0 _function = new Function0() { + @Override + public Boolean apply() { + return initializer.apply(wait); + } + }; + final Function0 condition = _function; + wait.until(condition); + } + + private final Sleeper sleeper; + + private final Clock clock; + + private String message = "Timeout occurred"; + + private long duration = 500l; + + private long pollingInterval = 50l; + + public Wait(final Sleeper sleeper, final Clock clock) { + this.sleeper = sleeper; + this.clock = clock; + } + + public void until(final Function0 condition) { + try { + final long start = this.clock.currentTime(); + while ((!(condition.apply()).booleanValue())) { + { + boolean _timeOut = this.timeOut(start); + if (_timeOut) { + throw new TimeoutError(this.message); + } + this.sleeper.sleep(this.pollingInterval); + } + } + } catch (Throwable _e) { + throw Exceptions.sneakyThrow(_e); + } + } + + public boolean timeOut(final long start) { + long _currentTime = this.clock.currentTime(); + return (_currentTime > (start + this.duration)); + } + + public String setMessage(final String message) { + return this.message = message; + } + + public long setDuration(final long duration) { + return this.duration = duration; + } + + public long setPollingInterval(final long pollingInterval) { + return this.pollingInterval = pollingInterval; + } +} diff --git a/plugins/org.jnario.spec/xtend-gen/org/jnario/spec/doc/SpecDocGenerator.java b/plugins/org.jnario.spec/xtend-gen/org/jnario/spec/doc/SpecDocGenerator.java index c2a860682..18af0b73c 100644 --- a/plugins/org.jnario.spec/xtend-gen/org/jnario/spec/doc/SpecDocGenerator.java +++ b/plugins/org.jnario.spec/xtend-gen/org/jnario/spec/doc/SpecDocGenerator.java @@ -1,313 +1,313 @@ -/** - * Copyright (c) 2012 BMW Car IT and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.jnario.spec.doc; - -import com.google.common.base.Objects; -import com.google.inject.Inject; -import java.util.Arrays; -import java.util.List; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.xtend2.lib.StringConcatenation; -import org.eclipse.xtext.xbase.lib.CollectionLiterals; -import org.eclipse.xtext.xbase.lib.Extension; -import org.eclipse.xtext.xbase.lib.Functions.Function1; -import org.eclipse.xtext.xbase.lib.IterableExtensions; -import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; -import org.jnario.ExampleTable; -import org.jnario.JnarioClass; -import org.jnario.JnarioMember; -import org.jnario.JnarioPackage; -import org.jnario.doc.AbstractDocGenerator; -import org.jnario.doc.Filter; -import org.jnario.doc.FilterExtractor; -import org.jnario.doc.FilteringResult; -import org.jnario.doc.HtmlFile; -import org.jnario.spec.naming.ExampleNameProvider; -import org.jnario.spec.spec.Example; -import org.jnario.spec.spec.ExampleGroup; - -@SuppressWarnings("all") -public class SpecDocGenerator extends AbstractDocGenerator { - @Inject - @Extension - private ExampleNameProvider _exampleNameProvider; - - @Inject - @Extension - private FilterExtractor _filterExtractor; - - @Override - public HtmlFile createHtmlFile(final JnarioClass xtendClass) { - HtmlFile _xblockexpression = null; - { - if ((!(xtendClass instanceof ExampleGroup))) { - return HtmlFile.EMPTY_FILE; - } - final ExampleGroup exampleGroup = ((ExampleGroup) xtendClass); - final Procedure1 _function = (HtmlFile it) -> { - it.setName(this._exampleNameProvider.toJavaClassName(exampleGroup)); - it.setTitle(this.asTitle(exampleGroup)); - it.setContent(this.generateContent(exampleGroup)); - it.setRootFolder(this.root(exampleGroup)); - it.setSourceCode(this.pre(xtendClass.eContainer(), "lang-spec")); - it.setFileName(this.fileName(xtendClass)); - it.setExecutionStatus(this.executionStateClass(exampleGroup)); - }; - _xblockexpression = HtmlFile.newHtmlFile(_function); - } - return _xblockexpression; - } - - private CharSequence generateContent(final ExampleGroup exampleGroup) { - StringConcatenation _builder = new StringConcatenation(); - CharSequence _generateDoc = this.generateDoc(exampleGroup); - _builder.append(_generateDoc); - _builder.newLineIfNotEmpty(); - StringConcatenation _generateMembers = this.generateMembers(exampleGroup, 1); - _builder.append(_generateMembers); - _builder.newLineIfNotEmpty(); - return _builder; - } - - private StringConcatenation generateMembers(final ExampleGroup exampleGroup, final int level) { - final StringConcatenation result = new StringConcatenation(); - boolean inList = false; - final Function1 _function = (JnarioMember it) -> { - return Boolean.valueOf((((it instanceof Example) || (it instanceof ExampleGroup)) || (it instanceof ExampleTable))); - }; - final Iterable members = IterableExtensions.filter(exampleGroup.getMembers(), _function); - for (final JnarioMember member : members) { - { - final boolean isExampleGroup = (member instanceof ExampleGroup); - if ((inList && (!isExampleGroup))) { - result.append("
  • "); - result.append(this.generate(member, level)); - result.append("
  • "); - } else { - if (((!inList) && (!isExampleGroup))) { - result.append("
      "); - result.append("
    • "); - result.append(this.generate(member, level)); - result.append("
    • "); - inList = true; - } else { - if ((inList && isExampleGroup)) { - result.append("
    "); - result.append(this.generate(member, level)); - inList = false; - } else { - if (((!inList) && isExampleGroup)) { - result.append(this.generate(member, level)); - } - } - } - } - } - } - if (inList) { - result.append(""); - } - return result; - } - - private CharSequence generateDoc(final EObject eObject) { - StringConcatenation _builder = new StringConcatenation(); - { - String _documentation = this.documentation(eObject); - boolean _notEquals = (!Objects.equal(_documentation, null)); - if (_notEquals) { - String _markdown2Html = this.markdown2Html(this.documentation(eObject)); - _builder.append(_markdown2Html); - _builder.newLineIfNotEmpty(); - } - } - return _builder; - } - - protected CharSequence _generate(final JnarioMember member, final int level) { - StringConcatenation _builder = new StringConcatenation(); - return _builder; - } - - protected CharSequence _generate(final Example example, final int level) { - CharSequence _xblockexpression = null; - { - String docString = this.documentation(example); - List filters = CollectionLiterals.emptyList(); - boolean _notEquals = (!Objects.equal(docString, null)); - if (_notEquals) { - final FilteringResult filterResult = this._filterExtractor.apply(docString); - filters = filterResult.getFilters(); - docString = filterResult.getString(); - docString = this.markdown2Html(docString); - } - StringConcatenation _builder = new StringConcatenation(); - { - String _name = example.getName(); - boolean _notEquals_1 = (!Objects.equal(_name, null)); - if (_notEquals_1) { - _builder.append(""); - String _decode = this.decode(this._exampleNameProvider.describe(example)); - _builder.append(_decode); - _builder.append("

    "); - _builder.newLineIfNotEmpty(); - } - } - _builder.append(docString); - _builder.newLineIfNotEmpty(); - { - if (((!example.isPending()) && example.eIsSet(JnarioPackage.Literals.JNARIO_FUNCTION__EXPRESSION))) { - CharSequence _codeBlock = this.toCodeBlock(example, filters); - _builder.append(_codeBlock); - _builder.newLineIfNotEmpty(); - } - } - String _errorMessage = this.errorMessage(example); - _builder.append(_errorMessage); - _builder.newLineIfNotEmpty(); - _xblockexpression = _builder; - } - return _xblockexpression; - } - - public CharSequence toCodeBlock(final Example example, final List filters) { - CharSequence _xblockexpression = null; - { - String prefix = "
    ";
    -      prefix = this.apply(filters, prefix);
    -      final String code = this.serialize(example.getExpression(), filters);
    -      int _length = code.length();
    -      boolean _equals = (_length == 0);
    -      if (_equals) {
    -        return "";
    -      }
    -      StringConcatenation _builder = new StringConcatenation();
    -      _builder.append(prefix);
    -      _builder.newLineIfNotEmpty();
    -      _builder.append(code);
    -      _builder.append("
    "); - _xblockexpression = _builder; - } - return _xblockexpression; - } - - protected CharSequence _generate(final ExampleTable table, final int level) { - StringConcatenation _builder = new StringConcatenation(); - _builder.append(""); - String _title = this.toTitle(this._exampleNameProvider.toFieldName(table)); - _builder.append(_title); - _builder.append("

    "); - _builder.newLineIfNotEmpty(); - CharSequence _generateDoc = this.generateDoc(table); - _builder.append(_generateDoc); - _builder.newLineIfNotEmpty(); - CharSequence _generate = super.generate(table); - _builder.append(_generate); - _builder.newLineIfNotEmpty(); - return _builder; - } - - protected CharSequence _generate(final ExampleGroup exampleGroup, final int level) { - StringConcatenation _builder = new StringConcatenation(); - { - if ((level > 1)) { - _builder.append("
    "); - _builder.newLine(); - } - } - _builder.append(""); - String _asTitle = this.asTitle(exampleGroup); - _builder.append(_asTitle); - _builder.append(""); - _builder.newLineIfNotEmpty(); - CharSequence _generateDoc = this.generateDoc(exampleGroup); - _builder.append(_generateDoc); - _builder.newLineIfNotEmpty(); - StringConcatenation _generateMembers = this.generateMembers(exampleGroup, (level + 1)); - _builder.append(_generateMembers); - _builder.newLineIfNotEmpty(); - { - if ((level > 1)) { - _builder.append("
    "); - _builder.newLine(); - } - } - return _builder; - } - - private String header(final ExampleGroup exampleGroup, final int level) { - String _xifexpression = null; - if ((level <= 1)) { - _xifexpression = "3"; - } else { - String _xifexpression_1 = null; - if ((level == 2)) { - _xifexpression_1 = "4"; - } else { - _xifexpression_1 = "5"; - } - _xifexpression = _xifexpression_1; - } - return _xifexpression; - } - - protected String _asTitle(final ExampleGroup exampleGroup) { - return this.toTitle(this._exampleNameProvider.describe(exampleGroup)); - } - - protected String _asTitle(final Example example) { - return this.toTitle(this._exampleNameProvider.describe(example)); - } - - public CharSequence generate(final JnarioMember exampleGroup, final int level) { - if (exampleGroup instanceof ExampleGroup) { - return _generate((ExampleGroup)exampleGroup, level); - } else if (exampleGroup instanceof Example) { - return _generate((Example)exampleGroup, level); - } else if (exampleGroup instanceof ExampleTable) { - return _generate((ExampleTable)exampleGroup, level); - } else if (exampleGroup != null) { - return _generate(exampleGroup, level); - } else { - throw new IllegalArgumentException("Unhandled parameter types: " + - Arrays.asList(exampleGroup, level).toString()); - } - } - - public String asTitle(final EObject exampleGroup) { - if (exampleGroup instanceof ExampleGroup) { - return _asTitle((ExampleGroup)exampleGroup); - } else if (exampleGroup instanceof Example) { - return _asTitle((Example)exampleGroup); - } else { - throw new IllegalArgumentException("Unhandled parameter types: " + - Arrays.asList(exampleGroup).toString()); - } - } -} +/** + * Copyright (c) 2012 BMW Car IT and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.jnario.spec.doc; + +import com.google.common.base.Objects; +import com.google.inject.Inject; +import java.util.Arrays; +import java.util.List; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.xtend2.lib.StringConcatenation; +import org.eclipse.xtext.xbase.lib.CollectionLiterals; +import org.eclipse.xtext.xbase.lib.Extension; +import org.eclipse.xtext.xbase.lib.Functions.Function1; +import org.eclipse.xtext.xbase.lib.IterableExtensions; +import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; +import org.jnario.ExampleTable; +import org.jnario.JnarioClass; +import org.jnario.JnarioMember; +import org.jnario.JnarioPackage; +import org.jnario.doc.AbstractDocGenerator; +import org.jnario.doc.Filter; +import org.jnario.doc.FilterExtractor; +import org.jnario.doc.FilteringResult; +import org.jnario.doc.HtmlFile; +import org.jnario.spec.naming.ExampleNameProvider; +import org.jnario.spec.spec.Example; +import org.jnario.spec.spec.ExampleGroup; + +@SuppressWarnings("all") +public class SpecDocGenerator extends AbstractDocGenerator { + @Inject + @Extension + private ExampleNameProvider _exampleNameProvider; + + @Inject + @Extension + private FilterExtractor _filterExtractor; + + @Override + public HtmlFile createHtmlFile(final JnarioClass xtendClass) { + HtmlFile _xblockexpression = null; + { + if ((!(xtendClass instanceof ExampleGroup))) { + return HtmlFile.EMPTY_FILE; + } + final ExampleGroup exampleGroup = ((ExampleGroup) xtendClass); + final Procedure1 _function = (HtmlFile it) -> { + it.setName(this._exampleNameProvider.toJavaClassName(exampleGroup)); + it.setTitle(this.asTitle(exampleGroup)); + it.setContent(this.generateContent(exampleGroup)); + it.setRootFolder(this.root(exampleGroup)); + it.setSourceCode(this.pre(xtendClass.eContainer(), "lang-spec")); + it.setFileName(this.fileName(xtendClass)); + it.setExecutionStatus(this.executionStateClass(exampleGroup)); + }; + _xblockexpression = HtmlFile.newHtmlFile(_function); + } + return _xblockexpression; + } + + private CharSequence generateContent(final ExampleGroup exampleGroup) { + StringConcatenation _builder = new StringConcatenation(); + CharSequence _generateDoc = this.generateDoc(exampleGroup); + _builder.append(_generateDoc); + _builder.newLineIfNotEmpty(); + StringConcatenation _generateMembers = this.generateMembers(exampleGroup, 1); + _builder.append(_generateMembers); + _builder.newLineIfNotEmpty(); + return _builder; + } + + private StringConcatenation generateMembers(final ExampleGroup exampleGroup, final int level) { + final StringConcatenation result = new StringConcatenation(); + boolean inList = false; + final Function1 _function = (JnarioMember it) -> { + return Boolean.valueOf((((it instanceof Example) || (it instanceof ExampleGroup)) || (it instanceof ExampleTable))); + }; + final Iterable members = IterableExtensions.filter(exampleGroup.getMembers(), _function); + for (final JnarioMember member : members) { + { + final boolean isExampleGroup = (member instanceof ExampleGroup); + if ((inList && (!isExampleGroup))) { + result.append("
  • "); + result.append(this.generate(member, level)); + result.append("
  • "); + } else { + if (((!inList) && (!isExampleGroup))) { + result.append("
      "); + result.append("
    • "); + result.append(this.generate(member, level)); + result.append("
    • "); + inList = true; + } else { + if ((inList && isExampleGroup)) { + result.append("
    "); + result.append(this.generate(member, level)); + inList = false; + } else { + if (((!inList) && isExampleGroup)) { + result.append(this.generate(member, level)); + } + } + } + } + } + } + if (inList) { + result.append(""); + } + return result; + } + + private CharSequence generateDoc(final EObject eObject) { + StringConcatenation _builder = new StringConcatenation(); + { + String _documentation = this.documentation(eObject); + boolean _notEquals = (!Objects.equal(_documentation, null)); + if (_notEquals) { + String _markdown2Html = this.markdown2Html(this.documentation(eObject)); + _builder.append(_markdown2Html); + _builder.newLineIfNotEmpty(); + } + } + return _builder; + } + + protected CharSequence _generate(final JnarioMember member, final int level) { + StringConcatenation _builder = new StringConcatenation(); + return _builder; + } + + protected CharSequence _generate(final Example example, final int level) { + CharSequence _xblockexpression = null; + { + String docString = this.documentation(example); + List filters = CollectionLiterals.emptyList(); + boolean _notEquals = (!Objects.equal(docString, null)); + if (_notEquals) { + final FilteringResult filterResult = this._filterExtractor.apply(docString); + filters = filterResult.getFilters(); + docString = filterResult.getString(); + docString = this.markdown2Html(docString); + } + StringConcatenation _builder = new StringConcatenation(); + { + String _name = example.getName(); + boolean _notEquals_1 = (!Objects.equal(_name, null)); + if (_notEquals_1) { + _builder.append(""); + String _decode = this.decode(this._exampleNameProvider.describe(example)); + _builder.append(_decode); + _builder.append("

    "); + _builder.newLineIfNotEmpty(); + } + } + _builder.append(docString); + _builder.newLineIfNotEmpty(); + { + if (((!example.isPending()) && example.eIsSet(JnarioPackage.Literals.JNARIO_FUNCTION__EXPRESSION))) { + CharSequence _codeBlock = this.toCodeBlock(example, filters); + _builder.append(_codeBlock); + _builder.newLineIfNotEmpty(); + } + } + String _errorMessage = this.errorMessage(example); + _builder.append(_errorMessage); + _builder.newLineIfNotEmpty(); + _xblockexpression = _builder; + } + return _xblockexpression; + } + + public CharSequence toCodeBlock(final Example example, final List filters) { + CharSequence _xblockexpression = null; + { + String prefix = "
    ";
    +      prefix = this.apply(filters, prefix);
    +      final String code = this.serialize(example.getExpression(), filters);
    +      int _length = code.length();
    +      boolean _equals = (_length == 0);
    +      if (_equals) {
    +        return "";
    +      }
    +      StringConcatenation _builder = new StringConcatenation();
    +      _builder.append(prefix);
    +      _builder.newLineIfNotEmpty();
    +      _builder.append(code);
    +      _builder.append("
    "); + _xblockexpression = _builder; + } + return _xblockexpression; + } + + protected CharSequence _generate(final ExampleTable table, final int level) { + StringConcatenation _builder = new StringConcatenation(); + _builder.append(""); + String _title = this.toTitle(this._exampleNameProvider.toFieldName(table)); + _builder.append(_title); + _builder.append("

    "); + _builder.newLineIfNotEmpty(); + CharSequence _generateDoc = this.generateDoc(table); + _builder.append(_generateDoc); + _builder.newLineIfNotEmpty(); + CharSequence _generate = super.generate(table); + _builder.append(_generate); + _builder.newLineIfNotEmpty(); + return _builder; + } + + protected CharSequence _generate(final ExampleGroup exampleGroup, final int level) { + StringConcatenation _builder = new StringConcatenation(); + { + if ((level > 1)) { + _builder.append("
    "); + _builder.newLine(); + } + } + _builder.append(""); + String _asTitle = this.asTitle(exampleGroup); + _builder.append(_asTitle); + _builder.append(""); + _builder.newLineIfNotEmpty(); + CharSequence _generateDoc = this.generateDoc(exampleGroup); + _builder.append(_generateDoc); + _builder.newLineIfNotEmpty(); + StringConcatenation _generateMembers = this.generateMembers(exampleGroup, (level + 1)); + _builder.append(_generateMembers); + _builder.newLineIfNotEmpty(); + { + if ((level > 1)) { + _builder.append("
    "); + _builder.newLine(); + } + } + return _builder; + } + + private String header(final ExampleGroup exampleGroup, final int level) { + String _xifexpression = null; + if ((level <= 1)) { + _xifexpression = "3"; + } else { + String _xifexpression_1 = null; + if ((level == 2)) { + _xifexpression_1 = "4"; + } else { + _xifexpression_1 = "5"; + } + _xifexpression = _xifexpression_1; + } + return _xifexpression; + } + + protected String _asTitle(final ExampleGroup exampleGroup) { + return this.toTitle(this._exampleNameProvider.describe(exampleGroup)); + } + + protected String _asTitle(final Example example) { + return this.toTitle(this._exampleNameProvider.describe(example)); + } + + public CharSequence generate(final JnarioMember exampleGroup, final int level) { + if (exampleGroup instanceof ExampleGroup) { + return _generate((ExampleGroup)exampleGroup, level); + } else if (exampleGroup instanceof Example) { + return _generate((Example)exampleGroup, level); + } else if (exampleGroup instanceof ExampleTable) { + return _generate((ExampleTable)exampleGroup, level); + } else if (exampleGroup != null) { + return _generate(exampleGroup, level); + } else { + throw new IllegalArgumentException("Unhandled parameter types: " + + Arrays.asList(exampleGroup, level).toString()); + } + } + + public String asTitle(final EObject exampleGroup) { + if (exampleGroup instanceof ExampleGroup) { + return _asTitle((ExampleGroup)exampleGroup); + } else if (exampleGroup instanceof Example) { + return _asTitle((Example)exampleGroup); + } else { + throw new IllegalArgumentException("Unhandled parameter types: " + + Arrays.asList(exampleGroup).toString()); + } + } +} diff --git a/plugins/org.jnario.spec/xtend-gen/org/jnario/spec/formatting2/SpecFormatter.java b/plugins/org.jnario.spec/xtend-gen/org/jnario/spec/formatting2/SpecFormatter.java index d4a87e451..0bdb78641 100644 --- a/plugins/org.jnario.spec/xtend-gen/org/jnario/spec/formatting2/SpecFormatter.java +++ b/plugins/org.jnario.spec/xtend-gen/org/jnario/spec/formatting2/SpecFormatter.java @@ -1,360 +1,360 @@ -/** - * generated by Xtext - */ -package org.jnario.spec.formatting2; - -import java.util.Arrays; -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.xtext.common.types.JvmFormalParameter; -import org.eclipse.xtext.common.types.JvmGenericArrayTypeReference; -import org.eclipse.xtext.common.types.JvmParameterizedTypeReference; -import org.eclipse.xtext.common.types.JvmTypeConstraint; -import org.eclipse.xtext.common.types.JvmTypeParameter; -import org.eclipse.xtext.common.types.JvmTypeReference; -import org.eclipse.xtext.common.types.JvmWildcardTypeReference; -import org.eclipse.xtext.formatting2.IFormattableDocument; -import org.eclipse.xtext.formatting2.IHiddenRegionFormatter; -import org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion; -import org.eclipse.xtext.resource.XtextResource; -import org.eclipse.xtext.xbase.XAssignment; -import org.eclipse.xtext.xbase.XBasicForLoopExpression; -import org.eclipse.xtext.xbase.XBinaryOperation; -import org.eclipse.xtext.xbase.XBlockExpression; -import org.eclipse.xtext.xbase.XCastedExpression; -import org.eclipse.xtext.xbase.XClosure; -import org.eclipse.xtext.xbase.XCollectionLiteral; -import org.eclipse.xtext.xbase.XConstructorCall; -import org.eclipse.xtext.xbase.XDoWhileExpression; -import org.eclipse.xtext.xbase.XExpression; -import org.eclipse.xtext.xbase.XFeatureCall; -import org.eclipse.xtext.xbase.XForLoopExpression; -import org.eclipse.xtext.xbase.XIfExpression; -import org.eclipse.xtext.xbase.XInstanceOfExpression; -import org.eclipse.xtext.xbase.XMemberFeatureCall; -import org.eclipse.xtext.xbase.XPostfixOperation; -import org.eclipse.xtext.xbase.XReturnExpression; -import org.eclipse.xtext.xbase.XSwitchExpression; -import org.eclipse.xtext.xbase.XSynchronizedExpression; -import org.eclipse.xtext.xbase.XThrowExpression; -import org.eclipse.xtext.xbase.XTryCatchFinallyExpression; -import org.eclipse.xtext.xbase.XTypeLiteral; -import org.eclipse.xtext.xbase.XVariableDeclaration; -import org.eclipse.xtext.xbase.XWhileExpression; -import org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation; -import org.eclipse.xtext.xbase.lib.Extension; -import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; -import org.eclipse.xtext.xtype.XFunctionTypeRef; -import org.eclipse.xtext.xtype.XImportDeclaration; -import org.eclipse.xtext.xtype.XImportSection; -import org.jnario.Assertion; -import org.jnario.ExampleCell; -import org.jnario.ExampleColumn; -import org.jnario.ExampleRow; -import org.jnario.JnarioField; -import org.jnario.JnarioFunction; -import org.jnario.JnarioMember; -import org.jnario.JnarioParameter; -import org.jnario.JnarioTypeDeclaration; -import org.jnario.Should; -import org.jnario.ShouldThrow; -import org.jnario.formatter.JnarioFormatter; -import org.jnario.spec.spec.After; -import org.jnario.spec.spec.Before; -import org.jnario.spec.spec.Example; -import org.jnario.spec.spec.ExampleGroup; -import org.jnario.spec.spec.SpecFile; - -@SuppressWarnings("all") -public class SpecFormatter extends JnarioFormatter { - protected void _format(final SpecFile specfile, @Extension final IFormattableDocument document) { - this.format(specfile.getImportSection(), document); - EList _xtendTypes = specfile.getXtendTypes(); - for (final JnarioTypeDeclaration xtendTypes : _xtendTypes) { - this.format(xtendTypes, document); - } - } - - protected void _format(final ExampleGroup examplegroup, @Extension final IFormattableDocument document) { - final Procedure1 _function = (IHiddenRegionFormatter it) -> { - it.setNewLines(1, 1, 2); - }; - final ISemanticRegion open = document.append(this.textRegionExtensions.regionFor(examplegroup).keyword("{"), _function); - final Procedure1 _function_1 = (IHiddenRegionFormatter it) -> { - it.newLine(); - }; - final ISemanticRegion close = document.prepend(this.textRegionExtensions.regionFor(examplegroup).keyword("}"), _function_1); - final Procedure1 _function_2 = (IHiddenRegionFormatter it) -> { - it.indent(); - }; - document.interior(open, close, _function_2); - this.format(examplegroup.getTargetType(), document); - EList _members = examplegroup.getMembers(); - for (final JnarioMember members : _members) { - this.format(members, document); - } - this.format(examplegroup.getAnnotationInfo(), document); - } - - protected void _format(final JnarioMember jnariomember, @Extension final IFormattableDocument document) { - EList _annotations = jnariomember.getAnnotations(); - for (final XAnnotation annotations : _annotations) { - this.format(annotations, document); - } - } - - protected void _format(final Example example, @Extension final IFormattableDocument document) { - this.format(example.getExpr(), document); - this.format(example.getExpression(), document); - this.format(example.getAnnotationInfo(), document); - } - - protected void _format(final Before before, @Extension final IFormattableDocument document) { - this.format(before.getExpression(), document); - this.format(before.getAnnotationInfo(), document); - } - - protected void _format(final After after, @Extension final IFormattableDocument document) { - this.format(after.getExpression(), document); - this.format(after.getAnnotationInfo(), document); - } - - protected void _format(final JnarioField jnariofield, @Extension final IFormattableDocument document) { - this.format(jnariofield.getType(), document); - this.format(jnariofield.getInitialValue(), document); - this.format(jnariofield.getAnnotationInfo(), document); - } - - protected void _format(final JnarioFunction jnariofunction, @Extension final IFormattableDocument document) { - EList _typeParameters = jnariofunction.getTypeParameters(); - for (final JvmTypeParameter typeParameters : _typeParameters) { - this.format(typeParameters, document); - } - this.format(jnariofunction.getReturnType(), document); - EList _parameters = jnariofunction.getParameters(); - for (final JnarioParameter parameters : _parameters) { - this.format(parameters, document); - } - EList _exceptions = jnariofunction.getExceptions(); - for (final JvmTypeReference exceptions : _exceptions) { - this.format(exceptions, document); - } - this.format(jnariofunction.getExpression(), document); - this.format(jnariofunction.getAnnotationInfo(), document); - } - - protected void _format(final Should should, @Extension final IFormattableDocument document) { - this.format(should.getRightOperand(), document); - this.format(should.getLeftOperand(), document); - } - - protected void _format(final ShouldThrow shouldthrow, @Extension final IFormattableDocument document) { - this.format(shouldthrow.getType(), document); - this.format(shouldthrow.getExpression(), document); - } - - @Override - protected void _format(final XInstanceOfExpression xinstanceofexpression, @Extension final IFormattableDocument document) { - this.format(xinstanceofexpression.getType(), document); - this.format(xinstanceofexpression.getExpression(), document); - } - - @Override - protected void _format(final XBinaryOperation xbinaryoperation, @Extension final IFormattableDocument document) { - this.format(xbinaryoperation.getRightOperand(), document); - this.format(xbinaryoperation.getLeftOperand(), document); - } - - protected void _format(final Assertion assertion, @Extension final IFormattableDocument document) { - this.format(assertion.getExpression(), document); - } - - protected void _format(final ExampleColumn examplecolumn, @Extension final IFormattableDocument document) { - this.format(examplecolumn.getType(), document); - } - - protected void _format(final ExampleRow examplerow, @Extension final IFormattableDocument document) { - EList _cells = examplerow.getCells(); - for (final ExampleCell cells : _cells) { - this.format(cells, document); - } - } - - protected void _format(final ExampleCell examplecell, @Extension final IFormattableDocument document) { - this.format(examplecell.getExpression(), document); - } - - protected void _format(final JnarioParameter jnarioparameter, @Extension final IFormattableDocument document) { - EList _annotations = jnarioparameter.getAnnotations(); - for (final XAnnotation annotations : _annotations) { - this.format(annotations, document); - } - this.format(jnarioparameter.getParameterType(), document); - } - - public void format(final Object examplegroup, final IFormattableDocument document) { - if (examplegroup instanceof ExampleGroup) { - _format((ExampleGroup)examplegroup, document); - return; - } else if (examplegroup instanceof After) { - _format((After)examplegroup, document); - return; - } else if (examplegroup instanceof Before) { - _format((Before)examplegroup, document); - return; - } else if (examplegroup instanceof Example) { - _format((Example)examplegroup, document); - return; - } else if (examplegroup instanceof JvmTypeParameter) { - _format((JvmTypeParameter)examplegroup, document); - return; - } else if (examplegroup instanceof ExampleCell) { - _format((ExampleCell)examplegroup, document); - return; - } else if (examplegroup instanceof Should) { - _format((Should)examplegroup, document); - return; - } else if (examplegroup instanceof JvmFormalParameter) { - _format((JvmFormalParameter)examplegroup, document); - return; - } else if (examplegroup instanceof XtextResource) { - _format((XtextResource)examplegroup, document); - return; - } else if (examplegroup instanceof XAssignment) { - _format((XAssignment)examplegroup, document); - return; - } else if (examplegroup instanceof XBinaryOperation) { - _format((XBinaryOperation)examplegroup, document); - return; - } else if (examplegroup instanceof XDoWhileExpression) { - _format((XDoWhileExpression)examplegroup, document); - return; - } else if (examplegroup instanceof XFeatureCall) { - _format((XFeatureCall)examplegroup, document); - return; - } else if (examplegroup instanceof XMemberFeatureCall) { - _format((XMemberFeatureCall)examplegroup, document); - return; - } else if (examplegroup instanceof XPostfixOperation) { - _format((XPostfixOperation)examplegroup, document); - return; - } else if (examplegroup instanceof XWhileExpression) { - _format((XWhileExpression)examplegroup, document); - return; - } else if (examplegroup instanceof XFunctionTypeRef) { - _format((XFunctionTypeRef)examplegroup, document); - return; - } else if (examplegroup instanceof JnarioField) { - _format((JnarioField)examplegroup, document); - return; - } else if (examplegroup instanceof JnarioFunction) { - _format((JnarioFunction)examplegroup, document); - return; - } else if (examplegroup instanceof JvmGenericArrayTypeReference) { - _format((JvmGenericArrayTypeReference)examplegroup, document); - return; - } else if (examplegroup instanceof JvmParameterizedTypeReference) { - _format((JvmParameterizedTypeReference)examplegroup, document); - return; - } else if (examplegroup instanceof JvmWildcardTypeReference) { - _format((JvmWildcardTypeReference)examplegroup, document); - return; - } else if (examplegroup instanceof XBasicForLoopExpression) { - _format((XBasicForLoopExpression)examplegroup, document); - return; - } else if (examplegroup instanceof XBlockExpression) { - _format((XBlockExpression)examplegroup, document); - return; - } else if (examplegroup instanceof XCastedExpression) { - _format((XCastedExpression)examplegroup, document); - return; - } else if (examplegroup instanceof XClosure) { - _format((XClosure)examplegroup, document); - return; - } else if (examplegroup instanceof XCollectionLiteral) { - _format((XCollectionLiteral)examplegroup, document); - return; - } else if (examplegroup instanceof XConstructorCall) { - _format((XConstructorCall)examplegroup, document); - return; - } else if (examplegroup instanceof XForLoopExpression) { - _format((XForLoopExpression)examplegroup, document); - return; - } else if (examplegroup instanceof XIfExpression) { - _format((XIfExpression)examplegroup, document); - return; - } else if (examplegroup instanceof XInstanceOfExpression) { - _format((XInstanceOfExpression)examplegroup, document); - return; - } else if (examplegroup instanceof XReturnExpression) { - _format((XReturnExpression)examplegroup, document); - return; - } else if (examplegroup instanceof XSwitchExpression) { - _format((XSwitchExpression)examplegroup, document); - return; - } else if (examplegroup instanceof XSynchronizedExpression) { - _format((XSynchronizedExpression)examplegroup, document); - return; - } else if (examplegroup instanceof XThrowExpression) { - _format((XThrowExpression)examplegroup, document); - return; - } else if (examplegroup instanceof XTryCatchFinallyExpression) { - _format((XTryCatchFinallyExpression)examplegroup, document); - return; - } else if (examplegroup instanceof XTypeLiteral) { - _format((XTypeLiteral)examplegroup, document); - return; - } else if (examplegroup instanceof XVariableDeclaration) { - _format((XVariableDeclaration)examplegroup, document); - return; - } else if (examplegroup instanceof XAnnotation) { - _format((XAnnotation)examplegroup, document); - return; - } else if (examplegroup instanceof Assertion) { - _format((Assertion)examplegroup, document); - return; - } else if (examplegroup instanceof JnarioMember) { - _format((JnarioMember)examplegroup, document); - return; - } else if (examplegroup instanceof JnarioParameter) { - _format((JnarioParameter)examplegroup, document); - return; - } else if (examplegroup instanceof ShouldThrow) { - _format((ShouldThrow)examplegroup, document); - return; - } else if (examplegroup instanceof SpecFile) { - _format((SpecFile)examplegroup, document); - return; - } else if (examplegroup instanceof JvmTypeConstraint) { - _format((JvmTypeConstraint)examplegroup, document); - return; - } else if (examplegroup instanceof XExpression) { - _format((XExpression)examplegroup, document); - return; - } else if (examplegroup instanceof XImportDeclaration) { - _format((XImportDeclaration)examplegroup, document); - return; - } else if (examplegroup instanceof XImportSection) { - _format((XImportSection)examplegroup, document); - return; - } else if (examplegroup instanceof ExampleColumn) { - _format((ExampleColumn)examplegroup, document); - return; - } else if (examplegroup instanceof ExampleRow) { - _format((ExampleRow)examplegroup, document); - return; - } else if (examplegroup instanceof EObject) { - _format((EObject)examplegroup, document); - return; - } else if (examplegroup == null) { - _format((Void)null, document); - return; - } else if (examplegroup != null) { - _format(examplegroup, document); - return; - } else { - throw new IllegalArgumentException("Unhandled parameter types: " + - Arrays.asList(examplegroup, document).toString()); - } - } -} +/** + * generated by Xtext + */ +package org.jnario.spec.formatting2; + +import java.util.Arrays; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.xtext.common.types.JvmFormalParameter; +import org.eclipse.xtext.common.types.JvmGenericArrayTypeReference; +import org.eclipse.xtext.common.types.JvmParameterizedTypeReference; +import org.eclipse.xtext.common.types.JvmTypeConstraint; +import org.eclipse.xtext.common.types.JvmTypeParameter; +import org.eclipse.xtext.common.types.JvmTypeReference; +import org.eclipse.xtext.common.types.JvmWildcardTypeReference; +import org.eclipse.xtext.formatting2.IFormattableDocument; +import org.eclipse.xtext.formatting2.IHiddenRegionFormatter; +import org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion; +import org.eclipse.xtext.resource.XtextResource; +import org.eclipse.xtext.xbase.XAssignment; +import org.eclipse.xtext.xbase.XBasicForLoopExpression; +import org.eclipse.xtext.xbase.XBinaryOperation; +import org.eclipse.xtext.xbase.XBlockExpression; +import org.eclipse.xtext.xbase.XCastedExpression; +import org.eclipse.xtext.xbase.XClosure; +import org.eclipse.xtext.xbase.XCollectionLiteral; +import org.eclipse.xtext.xbase.XConstructorCall; +import org.eclipse.xtext.xbase.XDoWhileExpression; +import org.eclipse.xtext.xbase.XExpression; +import org.eclipse.xtext.xbase.XFeatureCall; +import org.eclipse.xtext.xbase.XForLoopExpression; +import org.eclipse.xtext.xbase.XIfExpression; +import org.eclipse.xtext.xbase.XInstanceOfExpression; +import org.eclipse.xtext.xbase.XMemberFeatureCall; +import org.eclipse.xtext.xbase.XPostfixOperation; +import org.eclipse.xtext.xbase.XReturnExpression; +import org.eclipse.xtext.xbase.XSwitchExpression; +import org.eclipse.xtext.xbase.XSynchronizedExpression; +import org.eclipse.xtext.xbase.XThrowExpression; +import org.eclipse.xtext.xbase.XTryCatchFinallyExpression; +import org.eclipse.xtext.xbase.XTypeLiteral; +import org.eclipse.xtext.xbase.XVariableDeclaration; +import org.eclipse.xtext.xbase.XWhileExpression; +import org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation; +import org.eclipse.xtext.xbase.lib.Extension; +import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; +import org.eclipse.xtext.xtype.XFunctionTypeRef; +import org.eclipse.xtext.xtype.XImportDeclaration; +import org.eclipse.xtext.xtype.XImportSection; +import org.jnario.Assertion; +import org.jnario.ExampleCell; +import org.jnario.ExampleColumn; +import org.jnario.ExampleRow; +import org.jnario.JnarioField; +import org.jnario.JnarioFunction; +import org.jnario.JnarioMember; +import org.jnario.JnarioParameter; +import org.jnario.JnarioTypeDeclaration; +import org.jnario.Should; +import org.jnario.ShouldThrow; +import org.jnario.formatter.JnarioFormatter; +import org.jnario.spec.spec.After; +import org.jnario.spec.spec.Before; +import org.jnario.spec.spec.Example; +import org.jnario.spec.spec.ExampleGroup; +import org.jnario.spec.spec.SpecFile; + +@SuppressWarnings("all") +public class SpecFormatter extends JnarioFormatter { + protected void _format(final SpecFile specfile, @Extension final IFormattableDocument document) { + this.format(specfile.getImportSection(), document); + EList _xtendTypes = specfile.getXtendTypes(); + for (final JnarioTypeDeclaration xtendTypes : _xtendTypes) { + this.format(xtendTypes, document); + } + } + + protected void _format(final ExampleGroup examplegroup, @Extension final IFormattableDocument document) { + final Procedure1 _function = (IHiddenRegionFormatter it) -> { + it.setNewLines(1, 1, 2); + }; + final ISemanticRegion open = document.append(this.textRegionExtensions.regionFor(examplegroup).keyword("{"), _function); + final Procedure1 _function_1 = (IHiddenRegionFormatter it) -> { + it.newLine(); + }; + final ISemanticRegion close = document.prepend(this.textRegionExtensions.regionFor(examplegroup).keyword("}"), _function_1); + final Procedure1 _function_2 = (IHiddenRegionFormatter it) -> { + it.indent(); + }; + document.interior(open, close, _function_2); + this.format(examplegroup.getTargetType(), document); + EList _members = examplegroup.getMembers(); + for (final JnarioMember members : _members) { + this.format(members, document); + } + this.format(examplegroup.getAnnotationInfo(), document); + } + + protected void _format(final JnarioMember jnariomember, @Extension final IFormattableDocument document) { + EList _annotations = jnariomember.getAnnotations(); + for (final XAnnotation annotations : _annotations) { + this.format(annotations, document); + } + } + + protected void _format(final Example example, @Extension final IFormattableDocument document) { + this.format(example.getExpr(), document); + this.format(example.getExpression(), document); + this.format(example.getAnnotationInfo(), document); + } + + protected void _format(final Before before, @Extension final IFormattableDocument document) { + this.format(before.getExpression(), document); + this.format(before.getAnnotationInfo(), document); + } + + protected void _format(final After after, @Extension final IFormattableDocument document) { + this.format(after.getExpression(), document); + this.format(after.getAnnotationInfo(), document); + } + + protected void _format(final JnarioField jnariofield, @Extension final IFormattableDocument document) { + this.format(jnariofield.getType(), document); + this.format(jnariofield.getInitialValue(), document); + this.format(jnariofield.getAnnotationInfo(), document); + } + + protected void _format(final JnarioFunction jnariofunction, @Extension final IFormattableDocument document) { + EList _typeParameters = jnariofunction.getTypeParameters(); + for (final JvmTypeParameter typeParameters : _typeParameters) { + this.format(typeParameters, document); + } + this.format(jnariofunction.getReturnType(), document); + EList _parameters = jnariofunction.getParameters(); + for (final JnarioParameter parameters : _parameters) { + this.format(parameters, document); + } + EList _exceptions = jnariofunction.getExceptions(); + for (final JvmTypeReference exceptions : _exceptions) { + this.format(exceptions, document); + } + this.format(jnariofunction.getExpression(), document); + this.format(jnariofunction.getAnnotationInfo(), document); + } + + protected void _format(final Should should, @Extension final IFormattableDocument document) { + this.format(should.getRightOperand(), document); + this.format(should.getLeftOperand(), document); + } + + protected void _format(final ShouldThrow shouldthrow, @Extension final IFormattableDocument document) { + this.format(shouldthrow.getType(), document); + this.format(shouldthrow.getExpression(), document); + } + + @Override + protected void _format(final XInstanceOfExpression xinstanceofexpression, @Extension final IFormattableDocument document) { + this.format(xinstanceofexpression.getType(), document); + this.format(xinstanceofexpression.getExpression(), document); + } + + @Override + protected void _format(final XBinaryOperation xbinaryoperation, @Extension final IFormattableDocument document) { + this.format(xbinaryoperation.getRightOperand(), document); + this.format(xbinaryoperation.getLeftOperand(), document); + } + + protected void _format(final Assertion assertion, @Extension final IFormattableDocument document) { + this.format(assertion.getExpression(), document); + } + + protected void _format(final ExampleColumn examplecolumn, @Extension final IFormattableDocument document) { + this.format(examplecolumn.getType(), document); + } + + protected void _format(final ExampleRow examplerow, @Extension final IFormattableDocument document) { + EList _cells = examplerow.getCells(); + for (final ExampleCell cells : _cells) { + this.format(cells, document); + } + } + + protected void _format(final ExampleCell examplecell, @Extension final IFormattableDocument document) { + this.format(examplecell.getExpression(), document); + } + + protected void _format(final JnarioParameter jnarioparameter, @Extension final IFormattableDocument document) { + EList _annotations = jnarioparameter.getAnnotations(); + for (final XAnnotation annotations : _annotations) { + this.format(annotations, document); + } + this.format(jnarioparameter.getParameterType(), document); + } + + public void format(final Object examplegroup, final IFormattableDocument document) { + if (examplegroup instanceof ExampleGroup) { + _format((ExampleGroup)examplegroup, document); + return; + } else if (examplegroup instanceof After) { + _format((After)examplegroup, document); + return; + } else if (examplegroup instanceof Before) { + _format((Before)examplegroup, document); + return; + } else if (examplegroup instanceof Example) { + _format((Example)examplegroup, document); + return; + } else if (examplegroup instanceof JvmTypeParameter) { + _format((JvmTypeParameter)examplegroup, document); + return; + } else if (examplegroup instanceof ExampleCell) { + _format((ExampleCell)examplegroup, document); + return; + } else if (examplegroup instanceof Should) { + _format((Should)examplegroup, document); + return; + } else if (examplegroup instanceof JvmFormalParameter) { + _format((JvmFormalParameter)examplegroup, document); + return; + } else if (examplegroup instanceof XtextResource) { + _format((XtextResource)examplegroup, document); + return; + } else if (examplegroup instanceof XAssignment) { + _format((XAssignment)examplegroup, document); + return; + } else if (examplegroup instanceof XBinaryOperation) { + _format((XBinaryOperation)examplegroup, document); + return; + } else if (examplegroup instanceof XDoWhileExpression) { + _format((XDoWhileExpression)examplegroup, document); + return; + } else if (examplegroup instanceof XFeatureCall) { + _format((XFeatureCall)examplegroup, document); + return; + } else if (examplegroup instanceof XMemberFeatureCall) { + _format((XMemberFeatureCall)examplegroup, document); + return; + } else if (examplegroup instanceof XPostfixOperation) { + _format((XPostfixOperation)examplegroup, document); + return; + } else if (examplegroup instanceof XWhileExpression) { + _format((XWhileExpression)examplegroup, document); + return; + } else if (examplegroup instanceof XFunctionTypeRef) { + _format((XFunctionTypeRef)examplegroup, document); + return; + } else if (examplegroup instanceof JnarioField) { + _format((JnarioField)examplegroup, document); + return; + } else if (examplegroup instanceof JnarioFunction) { + _format((JnarioFunction)examplegroup, document); + return; + } else if (examplegroup instanceof JvmGenericArrayTypeReference) { + _format((JvmGenericArrayTypeReference)examplegroup, document); + return; + } else if (examplegroup instanceof JvmParameterizedTypeReference) { + _format((JvmParameterizedTypeReference)examplegroup, document); + return; + } else if (examplegroup instanceof JvmWildcardTypeReference) { + _format((JvmWildcardTypeReference)examplegroup, document); + return; + } else if (examplegroup instanceof XBasicForLoopExpression) { + _format((XBasicForLoopExpression)examplegroup, document); + return; + } else if (examplegroup instanceof XBlockExpression) { + _format((XBlockExpression)examplegroup, document); + return; + } else if (examplegroup instanceof XCastedExpression) { + _format((XCastedExpression)examplegroup, document); + return; + } else if (examplegroup instanceof XClosure) { + _format((XClosure)examplegroup, document); + return; + } else if (examplegroup instanceof XCollectionLiteral) { + _format((XCollectionLiteral)examplegroup, document); + return; + } else if (examplegroup instanceof XConstructorCall) { + _format((XConstructorCall)examplegroup, document); + return; + } else if (examplegroup instanceof XForLoopExpression) { + _format((XForLoopExpression)examplegroup, document); + return; + } else if (examplegroup instanceof XIfExpression) { + _format((XIfExpression)examplegroup, document); + return; + } else if (examplegroup instanceof XInstanceOfExpression) { + _format((XInstanceOfExpression)examplegroup, document); + return; + } else if (examplegroup instanceof XReturnExpression) { + _format((XReturnExpression)examplegroup, document); + return; + } else if (examplegroup instanceof XSwitchExpression) { + _format((XSwitchExpression)examplegroup, document); + return; + } else if (examplegroup instanceof XSynchronizedExpression) { + _format((XSynchronizedExpression)examplegroup, document); + return; + } else if (examplegroup instanceof XThrowExpression) { + _format((XThrowExpression)examplegroup, document); + return; + } else if (examplegroup instanceof XTryCatchFinallyExpression) { + _format((XTryCatchFinallyExpression)examplegroup, document); + return; + } else if (examplegroup instanceof XTypeLiteral) { + _format((XTypeLiteral)examplegroup, document); + return; + } else if (examplegroup instanceof XVariableDeclaration) { + _format((XVariableDeclaration)examplegroup, document); + return; + } else if (examplegroup instanceof XAnnotation) { + _format((XAnnotation)examplegroup, document); + return; + } else if (examplegroup instanceof Assertion) { + _format((Assertion)examplegroup, document); + return; + } else if (examplegroup instanceof JnarioMember) { + _format((JnarioMember)examplegroup, document); + return; + } else if (examplegroup instanceof JnarioParameter) { + _format((JnarioParameter)examplegroup, document); + return; + } else if (examplegroup instanceof ShouldThrow) { + _format((ShouldThrow)examplegroup, document); + return; + } else if (examplegroup instanceof SpecFile) { + _format((SpecFile)examplegroup, document); + return; + } else if (examplegroup instanceof JvmTypeConstraint) { + _format((JvmTypeConstraint)examplegroup, document); + return; + } else if (examplegroup instanceof XExpression) { + _format((XExpression)examplegroup, document); + return; + } else if (examplegroup instanceof XImportDeclaration) { + _format((XImportDeclaration)examplegroup, document); + return; + } else if (examplegroup instanceof XImportSection) { + _format((XImportSection)examplegroup, document); + return; + } else if (examplegroup instanceof ExampleColumn) { + _format((ExampleColumn)examplegroup, document); + return; + } else if (examplegroup instanceof ExampleRow) { + _format((ExampleRow)examplegroup, document); + return; + } else if (examplegroup instanceof EObject) { + _format((EObject)examplegroup, document); + return; + } else if (examplegroup == null) { + _format((Void)null, document); + return; + } else if (examplegroup != null) { + _format(examplegroup, document); + return; + } else { + throw new IllegalArgumentException("Unhandled parameter types: " + + Arrays.asList(examplegroup, document).toString()); + } + } +} diff --git a/plugins/org.jnario.spec/xtend-gen/org/jnario/spec/jvmmodel/ImplicitSubject.java b/plugins/org.jnario.spec/xtend-gen/org/jnario/spec/jvmmodel/ImplicitSubject.java index ee7c0e476..a5bd30922 100644 --- a/plugins/org.jnario.spec/xtend-gen/org/jnario/spec/jvmmodel/ImplicitSubject.java +++ b/plugins/org.jnario.spec/xtend-gen/org/jnario/spec/jvmmodel/ImplicitSubject.java @@ -1,149 +1,149 @@ -/** - * Copyright (c) 2012 BMW Car IT and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.jnario.spec.jvmmodel; - -import com.google.common.base.Objects; -import com.google.common.collect.Iterables; -import com.google.common.collect.Iterators; -import com.google.inject.Inject; -import java.util.Iterator; -import org.eclipse.emf.common.util.EList; -import org.eclipse.xtext.EcoreUtil2; -import org.eclipse.xtext.common.types.JvmAnnotationReference; -import org.eclipse.xtext.common.types.JvmField; -import org.eclipse.xtext.common.types.JvmGenericType; -import org.eclipse.xtext.common.types.JvmType; -import org.eclipse.xtext.common.types.JvmTypeReference; -import org.eclipse.xtext.common.types.JvmVisibility; -import org.eclipse.xtext.xbase.XAbstractFeatureCall; -import org.eclipse.xtext.xbase.XAssignment; -import org.eclipse.xtext.xbase.XbasePackage; -import org.eclipse.xtext.xbase.lib.Extension; -import org.eclipse.xtext.xbase.lib.Functions.Function1; -import org.eclipse.xtext.xbase.lib.IterableExtensions; -import org.eclipse.xtext.xbase.lib.IteratorExtensions; -import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; -import org.jnario.JnarioFunction; -import org.jnario.JnarioMember; -import org.jnario.jvmmodel.ExtendedJvmTypesBuilder; -import org.jnario.runner.Subject; -import org.jnario.spec.jvmmodel.Constants; -import org.jnario.spec.spec.ExampleGroup; -import org.jnario.spec.spec.TestFunction; -import org.jnario.util.Nodes; - -/** - * @author Sebastian Benz - Initial contribution and API - */ -@SuppressWarnings("all") -public class ImplicitSubject { - @Inject - @Extension - private ExtendedJvmTypesBuilder _extendedJvmTypesBuilder; - - public void addImplicitSubject(final JvmGenericType type, final ExampleGroup exampleGroup) { - final JvmTypeReference targetType = this.resolveTargetType(exampleGroup); - if ((Objects.equal(targetType, null) || targetType.eIsProxy())) { - return; - } - boolean _hasSubject = this.hasSubject(type); - if (_hasSubject) { - return; - } - boolean _neverUsesSubject = this.neverUsesSubject(exampleGroup); - if (_neverUsesSubject) { - return; - } - final Procedure1 _function = (JvmField it) -> { - boolean _doesNotInitializeSubject = this.doesNotInitializeSubject(exampleGroup); - if (_doesNotInitializeSubject) { - EList _annotations = it.getAnnotations(); - JvmAnnotationReference _annotation = this._extendedJvmTypesBuilder.toAnnotation(exampleGroup, Subject.class); - this._extendedJvmTypesBuilder.operator_add(_annotations, _annotation); - } - it.setVisibility(JvmVisibility.PUBLIC); - }; - type.getMembers().add(0, this._extendedJvmTypesBuilder.toField(exampleGroup, Constants.SUBJECT_FIELD_NAME, targetType, _function)); - } - - public JvmTypeReference resolveTargetType(final ExampleGroup exampleGroup) { - JvmTypeReference _targetType = exampleGroup.getTargetType(); - boolean _notEquals = (!Objects.equal(_targetType, null)); - if (_notEquals) { - return this._extendedJvmTypesBuilder.cloneWithProxies(exampleGroup.getTargetType()); - } - final ExampleGroup parentGroup = this.parent(exampleGroup); - boolean _equals = Objects.equal(parentGroup, null); - if (_equals) { - return null; - } - return this.resolveTargetType(parentGroup); - } - - public ExampleGroup parent(final ExampleGroup exampleGroup) { - return EcoreUtil2.getContainerOfType(exampleGroup.eContainer(), ExampleGroup.class); - } - - public boolean hasSubject(final JvmGenericType type) { - final Iterable fields = Iterables.filter(type.getMembers(), JvmField.class); - final Function1 _function = (JvmField it) -> { - String _simpleName = it.getSimpleName(); - return Boolean.valueOf(Objects.equal(_simpleName, Constants.SUBJECT_FIELD_NAME)); - }; - final JvmField subjectField = IterableExtensions.findFirst(fields, _function); - boolean _notEquals = (!Objects.equal(subjectField, null)); - if (_notEquals) { - return true; - } - JvmTypeReference _extendedClass = type.getExtendedClass(); - JvmType _type = null; - if (_extendedClass!=null) { - _type=_extendedClass.getType(); - } - final JvmType extendedClass = _type; - boolean _equals = Objects.equal(extendedClass, null); - if (_equals) { - return false; - } - return this.hasSubject(((JvmGenericType) extendedClass)); - } - - public boolean neverUsesSubject(final ExampleGroup exampleGroup) { - Iterator allFeatureCalls = Iterators.emptyIterator(); - final EList members = exampleGroup.getMembers(); - Iterable _filter = Iterables.filter(members, JnarioFunction.class); - Iterable _filter_1 = Iterables.filter(members, TestFunction.class); - Iterable _plus = Iterables.concat(_filter, _filter_1); - for (final JnarioFunction example : _plus) { - allFeatureCalls = Iterators.concat(allFeatureCalls, Iterators.filter(example.eAllContents(), XAbstractFeatureCall.class)); - } - final Function1 _function = (XAbstractFeatureCall it) -> { - String _concreteSyntaxFeatureName = it.getConcreteSyntaxFeatureName(); - return Boolean.valueOf(Objects.equal(_concreteSyntaxFeatureName, Constants.SUBJECT_FIELD_NAME)); - }; - XAbstractFeatureCall _findFirst = IteratorExtensions.findFirst(allFeatureCalls, _function); - return Objects.equal(null, _findFirst); - } - - public boolean doesNotInitializeSubject(final ExampleGroup exampleGroup) { - Iterator allAssignments = Iterators.emptyIterator(); - final EList members = exampleGroup.getMembers(); - Iterable _filter = Iterables.filter(members, JnarioFunction.class); - Iterable _filter_1 = Iterables.filter(members, TestFunction.class); - Iterable _plus = Iterables.concat(_filter, _filter_1); - for (final JnarioFunction example : _plus) { - allAssignments = Iterators.concat(allAssignments, Iterators.filter(example.eAllContents(), XAssignment.class)); - } - final Function1 _function = (XAssignment it) -> { - final String assignable = Nodes.textForFeature(it, XbasePackage.eINSTANCE.getXAbstractFeatureCall_Feature()); - return Boolean.valueOf(Objects.equal(assignable, Constants.SUBJECT_FIELD_NAME)); - }; - XAssignment _findFirst = IteratorExtensions.findFirst(allAssignments, _function); - return Objects.equal(null, _findFirst); - } -} +/** + * Copyright (c) 2012 BMW Car IT and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.jnario.spec.jvmmodel; + +import com.google.common.base.Objects; +import com.google.common.collect.Iterables; +import com.google.common.collect.Iterators; +import com.google.inject.Inject; +import java.util.Iterator; +import org.eclipse.emf.common.util.EList; +import org.eclipse.xtext.EcoreUtil2; +import org.eclipse.xtext.common.types.JvmAnnotationReference; +import org.eclipse.xtext.common.types.JvmField; +import org.eclipse.xtext.common.types.JvmGenericType; +import org.eclipse.xtext.common.types.JvmType; +import org.eclipse.xtext.common.types.JvmTypeReference; +import org.eclipse.xtext.common.types.JvmVisibility; +import org.eclipse.xtext.xbase.XAbstractFeatureCall; +import org.eclipse.xtext.xbase.XAssignment; +import org.eclipse.xtext.xbase.XbasePackage; +import org.eclipse.xtext.xbase.lib.Extension; +import org.eclipse.xtext.xbase.lib.Functions.Function1; +import org.eclipse.xtext.xbase.lib.IterableExtensions; +import org.eclipse.xtext.xbase.lib.IteratorExtensions; +import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; +import org.jnario.JnarioFunction; +import org.jnario.JnarioMember; +import org.jnario.jvmmodel.ExtendedJvmTypesBuilder; +import org.jnario.runner.Subject; +import org.jnario.spec.jvmmodel.Constants; +import org.jnario.spec.spec.ExampleGroup; +import org.jnario.spec.spec.TestFunction; +import org.jnario.util.Nodes; + +/** + * @author Sebastian Benz - Initial contribution and API + */ +@SuppressWarnings("all") +public class ImplicitSubject { + @Inject + @Extension + private ExtendedJvmTypesBuilder _extendedJvmTypesBuilder; + + public void addImplicitSubject(final JvmGenericType type, final ExampleGroup exampleGroup) { + final JvmTypeReference targetType = this.resolveTargetType(exampleGroup); + if ((Objects.equal(targetType, null) || targetType.eIsProxy())) { + return; + } + boolean _hasSubject = this.hasSubject(type); + if (_hasSubject) { + return; + } + boolean _neverUsesSubject = this.neverUsesSubject(exampleGroup); + if (_neverUsesSubject) { + return; + } + final Procedure1 _function = (JvmField it) -> { + boolean _doesNotInitializeSubject = this.doesNotInitializeSubject(exampleGroup); + if (_doesNotInitializeSubject) { + EList _annotations = it.getAnnotations(); + JvmAnnotationReference _annotation = this._extendedJvmTypesBuilder.toAnnotation(exampleGroup, Subject.class); + this._extendedJvmTypesBuilder.operator_add(_annotations, _annotation); + } + it.setVisibility(JvmVisibility.PUBLIC); + }; + type.getMembers().add(0, this._extendedJvmTypesBuilder.toField(exampleGroup, Constants.SUBJECT_FIELD_NAME, targetType, _function)); + } + + public JvmTypeReference resolveTargetType(final ExampleGroup exampleGroup) { + JvmTypeReference _targetType = exampleGroup.getTargetType(); + boolean _notEquals = (!Objects.equal(_targetType, null)); + if (_notEquals) { + return this._extendedJvmTypesBuilder.cloneWithProxies(exampleGroup.getTargetType()); + } + final ExampleGroup parentGroup = this.parent(exampleGroup); + boolean _equals = Objects.equal(parentGroup, null); + if (_equals) { + return null; + } + return this.resolveTargetType(parentGroup); + } + + public ExampleGroup parent(final ExampleGroup exampleGroup) { + return EcoreUtil2.getContainerOfType(exampleGroup.eContainer(), ExampleGroup.class); + } + + public boolean hasSubject(final JvmGenericType type) { + final Iterable fields = Iterables.filter(type.getMembers(), JvmField.class); + final Function1 _function = (JvmField it) -> { + String _simpleName = it.getSimpleName(); + return Boolean.valueOf(Objects.equal(_simpleName, Constants.SUBJECT_FIELD_NAME)); + }; + final JvmField subjectField = IterableExtensions.findFirst(fields, _function); + boolean _notEquals = (!Objects.equal(subjectField, null)); + if (_notEquals) { + return true; + } + JvmTypeReference _extendedClass = type.getExtendedClass(); + JvmType _type = null; + if (_extendedClass!=null) { + _type=_extendedClass.getType(); + } + final JvmType extendedClass = _type; + boolean _equals = Objects.equal(extendedClass, null); + if (_equals) { + return false; + } + return this.hasSubject(((JvmGenericType) extendedClass)); + } + + public boolean neverUsesSubject(final ExampleGroup exampleGroup) { + Iterator allFeatureCalls = Iterators.emptyIterator(); + final EList members = exampleGroup.getMembers(); + Iterable _filter = Iterables.filter(members, JnarioFunction.class); + Iterable _filter_1 = Iterables.filter(members, TestFunction.class); + Iterable _plus = Iterables.concat(_filter, _filter_1); + for (final JnarioFunction example : _plus) { + allFeatureCalls = Iterators.concat(allFeatureCalls, Iterators.filter(example.eAllContents(), XAbstractFeatureCall.class)); + } + final Function1 _function = (XAbstractFeatureCall it) -> { + String _concreteSyntaxFeatureName = it.getConcreteSyntaxFeatureName(); + return Boolean.valueOf(Objects.equal(_concreteSyntaxFeatureName, Constants.SUBJECT_FIELD_NAME)); + }; + XAbstractFeatureCall _findFirst = IteratorExtensions.findFirst(allFeatureCalls, _function); + return Objects.equal(null, _findFirst); + } + + public boolean doesNotInitializeSubject(final ExampleGroup exampleGroup) { + Iterator allAssignments = Iterators.emptyIterator(); + final EList members = exampleGroup.getMembers(); + Iterable _filter = Iterables.filter(members, JnarioFunction.class); + Iterable _filter_1 = Iterables.filter(members, TestFunction.class); + Iterable _plus = Iterables.concat(_filter, _filter_1); + for (final JnarioFunction example : _plus) { + allAssignments = Iterators.concat(allAssignments, Iterators.filter(example.eAllContents(), XAssignment.class)); + } + final Function1 _function = (XAssignment it) -> { + final String assignable = Nodes.textForFeature(it, XbasePackage.eINSTANCE.getXAbstractFeatureCall_Feature()); + return Boolean.valueOf(Objects.equal(assignable, Constants.SUBJECT_FIELD_NAME)); + }; + XAssignment _findFirst = IteratorExtensions.findFirst(allAssignments, _function); + return Objects.equal(null, _findFirst); + } +} diff --git a/plugins/org.jnario.spec/xtend-gen/org/jnario/spec/jvmmodel/SpecJvmModelGenerator.java b/plugins/org.jnario.spec/xtend-gen/org/jnario/spec/jvmmodel/SpecJvmModelGenerator.java index 1e1fb0336..d8b8e14f4 100644 --- a/plugins/org.jnario.spec/xtend-gen/org/jnario/spec/jvmmodel/SpecJvmModelGenerator.java +++ b/plugins/org.jnario.spec/xtend-gen/org/jnario/spec/jvmmodel/SpecJvmModelGenerator.java @@ -1,7 +1,7 @@ -package org.jnario.spec.jvmmodel; - -import org.jnario.jvmmodel.ExtendedJvmModelGenerator; - -@SuppressWarnings("all") -public class SpecJvmModelGenerator extends ExtendedJvmModelGenerator { -} +package org.jnario.spec.jvmmodel; + +import org.jnario.jvmmodel.ExtendedJvmModelGenerator; + +@SuppressWarnings("all") +public class SpecJvmModelGenerator extends ExtendedJvmModelGenerator { +} diff --git a/plugins/org.jnario.spec/xtend-gen/org/jnario/spec/jvmmodel/SpecJvmModelInferrer.java b/plugins/org.jnario.spec/xtend-gen/org/jnario/spec/jvmmodel/SpecJvmModelInferrer.java index 97a97075c..461811532 100644 --- a/plugins/org.jnario.spec/xtend-gen/org/jnario/spec/jvmmodel/SpecJvmModelInferrer.java +++ b/plugins/org.jnario.spec/xtend-gen/org/jnario/spec/jvmmodel/SpecJvmModelInferrer.java @@ -1,529 +1,529 @@ -/** - * Copyright (c) 2012 BMW Car IT and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.jnario.spec.jvmmodel; - -import com.google.common.base.Objects; -import com.google.common.collect.Iterables; -import com.google.inject.Inject; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.function.Consumer; -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.xtext.common.types.JvmAnnotationReference; -import org.eclipse.xtext.common.types.JvmAnnotationValue; -import org.eclipse.xtext.common.types.JvmConstructor; -import org.eclipse.xtext.common.types.JvmField; -import org.eclipse.xtext.common.types.JvmFormalParameter; -import org.eclipse.xtext.common.types.JvmGenericType; -import org.eclipse.xtext.common.types.JvmIntAnnotationValue; -import org.eclipse.xtext.common.types.JvmMember; -import org.eclipse.xtext.common.types.JvmOperation; -import org.eclipse.xtext.common.types.JvmType; -import org.eclipse.xtext.common.types.JvmTypeReference; -import org.eclipse.xtext.common.types.JvmVisibility; -import org.eclipse.xtext.common.types.TypesFactory; -import org.eclipse.xtext.common.types.util.TypeReferences; -import org.eclipse.xtext.util.Strings; -import org.eclipse.xtext.xbase.XExpression; -import org.eclipse.xtext.xbase.XNullLiteral; -import org.eclipse.xtext.xbase.XbaseFactory; -import org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation; -import org.eclipse.xtext.xbase.compiler.output.ITreeAppendable; -import org.eclipse.xtext.xbase.jvmmodel.IJvmDeclaredTypeAcceptor; -import org.eclipse.xtext.xbase.jvmmodel.IJvmModelAssociator; -import org.eclipse.xtext.xbase.lib.CollectionLiterals; -import org.eclipse.xtext.xbase.lib.Extension; -import org.eclipse.xtext.xbase.lib.Functions.Function1; -import org.eclipse.xtext.xbase.lib.IterableExtensions; -import org.eclipse.xtext.xbase.lib.ListExtensions; -import org.eclipse.xtext.xbase.lib.ObjectExtensions; -import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; -import org.eclipse.xtext.xbase.lib.Procedures.Procedure2; -import org.jnario.ExampleCell; -import org.jnario.ExampleColumn; -import org.jnario.ExampleRow; -import org.jnario.ExampleTable; -import org.jnario.JnarioClass; -import org.jnario.JnarioField; -import org.jnario.JnarioFile; -import org.jnario.JnarioFunction; -import org.jnario.JnarioMember; -import org.jnario.jvmmodel.ExtendedJvmTypesBuilder; -import org.jnario.jvmmodel.JnarioJvmModelInferrer; -import org.jnario.lib.ExampleTableRow; -import org.jnario.runner.Named; -import org.jnario.runner.Order; -import org.jnario.spec.jvmmodel.ImplicitSubject; -import org.jnario.spec.jvmmodel.SpecIgnoringXtendJvmModelInferrer; -import org.jnario.spec.jvmmodel.SpecSyntheticNameClashResolver; -import org.jnario.spec.naming.ExampleNameProvider; -import org.jnario.spec.spec.After; -import org.jnario.spec.spec.Before; -import org.jnario.spec.spec.Example; -import org.jnario.spec.spec.ExampleGroup; -import org.jnario.spec.spec.TestFunction; - -/** - * @author Sebastian Benz - Initial contribution and API - */ -@SuppressWarnings("all") -public class SpecJvmModelInferrer extends JnarioJvmModelInferrer { - @Inject - @Extension - private ExtendedJvmTypesBuilder _extendedJvmTypesBuilder; - - @Inject - @Extension - private TypeReferences _typeReferences; - - @Inject - @Extension - private ExampleNameProvider _exampleNameProvider; - - @Inject - @Extension - private ImplicitSubject _implicitSubject; - - @Inject - @Extension - private SpecSyntheticNameClashResolver _specSyntheticNameClashResolver; - - @Inject - @Extension - private TypesFactory typesFactory; - - @Inject - private SpecIgnoringXtendJvmModelInferrer xtendJvmModelInferrer; - - @Inject - private IJvmModelAssociator modelAssociator; - - private int exampleIndex = 0; - - private int index = 0; - - @Override - public void doInfer(final EObject object, final IJvmDeclaredTypeAcceptor acceptor, final boolean preIndexingPhase) { - if ((!(object instanceof JnarioFile))) { - return; - } - final JnarioFile jnarioFile = ((JnarioFile) object); - this.xtendJvmModelInferrer.infer(object, acceptor, preIndexingPhase); - final ArrayList doLater = CollectionLiterals.newArrayList(); - Iterable _filter = Iterables.filter(jnarioFile.getXtendTypes(), ExampleGroup.class); - for (final ExampleGroup declaration : _filter) { - this.infer(acceptor, declaration, null, doLater, preIndexingPhase); - } - this.exampleIndex = 0; - if ((!preIndexingPhase)) { - for (final Runnable runnable : doLater) { - runnable.run(); - } - } - } - - public JvmGenericType infer(final IJvmDeclaredTypeAcceptor acceptor, final ExampleGroup exampleGroup, final JvmGenericType superType, final List doLater, final boolean preIndexingPhase) { - JvmGenericType _xblockexpression = null; - { - boolean _notEquals = (!Objects.equal(superType, null)); - if (_notEquals) { - exampleGroup.setExtends(this._typeReferences.createTypeRef(superType)); - } else { - this.addSuperClass(exampleGroup); - } - final JvmGenericType javaType = this.typesFactory.createJvmGenericType(); - this.setNameAndAssociate(this.jnarioFile(exampleGroup), exampleGroup, javaType); - acceptor.accept(javaType); - if ((!preIndexingPhase)) { - final Runnable _function = () -> { - this.initialize(exampleGroup, javaType); - }; - doLater.add(_function); - } - final ArrayList children = CollectionLiterals.newArrayList(); - final Consumer _function_1 = (ExampleGroup child) -> { - JvmGenericType _infer = this.infer(acceptor, child, javaType, doLater, preIndexingPhase); - children.add(_infer); - }; - Iterables.filter(exampleGroup.getMembers(), ExampleGroup.class).forEach(_function_1); - boolean _isEmpty = children.isEmpty(); - boolean _not = (!_isEmpty); - if (_not) { - final Function1 _function_2 = (JvmGenericType it) -> { - return this._typeReferences.createTypeRef(it); - }; - this.getTestRuntime().addChildren(exampleGroup, javaType, ListExtensions.map(children, _function_2)); - } - _xblockexpression = javaType; - } - return _xblockexpression; - } - - @Override - public void initialize(final JnarioClass source, final JvmGenericType inferredJvmType) { - inferredJvmType.setVisibility(JvmVisibility.PUBLIC); - final Function1 _function = (XAnnotation it) -> { - JvmType _annotationType = null; - if (it!=null) { - _annotationType=it.getAnnotationType(); - } - return Boolean.valueOf((!Objects.equal(_annotationType, null))); - }; - this._extendedJvmTypesBuilder.addAnnotations(inferredJvmType, IterableExtensions.filter(source.getAnnotations(), _function)); - EList _annotations = inferredJvmType.getAnnotations(); - JvmAnnotationReference _annotationRef = this._annotationTypesBuilder.annotationRef(Named.class, this._exampleNameProvider.describe(source)); - this._extendedJvmTypesBuilder.operator_add(_annotations, _annotationRef); - JvmTypeReference _extends = source.getExtends(); - boolean _equals = Objects.equal(_extends, null); - if (_equals) { - final JvmTypeReference typeRefToObject = this._typeReferences.getTypeForName(Object.class, source); - boolean _notEquals = (!Objects.equal(typeRefToObject, null)); - if (_notEquals) { - inferredJvmType.getSuperTypes().add(typeRefToObject); - } - } else { - inferredJvmType.getSuperTypes().add(this._extendedJvmTypesBuilder.cloneWithProxies(source.getExtends())); - } - this.getTestRuntime().updateExampleGroup(source, inferredJvmType); - this.exampleIndex = 0; - EList _members = source.getMembers(); - for (final JnarioMember member : _members) { - this.transform(member, inferredJvmType); - } - this._implicitSubject.addImplicitSubject(inferredJvmType, ((ExampleGroup) source)); - this._extendedJvmTypesBuilder.copyDocumentationTo(source, inferredJvmType); - this._specSyntheticNameClashResolver.resolveNameClashes(inferredJvmType); - } - - protected void _transform(final Example element, final JvmGenericType container) { - this.exampleIndex = (this.exampleIndex + 1); - XExpression _expression = element.getExpression(); - boolean _equals = Objects.equal(_expression, null); - if (_equals) { - element.setExpression(XbaseFactory.eINSTANCE.createXBlockExpression()); - } - final JvmOperation method = this.toMethod(element, container); - this.getTestRuntime().markAsTestMethod(element, method); - boolean _isPending = element.isPending(); - if (_isPending) { - this.getTestRuntime().markAsPending(element, method); - } - EList _annotations = method.getAnnotations(); - JvmAnnotationReference _annotationRef = this._annotationTypesBuilder.annotationRef(Named.class, this._exampleNameProvider.describe(element)); - this._extendedJvmTypesBuilder.operator_add(_annotations, _annotationRef); - EList _annotations_1 = method.getAnnotations(); - JvmAnnotationReference _annotationRef_1 = this._annotationTypesBuilder.annotationRef(Order.class); - final Procedure1 _function = (JvmAnnotationReference it) -> { - EList _explicitValues = it.getExplicitValues(); - JvmIntAnnotationValue _createJvmIntAnnotationValue = this.typesFactory.createJvmIntAnnotationValue(); - final Procedure1 _function_1 = (JvmIntAnnotationValue it_1) -> { - EList _values = it_1.getValues(); - this._extendedJvmTypesBuilder.operator_add(_values, Integer.valueOf(this.exampleIndex)); - }; - JvmIntAnnotationValue _doubleArrow = ObjectExtensions.operator_doubleArrow(_createJvmIntAnnotationValue, _function_1); - this._extendedJvmTypesBuilder.operator_add(_explicitValues, _doubleArrow); - }; - JvmAnnotationReference _doubleArrow = ObjectExtensions.operator_doubleArrow(_annotationRef_1, _function); - this._extendedJvmTypesBuilder.operator_add(_annotations_1, _doubleArrow); - EList _members = container.getMembers(); - this._extendedJvmTypesBuilder.operator_add(_members, method); - this.modelAssociator.associatePrimary(element, method); - } - - protected void _transform(final Before element, final JvmGenericType container) { - final Procedure2 _function = (JnarioMember e, JvmOperation m) -> { - this.getTestRuntime().beforeMethod(e, m); - }; - final Procedure2 _function_1 = (JnarioMember e, JvmOperation m) -> { - this.getTestRuntime().beforeAllMethod(e, m); - }; - this.transformAround(element, container, _function, _function_1); - } - - protected void _transform(final After element, final JvmGenericType container) { - final Procedure2 _function = (JnarioMember e, JvmOperation m) -> { - this.getTestRuntime().afterMethod(e, m); - }; - final Procedure2 _function_1 = (JnarioMember e, JvmOperation m) -> { - this.getTestRuntime().afterAllMethod(e, m); - }; - this.transformAround(element, container, _function, _function_1); - } - - public boolean transformAround(final TestFunction element, final JvmGenericType container, final Procedure2 around, final Procedure2 aroundAll) { - boolean _xblockexpression = false; - { - final JvmOperation afterMethod = this.toMethod(element, container); - boolean _isStatic = element.isStatic(); - if (_isStatic) { - aroundAll.apply(((JnarioMember) element), afterMethod); - } else { - around.apply(element, afterMethod); - } - EList _members = container.getMembers(); - _xblockexpression = this._extendedJvmTypesBuilder.operator_add(_members, afterMethod); - } - return _xblockexpression; - } - - @Override - protected void _transform(final JnarioMember source, final JvmGenericType container) { - } - - public JvmOperation toMethod(final TestFunction element, final JvmGenericType container) { - JvmOperation _xblockexpression = null; - { - element.setReturnType(this._typeReferences.getTypeForName(Void.TYPE, element)); - JvmOperation _createJvmOperation = this.typesFactory.createJvmOperation(); - final Procedure1 _function = (JvmOperation it) -> { - it.setSimpleName(this._exampleNameProvider.toMethodName(element)); - it.setVisibility(JvmVisibility.PUBLIC); - it.setStatic(element.isStatic()); - it.setReturnType(this._typeReferences.getTypeForName(Void.TYPE, element)); - }; - final JvmOperation operation = ObjectExtensions.operator_doubleArrow(_createJvmOperation, _function); - this._extendedJvmTypesBuilder.setBody(operation, element.getExpression()); - final Function1 _function_1 = (XAnnotation it) -> { - JvmType _annotationType = null; - if (it!=null) { - _annotationType=it.getAnnotationType(); - } - return Boolean.valueOf((!Objects.equal(_annotationType, null))); - }; - this._extendedJvmTypesBuilder.addAnnotations(operation, IterableExtensions.filter(element.getAnnotations(), _function_1)); - this._extendedJvmTypesBuilder.copyDocumentationTo(element, operation); - container.getMembers().add(operation); - EList _exceptions = operation.getExceptions(); - JvmTypeReference _typeForName = this._typeReferences.getTypeForName(Exception.class, element); - this._extendedJvmTypesBuilder.operator_add(_exceptions, _typeForName); - _xblockexpression = operation; - } - return _xblockexpression; - } - - public void configureWith(final JvmGenericType type, final EObject source, final JnarioFile spec) { - EList _contents = spec.eResource().getContents(); - this._extendedJvmTypesBuilder.operator_add(_contents, type); - type.setPackageName(spec.getPackage()); - this._extendedJvmTypesBuilder.setDocumentation(type, this._extendedJvmTypesBuilder.getDocumentation(source)); - } - - protected void _transform(final ExampleTable table, final JvmGenericType specType) { - this.associateTableWithSpec(specType, table); - final Procedure1 _function = (JvmGenericType exampleTableType) -> { - EList _superTypes = exampleTableType.getSuperTypes(); - JvmTypeReference _typeForName = this._typeReferences.getTypeForName(ExampleTableRow.class, table); - this._extendedJvmTypesBuilder.operator_add(_superTypes, _typeForName); - this.configureWith(exampleTableType, table, this.jnarioFile(table)); - final JvmTypeReference type = this._typeReferences.getTypeForName(org.jnario.lib.ExampleTable.class, table, this._typeReferences.createTypeRef(exampleTableType)); - String _javaClassName = this._exampleNameProvider.toJavaClassName(table); - final String initMethodName = ("_init" + _javaClassName); - EList _members = specType.getMembers(); - final Procedure1 _function_1 = (JvmOperation it) -> { - final Procedure1 _function_2 = (ITreeAppendable a) -> { - it.setDeclaringType(specType); - this.generateInitializationMethod(table, a); - }; - this._extendedJvmTypesBuilder.setBody(it, _function_2); - }; - JvmOperation _method = this._extendedJvmTypesBuilder.toMethod(table, initMethodName, type, _function_1); - this._extendedJvmTypesBuilder.operator_add(_members, _method); - EList _members_1 = specType.getMembers(); - final Procedure1 _function_2 = (JvmField it) -> { - it.setVisibility(JvmVisibility.PROTECTED); - final Procedure1 _function_3 = (ITreeAppendable it_1) -> { - it_1.append(initMethodName).append("()"); - }; - this._extendedJvmTypesBuilder.setInitializer(it, _function_3); - }; - JvmField _field = this._extendedJvmTypesBuilder.toField(table, this._exampleNameProvider.toFieldName(table), type, _function_2); - this._extendedJvmTypesBuilder.operator_add(_members_1, _field); - final Procedure1 _function_3 = (JvmConstructor it) -> { - it.setSimpleName(exampleTableType.getSimpleName()); - }; - final JvmConstructor constructor = this._extendedJvmTypesBuilder.toConstructor(table, _function_3); - EList _members_2 = exampleTableType.getMembers(); - this._extendedJvmTypesBuilder.operator_add(_members_2, constructor); - final ArrayList assignments = CollectionLiterals.newArrayList(); - final JvmTypeReference stringType = this._typeReferences.getTypeForName(String.class, table); - final JvmTypeReference listType = this._typeReferences.getTypeForName(List.class, table, stringType); - final JvmFormalParameter cellNames = this.typesFactory.createJvmFormalParameter(); - cellNames.setName("cellNames"); - cellNames.setParameterType(listType); - EList _parameters = constructor.getParameters(); - this._extendedJvmTypesBuilder.operator_add(_parameters, cellNames); - assignments.add("super(cellNames);"); - this.index = 0; - final Consumer _function_4 = (ExampleColumn column) -> { - JvmTypeReference _xifexpression = null; - JvmTypeReference _type = column.getType(); - boolean _notEquals = (!Objects.equal(_type, null)); - if (_notEquals) { - _xifexpression = column.getType(); - } else { - _xifexpression = this._extendedJvmTypesBuilder.inferredType(); - } - final JvmTypeReference columnType = _xifexpression; - EList _members_3 = exampleTableType.getMembers(); - JvmField _field_1 = this._extendedJvmTypesBuilder.toField(column, column.getName(), this._extendedJvmTypesBuilder.cloneWithProxies(columnType)); - this._extendedJvmTypesBuilder.operator_add(_members_3, _field_1); - final JvmFormalParameter param = this._extendedJvmTypesBuilder.toParameter(column, column.getName(), this._extendedJvmTypesBuilder.cloneWithProxies(columnType)); - EList _parameters_1 = constructor.getParameters(); - this._extendedJvmTypesBuilder.operator_add(_parameters_1, param); - final JvmOperation getter = this._extendedJvmTypesBuilder.toGetter(column, column.getName(), this._extendedJvmTypesBuilder.cloneWithProxies(columnType)); - EList _members_4 = exampleTableType.getMembers(); - this._extendedJvmTypesBuilder.operator_add(_members_4, getter); - String _name = column.getName(); - String _plus = ("this." + _name); - String _plus_1 = (_plus + " = "); - String _name_1 = column.getName(); - String _plus_2 = (_plus_1 + _name_1); - String _plus_3 = (_plus_2 + ";"); - assignments.add(_plus_3); - }; - table.getColumns().forEach(_function_4); - final Consumer _function_5 = (ExampleRow it) -> { - final Consumer _function_6 = (ExampleCell it_1) -> { - this.generateCellInitializerMethod(specType, this.initMethodName(table, this.index), it_1); - this.index = (this.index + 1); - }; - it.getCells().forEach(_function_6); - }; - table.getRows().forEach(_function_5); - final Procedure1 _function_6 = (ITreeAppendable a) -> { - final Consumer _function_7 = (String it) -> { - a.append(it).newLine(); - }; - assignments.forEach(_function_7); - }; - this._extendedJvmTypesBuilder.setBody(constructor, _function_6); - }; - this._extendedJvmTypesBuilder.toClass(this.jnarioFile(table), this._exampleNameProvider.toJavaClassName(table), _function); - } - - public void generateInitializationMethod(final ExampleTable exampleTable, final ITreeAppendable appendable) { - final JvmType arraysType = this._typeReferences.getTypeForName(Arrays.class, exampleTable).getType(); - String _fieldName = this._exampleNameProvider.toFieldName(exampleTable); - String _plus = ("return ExampleTable.create(\"" + _fieldName); - String _plus_1 = (_plus + "\", \n"); - appendable.append(_plus_1); - ITreeAppendable _append = appendable.append(" ").append(arraysType).append(".asList(\""); - String _join = IterableExtensions.join(this.columnNames(exampleTable), "\", \""); - String _plus_2 = (_join + "\"), "); - _append.append(_plus_2); - appendable.increaseIndentation(); - appendable.append("\n"); - this.index = 0; - EList _rows = exampleTable.getRows(); - for (final ExampleRow row : _rows) { - { - appendable.append("new ").append(this._exampleNameProvider.toJavaClassName(exampleTable)).append("("); - ITreeAppendable _append_1 = appendable.append(" ").append(arraysType); - final Function1 _function = (ExampleCell it) -> { - return Strings.convertToJavaString(this.serialize(it).trim()); - }; - String _join_1 = IterableExtensions.join(ListExtensions.map(row.getCells(), _function), "\", \""); - String _plus_3 = (".asList(\"" + _join_1); - String _plus_4 = (_plus_3 + "\"), "); - _append_1.append(_plus_4); - EList _cells = row.getCells(); - for (final ExampleCell cell : _cells) { - { - XExpression _expression = cell.getExpression(); - if ((_expression instanceof XNullLiteral)) { - appendable.append("null"); - } else { - String _initMethodName = this.initMethodName(exampleTable, this.index); - String _plus_5 = (_initMethodName + "()"); - appendable.append(_plus_5); - } - this.index = (this.index + 1); - ExampleCell _last = IterableExtensions.last(row.getCells()); - boolean _notEquals = (!Objects.equal(_last, cell)); - if (_notEquals) { - appendable.append(", "); - } - } - } - appendable.append(")"); - ExampleRow _last = IterableExtensions.last(exampleTable.getRows()); - boolean _notEquals = (!Objects.equal(_last, row)); - if (_notEquals) { - appendable.append(",\n"); - } - } - } - appendable.decreaseIndentation(); - appendable.append("\n);"); - } - - public void associateTableWithSpec(final JvmGenericType type, final ExampleTable table) { - EList _rows = table.getRows(); - for (final ExampleRow row : _rows) { - this._extendedJvmTypesBuilder.associate(row, type); - } - } - - public String initMethodName(final ExampleTable exampleTable, final int i) { - String _javaClassName = this._exampleNameProvider.toJavaClassName(exampleTable); - String _plus = ("_init" + _javaClassName); - String _plus_1 = (_plus + "Cell"); - return (_plus_1 + Integer.valueOf(i)); - } - - public boolean generateCellInitializerMethod(final JvmGenericType specType, final String name, final ExampleCell cell) { - EList _members = specType.getMembers(); - final Procedure1 _function = (JvmOperation it) -> { - it.setDeclaringType(specType); - this._extendedJvmTypesBuilder.setBody(it, cell.getExpression()); - }; - JvmOperation _method = this._extendedJvmTypesBuilder.toMethod(cell, name, this._extendedJvmTypesBuilder.inferredType(), _function); - return this._extendedJvmTypesBuilder.operator_add(_members, _method); - } - - public List columnNames(final ExampleTable exampleTable) { - final Function1 _function = (ExampleColumn it) -> { - String _name = null; - if (it!=null) { - _name=it.getName(); - } - return _name; - }; - return ListExtensions.map(exampleTable.getColumns(), _function); - } - - protected void transform(final JnarioMember element, final JvmGenericType container) { - if (element instanceof After) { - _transform((After)element, container); - return; - } else if (element instanceof Before) { - _transform((Before)element, container); - return; - } else if (element instanceof Example) { - _transform((Example)element, container); - return; - } else if (element instanceof ExampleTable) { - _transform((ExampleTable)element, container); - return; - } else if (element instanceof JnarioField) { - _transform((JnarioField)element, container); - return; - } else if (element instanceof JnarioFunction) { - _transform((JnarioFunction)element, container); - return; - } else if (element != null) { - _transform(element, container); - return; - } else { - throw new IllegalArgumentException("Unhandled parameter types: " + - Arrays.asList(element, container).toString()); - } - } -} +/** + * Copyright (c) 2012 BMW Car IT and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.jnario.spec.jvmmodel; + +import com.google.common.base.Objects; +import com.google.common.collect.Iterables; +import com.google.inject.Inject; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.function.Consumer; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.xtext.common.types.JvmAnnotationReference; +import org.eclipse.xtext.common.types.JvmAnnotationValue; +import org.eclipse.xtext.common.types.JvmConstructor; +import org.eclipse.xtext.common.types.JvmField; +import org.eclipse.xtext.common.types.JvmFormalParameter; +import org.eclipse.xtext.common.types.JvmGenericType; +import org.eclipse.xtext.common.types.JvmIntAnnotationValue; +import org.eclipse.xtext.common.types.JvmMember; +import org.eclipse.xtext.common.types.JvmOperation; +import org.eclipse.xtext.common.types.JvmType; +import org.eclipse.xtext.common.types.JvmTypeReference; +import org.eclipse.xtext.common.types.JvmVisibility; +import org.eclipse.xtext.common.types.TypesFactory; +import org.eclipse.xtext.common.types.util.TypeReferences; +import org.eclipse.xtext.util.Strings; +import org.eclipse.xtext.xbase.XExpression; +import org.eclipse.xtext.xbase.XNullLiteral; +import org.eclipse.xtext.xbase.XbaseFactory; +import org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation; +import org.eclipse.xtext.xbase.compiler.output.ITreeAppendable; +import org.eclipse.xtext.xbase.jvmmodel.IJvmDeclaredTypeAcceptor; +import org.eclipse.xtext.xbase.jvmmodel.IJvmModelAssociator; +import org.eclipse.xtext.xbase.lib.CollectionLiterals; +import org.eclipse.xtext.xbase.lib.Extension; +import org.eclipse.xtext.xbase.lib.Functions.Function1; +import org.eclipse.xtext.xbase.lib.IterableExtensions; +import org.eclipse.xtext.xbase.lib.ListExtensions; +import org.eclipse.xtext.xbase.lib.ObjectExtensions; +import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; +import org.eclipse.xtext.xbase.lib.Procedures.Procedure2; +import org.jnario.ExampleCell; +import org.jnario.ExampleColumn; +import org.jnario.ExampleRow; +import org.jnario.ExampleTable; +import org.jnario.JnarioClass; +import org.jnario.JnarioField; +import org.jnario.JnarioFile; +import org.jnario.JnarioFunction; +import org.jnario.JnarioMember; +import org.jnario.jvmmodel.ExtendedJvmTypesBuilder; +import org.jnario.jvmmodel.JnarioJvmModelInferrer; +import org.jnario.lib.ExampleTableRow; +import org.jnario.runner.Named; +import org.jnario.runner.Order; +import org.jnario.spec.jvmmodel.ImplicitSubject; +import org.jnario.spec.jvmmodel.SpecIgnoringXtendJvmModelInferrer; +import org.jnario.spec.jvmmodel.SpecSyntheticNameClashResolver; +import org.jnario.spec.naming.ExampleNameProvider; +import org.jnario.spec.spec.After; +import org.jnario.spec.spec.Before; +import org.jnario.spec.spec.Example; +import org.jnario.spec.spec.ExampleGroup; +import org.jnario.spec.spec.TestFunction; + +/** + * @author Sebastian Benz - Initial contribution and API + */ +@SuppressWarnings("all") +public class SpecJvmModelInferrer extends JnarioJvmModelInferrer { + @Inject + @Extension + private ExtendedJvmTypesBuilder _extendedJvmTypesBuilder; + + @Inject + @Extension + private TypeReferences _typeReferences; + + @Inject + @Extension + private ExampleNameProvider _exampleNameProvider; + + @Inject + @Extension + private ImplicitSubject _implicitSubject; + + @Inject + @Extension + private SpecSyntheticNameClashResolver _specSyntheticNameClashResolver; + + @Inject + @Extension + private TypesFactory typesFactory; + + @Inject + private SpecIgnoringXtendJvmModelInferrer xtendJvmModelInferrer; + + @Inject + private IJvmModelAssociator modelAssociator; + + private int exampleIndex = 0; + + private int index = 0; + + @Override + public void doInfer(final EObject object, final IJvmDeclaredTypeAcceptor acceptor, final boolean preIndexingPhase) { + if ((!(object instanceof JnarioFile))) { + return; + } + final JnarioFile jnarioFile = ((JnarioFile) object); + this.xtendJvmModelInferrer.infer(object, acceptor, preIndexingPhase); + final ArrayList doLater = CollectionLiterals.newArrayList(); + Iterable _filter = Iterables.filter(jnarioFile.getXtendTypes(), ExampleGroup.class); + for (final ExampleGroup declaration : _filter) { + this.infer(acceptor, declaration, null, doLater, preIndexingPhase); + } + this.exampleIndex = 0; + if ((!preIndexingPhase)) { + for (final Runnable runnable : doLater) { + runnable.run(); + } + } + } + + public JvmGenericType infer(final IJvmDeclaredTypeAcceptor acceptor, final ExampleGroup exampleGroup, final JvmGenericType superType, final List doLater, final boolean preIndexingPhase) { + JvmGenericType _xblockexpression = null; + { + boolean _notEquals = (!Objects.equal(superType, null)); + if (_notEquals) { + exampleGroup.setExtends(this._typeReferences.createTypeRef(superType)); + } else { + this.addSuperClass(exampleGroup); + } + final JvmGenericType javaType = this.typesFactory.createJvmGenericType(); + this.setNameAndAssociate(this.jnarioFile(exampleGroup), exampleGroup, javaType); + acceptor.accept(javaType); + if ((!preIndexingPhase)) { + final Runnable _function = () -> { + this.initialize(exampleGroup, javaType); + }; + doLater.add(_function); + } + final ArrayList children = CollectionLiterals.newArrayList(); + final Consumer _function_1 = (ExampleGroup child) -> { + JvmGenericType _infer = this.infer(acceptor, child, javaType, doLater, preIndexingPhase); + children.add(_infer); + }; + Iterables.filter(exampleGroup.getMembers(), ExampleGroup.class).forEach(_function_1); + boolean _isEmpty = children.isEmpty(); + boolean _not = (!_isEmpty); + if (_not) { + final Function1 _function_2 = (JvmGenericType it) -> { + return this._typeReferences.createTypeRef(it); + }; + this.getTestRuntime().addChildren(exampleGroup, javaType, ListExtensions.map(children, _function_2)); + } + _xblockexpression = javaType; + } + return _xblockexpression; + } + + @Override + public void initialize(final JnarioClass source, final JvmGenericType inferredJvmType) { + inferredJvmType.setVisibility(JvmVisibility.PUBLIC); + final Function1 _function = (XAnnotation it) -> { + JvmType _annotationType = null; + if (it!=null) { + _annotationType=it.getAnnotationType(); + } + return Boolean.valueOf((!Objects.equal(_annotationType, null))); + }; + this._extendedJvmTypesBuilder.addAnnotations(inferredJvmType, IterableExtensions.filter(source.getAnnotations(), _function)); + EList _annotations = inferredJvmType.getAnnotations(); + JvmAnnotationReference _annotationRef = this._annotationTypesBuilder.annotationRef(Named.class, this._exampleNameProvider.describe(source)); + this._extendedJvmTypesBuilder.operator_add(_annotations, _annotationRef); + JvmTypeReference _extends = source.getExtends(); + boolean _equals = Objects.equal(_extends, null); + if (_equals) { + final JvmTypeReference typeRefToObject = this._typeReferences.getTypeForName(Object.class, source); + boolean _notEquals = (!Objects.equal(typeRefToObject, null)); + if (_notEquals) { + inferredJvmType.getSuperTypes().add(typeRefToObject); + } + } else { + inferredJvmType.getSuperTypes().add(this._extendedJvmTypesBuilder.cloneWithProxies(source.getExtends())); + } + this.getTestRuntime().updateExampleGroup(source, inferredJvmType); + this.exampleIndex = 0; + EList _members = source.getMembers(); + for (final JnarioMember member : _members) { + this.transform(member, inferredJvmType); + } + this._implicitSubject.addImplicitSubject(inferredJvmType, ((ExampleGroup) source)); + this._extendedJvmTypesBuilder.copyDocumentationTo(source, inferredJvmType); + this._specSyntheticNameClashResolver.resolveNameClashes(inferredJvmType); + } + + protected void _transform(final Example element, final JvmGenericType container) { + this.exampleIndex = (this.exampleIndex + 1); + XExpression _expression = element.getExpression(); + boolean _equals = Objects.equal(_expression, null); + if (_equals) { + element.setExpression(XbaseFactory.eINSTANCE.createXBlockExpression()); + } + final JvmOperation method = this.toMethod(element, container); + this.getTestRuntime().markAsTestMethod(element, method); + boolean _isPending = element.isPending(); + if (_isPending) { + this.getTestRuntime().markAsPending(element, method); + } + EList _annotations = method.getAnnotations(); + JvmAnnotationReference _annotationRef = this._annotationTypesBuilder.annotationRef(Named.class, this._exampleNameProvider.describe(element)); + this._extendedJvmTypesBuilder.operator_add(_annotations, _annotationRef); + EList _annotations_1 = method.getAnnotations(); + JvmAnnotationReference _annotationRef_1 = this._annotationTypesBuilder.annotationRef(Order.class); + final Procedure1 _function = (JvmAnnotationReference it) -> { + EList _explicitValues = it.getExplicitValues(); + JvmIntAnnotationValue _createJvmIntAnnotationValue = this.typesFactory.createJvmIntAnnotationValue(); + final Procedure1 _function_1 = (JvmIntAnnotationValue it_1) -> { + EList _values = it_1.getValues(); + this._extendedJvmTypesBuilder.operator_add(_values, Integer.valueOf(this.exampleIndex)); + }; + JvmIntAnnotationValue _doubleArrow = ObjectExtensions.operator_doubleArrow(_createJvmIntAnnotationValue, _function_1); + this._extendedJvmTypesBuilder.operator_add(_explicitValues, _doubleArrow); + }; + JvmAnnotationReference _doubleArrow = ObjectExtensions.operator_doubleArrow(_annotationRef_1, _function); + this._extendedJvmTypesBuilder.operator_add(_annotations_1, _doubleArrow); + EList _members = container.getMembers(); + this._extendedJvmTypesBuilder.operator_add(_members, method); + this.modelAssociator.associatePrimary(element, method); + } + + protected void _transform(final Before element, final JvmGenericType container) { + final Procedure2 _function = (JnarioMember e, JvmOperation m) -> { + this.getTestRuntime().beforeMethod(e, m); + }; + final Procedure2 _function_1 = (JnarioMember e, JvmOperation m) -> { + this.getTestRuntime().beforeAllMethod(e, m); + }; + this.transformAround(element, container, _function, _function_1); + } + + protected void _transform(final After element, final JvmGenericType container) { + final Procedure2 _function = (JnarioMember e, JvmOperation m) -> { + this.getTestRuntime().afterMethod(e, m); + }; + final Procedure2 _function_1 = (JnarioMember e, JvmOperation m) -> { + this.getTestRuntime().afterAllMethod(e, m); + }; + this.transformAround(element, container, _function, _function_1); + } + + public boolean transformAround(final TestFunction element, final JvmGenericType container, final Procedure2 around, final Procedure2 aroundAll) { + boolean _xblockexpression = false; + { + final JvmOperation afterMethod = this.toMethod(element, container); + boolean _isStatic = element.isStatic(); + if (_isStatic) { + aroundAll.apply(((JnarioMember) element), afterMethod); + } else { + around.apply(element, afterMethod); + } + EList _members = container.getMembers(); + _xblockexpression = this._extendedJvmTypesBuilder.operator_add(_members, afterMethod); + } + return _xblockexpression; + } + + @Override + protected void _transform(final JnarioMember source, final JvmGenericType container) { + } + + public JvmOperation toMethod(final TestFunction element, final JvmGenericType container) { + JvmOperation _xblockexpression = null; + { + element.setReturnType(this._typeReferences.getTypeForName(Void.TYPE, element)); + JvmOperation _createJvmOperation = this.typesFactory.createJvmOperation(); + final Procedure1 _function = (JvmOperation it) -> { + it.setSimpleName(this._exampleNameProvider.toMethodName(element)); + it.setVisibility(JvmVisibility.PUBLIC); + it.setStatic(element.isStatic()); + it.setReturnType(this._typeReferences.getTypeForName(Void.TYPE, element)); + }; + final JvmOperation operation = ObjectExtensions.operator_doubleArrow(_createJvmOperation, _function); + this._extendedJvmTypesBuilder.setBody(operation, element.getExpression()); + final Function1 _function_1 = (XAnnotation it) -> { + JvmType _annotationType = null; + if (it!=null) { + _annotationType=it.getAnnotationType(); + } + return Boolean.valueOf((!Objects.equal(_annotationType, null))); + }; + this._extendedJvmTypesBuilder.addAnnotations(operation, IterableExtensions.filter(element.getAnnotations(), _function_1)); + this._extendedJvmTypesBuilder.copyDocumentationTo(element, operation); + container.getMembers().add(operation); + EList _exceptions = operation.getExceptions(); + JvmTypeReference _typeForName = this._typeReferences.getTypeForName(Exception.class, element); + this._extendedJvmTypesBuilder.operator_add(_exceptions, _typeForName); + _xblockexpression = operation; + } + return _xblockexpression; + } + + public void configureWith(final JvmGenericType type, final EObject source, final JnarioFile spec) { + EList _contents = spec.eResource().getContents(); + this._extendedJvmTypesBuilder.operator_add(_contents, type); + type.setPackageName(spec.getPackage()); + this._extendedJvmTypesBuilder.setDocumentation(type, this._extendedJvmTypesBuilder.getDocumentation(source)); + } + + protected void _transform(final ExampleTable table, final JvmGenericType specType) { + this.associateTableWithSpec(specType, table); + final Procedure1 _function = (JvmGenericType exampleTableType) -> { + EList _superTypes = exampleTableType.getSuperTypes(); + JvmTypeReference _typeForName = this._typeReferences.getTypeForName(ExampleTableRow.class, table); + this._extendedJvmTypesBuilder.operator_add(_superTypes, _typeForName); + this.configureWith(exampleTableType, table, this.jnarioFile(table)); + final JvmTypeReference type = this._typeReferences.getTypeForName(org.jnario.lib.ExampleTable.class, table, this._typeReferences.createTypeRef(exampleTableType)); + String _javaClassName = this._exampleNameProvider.toJavaClassName(table); + final String initMethodName = ("_init" + _javaClassName); + EList _members = specType.getMembers(); + final Procedure1 _function_1 = (JvmOperation it) -> { + final Procedure1 _function_2 = (ITreeAppendable a) -> { + it.setDeclaringType(specType); + this.generateInitializationMethod(table, a); + }; + this._extendedJvmTypesBuilder.setBody(it, _function_2); + }; + JvmOperation _method = this._extendedJvmTypesBuilder.toMethod(table, initMethodName, type, _function_1); + this._extendedJvmTypesBuilder.operator_add(_members, _method); + EList _members_1 = specType.getMembers(); + final Procedure1 _function_2 = (JvmField it) -> { + it.setVisibility(JvmVisibility.PROTECTED); + final Procedure1 _function_3 = (ITreeAppendable it_1) -> { + it_1.append(initMethodName).append("()"); + }; + this._extendedJvmTypesBuilder.setInitializer(it, _function_3); + }; + JvmField _field = this._extendedJvmTypesBuilder.toField(table, this._exampleNameProvider.toFieldName(table), type, _function_2); + this._extendedJvmTypesBuilder.operator_add(_members_1, _field); + final Procedure1 _function_3 = (JvmConstructor it) -> { + it.setSimpleName(exampleTableType.getSimpleName()); + }; + final JvmConstructor constructor = this._extendedJvmTypesBuilder.toConstructor(table, _function_3); + EList _members_2 = exampleTableType.getMembers(); + this._extendedJvmTypesBuilder.operator_add(_members_2, constructor); + final ArrayList assignments = CollectionLiterals.newArrayList(); + final JvmTypeReference stringType = this._typeReferences.getTypeForName(String.class, table); + final JvmTypeReference listType = this._typeReferences.getTypeForName(List.class, table, stringType); + final JvmFormalParameter cellNames = this.typesFactory.createJvmFormalParameter(); + cellNames.setName("cellNames"); + cellNames.setParameterType(listType); + EList _parameters = constructor.getParameters(); + this._extendedJvmTypesBuilder.operator_add(_parameters, cellNames); + assignments.add("super(cellNames);"); + this.index = 0; + final Consumer _function_4 = (ExampleColumn column) -> { + JvmTypeReference _xifexpression = null; + JvmTypeReference _type = column.getType(); + boolean _notEquals = (!Objects.equal(_type, null)); + if (_notEquals) { + _xifexpression = column.getType(); + } else { + _xifexpression = this._extendedJvmTypesBuilder.inferredType(); + } + final JvmTypeReference columnType = _xifexpression; + EList _members_3 = exampleTableType.getMembers(); + JvmField _field_1 = this._extendedJvmTypesBuilder.toField(column, column.getName(), this._extendedJvmTypesBuilder.cloneWithProxies(columnType)); + this._extendedJvmTypesBuilder.operator_add(_members_3, _field_1); + final JvmFormalParameter param = this._extendedJvmTypesBuilder.toParameter(column, column.getName(), this._extendedJvmTypesBuilder.cloneWithProxies(columnType)); + EList _parameters_1 = constructor.getParameters(); + this._extendedJvmTypesBuilder.operator_add(_parameters_1, param); + final JvmOperation getter = this._extendedJvmTypesBuilder.toGetter(column, column.getName(), this._extendedJvmTypesBuilder.cloneWithProxies(columnType)); + EList _members_4 = exampleTableType.getMembers(); + this._extendedJvmTypesBuilder.operator_add(_members_4, getter); + String _name = column.getName(); + String _plus = ("this." + _name); + String _plus_1 = (_plus + " = "); + String _name_1 = column.getName(); + String _plus_2 = (_plus_1 + _name_1); + String _plus_3 = (_plus_2 + ";"); + assignments.add(_plus_3); + }; + table.getColumns().forEach(_function_4); + final Consumer _function_5 = (ExampleRow it) -> { + final Consumer _function_6 = (ExampleCell it_1) -> { + this.generateCellInitializerMethod(specType, this.initMethodName(table, this.index), it_1); + this.index = (this.index + 1); + }; + it.getCells().forEach(_function_6); + }; + table.getRows().forEach(_function_5); + final Procedure1 _function_6 = (ITreeAppendable a) -> { + final Consumer _function_7 = (String it) -> { + a.append(it).newLine(); + }; + assignments.forEach(_function_7); + }; + this._extendedJvmTypesBuilder.setBody(constructor, _function_6); + }; + this._extendedJvmTypesBuilder.toClass(this.jnarioFile(table), this._exampleNameProvider.toJavaClassName(table), _function); + } + + public void generateInitializationMethod(final ExampleTable exampleTable, final ITreeAppendable appendable) { + final JvmType arraysType = this._typeReferences.getTypeForName(Arrays.class, exampleTable).getType(); + String _fieldName = this._exampleNameProvider.toFieldName(exampleTable); + String _plus = ("return ExampleTable.create(\"" + _fieldName); + String _plus_1 = (_plus + "\", \n"); + appendable.append(_plus_1); + ITreeAppendable _append = appendable.append(" ").append(arraysType).append(".asList(\""); + String _join = IterableExtensions.join(this.columnNames(exampleTable), "\", \""); + String _plus_2 = (_join + "\"), "); + _append.append(_plus_2); + appendable.increaseIndentation(); + appendable.append("\n"); + this.index = 0; + EList _rows = exampleTable.getRows(); + for (final ExampleRow row : _rows) { + { + appendable.append("new ").append(this._exampleNameProvider.toJavaClassName(exampleTable)).append("("); + ITreeAppendable _append_1 = appendable.append(" ").append(arraysType); + final Function1 _function = (ExampleCell it) -> { + return Strings.convertToJavaString(this.serialize(it).trim()); + }; + String _join_1 = IterableExtensions.join(ListExtensions.map(row.getCells(), _function), "\", \""); + String _plus_3 = (".asList(\"" + _join_1); + String _plus_4 = (_plus_3 + "\"), "); + _append_1.append(_plus_4); + EList _cells = row.getCells(); + for (final ExampleCell cell : _cells) { + { + XExpression _expression = cell.getExpression(); + if ((_expression instanceof XNullLiteral)) { + appendable.append("null"); + } else { + String _initMethodName = this.initMethodName(exampleTable, this.index); + String _plus_5 = (_initMethodName + "()"); + appendable.append(_plus_5); + } + this.index = (this.index + 1); + ExampleCell _last = IterableExtensions.last(row.getCells()); + boolean _notEquals = (!Objects.equal(_last, cell)); + if (_notEquals) { + appendable.append(", "); + } + } + } + appendable.append(")"); + ExampleRow _last = IterableExtensions.last(exampleTable.getRows()); + boolean _notEquals = (!Objects.equal(_last, row)); + if (_notEquals) { + appendable.append(",\n"); + } + } + } + appendable.decreaseIndentation(); + appendable.append("\n);"); + } + + public void associateTableWithSpec(final JvmGenericType type, final ExampleTable table) { + EList _rows = table.getRows(); + for (final ExampleRow row : _rows) { + this._extendedJvmTypesBuilder.associate(row, type); + } + } + + public String initMethodName(final ExampleTable exampleTable, final int i) { + String _javaClassName = this._exampleNameProvider.toJavaClassName(exampleTable); + String _plus = ("_init" + _javaClassName); + String _plus_1 = (_plus + "Cell"); + return (_plus_1 + Integer.valueOf(i)); + } + + public boolean generateCellInitializerMethod(final JvmGenericType specType, final String name, final ExampleCell cell) { + EList _members = specType.getMembers(); + final Procedure1 _function = (JvmOperation it) -> { + it.setDeclaringType(specType); + this._extendedJvmTypesBuilder.setBody(it, cell.getExpression()); + }; + JvmOperation _method = this._extendedJvmTypesBuilder.toMethod(cell, name, this._extendedJvmTypesBuilder.inferredType(), _function); + return this._extendedJvmTypesBuilder.operator_add(_members, _method); + } + + public List columnNames(final ExampleTable exampleTable) { + final Function1 _function = (ExampleColumn it) -> { + String _name = null; + if (it!=null) { + _name=it.getName(); + } + return _name; + }; + return ListExtensions.map(exampleTable.getColumns(), _function); + } + + protected void transform(final JnarioMember element, final JvmGenericType container) { + if (element instanceof After) { + _transform((After)element, container); + return; + } else if (element instanceof Before) { + _transform((Before)element, container); + return; + } else if (element instanceof Example) { + _transform((Example)element, container); + return; + } else if (element instanceof ExampleTable) { + _transform((ExampleTable)element, container); + return; + } else if (element instanceof JnarioField) { + _transform((JnarioField)element, container); + return; + } else if (element instanceof JnarioFunction) { + _transform((JnarioFunction)element, container); + return; + } else if (element != null) { + _transform(element, container); + return; + } else { + throw new IllegalArgumentException("Unhandled parameter types: " + + Arrays.asList(element, container).toString()); + } + } +} diff --git a/plugins/org.jnario.spec/xtend-gen/org/jnario/spec/scoping/SpecResourceDescriptionStrategy.java b/plugins/org.jnario.spec/xtend-gen/org/jnario/spec/scoping/SpecResourceDescriptionStrategy.java index 47a2daca2..e49ecbe3f 100644 --- a/plugins/org.jnario.spec/xtend-gen/org/jnario/spec/scoping/SpecResourceDescriptionStrategy.java +++ b/plugins/org.jnario.spec/xtend-gen/org/jnario/spec/scoping/SpecResourceDescriptionStrategy.java @@ -1,163 +1,163 @@ -/** - * Copyright (c) 2012 BMW Car IT and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.jnario.spec.scoping; - -import com.google.common.collect.ImmutableMap; -import com.google.inject.Inject; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.xtext.common.types.JvmOperation; -import org.eclipse.xtext.common.types.JvmType; -import org.eclipse.xtext.common.types.JvmTypeReference; -import org.eclipse.xtext.common.types.JvmVoid; -import org.eclipse.xtext.naming.QualifiedName; -import org.eclipse.xtext.resource.IEObjectDescription; -import org.eclipse.xtext.resource.IResourceDescription; -import org.eclipse.xtext.resource.IResourceDescriptions; -import org.eclipse.xtext.xbase.lib.Functions.Function1; -import org.eclipse.xtext.xbase.lib.IterableExtensions; -import org.jnario.scoping.JnarioResourceDescriptionStrategy; -import org.jnario.spec.naming.OperationNameProvider; -import org.jnario.spec.spec.ExampleGroup; -import org.jnario.spec.spec.SpecPackage; -import org.jnario.util.Nodes; - -@SuppressWarnings("all") -public class SpecResourceDescriptionStrategy extends JnarioResourceDescriptionStrategy { - public final static String ROOT_SPEC = "root"; - - public final static String TRUE = "1"; - - public final static String FALSE = "0"; - - public final static String EXAMPLE_TYPE = "type"; - - public final static String EXAMPLE_OPERATION = "operation"; - - @Inject - private OperationNameProvider operationNameProvider; - - @Override - public void createUserData(final EObject eObject, final ImmutableMap.Builder userData) { - super.createUserData(eObject, userData); - if ((eObject instanceof ExampleGroup)) { - final ExampleGroup exampleGroup = ((ExampleGroup) eObject); - userData.put(SpecResourceDescriptionStrategy.ROOT_SPEC, String.valueOf(this.isRoot(exampleGroup))); - userData.put(SpecResourceDescriptionStrategy.EXAMPLE_TYPE, this.getTargetName(exampleGroup)); - userData.put(SpecResourceDescriptionStrategy.EXAMPLE_OPERATION, this.getTargetOperation(exampleGroup)); - } - } - - protected String getTargetName(final ExampleGroup exampleGroup) { - Object _eGet = exampleGroup.eGet(SpecPackage.Literals.EXAMPLE_GROUP__TARGET_TYPE, false); - final JvmTypeReference targetType = ((JvmTypeReference) _eGet); - if (((targetType != null) && (!targetType.eIsProxy()))) { - JvmType _type = targetType.getType(); - boolean _not = (!(_type instanceof JvmVoid)); - if (_not) { - return exampleGroup.getTargetType().getSimpleName(); - } - } - return SpecResourceDescriptionStrategy.retrieveNameFromNodeModel(exampleGroup); - } - - protected String getTargetOperation(final ExampleGroup exampleGroup) { - String _xblockexpression = null; - { - Object _eGet = exampleGroup.eGet(SpecPackage.Literals.EXAMPLE_GROUP__TARGET_OPERATION, false); - final JvmOperation targetOperation = ((JvmOperation) _eGet); - if (((targetOperation != null) && (!targetOperation.eIsProxy()))) { - return this.operationNameProvider.apply(targetOperation).toString(); - } - _xblockexpression = SpecResourceDescriptionStrategy.getTargetOperationFromNodeModel(exampleGroup); - } - return _xblockexpression; - } - - protected static String getTargetOperationFromNodeModel(final ExampleGroup exampleGroup) { - return Nodes.textForFeature(exampleGroup, SpecPackage.Literals.EXAMPLE_GROUP__TARGET_OPERATION); - } - - public String isRoot(final ExampleGroup exampleGroup) { - String _xifexpression = null; - EObject _eContainer = exampleGroup.eContainer(); - boolean _not = (!(_eContainer instanceof ExampleGroup)); - if (_not) { - _xifexpression = SpecResourceDescriptionStrategy.TRUE; - } else { - _xifexpression = SpecResourceDescriptionStrategy.FALSE; - } - return _xifexpression; - } - - public static String getTypeName(final IEObjectDescription specDescription) { - return specDescription.getUserData(SpecResourceDescriptionStrategy.EXAMPLE_TYPE); - } - - public static String getTargetOperation(final IEObjectDescription specDescription) { - return specDescription.getUserData(SpecResourceDescriptionStrategy.EXAMPLE_OPERATION); - } - - public static String getTypeName(final IResourceDescriptions index, final ExampleGroup exampleGroup) { - final IResourceDescription localizedIndex = SpecResourceDescriptionStrategy.getLocalizedIndex(index, exampleGroup); - if ((localizedIndex != null)) { - final Iterable result = localizedIndex.getExportedObjectsByObject(exampleGroup); - String _elvis = null; - final Function1 _function = (IEObjectDescription it) -> { - return SpecResourceDescriptionStrategy.getTypeName(it); - }; - String _head = IterableExtensions.head(IterableExtensions.map(result, _function)); - if (_head != null) { - _elvis = _head; - } else { - String _retrieveNameFromNodeModel = SpecResourceDescriptionStrategy.retrieveNameFromNodeModel(exampleGroup); - _elvis = _retrieveNameFromNodeModel; - } - return _elvis; - } - return SpecResourceDescriptionStrategy.retrieveNameFromNodeModel(exampleGroup); - } - - public static QualifiedName getOperationName(final IResourceDescriptions index, final ExampleGroup exampleGroup) { - final IResourceDescription localizedIndex = SpecResourceDescriptionStrategy.getLocalizedIndex(index, exampleGroup); - if ((localizedIndex != null)) { - final Iterable result = localizedIndex.getExportedObjectsByObject(exampleGroup); - String _elvis = null; - final Function1 _function = (IEObjectDescription it) -> { - return SpecResourceDescriptionStrategy.getTargetOperation(it); - }; - String _head = IterableExtensions.head(IterableExtensions.map(result, _function)); - if (_head != null) { - _elvis = _head; - } else { - String _targetOperationFromNodeModel = SpecResourceDescriptionStrategy.getTargetOperationFromNodeModel(exampleGroup); - _elvis = _targetOperationFromNodeModel; - } - return QualifiedName.create(_elvis); - } - return QualifiedName.create(SpecResourceDescriptionStrategy.getTargetOperationFromNodeModel(exampleGroup)); - } - - private static IResourceDescription getLocalizedIndex(final IResourceDescriptions index, final EObject context) { - if ((index instanceof IResourceDescriptions.IContextAware)) { - ((IResourceDescriptions.IContextAware) index).setContext(context); - } - return index.getResourceDescription(context.eResource().getURI()); - } - - private static String retrieveNameFromNodeModel(final ExampleGroup exampleGroup) { - String text = Nodes.textForFeature(exampleGroup, SpecPackage.Literals.EXAMPLE_GROUP__TARGET_TYPE); - int _max = Math.max(text.lastIndexOf(Character.valueOf('.').charValue()), - text.lastIndexOf(Character.valueOf('$').charValue())); - int begin = (_max + 1); - int end = text.indexOf(Character.valueOf('<').charValue()); - if ((end == (-1))) { - end = text.length(); - } - return text.substring(begin, end); - } -} +/** + * Copyright (c) 2012 BMW Car IT and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.jnario.spec.scoping; + +import com.google.common.collect.ImmutableMap; +import com.google.inject.Inject; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.xtext.common.types.JvmOperation; +import org.eclipse.xtext.common.types.JvmType; +import org.eclipse.xtext.common.types.JvmTypeReference; +import org.eclipse.xtext.common.types.JvmVoid; +import org.eclipse.xtext.naming.QualifiedName; +import org.eclipse.xtext.resource.IEObjectDescription; +import org.eclipse.xtext.resource.IResourceDescription; +import org.eclipse.xtext.resource.IResourceDescriptions; +import org.eclipse.xtext.xbase.lib.Functions.Function1; +import org.eclipse.xtext.xbase.lib.IterableExtensions; +import org.jnario.scoping.JnarioResourceDescriptionStrategy; +import org.jnario.spec.naming.OperationNameProvider; +import org.jnario.spec.spec.ExampleGroup; +import org.jnario.spec.spec.SpecPackage; +import org.jnario.util.Nodes; + +@SuppressWarnings("all") +public class SpecResourceDescriptionStrategy extends JnarioResourceDescriptionStrategy { + public final static String ROOT_SPEC = "root"; + + public final static String TRUE = "1"; + + public final static String FALSE = "0"; + + public final static String EXAMPLE_TYPE = "type"; + + public final static String EXAMPLE_OPERATION = "operation"; + + @Inject + private OperationNameProvider operationNameProvider; + + @Override + public void createUserData(final EObject eObject, final ImmutableMap.Builder userData) { + super.createUserData(eObject, userData); + if ((eObject instanceof ExampleGroup)) { + final ExampleGroup exampleGroup = ((ExampleGroup) eObject); + userData.put(SpecResourceDescriptionStrategy.ROOT_SPEC, String.valueOf(this.isRoot(exampleGroup))); + userData.put(SpecResourceDescriptionStrategy.EXAMPLE_TYPE, this.getTargetName(exampleGroup)); + userData.put(SpecResourceDescriptionStrategy.EXAMPLE_OPERATION, this.getTargetOperation(exampleGroup)); + } + } + + protected String getTargetName(final ExampleGroup exampleGroup) { + Object _eGet = exampleGroup.eGet(SpecPackage.Literals.EXAMPLE_GROUP__TARGET_TYPE, false); + final JvmTypeReference targetType = ((JvmTypeReference) _eGet); + if (((targetType != null) && (!targetType.eIsProxy()))) { + JvmType _type = targetType.getType(); + boolean _not = (!(_type instanceof JvmVoid)); + if (_not) { + return exampleGroup.getTargetType().getSimpleName(); + } + } + return SpecResourceDescriptionStrategy.retrieveNameFromNodeModel(exampleGroup); + } + + protected String getTargetOperation(final ExampleGroup exampleGroup) { + String _xblockexpression = null; + { + Object _eGet = exampleGroup.eGet(SpecPackage.Literals.EXAMPLE_GROUP__TARGET_OPERATION, false); + final JvmOperation targetOperation = ((JvmOperation) _eGet); + if (((targetOperation != null) && (!targetOperation.eIsProxy()))) { + return this.operationNameProvider.apply(targetOperation).toString(); + } + _xblockexpression = SpecResourceDescriptionStrategy.getTargetOperationFromNodeModel(exampleGroup); + } + return _xblockexpression; + } + + protected static String getTargetOperationFromNodeModel(final ExampleGroup exampleGroup) { + return Nodes.textForFeature(exampleGroup, SpecPackage.Literals.EXAMPLE_GROUP__TARGET_OPERATION); + } + + public String isRoot(final ExampleGroup exampleGroup) { + String _xifexpression = null; + EObject _eContainer = exampleGroup.eContainer(); + boolean _not = (!(_eContainer instanceof ExampleGroup)); + if (_not) { + _xifexpression = SpecResourceDescriptionStrategy.TRUE; + } else { + _xifexpression = SpecResourceDescriptionStrategy.FALSE; + } + return _xifexpression; + } + + public static String getTypeName(final IEObjectDescription specDescription) { + return specDescription.getUserData(SpecResourceDescriptionStrategy.EXAMPLE_TYPE); + } + + public static String getTargetOperation(final IEObjectDescription specDescription) { + return specDescription.getUserData(SpecResourceDescriptionStrategy.EXAMPLE_OPERATION); + } + + public static String getTypeName(final IResourceDescriptions index, final ExampleGroup exampleGroup) { + final IResourceDescription localizedIndex = SpecResourceDescriptionStrategy.getLocalizedIndex(index, exampleGroup); + if ((localizedIndex != null)) { + final Iterable result = localizedIndex.getExportedObjectsByObject(exampleGroup); + String _elvis = null; + final Function1 _function = (IEObjectDescription it) -> { + return SpecResourceDescriptionStrategy.getTypeName(it); + }; + String _head = IterableExtensions.head(IterableExtensions.map(result, _function)); + if (_head != null) { + _elvis = _head; + } else { + String _retrieveNameFromNodeModel = SpecResourceDescriptionStrategy.retrieveNameFromNodeModel(exampleGroup); + _elvis = _retrieveNameFromNodeModel; + } + return _elvis; + } + return SpecResourceDescriptionStrategy.retrieveNameFromNodeModel(exampleGroup); + } + + public static QualifiedName getOperationName(final IResourceDescriptions index, final ExampleGroup exampleGroup) { + final IResourceDescription localizedIndex = SpecResourceDescriptionStrategy.getLocalizedIndex(index, exampleGroup); + if ((localizedIndex != null)) { + final Iterable result = localizedIndex.getExportedObjectsByObject(exampleGroup); + String _elvis = null; + final Function1 _function = (IEObjectDescription it) -> { + return SpecResourceDescriptionStrategy.getTargetOperation(it); + }; + String _head = IterableExtensions.head(IterableExtensions.map(result, _function)); + if (_head != null) { + _elvis = _head; + } else { + String _targetOperationFromNodeModel = SpecResourceDescriptionStrategy.getTargetOperationFromNodeModel(exampleGroup); + _elvis = _targetOperationFromNodeModel; + } + return QualifiedName.create(_elvis); + } + return QualifiedName.create(SpecResourceDescriptionStrategy.getTargetOperationFromNodeModel(exampleGroup)); + } + + private static IResourceDescription getLocalizedIndex(final IResourceDescriptions index, final EObject context) { + if ((index instanceof IResourceDescriptions.IContextAware)) { + ((IResourceDescriptions.IContextAware) index).setContext(context); + } + return index.getResourceDescription(context.eResource().getURI()); + } + + private static String retrieveNameFromNodeModel(final ExampleGroup exampleGroup) { + String text = Nodes.textForFeature(exampleGroup, SpecPackage.Literals.EXAMPLE_GROUP__TARGET_TYPE); + int _max = Math.max(text.lastIndexOf(Character.valueOf('.').charValue()), + text.lastIndexOf(Character.valueOf('$').charValue())); + int begin = (_max + 1); + int end = text.indexOf(Character.valueOf('<').charValue()); + if ((end == (-1))) { + end = text.length(); + } + return text.substring(begin, end); + } +} diff --git a/plugins/org.jnario.spec/xtend-gen/org/jnario/spec/validation/SpecModifierValidator.java b/plugins/org.jnario.spec/xtend-gen/org/jnario/spec/validation/SpecModifierValidator.java index 1b69a20d5..da0fa1a03 100644 --- a/plugins/org.jnario.spec/xtend-gen/org/jnario/spec/validation/SpecModifierValidator.java +++ b/plugins/org.jnario.spec/xtend-gen/org/jnario/spec/validation/SpecModifierValidator.java @@ -1,5 +1,5 @@ -package org.jnario.spec.validation; - -@SuppressWarnings("all") -public class SpecModifierValidator { -} +package org.jnario.spec.validation; + +@SuppressWarnings("all") +public class SpecModifierValidator { +} diff --git a/plugins/org.jnario.standalone/xtend-gen/org/jnario/compiler/CompileTask.java b/plugins/org.jnario.standalone/xtend-gen/org/jnario/compiler/CompileTask.java index 96ec5f061..9d7b9ba94 100644 --- a/plugins/org.jnario.standalone/xtend-gen/org/jnario/compiler/CompileTask.java +++ b/plugins/org.jnario.standalone/xtend-gen/org/jnario/compiler/CompileTask.java @@ -1,159 +1,150 @@ -package org.jnario.compiler; - -import com.google.common.base.Objects; -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.Task; -import org.apache.tools.ant.types.Path; -import org.apache.tools.ant.types.Reference; -import org.eclipse.xtend.lib.Property; -import org.eclipse.xtext.xbase.lib.ObjectExtensions; -import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; -import org.eclipse.xtext.xbase.lib.Pure; -import org.jnario.compiler.CompilerMain; - -@SuppressWarnings("all") -public class CompileTask extends Task { - /** - * Set target for the generated Java source. Default is "xtend-gen". - */ - @Property - private String _outputPath = "xtend-gen"; - - private Path classPath = null; - - /** - * Set the temporary folder to use. Default is a temporary folder obtained via System::getProperty("java.io.tmpdir"). - */ - @Property - private String _tempDirectory = System.getProperty("java.io.tmpdir"); - - /** - * The spec encoding. Default is UTF-8. - */ - @Property - private String _fileEncoding = "UTF-8"; - - private Path sourcePath = null; - - @Override - public void execute() throws BuildException { - CompilerMain _compilerMain = new CompilerMain(); - final Procedure1 _function = new Procedure1() { - @Override - public void apply(final CompilerMain it) { - String _outputPath = CompileTask.this.getOutputPath(); - it.setOutputPath(_outputPath); - String _string = CompileTask.this.classPath.toString(); - it.setClassPath(_string); - String _tempDirectory = CompileTask.this.getTempDirectory(); - it.setTempDirectory(_tempDirectory); - String _fileEncoding = CompileTask.this.getFileEncoding(); - it.setFileEncoding(_fileEncoding); - String _string_1 = CompileTask.this.sourcePath.toString(); - it.setSourcePath(_string_1); - } - }; - final CompilerMain compiler = ObjectExtensions.operator_doubleArrow(_compilerMain, _function); - int _compile = compiler.compile(); - boolean _equals = (_compile == CompilerMain.COMPILATION_ERROR); - if (_equals) { - throw new BuildException("Error when compiling Jnario specs"); - } - } - - /** - * Set the sourcepath to use by reference. - * - * @param r a reference to an existing sourcepath. - */ - public void setSourcepathRef(final Reference r) { - Path _createSourcepath = this.createSourcepath(); - _createSourcepath.setRefid(r); - } - - /** - * Set the sourcepath to be used when compiling the Jnario specs. - * - * @param s an Ant Path object containing the sourcepath. - */ - public void setSourcepath(final Path s) { - Path _createSourcepath = this.createSourcepath(); - _createSourcepath.append(s); - } - - /** - * Set the classpath to use by reference. - * - * @param r a reference to an existing classpath. - */ - public void setClasspathRef(final Reference r) { - Path _createClasspath = this.createClasspath(); - _createClasspath.setRefid(r); - } - - /** - * Set the classpath to be used when compiling the Jnario specs. - * - * @param s an Ant Path object containing the classpath. - */ - public void setClasspath(final Path s) { - Path _createClasspath = this.createClasspath(); - _createClasspath.append(s); - } - - private Path createClasspath() { - Path _xblockexpression = null; - { - boolean _equals = Objects.equal(this.classPath, null); - if (_equals) { - Project _project = this.getProject(); - Path _path = new Path(_project); - this.classPath = _path; - } - _xblockexpression = this.classPath; - } - return _xblockexpression; - } - - private Path createSourcepath() { - Path _xblockexpression = null; - { - boolean _equals = Objects.equal(this.sourcePath, null); - if (_equals) { - Project _project = this.getProject(); - Path _path = new Path(_project); - this.sourcePath = _path; - } - _xblockexpression = this.sourcePath; - } - return _xblockexpression; - } - - @Pure - public String getOutputPath() { - return this._outputPath; - } - - public void setOutputPath(final String outputPath) { - this._outputPath = outputPath; - } - - @Pure - public String getTempDirectory() { - return this._tempDirectory; - } - - public void setTempDirectory(final String tempDirectory) { - this._tempDirectory = tempDirectory; - } - - @Pure - public String getFileEncoding() { - return this._fileEncoding; - } - - public void setFileEncoding(final String fileEncoding) { - this._fileEncoding = fileEncoding; - } -} +package org.jnario.compiler; + +import com.google.common.base.Objects; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.Task; +import org.apache.tools.ant.types.Path; +import org.apache.tools.ant.types.Reference; +import org.eclipse.xtend.lib.Property; +import org.eclipse.xtext.xbase.lib.ObjectExtensions; +import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; +import org.eclipse.xtext.xbase.lib.Pure; +import org.jnario.compiler.CompilerMain; + +@SuppressWarnings("all") +public class CompileTask extends Task { + /** + * Set target for the generated Java source. Default is "xtend-gen". + */ + @Property + private String _outputPath = "xtend-gen"; + + private Path classPath = null; + + /** + * Set the temporary folder to use. Default is a temporary folder obtained via System::getProperty("java.io.tmpdir"). + */ + @Property + private String _tempDirectory = System.getProperty("java.io.tmpdir"); + + /** + * The spec encoding. Default is UTF-8. + */ + @Property + private String _fileEncoding = "UTF-8"; + + private Path sourcePath = null; + + @Override + public void execute() throws BuildException { + CompilerMain _compilerMain = new CompilerMain(); + final Procedure1 _function = new Procedure1() { + @Override + public void apply(final CompilerMain it) { + it.setOutputPath(CompileTask.this.getOutputPath()); + it.setClassPath(CompileTask.this.classPath.toString()); + it.setTempDirectory(CompileTask.this.getTempDirectory()); + it.setFileEncoding(CompileTask.this.getFileEncoding()); + it.setSourcePath(CompileTask.this.sourcePath.toString()); + } + }; + final CompilerMain compiler = ObjectExtensions.operator_doubleArrow(_compilerMain, _function); + int _compile = compiler.compile(); + boolean _equals = (_compile == CompilerMain.COMPILATION_ERROR); + if (_equals) { + throw new BuildException("Error when compiling Jnario specs"); + } + } + + /** + * Set the sourcepath to use by reference. + * + * @param r a reference to an existing sourcepath. + */ + public void setSourcepathRef(final Reference r) { + this.createSourcepath().setRefid(r); + } + + /** + * Set the sourcepath to be used when compiling the Jnario specs. + * + * @param s an Ant Path object containing the sourcepath. + */ + public void setSourcepath(final Path s) { + this.createSourcepath().append(s); + } + + /** + * Set the classpath to use by reference. + * + * @param r a reference to an existing classpath. + */ + public void setClasspathRef(final Reference r) { + this.createClasspath().setRefid(r); + } + + /** + * Set the classpath to be used when compiling the Jnario specs. + * + * @param s an Ant Path object containing the classpath. + */ + public void setClasspath(final Path s) { + this.createClasspath().append(s); + } + + private Path createClasspath() { + Path _xblockexpression = null; + { + boolean _equals = Objects.equal(this.classPath, null); + if (_equals) { + Project _project = this.getProject(); + Path _path = new Path(_project); + this.classPath = _path; + } + _xblockexpression = this.classPath; + } + return _xblockexpression; + } + + private Path createSourcepath() { + Path _xblockexpression = null; + { + boolean _equals = Objects.equal(this.sourcePath, null); + if (_equals) { + Project _project = this.getProject(); + Path _path = new Path(_project); + this.sourcePath = _path; + } + _xblockexpression = this.sourcePath; + } + return _xblockexpression; + } + + @Pure + public String getOutputPath() { + return this._outputPath; + } + + public void setOutputPath(final String outputPath) { + this._outputPath = outputPath; + } + + @Pure + public String getTempDirectory() { + return this._tempDirectory; + } + + public void setTempDirectory(final String tempDirectory) { + this._tempDirectory = tempDirectory; + } + + @Pure + public String getFileEncoding() { + return this._fileEncoding; + } + + public void setFileEncoding(final String fileEncoding) { + this._fileEncoding = fileEncoding; + } +} diff --git a/plugins/org.jnario.standalone/xtend-gen/org/jnario/compiler/DocCompilerMain.java b/plugins/org.jnario.standalone/xtend-gen/org/jnario/compiler/DocCompilerMain.java index 59e710a3c..7abc2cbe3 100644 --- a/plugins/org.jnario.standalone/xtend-gen/org/jnario/compiler/DocCompilerMain.java +++ b/plugins/org.jnario.standalone/xtend-gen/org/jnario/compiler/DocCompilerMain.java @@ -1,261 +1,241 @@ -/** - * Copyright (c) 2012 BMW Car IT and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.jnario.compiler; - -import com.google.common.base.Objects; -import com.google.common.io.Closeables; -import com.google.inject.Injector; -import com.google.inject.Provider; -import java.io.File; -import java.io.FileFilter; -import java.io.FileInputStream; -import java.util.Iterator; -import java.util.List; -import org.apache.log4j.BasicConfigurator; -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.resource.ResourceSet; -import org.eclipse.xtend.lib.Property; -import org.eclipse.xtext.ISetup; -import org.eclipse.xtext.xbase.lib.CollectionLiterals; -import org.eclipse.xtext.xbase.lib.Conversions; -import org.eclipse.xtext.xbase.lib.Exceptions; -import org.eclipse.xtext.xbase.lib.InputOutput; -import org.eclipse.xtext.xbase.lib.ObjectExtensions; -import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; -import org.eclipse.xtext.xbase.lib.Pure; -import org.jnario.compiler.CompilerMain; -import org.jnario.compiler.HtmlAssetsCompiler; -import org.jnario.compiler.JnarioDocCompiler; -import org.jnario.compiler.StandaloneResourceProvider; -import org.jnario.feature.FeatureStandaloneSetup; -import org.jnario.report.HashBasedSpec2ResultMapping; -import org.jnario.report.SpecResultParser; -import org.jnario.spec.SpecStandaloneSetup; -import org.jnario.suite.SuiteStandaloneSetup; - -@SuppressWarnings("all") -public class DocCompilerMain { - public static void main(final String[] args) { - if ((Objects.equal(args, null) || (((List)Conversions.doWrapArray(args)).size() == 0))) { - DocCompilerMain.printUsage(); - return; - } - DocCompilerMain _docCompilerMain = new DocCompilerMain(); - final Procedure1 _function = new Procedure1() { - @Override - public void apply(final DocCompilerMain it) { - final Iterator arguments = ((List)Conversions.doWrapArray(args)).iterator(); - while (arguments.hasNext()) { - { - String _next = arguments.next(); - final String argument = _next.trim(); - boolean _matched = false; - if ((Objects.equal(argument, "-cp") || Objects.equal(argument, "-classpath"))) { - _matched=true; - String _next_1 = arguments.next(); - it.setClassPath(_next_1); - } - if (!_matched) { - if (Objects.equal(argument, "-d")) { - _matched=true; - String _next_2 = arguments.next(); - it.setOutputPath(_next_2); - } - } - if (!_matched) { - if (Objects.equal(argument, "-results")) { - _matched=true; - String _next_3 = arguments.next(); - it.setResultFolder(_next_3); - } - } - if (!_matched) { - if (Objects.equal(argument, "-encoding")) { - _matched=true; - String _next_4 = arguments.next(); - it.setFileEncoding(_next_4); - } - } - if (!_matched) { - it.setSourcePath(argument); - } - } - } - } - }; - final DocCompilerMain main = ObjectExtensions.operator_doubleArrow(_docCompilerMain, _function); - int _compile = main.compile(); - System.exit(_compile); - } - - @Property - private String _outputPath = "doc-gen"; - - @Property - private String _classPath = ""; - - @Property - private String _resultFolder = ""; - - @Property - private String _fileEncoding = "UTF-8"; - - @Property - private String _sourcePath = "."; - - public int compile() { - int _xblockexpression = (int) 0; - { - BasicConfigurator.configure(); - ISetup _get = DocCompilerMain.SETUPS.get(0); - final Injector anyInjector = _get.createInjectorAndDoEMFRegistration(); - final ResourceSet resourceSet = anyInjector.getInstance(ResourceSet.class); - this.generateCssAndJsFiles(anyInjector); - StandaloneResourceProvider _standaloneResourceProvider = new StandaloneResourceProvider(resourceSet); - _xblockexpression = this.generateDocs(_standaloneResourceProvider); - } - return _xblockexpression; - } - - private int generateDocs(final Provider resourceSet) { - for (final ISetup setup : DocCompilerMain.SETUPS) { - { - final Injector injector = setup.createInjectorAndDoEMFRegistration(); - final JnarioDocCompiler jnarioCompiler = injector.getInstance(JnarioDocCompiler.class); - String _outputPath = this.getOutputPath(); - jnarioCompiler.setOutputPath(_outputPath); - String _classPath = this.getClassPath(); - jnarioCompiler.setClassPath(_classPath); - String _fileEncoding = this.getFileEncoding(); - jnarioCompiler.setFileEncoding(_fileEncoding); - String _sourcePath = this.getSourcePath(); - jnarioCompiler.setSourcePath(_sourcePath); - ResourceSet _get = resourceSet.get(); - EList _eAdapters = _get.eAdapters(); - _eAdapters.clear(); - jnarioCompiler.setResourceSetProvider(resourceSet); - HashBasedSpec2ResultMapping _createSpec2ResultMapping = this.createSpec2ResultMapping(); - jnarioCompiler.setExecutable2ResultMapping(_createSpec2ResultMapping); - boolean _compile = jnarioCompiler.compile(); - boolean _not = (!_compile); - if (_not) { - return CompilerMain.COMPILATION_ERROR; - } - } - } - return CompilerMain.OK; - } - - private static void printUsage() { - InputOutput.println("Usage: JnarioDocCompiler "); - InputOutput.println("where possible options include:"); - InputOutput.println("-d Specify where to place generated documentation files"); - InputOutput.println("-results Specify folder containing JUnit XML test results"); - InputOutput.println("-encoding Specify character encoding used by source files"); - } - - public HashBasedSpec2ResultMapping createSpec2ResultMapping() { - ISetup _get = DocCompilerMain.SETUPS.get(2); - Injector _createInjectorAndDoEMFRegistration = _get.createInjectorAndDoEMFRegistration(); - final HashBasedSpec2ResultMapping resultMapping = _createInjectorAndDoEMFRegistration.getInstance(HashBasedSpec2ResultMapping.class); - String _resultFolder = this.getResultFolder(); - final File reportFolder = new File(_resultFolder); - boolean _exists = reportFolder.exists(); - if (_exists) { - this.addExecutionResults(resultMapping, reportFolder); - } - return resultMapping; - } - - public boolean generateCssAndJsFiles(final Injector injector) { - boolean _xblockexpression = false; - { - final HtmlAssetsCompiler assetsCompiler = injector.getInstance(HtmlAssetsCompiler.class); - String _outputPath = this.getOutputPath(); - assetsCompiler.setOutputPath(_outputPath); - _xblockexpression = assetsCompiler.compile(); - } - return _xblockexpression; - } - - public void addExecutionResults(final HashBasedSpec2ResultMapping resultMapping, final File reportFolder) { - try { - final SpecResultParser specResultParser = new SpecResultParser(); - final FileFilter _function = new FileFilter() { - @Override - public boolean accept(final File it) { - String _name = it.getName(); - return _name.endsWith("xml"); - } - }; - File[] _listFiles = reportFolder.listFiles(_function); - for (final File file : _listFiles) { - { - FileInputStream is = null; - try { - FileInputStream _fileInputStream = new FileInputStream(file); - is = _fileInputStream; - specResultParser.parse(is, resultMapping); - } finally { - Closeables.closeQuietly(is); - } - } - } - } catch (Throwable _e) { - throw Exceptions.sneakyThrow(_e); - } - } - - public final static List SETUPS = CollectionLiterals.newArrayList(new SpecStandaloneSetup(), new FeatureStandaloneSetup(), new SuiteStandaloneSetup()); - - @Pure - public String getOutputPath() { - return this._outputPath; - } - - public void setOutputPath(final String outputPath) { - this._outputPath = outputPath; - } - - @Pure - public String getClassPath() { - return this._classPath; - } - - public void setClassPath(final String classPath) { - this._classPath = classPath; - } - - @Pure - public String getResultFolder() { - return this._resultFolder; - } - - public void setResultFolder(final String resultFolder) { - this._resultFolder = resultFolder; - } - - @Pure - public String getFileEncoding() { - return this._fileEncoding; - } - - public void setFileEncoding(final String fileEncoding) { - this._fileEncoding = fileEncoding; - } - - @Pure - public String getSourcePath() { - return this._sourcePath; - } - - public void setSourcePath(final String sourcePath) { - this._sourcePath = sourcePath; - } -} +/** + * Copyright (c) 2012 BMW Car IT and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.jnario.compiler; + +import com.google.common.base.Objects; +import com.google.common.io.Closeables; +import com.google.inject.Injector; +import com.google.inject.Provider; +import java.io.File; +import java.io.FileFilter; +import java.io.FileInputStream; +import java.util.Iterator; +import java.util.List; +import org.apache.log4j.BasicConfigurator; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.xtend.lib.Property; +import org.eclipse.xtext.ISetup; +import org.eclipse.xtext.xbase.lib.CollectionLiterals; +import org.eclipse.xtext.xbase.lib.Conversions; +import org.eclipse.xtext.xbase.lib.Exceptions; +import org.eclipse.xtext.xbase.lib.InputOutput; +import org.eclipse.xtext.xbase.lib.ObjectExtensions; +import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; +import org.eclipse.xtext.xbase.lib.Pure; +import org.jnario.compiler.CompilerMain; +import org.jnario.compiler.HtmlAssetsCompiler; +import org.jnario.compiler.JnarioDocCompiler; +import org.jnario.compiler.StandaloneResourceProvider; +import org.jnario.feature.FeatureStandaloneSetup; +import org.jnario.report.HashBasedSpec2ResultMapping; +import org.jnario.report.SpecResultParser; +import org.jnario.spec.SpecStandaloneSetup; +import org.jnario.suite.SuiteStandaloneSetup; + +@SuppressWarnings("all") +public class DocCompilerMain { + public static void main(final String[] args) { + if ((Objects.equal(args, null) || (((List)Conversions.doWrapArray(args)).size() == 0))) { + DocCompilerMain.printUsage(); + return; + } + DocCompilerMain _docCompilerMain = new DocCompilerMain(); + final Procedure1 _function = new Procedure1() { + @Override + public void apply(final DocCompilerMain it) { + final Iterator arguments = ((List)Conversions.doWrapArray(args)).iterator(); + while (arguments.hasNext()) { + { + final String argument = arguments.next().trim(); + boolean _matched = false; + if ((Objects.equal(argument, "-cp") || Objects.equal(argument, "-classpath"))) { + _matched=true; + it.setClassPath(arguments.next()); + } + if (!_matched) { + if (Objects.equal(argument, "-d")) { + _matched=true; + it.setOutputPath(arguments.next()); + } + } + if (!_matched) { + if (Objects.equal(argument, "-results")) { + _matched=true; + it.setResultFolder(arguments.next()); + } + } + if (!_matched) { + if (Objects.equal(argument, "-encoding")) { + _matched=true; + it.setFileEncoding(arguments.next()); + } + } + if (!_matched) { + it.setSourcePath(argument); + } + } + } + } + }; + final DocCompilerMain main = ObjectExtensions.operator_doubleArrow(_docCompilerMain, _function); + System.exit(main.compile()); + } + + @Property + private String _outputPath = "doc-gen"; + + @Property + private String _classPath = ""; + + @Property + private String _resultFolder = ""; + + @Property + private String _fileEncoding = "UTF-8"; + + @Property + private String _sourcePath = "."; + + public int compile() { + int _xblockexpression = (int) 0; + { + BasicConfigurator.configure(); + final Injector anyInjector = DocCompilerMain.SETUPS.get(0).createInjectorAndDoEMFRegistration(); + final ResourceSet resourceSet = anyInjector.getInstance(ResourceSet.class); + this.generateCssAndJsFiles(anyInjector); + StandaloneResourceProvider _standaloneResourceProvider = new StandaloneResourceProvider(resourceSet); + _xblockexpression = this.generateDocs(_standaloneResourceProvider); + } + return _xblockexpression; + } + + private int generateDocs(final Provider resourceSet) { + for (final ISetup setup : DocCompilerMain.SETUPS) { + { + final Injector injector = setup.createInjectorAndDoEMFRegistration(); + final JnarioDocCompiler jnarioCompiler = injector.getInstance(JnarioDocCompiler.class); + jnarioCompiler.setOutputPath(this.getOutputPath()); + jnarioCompiler.setClassPath(this.getClassPath()); + jnarioCompiler.setFileEncoding(this.getFileEncoding()); + jnarioCompiler.setSourcePath(this.getSourcePath()); + resourceSet.get().eAdapters().clear(); + jnarioCompiler.setResourceSetProvider(resourceSet); + jnarioCompiler.setExecutable2ResultMapping(this.createSpec2ResultMapping()); + boolean _compile = jnarioCompiler.compile(); + boolean _not = (!_compile); + if (_not) { + return CompilerMain.COMPILATION_ERROR; + } + } + } + return CompilerMain.OK; + } + + private static void printUsage() { + InputOutput.println("Usage: JnarioDocCompiler "); + InputOutput.println("where possible options include:"); + InputOutput.println("-d Specify where to place generated documentation files"); + InputOutput.println("-results Specify folder containing JUnit XML test results"); + InputOutput.println("-encoding Specify character encoding used by source files"); + } + + public HashBasedSpec2ResultMapping createSpec2ResultMapping() { + final HashBasedSpec2ResultMapping resultMapping = DocCompilerMain.SETUPS.get(2).createInjectorAndDoEMFRegistration().getInstance(HashBasedSpec2ResultMapping.class); + String _resultFolder = this.getResultFolder(); + final File reportFolder = new File(_resultFolder); + boolean _exists = reportFolder.exists(); + if (_exists) { + this.addExecutionResults(resultMapping, reportFolder); + } + return resultMapping; + } + + public boolean generateCssAndJsFiles(final Injector injector) { + boolean _xblockexpression = false; + { + final HtmlAssetsCompiler assetsCompiler = injector.getInstance(HtmlAssetsCompiler.class); + assetsCompiler.setOutputPath(this.getOutputPath()); + _xblockexpression = assetsCompiler.compile(); + } + return _xblockexpression; + } + + public void addExecutionResults(final HashBasedSpec2ResultMapping resultMapping, final File reportFolder) { + try { + final SpecResultParser specResultParser = new SpecResultParser(); + final FileFilter _function = new FileFilter() { + @Override + public boolean accept(final File it) { + return it.getName().endsWith("xml"); + } + }; + File[] _listFiles = reportFolder.listFiles(_function); + for (final File file : _listFiles) { + { + FileInputStream is = null; + try { + FileInputStream _fileInputStream = new FileInputStream(file); + is = _fileInputStream; + specResultParser.parse(is, resultMapping); + } finally { + Closeables.closeQuietly(is); + } + } + } + } catch (Throwable _e) { + throw Exceptions.sneakyThrow(_e); + } + } + + public final static List SETUPS = CollectionLiterals.newArrayList(new SpecStandaloneSetup(), new FeatureStandaloneSetup(), new SuiteStandaloneSetup()); + + @Pure + public String getOutputPath() { + return this._outputPath; + } + + public void setOutputPath(final String outputPath) { + this._outputPath = outputPath; + } + + @Pure + public String getClassPath() { + return this._classPath; + } + + public void setClassPath(final String classPath) { + this._classPath = classPath; + } + + @Pure + public String getResultFolder() { + return this._resultFolder; + } + + public void setResultFolder(final String resultFolder) { + this._resultFolder = resultFolder; + } + + @Pure + public String getFileEncoding() { + return this._fileEncoding; + } + + public void setFileEncoding(final String fileEncoding) { + this._fileEncoding = fileEncoding; + } + + @Pure + public String getSourcePath() { + return this._sourcePath; + } + + public void setSourcePath(final String sourcePath) { + this._sourcePath = sourcePath; + } +} diff --git a/plugins/org.jnario.standalone/xtend-gen/org/jnario/compiler/JnarioStandaloneCompiler.java b/plugins/org.jnario.standalone/xtend-gen/org/jnario/compiler/JnarioStandaloneCompiler.java index 571b78c89..2a29efe49 100644 --- a/plugins/org.jnario.standalone/xtend-gen/org/jnario/compiler/JnarioStandaloneCompiler.java +++ b/plugins/org.jnario.standalone/xtend-gen/org/jnario/compiler/JnarioStandaloneCompiler.java @@ -1,370 +1,331 @@ -/** - * Copyright (c) 2014 itemis AG (http://www.itemis.eu) and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.jnario.compiler; - -import com.google.common.base.Joiner; -import com.google.common.base.Objects; -import com.google.common.base.Predicate; -import com.google.common.collect.Lists; -import com.google.common.collect.Multimap; -import com.google.inject.Inject; -import com.google.inject.Injector; -import java.io.File; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.function.Consumer; -import org.apache.log4j.Logger; -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.common.util.URI; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.emf.ecore.resource.ResourceSet; -import org.eclipse.emf.ecore.resource.URIConverter; -import org.eclipse.xtext.ISetup; -import org.eclipse.xtext.common.types.JvmDeclaredType; -import org.eclipse.xtext.common.types.TypesPackage; -import org.eclipse.xtext.common.types.descriptions.IStubGenerator; -import org.eclipse.xtext.common.types.descriptions.JvmTypesResourceDescriptionStrategy; -import org.eclipse.xtext.generator.JavaIoFileSystemAccess; -import org.eclipse.xtext.mwe.NameBasedFilter; -import org.eclipse.xtext.mwe.PathTraverser; -import org.eclipse.xtext.naming.IQualifiedNameProvider; -import org.eclipse.xtext.naming.QualifiedName; -import org.eclipse.xtext.parser.IEncodingProvider; -import org.eclipse.xtext.resource.FileExtensionProvider; -import org.eclipse.xtext.resource.IEObjectDescription; -import org.eclipse.xtext.resource.IResourceDescription; -import org.eclipse.xtext.resource.containers.FlatResourceSetBasedAllContainersState; -import org.eclipse.xtext.resource.impl.ResourceSetBasedResourceDescriptions; -import org.eclipse.xtext.util.Strings; -import org.eclipse.xtext.xbase.compiler.GeneratorConfig; -import org.eclipse.xtext.xbase.compiler.IGeneratorConfigProvider; -import org.eclipse.xtext.xbase.compiler.JvmModelGenerator; -import org.eclipse.xtext.xbase.lib.CollectionExtensions; -import org.eclipse.xtext.xbase.lib.CollectionLiterals; -import org.eclipse.xtext.xbase.lib.Conversions; -import org.eclipse.xtext.xbase.lib.Functions.Function1; -import org.eclipse.xtext.xbase.lib.IterableExtensions; -import org.eclipse.xtext.xbase.lib.ListExtensions; -import org.eclipse.xtext.xbase.lib.ObjectExtensions; -import org.eclipse.xtext.xbase.lib.Pair; -import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; -import org.jnario.compiler.AbstractBatchCompiler; -import org.jnario.feature.FeatureStandaloneSetup; -import org.jnario.spec.SpecStandaloneSetup; -import org.jnario.suite.SuiteStandaloneSetup; - -@SuppressWarnings("all") -public class JnarioStandaloneCompiler extends AbstractBatchCompiler { - private final static Logger log = Logger.getLogger(JnarioStandaloneCompiler.class.getName()); - - @Inject - private IStubGenerator stubGenerator; - - private List injectors; - - private Map injectorMap; - - public static JnarioStandaloneCompiler create() { - JnarioStandaloneCompiler _xblockexpression = null; - { - FeatureStandaloneSetup _featureStandaloneSetup = new FeatureStandaloneSetup(); - SpecStandaloneSetup _specStandaloneSetup = new SpecStandaloneSetup(); - SuiteStandaloneSetup _suiteStandaloneSetup = new SuiteStandaloneSetup(); - final List setups = Collections.unmodifiableList(CollectionLiterals.newArrayList(_featureStandaloneSetup, _specStandaloneSetup, _suiteStandaloneSetup)); - _xblockexpression = JnarioStandaloneCompiler.fromSetups(setups); - } - return _xblockexpression; - } - - public Map initWithInjectors(final List injectors) { - Map _xblockexpression = null; - { - this.injectors = injectors; - final Function1> _function = new Function1>() { - @Override - public Pair apply(final Injector it) { - Pair _xblockexpression = null; - { - FileExtensionProvider _instance = it.getInstance(FileExtensionProvider.class); - final String fileExtension = _instance.getPrimaryFileExtension(); - _xblockexpression = Pair.of(fileExtension, it); - } - return _xblockexpression; - } - }; - List> _map = ListExtensions.>map(injectors, _function); - HashMap _newHashMap = CollectionLiterals.newHashMap(((Pair[])Conversions.unwrapArray(_map, Pair.class))); - _xblockexpression = this.injectorMap = _newHashMap; - } - return _xblockexpression; - } - - public static JnarioStandaloneCompiler fromSetups(final List setups) { - JnarioStandaloneCompiler _jnarioStandaloneCompiler = new JnarioStandaloneCompiler(); - final Procedure1 _function = new Procedure1() { - @Override - public void apply(final JnarioStandaloneCompiler it) { - final Function1 _function = new Function1() { - @Override - public Injector apply(final ISetup it) { - return it.createInjectorAndDoEMFRegistration(); - } - }; - List _eagerMap = JnarioStandaloneCompiler.eagerMap(setups, _function); - List _list = IterableExtensions.toList(_eagerMap); - it.injectors = _list; - Injector _head = IterableExtensions.head(it.injectors); - _head.injectMembers(it); - final Function1> _function_1 = new Function1>() { - @Override - public Pair apply(final Injector it) { - Pair _xblockexpression = null; - { - FileExtensionProvider _instance = it.getInstance(FileExtensionProvider.class); - final String fileExtension = _instance.getPrimaryFileExtension(); - _xblockexpression = Pair.of(fileExtension, it); - } - return _xblockexpression; - } - }; - List> _map = ListExtensions.>map(it.injectors, _function_1); - HashMap _newHashMap = CollectionLiterals.newHashMap(((Pair[])Conversions.unwrapArray(_map, Pair.class))); - it.injectorMap = _newHashMap; - } - }; - return ObjectExtensions.operator_doubleArrow(_jnarioStandaloneCompiler, _function); - } - - @Override - protected ResourceSet loadXtendFiles(final ResourceSet resourceSet) { - this.applyEncoding(); - EList _eAdapters = resourceSet.eAdapters(); - _eAdapters.add( - new FlatResourceSetBasedAllContainersState(resourceSet) { - @Override - public Collection getContainedURIs(final String containerHandle) { - ResourceSet _resourceSet = this.getResourceSet(); - EList _resources = _resourceSet.getResources(); - int _size = _resources.size(); - final ArrayList uris = Lists.newArrayListWithCapacity(_size); - ResourceSet _resourceSet_1 = this.getResourceSet(); - EList _resources_1 = _resourceSet_1.getResources(); - for (final Resource r : _resources_1) { - URI _uRI = r.getURI(); - uris.add(_uRI); - } - return uris; - } - }); - final List nameBasedFilter = this.getNameBasedFilters(); - final PathTraverser pathTraverser = new PathTraverser(); - final List sourcePathDirectories = this.getSourcePathDirectories(); - final Predicate _function = new Predicate() { - @Override - public boolean apply(final URI src) { - final Function1 _function = new Function1() { - @Override - public Boolean apply(final NameBasedFilter it) { - return Boolean.valueOf(it.matches(src)); - } - }; - return IterableExtensions.exists(nameBasedFilter, _function); - } - }; - final Multimap pathes = pathTraverser.resolvePathes(sourcePathDirectories, _function); - Set _keySet = pathes.keySet(); - final Consumer _function_1 = new Consumer() { - @Override - public void accept(final String src) { - final URI baseDir = URI.createFileURI((src + "/")); - Joiner _on = Joiner.on("_"); - String[] _segments = baseDir.segments(); - final String identifier = _on.join(_segments); - final URI platformResourceURI = URI.createPlatformResourceURI((identifier + "/"), true); - URIConverter _uRIConverter = resourceSet.getURIConverter(); - Map _uRIMap = _uRIConverter.getURIMap(); - _uRIMap.put(platformResourceURI, baseDir); - Collection _get = pathes.get(src); - for (final URI uri : _get) { - { - boolean _isDebugEnabled = JnarioStandaloneCompiler.log.isDebugEnabled(); - if (_isDebugEnabled) { - JnarioStandaloneCompiler.log.debug((("load xtend file \'" + uri) + "\'")); - } - final URI uriToUse = uri.replacePrefix(baseDir, platformResourceURI); - resourceSet.getResource(uriToUse, true); - } - } - } - }; - _keySet.forEach(_function_1); - return resourceSet; - } - - public void applyEncoding() { - final Consumer _function = new Consumer() { - @Override - public void accept(final Injector it) { - IEncodingProvider.Runtime _instance = it.getInstance(IEncodingProvider.Runtime.class); - String _fileEncoding = JnarioStandaloneCompiler.this.getFileEncoding(); - _instance.setDefaultEncoding(_fileEncoding); - } - }; - this.injectors.forEach(_function); - } - - public List getNameBasedFilters() { - final Function1 _function = new Function1() { - @Override - public NameBasedFilter apply(final Injector it) { - NameBasedFilter _xblockexpression = null; - { - final NameBasedFilter filter = new NameBasedFilter(); - FileExtensionProvider _instance = it.getInstance(FileExtensionProvider.class); - String _primaryFileExtension = _instance.getPrimaryFileExtension(); - filter.setExtension(_primaryFileExtension); - _xblockexpression = filter; - } - return _xblockexpression; - } - }; - return JnarioStandaloneCompiler.eagerMap(this.injectors, _function); - } - - @Override - public File createStubs(final ResourceSet resourceSet) { - final File outputDirectory = this.createTempDir("stubs"); - final JavaIoFileSystemAccess fileSystemAccess = this.javaIoFileSystemAccessProvider.get(); - String _string = outputDirectory.toString(); - fileSystemAccess.setOutputPath(_string); - EList _resources = resourceSet.getResources(); - ArrayList _newArrayList = Lists.newArrayList(_resources); - final Consumer _function = new Consumer() { - @Override - public void accept(final Resource it) { - IResourceDescription.Manager _findResourceDescriptionManager = JnarioStandaloneCompiler.this.findResourceDescriptionManager(it); - IResourceDescription _resourceDescription = null; - if (_findResourceDescriptionManager!=null) { - _resourceDescription=_findResourceDescriptionManager.getResourceDescription(it); - } - final IResourceDescription description = _resourceDescription; - boolean _notEquals = (!Objects.equal(description, null)); - if (_notEquals) { - JnarioStandaloneCompiler.this.stubGenerator.doGenerateStubs(fileSystemAccess, description); - } - } - }; - _newArrayList.forEach(_function); - return outputDirectory; - } - - public IResourceDescription.Manager findResourceDescriptionManager(final Resource resource) { - return this.getInstance(resource, IResourceDescription.Manager.class); - } - - public T getInstance(final Resource resource, final Class type) { - URI _uRI = resource.getURI(); - String _fileExtension = _uRI.fileExtension(); - String _lowerCase = _fileExtension.toLowerCase(); - Injector _get = this.injectorMap.get(_lowerCase); - T _instance = null; - if (_get!=null) { - _instance=_get.getInstance(type); - } - return _instance; - } - - @Override - public void generateJavaFiles(final ResourceSet resourceSet) { - final JavaIoFileSystemAccess javaIoFileSystemAccess = this.javaIoFileSystemAccessProvider.get(); - final String outputPath = this.outputPath; - javaIoFileSystemAccess.setOutputPath(outputPath); - javaIoFileSystemAccess.setWriteTrace(this.writeTraceFiles); - final ResourceSetBasedResourceDescriptions resourceDescriptions = this.getResourceDescriptions(resourceSet); - final Iterable exportedObjectsByType = resourceDescriptions.getExportedObjectsByType(TypesPackage.Literals.JVM_DECLARED_TYPE); - boolean _isInfoEnabled = JnarioStandaloneCompiler.log.isInfoEnabled(); - if (_isInfoEnabled) { - final int size = IterableExtensions.size(exportedObjectsByType); - if ((size == 0)) { - JnarioStandaloneCompiler.log.info((("No sources to compile in \'" + this.sourcePath) + "\'")); - } else { - String _xifexpression = null; - if ((size == 1)) { - _xifexpression = "file"; - } else { - _xifexpression = "files"; - } - String _plus = ((("Compiling " + Integer.valueOf(size)) + " source ") + _xifexpression); - String _plus_1 = (_plus + " to "); - String _plus_2 = (_plus_1 + outputPath); - JnarioStandaloneCompiler.log.info(_plus_2); - } - } - final Function1 _function = new Function1() { - @Override - public Boolean apply(final IEObjectDescription it) { - String _userData = it.getUserData(JvmTypesResourceDescriptionStrategy.IS_NESTED_TYPE); - return Boolean.valueOf(Objects.equal(_userData, null)); - } - }; - Iterable _filter = IterableExtensions.filter(exportedObjectsByType, _function); - final Consumer _function_1 = new Consumer() { - @Override - public void accept(final IEObjectDescription eObjectDescription) { - EObject _eObjectOrProxy = eObjectDescription.getEObjectOrProxy(); - final JvmDeclaredType jvmGenericType = ((JvmDeclaredType) _eObjectOrProxy); - Resource _eResource = jvmGenericType.eResource(); - final JvmModelGenerator generator = JnarioStandaloneCompiler.this.getInstance(_eResource, JvmModelGenerator.class); - Resource _eResource_1 = jvmGenericType.eResource(); - final IGeneratorConfigProvider generatorConfig = JnarioStandaloneCompiler.this.getInstance(_eResource_1, IGeneratorConfigProvider.class); - Resource _eResource_2 = jvmGenericType.eResource(); - final IQualifiedNameProvider nameProvider = JnarioStandaloneCompiler.this.getInstance(_eResource_2, IQualifiedNameProvider.class); - GeneratorConfig _get = generatorConfig.get(jvmGenericType); - final CharSequence generatedType = generator.generateType(jvmGenericType, _get); - final QualifiedName qualifiedName = nameProvider.getFullyQualifiedName(jvmGenericType); - boolean _isDebugEnabled = JnarioStandaloneCompiler.log.isDebugEnabled(); - if (_isDebugEnabled) { - String _javaFileName = JnarioStandaloneCompiler.this.getJavaFileName(qualifiedName); - String _plus = ((("write \'" + outputPath) + File.separator) + _javaFileName); - String _plus_1 = (_plus + "\'"); - JnarioStandaloneCompiler.log.debug(_plus_1); - } - String _javaFileName_1 = JnarioStandaloneCompiler.this.getJavaFileName(qualifiedName); - javaIoFileSystemAccess.generateFile(_javaFileName_1, generatedType); - } - }; - _filter.forEach(_function_1); - } - - public String getJavaFileName(final QualifiedName typeName) { - List _segments = typeName.getSegments(); - String _concat = Strings.concat("/", _segments); - return (_concat + ".java"); - } - - public static List eagerMap(final List list, final Function1 transformation) { - ArrayList _xblockexpression = null; - { - int _size = list.size(); - final ArrayList result = new ArrayList(_size); - for (final T t : list) { - R _apply = transformation.apply(t); - CollectionExtensions.addAll(result, _apply); - } - _xblockexpression = result; - } - return _xblockexpression; - } -} +/** + * Copyright (c) 2014 itemis AG (http://www.itemis.eu) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.jnario.compiler; + +import com.google.common.base.Joiner; +import com.google.common.base.Objects; +import com.google.common.base.Predicate; +import com.google.common.collect.Lists; +import com.google.common.collect.Multimap; +import com.google.inject.Inject; +import com.google.inject.Injector; +import java.io.File; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.function.Consumer; +import org.apache.log4j.Logger; +import org.eclipse.emf.common.notify.Adapter; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.xtext.ISetup; +import org.eclipse.xtext.common.types.JvmDeclaredType; +import org.eclipse.xtext.common.types.TypesPackage; +import org.eclipse.xtext.common.types.descriptions.IStubGenerator; +import org.eclipse.xtext.common.types.descriptions.JvmTypesResourceDescriptionStrategy; +import org.eclipse.xtext.generator.JavaIoFileSystemAccess; +import org.eclipse.xtext.mwe.NameBasedFilter; +import org.eclipse.xtext.mwe.PathTraverser; +import org.eclipse.xtext.naming.IQualifiedNameProvider; +import org.eclipse.xtext.naming.QualifiedName; +import org.eclipse.xtext.parser.IEncodingProvider; +import org.eclipse.xtext.resource.FileExtensionProvider; +import org.eclipse.xtext.resource.IEObjectDescription; +import org.eclipse.xtext.resource.IResourceDescription; +import org.eclipse.xtext.resource.containers.FlatResourceSetBasedAllContainersState; +import org.eclipse.xtext.resource.impl.ResourceSetBasedResourceDescriptions; +import org.eclipse.xtext.util.Strings; +import org.eclipse.xtext.xbase.compiler.IGeneratorConfigProvider; +import org.eclipse.xtext.xbase.compiler.JvmModelGenerator; +import org.eclipse.xtext.xbase.lib.CollectionExtensions; +import org.eclipse.xtext.xbase.lib.CollectionLiterals; +import org.eclipse.xtext.xbase.lib.Conversions; +import org.eclipse.xtext.xbase.lib.Functions.Function1; +import org.eclipse.xtext.xbase.lib.IterableExtensions; +import org.eclipse.xtext.xbase.lib.ListExtensions; +import org.eclipse.xtext.xbase.lib.ObjectExtensions; +import org.eclipse.xtext.xbase.lib.Pair; +import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; +import org.jnario.compiler.AbstractBatchCompiler; +import org.jnario.feature.FeatureStandaloneSetup; +import org.jnario.spec.SpecStandaloneSetup; +import org.jnario.suite.SuiteStandaloneSetup; + +@SuppressWarnings("all") +public class JnarioStandaloneCompiler extends AbstractBatchCompiler { + private final static Logger log = Logger.getLogger(JnarioStandaloneCompiler.class.getName()); + + @Inject + private IStubGenerator stubGenerator; + + private List injectors; + + private Map injectorMap; + + public static JnarioStandaloneCompiler create() { + JnarioStandaloneCompiler _xblockexpression = null; + { + FeatureStandaloneSetup _featureStandaloneSetup = new FeatureStandaloneSetup(); + SpecStandaloneSetup _specStandaloneSetup = new SpecStandaloneSetup(); + SuiteStandaloneSetup _suiteStandaloneSetup = new SuiteStandaloneSetup(); + final List setups = Collections.unmodifiableList(CollectionLiterals.newArrayList(_featureStandaloneSetup, _specStandaloneSetup, _suiteStandaloneSetup)); + _xblockexpression = JnarioStandaloneCompiler.fromSetups(setups); + } + return _xblockexpression; + } + + public Map initWithInjectors(final List injectors) { + Map _xblockexpression = null; + { + this.injectors = injectors; + final Function1> _function = new Function1>() { + @Override + public Pair apply(final Injector it) { + Pair _xblockexpression = null; + { + final String fileExtension = it.getInstance(FileExtensionProvider.class).getPrimaryFileExtension(); + _xblockexpression = Pair.of(fileExtension, it); + } + return _xblockexpression; + } + }; + _xblockexpression = this.injectorMap = CollectionLiterals.newHashMap( + ((Pair[])Conversions.unwrapArray(ListExtensions.>map(injectors, _function), Pair.class))); + } + return _xblockexpression; + } + + public static JnarioStandaloneCompiler fromSetups(final List setups) { + JnarioStandaloneCompiler _jnarioStandaloneCompiler = new JnarioStandaloneCompiler(); + final Procedure1 _function = new Procedure1() { + @Override + public void apply(final JnarioStandaloneCompiler it) { + final Function1 _function = new Function1() { + @Override + public Injector apply(final ISetup it) { + return it.createInjectorAndDoEMFRegistration(); + } + }; + it.injectors = IterableExtensions.toList(JnarioStandaloneCompiler.eagerMap(setups, _function)); + IterableExtensions.head(it.injectors).injectMembers(it); + final Function1> _function_1 = new Function1>() { + @Override + public Pair apply(final Injector it) { + Pair _xblockexpression = null; + { + final String fileExtension = it.getInstance(FileExtensionProvider.class).getPrimaryFileExtension(); + _xblockexpression = Pair.of(fileExtension, it); + } + return _xblockexpression; + } + }; + it.injectorMap = CollectionLiterals.newHashMap( + ((Pair[])Conversions.unwrapArray(ListExtensions.>map(it.injectors, _function_1), Pair.class))); + } + }; + return ObjectExtensions.operator_doubleArrow(_jnarioStandaloneCompiler, _function); + } + + @Override + protected ResourceSet loadXtendFiles(final ResourceSet resourceSet) { + this.applyEncoding(); + EList _eAdapters = resourceSet.eAdapters(); + _eAdapters.add( + new FlatResourceSetBasedAllContainersState(resourceSet) { + @Override + public Collection getContainedURIs(final String containerHandle) { + final ArrayList uris = Lists.newArrayListWithCapacity(this.getResourceSet().getResources().size()); + EList _resources = this.getResourceSet().getResources(); + for (final Resource r : _resources) { + uris.add(r.getURI()); + } + return uris; + } + }); + final List nameBasedFilter = this.getNameBasedFilters(); + final PathTraverser pathTraverser = new PathTraverser(); + final List sourcePathDirectories = this.getSourcePathDirectories(); + final Predicate _function = new Predicate() { + @Override + public boolean apply(final URI src) { + final Function1 _function = new Function1() { + @Override + public Boolean apply(final NameBasedFilter it) { + return Boolean.valueOf(it.matches(src)); + } + }; + return IterableExtensions.exists(nameBasedFilter, _function); + } + }; + final Multimap pathes = pathTraverser.resolvePathes(sourcePathDirectories, _function); + final Consumer _function_1 = new Consumer() { + @Override + public void accept(final String src) { + final URI baseDir = URI.createFileURI((src + "/")); + final String identifier = Joiner.on("_").join(baseDir.segments()); + final URI platformResourceURI = URI.createPlatformResourceURI((identifier + "/"), true); + resourceSet.getURIConverter().getURIMap().put(platformResourceURI, baseDir); + Collection _get = pathes.get(src); + for (final URI uri : _get) { + { + boolean _isDebugEnabled = JnarioStandaloneCompiler.log.isDebugEnabled(); + if (_isDebugEnabled) { + JnarioStandaloneCompiler.log.debug((("load xtend file \'" + uri) + "\'")); + } + final URI uriToUse = uri.replacePrefix(baseDir, platformResourceURI); + resourceSet.getResource(uriToUse, true); + } + } + } + }; + pathes.keySet().forEach(_function_1); + return resourceSet; + } + + public void applyEncoding() { + final Consumer _function = new Consumer() { + @Override + public void accept(final Injector it) { + it.getInstance(IEncodingProvider.Runtime.class).setDefaultEncoding(JnarioStandaloneCompiler.this.getFileEncoding()); + } + }; + this.injectors.forEach(_function); + } + + public List getNameBasedFilters() { + final Function1 _function = new Function1() { + @Override + public NameBasedFilter apply(final Injector it) { + NameBasedFilter _xblockexpression = null; + { + final NameBasedFilter filter = new NameBasedFilter(); + filter.setExtension(it.getInstance(FileExtensionProvider.class).getPrimaryFileExtension()); + _xblockexpression = filter; + } + return _xblockexpression; + } + }; + return JnarioStandaloneCompiler.eagerMap(this.injectors, _function); + } + + @Override + public File createStubs(final ResourceSet resourceSet) { + final File outputDirectory = this.createTempDir("stubs"); + final JavaIoFileSystemAccess fileSystemAccess = this.javaIoFileSystemAccessProvider.get(); + fileSystemAccess.setOutputPath(outputDirectory.toString()); + final Consumer _function = new Consumer() { + @Override + public void accept(final Resource it) { + IResourceDescription.Manager _findResourceDescriptionManager = JnarioStandaloneCompiler.this.findResourceDescriptionManager(it); + IResourceDescription _resourceDescription = null; + if (_findResourceDescriptionManager!=null) { + _resourceDescription=_findResourceDescriptionManager.getResourceDescription(it); + } + final IResourceDescription description = _resourceDescription; + boolean _notEquals = (!Objects.equal(description, null)); + if (_notEquals) { + JnarioStandaloneCompiler.this.stubGenerator.doGenerateStubs(fileSystemAccess, description); + } + } + }; + Lists.newArrayList(resourceSet.getResources()).forEach(_function); + return outputDirectory; + } + + public IResourceDescription.Manager findResourceDescriptionManager(final Resource resource) { + return this.getInstance(resource, IResourceDescription.Manager.class); + } + + public T getInstance(final Resource resource, final Class type) { + Injector _get = this.injectorMap.get(resource.getURI().fileExtension().toLowerCase()); + T _instance = null; + if (_get!=null) { + _instance=_get.getInstance(type); + } + return _instance; + } + + @Override + public void generateJavaFiles(final ResourceSet resourceSet) { + final JavaIoFileSystemAccess javaIoFileSystemAccess = this.javaIoFileSystemAccessProvider.get(); + final String outputPath = this.outputPath; + javaIoFileSystemAccess.setOutputPath(outputPath); + javaIoFileSystemAccess.setWriteTrace(this.writeTraceFiles); + final ResourceSetBasedResourceDescriptions resourceDescriptions = this.getResourceDescriptions(resourceSet); + final Iterable exportedObjectsByType = resourceDescriptions.getExportedObjectsByType(TypesPackage.Literals.JVM_DECLARED_TYPE); + boolean _isInfoEnabled = JnarioStandaloneCompiler.log.isInfoEnabled(); + if (_isInfoEnabled) { + final int size = IterableExtensions.size(exportedObjectsByType); + if ((size == 0)) { + JnarioStandaloneCompiler.log.info((("No sources to compile in \'" + this.sourcePath) + "\'")); + } else { + String _xifexpression = null; + if ((size == 1)) { + _xifexpression = "file"; + } else { + _xifexpression = "files"; + } + String _plus = ((("Compiling " + Integer.valueOf(size)) + " source ") + _xifexpression); + String _plus_1 = (_plus + " to "); + String _plus_2 = (_plus_1 + outputPath); + JnarioStandaloneCompiler.log.info(_plus_2); + } + } + final Function1 _function = new Function1() { + @Override + public Boolean apply(final IEObjectDescription it) { + String _userData = it.getUserData(JvmTypesResourceDescriptionStrategy.IS_NESTED_TYPE); + return Boolean.valueOf(Objects.equal(_userData, null)); + } + }; + final Consumer _function_1 = new Consumer() { + @Override + public void accept(final IEObjectDescription eObjectDescription) { + EObject _eObjectOrProxy = eObjectDescription.getEObjectOrProxy(); + final JvmDeclaredType jvmGenericType = ((JvmDeclaredType) _eObjectOrProxy); + final JvmModelGenerator generator = JnarioStandaloneCompiler.this.getInstance(jvmGenericType.eResource(), JvmModelGenerator.class); + final IGeneratorConfigProvider generatorConfig = JnarioStandaloneCompiler.this.getInstance(jvmGenericType.eResource(), IGeneratorConfigProvider.class); + final IQualifiedNameProvider nameProvider = JnarioStandaloneCompiler.this.getInstance(jvmGenericType.eResource(), IQualifiedNameProvider.class); + final CharSequence generatedType = generator.generateType(jvmGenericType, generatorConfig.get(jvmGenericType)); + final QualifiedName qualifiedName = nameProvider.getFullyQualifiedName(jvmGenericType); + boolean _isDebugEnabled = JnarioStandaloneCompiler.log.isDebugEnabled(); + if (_isDebugEnabled) { + String _javaFileName = JnarioStandaloneCompiler.this.getJavaFileName(qualifiedName); + String _plus = ((("write \'" + outputPath) + File.separator) + _javaFileName); + String _plus_1 = (_plus + "\'"); + JnarioStandaloneCompiler.log.debug(_plus_1); + } + javaIoFileSystemAccess.generateFile(JnarioStandaloneCompiler.this.getJavaFileName(qualifiedName), generatedType); + } + }; + IterableExtensions.filter(exportedObjectsByType, _function).forEach(_function_1); + } + + public String getJavaFileName(final QualifiedName typeName) { + String _concat = Strings.concat("/", typeName.getSegments()); + return (_concat + ".java"); + } + + public static List eagerMap(final List list, final Function1 transformation) { + ArrayList _xblockexpression = null; + { + int _size = list.size(); + final ArrayList result = new ArrayList(_size); + for (final T t : list) { + CollectionExtensions.addAll(result, transformation.apply(t)); + } + _xblockexpression = result; + } + return _xblockexpression; + } +} diff --git a/plugins/org.jnario.standalone/xtend-gen/org/jnario/compiler/ReportTask.java b/plugins/org.jnario.standalone/xtend-gen/org/jnario/compiler/ReportTask.java index e867f177e..17ec6aed7 100644 --- a/plugins/org.jnario.standalone/xtend-gen/org/jnario/compiler/ReportTask.java +++ b/plugins/org.jnario.standalone/xtend-gen/org/jnario/compiler/ReportTask.java @@ -1,122 +1,116 @@ -package org.jnario.compiler; - -import com.google.common.base.Objects; -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.Task; -import org.apache.tools.ant.types.Path; -import org.apache.tools.ant.types.Reference; -import org.eclipse.xtend.lib.Property; -import org.eclipse.xtext.xbase.lib.ObjectExtensions; -import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; -import org.eclipse.xtext.xbase.lib.Pure; -import org.jnario.compiler.CompilerMain; -import org.jnario.compiler.DocCompilerMain; - -@SuppressWarnings("all") -public class ReportTask extends Task { - /** - * Set target for the generated Jnario reports. Default is "doc-gen". - */ - @Property - private String _outputPath = "doc-gen"; - - /** - * Set folder containing JUnit XML test results. Default is "test-reports". - */ - @Property - private String _resultFolder = "test-reports"; - - /** - * The spec encoding. Default is UTF-8. - */ - @Property - private String _fileEncoding = "UTF-8"; - - private Path sourcePath = null; - - @Override - public void execute() throws BuildException { - DocCompilerMain _docCompilerMain = new DocCompilerMain(); - final Procedure1 _function = new Procedure1() { - @Override - public void apply(final DocCompilerMain it) { - String _outputPath = ReportTask.this.getOutputPath(); - it.setOutputPath(_outputPath); - String _fileEncoding = ReportTask.this.getFileEncoding(); - it.setFileEncoding(_fileEncoding); - String _string = ReportTask.this.sourcePath.toString(); - it.setSourcePath(_string); - String _resultFolder = ReportTask.this.getResultFolder(); - it.setResultFolder(_resultFolder); - } - }; - final DocCompilerMain compiler = ObjectExtensions.operator_doubleArrow(_docCompilerMain, _function); - int _compile = compiler.compile(); - boolean _equals = (_compile == CompilerMain.COMPILATION_ERROR); - if (_equals) { - throw new BuildException("Error when generating Jnario report"); - } - } - - /** - * Set the sourcepath to use by reference. - * - * @param r a reference to an existing sourcepath. - */ - public void setSourcepathRef(final Reference r) { - Path _createSourcepath = this.createSourcepath(); - _createSourcepath.setRefid(r); - } - - /** - * Set the sourcepath to be used when compiling the Jnario specs. - * - * @param s an Ant Path object containing the sourcepath. - */ - public void setSourcepath(final Path s) { - Path _createSourcepath = this.createSourcepath(); - _createSourcepath.append(s); - } - - private Path createSourcepath() { - Path _xblockexpression = null; - { - boolean _equals = Objects.equal(this.sourcePath, null); - if (_equals) { - Project _project = this.getProject(); - Path _path = new Path(_project); - this.sourcePath = _path; - } - _xblockexpression = this.sourcePath; - } - return _xblockexpression; - } - - @Pure - public String getOutputPath() { - return this._outputPath; - } - - public void setOutputPath(final String outputPath) { - this._outputPath = outputPath; - } - - @Pure - public String getResultFolder() { - return this._resultFolder; - } - - public void setResultFolder(final String resultFolder) { - this._resultFolder = resultFolder; - } - - @Pure - public String getFileEncoding() { - return this._fileEncoding; - } - - public void setFileEncoding(final String fileEncoding) { - this._fileEncoding = fileEncoding; - } -} +package org.jnario.compiler; + +import com.google.common.base.Objects; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.Task; +import org.apache.tools.ant.types.Path; +import org.apache.tools.ant.types.Reference; +import org.eclipse.xtend.lib.Property; +import org.eclipse.xtext.xbase.lib.ObjectExtensions; +import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; +import org.eclipse.xtext.xbase.lib.Pure; +import org.jnario.compiler.CompilerMain; +import org.jnario.compiler.DocCompilerMain; + +@SuppressWarnings("all") +public class ReportTask extends Task { + /** + * Set target for the generated Jnario reports. Default is "doc-gen". + */ + @Property + private String _outputPath = "doc-gen"; + + /** + * Set folder containing JUnit XML test results. Default is "test-reports". + */ + @Property + private String _resultFolder = "test-reports"; + + /** + * The spec encoding. Default is UTF-8. + */ + @Property + private String _fileEncoding = "UTF-8"; + + private Path sourcePath = null; + + @Override + public void execute() throws BuildException { + DocCompilerMain _docCompilerMain = new DocCompilerMain(); + final Procedure1 _function = new Procedure1() { + @Override + public void apply(final DocCompilerMain it) { + it.setOutputPath(ReportTask.this.getOutputPath()); + it.setFileEncoding(ReportTask.this.getFileEncoding()); + it.setSourcePath(ReportTask.this.sourcePath.toString()); + it.setResultFolder(ReportTask.this.getResultFolder()); + } + }; + final DocCompilerMain compiler = ObjectExtensions.operator_doubleArrow(_docCompilerMain, _function); + int _compile = compiler.compile(); + boolean _equals = (_compile == CompilerMain.COMPILATION_ERROR); + if (_equals) { + throw new BuildException("Error when generating Jnario report"); + } + } + + /** + * Set the sourcepath to use by reference. + * + * @param r a reference to an existing sourcepath. + */ + public void setSourcepathRef(final Reference r) { + this.createSourcepath().setRefid(r); + } + + /** + * Set the sourcepath to be used when compiling the Jnario specs. + * + * @param s an Ant Path object containing the sourcepath. + */ + public void setSourcepath(final Path s) { + this.createSourcepath().append(s); + } + + private Path createSourcepath() { + Path _xblockexpression = null; + { + boolean _equals = Objects.equal(this.sourcePath, null); + if (_equals) { + Project _project = this.getProject(); + Path _path = new Path(_project); + this.sourcePath = _path; + } + _xblockexpression = this.sourcePath; + } + return _xblockexpression; + } + + @Pure + public String getOutputPath() { + return this._outputPath; + } + + public void setOutputPath(final String outputPath) { + this._outputPath = outputPath; + } + + @Pure + public String getResultFolder() { + return this._resultFolder; + } + + public void setResultFolder(final String resultFolder) { + this._resultFolder = resultFolder; + } + + @Pure + public String getFileEncoding() { + return this._fileEncoding; + } + + public void setFileEncoding(final String fileEncoding) { + this._fileEncoding = fileEncoding; + } +} diff --git a/plugins/org.jnario.standalone/xtend-gen/org/jnario/compiler/StandaloneResourceProvider.java b/plugins/org.jnario.standalone/xtend-gen/org/jnario/compiler/StandaloneResourceProvider.java index 391b6021b..b3feda3fe 100644 --- a/plugins/org.jnario.standalone/xtend-gen/org/jnario/compiler/StandaloneResourceProvider.java +++ b/plugins/org.jnario.standalone/xtend-gen/org/jnario/compiler/StandaloneResourceProvider.java @@ -1,25 +1,25 @@ -/** - * Copyright (c) 2012 BMW Car IT and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.jnario.compiler; - -import com.google.inject.Provider; -import org.eclipse.emf.ecore.resource.ResourceSet; - -@SuppressWarnings("all") -public class StandaloneResourceProvider implements Provider { - private ResourceSet resourceSet; - - public StandaloneResourceProvider(final ResourceSet resourceSet) { - this.resourceSet = resourceSet; - } - - @Override - public ResourceSet get() { - return this.resourceSet; - } -} +/** + * Copyright (c) 2012 BMW Car IT and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.jnario.compiler; + +import com.google.inject.Provider; +import org.eclipse.emf.ecore.resource.ResourceSet; + +@SuppressWarnings("all") +public class StandaloneResourceProvider implements Provider { + private ResourceSet resourceSet; + + public StandaloneResourceProvider(final ResourceSet resourceSet) { + this.resourceSet = resourceSet; + } + + @Override + public ResourceSet get() { + return this.resourceSet; + } +} diff --git a/plugins/org.jnario.suite.ui/xtend-gen/org/jnario/suite/ui/highlighting/SuiteHighlightingCalculator.java b/plugins/org.jnario.suite.ui/xtend-gen/org/jnario/suite/ui/highlighting/SuiteHighlightingCalculator.java index 37f677ee9..400a3a5f6 100644 --- a/plugins/org.jnario.suite.ui/xtend-gen/org/jnario/suite/ui/highlighting/SuiteHighlightingCalculator.java +++ b/plugins/org.jnario.suite.ui/xtend-gen/org/jnario/suite/ui/highlighting/SuiteHighlightingCalculator.java @@ -1,87 +1,77 @@ -/** - * Copyright (c) 2012 BMW Car IT and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.jnario.suite.ui.highlighting; - -import java.util.Arrays; -import org.eclipse.emf.common.util.TreeIterator; -import org.eclipse.emf.ecore.EAttribute; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EReference; -import org.eclipse.xtext.nodemodel.ICompositeNode; -import org.eclipse.xtext.nodemodel.util.NodeModelUtils; -import org.eclipse.xtext.resource.XtextResource; -import org.eclipse.xtext.ui.editor.syntaxcoloring.IHighlightedPositionAcceptor; -import org.eclipse.xtext.xbase.lib.IteratorExtensions; -import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; -import org.eclipse.xtext.xbase.ui.highlighting.XbaseHighlightingCalculator; -import org.jnario.suite.suite.PatternReference; -import org.jnario.suite.suite.SpecReference; -import org.jnario.suite.suite.Suite; -import org.jnario.suite.suite.SuitePackage; -import org.jnario.suite.ui.highlighting.SuiteHighlightingConfiguration; -import org.jnario.util.Strings; - -@SuppressWarnings("all") -public class SuiteHighlightingCalculator extends XbaseHighlightingCalculator { - @Override - public void searchAndHighlightElements(final XtextResource resource, final IHighlightedPositionAcceptor acceptor) { - TreeIterator _allContents = resource.getAllContents(); - final Procedure1 _function = new Procedure1() { - @Override - public void apply(final EObject it) { - SuiteHighlightingCalculator.this.highlight(it, acceptor); - } - }; - IteratorExtensions.forEach(_allContents, _function); - } - - protected Void _highlight(final SpecReference ref, final IHighlightedPositionAcceptor acceptor) { - EReference _specReference_Spec = SuitePackage.eINSTANCE.getSpecReference_Spec(); - this.highlightObjectAtFeature(acceptor, ref, _specReference_Spec, SuiteHighlightingConfiguration.LINK_ID); - return null; - } - - protected Void _highlight(final PatternReference ref, final IHighlightedPositionAcceptor acceptor) { - EAttribute _patternReference_Pattern = SuitePackage.eINSTANCE.getPatternReference_Pattern(); - this.highlightObjectAtFeature(acceptor, ref, _patternReference_Pattern, SuiteHighlightingConfiguration.PATTERN_ID); - return null; - } - - protected Void _highlight(final Suite suite, final IHighlightedPositionAcceptor acceptor) { - final ICompositeNode node = NodeModelUtils.getNode(suite); - String _name = suite.getName(); - int lineEnd = Strings.indexOfNewLine(_name); - if ((lineEnd == (-1))) { - String _name_1 = suite.getName(); - int _length = _name_1.length(); - lineEnd = _length; - } - int _offset = node.getOffset(); - acceptor.addPosition(_offset, lineEnd, SuiteHighlightingConfiguration.SUITE_ID); - return null; - } - - protected Void _highlight(final EObject ref, final IHighlightedPositionAcceptor acceptor) { - return null; - } - - public Void highlight(final EObject suite, final IHighlightedPositionAcceptor acceptor) { - if (suite instanceof Suite) { - return _highlight((Suite)suite, acceptor); - } else if (suite instanceof PatternReference) { - return _highlight((PatternReference)suite, acceptor); - } else if (suite instanceof SpecReference) { - return _highlight((SpecReference)suite, acceptor); - } else if (suite != null) { - return _highlight(suite, acceptor); - } else { - throw new IllegalArgumentException("Unhandled parameter types: " + - Arrays.asList(suite, acceptor).toString()); - } - } -} +/** + * Copyright (c) 2012 BMW Car IT and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.jnario.suite.ui.highlighting; + +import java.util.Arrays; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.xtext.nodemodel.ICompositeNode; +import org.eclipse.xtext.nodemodel.util.NodeModelUtils; +import org.eclipse.xtext.resource.XtextResource; +import org.eclipse.xtext.ui.editor.syntaxcoloring.IHighlightedPositionAcceptor; +import org.eclipse.xtext.xbase.lib.IteratorExtensions; +import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; +import org.eclipse.xtext.xbase.ui.highlighting.XbaseHighlightingCalculator; +import org.jnario.suite.suite.PatternReference; +import org.jnario.suite.suite.SpecReference; +import org.jnario.suite.suite.Suite; +import org.jnario.suite.suite.SuitePackage; +import org.jnario.suite.ui.highlighting.SuiteHighlightingConfiguration; +import org.jnario.util.Strings; + +@SuppressWarnings("all") +public class SuiteHighlightingCalculator extends XbaseHighlightingCalculator { + @Override + public void searchAndHighlightElements(final XtextResource resource, final IHighlightedPositionAcceptor acceptor) { + final Procedure1 _function = new Procedure1() { + @Override + public void apply(final EObject it) { + SuiteHighlightingCalculator.this.highlight(it, acceptor); + } + }; + IteratorExtensions.forEach(resource.getAllContents(), _function); + } + + protected Void _highlight(final SpecReference ref, final IHighlightedPositionAcceptor acceptor) { + this.highlightObjectAtFeature(acceptor, ref, SuitePackage.eINSTANCE.getSpecReference_Spec(), SuiteHighlightingConfiguration.LINK_ID); + return null; + } + + protected Void _highlight(final PatternReference ref, final IHighlightedPositionAcceptor acceptor) { + this.highlightObjectAtFeature(acceptor, ref, SuitePackage.eINSTANCE.getPatternReference_Pattern(), SuiteHighlightingConfiguration.PATTERN_ID); + return null; + } + + protected Void _highlight(final Suite suite, final IHighlightedPositionAcceptor acceptor) { + final ICompositeNode node = NodeModelUtils.getNode(suite); + int lineEnd = Strings.indexOfNewLine(suite.getName()); + if ((lineEnd == (-1))) { + lineEnd = suite.getName().length(); + } + acceptor.addPosition(node.getOffset(), lineEnd, SuiteHighlightingConfiguration.SUITE_ID); + return null; + } + + protected Void _highlight(final EObject ref, final IHighlightedPositionAcceptor acceptor) { + return null; + } + + public Void highlight(final EObject suite, final IHighlightedPositionAcceptor acceptor) { + if (suite instanceof Suite) { + return _highlight((Suite)suite, acceptor); + } else if (suite instanceof PatternReference) { + return _highlight((PatternReference)suite, acceptor); + } else if (suite instanceof SpecReference) { + return _highlight((SpecReference)suite, acceptor); + } else if (suite != null) { + return _highlight(suite, acceptor); + } else { + throw new IllegalArgumentException("Unhandled parameter types: " + + Arrays.asList(suite, acceptor).toString()); + } + } +} diff --git a/plugins/org.jnario.suite.ui/xtend-gen/org/jnario/suite/ui/hover/SuiteHoverProvider.java b/plugins/org.jnario.suite.ui/xtend-gen/org/jnario/suite/ui/hover/SuiteHoverProvider.java index 10d7c3ad9..aa6403143 100644 --- a/plugins/org.jnario.suite.ui/xtend-gen/org/jnario/suite/ui/hover/SuiteHoverProvider.java +++ b/plugins/org.jnario.suite.ui/xtend-gen/org/jnario/suite/ui/hover/SuiteHoverProvider.java @@ -1,66 +1,62 @@ -/** - * Copyright (c) 2012 BMW Car IT and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.jnario.suite.ui.hover; - -import com.google.inject.Inject; -import java.util.List; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jface.text.IRegion; -import org.eclipse.xtend2.lib.StringConcatenation; -import org.eclipse.xtext.xbase.lib.Extension; -import org.jnario.Specification; -import org.jnario.suite.jvmmodel.SpecResolver; -import org.jnario.suite.jvmmodel.SuiteClassNameProvider; -import org.jnario.suite.suite.PatternReference; -import org.jnario.ui.doc.JnarioHoverProvider; - -@SuppressWarnings("all") -public class SuiteHoverProvider extends JnarioHoverProvider { - @Inject - @Extension - private SpecResolver _specResolver; - - @Inject - @Extension - private SuiteClassNameProvider _suiteClassNameProvider; - - @Override - public String getHoverInfoAsHtml(final EObject call, final EObject objectToView, final IRegion hoverRegion) { - String comment = null; - if ((objectToView instanceof PatternReference)) { - final PatternReference spec = ((PatternReference) objectToView); - List _resolveSpecs = this._specResolver.resolveSpecs(spec); - CharSequence _document = this.document(_resolveSpecs); - String _string = _document.toString(); - comment = _string; - } else { - String _hoverInfoAsHtml = super.getHoverInfoAsHtml(call, objectToView, hoverRegion); - comment = _hoverInfoAsHtml; - } - return comment; - } - - public CharSequence document(final List specs) { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("
      "); - _builder.newLine(); - { - for(final Specification spec : specs) { - _builder.append("\t"); - _builder.append("
    • "); - String _describe = this._suiteClassNameProvider.describe(spec); - _builder.append(_describe, "\t"); - _builder.append("
    • "); - _builder.newLineIfNotEmpty(); - } - } - _builder.append("
    "); - _builder.newLine(); - return _builder; - } -} +/** + * Copyright (c) 2012 BMW Car IT and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.jnario.suite.ui.hover; + +import com.google.inject.Inject; +import java.util.List; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.jface.text.IRegion; +import org.eclipse.xtend2.lib.StringConcatenation; +import org.eclipse.xtext.xbase.lib.Extension; +import org.jnario.Specification; +import org.jnario.suite.jvmmodel.SpecResolver; +import org.jnario.suite.jvmmodel.SuiteClassNameProvider; +import org.jnario.suite.suite.PatternReference; +import org.jnario.ui.doc.JnarioHoverProvider; + +@SuppressWarnings("all") +public class SuiteHoverProvider extends JnarioHoverProvider { + @Inject + @Extension + private SpecResolver _specResolver; + + @Inject + @Extension + private SuiteClassNameProvider _suiteClassNameProvider; + + @Override + public String getHoverInfoAsHtml(final EObject call, final EObject objectToView, final IRegion hoverRegion) { + String comment = null; + if ((objectToView instanceof PatternReference)) { + final PatternReference spec = ((PatternReference) objectToView); + comment = this.document(this._specResolver.resolveSpecs(spec)).toString(); + } else { + comment = super.getHoverInfoAsHtml(call, objectToView, hoverRegion); + } + return comment; + } + + public CharSequence document(final List specs) { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("
      "); + _builder.newLine(); + { + for(final Specification spec : specs) { + _builder.append("\t"); + _builder.append("
    • "); + String _describe = this._suiteClassNameProvider.describe(spec); + _builder.append(_describe, "\t"); + _builder.append("
    • "); + _builder.newLineIfNotEmpty(); + } + } + _builder.append("
    "); + _builder.newLine(); + return _builder; + } +} diff --git a/plugins/org.jnario.suite.ui/xtend-gen/org/jnario/suite/ui/resource/SuiteResourceDescriptionManager.java b/plugins/org.jnario.suite.ui/xtend-gen/org/jnario/suite/ui/resource/SuiteResourceDescriptionManager.java index 617efdbc2..cf9a99164 100644 --- a/plugins/org.jnario.suite.ui/xtend-gen/org/jnario/suite/ui/resource/SuiteResourceDescriptionManager.java +++ b/plugins/org.jnario.suite.ui/xtend-gen/org/jnario/suite/ui/resource/SuiteResourceDescriptionManager.java @@ -1,400 +1,365 @@ -/** - * Copyright (c) 2012 BMW Car IT and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.jnario.suite.ui.resource; - -import com.google.common.base.Objects; -import com.google.common.collect.Iterables; -import com.google.inject.Inject; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.WeakHashMap; -import java.util.function.Consumer; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import org.apache.log4j.Logger; -import org.eclipse.emf.common.notify.Notifier; -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.common.util.URI; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.resource.ResourceSet; -import org.eclipse.emf.ecore.util.EcoreUtil; -import org.eclipse.xtext.builder.clustering.CurrentDescriptions; -import org.eclipse.xtext.builder.impl.BuildData; -import org.eclipse.xtext.naming.IQualifiedNameConverter; -import org.eclipse.xtext.naming.QualifiedName; -import org.eclipse.xtext.resource.DerivedStateAwareResourceDescriptionManager; -import org.eclipse.xtext.resource.IEObjectDescription; -import org.eclipse.xtext.resource.IResourceDescription; -import org.eclipse.xtext.resource.IResourceDescriptions; -import org.eclipse.xtext.xbase.lib.CollectionLiterals; -import org.eclipse.xtext.xbase.lib.Extension; -import org.eclipse.xtext.xbase.lib.Functions.Function1; -import org.eclipse.xtext.xbase.lib.IterableExtensions; -import org.eclipse.xtext.xbase.lib.ListExtensions; -import org.eclipse.xtext.xbase.lib.StringExtensions; -import org.jnario.JnarioPackage; -import org.jnario.Specification; -import org.jnario.feature.feature.FeaturePackage; -import org.jnario.spec.spec.SpecPackage; -import org.jnario.suite.suite.PatternReference; -import org.jnario.suite.suite.Reference; -import org.jnario.suite.suite.SpecReference; -import org.jnario.suite.suite.Suite; -import org.jnario.suite.suite.SuitePackage; - -@SuppressWarnings("all") -public class SuiteResourceDescriptionManager extends DerivedStateAwareResourceDescriptionManager { - private final static Logger logger = Logger.getLogger(SuiteResourceDescriptionManager.class); - - private final static HashSet FILE_EXTENSIONS = CollectionLiterals.newHashSet("suite", "spec", "feature"); - - @Inject - @Extension - private IQualifiedNameConverter _iQualifiedNameConverter; - - private final WeakHashMap, List> cachedDeltas = new WeakHashMap, List>(); - - /** - * Every spec change means new potential matches for a regex in a spec PatternReference. - */ - @Override - public boolean isAffected(final Collection deltas, final IResourceDescription candidate, final IResourceDescriptions context) { - boolean _isAffected = super.isAffected(deltas, candidate, context); - if (_isAffected) { - return true; - } - URI _uRI = candidate.getURI(); - String _string = _uRI.toString(); - boolean _endsWith = _string.endsWith(".suite"); - if (_endsWith) { - URI _uRI_1 = candidate.getURI(); - String _plus = ("Considering suite: " + _uRI_1); - SuiteResourceDescriptionManager.logger.debug(_plus); - boolean _isTraceEnabled = SuiteResourceDescriptionManager.logger.isTraceEnabled(); - if (_isTraceEnabled) { - SuiteResourceDescriptionManager.logger.debug(" Deltas to check: "); - final Consumer _function = new Consumer() { - @Override - public void accept(final IResourceDescription.Delta it) { - SuiteResourceDescriptionManager.logger.debug((" " + it)); - } - }; - deltas.forEach(_function); - } - ResourceSet _xifexpression = null; - if ((context instanceof CurrentDescriptions)) { - BuildData _buildData = ((CurrentDescriptions) context).getBuildData(); - _xifexpression = _buildData.getResourceSet(); - } else { - return false; - } - final ResourceSet resourceSet = _xifexpression; - List changedSpecs = this.cachedDeltas.get(deltas); - boolean _equals = Objects.equal(changedSpecs, null); - if (_equals) { - final Function1 _function_1 = new Function1() { - @Override - public Boolean apply(final IResourceDescription.Delta it) { - return Boolean.valueOf(SuiteResourceDescriptionManager.this.isSpecFile(it)); - } - }; - Iterable _filter = IterableExtensions.filter(deltas, _function_1); - final Function1> _function_2 = new Function1>() { - @Override - public Iterable apply(final IResourceDescription.Delta it) { - return SuiteResourceDescriptionManager.this.modifiedSpecs(it, resourceSet); - } - }; - Iterable> _map = IterableExtensions.>map(_filter, _function_2); - Iterable _flatten = Iterables.concat(_map); - List _list = IterableExtensions.toList(_flatten); - changedSpecs = _list; - this.cachedDeltas.put(deltas, changedSpecs); - } else { - SuiteResourceDescriptionManager.logger.trace(" using cached deltas"); - } - boolean _isEmpty = changedSpecs.isEmpty(); - if (_isEmpty) { - SuiteResourceDescriptionManager.logger.debug(" no relevant changes in delta"); - return false; - } - boolean _isDebugEnabled = SuiteResourceDescriptionManager.logger.isDebugEnabled(); - if (_isDebugEnabled) { - SuiteResourceDescriptionManager.logger.debug(" Changed specs: "); - final Consumer _function_3 = new Consumer() { - @Override - public void accept(final QualifiedName it) { - String _string = SuiteResourceDescriptionManager.this._iQualifiedNameConverter.toString(it); - String _plus = (" " + _string); - SuiteResourceDescriptionManager.logger.debug(_plus); - } - }; - changedSpecs.forEach(_function_3); - } - final Iterable suites = candidate.getExportedObjectsByType(SuitePackage.Literals.SUITE); - final Function1 _function_4 = new Function1() { - @Override - public Suite apply(final IEObjectDescription it) { - EObject _eObjectOrProxy = it.getEObjectOrProxy(); - EObject _resolve = EcoreUtil.resolve(((Suite) _eObjectOrProxy), resourceSet); - return ((Suite) _resolve); - } - }; - Iterable _map_1 = IterableExtensions.map(suites, _function_4); - final Function1 _function_5 = new Function1() { - @Override - public Boolean apply(final Suite it) { - boolean _eIsProxy = it.eIsProxy(); - return Boolean.valueOf((!_eIsProxy)); - } - }; - Iterable _filter_1 = IterableExtensions.filter(_map_1, _function_5); - final Function1> _function_6 = new Function1>() { - @Override - public List apply(final Suite it) { - List _resolvePatternReferences = SuiteResourceDescriptionManager.this.resolvePatternReferences(it); - final Function1 _function = new Function1() { - @Override - public Pattern apply(final PatternReference it) { - String _pattern = it.getPattern(); - return Pattern.compile(_pattern); - } - }; - return ListExtensions.map(_resolvePatternReferences, _function); - } - }; - Iterable> _map_2 = IterableExtensions.>map(_filter_1, _function_6); - Iterable _flatten_1 = Iterables.concat(_map_2); - final List matchers = IterableExtensions.toList(_flatten_1); - int _size = matchers.size(); - String _plus_1 = (" " + Integer.valueOf(_size)); - String _plus_2 = (_plus_1 + " referenced matchers"); - SuiteResourceDescriptionManager.logger.debug(_plus_2); - boolean _isTraceEnabled_1 = SuiteResourceDescriptionManager.logger.isTraceEnabled(); - if (_isTraceEnabled_1) { - final Consumer _function_7 = new Consumer() { - @Override - public void accept(final Pattern it) { - String _pattern = it.pattern(); - String _plus = (" " + _pattern); - SuiteResourceDescriptionManager.logger.trace(_plus); - } - }; - matchers.forEach(_function_7); - } - final Function1 _function_8 = new Function1() { - @Override - public Boolean apply(final QualifiedName specName) { - final Function1 _function = new Function1() { - @Override - public Boolean apply(final Pattern it) { - String _string = SuiteResourceDescriptionManager.this._iQualifiedNameConverter.toString(specName); - Matcher _matcher = it.matcher(_string); - return Boolean.valueOf(_matcher.matches()); - } - }; - Pattern _findFirst = IterableExtensions.findFirst(matchers, _function); - return Boolean.valueOf((!Objects.equal(_findFirst, null))); - } - }; - final QualifiedName firstRelevant = IterableExtensions.findFirst(changedSpecs, _function_8); - boolean _isDebugEnabled_1 = SuiteResourceDescriptionManager.logger.isDebugEnabled(); - if (_isDebugEnabled_1) { - boolean _notEquals = (!Objects.equal(firstRelevant, null)); - if (_notEquals) { - String _string_1 = this._iQualifiedNameConverter.toString(firstRelevant); - String _plus_3 = (">> relevant spec change: " + _string_1); - SuiteResourceDescriptionManager.logger.debug(_plus_3); - } else { - SuiteResourceDescriptionManager.logger.debug(" no relevant spec changes"); - } - } - return (!Objects.equal(firstRelevant, null)); - } - return false; - } - - protected List _resolvePatternReferences(final Suite suite) { - EList _elements = suite.getElements(); - final Function1> _function = new Function1>() { - @Override - public List apply(final Reference it) { - return SuiteResourceDescriptionManager.this.resolvePatternReferences(it); - } - }; - List> _map = ListExtensions.>map(_elements, _function); - Iterable _flatten = Iterables.concat(_map); - return IterableExtensions.toList(_flatten); - } - - protected List _resolvePatternReferences(final SpecReference specRef) { - return Collections.emptyList(); - } - - protected List _resolvePatternReferences(final PatternReference specRef) { - List _xblockexpression = null; - { - String _pattern = specRef.getPattern(); - boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(_pattern); - if (_isNullOrEmpty) { - return Collections.emptyList(); - } - _xblockexpression = Collections.singletonList(specRef); - } - return _xblockexpression; - } - - public boolean isSpecFile(final IResourceDescription.Delta delta) { - URI _uri = delta.getUri(); - String _fileExtension = _uri.fileExtension(); - return SuiteResourceDescriptionManager.FILE_EXTENSIONS.contains(_fileExtension); - } - - public Iterable modifiedSpecs(final IResourceDescription.Delta delta, final ResourceSet resourceSet) { - Iterable _xblockexpression = null; - { - final IResourceDescription old = delta.getOld(); - final IResourceDescription _new = delta.getNew(); - Iterable _xifexpression = null; - boolean _equals = Objects.equal(old, null); - if (_equals) { - _xifexpression = Collections.emptyList(); - } else { - _xifexpression = this.topLevelSpecs(old, resourceSet); - } - final Iterable oldEObjects = _xifexpression; - Iterable _xifexpression_1 = null; - boolean _equals_1 = Objects.equal(_new, null); - if (_equals_1) { - _xifexpression_1 = Collections.emptyList(); - } else { - _xifexpression_1 = this.topLevelSpecs(_new, resourceSet); - } - final Iterable newEObjects = _xifexpression_1; - final Function1 _function = new Function1() { - @Override - public QualifiedName apply(final IEObjectDescription it) { - return it.getQualifiedName(); - } - }; - final Map before = IterableExtensions.toMap(oldEObjects, _function); - final Function1 _function_1 = new Function1() { - @Override - public QualifiedName apply(final IEObjectDescription it) { - return it.getQualifiedName(); - } - }; - final Map after = IterableExtensions.toMap(newEObjects, _function_1); - Set _keySet = before.keySet(); - final Function1 _function_2 = new Function1() { - @Override - public Boolean apply(final QualifiedName it) { - boolean _containsKey = after.containsKey(it); - return Boolean.valueOf((!_containsKey)); - } - }; - Iterable _filter = IterableExtensions.filter(_keySet, _function_2); - final Set deleted = IterableExtensions.toSet(_filter); - Set _keySet_1 = after.keySet(); - final Function1 _function_3 = new Function1() { - @Override - public Boolean apply(final QualifiedName it) { - boolean _containsKey = before.containsKey(it); - return Boolean.valueOf((!_containsKey)); - } - }; - Iterable _filter_1 = IterableExtensions.filter(_keySet_1, _function_3); - final Set added = IterableExtensions.toSet(_filter_1); - Set _keySet_2 = before.keySet(); - Set _keySet_3 = after.keySet(); - Iterable _plus = Iterables.concat(_keySet_2, _keySet_3); - final Function1 _function_4 = new Function1() { - @Override - public Boolean apply(final QualifiedName it) { - return Boolean.valueOf((!(deleted.contains(it) || added.contains(it)))); - } - }; - final Iterable kept = IterableExtensions.filter(_plus, _function_4); - final Function1 _function_5 = new Function1() { - @Override - public Boolean apply(final QualifiedName it) { - IEObjectDescription _get = before.get(it); - IEObjectDescription _get_1 = after.get(it); - boolean _equals = SuiteResourceDescriptionManager.this.equals(_get, _get_1); - return Boolean.valueOf((!_equals)); - } - }; - final Iterable changed = IterableExtensions.filter(kept, _function_5); - Iterable _plus_1 = Iterables.concat(deleted, added); - _xblockexpression = Iterables.concat(_plus_1, changed); - } - return _xblockexpression; - } - - public Iterable topLevelSpecs(final IResourceDescription resource, final ResourceSet resourceSet) { - Iterable _exportedObjectsByType = resource.getExportedObjectsByType(JnarioPackage.Literals.SPECIFICATION); - final Function1 _function = new Function1() { - @Override - public Boolean apply(final IEObjectDescription it) { - boolean _xblockexpression = false; - { - EObject _eObjectOrProxy = it.getEObjectOrProxy(); - final EObject object = EcoreUtil.resolve(_eObjectOrProxy, resourceSet); - _xblockexpression = (((object instanceof Specification) && (!Objects.equal(object.eContainer(), null))) && - (Objects.equal(object.eContainer().eClass(), SpecPackage.Literals.SPEC_FILE) || - Objects.equal(object.eContainer().eClass(), FeaturePackage.Literals.FEATURE_FILE))); - } - return Boolean.valueOf(_xblockexpression); - } - }; - return IterableExtensions.filter(_exportedObjectsByType, _function); - } - - public boolean equals(final IEObjectDescription oldObj, final IEObjectDescription newObj) { - boolean _equals = Objects.equal(oldObj, newObj); - if (_equals) { - return true; - } - EClass _eClass = oldObj.getEClass(); - EClass _eClass_1 = newObj.getEClass(); - boolean _notEquals = (!Objects.equal(_eClass, _eClass_1)); - if (_notEquals) { - return false; - } - if (((!Objects.equal(oldObj.getName(), null)) && (!oldObj.getName().equals(newObj.getName())))) { - return false; - } - URI _eObjectURI = oldObj.getEObjectURI(); - URI _eObjectURI_1 = newObj.getEObjectURI(); - boolean _equals_1 = _eObjectURI.equals(_eObjectURI_1); - boolean _not = (!_equals_1); - if (_not) { - return false; - } - return true; - } - - public List resolvePatternReferences(final Notifier suite) { - if (suite instanceof Suite) { - return _resolvePatternReferences((Suite)suite); - } else if (suite instanceof PatternReference) { - return _resolvePatternReferences((PatternReference)suite); - } else if (suite instanceof SpecReference) { - return _resolvePatternReferences((SpecReference)suite); - } else { - throw new IllegalArgumentException("Unhandled parameter types: " + - Arrays.asList(suite).toString()); - } - } -} +/** + * Copyright (c) 2012 BMW Car IT and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.jnario.suite.ui.resource; + +import com.google.common.base.Objects; +import com.google.common.collect.Iterables; +import com.google.inject.Inject; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.WeakHashMap; +import java.util.function.Consumer; +import java.util.regex.Pattern; +import org.apache.log4j.Logger; +import org.eclipse.emf.common.notify.Notifier; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.emf.ecore.util.EcoreUtil; +import org.eclipse.xtext.builder.clustering.CurrentDescriptions; +import org.eclipse.xtext.naming.IQualifiedNameConverter; +import org.eclipse.xtext.naming.QualifiedName; +import org.eclipse.xtext.resource.DerivedStateAwareResourceDescriptionManager; +import org.eclipse.xtext.resource.IEObjectDescription; +import org.eclipse.xtext.resource.IResourceDescription; +import org.eclipse.xtext.resource.IResourceDescriptions; +import org.eclipse.xtext.xbase.lib.CollectionLiterals; +import org.eclipse.xtext.xbase.lib.Extension; +import org.eclipse.xtext.xbase.lib.Functions.Function1; +import org.eclipse.xtext.xbase.lib.IterableExtensions; +import org.eclipse.xtext.xbase.lib.ListExtensions; +import org.eclipse.xtext.xbase.lib.StringExtensions; +import org.jnario.JnarioPackage; +import org.jnario.Specification; +import org.jnario.feature.feature.FeaturePackage; +import org.jnario.spec.spec.SpecPackage; +import org.jnario.suite.suite.PatternReference; +import org.jnario.suite.suite.Reference; +import org.jnario.suite.suite.SpecReference; +import org.jnario.suite.suite.Suite; +import org.jnario.suite.suite.SuitePackage; + +@SuppressWarnings("all") +public class SuiteResourceDescriptionManager extends DerivedStateAwareResourceDescriptionManager { + private final static Logger logger = Logger.getLogger(SuiteResourceDescriptionManager.class); + + private final static HashSet FILE_EXTENSIONS = CollectionLiterals.newHashSet("suite", "spec", "feature"); + + @Inject + @Extension + private IQualifiedNameConverter _iQualifiedNameConverter; + + private final WeakHashMap, List> cachedDeltas = new WeakHashMap, List>(); + + /** + * Every spec change means new potential matches for a regex in a spec PatternReference. + */ + @Override + public boolean isAffected(final Collection deltas, final IResourceDescription candidate, final IResourceDescriptions context) { + boolean _isAffected = super.isAffected(deltas, candidate, context); + if (_isAffected) { + return true; + } + boolean _endsWith = candidate.getURI().toString().endsWith(".suite"); + if (_endsWith) { + URI _uRI = candidate.getURI(); + String _plus = ("Considering suite: " + _uRI); + SuiteResourceDescriptionManager.logger.debug(_plus); + boolean _isTraceEnabled = SuiteResourceDescriptionManager.logger.isTraceEnabled(); + if (_isTraceEnabled) { + SuiteResourceDescriptionManager.logger.debug(" Deltas to check: "); + final Consumer _function = new Consumer() { + @Override + public void accept(final IResourceDescription.Delta it) { + SuiteResourceDescriptionManager.logger.debug((" " + it)); + } + }; + deltas.forEach(_function); + } + ResourceSet _xifexpression = null; + if ((context instanceof CurrentDescriptions)) { + _xifexpression = ((CurrentDescriptions) context).getBuildData().getResourceSet(); + } else { + return false; + } + final ResourceSet resourceSet = _xifexpression; + List changedSpecs = this.cachedDeltas.get(deltas); + boolean _equals = Objects.equal(changedSpecs, null); + if (_equals) { + final Function1 _function_1 = new Function1() { + @Override + public Boolean apply(final IResourceDescription.Delta it) { + return Boolean.valueOf(SuiteResourceDescriptionManager.this.isSpecFile(it)); + } + }; + final Function1> _function_2 = new Function1>() { + @Override + public Iterable apply(final IResourceDescription.Delta it) { + return SuiteResourceDescriptionManager.this.modifiedSpecs(it, resourceSet); + } + }; + changedSpecs = IterableExtensions.toList(Iterables.concat(IterableExtensions.>map(IterableExtensions.filter(deltas, _function_1), _function_2))); + this.cachedDeltas.put(deltas, changedSpecs); + } else { + SuiteResourceDescriptionManager.logger.trace(" using cached deltas"); + } + boolean _isEmpty = changedSpecs.isEmpty(); + if (_isEmpty) { + SuiteResourceDescriptionManager.logger.debug(" no relevant changes in delta"); + return false; + } + boolean _isDebugEnabled = SuiteResourceDescriptionManager.logger.isDebugEnabled(); + if (_isDebugEnabled) { + SuiteResourceDescriptionManager.logger.debug(" Changed specs: "); + final Consumer _function_3 = new Consumer() { + @Override + public void accept(final QualifiedName it) { + String _string = SuiteResourceDescriptionManager.this._iQualifiedNameConverter.toString(it); + String _plus = (" " + _string); + SuiteResourceDescriptionManager.logger.debug(_plus); + } + }; + changedSpecs.forEach(_function_3); + } + final Iterable suites = candidate.getExportedObjectsByType(SuitePackage.Literals.SUITE); + final Function1 _function_4 = new Function1() { + @Override + public Suite apply(final IEObjectDescription it) { + EObject _eObjectOrProxy = it.getEObjectOrProxy(); + EObject _resolve = EcoreUtil.resolve(((Suite) _eObjectOrProxy), resourceSet); + return ((Suite) _resolve); + } + }; + final Function1 _function_5 = new Function1() { + @Override + public Boolean apply(final Suite it) { + boolean _eIsProxy = it.eIsProxy(); + return Boolean.valueOf((!_eIsProxy)); + } + }; + final Function1> _function_6 = new Function1>() { + @Override + public List apply(final Suite it) { + final Function1 _function = new Function1() { + @Override + public Pattern apply(final PatternReference it) { + return Pattern.compile(it.getPattern()); + } + }; + return ListExtensions.map(SuiteResourceDescriptionManager.this.resolvePatternReferences(it), _function); + } + }; + final List matchers = IterableExtensions.toList(Iterables.concat(IterableExtensions.>map(IterableExtensions.filter(IterableExtensions.map(suites, _function_4), _function_5), _function_6))); + int _size = matchers.size(); + String _plus_1 = (" " + Integer.valueOf(_size)); + String _plus_2 = (_plus_1 + " referenced matchers"); + SuiteResourceDescriptionManager.logger.debug(_plus_2); + boolean _isTraceEnabled_1 = SuiteResourceDescriptionManager.logger.isTraceEnabled(); + if (_isTraceEnabled_1) { + final Consumer _function_7 = new Consumer() { + @Override + public void accept(final Pattern it) { + String _pattern = it.pattern(); + String _plus = (" " + _pattern); + SuiteResourceDescriptionManager.logger.trace(_plus); + } + }; + matchers.forEach(_function_7); + } + final Function1 _function_8 = new Function1() { + @Override + public Boolean apply(final QualifiedName specName) { + final Function1 _function = new Function1() { + @Override + public Boolean apply(final Pattern it) { + return Boolean.valueOf(it.matcher(SuiteResourceDescriptionManager.this._iQualifiedNameConverter.toString(specName)).matches()); + } + }; + Pattern _findFirst = IterableExtensions.findFirst(matchers, _function); + return Boolean.valueOf((!Objects.equal(_findFirst, null))); + } + }; + final QualifiedName firstRelevant = IterableExtensions.findFirst(changedSpecs, _function_8); + boolean _isDebugEnabled_1 = SuiteResourceDescriptionManager.logger.isDebugEnabled(); + if (_isDebugEnabled_1) { + boolean _notEquals = (!Objects.equal(firstRelevant, null)); + if (_notEquals) { + String _string = this._iQualifiedNameConverter.toString(firstRelevant); + String _plus_3 = (">> relevant spec change: " + _string); + SuiteResourceDescriptionManager.logger.debug(_plus_3); + } else { + SuiteResourceDescriptionManager.logger.debug(" no relevant spec changes"); + } + } + return (!Objects.equal(firstRelevant, null)); + } + return false; + } + + protected List _resolvePatternReferences(final Suite suite) { + final Function1> _function = new Function1>() { + @Override + public List apply(final Reference it) { + return SuiteResourceDescriptionManager.this.resolvePatternReferences(it); + } + }; + return IterableExtensions.toList(Iterables.concat(ListExtensions.>map(suite.getElements(), _function))); + } + + protected List _resolvePatternReferences(final SpecReference specRef) { + return Collections.emptyList(); + } + + protected List _resolvePatternReferences(final PatternReference specRef) { + List _xblockexpression = null; + { + boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(specRef.getPattern()); + if (_isNullOrEmpty) { + return Collections.emptyList(); + } + _xblockexpression = Collections.singletonList(specRef); + } + return _xblockexpression; + } + + public boolean isSpecFile(final IResourceDescription.Delta delta) { + return SuiteResourceDescriptionManager.FILE_EXTENSIONS.contains(delta.getUri().fileExtension()); + } + + public Iterable modifiedSpecs(final IResourceDescription.Delta delta, final ResourceSet resourceSet) { + Iterable _xblockexpression = null; + { + final IResourceDescription old = delta.getOld(); + final IResourceDescription _new = delta.getNew(); + Iterable _xifexpression = null; + boolean _equals = Objects.equal(old, null); + if (_equals) { + _xifexpression = Collections.emptyList(); + } else { + _xifexpression = this.topLevelSpecs(old, resourceSet); + } + final Iterable oldEObjects = _xifexpression; + Iterable _xifexpression_1 = null; + boolean _equals_1 = Objects.equal(_new, null); + if (_equals_1) { + _xifexpression_1 = Collections.emptyList(); + } else { + _xifexpression_1 = this.topLevelSpecs(_new, resourceSet); + } + final Iterable newEObjects = _xifexpression_1; + final Function1 _function = new Function1() { + @Override + public QualifiedName apply(final IEObjectDescription it) { + return it.getQualifiedName(); + } + }; + final Map before = IterableExtensions.toMap(oldEObjects, _function); + final Function1 _function_1 = new Function1() { + @Override + public QualifiedName apply(final IEObjectDescription it) { + return it.getQualifiedName(); + } + }; + final Map after = IterableExtensions.toMap(newEObjects, _function_1); + final Function1 _function_2 = new Function1() { + @Override + public Boolean apply(final QualifiedName it) { + boolean _containsKey = after.containsKey(it); + return Boolean.valueOf((!_containsKey)); + } + }; + final Set deleted = IterableExtensions.toSet(IterableExtensions.filter(before.keySet(), _function_2)); + final Function1 _function_3 = new Function1() { + @Override + public Boolean apply(final QualifiedName it) { + boolean _containsKey = before.containsKey(it); + return Boolean.valueOf((!_containsKey)); + } + }; + final Set added = IterableExtensions.toSet(IterableExtensions.filter(after.keySet(), _function_3)); + Set _keySet = before.keySet(); + Set _keySet_1 = after.keySet(); + final Function1 _function_4 = new Function1() { + @Override + public Boolean apply(final QualifiedName it) { + return Boolean.valueOf((!(deleted.contains(it) || added.contains(it)))); + } + }; + final Iterable kept = IterableExtensions.filter(Iterables.concat(_keySet, _keySet_1), _function_4); + final Function1 _function_5 = new Function1() { + @Override + public Boolean apply(final QualifiedName it) { + boolean _equals = SuiteResourceDescriptionManager.this.equals(before.get(it), after.get(it)); + return Boolean.valueOf((!_equals)); + } + }; + final Iterable changed = IterableExtensions.filter(kept, _function_5); + Iterable _plus = Iterables.concat(deleted, added); + _xblockexpression = Iterables.concat(_plus, changed); + } + return _xblockexpression; + } + + public Iterable topLevelSpecs(final IResourceDescription resource, final ResourceSet resourceSet) { + final Function1 _function = new Function1() { + @Override + public Boolean apply(final IEObjectDescription it) { + boolean _xblockexpression = false; + { + final EObject object = EcoreUtil.resolve(it.getEObjectOrProxy(), resourceSet); + _xblockexpression = (((object instanceof Specification) && (!Objects.equal(object.eContainer(), null))) && + (Objects.equal(object.eContainer().eClass(), SpecPackage.Literals.SPEC_FILE) || + Objects.equal(object.eContainer().eClass(), FeaturePackage.Literals.FEATURE_FILE))); + } + return Boolean.valueOf(_xblockexpression); + } + }; + return IterableExtensions.filter(resource.getExportedObjectsByType(JnarioPackage.Literals.SPECIFICATION), _function); + } + + public boolean equals(final IEObjectDescription oldObj, final IEObjectDescription newObj) { + boolean _equals = Objects.equal(oldObj, newObj); + if (_equals) { + return true; + } + EClass _eClass = oldObj.getEClass(); + EClass _eClass_1 = newObj.getEClass(); + boolean _notEquals = (!Objects.equal(_eClass, _eClass_1)); + if (_notEquals) { + return false; + } + if (((!Objects.equal(oldObj.getName(), null)) && (!oldObj.getName().equals(newObj.getName())))) { + return false; + } + boolean _equals_1 = oldObj.getEObjectURI().equals(newObj.getEObjectURI()); + boolean _not = (!_equals_1); + if (_not) { + return false; + } + return true; + } + + public List resolvePatternReferences(final Notifier suite) { + if (suite instanceof Suite) { + return _resolvePatternReferences((Suite)suite); + } else if (suite instanceof PatternReference) { + return _resolvePatternReferences((PatternReference)suite); + } else if (suite instanceof SpecReference) { + return _resolvePatternReferences((SpecReference)suite); + } else { + throw new IllegalArgumentException("Unhandled parameter types: " + + Arrays.asList(suite).toString()); + } + } +} diff --git a/plugins/org.jnario.suite/xtend-gen/org/jnario/suite/conversion/PatternValueConverter.java b/plugins/org.jnario.suite/xtend-gen/org/jnario/suite/conversion/PatternValueConverter.java index b2a3dd339..0539e13ee 100644 --- a/plugins/org.jnario.suite/xtend-gen/org/jnario/suite/conversion/PatternValueConverter.java +++ b/plugins/org.jnario.suite/xtend-gen/org/jnario/suite/conversion/PatternValueConverter.java @@ -1,58 +1,58 @@ -/** - * Copyright (c) 2012 BMW Car IT and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.jnario.suite.conversion; - -import com.google.common.base.Objects; -import java.util.regex.Pattern; -import java.util.regex.PatternSyntaxException; -import org.eclipse.xtext.conversion.IValueConverter; -import org.eclipse.xtext.conversion.ValueConverterException; -import org.eclipse.xtext.nodemodel.INode; -import org.eclipse.xtext.util.Strings; -import org.eclipse.xtext.xbase.lib.Exceptions; - -@SuppressWarnings("all") -public class PatternValueConverter implements IValueConverter { - @Override - public String toString(final String string) throws ValueConverterException { - String _xblockexpression = null; - { - String result = string; - boolean _equals = Objects.equal(result, null); - if (_equals) { - result = ""; - } - String _newLine = Strings.newLine(); - _xblockexpression = ((("\\" + result) + "\\") + _newLine); - } - return _xblockexpression; - } - - @Override - public String toValue(final String string, final INode node) throws ValueConverterException { - try { - boolean _isNullOrEmpty = com.google.common.base.Strings.isNullOrEmpty(string); - if (_isNullOrEmpty) { - return null; - } - int begin = string.indexOf("\\"); - int end = string.lastIndexOf("\\"); - final String result = string.substring((begin + 1), end); - Pattern.compile(result); - return result; - } catch (final Throwable _t) { - if (_t instanceof PatternSyntaxException) { - final PatternSyntaxException e = (PatternSyntaxException)_t; - String _message = e.getMessage(); - throw new ValueConverterException(_message, node, e); - } else { - throw Exceptions.sneakyThrow(_t); - } - } - } -} +/** + * Copyright (c) 2012 BMW Car IT and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.jnario.suite.conversion; + +import com.google.common.base.Objects; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; +import org.eclipse.xtext.conversion.IValueConverter; +import org.eclipse.xtext.conversion.ValueConverterException; +import org.eclipse.xtext.nodemodel.INode; +import org.eclipse.xtext.util.Strings; +import org.eclipse.xtext.xbase.lib.Exceptions; + +@SuppressWarnings("all") +public class PatternValueConverter implements IValueConverter { + @Override + public String toString(final String string) throws ValueConverterException { + String _xblockexpression = null; + { + String result = string; + boolean _equals = Objects.equal(result, null); + if (_equals) { + result = ""; + } + String _newLine = Strings.newLine(); + _xblockexpression = ((("\\" + result) + "\\") + _newLine); + } + return _xblockexpression; + } + + @Override + public String toValue(final String string, final INode node) throws ValueConverterException { + try { + boolean _isNullOrEmpty = com.google.common.base.Strings.isNullOrEmpty(string); + if (_isNullOrEmpty) { + return null; + } + int begin = string.indexOf("\\"); + int end = string.lastIndexOf("\\"); + final String result = string.substring((begin + 1), end); + Pattern.compile(result); + return result; + } catch (final Throwable _t) { + if (_t instanceof PatternSyntaxException) { + final PatternSyntaxException e = (PatternSyntaxException)_t; + String _message = e.getMessage(); + throw new ValueConverterException(_message, node, e); + } else { + throw Exceptions.sneakyThrow(_t); + } + } + } +} diff --git a/plugins/org.jnario.suite/xtend-gen/org/jnario/suite/conversion/SuiteValueConverter.java b/plugins/org.jnario.suite/xtend-gen/org/jnario/suite/conversion/SuiteValueConverter.java index c2b21d28a..d164209f1 100644 --- a/plugins/org.jnario.suite/xtend-gen/org/jnario/suite/conversion/SuiteValueConverter.java +++ b/plugins/org.jnario.suite/xtend-gen/org/jnario/suite/conversion/SuiteValueConverter.java @@ -1,59 +1,55 @@ -/** - * Copyright (c) 2012 BMW Car IT and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.jnario.suite.conversion; - -import com.google.common.base.Objects; -import org.eclipse.xtext.conversion.IValueConverter; -import org.eclipse.xtext.conversion.ValueConverterException; -import org.eclipse.xtext.nodemodel.INode; -import org.jnario.util.Strings; - -@SuppressWarnings("all") -public class SuiteValueConverter implements IValueConverter { - private final char prefix; - - public SuiteValueConverter(final char prefix) { - this.prefix = prefix; - } - - @Override - public String toString(final String value) throws ValueConverterException { - String _xblockexpression = null; - { - boolean _equals = Objects.equal(value, null); - if (_equals) { - return null; - } - final int begin = Strings.lastIndexOfPrefix(value, this.prefix); - final String prefix = value.substring(0, begin); - String _substring = value.substring(begin); - String _replace = _substring.replace("-", "\\-"); - String _replace_1 = _replace.replace("#", "\\#"); - _xblockexpression = (prefix + _replace_1); - } - return _xblockexpression; - } - - @Override - public String toValue(final String string, final INode node) throws ValueConverterException { - String _xblockexpression = null; - { - boolean _equals = Objects.equal(string, null); - if (_equals) { - return null; - } - final int begin = Strings.lastIndexOfPrefix(string, this.prefix); - final String prefix = string.substring(0, begin); - String _substring = string.substring(begin); - String _replace = _substring.replace("\\-", "-"); - String _replace_1 = _replace.replace("\\#", "#"); - _xblockexpression = (prefix + _replace_1); - } - return _xblockexpression; - } -} +/** + * Copyright (c) 2012 BMW Car IT and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.jnario.suite.conversion; + +import com.google.common.base.Objects; +import org.eclipse.xtext.conversion.IValueConverter; +import org.eclipse.xtext.conversion.ValueConverterException; +import org.eclipse.xtext.nodemodel.INode; +import org.jnario.util.Strings; + +@SuppressWarnings("all") +public class SuiteValueConverter implements IValueConverter { + private final char prefix; + + public SuiteValueConverter(final char prefix) { + this.prefix = prefix; + } + + @Override + public String toString(final String value) throws ValueConverterException { + String _xblockexpression = null; + { + boolean _equals = Objects.equal(value, null); + if (_equals) { + return null; + } + final int begin = Strings.lastIndexOfPrefix(value, this.prefix); + final String prefix = value.substring(0, begin); + String _replace = value.substring(begin).replace("-", "\\-").replace("#", "\\#"); + _xblockexpression = (prefix + _replace); + } + return _xblockexpression; + } + + @Override + public String toValue(final String string, final INode node) throws ValueConverterException { + String _xblockexpression = null; + { + boolean _equals = Objects.equal(string, null); + if (_equals) { + return null; + } + final int begin = Strings.lastIndexOfPrefix(string, this.prefix); + final String prefix = string.substring(0, begin); + String _replace = string.substring(begin).replace("\\-", "-").replace("\\#", "#"); + _xblockexpression = (prefix + _replace); + } + return _xblockexpression; + } +} diff --git a/plugins/org.jnario.suite/xtend-gen/org/jnario/suite/conversion/SuiteValueConverterService.java b/plugins/org.jnario.suite/xtend-gen/org/jnario/suite/conversion/SuiteValueConverterService.java index 885af7a93..12759c087 100644 --- a/plugins/org.jnario.suite/xtend-gen/org/jnario/suite/conversion/SuiteValueConverterService.java +++ b/plugins/org.jnario.suite/xtend-gen/org/jnario/suite/conversion/SuiteValueConverterService.java @@ -1,39 +1,39 @@ -/** - * Copyright (c) 2012 BMW Car IT and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.jnario.suite.conversion; - -import org.eclipse.xtext.conversion.IValueConverter; -import org.eclipse.xtext.conversion.ValueConverter; -import org.eclipse.xtext.xbase.conversion.XbaseValueConverterService; -import org.jnario.suite.conversion.PatternValueConverter; -import org.jnario.suite.conversion.SuiteValueConverter; -import org.jnario.suite.conversion.TextValueConverter; - -@SuppressWarnings("all") -public class SuiteValueConverterService extends XbaseValueConverterService { - private final TextValueConverter textValueConverter = new TextValueConverter(":", ""); - - private final PatternValueConverter patternValueConverter = new PatternValueConverter(); - - private final SuiteValueConverter suiteValueConverter = new SuiteValueConverter("#".charAt(0)); - - @ValueConverter(rule = "TEXT") - public IValueConverter getTextValueConverter() { - return this.textValueConverter; - } - - @ValueConverter(rule = "PATTERN") - public IValueConverter getPatternValueConverter() { - return this.patternValueConverter; - } - - @ValueConverter(rule = "SUITE_NAME") - public IValueConverter getSuiteValueConverter() { - return this.suiteValueConverter; - } -} +/** + * Copyright (c) 2012 BMW Car IT and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.jnario.suite.conversion; + +import org.eclipse.xtext.conversion.IValueConverter; +import org.eclipse.xtext.conversion.ValueConverter; +import org.eclipse.xtext.xbase.conversion.XbaseValueConverterService; +import org.jnario.suite.conversion.PatternValueConverter; +import org.jnario.suite.conversion.SuiteValueConverter; +import org.jnario.suite.conversion.TextValueConverter; + +@SuppressWarnings("all") +public class SuiteValueConverterService extends XbaseValueConverterService { + private final TextValueConverter textValueConverter = new TextValueConverter(":", ""); + + private final PatternValueConverter patternValueConverter = new PatternValueConverter(); + + private final SuiteValueConverter suiteValueConverter = new SuiteValueConverter("#".charAt(0)); + + @ValueConverter(rule = "TEXT") + public IValueConverter getTextValueConverter() { + return this.textValueConverter; + } + + @ValueConverter(rule = "PATTERN") + public IValueConverter getPatternValueConverter() { + return this.patternValueConverter; + } + + @ValueConverter(rule = "SUITE_NAME") + public IValueConverter getSuiteValueConverter() { + return this.suiteValueConverter; + } +} diff --git a/plugins/org.jnario.suite/xtend-gen/org/jnario/suite/conversion/TextValueConverter.java b/plugins/org.jnario.suite/xtend-gen/org/jnario/suite/conversion/TextValueConverter.java index 8b4d12e43..339020aa9 100644 --- a/plugins/org.jnario.suite/xtend-gen/org/jnario/suite/conversion/TextValueConverter.java +++ b/plugins/org.jnario.suite/xtend-gen/org/jnario/suite/conversion/TextValueConverter.java @@ -1,50 +1,48 @@ -/** - * Copyright (c) 2012 BMW Car IT and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.jnario.suite.conversion; - -import com.google.common.base.Objects; -import org.eclipse.xtext.conversion.ValueConverterException; -import org.eclipse.xtext.nodemodel.INode; -import org.jnario.suite.conversion.SuiteValueConverter; - -@SuppressWarnings("all") -public class TextValueConverter extends SuiteValueConverter { - private final String prefix; - - private final String postfix; - - public TextValueConverter(final String prefix, final String postfix) { - super(":".charAt(0)); - this.prefix = prefix; - this.postfix = postfix; - } - - @Override - public String toString(final String value) throws ValueConverterException { - String _string = super.toString(value); - String _plus = (this.prefix + _string); - return (_plus + this.postfix); - } - - @Override - public String toValue(final String input, final INode node) throws ValueConverterException { - String string = super.toValue(input, node); - String result = ""; - boolean _notEquals = (!Objects.equal(string, null)); - if (_notEquals) { - int _length = this.prefix.length(); - int _length_1 = string.length(); - int _length_2 = this.postfix.length(); - int _minus = (_length_1 - _length_2); - String _substring = string.substring(_length, _minus); - String _trim = _substring.trim(); - result = _trim; - } - return result; - } -} +/** + * Copyright (c) 2012 BMW Car IT and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.jnario.suite.conversion; + +import com.google.common.base.Objects; +import org.eclipse.xtext.conversion.ValueConverterException; +import org.eclipse.xtext.nodemodel.INode; +import org.jnario.suite.conversion.SuiteValueConverter; + +@SuppressWarnings("all") +public class TextValueConverter extends SuiteValueConverter { + private final String prefix; + + private final String postfix; + + public TextValueConverter(final String prefix, final String postfix) { + super(":".charAt(0)); + this.prefix = prefix; + this.postfix = postfix; + } + + @Override + public String toString(final String value) throws ValueConverterException { + String _string = super.toString(value); + String _plus = (this.prefix + _string); + return (_plus + this.postfix); + } + + @Override + public String toValue(final String input, final INode node) throws ValueConverterException { + String string = super.toValue(input, node); + String result = ""; + boolean _notEquals = (!Objects.equal(string, null)); + if (_notEquals) { + int _length = this.prefix.length(); + int _length_1 = string.length(); + int _length_2 = this.postfix.length(); + int _minus = (_length_1 - _length_2); + result = string.substring(_length, _minus).trim(); + } + return result; + } +} diff --git a/plugins/org.jnario.suite/xtend-gen/org/jnario/suite/doc/SuiteDocGenerator.java b/plugins/org.jnario.suite/xtend-gen/org/jnario/suite/doc/SuiteDocGenerator.java index f98e02003..f0210ee55 100644 --- a/plugins/org.jnario.suite/xtend-gen/org/jnario/suite/doc/SuiteDocGenerator.java +++ b/plugins/org.jnario.suite/xtend-gen/org/jnario/suite/doc/SuiteDocGenerator.java @@ -1,283 +1,254 @@ -/** - * Copyright (c) 2012 BMW Car IT and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.jnario.suite.doc; - -import com.google.common.base.Objects; -import com.google.common.collect.Iterables; -import com.google.inject.Inject; -import java.util.List; -import java.util.function.Consumer; -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.xtend2.lib.StringConcatenation; -import org.eclipse.xtext.generator.IFileSystemAccess; -import org.eclipse.xtext.xbase.lib.Extension; -import org.eclipse.xtext.xbase.lib.IterableExtensions; -import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; -import org.eclipse.xtext.xbase.lib.StringExtensions; -import org.jnario.JnarioClass; -import org.jnario.JnarioTypeDeclaration; -import org.jnario.Specification; -import org.jnario.doc.AbstractDocGenerator; -import org.jnario.doc.HtmlFile; -import org.jnario.doc.HtmlFileBuilder; -import org.jnario.report.Executable2ResultMapping; -import org.jnario.suite.jvmmodel.SpecResolver; -import org.jnario.suite.jvmmodel.SuiteClassNameProvider; -import org.jnario.suite.suite.Reference; -import org.jnario.suite.suite.SpecReference; -import org.jnario.suite.suite.Suite; -import org.jnario.suite.suite.SuiteFile; -import org.jnario.util.Strings; -import org.jnario.util.XtendTypes; - -@SuppressWarnings("all") -public class SuiteDocGenerator extends AbstractDocGenerator { - @Inject - @Extension - private SuiteClassNameProvider _suiteClassNameProvider; - - @Inject - @Extension - private SpecResolver _specResolver; - - @Inject - @Extension - private HtmlFileBuilder _htmlFileBuilder; - - @Override - public void doGenerate(final Resource input, final IFileSystemAccess fsa, final Executable2ResultMapping spec2ResultMapping) { - this.initResultMapping(spec2ResultMapping); - EList _contents = input.getContents(); - Iterable _filter = Iterables.filter(_contents, SuiteFile.class); - final Consumer _function = new Consumer() { - @Override - public void accept(final SuiteFile it) { - final HtmlFile htmlFile = SuiteDocGenerator.this.createHtmlFile(it); - EList _xtendTypes = it.getXtendTypes(); - JnarioTypeDeclaration _head = IterableExtensions.head(_xtendTypes); - SuiteDocGenerator.this._htmlFileBuilder.generate(_head, fsa, htmlFile); - } - }; - _filter.forEach(_function); - } - - public HtmlFile createHtmlFile(final SuiteFile file) { - HtmlFile _xblockexpression = null; - { - EList _xtendTypes = file.getXtendTypes(); - final Iterable suites = Iterables.filter(_xtendTypes, Suite.class); - boolean _isEmpty = IterableExtensions.isEmpty(suites); - if (_isEmpty) { - return HtmlFile.EMPTY_FILE; - } - final Suite rootSuite = IterableExtensions.head(suites); - final Procedure1 _function = new Procedure1() { - @Override - public void apply(final HtmlFile it) { - String _javaClassName = SuiteDocGenerator.this._suiteClassNameProvider.toJavaClassName(rootSuite); - it.setName(_javaClassName); - String _describe = SuiteDocGenerator.this._suiteClassNameProvider.describe(rootSuite); - String _decode = SuiteDocGenerator.this.decode(_describe); - it.setTitle(_decode); - CharSequence _generateContent = SuiteDocGenerator.this.generateContent(suites); - it.setContent(_generateContent); - String _root = SuiteDocGenerator.this.root(rootSuite); - it.setRootFolder(_root); - CharSequence _pre = SuiteDocGenerator.this.pre(file, "lang-suite"); - it.setSourceCode(_pre); - String _fileName = SuiteDocGenerator.this.fileName(file); - it.setFileName(_fileName); - String _executionStateClass = SuiteDocGenerator.this.executionStateClass(rootSuite); - it.setExecutionStatus(_executionStateClass); - } - }; - _xblockexpression = HtmlFile.newHtmlFile(_function); - } - return _xblockexpression; - } - - @Override - public HtmlFile createHtmlFile(final JnarioClass file) { - HtmlFile _xblockexpression = null; - { - final Suite suite = ((Suite) file); - final Procedure1 _function = new Procedure1() { - @Override - public void apply(final HtmlFile it) { - String _javaClassName = SuiteDocGenerator.this._suiteClassNameProvider.toJavaClassName(suite); - it.setName(_javaClassName); - String _describe = SuiteDocGenerator.this._suiteClassNameProvider.describe(suite); - String _decode = SuiteDocGenerator.this.decode(_describe); - it.setTitle(_decode); - CharSequence _generateContent = SuiteDocGenerator.this.generateContent(suite); - it.setContent(_generateContent); - String _root = SuiteDocGenerator.this.root(suite); - it.setRootFolder(_root); - CharSequence _pre = SuiteDocGenerator.this.pre(file, "lang-suite"); - it.setSourceCode(_pre); - String _fileName = SuiteDocGenerator.this.fileName(file); - it.setFileName(_fileName); - String _executionStateClass = SuiteDocGenerator.this.executionStateClass(suite); - it.setExecutionStatus(_executionStateClass); - } - }; - _xblockexpression = HtmlFile.newHtmlFile(_function); - } - return _xblockexpression; - } - - public CharSequence generateContent(final Iterable suites) { - StringConcatenation _builder = new StringConcatenation(); - { - for(final Suite suite : suites) { - { - Suite _head = IterableExtensions.head(suites); - boolean _equals = Objects.equal(suite, _head); - boolean _not = (!_equals); - if (_not) { - CharSequence _title = this.title(suite); - _builder.append(_title, ""); - _builder.newLineIfNotEmpty(); - } - } - CharSequence _generateContent = this.generateContent(suite); - _builder.append(_generateContent, ""); - _builder.newLineIfNotEmpty(); - } - } - return _builder; - } - - public CharSequence title(final Suite suite) { - StringConcatenation _builder = new StringConcatenation(); - String _name = suite.getName(); - final String title = Strings.firstLine(_name); - _builder.newLineIfNotEmpty(); - _builder.append(""); - String _markdown2Html = this.markdown2Html(title); - _builder.append(_markdown2Html, ""); - _builder.append(""); - _builder.newLineIfNotEmpty(); - return _builder; - } - - public String desc(final Suite suite) { - String _name = suite.getName(); - String _trimFirstLine = Strings.trimFirstLine(_name); - return this.markdown2Html(_trimFirstLine); - } - - public CharSequence generateContent(final Suite suite) { - StringConcatenation _builder = new StringConcatenation(); - String _desc = this.desc(suite); - _builder.append(_desc, ""); - _builder.newLineIfNotEmpty(); - { - EList _elements = suite.getElements(); - boolean _isEmpty = _elements.isEmpty(); - boolean _not = (!_isEmpty); - if (_not) { - _builder.append("
      "); - _builder.newLine(); - { - EList _elements_1 = suite.getElements(); - for(final Reference spec : _elements_1) { - _builder.append("\t"); - CharSequence _generate = this.generate(spec); - _builder.append(_generate, "\t"); - _builder.newLineIfNotEmpty(); - } - } - _builder.append("
    "); - _builder.newLine(); - } - } - return _builder; - } - - public CharSequence generate(final Reference ref) { - StringConcatenation _builder = new StringConcatenation(); - { - List _resolveSpecs = this._specResolver.resolveSpecs(ref); - for(final Specification spec : _resolveSpecs) { - _builder.append("
  • "); - String _describe = this._suiteClassNameProvider.describe(spec); - _builder.append(_describe, ""); - _builder.append(""); - String _executionState = this.executionState(spec); - _builder.append(_executionState, ""); - String _text = this.text(ref); - _builder.append(_text, ""); - _builder.append("
  • "); - _builder.newLineIfNotEmpty(); - } - } - return _builder; - } - - public String linkTo(final EObject context, final Specification spec) { - String _xblockexpression = null; - { - String _xifexpression = null; - String _packageName = XtendTypes.packageName(spec); - boolean _equals = Objects.equal(_packageName, null); - if (_equals) { - _xifexpression = ""; - } else { - String _packageName_1 = XtendTypes.packageName(spec); - _xifexpression = _packageName_1.replace(".", "/"); - } - final String path = _xifexpression; - String _root = this.root(context); - String _plus = (_root + path); - String _plus_1 = (_plus + "/"); - String _javaClassName = this._suiteClassNameProvider.toJavaClassName(spec); - String _htmlFileName = this.htmlFileName(_javaClassName); - _xblockexpression = (_plus_1 + _htmlFileName); - } - return _xblockexpression; - } - - public String text(final Reference ref) { - boolean _matched = false; - if (ref instanceof SpecReference) { - String _text = ((SpecReference)ref).getText(); - String _trim = null; - if (_text!=null) { - _trim=_text.trim(); - } - boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(_trim); - boolean _not = (!_isNullOrEmpty); - if (_not) { - _matched=true; - String _text_1 = ((SpecReference)ref).getText(); - String result = this.markdown2Html(_text_1); - int _length = result.length(); - int _minus = (_length - 4); - String _substring = result.substring(3, _minus); - result = _substring; - return (": " + result); - } - } - return ""; - } -} +/** + * Copyright (c) 2012 BMW Car IT and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.jnario.suite.doc; + +import com.google.common.base.Objects; +import com.google.common.collect.Iterables; +import com.google.inject.Inject; +import java.util.List; +import java.util.function.Consumer; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.xtend2.lib.StringConcatenation; +import org.eclipse.xtext.generator.IFileSystemAccess; +import org.eclipse.xtext.xbase.lib.Extension; +import org.eclipse.xtext.xbase.lib.IterableExtensions; +import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; +import org.eclipse.xtext.xbase.lib.StringExtensions; +import org.jnario.JnarioClass; +import org.jnario.JnarioTypeDeclaration; +import org.jnario.Specification; +import org.jnario.doc.AbstractDocGenerator; +import org.jnario.doc.HtmlFile; +import org.jnario.doc.HtmlFileBuilder; +import org.jnario.report.Executable2ResultMapping; +import org.jnario.suite.jvmmodel.SpecResolver; +import org.jnario.suite.jvmmodel.SuiteClassNameProvider; +import org.jnario.suite.suite.Reference; +import org.jnario.suite.suite.SpecReference; +import org.jnario.suite.suite.Suite; +import org.jnario.suite.suite.SuiteFile; +import org.jnario.util.Strings; +import org.jnario.util.XtendTypes; + +@SuppressWarnings("all") +public class SuiteDocGenerator extends AbstractDocGenerator { + @Inject + @Extension + private SuiteClassNameProvider _suiteClassNameProvider; + + @Inject + @Extension + private SpecResolver _specResolver; + + @Inject + @Extension + private HtmlFileBuilder _htmlFileBuilder; + + @Override + public void doGenerate(final Resource input, final IFileSystemAccess fsa, final Executable2ResultMapping spec2ResultMapping) { + this.initResultMapping(spec2ResultMapping); + final Consumer _function = new Consumer() { + @Override + public void accept(final SuiteFile it) { + final HtmlFile htmlFile = SuiteDocGenerator.this.createHtmlFile(it); + SuiteDocGenerator.this._htmlFileBuilder.generate(IterableExtensions.head(it.getXtendTypes()), fsa, htmlFile); + } + }; + Iterables.filter(input.getContents(), SuiteFile.class).forEach(_function); + } + + public HtmlFile createHtmlFile(final SuiteFile file) { + HtmlFile _xblockexpression = null; + { + final Iterable suites = Iterables.filter(file.getXtendTypes(), Suite.class); + boolean _isEmpty = IterableExtensions.isEmpty(suites); + if (_isEmpty) { + return HtmlFile.EMPTY_FILE; + } + final Suite rootSuite = IterableExtensions.head(suites); + final Procedure1 _function = new Procedure1() { + @Override + public void apply(final HtmlFile it) { + it.setName(SuiteDocGenerator.this._suiteClassNameProvider.toJavaClassName(rootSuite)); + it.setTitle(SuiteDocGenerator.this.decode(SuiteDocGenerator.this._suiteClassNameProvider.describe(rootSuite))); + it.setContent(SuiteDocGenerator.this.generateContent(suites)); + it.setRootFolder(SuiteDocGenerator.this.root(rootSuite)); + it.setSourceCode(SuiteDocGenerator.this.pre(file, "lang-suite")); + it.setFileName(SuiteDocGenerator.this.fileName(file)); + it.setExecutionStatus(SuiteDocGenerator.this.executionStateClass(rootSuite)); + } + }; + _xblockexpression = HtmlFile.newHtmlFile(_function); + } + return _xblockexpression; + } + + @Override + public HtmlFile createHtmlFile(final JnarioClass file) { + HtmlFile _xblockexpression = null; + { + final Suite suite = ((Suite) file); + final Procedure1 _function = new Procedure1() { + @Override + public void apply(final HtmlFile it) { + it.setName(SuiteDocGenerator.this._suiteClassNameProvider.toJavaClassName(suite)); + it.setTitle(SuiteDocGenerator.this.decode(SuiteDocGenerator.this._suiteClassNameProvider.describe(suite))); + it.setContent(SuiteDocGenerator.this.generateContent(suite)); + it.setRootFolder(SuiteDocGenerator.this.root(suite)); + it.setSourceCode(SuiteDocGenerator.this.pre(file, "lang-suite")); + it.setFileName(SuiteDocGenerator.this.fileName(file)); + it.setExecutionStatus(SuiteDocGenerator.this.executionStateClass(suite)); + } + }; + _xblockexpression = HtmlFile.newHtmlFile(_function); + } + return _xblockexpression; + } + + public CharSequence generateContent(final Iterable suites) { + StringConcatenation _builder = new StringConcatenation(); + { + for(final Suite suite : suites) { + { + Suite _head = IterableExtensions.head(suites); + boolean _equals = Objects.equal(suite, _head); + boolean _not = (!_equals); + if (_not) { + CharSequence _title = this.title(suite); + _builder.append(_title); + _builder.newLineIfNotEmpty(); + } + } + CharSequence _generateContent = this.generateContent(suite); + _builder.append(_generateContent); + _builder.newLineIfNotEmpty(); + } + } + return _builder; + } + + public CharSequence title(final Suite suite) { + StringConcatenation _builder = new StringConcatenation(); + final String title = Strings.firstLine(suite.getName()); + _builder.newLineIfNotEmpty(); + _builder.append(""); + String _markdown2Html = this.markdown2Html(title); + _builder.append(_markdown2Html); + _builder.append(""); + _builder.newLineIfNotEmpty(); + return _builder; + } + + public String desc(final Suite suite) { + return this.markdown2Html(Strings.trimFirstLine(suite.getName())); + } + + public CharSequence generateContent(final Suite suite) { + StringConcatenation _builder = new StringConcatenation(); + String _desc = this.desc(suite); + _builder.append(_desc); + _builder.newLineIfNotEmpty(); + { + boolean _isEmpty = suite.getElements().isEmpty(); + boolean _not = (!_isEmpty); + if (_not) { + _builder.append("
      "); + _builder.newLine(); + { + EList _elements = suite.getElements(); + for(final Reference spec : _elements) { + _builder.append("\t"); + CharSequence _generate = this.generate(spec); + _builder.append(_generate, "\t"); + _builder.newLineIfNotEmpty(); + } + } + _builder.append("
    "); + _builder.newLine(); + } + } + return _builder; + } + + public CharSequence generate(final Reference ref) { + StringConcatenation _builder = new StringConcatenation(); + { + List _resolveSpecs = this._specResolver.resolveSpecs(ref); + for(final Specification spec : _resolveSpecs) { + _builder.append("
  • "); + String _describe = this._suiteClassNameProvider.describe(spec); + _builder.append(_describe); + _builder.append(""); + String _executionState = this.executionState(spec); + _builder.append(_executionState); + String _text = this.text(ref); + _builder.append(_text); + _builder.append("
  • "); + _builder.newLineIfNotEmpty(); + } + } + return _builder; + } + + public String linkTo(final EObject context, final Specification spec) { + String _xblockexpression = null; + { + String _xifexpression = null; + String _packageName = XtendTypes.packageName(spec); + boolean _equals = Objects.equal(_packageName, null); + if (_equals) { + _xifexpression = ""; + } else { + _xifexpression = XtendTypes.packageName(spec).replace(".", "/"); + } + final String path = _xifexpression; + String _root = this.root(context); + String _plus = (_root + path); + String _plus_1 = (_plus + "/"); + String _htmlFileName = this.htmlFileName(this._suiteClassNameProvider.toJavaClassName(spec)); + _xblockexpression = (_plus_1 + _htmlFileName); + } + return _xblockexpression; + } + + public String text(final Reference ref) { + boolean _matched = false; + if (ref instanceof SpecReference) { + String _text = ((SpecReference)ref).getText(); + String _trim = null; + if (_text!=null) { + _trim=_text.trim(); + } + boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(_trim); + boolean _not = (!_isNullOrEmpty); + if (_not) { + _matched=true; + String result = this.markdown2Html(((SpecReference)ref).getText()); + int _length = result.length(); + int _minus = (_length - 4); + result = result.substring(3, _minus); + return (": " + result); + } + } + return ""; + } +} diff --git a/plugins/org.jnario.suite/xtend-gen/org/jnario/suite/formatting2/SuiteFormatter.java b/plugins/org.jnario.suite/xtend-gen/org/jnario/suite/formatting2/SuiteFormatter.java index 2983cc711..78fc27ec1 100644 --- a/plugins/org.jnario.suite/xtend-gen/org/jnario/suite/formatting2/SuiteFormatter.java +++ b/plugins/org.jnario.suite/xtend-gen/org/jnario/suite/formatting2/SuiteFormatter.java @@ -1,206 +1,205 @@ -/** - * generated by Xtext - */ -package org.jnario.suite.formatting2; - -import com.google.inject.Inject; -import java.util.Arrays; -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.xtext.common.types.JvmFormalParameter; -import org.eclipse.xtext.common.types.JvmGenericArrayTypeReference; -import org.eclipse.xtext.common.types.JvmParameterizedTypeReference; -import org.eclipse.xtext.common.types.JvmTypeConstraint; -import org.eclipse.xtext.common.types.JvmTypeParameter; -import org.eclipse.xtext.common.types.JvmWildcardTypeReference; -import org.eclipse.xtext.formatting2.IFormattableDocument; -import org.eclipse.xtext.resource.XtextResource; -import org.eclipse.xtext.xbase.XAssignment; -import org.eclipse.xtext.xbase.XBasicForLoopExpression; -import org.eclipse.xtext.xbase.XBinaryOperation; -import org.eclipse.xtext.xbase.XBlockExpression; -import org.eclipse.xtext.xbase.XCastedExpression; -import org.eclipse.xtext.xbase.XClosure; -import org.eclipse.xtext.xbase.XCollectionLiteral; -import org.eclipse.xtext.xbase.XConstructorCall; -import org.eclipse.xtext.xbase.XDoWhileExpression; -import org.eclipse.xtext.xbase.XExpression; -import org.eclipse.xtext.xbase.XFeatureCall; -import org.eclipse.xtext.xbase.XForLoopExpression; -import org.eclipse.xtext.xbase.XIfExpression; -import org.eclipse.xtext.xbase.XInstanceOfExpression; -import org.eclipse.xtext.xbase.XMemberFeatureCall; -import org.eclipse.xtext.xbase.XPostfixOperation; -import org.eclipse.xtext.xbase.XReturnExpression; -import org.eclipse.xtext.xbase.XSwitchExpression; -import org.eclipse.xtext.xbase.XSynchronizedExpression; -import org.eclipse.xtext.xbase.XThrowExpression; -import org.eclipse.xtext.xbase.XTryCatchFinallyExpression; -import org.eclipse.xtext.xbase.XTypeLiteral; -import org.eclipse.xtext.xbase.XVariableDeclaration; -import org.eclipse.xtext.xbase.XWhileExpression; -import org.eclipse.xtext.xbase.annotations.formatting2.XbaseWithAnnotationsFormatter; -import org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation; -import org.eclipse.xtext.xbase.lib.Extension; -import org.eclipse.xtext.xtype.XFunctionTypeRef; -import org.eclipse.xtext.xtype.XImportDeclaration; -import org.eclipse.xtext.xtype.XImportSection; -import org.jnario.JnarioTypeDeclaration; -import org.jnario.suite.services.SuiteGrammarAccess; -import org.jnario.suite.suite.Reference; -import org.jnario.suite.suite.Suite; -import org.jnario.suite.suite.SuiteFile; - -@SuppressWarnings("all") -public class SuiteFormatter extends XbaseWithAnnotationsFormatter { - @Inject - @Extension - private SuiteGrammarAccess _suiteGrammarAccess; - - protected void _format(final SuiteFile suitefile, @Extension final IFormattableDocument document) { - XImportSection _importSection = suitefile.getImportSection(); - this.format(_importSection, document); - EList _xtendTypes = suitefile.getXtendTypes(); - for (final JnarioTypeDeclaration xtendTypes : _xtendTypes) { - this.format(xtendTypes, document); - } - } - - protected void _format(final Suite suite, @Extension final IFormattableDocument document) { - EList _annotations = suite.getAnnotations(); - for (final XAnnotation annotations : _annotations) { - this.format(annotations, document); - } - EList _elements = suite.getElements(); - for (final Reference elements : _elements) { - this.format(elements, document); - } - } - - public void format(final Object suite, final IFormattableDocument document) { - if (suite instanceof Suite) { - _format((Suite)suite, document); - return; - } else if (suite instanceof JvmTypeParameter) { - _format((JvmTypeParameter)suite, document); - return; - } else if (suite instanceof JvmFormalParameter) { - _format((JvmFormalParameter)suite, document); - return; - } else if (suite instanceof XtextResource) { - _format((XtextResource)suite, document); - return; - } else if (suite instanceof XAssignment) { - _format((XAssignment)suite, document); - return; - } else if (suite instanceof XBinaryOperation) { - _format((XBinaryOperation)suite, document); - return; - } else if (suite instanceof XDoWhileExpression) { - _format((XDoWhileExpression)suite, document); - return; - } else if (suite instanceof XFeatureCall) { - _format((XFeatureCall)suite, document); - return; - } else if (suite instanceof XMemberFeatureCall) { - _format((XMemberFeatureCall)suite, document); - return; - } else if (suite instanceof XPostfixOperation) { - _format((XPostfixOperation)suite, document); - return; - } else if (suite instanceof XWhileExpression) { - _format((XWhileExpression)suite, document); - return; - } else if (suite instanceof XFunctionTypeRef) { - _format((XFunctionTypeRef)suite, document); - return; - } else if (suite instanceof JvmGenericArrayTypeReference) { - _format((JvmGenericArrayTypeReference)suite, document); - return; - } else if (suite instanceof JvmParameterizedTypeReference) { - _format((JvmParameterizedTypeReference)suite, document); - return; - } else if (suite instanceof JvmWildcardTypeReference) { - _format((JvmWildcardTypeReference)suite, document); - return; - } else if (suite instanceof XBasicForLoopExpression) { - _format((XBasicForLoopExpression)suite, document); - return; - } else if (suite instanceof XBlockExpression) { - _format((XBlockExpression)suite, document); - return; - } else if (suite instanceof XCastedExpression) { - _format((XCastedExpression)suite, document); - return; - } else if (suite instanceof XClosure) { - _format((XClosure)suite, document); - return; - } else if (suite instanceof XCollectionLiteral) { - _format((XCollectionLiteral)suite, document); - return; - } else if (suite instanceof XConstructorCall) { - _format((XConstructorCall)suite, document); - return; - } else if (suite instanceof XForLoopExpression) { - _format((XForLoopExpression)suite, document); - return; - } else if (suite instanceof XIfExpression) { - _format((XIfExpression)suite, document); - return; - } else if (suite instanceof XInstanceOfExpression) { - _format((XInstanceOfExpression)suite, document); - return; - } else if (suite instanceof XReturnExpression) { - _format((XReturnExpression)suite, document); - return; - } else if (suite instanceof XSwitchExpression) { - _format((XSwitchExpression)suite, document); - return; - } else if (suite instanceof XSynchronizedExpression) { - _format((XSynchronizedExpression)suite, document); - return; - } else if (suite instanceof XThrowExpression) { - _format((XThrowExpression)suite, document); - return; - } else if (suite instanceof XTryCatchFinallyExpression) { - _format((XTryCatchFinallyExpression)suite, document); - return; - } else if (suite instanceof XTypeLiteral) { - _format((XTypeLiteral)suite, document); - return; - } else if (suite instanceof XVariableDeclaration) { - _format((XVariableDeclaration)suite, document); - return; - } else if (suite instanceof XAnnotation) { - _format((XAnnotation)suite, document); - return; - } else if (suite instanceof SuiteFile) { - _format((SuiteFile)suite, document); - return; - } else if (suite instanceof JvmTypeConstraint) { - _format((JvmTypeConstraint)suite, document); - return; - } else if (suite instanceof XExpression) { - _format((XExpression)suite, document); - return; - } else if (suite instanceof XImportDeclaration) { - _format((XImportDeclaration)suite, document); - return; - } else if (suite instanceof XImportSection) { - _format((XImportSection)suite, document); - return; - } else if (suite instanceof EObject) { - _format((EObject)suite, document); - return; - } else if (suite == null) { - _format((Void)null, document); - return; - } else if (suite != null) { - _format(suite, document); - return; - } else { - throw new IllegalArgumentException("Unhandled parameter types: " + - Arrays.asList(suite, document).toString()); - } - } -} +/** + * generated by Xtext + */ +package org.jnario.suite.formatting2; + +import com.google.inject.Inject; +import java.util.Arrays; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.xtext.common.types.JvmFormalParameter; +import org.eclipse.xtext.common.types.JvmGenericArrayTypeReference; +import org.eclipse.xtext.common.types.JvmParameterizedTypeReference; +import org.eclipse.xtext.common.types.JvmTypeConstraint; +import org.eclipse.xtext.common.types.JvmTypeParameter; +import org.eclipse.xtext.common.types.JvmWildcardTypeReference; +import org.eclipse.xtext.formatting2.IFormattableDocument; +import org.eclipse.xtext.resource.XtextResource; +import org.eclipse.xtext.xbase.XAssignment; +import org.eclipse.xtext.xbase.XBasicForLoopExpression; +import org.eclipse.xtext.xbase.XBinaryOperation; +import org.eclipse.xtext.xbase.XBlockExpression; +import org.eclipse.xtext.xbase.XCastedExpression; +import org.eclipse.xtext.xbase.XClosure; +import org.eclipse.xtext.xbase.XCollectionLiteral; +import org.eclipse.xtext.xbase.XConstructorCall; +import org.eclipse.xtext.xbase.XDoWhileExpression; +import org.eclipse.xtext.xbase.XExpression; +import org.eclipse.xtext.xbase.XFeatureCall; +import org.eclipse.xtext.xbase.XForLoopExpression; +import org.eclipse.xtext.xbase.XIfExpression; +import org.eclipse.xtext.xbase.XInstanceOfExpression; +import org.eclipse.xtext.xbase.XMemberFeatureCall; +import org.eclipse.xtext.xbase.XPostfixOperation; +import org.eclipse.xtext.xbase.XReturnExpression; +import org.eclipse.xtext.xbase.XSwitchExpression; +import org.eclipse.xtext.xbase.XSynchronizedExpression; +import org.eclipse.xtext.xbase.XThrowExpression; +import org.eclipse.xtext.xbase.XTryCatchFinallyExpression; +import org.eclipse.xtext.xbase.XTypeLiteral; +import org.eclipse.xtext.xbase.XVariableDeclaration; +import org.eclipse.xtext.xbase.XWhileExpression; +import org.eclipse.xtext.xbase.annotations.formatting2.XbaseWithAnnotationsFormatter; +import org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation; +import org.eclipse.xtext.xbase.lib.Extension; +import org.eclipse.xtext.xtype.XFunctionTypeRef; +import org.eclipse.xtext.xtype.XImportDeclaration; +import org.eclipse.xtext.xtype.XImportSection; +import org.jnario.JnarioTypeDeclaration; +import org.jnario.suite.services.SuiteGrammarAccess; +import org.jnario.suite.suite.Reference; +import org.jnario.suite.suite.Suite; +import org.jnario.suite.suite.SuiteFile; + +@SuppressWarnings("all") +public class SuiteFormatter extends XbaseWithAnnotationsFormatter { + @Inject + @Extension + private SuiteGrammarAccess _suiteGrammarAccess; + + protected void _format(final SuiteFile suitefile, @Extension final IFormattableDocument document) { + this.format(suitefile.getImportSection(), document); + EList _xtendTypes = suitefile.getXtendTypes(); + for (final JnarioTypeDeclaration xtendTypes : _xtendTypes) { + this.format(xtendTypes, document); + } + } + + protected void _format(final Suite suite, @Extension final IFormattableDocument document) { + EList _annotations = suite.getAnnotations(); + for (final XAnnotation annotations : _annotations) { + this.format(annotations, document); + } + EList _elements = suite.getElements(); + for (final Reference elements : _elements) { + this.format(elements, document); + } + } + + public void format(final Object suite, final IFormattableDocument document) { + if (suite instanceof Suite) { + _format((Suite)suite, document); + return; + } else if (suite instanceof JvmTypeParameter) { + _format((JvmTypeParameter)suite, document); + return; + } else if (suite instanceof JvmFormalParameter) { + _format((JvmFormalParameter)suite, document); + return; + } else if (suite instanceof XtextResource) { + _format((XtextResource)suite, document); + return; + } else if (suite instanceof XAssignment) { + _format((XAssignment)suite, document); + return; + } else if (suite instanceof XBinaryOperation) { + _format((XBinaryOperation)suite, document); + return; + } else if (suite instanceof XDoWhileExpression) { + _format((XDoWhileExpression)suite, document); + return; + } else if (suite instanceof XFeatureCall) { + _format((XFeatureCall)suite, document); + return; + } else if (suite instanceof XMemberFeatureCall) { + _format((XMemberFeatureCall)suite, document); + return; + } else if (suite instanceof XPostfixOperation) { + _format((XPostfixOperation)suite, document); + return; + } else if (suite instanceof XWhileExpression) { + _format((XWhileExpression)suite, document); + return; + } else if (suite instanceof XFunctionTypeRef) { + _format((XFunctionTypeRef)suite, document); + return; + } else if (suite instanceof JvmGenericArrayTypeReference) { + _format((JvmGenericArrayTypeReference)suite, document); + return; + } else if (suite instanceof JvmParameterizedTypeReference) { + _format((JvmParameterizedTypeReference)suite, document); + return; + } else if (suite instanceof JvmWildcardTypeReference) { + _format((JvmWildcardTypeReference)suite, document); + return; + } else if (suite instanceof XBasicForLoopExpression) { + _format((XBasicForLoopExpression)suite, document); + return; + } else if (suite instanceof XBlockExpression) { + _format((XBlockExpression)suite, document); + return; + } else if (suite instanceof XCastedExpression) { + _format((XCastedExpression)suite, document); + return; + } else if (suite instanceof XClosure) { + _format((XClosure)suite, document); + return; + } else if (suite instanceof XCollectionLiteral) { + _format((XCollectionLiteral)suite, document); + return; + } else if (suite instanceof XConstructorCall) { + _format((XConstructorCall)suite, document); + return; + } else if (suite instanceof XForLoopExpression) { + _format((XForLoopExpression)suite, document); + return; + } else if (suite instanceof XIfExpression) { + _format((XIfExpression)suite, document); + return; + } else if (suite instanceof XInstanceOfExpression) { + _format((XInstanceOfExpression)suite, document); + return; + } else if (suite instanceof XReturnExpression) { + _format((XReturnExpression)suite, document); + return; + } else if (suite instanceof XSwitchExpression) { + _format((XSwitchExpression)suite, document); + return; + } else if (suite instanceof XSynchronizedExpression) { + _format((XSynchronizedExpression)suite, document); + return; + } else if (suite instanceof XThrowExpression) { + _format((XThrowExpression)suite, document); + return; + } else if (suite instanceof XTryCatchFinallyExpression) { + _format((XTryCatchFinallyExpression)suite, document); + return; + } else if (suite instanceof XTypeLiteral) { + _format((XTypeLiteral)suite, document); + return; + } else if (suite instanceof XVariableDeclaration) { + _format((XVariableDeclaration)suite, document); + return; + } else if (suite instanceof XAnnotation) { + _format((XAnnotation)suite, document); + return; + } else if (suite instanceof SuiteFile) { + _format((SuiteFile)suite, document); + return; + } else if (suite instanceof JvmTypeConstraint) { + _format((JvmTypeConstraint)suite, document); + return; + } else if (suite instanceof XExpression) { + _format((XExpression)suite, document); + return; + } else if (suite instanceof XImportDeclaration) { + _format((XImportDeclaration)suite, document); + return; + } else if (suite instanceof XImportSection) { + _format((XImportSection)suite, document); + return; + } else if (suite instanceof EObject) { + _format((EObject)suite, document); + return; + } else if (suite == null) { + _format((Void)null, document); + return; + } else if (suite != null) { + _format(suite, document); + return; + } else { + throw new IllegalArgumentException("Unhandled parameter types: " + + Arrays.asList(suite, document).toString()); + } + } +} diff --git a/plugins/org.jnario.suite/xtend-gen/org/jnario/suite/generator/SuiteGenerator.java b/plugins/org.jnario.suite/xtend-gen/org/jnario/suite/generator/SuiteGenerator.java index 52d23347a..044f8e939 100644 --- a/plugins/org.jnario.suite/xtend-gen/org/jnario/suite/generator/SuiteGenerator.java +++ b/plugins/org.jnario.suite/xtend-gen/org/jnario/suite/generator/SuiteGenerator.java @@ -1,26 +1,26 @@ -/** - * generated by Xtext - */ -package org.jnario.suite.generator; - -import com.google.inject.Inject; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.xtext.generator.IFileSystemAccess; -import org.eclipse.xtext.generator.IGenerator; -import org.eclipse.xtext.xbase.compiler.JvmModelGenerator; -import org.jnario.suite.doc.SuiteDocGenerator; - -@SuppressWarnings("all") -public class SuiteGenerator implements IGenerator { - @Inject - private JvmModelGenerator jvmModelGenerator; - - @Inject - private SuiteDocGenerator docGenerator; - - @Override - public void doGenerate(final Resource input, final IFileSystemAccess fsa) { - this.jvmModelGenerator.doGenerate(input, fsa); - this.docGenerator.doGenerate(input, fsa); - } -} +/** + * generated by Xtext + */ +package org.jnario.suite.generator; + +import com.google.inject.Inject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.xtext.generator.IFileSystemAccess; +import org.eclipse.xtext.generator.IGenerator; +import org.eclipse.xtext.xbase.compiler.JvmModelGenerator; +import org.jnario.suite.doc.SuiteDocGenerator; + +@SuppressWarnings("all") +public class SuiteGenerator implements IGenerator { + @Inject + private JvmModelGenerator jvmModelGenerator; + + @Inject + private SuiteDocGenerator docGenerator; + + @Override + public void doGenerate(final Resource input, final IFileSystemAccess fsa) { + this.jvmModelGenerator.doGenerate(input, fsa); + this.docGenerator.doGenerate(input, fsa); + } +} diff --git a/plugins/org.jnario.suite/xtend-gen/org/jnario/suite/jvmmodel/SpecResolver.java b/plugins/org.jnario.suite/xtend-gen/org/jnario/suite/jvmmodel/SpecResolver.java index fa60e04f9..e364d608c 100644 --- a/plugins/org.jnario.suite/xtend-gen/org/jnario/suite/jvmmodel/SpecResolver.java +++ b/plugins/org.jnario.suite/xtend-gen/org/jnario/suite/jvmmodel/SpecResolver.java @@ -1,179 +1,157 @@ -/** - * Copyright (c) 2012 BMW Car IT and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.jnario.suite.jvmmodel; - -import com.google.common.base.Objects; -import com.google.common.base.Strings; -import com.google.common.collect.Iterables; -import com.google.inject.Inject; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; -import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import org.eclipse.emf.common.notify.Notifier; -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.emf.ecore.util.EcoreUtil; -import org.eclipse.xtext.naming.IQualifiedNameConverter; -import org.eclipse.xtext.naming.QualifiedName; -import org.eclipse.xtext.resource.IEObjectDescription; -import org.eclipse.xtext.scoping.IScope; -import org.eclipse.xtext.scoping.IScopeProvider; -import org.eclipse.xtext.xbase.lib.Extension; -import org.eclipse.xtext.xbase.lib.Functions.Function1; -import org.eclipse.xtext.xbase.lib.IterableExtensions; -import org.eclipse.xtext.xbase.lib.ListExtensions; -import org.jnario.JnarioPackage; -import org.jnario.Specification; -import org.jnario.suite.jvmmodel.SuiteClassNameProvider; -import org.jnario.suite.suite.PatternReference; -import org.jnario.suite.suite.Reference; -import org.jnario.suite.suite.SpecReference; -import org.jnario.suite.suite.Suite; -import org.jnario.suite.suite.SuitePackage; - -@SuppressWarnings("all") -public class SpecResolver { - @Inject - @Extension - private IScopeProvider scopeProvider; - - @Inject - @Extension - private IQualifiedNameConverter _iQualifiedNameConverter; - - @Inject - @Extension - private SuiteClassNameProvider _suiteClassNameProvider; - - protected List _resolveSpecs(final Suite suite) { - EList _elements = suite.getElements(); - final Function1> _function = new Function1>() { - @Override - public List apply(final Reference it) { - return SpecResolver.this.resolveSpecs(it); - } - }; - List> _map = ListExtensions.>map(_elements, _function); - Iterable _flatten = Iterables.concat(_map); - return this.sort(_flatten); - } - - protected List _resolveSpecs(final SpecReference specRef) { - Specification _spec = specRef.getSpec(); - return Collections.singletonList(_spec); - } - - protected List _resolveSpecs(final PatternReference specRef) { - List _xblockexpression = null; - { - String _pattern = specRef.getPattern(); - boolean _isNullOrEmpty = Strings.isNullOrEmpty(_pattern); - if (_isNullOrEmpty) { - return Collections.emptyList(); - } - final IScope scope = this.scopeProvider.getScope(specRef, SuitePackage.Literals.SPEC_REFERENCE__SPEC); - Iterable _allElements = scope.getAllElements(); - final Function1 _function = new Function1() { - @Override - public Boolean apply(final IEObjectDescription it) { - EClass _eClass = it.getEClass(); - return Boolean.valueOf(JnarioPackage.Literals.SPECIFICATION.isSuperTypeOf(_eClass)); - } - }; - Iterable specs = IterableExtensions.filter(_allElements, _function); - String _pattern_1 = specRef.getPattern(); - final Pattern pattern = Pattern.compile(_pattern_1); - final Function1 _function_1 = new Function1() { - @Override - public Boolean apply(final IEObjectDescription it) { - QualifiedName _qualifiedName = it.getQualifiedName(); - String _string = SpecResolver.this._iQualifiedNameConverter.toString(_qualifiedName); - Matcher _matcher = pattern.matcher(_string); - return Boolean.valueOf(_matcher.matches()); - } - }; - Iterable _filter = IterableExtensions.filter(specs, _function_1); - specs = _filter; - final Resource suiteResource = specRef.eResource(); - final Function1 _function_2 = new Function1() { - @Override - public EObject apply(final IEObjectDescription it) { - EObject _eObjectOrProxy = it.getEObjectOrProxy(); - return EcoreUtil.resolve(_eObjectOrProxy, specRef); - } - }; - Iterable _map = IterableExtensions.map(specs, _function_2); - Iterable _filter_1 = Iterables.filter(_map, Specification.class); - final Iterable resolvedSpecs = IterableExtensions.filterNull(_filter_1); - final Function1 _function_3 = new Function1() { - @Override - public Boolean apply(final Specification it) { - Resource _eResource = it.eResource(); - return Boolean.valueOf((!Objects.equal(_eResource, suiteResource))); - } - }; - final Iterable withoutSuites = IterableExtensions.filter(resolvedSpecs, _function_3); - final Function1 _function_4 = new Function1() { - @Override - public String apply(final Specification it) { - return SpecResolver.this._suiteClassNameProvider.toQualifiedJavaClassName(it); - } - }; - final Map classNames = IterableExtensions.toMap(withoutSuites, _function_4); - Collection _values = classNames.values(); - _xblockexpression = this.sort(_values); - } - return _xblockexpression; - } - - private List sort(final Iterable specs) { - final Function1 _function = new Function1() { - @Override - public Boolean apply(final Specification it) { - return Boolean.valueOf((!Objects.equal(it, null))); - } - }; - Iterable _filter = IterableExtensions.filter(specs, _function); - final Comparator _function_1 = new Comparator() { - @Override - public int compare(final Specification left, final Specification right) { - int _xblockexpression = (int) 0; - { - final String leftName = SpecResolver.this._suiteClassNameProvider.describe(left); - final String rightName = SpecResolver.this._suiteClassNameProvider.describe(right); - if ((Objects.equal(leftName, null) || Objects.equal(rightName, null))) { - return 0; - } - _xblockexpression = leftName.compareToIgnoreCase(rightName); - } - return _xblockexpression; - } - }; - return IterableExtensions.sortWith(_filter, _function_1); - } - - public List resolveSpecs(final Notifier suite) { - if (suite instanceof Suite) { - return _resolveSpecs((Suite)suite); - } else if (suite instanceof PatternReference) { - return _resolveSpecs((PatternReference)suite); - } else if (suite instanceof SpecReference) { - return _resolveSpecs((SpecReference)suite); - } else { - throw new IllegalArgumentException("Unhandled parameter types: " + - Arrays.asList(suite).toString()); - } - } -} +/** + * Copyright (c) 2012 BMW Car IT and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.jnario.suite.jvmmodel; + +import com.google.common.base.Objects; +import com.google.common.base.Strings; +import com.google.common.collect.Iterables; +import com.google.inject.Inject; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import java.util.Map; +import java.util.regex.Pattern; +import org.eclipse.emf.common.notify.Notifier; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.util.EcoreUtil; +import org.eclipse.xtext.naming.IQualifiedNameConverter; +import org.eclipse.xtext.resource.IEObjectDescription; +import org.eclipse.xtext.scoping.IScope; +import org.eclipse.xtext.scoping.IScopeProvider; +import org.eclipse.xtext.xbase.lib.Extension; +import org.eclipse.xtext.xbase.lib.Functions.Function1; +import org.eclipse.xtext.xbase.lib.IterableExtensions; +import org.eclipse.xtext.xbase.lib.ListExtensions; +import org.jnario.JnarioPackage; +import org.jnario.Specification; +import org.jnario.suite.jvmmodel.SuiteClassNameProvider; +import org.jnario.suite.suite.PatternReference; +import org.jnario.suite.suite.Reference; +import org.jnario.suite.suite.SpecReference; +import org.jnario.suite.suite.Suite; +import org.jnario.suite.suite.SuitePackage; + +@SuppressWarnings("all") +public class SpecResolver { + @Inject + @Extension + private IScopeProvider scopeProvider; + + @Inject + @Extension + private IQualifiedNameConverter _iQualifiedNameConverter; + + @Inject + @Extension + private SuiteClassNameProvider _suiteClassNameProvider; + + protected List _resolveSpecs(final Suite suite) { + final Function1> _function = new Function1>() { + @Override + public List apply(final Reference it) { + return SpecResolver.this.resolveSpecs(it); + } + }; + return this.sort(Iterables.concat(ListExtensions.>map(suite.getElements(), _function))); + } + + protected List _resolveSpecs(final SpecReference specRef) { + return Collections.singletonList(specRef.getSpec()); + } + + protected List _resolveSpecs(final PatternReference specRef) { + List _xblockexpression = null; + { + boolean _isNullOrEmpty = Strings.isNullOrEmpty(specRef.getPattern()); + if (_isNullOrEmpty) { + return Collections.emptyList(); + } + final IScope scope = this.scopeProvider.getScope(specRef, SuitePackage.Literals.SPEC_REFERENCE__SPEC); + final Function1 _function = new Function1() { + @Override + public Boolean apply(final IEObjectDescription it) { + return Boolean.valueOf(JnarioPackage.Literals.SPECIFICATION.isSuperTypeOf(it.getEClass())); + } + }; + Iterable specs = IterableExtensions.filter(scope.getAllElements(), _function); + final Pattern pattern = Pattern.compile(specRef.getPattern()); + final Function1 _function_1 = new Function1() { + @Override + public Boolean apply(final IEObjectDescription it) { + return Boolean.valueOf(pattern.matcher(SpecResolver.this._iQualifiedNameConverter.toString(it.getQualifiedName())).matches()); + } + }; + specs = IterableExtensions.filter(specs, _function_1); + final Resource suiteResource = specRef.eResource(); + final Function1 _function_2 = new Function1() { + @Override + public EObject apply(final IEObjectDescription it) { + return EcoreUtil.resolve(it.getEObjectOrProxy(), specRef); + } + }; + final Iterable resolvedSpecs = IterableExtensions.filterNull(Iterables.filter(IterableExtensions.map(specs, _function_2), Specification.class)); + final Function1 _function_3 = new Function1() { + @Override + public Boolean apply(final Specification it) { + Resource _eResource = it.eResource(); + return Boolean.valueOf((!Objects.equal(_eResource, suiteResource))); + } + }; + final Iterable withoutSuites = IterableExtensions.filter(resolvedSpecs, _function_3); + final Function1 _function_4 = new Function1() { + @Override + public String apply(final Specification it) { + return SpecResolver.this._suiteClassNameProvider.toQualifiedJavaClassName(it); + } + }; + final Map classNames = IterableExtensions.toMap(withoutSuites, _function_4); + _xblockexpression = this.sort(classNames.values()); + } + return _xblockexpression; + } + + private List sort(final Iterable specs) { + final Function1 _function = new Function1() { + @Override + public Boolean apply(final Specification it) { + return Boolean.valueOf((!Objects.equal(it, null))); + } + }; + final Comparator _function_1 = new Comparator() { + @Override + public int compare(final Specification left, final Specification right) { + int _xblockexpression = (int) 0; + { + final String leftName = SpecResolver.this._suiteClassNameProvider.describe(left); + final String rightName = SpecResolver.this._suiteClassNameProvider.describe(right); + if ((Objects.equal(leftName, null) || Objects.equal(rightName, null))) { + return 0; + } + _xblockexpression = leftName.compareToIgnoreCase(rightName); + } + return _xblockexpression; + } + }; + return IterableExtensions.sortWith(IterableExtensions.filter(specs, _function), _function_1); + } + + public List resolveSpecs(final Notifier suite) { + if (suite instanceof Suite) { + return _resolveSpecs((Suite)suite); + } else if (suite instanceof PatternReference) { + return _resolveSpecs((PatternReference)suite); + } else if (suite instanceof SpecReference) { + return _resolveSpecs((SpecReference)suite); + } else { + throw new IllegalArgumentException("Unhandled parameter types: " + + Arrays.asList(suite).toString()); + } + } +} diff --git a/plugins/org.jnario.suite/xtend-gen/org/jnario/suite/jvmmodel/SuiteClassNameProvider.java b/plugins/org.jnario.suite/xtend-gen/org/jnario/suite/jvmmodel/SuiteClassNameProvider.java index ffb5ab6d1..3f0fa2819 100644 --- a/plugins/org.jnario.suite/xtend-gen/org/jnario/suite/jvmmodel/SuiteClassNameProvider.java +++ b/plugins/org.jnario.suite/xtend-gen/org/jnario/suite/jvmmodel/SuiteClassNameProvider.java @@ -1,159 +1,159 @@ -/** - * Copyright (c) 2012 BMW Car IT and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.jnario.suite.jvmmodel; - -import com.google.common.base.Objects; -import com.google.inject.Inject; -import com.google.inject.Singleton; -import java.util.Arrays; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.xtext.resource.IResourceServiceProvider; -import org.eclipse.xtext.resource.XtextResource; -import org.jnario.feature.naming.FeatureClassNameProvider; -import org.jnario.jvmmodel.JnarioNameProvider; -import org.jnario.spec.naming.ExampleNameProvider; -import org.jnario.suite.suite.Suite; -import org.jnario.util.Strings; - -@Singleton -@SuppressWarnings("all") -public class SuiteClassNameProvider extends JnarioNameProvider { - private ExampleNameProvider exampleNameProvider; - - private FeatureClassNameProvider featureNameProvider; - - @Inject - SuiteClassNameProvider(final ExampleNameProvider exampleNameProvider, final FeatureClassNameProvider featureNameProvider) { - this.exampleNameProvider = exampleNameProvider; - this.featureNameProvider = featureNameProvider; - } - - private final static String POSTFIX = "Suite"; - - protected String removePrefix(final Suite suite) { - String _xblockexpression = null; - { - String name = Strings.firstLine(suite.getName()); - boolean _isNullOrEmpty = com.google.common.base.Strings.isNullOrEmpty(name); - if (_isNullOrEmpty) { - return null; - } - int _lastIndexOf = name.lastIndexOf("#"); - int _plus = (_lastIndexOf + 1); - name = name.substring(_plus).trim(); - String _xifexpression = null; - boolean _isNullOrEmpty_1 = com.google.common.base.Strings.isNullOrEmpty(name); - if (_isNullOrEmpty_1) { - return null; - } else { - _xifexpression = name; - } - _xblockexpression = _xifexpression; - } - return _xblockexpression; - } - - protected String _internalGetClassName(final Suite suite) { - String _xblockexpression = null; - { - final String name = this.removePrefix(suite); - boolean _equals = Objects.equal(name, null); - if (_equals) { - return null; - } - String _className = Strings.toClassName(name); - _xblockexpression = (_className + SuiteClassNameProvider.POSTFIX); - } - return _xblockexpression; - } - - protected String _internalGetClassName(final EObject element) { - JnarioNameProvider _classNameProvider = this.classNameProvider(element); - String _javaClassName = null; - if (_classNameProvider!=null) { - _javaClassName=_classNameProvider.toJavaClassName(element); - } - return _javaClassName; - } - - @Override - protected String internalDescribe(final EObject eObject) { - return this.doDescribe(eObject); - } - - protected String _doDescribe(final Suite suite) { - String _removePrefix = this.removePrefix(suite); - String _convertToJavaString = null; - if (_removePrefix!=null) { - _convertToJavaString=org.eclipse.xtext.util.Strings.convertToJavaString(_removePrefix, true); - } - return _convertToJavaString; - } - - protected String _doDescribe(final EObject element) { - JnarioNameProvider _classNameProvider = this.classNameProvider(element); - String _describe = null; - if (_classNameProvider!=null) { - _describe=_classNameProvider.describe(element); - } - return _describe; - } - - private JnarioNameProvider classNameProvider(final EObject element) { - JnarioNameProvider _xblockexpression = null; - { - Resource _eResource = element.eResource(); - final XtextResource resource = ((XtextResource) _eResource); - boolean _equals = Objects.equal(resource, null); - if (_equals) { - return null; - } - final IResourceServiceProvider resourceServiceProvider = resource.getResourceServiceProvider(); - _xblockexpression = resourceServiceProvider.get(JnarioNameProvider.class); - } - return _xblockexpression; - } - - @Override - protected String internalToJavaClassName(final EObject eObject) { - return this.internalGetClassName(eObject); - } - - @Override - protected String internalToFieldName(final EObject eObject) { - throw new UnsupportedOperationException("Auto-generated function stub"); - } - - @Override - protected String internalToMethodName(final EObject eObject) { - throw new UnsupportedOperationException("Auto-generated function stub"); - } - - protected String internalGetClassName(final EObject suite) { - if (suite instanceof Suite) { - return _internalGetClassName((Suite)suite); - } else if (suite != null) { - return _internalGetClassName(suite); - } else { - throw new IllegalArgumentException("Unhandled parameter types: " + - Arrays.asList(suite).toString()); - } - } - - protected String doDescribe(final EObject suite) { - if (suite instanceof Suite) { - return _doDescribe((Suite)suite); - } else if (suite != null) { - return _doDescribe(suite); - } else { - throw new IllegalArgumentException("Unhandled parameter types: " + - Arrays.asList(suite).toString()); - } - } -} +/** + * Copyright (c) 2012 BMW Car IT and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.jnario.suite.jvmmodel; + +import com.google.common.base.Objects; +import com.google.inject.Inject; +import com.google.inject.Singleton; +import java.util.Arrays; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.xtext.resource.IResourceServiceProvider; +import org.eclipse.xtext.resource.XtextResource; +import org.jnario.feature.naming.FeatureClassNameProvider; +import org.jnario.jvmmodel.JnarioNameProvider; +import org.jnario.spec.naming.ExampleNameProvider; +import org.jnario.suite.suite.Suite; +import org.jnario.util.Strings; + +@Singleton +@SuppressWarnings("all") +public class SuiteClassNameProvider extends JnarioNameProvider { + private ExampleNameProvider exampleNameProvider; + + private FeatureClassNameProvider featureNameProvider; + + @Inject + SuiteClassNameProvider(final ExampleNameProvider exampleNameProvider, final FeatureClassNameProvider featureNameProvider) { + this.exampleNameProvider = exampleNameProvider; + this.featureNameProvider = featureNameProvider; + } + + private final static String POSTFIX = "Suite"; + + protected String removePrefix(final Suite suite) { + String _xblockexpression = null; + { + String name = Strings.firstLine(suite.getName()); + boolean _isNullOrEmpty = com.google.common.base.Strings.isNullOrEmpty(name); + if (_isNullOrEmpty) { + return null; + } + int _lastIndexOf = name.lastIndexOf("#"); + int _plus = (_lastIndexOf + 1); + name = name.substring(_plus).trim(); + String _xifexpression = null; + boolean _isNullOrEmpty_1 = com.google.common.base.Strings.isNullOrEmpty(name); + if (_isNullOrEmpty_1) { + return null; + } else { + _xifexpression = name; + } + _xblockexpression = _xifexpression; + } + return _xblockexpression; + } + + protected String _internalGetClassName(final Suite suite) { + String _xblockexpression = null; + { + final String name = this.removePrefix(suite); + boolean _equals = Objects.equal(name, null); + if (_equals) { + return null; + } + String _className = Strings.toClassName(name); + _xblockexpression = (_className + SuiteClassNameProvider.POSTFIX); + } + return _xblockexpression; + } + + protected String _internalGetClassName(final EObject element) { + JnarioNameProvider _classNameProvider = this.classNameProvider(element); + String _javaClassName = null; + if (_classNameProvider!=null) { + _javaClassName=_classNameProvider.toJavaClassName(element); + } + return _javaClassName; + } + + @Override + protected String internalDescribe(final EObject eObject) { + return this.doDescribe(eObject); + } + + protected String _doDescribe(final Suite suite) { + String _removePrefix = this.removePrefix(suite); + String _convertToJavaString = null; + if (_removePrefix!=null) { + _convertToJavaString=org.eclipse.xtext.util.Strings.convertToJavaString(_removePrefix, true); + } + return _convertToJavaString; + } + + protected String _doDescribe(final EObject element) { + JnarioNameProvider _classNameProvider = this.classNameProvider(element); + String _describe = null; + if (_classNameProvider!=null) { + _describe=_classNameProvider.describe(element); + } + return _describe; + } + + private JnarioNameProvider classNameProvider(final EObject element) { + JnarioNameProvider _xblockexpression = null; + { + Resource _eResource = element.eResource(); + final XtextResource resource = ((XtextResource) _eResource); + boolean _equals = Objects.equal(resource, null); + if (_equals) { + return null; + } + final IResourceServiceProvider resourceServiceProvider = resource.getResourceServiceProvider(); + _xblockexpression = resourceServiceProvider.get(JnarioNameProvider.class); + } + return _xblockexpression; + } + + @Override + protected String internalToJavaClassName(final EObject eObject) { + return this.internalGetClassName(eObject); + } + + @Override + protected String internalToFieldName(final EObject eObject) { + throw new UnsupportedOperationException("Auto-generated function stub"); + } + + @Override + protected String internalToMethodName(final EObject eObject) { + throw new UnsupportedOperationException("Auto-generated function stub"); + } + + protected String internalGetClassName(final EObject suite) { + if (suite instanceof Suite) { + return _internalGetClassName((Suite)suite); + } else if (suite != null) { + return _internalGetClassName(suite); + } else { + throw new IllegalArgumentException("Unhandled parameter types: " + + Arrays.asList(suite).toString()); + } + } + + protected String doDescribe(final EObject suite) { + if (suite instanceof Suite) { + return _doDescribe((Suite)suite); + } else if (suite != null) { + return _doDescribe(suite); + } else { + throw new IllegalArgumentException("Unhandled parameter types: " + + Arrays.asList(suite).toString()); + } + } +} diff --git a/plugins/org.jnario.suite/xtend-gen/org/jnario/suite/jvmmodel/SuiteJvmModelInferrer.java b/plugins/org.jnario.suite/xtend-gen/org/jnario/suite/jvmmodel/SuiteJvmModelInferrer.java index 4d0abf4bc..b841a906b 100644 --- a/plugins/org.jnario.suite/xtend-gen/org/jnario/suite/jvmmodel/SuiteJvmModelInferrer.java +++ b/plugins/org.jnario.suite/xtend-gen/org/jnario/suite/jvmmodel/SuiteJvmModelInferrer.java @@ -1,215 +1,200 @@ -/** - * Copyright (c) 2012 BMW Car IT and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.jnario.suite.jvmmodel; - -import com.google.common.base.Objects; -import com.google.common.collect.Iterables; -import com.google.inject.Inject; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; -import java.util.function.Consumer; -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.xtext.common.types.JvmAnnotationReference; -import org.eclipse.xtext.common.types.JvmGenericType; -import org.eclipse.xtext.common.types.JvmParameterizedTypeReference; -import org.eclipse.xtext.common.types.JvmTypeReference; -import org.eclipse.xtext.common.types.TypesFactory; -import org.eclipse.xtext.common.types.util.TypeReferences; -import org.eclipse.xtext.xbase.jvmmodel.IJvmDeclaredTypeAcceptor; -import org.eclipse.xtext.xbase.lib.CollectionLiterals; -import org.eclipse.xtext.xbase.lib.Extension; -import org.eclipse.xtext.xbase.lib.Functions.Function1; -import org.eclipse.xtext.xbase.lib.IterableExtensions; -import org.eclipse.xtext.xbase.lib.ListExtensions; -import org.eclipse.xtext.xbase.typing.IJvmTypeReferenceProvider; -import org.eclipse.xtext.xtype.XComputedTypeReference; -import org.eclipse.xtext.xtype.XtypeFactory; -import org.eclipse.xtext.xtype.impl.XComputedTypeReferenceImplCustom; -import org.jnario.JnarioFile; -import org.jnario.JnarioTypeDeclaration; -import org.jnario.Specification; -import org.jnario.jvmmodel.ExtendedJvmTypesBuilder; -import org.jnario.jvmmodel.JnarioJvmModelInferrer; -import org.jnario.jvmmodel.TestRuntimeSupport; -import org.jnario.runner.Named; -import org.jnario.suite.jvmmodel.SpecResolver; -import org.jnario.suite.jvmmodel.SuiteClassNameProvider; -import org.jnario.suite.jvmmodel.SuiteNode; -import org.jnario.suite.jvmmodel.SuiteNodeBuilder; -import org.jnario.suite.suite.Suite; -import org.jnario.suite.suite.SuiteFile; - -@SuppressWarnings("all") -public class SuiteJvmModelInferrer extends JnarioJvmModelInferrer { - @Inject - @Extension - private ExtendedJvmTypesBuilder _extendedJvmTypesBuilder; - - @Inject - @Extension - private SuiteClassNameProvider _suiteClassNameProvider; - - @Inject - @Extension - private SpecResolver _specResolver; - - @Inject - @Extension - private TypeReferences _typeReferences; - - @Inject - @Extension - private SuiteNodeBuilder _suiteNodeBuilder; - - @Inject - private TypesFactory typesFactory; - - @Inject(optional = true) - private XtypeFactory xtypesFactory = XtypeFactory.eINSTANCE; - - @Override - public void doInfer(final EObject e, final IJvmDeclaredTypeAcceptor acceptor, final boolean preIndexingPhase) { - if ((!(e instanceof SuiteFile))) { - return; - } - final SuiteFile suiteFile = ((SuiteFile) e); - EList _xtendTypes = suiteFile.getXtendTypes(); - Iterable _filter = Iterables.filter(_xtendTypes, Suite.class); - final List suites = IterableExtensions.toList(_filter); - final Consumer _function = new Consumer() { - @Override - public void accept(final Suite it) { - final JvmGenericType javaType = SuiteJvmModelInferrer.this.typesFactory.createJvmGenericType(); - JnarioFile _jnarioFile = SuiteJvmModelInferrer.this.jnarioFile(it); - SuiteJvmModelInferrer.this.setNameAndAssociate(_jnarioFile, it, javaType); - } - }; - suites.forEach(_function); - final Iterable nodes = this._suiteNodeBuilder.buildNodeModel(suiteFile); - final ArrayList doLater = CollectionLiterals.newArrayList(); - final Consumer _function_1 = new Consumer() { - @Override - public void accept(final SuiteNode it) { - SuiteJvmModelInferrer.this.infer(it, acceptor, doLater, preIndexingPhase); - } - }; - nodes.forEach(_function_1); - if (preIndexingPhase) { - return; - } - final Consumer _function_2 = new Consumer() { - @Override - public void accept(final Runnable it) { - it.run(); - } - }; - doLater.forEach(_function_2); - } - - public JvmGenericType infer(final SuiteNode node, final IJvmDeclaredTypeAcceptor acceptor, final List doLater, final boolean preIndexingPhase) { - JvmGenericType _xblockexpression = null; - { - final Suite suite = node.getSuite(); - String _qualifiedJavaClassName = this._suiteClassNameProvider.toQualifiedJavaClassName(suite); - final JvmGenericType suiteClass = this._extendedJvmTypesBuilder.toClass(suite, _qualifiedJavaClassName); - boolean _equals = Objects.equal(suiteClass, null); - if (_equals) { - return null; - } - acceptor.accept(suiteClass); - List _children = node.getChildren(); - final Function1 _function = new Function1() { - @Override - public JvmGenericType apply(final SuiteNode it) { - return SuiteJvmModelInferrer.this.infer(it, acceptor, doLater, preIndexingPhase); - } - }; - List _map = ListExtensions.map(_children, _function); - Iterable _filterNull = IterableExtensions.filterNull(_map); - final Set subSuites = IterableExtensions.toSet(_filterNull); - if ((!preIndexingPhase)) { - final Function1 _function_1 = new Function1() { - @Override - public JvmTypeReference apply(final JvmGenericType it) { - JvmParameterizedTypeReference _createTypeRef = SuiteJvmModelInferrer.this._typeReferences.createTypeRef(it); - return ((JvmTypeReference) _createTypeRef); - } - }; - final Iterable subSuiteReferences = IterableExtensions.map(subSuites, _function_1); - final Runnable _function_2 = new Runnable() { - @Override - public void run() { - EList _annotations = suiteClass.getAnnotations(); - String _describe = SuiteJvmModelInferrer.this._suiteClassNameProvider.describe(suite); - JvmAnnotationReference _annotation = SuiteJvmModelInferrer.this._extendedJvmTypesBuilder.toAnnotation(suite, Named.class, _describe); - SuiteJvmModelInferrer.this._extendedJvmTypesBuilder.operator_add(_annotations, _annotation); - Iterable _children = SuiteJvmModelInferrer.this.children(suite); - final Iterable children = Iterables.concat(_children, subSuiteReferences); - boolean _isEmpty = IterableExtensions.isEmpty(children); - boolean _not = (!_isEmpty); - if (_not) { - TestRuntimeSupport _testRuntime = SuiteJvmModelInferrer.this.getTestRuntime(); - Set _set = IterableExtensions.toSet(children); - _testRuntime.addChildren(suite, suiteClass, _set); - } - SuiteJvmModelInferrer.this.initialize(suite, suiteClass); - TestRuntimeSupport _testRuntime_1 = SuiteJvmModelInferrer.this.getTestRuntime(); - _testRuntime_1.updateSuite(suite, suiteClass); - } - }; - doLater.add(_function_2); - } - _xblockexpression = suiteClass; - } - return _xblockexpression; - } - - public Iterable children(final Suite suite) { - Iterable _xblockexpression = null; - { - List _resolveSpecs = this._specResolver.resolveSpecs(suite); - final Function1 _function = new Function1() { - @Override - public Boolean apply(final Specification it) { - String _javaClassName = SuiteJvmModelInferrer.this._suiteClassNameProvider.toJavaClassName(it); - return Boolean.valueOf((!Objects.equal(_javaClassName, null))); - } - }; - final Iterable specs = IterableExtensions.filter(_resolveSpecs, _function); - final Function1 _function_1 = new Function1() { - @Override - public String apply(final Specification it) { - return SuiteJvmModelInferrer.this._suiteClassNameProvider.toQualifiedJavaClassName(it); - } - }; - final Iterable types = IterableExtensions.map(specs, _function_1); - final Function1 _function_2 = new Function1() { - @Override - public JvmTypeReference apply(final String it) { - return SuiteJvmModelInferrer.this.inferredType(it, suite); - } - }; - _xblockexpression = IterableExtensions.map(types, _function_2); - } - return _xblockexpression; - } - - public JvmTypeReference inferredType(final String name, final EObject context) { - final XComputedTypeReference result = this.xtypesFactory.createXComputedTypeReference(); - final IJvmTypeReferenceProvider _function = new IJvmTypeReferenceProvider() { - @Override - public JvmTypeReference getTypeReference(final XComputedTypeReferenceImplCustom it) { - return SuiteJvmModelInferrer.this._typeReferences.getTypeForName(name, context); - } - }; - result.setTypeProvider(_function); - return result; - } -} +/** + * Copyright (c) 2012 BMW Car IT and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.jnario.suite.jvmmodel; + +import com.google.common.base.Objects; +import com.google.common.collect.Iterables; +import com.google.inject.Inject; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; +import java.util.function.Consumer; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.xtext.common.types.JvmAnnotationReference; +import org.eclipse.xtext.common.types.JvmGenericType; +import org.eclipse.xtext.common.types.JvmParameterizedTypeReference; +import org.eclipse.xtext.common.types.JvmTypeReference; +import org.eclipse.xtext.common.types.TypesFactory; +import org.eclipse.xtext.common.types.util.TypeReferences; +import org.eclipse.xtext.xbase.jvmmodel.IJvmDeclaredTypeAcceptor; +import org.eclipse.xtext.xbase.lib.CollectionLiterals; +import org.eclipse.xtext.xbase.lib.Extension; +import org.eclipse.xtext.xbase.lib.Functions.Function1; +import org.eclipse.xtext.xbase.lib.IterableExtensions; +import org.eclipse.xtext.xbase.lib.ListExtensions; +import org.eclipse.xtext.xbase.typing.IJvmTypeReferenceProvider; +import org.eclipse.xtext.xtype.XComputedTypeReference; +import org.eclipse.xtext.xtype.XtypeFactory; +import org.eclipse.xtext.xtype.impl.XComputedTypeReferenceImplCustom; +import org.jnario.Specification; +import org.jnario.jvmmodel.ExtendedJvmTypesBuilder; +import org.jnario.jvmmodel.JnarioJvmModelInferrer; +import org.jnario.runner.Named; +import org.jnario.suite.jvmmodel.SpecResolver; +import org.jnario.suite.jvmmodel.SuiteClassNameProvider; +import org.jnario.suite.jvmmodel.SuiteNode; +import org.jnario.suite.jvmmodel.SuiteNodeBuilder; +import org.jnario.suite.suite.Suite; +import org.jnario.suite.suite.SuiteFile; + +@SuppressWarnings("all") +public class SuiteJvmModelInferrer extends JnarioJvmModelInferrer { + @Inject + @Extension + private ExtendedJvmTypesBuilder _extendedJvmTypesBuilder; + + @Inject + @Extension + private SuiteClassNameProvider _suiteClassNameProvider; + + @Inject + @Extension + private SpecResolver _specResolver; + + @Inject + @Extension + private TypeReferences _typeReferences; + + @Inject + @Extension + private SuiteNodeBuilder _suiteNodeBuilder; + + @Inject + private TypesFactory typesFactory; + + @Inject(optional = true) + private XtypeFactory xtypesFactory = XtypeFactory.eINSTANCE; + + @Override + public void doInfer(final EObject e, final IJvmDeclaredTypeAcceptor acceptor, final boolean preIndexingPhase) { + if ((!(e instanceof SuiteFile))) { + return; + } + final SuiteFile suiteFile = ((SuiteFile) e); + final List suites = IterableExtensions.toList(Iterables.filter(suiteFile.getXtendTypes(), Suite.class)); + final Consumer _function = new Consumer() { + @Override + public void accept(final Suite it) { + final JvmGenericType javaType = SuiteJvmModelInferrer.this.typesFactory.createJvmGenericType(); + SuiteJvmModelInferrer.this.setNameAndAssociate(SuiteJvmModelInferrer.this.jnarioFile(it), it, javaType); + } + }; + suites.forEach(_function); + final Iterable nodes = this._suiteNodeBuilder.buildNodeModel(suiteFile); + final ArrayList doLater = CollectionLiterals.newArrayList(); + final Consumer _function_1 = new Consumer() { + @Override + public void accept(final SuiteNode it) { + SuiteJvmModelInferrer.this.infer(it, acceptor, doLater, preIndexingPhase); + } + }; + nodes.forEach(_function_1); + if (preIndexingPhase) { + return; + } + final Consumer _function_2 = new Consumer() { + @Override + public void accept(final Runnable it) { + it.run(); + } + }; + doLater.forEach(_function_2); + } + + public JvmGenericType infer(final SuiteNode node, final IJvmDeclaredTypeAcceptor acceptor, final List doLater, final boolean preIndexingPhase) { + JvmGenericType _xblockexpression = null; + { + final Suite suite = node.getSuite(); + final JvmGenericType suiteClass = this._extendedJvmTypesBuilder.toClass(suite, this._suiteClassNameProvider.toQualifiedJavaClassName(suite)); + boolean _equals = Objects.equal(suiteClass, null); + if (_equals) { + return null; + } + acceptor.accept(suiteClass); + final Function1 _function = new Function1() { + @Override + public JvmGenericType apply(final SuiteNode it) { + return SuiteJvmModelInferrer.this.infer(it, acceptor, doLater, preIndexingPhase); + } + }; + final Set subSuites = IterableExtensions.toSet(IterableExtensions.filterNull(ListExtensions.map(node.getChildren(), _function))); + if ((!preIndexingPhase)) { + final Function1 _function_1 = new Function1() { + @Override + public JvmTypeReference apply(final JvmGenericType it) { + JvmParameterizedTypeReference _createTypeRef = SuiteJvmModelInferrer.this._typeReferences.createTypeRef(it); + return ((JvmTypeReference) _createTypeRef); + } + }; + final Iterable subSuiteReferences = IterableExtensions.map(subSuites, _function_1); + final Runnable _function_2 = new Runnable() { + @Override + public void run() { + EList _annotations = suiteClass.getAnnotations(); + JvmAnnotationReference _annotation = SuiteJvmModelInferrer.this._extendedJvmTypesBuilder.toAnnotation(suite, Named.class, SuiteJvmModelInferrer.this._suiteClassNameProvider.describe(suite)); + SuiteJvmModelInferrer.this._extendedJvmTypesBuilder.operator_add(_annotations, _annotation); + Iterable _children = SuiteJvmModelInferrer.this.children(suite); + final Iterable children = Iterables.concat(_children, subSuiteReferences); + boolean _isEmpty = IterableExtensions.isEmpty(children); + boolean _not = (!_isEmpty); + if (_not) { + SuiteJvmModelInferrer.this.getTestRuntime().addChildren(suite, suiteClass, IterableExtensions.toSet(children)); + } + SuiteJvmModelInferrer.this.initialize(suite, suiteClass); + SuiteJvmModelInferrer.this.getTestRuntime().updateSuite(suite, suiteClass); + } + }; + doLater.add(_function_2); + } + _xblockexpression = suiteClass; + } + return _xblockexpression; + } + + public Iterable children(final Suite suite) { + Iterable _xblockexpression = null; + { + final Function1 _function = new Function1() { + @Override + public Boolean apply(final Specification it) { + String _javaClassName = SuiteJvmModelInferrer.this._suiteClassNameProvider.toJavaClassName(it); + return Boolean.valueOf((!Objects.equal(_javaClassName, null))); + } + }; + final Iterable specs = IterableExtensions.filter(this._specResolver.resolveSpecs(suite), _function); + final Function1 _function_1 = new Function1() { + @Override + public String apply(final Specification it) { + return SuiteJvmModelInferrer.this._suiteClassNameProvider.toQualifiedJavaClassName(it); + } + }; + final Iterable types = IterableExtensions.map(specs, _function_1); + final Function1 _function_2 = new Function1() { + @Override + public JvmTypeReference apply(final String it) { + return SuiteJvmModelInferrer.this.inferredType(it, suite); + } + }; + _xblockexpression = IterableExtensions.map(types, _function_2); + } + return _xblockexpression; + } + + public JvmTypeReference inferredType(final String name, final EObject context) { + final XComputedTypeReference result = this.xtypesFactory.createXComputedTypeReference(); + final IJvmTypeReferenceProvider _function = new IJvmTypeReferenceProvider() { + @Override + public JvmTypeReference getTypeReference(final XComputedTypeReferenceImplCustom it) { + return SuiteJvmModelInferrer.this._typeReferences.getTypeForName(name, context); + } + }; + result.setTypeProvider(_function); + return result; + } +} diff --git a/plugins/org.jnario.suite/xtend-gen/org/jnario/suite/jvmmodel/SuiteNode.java b/plugins/org.jnario.suite/xtend-gen/org/jnario/suite/jvmmodel/SuiteNode.java index ad1aaf057..39e128af8 100644 --- a/plugins/org.jnario.suite/xtend-gen/org/jnario/suite/jvmmodel/SuiteNode.java +++ b/plugins/org.jnario.suite/xtend-gen/org/jnario/suite/jvmmodel/SuiteNode.java @@ -1,103 +1,103 @@ -/** - * Copyright (c) 2012 BMW Car IT and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.jnario.suite.jvmmodel; - -import com.google.common.base.Objects; -import java.util.List; -import org.eclipse.xtend.lib.Data; -import org.eclipse.xtext.xbase.lib.CollectionLiterals; -import org.eclipse.xtext.xbase.lib.Pure; -import org.eclipse.xtext.xbase.lib.util.ToStringHelper; -import org.jnario.Specification; -import org.jnario.suite.suite.Suite; - -@Data -@SuppressWarnings("all") -public class SuiteNode { - private final Suite _suite; - - private final List _children = CollectionLiterals.newArrayList(); - - private final Iterable _specs; - - public void setParent(final SuiteNode parent) { - boolean _equals = Objects.equal(parent, null); - if (_equals) { - return; - } - List _children = parent.getChildren(); - _children.add(this); - } - - public SuiteNode(final Suite suite, final Iterable specs) { - super(); - this._suite = suite; - this._specs = specs; - } - - @Override - @Pure - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((this._suite== null) ? 0 : this._suite.hashCode()); - result = prime * result + ((this._children== null) ? 0 : this._children.hashCode()); - result = prime * result + ((this._specs== null) ? 0 : this._specs.hashCode()); - return result; - } - - @Override - @Pure - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - SuiteNode other = (SuiteNode) obj; - if (this._suite == null) { - if (other._suite != null) - return false; - } else if (!this._suite.equals(other._suite)) - return false; - if (this._children == null) { - if (other._children != null) - return false; - } else if (!this._children.equals(other._children)) - return false; - if (this._specs == null) { - if (other._specs != null) - return false; - } else if (!this._specs.equals(other._specs)) - return false; - return true; - } - - @Override - @Pure - public String toString() { - String result = new ToStringHelper().toString(this); - return result; - } - - @Pure - public Suite getSuite() { - return this._suite; - } - - @Pure - public List getChildren() { - return this._children; - } - - @Pure - public Iterable getSpecs() { - return this._specs; - } -} +/** + * Copyright (c) 2012 BMW Car IT and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.jnario.suite.jvmmodel; + +import com.google.common.base.Objects; +import java.util.List; +import org.eclipse.xtend.lib.Data; +import org.eclipse.xtext.xbase.lib.CollectionLiterals; +import org.eclipse.xtext.xbase.lib.Pure; +import org.eclipse.xtext.xbase.lib.util.ToStringHelper; +import org.jnario.Specification; +import org.jnario.suite.suite.Suite; + +@Data +@SuppressWarnings("all") +public class SuiteNode { + private final Suite _suite; + + private final List _children = CollectionLiterals.newArrayList(); + + private final Iterable _specs; + + public void setParent(final SuiteNode parent) { + boolean _equals = Objects.equal(parent, null); + if (_equals) { + return; + } + List _children = parent.getChildren(); + _children.add(this); + } + + public SuiteNode(final Suite suite, final Iterable specs) { + super(); + this._suite = suite; + this._specs = specs; + } + + @Override + @Pure + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((this._suite== null) ? 0 : this._suite.hashCode()); + result = prime * result + ((this._children== null) ? 0 : this._children.hashCode()); + result = prime * result + ((this._specs== null) ? 0 : this._specs.hashCode()); + return result; + } + + @Override + @Pure + public boolean equals(final Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + SuiteNode other = (SuiteNode) obj; + if (this._suite == null) { + if (other._suite != null) + return false; + } else if (!this._suite.equals(other._suite)) + return false; + if (this._children == null) { + if (other._children != null) + return false; + } else if (!this._children.equals(other._children)) + return false; + if (this._specs == null) { + if (other._specs != null) + return false; + } else if (!this._specs.equals(other._specs)) + return false; + return true; + } + + @Override + @Pure + public String toString() { + String result = new ToStringHelper().toString(this); + return result; + } + + @Pure + public Suite getSuite() { + return this._suite; + } + + @Pure + public List getChildren() { + return this._children; + } + + @Pure + public Iterable getSpecs() { + return this._specs; + } +} diff --git a/plugins/org.jnario.suite/xtend-gen/org/jnario/suite/jvmmodel/SuiteNodeBuilder.java b/plugins/org.jnario.suite/xtend-gen/org/jnario/suite/jvmmodel/SuiteNodeBuilder.java index 46f2493ea..bd7ca3d4c 100644 --- a/plugins/org.jnario.suite/xtend-gen/org/jnario/suite/jvmmodel/SuiteNodeBuilder.java +++ b/plugins/org.jnario.suite/xtend-gen/org/jnario/suite/jvmmodel/SuiteNodeBuilder.java @@ -1,123 +1,115 @@ -/** - * Copyright (c) 2012 BMW Car IT and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.jnario.suite.jvmmodel; - -import com.google.common.base.Objects; -import com.google.common.collect.Iterables; -import com.google.inject.Inject; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.xtext.xbase.lib.CollectionLiterals; -import org.eclipse.xtext.xbase.lib.Extension; -import org.eclipse.xtext.xbase.lib.Functions.Function1; -import org.eclipse.xtext.xbase.lib.IntegerRange; -import org.eclipse.xtext.xbase.lib.IterableExtensions; -import org.eclipse.xtext.xbase.lib.ListExtensions; -import org.jnario.JnarioTypeDeclaration; -import org.jnario.Specification; -import org.jnario.suite.jvmmodel.SpecResolver; -import org.jnario.suite.jvmmodel.SuiteNode; -import org.jnario.suite.suite.Reference; -import org.jnario.suite.suite.Suite; -import org.jnario.suite.suite.SuiteFile; - -@SuppressWarnings("all") -public class SuiteNodeBuilder { - private final static char PREFIX = "#".charAt(0); - - @Inject - @Extension - private SpecResolver _specResolver; - - public Iterable buildNodeModel(final SuiteFile suiteFile) { - ArrayList _xblockexpression = null; - { - EList _xtendTypes = suiteFile.getXtendTypes(); - Iterable _filter = Iterables.filter(_xtendTypes, Suite.class); - final List suites = IterableExtensions.toList(_filter); - final ArrayList result = CollectionLiterals.newArrayList(); - boolean _isEmpty = suites.isEmpty(); - if (_isEmpty) { - return result; - } - final HashMap mapping = CollectionLiterals.newHashMap(); - int _size = suites.size(); - int _minus = (_size - 1); - IntegerRange _upTo = new IntegerRange(0, _minus); - for (final Integer i : _upTo) { - { - final Suite current = suites.get((i).intValue()); - Suite _parent = this.parent(suites, (i).intValue()); - final SuiteNode parentNode = mapping.get(_parent); - final SuiteNode currentNode = this.createNode(current, parentNode); - mapping.put(current, currentNode); - boolean _equals = Objects.equal(parentNode, null); - if (_equals) { - result.add(currentNode); - } - } - } - _xblockexpression = result; - } - return _xblockexpression; - } - - public SuiteNode createNode(final Suite current, final SuiteNode parent) { - EList _elements = current.getElements(); - final Function1> _function = new Function1>() { - @Override - public List apply(final Reference it) { - return SuiteNodeBuilder.this._specResolver.resolveSpecs(it); - } - }; - List> _map = ListExtensions.>map(_elements, _function); - final Iterable specs = Iterables.concat(_map); - final SuiteNode node = new SuiteNode(current, specs); - node.setParent(parent); - return node; - } - - public Suite parent(final List suites, final int i) { - if ((i == 0)) { - return null; - } - Suite _get = suites.get(i); - final int current = this.level(_get); - IntegerRange _upTo = new IntegerRange((i - 1), 0); - for (final Integer j : _upTo) { - { - final Suite candidate = suites.get((j).intValue()); - int _level = this.level(candidate); - boolean _greaterThan = (current > _level); - if (_greaterThan) { - return candidate; - } - } - } - return null; - } - - public int level(final Suite suite) { - final String name = suite.getName(); - int i = 0; - while ((i < name.length())) { - { - char _charAt = name.charAt(i); - boolean _notEquals = (_charAt != SuiteNodeBuilder.PREFIX); - if (_notEquals) { - return i; - } - i = (i + 1); - } - } - return i; - } -} +/** + * Copyright (c) 2012 BMW Car IT and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.jnario.suite.jvmmodel; + +import com.google.common.base.Objects; +import com.google.common.collect.Iterables; +import com.google.inject.Inject; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.xtext.xbase.lib.CollectionLiterals; +import org.eclipse.xtext.xbase.lib.Extension; +import org.eclipse.xtext.xbase.lib.Functions.Function1; +import org.eclipse.xtext.xbase.lib.IntegerRange; +import org.eclipse.xtext.xbase.lib.IterableExtensions; +import org.eclipse.xtext.xbase.lib.ListExtensions; +import org.jnario.Specification; +import org.jnario.suite.jvmmodel.SpecResolver; +import org.jnario.suite.jvmmodel.SuiteNode; +import org.jnario.suite.suite.Reference; +import org.jnario.suite.suite.Suite; +import org.jnario.suite.suite.SuiteFile; + +@SuppressWarnings("all") +public class SuiteNodeBuilder { + private final static char PREFIX = "#".charAt(0); + + @Inject + @Extension + private SpecResolver _specResolver; + + public Iterable buildNodeModel(final SuiteFile suiteFile) { + ArrayList _xblockexpression = null; + { + final List suites = IterableExtensions.toList(Iterables.filter(suiteFile.getXtendTypes(), Suite.class)); + final ArrayList result = CollectionLiterals.newArrayList(); + boolean _isEmpty = suites.isEmpty(); + if (_isEmpty) { + return result; + } + final HashMap mapping = CollectionLiterals.newHashMap(); + int _size = suites.size(); + int _minus = (_size - 1); + IntegerRange _upTo = new IntegerRange(0, _minus); + for (final Integer i : _upTo) { + { + final Suite current = suites.get((i).intValue()); + final SuiteNode parentNode = mapping.get(this.parent(suites, (i).intValue())); + final SuiteNode currentNode = this.createNode(current, parentNode); + mapping.put(current, currentNode); + boolean _equals = Objects.equal(parentNode, null); + if (_equals) { + result.add(currentNode); + } + } + } + _xblockexpression = result; + } + return _xblockexpression; + } + + public SuiteNode createNode(final Suite current, final SuiteNode parent) { + final Function1> _function = new Function1>() { + @Override + public List apply(final Reference it) { + return SuiteNodeBuilder.this._specResolver.resolveSpecs(it); + } + }; + final Iterable specs = Iterables.concat(ListExtensions.>map(current.getElements(), _function)); + final SuiteNode node = new SuiteNode(current, specs); + node.setParent(parent); + return node; + } + + public Suite parent(final List suites, final int i) { + if ((i == 0)) { + return null; + } + final int current = this.level(suites.get(i)); + IntegerRange _upTo = new IntegerRange((i - 1), 0); + for (final Integer j : _upTo) { + { + final Suite candidate = suites.get((j).intValue()); + int _level = this.level(candidate); + boolean _greaterThan = (current > _level); + if (_greaterThan) { + return candidate; + } + } + } + return null; + } + + public int level(final Suite suite) { + final String name = suite.getName(); + int i = 0; + while ((i < name.length())) { + { + char _charAt = name.charAt(i); + boolean _notEquals = (_charAt != SuiteNodeBuilder.PREFIX); + if (_notEquals) { + return i; + } + i = (i + 1); + } + } + return i; + } +} diff --git a/plugins/org.jnario.suite/xtend-gen/org/jnario/suite/scoping/SuiteSpecFilter.java b/plugins/org.jnario.suite/xtend-gen/org/jnario/suite/scoping/SuiteSpecFilter.java index a706b97aa..027bc9b7d 100644 --- a/plugins/org.jnario.suite/xtend-gen/org/jnario/suite/scoping/SuiteSpecFilter.java +++ b/plugins/org.jnario.suite/xtend-gen/org/jnario/suite/scoping/SuiteSpecFilter.java @@ -1,43 +1,43 @@ -/** - * Copyright (c) 2012 BMW Car IT and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.jnario.suite.scoping; - -import com.google.common.base.Objects; -import com.google.common.base.Predicate; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.xtext.resource.IEObjectDescription; -import org.eclipse.xtext.xbase.lib.Extension; -import org.jnario.spec.scoping.SpecResourceDescriptionStrategy; -import org.jnario.spec.spec.SpecPackage; - -@SuppressWarnings("all") -public class SuiteSpecFilter implements Predicate { - @Extension - private final SpecPackage _specPackage = SpecPackage.eINSTANCE; - - @Override - public boolean apply(final IEObjectDescription input) { - boolean _switchResult = false; - EClass _eClass = input.getEClass(); - boolean _matched = false; - EClass _exampleGroup = this._specPackage.getExampleGroup(); - if (Objects.equal(_eClass, _exampleGroup)) { - _matched=true; - _switchResult = this.isRoot(input); - } - if (!_matched) { - _switchResult = true; - } - return _switchResult; - } - - public boolean isRoot(final IEObjectDescription input) { - String _userData = input.getUserData(SpecResourceDescriptionStrategy.ROOT_SPEC); - return Objects.equal(_userData, SpecResourceDescriptionStrategy.TRUE); - } -} +/** + * Copyright (c) 2012 BMW Car IT and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.jnario.suite.scoping; + +import com.google.common.base.Objects; +import com.google.common.base.Predicate; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.xtext.resource.IEObjectDescription; +import org.eclipse.xtext.xbase.lib.Extension; +import org.jnario.spec.scoping.SpecResourceDescriptionStrategy; +import org.jnario.spec.spec.SpecPackage; + +@SuppressWarnings("all") +public class SuiteSpecFilter implements Predicate { + @Extension + private final SpecPackage _specPackage = SpecPackage.eINSTANCE; + + @Override + public boolean apply(final IEObjectDescription input) { + boolean _switchResult = false; + EClass _eClass = input.getEClass(); + boolean _matched = false; + EClass _exampleGroup = this._specPackage.getExampleGroup(); + if (Objects.equal(_eClass, _exampleGroup)) { + _matched=true; + _switchResult = this.isRoot(input); + } + if (!_matched) { + _switchResult = true; + } + return _switchResult; + } + + public boolean isRoot(final IEObjectDescription input) { + String _userData = input.getUserData(SpecResourceDescriptionStrategy.ROOT_SPEC); + return Objects.equal(_userData, SpecResourceDescriptionStrategy.TRUE); + } +} diff --git a/plugins/org.jnario.ui/xtend-gen/org/jnario/ui/builder/JnarioBuilderParticipant.java b/plugins/org.jnario.ui/xtend-gen/org/jnario/ui/builder/JnarioBuilderParticipant.java index ba06fd5f3..9b222dccb 100644 --- a/plugins/org.jnario.ui/xtend-gen/org/jnario/ui/builder/JnarioBuilderParticipant.java +++ b/plugins/org.jnario.ui/xtend-gen/org/jnario/ui/builder/JnarioBuilderParticipant.java @@ -1,94 +1,76 @@ -/** - * Copyright (c) 2012 BMW Car IT and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.jnario.ui.builder; - -import com.google.inject.Inject; -import com.google.inject.Provider; -import java.util.List; -import java.util.Map; -import java.util.function.Consumer; -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.emf.common.util.URI; -import org.eclipse.xtext.builder.BuilderParticipant; -import org.eclipse.xtext.builder.EclipseResourceFileSystemAccess2; -import org.eclipse.xtext.builder.EclipseSourceFolderProvider; -import org.eclipse.xtext.builder.IXtextBuilderParticipant; -import org.eclipse.xtext.generator.OutputConfiguration; -import org.eclipse.xtext.resource.IResourceDescription; -import org.eclipse.xtext.xbase.lib.Functions.Function1; -import org.eclipse.xtext.xbase.lib.IterableExtensions; -import org.jnario.doc.HtmlAssets; -import org.jnario.ui.builder.NullFileCallBack; - -@SuppressWarnings("all") -public class JnarioBuilderParticipant extends BuilderParticipant { - @Inject - private Provider fileSystemAccessProvider; - - @Inject - private HtmlAssets htmlAssets; - - @Inject - private EclipseSourceFolderProvider sourceFolders; - - @Override - public void build(final IXtextBuilderParticipant.IBuildContext context, final IProgressMonitor monitor) throws CoreException { - super.build(context, monitor); - IProject _builtProject = context.getBuiltProject(); - List _sourceFolders = this.sourceFolders.getSourceFolders(_builtProject); - final Consumer _function = new Consumer() { - @Override - public void accept(final IContainer source) { - List _relevantDeltas = JnarioBuilderParticipant.this.getRelevantDeltas(context); - final Function1 _function = new Function1() { - @Override - public Boolean apply(final IResourceDescription.Delta it) { - URI _uri = it.getUri(); - String _string = _uri.toString(); - String _makeProjectRelative = JnarioBuilderParticipant.this.makeProjectRelative(source); - return Boolean.valueOf(_string.contains(_makeProjectRelative)); - } - }; - boolean _exists = IterableExtensions.exists(_relevantDeltas, _function); - if (_exists) { - EclipseResourceFileSystemAccess2 _createFsa = JnarioBuilderParticipant.this.createFsa(context, source); - JnarioBuilderParticipant.this.htmlAssets.generate(_createFsa); - } - } - }; - _sourceFolders.forEach(_function); - } - - private EclipseResourceFileSystemAccess2 createFsa(final IXtextBuilderParticipant.IBuildContext context, final IContainer source) { - final EclipseResourceFileSystemAccess2 fsa = this.fileSystemAccessProvider.get(); - final IProject builtProject = context.getBuiltProject(); - fsa.setProject(builtProject); - Map _outputConfigurations = this.getOutputConfigurations(context); - fsa.setOutputConfigurations(_outputConfigurations); - NullProgressMonitor _nullProgressMonitor = new NullProgressMonitor(); - fsa.setMonitor(_nullProgressMonitor); - NullFileCallBack _nullFileCallBack = new NullFileCallBack(); - fsa.setPostProcessor(_nullFileCallBack); - String _makeProjectRelative = this.makeProjectRelative(source); - fsa.setCurrentSource(_makeProjectRelative); - return fsa; - } - - private String makeProjectRelative(final IContainer source) { - IPath _fullPath = source.getFullPath(); - IProject _project = source.getProject(); - IPath _fullPath_1 = _project.getFullPath(); - IPath _makeRelativeTo = _fullPath.makeRelativeTo(_fullPath_1); - return _makeRelativeTo.toString(); - } -} +/** + * Copyright (c) 2012 BMW Car IT and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.jnario.ui.builder; + +import com.google.inject.Inject; +import com.google.inject.Provider; +import java.util.function.Consumer; +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.xtext.builder.BuilderParticipant; +import org.eclipse.xtext.builder.EclipseResourceFileSystemAccess2; +import org.eclipse.xtext.builder.EclipseSourceFolderProvider; +import org.eclipse.xtext.builder.IXtextBuilderParticipant; +import org.eclipse.xtext.resource.IResourceDescription; +import org.eclipse.xtext.xbase.lib.Functions.Function1; +import org.eclipse.xtext.xbase.lib.IterableExtensions; +import org.jnario.doc.HtmlAssets; +import org.jnario.ui.builder.NullFileCallBack; + +@SuppressWarnings("all") +public class JnarioBuilderParticipant extends BuilderParticipant { + @Inject + private Provider fileSystemAccessProvider; + + @Inject + private HtmlAssets htmlAssets; + + @Inject + private EclipseSourceFolderProvider sourceFolders; + + @Override + public void build(final IXtextBuilderParticipant.IBuildContext context, final IProgressMonitor monitor) throws CoreException { + super.build(context, monitor); + final Consumer _function = new Consumer() { + @Override + public void accept(final IContainer source) { + final Function1 _function = new Function1() { + @Override + public Boolean apply(final IResourceDescription.Delta it) { + return Boolean.valueOf(it.getUri().toString().contains(JnarioBuilderParticipant.this.makeProjectRelative(source))); + } + }; + boolean _exists = IterableExtensions.exists(JnarioBuilderParticipant.this.getRelevantDeltas(context), _function); + if (_exists) { + JnarioBuilderParticipant.this.htmlAssets.generate(JnarioBuilderParticipant.this.createFsa(context, source)); + } + } + }; + this.sourceFolders.getSourceFolders(context.getBuiltProject()).forEach(_function); + } + + private EclipseResourceFileSystemAccess2 createFsa(final IXtextBuilderParticipant.IBuildContext context, final IContainer source) { + final EclipseResourceFileSystemAccess2 fsa = this.fileSystemAccessProvider.get(); + final IProject builtProject = context.getBuiltProject(); + fsa.setProject(builtProject); + fsa.setOutputConfigurations(this.getOutputConfigurations(context)); + NullProgressMonitor _nullProgressMonitor = new NullProgressMonitor(); + fsa.setMonitor(_nullProgressMonitor); + NullFileCallBack _nullFileCallBack = new NullFileCallBack(); + fsa.setPostProcessor(_nullFileCallBack); + fsa.setCurrentSource(this.makeProjectRelative(source)); + return fsa; + } + + private String makeProjectRelative(final IContainer source) { + return source.getFullPath().makeRelativeTo(source.getProject().getFullPath()).toString(); + } +} diff --git a/plugins/org.jnario.ui/xtend-gen/org/jnario/ui/editor/XtendCopyQualifiedNameService.java b/plugins/org.jnario.ui/xtend-gen/org/jnario/ui/editor/XtendCopyQualifiedNameService.java index 36884b4d5..ed8d32681 100644 --- a/plugins/org.jnario.ui/xtend-gen/org/jnario/ui/editor/XtendCopyQualifiedNameService.java +++ b/plugins/org.jnario.ui/xtend-gen/org/jnario/ui/editor/XtendCopyQualifiedNameService.java @@ -1,65 +1,65 @@ -package org.jnario.ui.editor; - -import java.util.Arrays; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.xtend2.lib.StringConcatenation; -import org.eclipse.xtext.common.types.JvmConstructor; -import org.eclipse.xtext.common.types.JvmExecutable; -import org.eclipse.xtext.xbase.XAbstractFeatureCall; -import org.eclipse.xtext.xbase.XConstructorCall; -import org.eclipse.xtext.xbase.ui.editor.copyqualifiedname.XbaseCopyQualifiedNameService; -import org.jnario.JnarioFunction; - -@SuppressWarnings("all") -public class XtendCopyQualifiedNameService extends XbaseCopyQualifiedNameService { - protected String _getQualifiedName(final JnarioFunction it, final EObject context) { - return this.toQualifiedName(it); - } - - protected String _getQualifiedName(final JnarioFunction it, final Void context) { - return this.toQualifiedName(it); - } - - protected String toQualifiedName(final JnarioFunction it) { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("´toFullyQualifiedNameª(´parameters.toQualifiedNames[parameterType.simpleName]ª)"); - return _builder.toString(); - } - - public String getQualifiedName(final EObject it, final EObject context) { - if (it instanceof JvmConstructor - && context instanceof XConstructorCall) { - return _getQualifiedName((JvmConstructor)it, (XConstructorCall)context); - } else if (it instanceof JvmExecutable - && context instanceof XAbstractFeatureCall) { - return _getQualifiedName((JvmExecutable)it, (XAbstractFeatureCall)context); - } else if (it instanceof JvmExecutable - && context != null) { - return _getQualifiedName((JvmExecutable)it, context); - } else if (it instanceof JvmExecutable - && context == null) { - return _getQualifiedName((JvmExecutable)it, (Void)null); - } else if (it instanceof JnarioFunction - && context != null) { - return _getQualifiedName((JnarioFunction)it, context); - } else if (it instanceof JnarioFunction - && context == null) { - return _getQualifiedName((JnarioFunction)it, (Void)null); - } else if (it != null - && context != null) { - return _getQualifiedName(it, context); - } else if (it != null - && context == null) { - return _getQualifiedName(it, (Void)null); - } else if (it == null - && context != null) { - return _getQualifiedName((Void)null, context); - } else if (it == null - && context == null) { - return _getQualifiedName((Void)null, (Void)null); - } else { - throw new IllegalArgumentException("Unhandled parameter types: " + - Arrays.asList(it, context).toString()); - } - } -} +package org.jnario.ui.editor; + +import java.util.Arrays; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.xtend2.lib.StringConcatenation; +import org.eclipse.xtext.common.types.JvmConstructor; +import org.eclipse.xtext.common.types.JvmExecutable; +import org.eclipse.xtext.xbase.XAbstractFeatureCall; +import org.eclipse.xtext.xbase.XConstructorCall; +import org.eclipse.xtext.xbase.ui.editor.copyqualifiedname.XbaseCopyQualifiedNameService; +import org.jnario.JnarioFunction; + +@SuppressWarnings("all") +public class XtendCopyQualifiedNameService extends XbaseCopyQualifiedNameService { + protected String _getQualifiedName(final JnarioFunction it, final EObject context) { + return this.toQualifiedName(it); + } + + protected String _getQualifiedName(final JnarioFunction it, final Void context) { + return this.toQualifiedName(it); + } + + protected String toQualifiedName(final JnarioFunction it) { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("´toFullyQualifiedNameª(´parameters.toQualifiedNames[parameterType.simpleName]ª)"); + return _builder.toString(); + } + + public String getQualifiedName(final EObject it, final EObject context) { + if (it instanceof JvmConstructor + && context instanceof XConstructorCall) { + return _getQualifiedName((JvmConstructor)it, (XConstructorCall)context); + } else if (it instanceof JvmExecutable + && context instanceof XAbstractFeatureCall) { + return _getQualifiedName((JvmExecutable)it, (XAbstractFeatureCall)context); + } else if (it instanceof JvmExecutable + && context != null) { + return _getQualifiedName((JvmExecutable)it, context); + } else if (it instanceof JvmExecutable + && context == null) { + return _getQualifiedName((JvmExecutable)it, (Void)null); + } else if (it instanceof JnarioFunction + && context != null) { + return _getQualifiedName((JnarioFunction)it, context); + } else if (it instanceof JnarioFunction + && context == null) { + return _getQualifiedName((JnarioFunction)it, (Void)null); + } else if (it != null + && context != null) { + return _getQualifiedName(it, context); + } else if (it != null + && context == null) { + return _getQualifiedName(it, (Void)null); + } else if (it == null + && context != null) { + return _getQualifiedName((Void)null, context); + } else if (it == null + && context == null) { + return _getQualifiedName((Void)null, (Void)null); + } else { + throw new IllegalArgumentException("Unhandled parameter types: " + + Arrays.asList(it, context).toString()); + } + } +} diff --git a/plugins/org.jnario.ui/xtend-gen/org/jnario/ui/findrefs/XtendReferenceFinder.java b/plugins/org.jnario.ui/xtend-gen/org/jnario/ui/findrefs/XtendReferenceFinder.java index 83b43af5e..07a7179cc 100644 --- a/plugins/org.jnario.ui/xtend-gen/org/jnario/ui/findrefs/XtendReferenceFinder.java +++ b/plugins/org.jnario.ui/xtend-gen/org/jnario/ui/findrefs/XtendReferenceFinder.java @@ -1,130 +1,119 @@ -package org.jnario.ui.findrefs; - -import com.google.common.base.Objects; -import com.google.common.base.Predicate; -import com.google.inject.Inject; -import java.util.HashSet; -import java.util.Set; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.emf.common.util.URI; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.emf.ecore.resource.ResourceSet; -import org.eclipse.xtext.EcoreUtil2; -import org.eclipse.xtext.common.types.JvmType; -import org.eclipse.xtext.naming.IQualifiedNameConverter; -import org.eclipse.xtext.naming.QualifiedName; -import org.eclipse.xtext.resource.IReferenceDescription; -import org.eclipse.xtext.resource.IResourceDescription; -import org.eclipse.xtext.resource.IResourceDescriptions; -import org.eclipse.xtext.resource.IResourceServiceProvider; -import org.eclipse.xtext.ui.editor.findrefs.DefaultReferenceFinder; -import org.eclipse.xtext.ui.editor.findrefs.IReferenceFinder; -import org.eclipse.xtext.util.IAcceptor; -import org.eclipse.xtext.util.concurrent.IUnitOfWork; -import org.eclipse.xtext.xbase.lib.CollectionLiterals; -import org.eclipse.xtext.xbase.lib.Functions.Function1; -import org.eclipse.xtext.xbase.lib.IterableExtensions; - -@SuppressWarnings("all") -public class XtendReferenceFinder extends DefaultReferenceFinder implements IReferenceFinder { - private IQualifiedNameConverter nameConverter; - - @Inject - public XtendReferenceFinder(final IResourceDescriptions indexData, final IResourceServiceProvider.Registry serviceProviderRegistry, final IQualifiedNameConverter nameConverter) { - super(indexData, serviceProviderRegistry); - this.nameConverter = nameConverter; - } - - @Override - public void findReferences(final Set targetURIs, final IResourceDescription resourceDescription, final IAcceptor acceptor, final IProgressMonitor monitor, final IReferenceFinder.ILocalResourceAccess localResourceAccess) { - final Function1 _function = new Function1() { - @Override - public URI apply(final URI it) { - return it.trimFragment(); - } - }; - Iterable _map = IterableExtensions.map(targetURIs, _function); - final Function1 _function_1 = new Function1() { - @Override - public Boolean apply(final URI it) { - URI _uRI = resourceDescription.getURI(); - return Boolean.valueOf(Objects.equal(it, _uRI)); - } - }; - boolean _exists = IterableExtensions.exists(_map, _function_1); - if (_exists) { - return; - } - final HashSet names = CollectionLiterals.newHashSet(); - for (final URI uri : targetURIs) { - final IUnitOfWork _function_2 = new IUnitOfWork() { - @Override - public Boolean exec(final ResourceSet it) throws Exception { - boolean _xblockexpression = false; - { - EObject _eObject = it.getEObject(uri, true); - final JvmType obj = EcoreUtil2.getContainerOfType(_eObject, JvmType.class); - boolean _xifexpression = false; - boolean _notEquals = (!Objects.equal(obj, null)); - if (_notEquals) { - String _identifier = obj.getIdentifier(); - String _lowerCase = _identifier.toLowerCase(); - QualifiedName _qualifiedName = XtendReferenceFinder.this.nameConverter.toQualifiedName(_lowerCase); - _xifexpression = names.add(_qualifiedName); - } - _xblockexpression = _xifexpression; - } - return Boolean.valueOf(_xblockexpression); - } - }; - localResourceAccess.readOnly(uri, _function_2); - } - Iterable _importedNames = resourceDescription.getImportedNames(); - final Function1 _function_3 = new Function1() { - @Override - public QualifiedName apply(final QualifiedName it) { - return it.toLowerCase(); - } - }; - Iterable _map_1 = IterableExtensions.map(_importedNames, _function_3); - final Set importedNames = IterableExtensions.toSet(_map_1); - final Function1 _function_4 = new Function1() { - @Override - public Boolean apply(final QualifiedName it) { - return Boolean.valueOf(importedNames.contains(it)); - } - }; - boolean _exists_1 = IterableExtensions.exists(names, _function_4); - if (_exists_1) { - URI _uRI = resourceDescription.getURI(); - final IUnitOfWork _function_5 = new IUnitOfWork() { - @Override - public Object exec(final ResourceSet it) throws Exception { - final Function1 _function = new Function1() { - @Override - public Boolean apply(final URI uri) { - return Boolean.valueOf(targetURIs.contains(uri)); - } - }; - final Function1 isInTargetURIs = _function; - URI _uRI = resourceDescription.getURI(); - Resource _resource = it.getResource(_uRI, true); - final IAcceptor _function_1 = new IAcceptor() { - @Override - public void accept(final IReferenceDescription it) { - acceptor.accept(it); - } - }; - XtendReferenceFinder.this.findLocalReferencesInResource(new Predicate() { - public boolean apply(URI arg0) { - return isInTargetURIs.apply(arg0); - } - }, _resource, _function_1); - return null; - } - }; - localResourceAccess.readOnly(_uRI, _function_5); - } - } -} +package org.jnario.ui.findrefs; + +import com.google.common.base.Objects; +import com.google.common.base.Predicate; +import com.google.inject.Inject; +import java.util.HashSet; +import java.util.Set; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.xtext.EcoreUtil2; +import org.eclipse.xtext.common.types.JvmType; +import org.eclipse.xtext.naming.IQualifiedNameConverter; +import org.eclipse.xtext.naming.QualifiedName; +import org.eclipse.xtext.resource.IReferenceDescription; +import org.eclipse.xtext.resource.IResourceDescription; +import org.eclipse.xtext.resource.IResourceDescriptions; +import org.eclipse.xtext.resource.IResourceServiceProvider; +import org.eclipse.xtext.ui.editor.findrefs.DefaultReferenceFinder; +import org.eclipse.xtext.ui.editor.findrefs.IReferenceFinder; +import org.eclipse.xtext.util.IAcceptor; +import org.eclipse.xtext.util.concurrent.IUnitOfWork; +import org.eclipse.xtext.xbase.lib.CollectionLiterals; +import org.eclipse.xtext.xbase.lib.Functions.Function1; +import org.eclipse.xtext.xbase.lib.IterableExtensions; + +@SuppressWarnings("all") +public class XtendReferenceFinder extends DefaultReferenceFinder implements IReferenceFinder { + private IQualifiedNameConverter nameConverter; + + @Inject + public XtendReferenceFinder(final IResourceDescriptions indexData, final IResourceServiceProvider.Registry serviceProviderRegistry, final IQualifiedNameConverter nameConverter) { + super(indexData, serviceProviderRegistry); + this.nameConverter = nameConverter; + } + + @Override + public void findReferences(final Set targetURIs, final IResourceDescription resourceDescription, final IAcceptor acceptor, final IProgressMonitor monitor, final IReferenceFinder.ILocalResourceAccess localResourceAccess) { + final Function1 _function = new Function1() { + @Override + public URI apply(final URI it) { + return it.trimFragment(); + } + }; + final Function1 _function_1 = new Function1() { + @Override + public Boolean apply(final URI it) { + URI _uRI = resourceDescription.getURI(); + return Boolean.valueOf(Objects.equal(it, _uRI)); + } + }; + boolean _exists = IterableExtensions.exists(IterableExtensions.map(targetURIs, _function), _function_1); + if (_exists) { + return; + } + final HashSet names = CollectionLiterals.newHashSet(); + for (final URI uri : targetURIs) { + final IUnitOfWork _function_2 = new IUnitOfWork() { + @Override + public Boolean exec(final ResourceSet it) throws Exception { + boolean _xblockexpression = false; + { + final JvmType obj = EcoreUtil2.getContainerOfType(it.getEObject(uri, true), JvmType.class); + boolean _xifexpression = false; + boolean _notEquals = (!Objects.equal(obj, null)); + if (_notEquals) { + QualifiedName _qualifiedName = XtendReferenceFinder.this.nameConverter.toQualifiedName(obj.getIdentifier().toLowerCase()); + _xifexpression = names.add(_qualifiedName); + } + _xblockexpression = _xifexpression; + } + return Boolean.valueOf(_xblockexpression); + } + }; + localResourceAccess.readOnly(uri, _function_2); + } + final Function1 _function_3 = new Function1() { + @Override + public QualifiedName apply(final QualifiedName it) { + return it.toLowerCase(); + } + }; + final Set importedNames = IterableExtensions.toSet(IterableExtensions.map(resourceDescription.getImportedNames(), _function_3)); + final Function1 _function_4 = new Function1() { + @Override + public Boolean apply(final QualifiedName it) { + return Boolean.valueOf(importedNames.contains(it)); + } + }; + boolean _exists_1 = IterableExtensions.exists(names, _function_4); + if (_exists_1) { + final IUnitOfWork _function_5 = new IUnitOfWork() { + @Override + public Object exec(final ResourceSet it) throws Exception { + final Function1 _function = new Function1() { + @Override + public Boolean apply(final URI uri) { + return Boolean.valueOf(targetURIs.contains(uri)); + } + }; + final Function1 isInTargetURIs = _function; + final IAcceptor _function_1 = new IAcceptor() { + @Override + public void accept(final IReferenceDescription it) { + acceptor.accept(it); + } + }; + XtendReferenceFinder.this.findLocalReferencesInResource(new Predicate() { + public boolean apply(URI arg0) { + return isInTargetURIs.apply(arg0); + } + }, it.getResource(resourceDescription.getURI(), true), _function_1); + return null; + } + }; + localResourceAccess.readOnly(resourceDescription.getURI(), _function_5); + } + } +} diff --git a/plugins/org.jnario.xbase.richstring/xtend-gen/org/jnario/xbase/richstring/formatting2/XbaseWithRichstringFormatter.java b/plugins/org.jnario.xbase.richstring/xtend-gen/org/jnario/xbase/richstring/formatting2/XbaseWithRichstringFormatter.java index 987465ede..7dbcb5ae6 100644 --- a/plugins/org.jnario.xbase.richstring/xtend-gen/org/jnario/xbase/richstring/formatting2/XbaseWithRichstringFormatter.java +++ b/plugins/org.jnario.xbase.richstring/xtend-gen/org/jnario/xbase/richstring/formatting2/XbaseWithRichstringFormatter.java @@ -1,187 +1,187 @@ -/** - * generated by Xtext - */ -package org.jnario.xbase.richstring.formatting2; - -import com.google.inject.Inject; -import java.util.Arrays; -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.xtext.common.types.JvmFormalParameter; -import org.eclipse.xtext.common.types.JvmGenericArrayTypeReference; -import org.eclipse.xtext.common.types.JvmParameterizedTypeReference; -import org.eclipse.xtext.common.types.JvmTypeConstraint; -import org.eclipse.xtext.common.types.JvmTypeParameter; -import org.eclipse.xtext.common.types.JvmWildcardTypeReference; -import org.eclipse.xtext.formatting2.IFormattableDocument; -import org.eclipse.xtext.resource.XtextResource; -import org.eclipse.xtext.xbase.XAssignment; -import org.eclipse.xtext.xbase.XBasicForLoopExpression; -import org.eclipse.xtext.xbase.XBinaryOperation; -import org.eclipse.xtext.xbase.XBlockExpression; -import org.eclipse.xtext.xbase.XCastedExpression; -import org.eclipse.xtext.xbase.XClosure; -import org.eclipse.xtext.xbase.XCollectionLiteral; -import org.eclipse.xtext.xbase.XConstructorCall; -import org.eclipse.xtext.xbase.XDoWhileExpression; -import org.eclipse.xtext.xbase.XExpression; -import org.eclipse.xtext.xbase.XFeatureCall; -import org.eclipse.xtext.xbase.XForLoopExpression; -import org.eclipse.xtext.xbase.XIfExpression; -import org.eclipse.xtext.xbase.XInstanceOfExpression; -import org.eclipse.xtext.xbase.XMemberFeatureCall; -import org.eclipse.xtext.xbase.XPostfixOperation; -import org.eclipse.xtext.xbase.XReturnExpression; -import org.eclipse.xtext.xbase.XSwitchExpression; -import org.eclipse.xtext.xbase.XSynchronizedExpression; -import org.eclipse.xtext.xbase.XThrowExpression; -import org.eclipse.xtext.xbase.XTryCatchFinallyExpression; -import org.eclipse.xtext.xbase.XTypeLiteral; -import org.eclipse.xtext.xbase.XVariableDeclaration; -import org.eclipse.xtext.xbase.XWhileExpression; -import org.eclipse.xtext.xbase.annotations.formatting2.XbaseWithAnnotationsFormatter; -import org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation; -import org.eclipse.xtext.xbase.lib.Extension; -import org.eclipse.xtext.xtype.XFunctionTypeRef; -import org.eclipse.xtext.xtype.XImportDeclaration; -import org.eclipse.xtext.xtype.XImportSection; -import org.jnario.xbase.richstring.services.XbaseWithRichstringGrammarAccess; -import org.jnario.xbase.richstring.xbasewithrichstring.RichString; - -@SuppressWarnings("all") -public class XbaseWithRichstringFormatter extends XbaseWithAnnotationsFormatter { - @Inject - @Extension - private XbaseWithRichstringGrammarAccess _xbaseWithRichstringGrammarAccess; - - protected void _format(final RichString richstring, @Extension final IFormattableDocument document) { - EList _expressions = richstring.getExpressions(); - for (final XExpression expressions : _expressions) { - this.format(expressions, document); - } - } - - public void format(final Object richstring, final IFormattableDocument document) { - if (richstring instanceof JvmTypeParameter) { - _format((JvmTypeParameter)richstring, document); - return; - } else if (richstring instanceof JvmFormalParameter) { - _format((JvmFormalParameter)richstring, document); - return; - } else if (richstring instanceof XtextResource) { - _format((XtextResource)richstring, document); - return; - } else if (richstring instanceof XAssignment) { - _format((XAssignment)richstring, document); - return; - } else if (richstring instanceof XBinaryOperation) { - _format((XBinaryOperation)richstring, document); - return; - } else if (richstring instanceof XDoWhileExpression) { - _format((XDoWhileExpression)richstring, document); - return; - } else if (richstring instanceof XFeatureCall) { - _format((XFeatureCall)richstring, document); - return; - } else if (richstring instanceof XMemberFeatureCall) { - _format((XMemberFeatureCall)richstring, document); - return; - } else if (richstring instanceof XPostfixOperation) { - _format((XPostfixOperation)richstring, document); - return; - } else if (richstring instanceof XWhileExpression) { - _format((XWhileExpression)richstring, document); - return; - } else if (richstring instanceof XFunctionTypeRef) { - _format((XFunctionTypeRef)richstring, document); - return; - } else if (richstring instanceof RichString) { - _format((RichString)richstring, document); - return; - } else if (richstring instanceof JvmGenericArrayTypeReference) { - _format((JvmGenericArrayTypeReference)richstring, document); - return; - } else if (richstring instanceof JvmParameterizedTypeReference) { - _format((JvmParameterizedTypeReference)richstring, document); - return; - } else if (richstring instanceof JvmWildcardTypeReference) { - _format((JvmWildcardTypeReference)richstring, document); - return; - } else if (richstring instanceof XBasicForLoopExpression) { - _format((XBasicForLoopExpression)richstring, document); - return; - } else if (richstring instanceof XBlockExpression) { - _format((XBlockExpression)richstring, document); - return; - } else if (richstring instanceof XCastedExpression) { - _format((XCastedExpression)richstring, document); - return; - } else if (richstring instanceof XClosure) { - _format((XClosure)richstring, document); - return; - } else if (richstring instanceof XCollectionLiteral) { - _format((XCollectionLiteral)richstring, document); - return; - } else if (richstring instanceof XConstructorCall) { - _format((XConstructorCall)richstring, document); - return; - } else if (richstring instanceof XForLoopExpression) { - _format((XForLoopExpression)richstring, document); - return; - } else if (richstring instanceof XIfExpression) { - _format((XIfExpression)richstring, document); - return; - } else if (richstring instanceof XInstanceOfExpression) { - _format((XInstanceOfExpression)richstring, document); - return; - } else if (richstring instanceof XReturnExpression) { - _format((XReturnExpression)richstring, document); - return; - } else if (richstring instanceof XSwitchExpression) { - _format((XSwitchExpression)richstring, document); - return; - } else if (richstring instanceof XSynchronizedExpression) { - _format((XSynchronizedExpression)richstring, document); - return; - } else if (richstring instanceof XThrowExpression) { - _format((XThrowExpression)richstring, document); - return; - } else if (richstring instanceof XTryCatchFinallyExpression) { - _format((XTryCatchFinallyExpression)richstring, document); - return; - } else if (richstring instanceof XTypeLiteral) { - _format((XTypeLiteral)richstring, document); - return; - } else if (richstring instanceof XVariableDeclaration) { - _format((XVariableDeclaration)richstring, document); - return; - } else if (richstring instanceof XAnnotation) { - _format((XAnnotation)richstring, document); - return; - } else if (richstring instanceof JvmTypeConstraint) { - _format((JvmTypeConstraint)richstring, document); - return; - } else if (richstring instanceof XExpression) { - _format((XExpression)richstring, document); - return; - } else if (richstring instanceof XImportDeclaration) { - _format((XImportDeclaration)richstring, document); - return; - } else if (richstring instanceof XImportSection) { - _format((XImportSection)richstring, document); - return; - } else if (richstring instanceof EObject) { - _format((EObject)richstring, document); - return; - } else if (richstring == null) { - _format((Void)null, document); - return; - } else if (richstring != null) { - _format(richstring, document); - return; - } else { - throw new IllegalArgumentException("Unhandled parameter types: " + - Arrays.asList(richstring, document).toString()); - } - } -} +/** + * generated by Xtext + */ +package org.jnario.xbase.richstring.formatting2; + +import com.google.inject.Inject; +import java.util.Arrays; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.xtext.common.types.JvmFormalParameter; +import org.eclipse.xtext.common.types.JvmGenericArrayTypeReference; +import org.eclipse.xtext.common.types.JvmParameterizedTypeReference; +import org.eclipse.xtext.common.types.JvmTypeConstraint; +import org.eclipse.xtext.common.types.JvmTypeParameter; +import org.eclipse.xtext.common.types.JvmWildcardTypeReference; +import org.eclipse.xtext.formatting2.IFormattableDocument; +import org.eclipse.xtext.resource.XtextResource; +import org.eclipse.xtext.xbase.XAssignment; +import org.eclipse.xtext.xbase.XBasicForLoopExpression; +import org.eclipse.xtext.xbase.XBinaryOperation; +import org.eclipse.xtext.xbase.XBlockExpression; +import org.eclipse.xtext.xbase.XCastedExpression; +import org.eclipse.xtext.xbase.XClosure; +import org.eclipse.xtext.xbase.XCollectionLiteral; +import org.eclipse.xtext.xbase.XConstructorCall; +import org.eclipse.xtext.xbase.XDoWhileExpression; +import org.eclipse.xtext.xbase.XExpression; +import org.eclipse.xtext.xbase.XFeatureCall; +import org.eclipse.xtext.xbase.XForLoopExpression; +import org.eclipse.xtext.xbase.XIfExpression; +import org.eclipse.xtext.xbase.XInstanceOfExpression; +import org.eclipse.xtext.xbase.XMemberFeatureCall; +import org.eclipse.xtext.xbase.XPostfixOperation; +import org.eclipse.xtext.xbase.XReturnExpression; +import org.eclipse.xtext.xbase.XSwitchExpression; +import org.eclipse.xtext.xbase.XSynchronizedExpression; +import org.eclipse.xtext.xbase.XThrowExpression; +import org.eclipse.xtext.xbase.XTryCatchFinallyExpression; +import org.eclipse.xtext.xbase.XTypeLiteral; +import org.eclipse.xtext.xbase.XVariableDeclaration; +import org.eclipse.xtext.xbase.XWhileExpression; +import org.eclipse.xtext.xbase.annotations.formatting2.XbaseWithAnnotationsFormatter; +import org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation; +import org.eclipse.xtext.xbase.lib.Extension; +import org.eclipse.xtext.xtype.XFunctionTypeRef; +import org.eclipse.xtext.xtype.XImportDeclaration; +import org.eclipse.xtext.xtype.XImportSection; +import org.jnario.xbase.richstring.services.XbaseWithRichstringGrammarAccess; +import org.jnario.xbase.richstring.xbasewithrichstring.RichString; + +@SuppressWarnings("all") +public class XbaseWithRichstringFormatter extends XbaseWithAnnotationsFormatter { + @Inject + @Extension + private XbaseWithRichstringGrammarAccess _xbaseWithRichstringGrammarAccess; + + protected void _format(final RichString richstring, @Extension final IFormattableDocument document) { + EList _expressions = richstring.getExpressions(); + for (final XExpression expressions : _expressions) { + this.format(expressions, document); + } + } + + public void format(final Object richstring, final IFormattableDocument document) { + if (richstring instanceof JvmTypeParameter) { + _format((JvmTypeParameter)richstring, document); + return; + } else if (richstring instanceof JvmFormalParameter) { + _format((JvmFormalParameter)richstring, document); + return; + } else if (richstring instanceof XtextResource) { + _format((XtextResource)richstring, document); + return; + } else if (richstring instanceof XAssignment) { + _format((XAssignment)richstring, document); + return; + } else if (richstring instanceof XBinaryOperation) { + _format((XBinaryOperation)richstring, document); + return; + } else if (richstring instanceof XDoWhileExpression) { + _format((XDoWhileExpression)richstring, document); + return; + } else if (richstring instanceof XFeatureCall) { + _format((XFeatureCall)richstring, document); + return; + } else if (richstring instanceof XMemberFeatureCall) { + _format((XMemberFeatureCall)richstring, document); + return; + } else if (richstring instanceof XPostfixOperation) { + _format((XPostfixOperation)richstring, document); + return; + } else if (richstring instanceof XWhileExpression) { + _format((XWhileExpression)richstring, document); + return; + } else if (richstring instanceof XFunctionTypeRef) { + _format((XFunctionTypeRef)richstring, document); + return; + } else if (richstring instanceof RichString) { + _format((RichString)richstring, document); + return; + } else if (richstring instanceof JvmGenericArrayTypeReference) { + _format((JvmGenericArrayTypeReference)richstring, document); + return; + } else if (richstring instanceof JvmParameterizedTypeReference) { + _format((JvmParameterizedTypeReference)richstring, document); + return; + } else if (richstring instanceof JvmWildcardTypeReference) { + _format((JvmWildcardTypeReference)richstring, document); + return; + } else if (richstring instanceof XBasicForLoopExpression) { + _format((XBasicForLoopExpression)richstring, document); + return; + } else if (richstring instanceof XBlockExpression) { + _format((XBlockExpression)richstring, document); + return; + } else if (richstring instanceof XCastedExpression) { + _format((XCastedExpression)richstring, document); + return; + } else if (richstring instanceof XClosure) { + _format((XClosure)richstring, document); + return; + } else if (richstring instanceof XCollectionLiteral) { + _format((XCollectionLiteral)richstring, document); + return; + } else if (richstring instanceof XConstructorCall) { + _format((XConstructorCall)richstring, document); + return; + } else if (richstring instanceof XForLoopExpression) { + _format((XForLoopExpression)richstring, document); + return; + } else if (richstring instanceof XIfExpression) { + _format((XIfExpression)richstring, document); + return; + } else if (richstring instanceof XInstanceOfExpression) { + _format((XInstanceOfExpression)richstring, document); + return; + } else if (richstring instanceof XReturnExpression) { + _format((XReturnExpression)richstring, document); + return; + } else if (richstring instanceof XSwitchExpression) { + _format((XSwitchExpression)richstring, document); + return; + } else if (richstring instanceof XSynchronizedExpression) { + _format((XSynchronizedExpression)richstring, document); + return; + } else if (richstring instanceof XThrowExpression) { + _format((XThrowExpression)richstring, document); + return; + } else if (richstring instanceof XTryCatchFinallyExpression) { + _format((XTryCatchFinallyExpression)richstring, document); + return; + } else if (richstring instanceof XTypeLiteral) { + _format((XTypeLiteral)richstring, document); + return; + } else if (richstring instanceof XVariableDeclaration) { + _format((XVariableDeclaration)richstring, document); + return; + } else if (richstring instanceof XAnnotation) { + _format((XAnnotation)richstring, document); + return; + } else if (richstring instanceof JvmTypeConstraint) { + _format((JvmTypeConstraint)richstring, document); + return; + } else if (richstring instanceof XExpression) { + _format((XExpression)richstring, document); + return; + } else if (richstring instanceof XImportDeclaration) { + _format((XImportDeclaration)richstring, document); + return; + } else if (richstring instanceof XImportSection) { + _format((XImportSection)richstring, document); + return; + } else if (richstring instanceof EObject) { + _format((EObject)richstring, document); + return; + } else if (richstring == null) { + _format((Void)null, document); + return; + } else if (richstring != null) { + _format(richstring, document); + return; + } else { + throw new IllegalArgumentException("Unhandled parameter types: " + + Arrays.asList(richstring, document).toString()); + } + } +} diff --git a/plugins/org.jnario.xbase.richstring/xtend-gen/org/jnario/xbase/richstring/util/DefaultIndentationHandler.java b/plugins/org.jnario.xbase.richstring/xtend-gen/org/jnario/xbase/richstring/util/DefaultIndentationHandler.java index 5e3b4cdbd..623715528 100644 --- a/plugins/org.jnario.xbase.richstring/xtend-gen/org/jnario/xbase/richstring/util/DefaultIndentationHandler.java +++ b/plugins/org.jnario.xbase.richstring/xtend-gen/org/jnario/xbase/richstring/util/DefaultIndentationHandler.java @@ -1,160 +1,150 @@ -package org.jnario.xbase.richstring.util; - -import com.google.common.collect.Lists; -import java.util.LinkedList; -import org.eclipse.xtend2.lib.StringConcatenation; -import org.jnario.xbase.richstring.util.IRichStringIndentationHandler; -import org.jnario.xbase.richstring.util.IRichStringPartAcceptor; - -/** - * Default indentation handler for rich strings. Tries to be graceful with - * inconsistent indentation. - * @author Sebastian Zarnekow - Initial contribution and API - */ -@SuppressWarnings("all") -public class DefaultIndentationHandler implements IRichStringIndentationHandler { - protected static abstract class IndentationData { - protected CharSequence value; - - protected IndentationData(final CharSequence value) { - this.value = value; - } - - protected abstract void accept(final IRichStringPartAcceptor acceptor); - - @Override - public String toString() { - StringConcatenation _builder = new StringConcatenation(); - Class _class = this.getClass(); - String _simpleName = _class.getSimpleName(); - _builder.append(_simpleName, ""); - _builder.append(" ["); - _builder.append(this.value, ""); - _builder.append("]"); - return _builder.toString(); - } - } - - protected static class SemanticIndentationData extends DefaultIndentationHandler.IndentationData { - protected SemanticIndentationData(final CharSequence value) { - super(value); - } - - @Override - protected void accept(final IRichStringPartAcceptor acceptor) { - acceptor.acceptSemanticText(this.value, null); - } - } - - protected static class TemplateIndentationData extends DefaultIndentationHandler.IndentationData { - protected TemplateIndentationData(final CharSequence value) { - super(value); - } - - @Override - protected void accept(final IRichStringPartAcceptor acceptor) { - acceptor.acceptTemplateText(this.value, null); - } - } - - private LinkedList indentationData; - - private LinkedList> indentationDataStack; - - public DefaultIndentationHandler() { - LinkedList _newLinkedList = Lists.newLinkedList(); - this.indentationData = _newLinkedList; - LinkedList> _newLinkedList_1 = Lists.>newLinkedList(); - this.indentationDataStack = _newLinkedList_1; - this.indentationDataStack.add(this.indentationData); - } - - @Override - public void popIndentation() { - this.indentationData.removeLast(); - if ((this.indentationData.isEmpty() && (this.indentationDataStack.size() > 1))) { - this.indentationDataStack.removeLast(); - LinkedList _last = this.indentationDataStack.getLast(); - this.indentationData = _last; - } - } - - @Override - public void pushTemplateIndentation(final CharSequence indentation) { - boolean _isEmpty = this.indentationData.isEmpty(); - if (_isEmpty) { - DefaultIndentationHandler.TemplateIndentationData _templateIndentationData = new DefaultIndentationHandler.TemplateIndentationData(indentation); - this.indentationData.add(_templateIndentationData); - } else { - String currentIndentation = this.getTotalIndentation(); - String _string = indentation.toString(); - boolean _startsWith = _string.startsWith(currentIndentation); - if (_startsWith) { - String _string_1 = indentation.toString(); - int _length = currentIndentation.length(); - String trimmedIndentation = _string_1.substring(_length); - DefaultIndentationHandler.TemplateIndentationData _templateIndentationData_1 = new DefaultIndentationHandler.TemplateIndentationData(trimmedIndentation); - this.indentationData.add(_templateIndentationData_1); - } else { - LinkedList newIndentationData = Lists.newLinkedList(); - DefaultIndentationHandler.TemplateIndentationData _templateIndentationData_2 = new DefaultIndentationHandler.TemplateIndentationData(indentation); - newIndentationData.add(_templateIndentationData_2); - this.indentationDataStack.add(newIndentationData); - this.indentationData = newIndentationData; - } - } - } - - @Override - public void pushSemanticIndentation(final CharSequence indentation) { - boolean _isEmpty = this.indentationData.isEmpty(); - if (_isEmpty) { - DefaultIndentationHandler.SemanticIndentationData _semanticIndentationData = new DefaultIndentationHandler.SemanticIndentationData(indentation); - this.indentationData.add(_semanticIndentationData); - } else { - String currentIndentation = this.getTotalIndentation(); - String _string = indentation.toString(); - boolean _startsWith = _string.startsWith(currentIndentation); - if (_startsWith) { - String _string_1 = indentation.toString(); - int _length = currentIndentation.length(); - String trimmedIndentation = _string_1.substring(_length); - DefaultIndentationHandler.SemanticIndentationData _semanticIndentationData_1 = new DefaultIndentationHandler.SemanticIndentationData(trimmedIndentation); - this.indentationData.add(_semanticIndentationData_1); - } else { - LinkedList newIndentationData = Lists.newLinkedList(); - DefaultIndentationHandler.SemanticIndentationData _semanticIndentationData_2 = new DefaultIndentationHandler.SemanticIndentationData(indentation); - newIndentationData.add(_semanticIndentationData_2); - this.indentationDataStack.add(newIndentationData); - this.indentationData = newIndentationData; - } - } - } - - @Override - public CharSequence getTotalSemanticIndentation() { - StringBuilder result = new StringBuilder(); - for (final DefaultIndentationHandler.IndentationData data : this.indentationData) { - if ((data instanceof DefaultIndentationHandler.SemanticIndentationData)) { - result.append(((DefaultIndentationHandler.SemanticIndentationData)data).value); - } - } - return result.toString(); - } - - @Override - public String getTotalIndentation() { - StringBuilder result = new StringBuilder(); - for (final DefaultIndentationHandler.IndentationData data : this.indentationData) { - result.append(data.value); - } - return result.toString(); - } - - @Override - public void accept(final IRichStringPartAcceptor acceptor) { - for (final DefaultIndentationHandler.IndentationData data : this.indentationData) { - data.accept(acceptor); - } - } -} +package org.jnario.xbase.richstring.util; + +import com.google.common.collect.Lists; +import java.util.LinkedList; +import org.eclipse.xtend2.lib.StringConcatenation; +import org.jnario.xbase.richstring.util.IRichStringIndentationHandler; +import org.jnario.xbase.richstring.util.IRichStringPartAcceptor; + +/** + * Default indentation handler for rich strings. Tries to be graceful with + * inconsistent indentation. + * @author Sebastian Zarnekow - Initial contribution and API + */ +@SuppressWarnings("all") +public class DefaultIndentationHandler implements IRichStringIndentationHandler { + protected static abstract class IndentationData { + protected CharSequence value; + + protected IndentationData(final CharSequence value) { + this.value = value; + } + + protected abstract void accept(final IRichStringPartAcceptor acceptor); + + @Override + public String toString() { + StringConcatenation _builder = new StringConcatenation(); + String _simpleName = this.getClass().getSimpleName(); + _builder.append(_simpleName); + _builder.append(" ["); + _builder.append(this.value); + _builder.append("]"); + return _builder.toString(); + } + } + + protected static class SemanticIndentationData extends DefaultIndentationHandler.IndentationData { + protected SemanticIndentationData(final CharSequence value) { + super(value); + } + + @Override + protected void accept(final IRichStringPartAcceptor acceptor) { + acceptor.acceptSemanticText(this.value, null); + } + } + + protected static class TemplateIndentationData extends DefaultIndentationHandler.IndentationData { + protected TemplateIndentationData(final CharSequence value) { + super(value); + } + + @Override + protected void accept(final IRichStringPartAcceptor acceptor) { + acceptor.acceptTemplateText(this.value, null); + } + } + + private LinkedList indentationData; + + private LinkedList> indentationDataStack; + + public DefaultIndentationHandler() { + this.indentationData = Lists.newLinkedList(); + this.indentationDataStack = Lists.>newLinkedList(); + this.indentationDataStack.add(this.indentationData); + } + + @Override + public void popIndentation() { + this.indentationData.removeLast(); + if ((this.indentationData.isEmpty() && (this.indentationDataStack.size() > 1))) { + this.indentationDataStack.removeLast(); + this.indentationData = this.indentationDataStack.getLast(); + } + } + + @Override + public void pushTemplateIndentation(final CharSequence indentation) { + boolean _isEmpty = this.indentationData.isEmpty(); + if (_isEmpty) { + DefaultIndentationHandler.TemplateIndentationData _templateIndentationData = new DefaultIndentationHandler.TemplateIndentationData(indentation); + this.indentationData.add(_templateIndentationData); + } else { + String currentIndentation = this.getTotalIndentation(); + boolean _startsWith = indentation.toString().startsWith(currentIndentation); + if (_startsWith) { + String trimmedIndentation = indentation.toString().substring(currentIndentation.length()); + DefaultIndentationHandler.TemplateIndentationData _templateIndentationData_1 = new DefaultIndentationHandler.TemplateIndentationData(trimmedIndentation); + this.indentationData.add(_templateIndentationData_1); + } else { + LinkedList newIndentationData = Lists.newLinkedList(); + DefaultIndentationHandler.TemplateIndentationData _templateIndentationData_2 = new DefaultIndentationHandler.TemplateIndentationData(indentation); + newIndentationData.add(_templateIndentationData_2); + this.indentationDataStack.add(newIndentationData); + this.indentationData = newIndentationData; + } + } + } + + @Override + public void pushSemanticIndentation(final CharSequence indentation) { + boolean _isEmpty = this.indentationData.isEmpty(); + if (_isEmpty) { + DefaultIndentationHandler.SemanticIndentationData _semanticIndentationData = new DefaultIndentationHandler.SemanticIndentationData(indentation); + this.indentationData.add(_semanticIndentationData); + } else { + String currentIndentation = this.getTotalIndentation(); + boolean _startsWith = indentation.toString().startsWith(currentIndentation); + if (_startsWith) { + String trimmedIndentation = indentation.toString().substring(currentIndentation.length()); + DefaultIndentationHandler.SemanticIndentationData _semanticIndentationData_1 = new DefaultIndentationHandler.SemanticIndentationData(trimmedIndentation); + this.indentationData.add(_semanticIndentationData_1); + } else { + LinkedList newIndentationData = Lists.newLinkedList(); + DefaultIndentationHandler.SemanticIndentationData _semanticIndentationData_2 = new DefaultIndentationHandler.SemanticIndentationData(indentation); + newIndentationData.add(_semanticIndentationData_2); + this.indentationDataStack.add(newIndentationData); + this.indentationData = newIndentationData; + } + } + } + + @Override + public CharSequence getTotalSemanticIndentation() { + StringBuilder result = new StringBuilder(); + for (final DefaultIndentationHandler.IndentationData data : this.indentationData) { + if ((data instanceof DefaultIndentationHandler.SemanticIndentationData)) { + result.append(((DefaultIndentationHandler.SemanticIndentationData)data).value); + } + } + return result.toString(); + } + + @Override + public String getTotalIndentation() { + StringBuilder result = new StringBuilder(); + for (final DefaultIndentationHandler.IndentationData data : this.indentationData) { + result.append(data.value); + } + return result.toString(); + } + + @Override + public void accept(final IRichStringPartAcceptor acceptor) { + for (final DefaultIndentationHandler.IndentationData data : this.indentationData) { + data.accept(acceptor); + } + } +} diff --git a/plugins/org.jnario.xbase.richstring/xtend-gen/org/jnario/xbase/richstring/util/XbaseWithRichstringExpressionHelper.java b/plugins/org.jnario.xbase.richstring/xtend-gen/org/jnario/xbase/richstring/util/XbaseWithRichstringExpressionHelper.java index 68355402b..345914af3 100644 --- a/plugins/org.jnario.xbase.richstring/xtend-gen/org/jnario/xbase/richstring/util/XbaseWithRichstringExpressionHelper.java +++ b/plugins/org.jnario.xbase.richstring/xtend-gen/org/jnario/xbase/richstring/util/XbaseWithRichstringExpressionHelper.java @@ -1,32 +1,32 @@ -package org.jnario.xbase.richstring.util; - -import org.eclipse.xtext.xbase.XBooleanLiteral; -import org.eclipse.xtext.xbase.XClosure; -import org.eclipse.xtext.xbase.XExpression; -import org.eclipse.xtext.xbase.XNullLiteral; -import org.eclipse.xtext.xbase.XNumberLiteral; -import org.eclipse.xtext.xbase.XStringLiteral; -import org.eclipse.xtext.xbase.XTypeLiteral; -import org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation; -import org.eclipse.xtext.xbase.util.XExpressionHelper; -import org.jnario.xbase.richstring.xbasewithrichstring.RichString; -import org.jnario.xbase.richstring.xbasewithrichstring.RichStringIf; - -@SuppressWarnings("all") -public class XbaseWithRichstringExpressionHelper extends XExpressionHelper { - @Override - public boolean hasSideEffects(final XExpression expr) { - boolean _xblockexpression = false; - { - if ((expr instanceof RichString)) { - return false; - } - _xblockexpression = super.hasSideEffects(expr); - } - return _xblockexpression; - } - - public boolean isLiteral(final XExpression expr) { - return ((((((((expr instanceof XClosure) || (expr instanceof XStringLiteral)) || (expr instanceof XTypeLiteral)) || (expr instanceof XBooleanLiteral)) || (expr instanceof XNumberLiteral)) || (expr instanceof XNullLiteral)) || (expr instanceof XAnnotation)) || (expr instanceof RichStringIf)); - } -} +package org.jnario.xbase.richstring.util; + +import org.eclipse.xtext.xbase.XBooleanLiteral; +import org.eclipse.xtext.xbase.XClosure; +import org.eclipse.xtext.xbase.XExpression; +import org.eclipse.xtext.xbase.XNullLiteral; +import org.eclipse.xtext.xbase.XNumberLiteral; +import org.eclipse.xtext.xbase.XStringLiteral; +import org.eclipse.xtext.xbase.XTypeLiteral; +import org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation; +import org.eclipse.xtext.xbase.util.XExpressionHelper; +import org.jnario.xbase.richstring.xbasewithrichstring.RichString; +import org.jnario.xbase.richstring.xbasewithrichstring.RichStringIf; + +@SuppressWarnings("all") +public class XbaseWithRichstringExpressionHelper extends XExpressionHelper { + @Override + public boolean hasSideEffects(final XExpression expr) { + boolean _xblockexpression = false; + { + if ((expr instanceof RichString)) { + return false; + } + _xblockexpression = super.hasSideEffects(expr); + } + return _xblockexpression; + } + + public boolean isLiteral(final XExpression expr) { + return ((((((((expr instanceof XClosure) || (expr instanceof XStringLiteral)) || (expr instanceof XTypeLiteral)) || (expr instanceof XBooleanLiteral)) || (expr instanceof XNumberLiteral)) || (expr instanceof XNullLiteral)) || (expr instanceof XAnnotation)) || (expr instanceof RichStringIf)); + } +} diff --git a/plugins/org.jnario/xtend-gen/org/jnario/compiler/AlternateJdkLoader.java b/plugins/org.jnario/xtend-gen/org/jnario/compiler/AlternateJdkLoader.java index 3f0c2dafe..d59fd998f 100644 --- a/plugins/org.jnario/xtend-gen/org/jnario/compiler/AlternateJdkLoader.java +++ b/plugins/org.jnario/xtend-gen/org/jnario/compiler/AlternateJdkLoader.java @@ -1,88 +1,88 @@ -/** - * Copyright (c) 2014 itemis AG (http://www.itemis.eu) and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.jnario.compiler; - -import com.google.common.collect.Maps; -import java.io.File; -import java.io.IOException; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.Enumeration; -import java.util.concurrent.ConcurrentMap; -import org.eclipse.xtext.xbase.lib.Conversions; -import org.eclipse.xtext.xbase.lib.Exceptions; -import org.eclipse.xtext.xbase.lib.Functions.Function1; -import org.eclipse.xtext.xbase.lib.IterableExtensions; - -/** - * Copy of the Xtend AlternateJdkLoader-class - */ -@SuppressWarnings("all") -public class AlternateJdkLoader extends URLClassLoader { - private final ConcurrentMap locks = Maps.newConcurrentMap(); - - public AlternateJdkLoader(final Iterable files) { - super(((URL[])Conversions.unwrapArray(IterableExtensions.map(files, new Function1() { - @Override - public URL apply(final File it) { - try { - return it.toURL(); - } catch (Throwable _e) { - throw Exceptions.sneakyThrow(_e); - } - } - }), URL.class))); - } - - @Override - protected Class loadClass(final String name, final boolean resolve) throws ClassNotFoundException { - Class _xsynchronizedexpression = null; - synchronized (this.getClassLoadingLockJdk5(name)) { - Class _xblockexpression = null; - { - Class _elvis = null; - Class _findLoadedClass = this.findLoadedClass(name); - if (_findLoadedClass != null) { - _elvis = _findLoadedClass; - } else { - Class _findClass = this.findClass(name); - _elvis = _findClass; - } - final Class c = _elvis; - if (resolve) { - this.resolveClass(c); - } - _xblockexpression = c; - } - _xsynchronizedexpression = _xblockexpression; - } - return _xsynchronizedexpression; - } - - @Override - public URL getResource(final String name) { - return this.findResource(name); - } - - @Override - public Enumeration getResources(final String name) throws IOException { - return this.findResources(name); - } - - private Object getClassLoadingLockJdk5(final String className) { - final Object newLock = new Object(); - final Object existingLock = this.locks.putIfAbsent(className, newLock); - Object _elvis = null; - if (existingLock != null) { - _elvis = existingLock; - } else { - _elvis = newLock; - } - return _elvis; - } -} +/** + * Copyright (c) 2014 itemis AG (http://www.itemis.eu) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.jnario.compiler; + +import com.google.common.collect.Maps; +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.Enumeration; +import java.util.concurrent.ConcurrentMap; +import org.eclipse.xtext.xbase.lib.Conversions; +import org.eclipse.xtext.xbase.lib.Exceptions; +import org.eclipse.xtext.xbase.lib.Functions.Function1; +import org.eclipse.xtext.xbase.lib.IterableExtensions; + +/** + * Copy of the Xtend AlternateJdkLoader-class + */ +@SuppressWarnings("all") +public class AlternateJdkLoader extends URLClassLoader { + private final ConcurrentMap locks = Maps.newConcurrentMap(); + + public AlternateJdkLoader(final Iterable files) { + super(((URL[])Conversions.unwrapArray(IterableExtensions.map(files, new Function1() { + @Override + public URL apply(final File it) { + try { + return it.toURL(); + } catch (Throwable _e) { + throw Exceptions.sneakyThrow(_e); + } + } + }), URL.class))); + } + + @Override + protected Class loadClass(final String name, final boolean resolve) throws ClassNotFoundException { + Class _xsynchronizedexpression = null; + synchronized (this.getClassLoadingLockJdk5(name)) { + Class _xblockexpression = null; + { + Class _elvis = null; + Class _findLoadedClass = this.findLoadedClass(name); + if (_findLoadedClass != null) { + _elvis = _findLoadedClass; + } else { + Class _findClass = this.findClass(name); + _elvis = _findClass; + } + final Class c = _elvis; + if (resolve) { + this.resolveClass(c); + } + _xblockexpression = c; + } + _xsynchronizedexpression = _xblockexpression; + } + return _xsynchronizedexpression; + } + + @Override + public URL getResource(final String name) { + return this.findResource(name); + } + + @Override + public Enumeration getResources(final String name) throws IOException { + return this.findResources(name); + } + + private Object getClassLoadingLockJdk5(final String className) { + final Object newLock = new Object(); + final Object existingLock = this.locks.putIfAbsent(className, newLock); + Object _elvis = null; + if (existingLock != null) { + _elvis = existingLock; + } else { + _elvis = newLock; + } + return _elvis; + } +} diff --git a/plugins/org.jnario/xtend-gen/org/jnario/compiler/HtmlAssetsCompiler.java b/plugins/org.jnario/xtend-gen/org/jnario/compiler/HtmlAssetsCompiler.java index bf5173a3f..a126f7de6 100644 --- a/plugins/org.jnario/xtend-gen/org/jnario/compiler/HtmlAssetsCompiler.java +++ b/plugins/org.jnario/xtend-gen/org/jnario/compiler/HtmlAssetsCompiler.java @@ -1,32 +1,32 @@ -/** - * Copyright (c) 2012 BMW Car IT and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.jnario.compiler; - -import com.google.inject.Inject; -import com.google.inject.Provider; -import org.eclipse.xtext.generator.JavaIoFileSystemAccess; -import org.jnario.compiler.JnarioDocCompiler; -import org.jnario.doc.DocOutputConfigurationProvider; -import org.jnario.doc.HtmlAssets; - -@SuppressWarnings("all") -public class HtmlAssetsCompiler extends JnarioDocCompiler { - @Inject - private Provider filesystemAccessProvider; - - @Inject - private HtmlAssets htmlAssets; - - @Override - public boolean compile() { - final JavaIoFileSystemAccess fsa = this.filesystemAccessProvider.get(); - fsa.setOutputPath(DocOutputConfigurationProvider.ASSET_OUTPUT, this.outputPath); - this.htmlAssets.generate(fsa); - return true; - } -} +/** + * Copyright (c) 2012 BMW Car IT and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.jnario.compiler; + +import com.google.inject.Inject; +import com.google.inject.Provider; +import org.eclipse.xtext.generator.JavaIoFileSystemAccess; +import org.jnario.compiler.JnarioDocCompiler; +import org.jnario.doc.DocOutputConfigurationProvider; +import org.jnario.doc.HtmlAssets; + +@SuppressWarnings("all") +public class HtmlAssetsCompiler extends JnarioDocCompiler { + @Inject + private Provider filesystemAccessProvider; + + @Inject + private HtmlAssets htmlAssets; + + @Override + public boolean compile() { + final JavaIoFileSystemAccess fsa = this.filesystemAccessProvider.get(); + fsa.setOutputPath(DocOutputConfigurationProvider.ASSET_OUTPUT, this.outputPath); + this.htmlAssets.generate(fsa); + return true; + } +} diff --git a/plugins/org.jnario/xtend-gen/org/jnario/compiler/JnarioDocCompiler.java b/plugins/org.jnario/xtend-gen/org/jnario/compiler/JnarioDocCompiler.java index c661e4168..338a483ab 100644 --- a/plugins/org.jnario/xtend-gen/org/jnario/compiler/JnarioDocCompiler.java +++ b/plugins/org.jnario/xtend-gen/org/jnario/compiler/JnarioDocCompiler.java @@ -1,115 +1,105 @@ -/** - * Copyright (c) 2012 BMW Car IT and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.jnario.compiler; - -import com.google.common.base.Predicate; -import com.google.inject.Inject; -import java.io.File; -import java.util.List; -import java.util.Map; -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.common.util.URI; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.emf.ecore.resource.ResourceSet; -import org.eclipse.emf.ecore.util.EcoreUtil; -import org.eclipse.xtend.lib.Property; -import org.eclipse.xtext.generator.JavaIoFileSystemAccess; -import org.eclipse.xtext.mwe.NameBasedFilter; -import org.eclipse.xtext.mwe.PathTraverser; -import org.eclipse.xtext.parser.IEncodingProvider; -import org.eclipse.xtext.resource.XtextResource; -import org.eclipse.xtext.xbase.lib.Pure; -import org.jnario.compiler.AbstractBatchCompiler; -import org.jnario.doc.AbstractDocGenerator; -import org.jnario.doc.DocOutputConfigurationProvider; -import org.jnario.report.Executable2ResultMapping; - -@SuppressWarnings("all") -public class JnarioDocCompiler extends AbstractBatchCompiler { - private Executable2ResultMapping resultMapping; - - @Property - private String _resultFolder; - - @Inject - private AbstractDocGenerator docGenerator; - - @Inject - private IEncodingProvider.Runtime encodingProvider; - - private ResourceSet resourceSet; - - @Override - public boolean compile() { - this.loadResources(); - this.generateDocumentation(this.resultMapping); - return true; - } - - @Inject - public Executable2ResultMapping setExecutable2ResultMapping(final Executable2ResultMapping resultMapping) { - return this.resultMapping = resultMapping; - } - - public ResourceSet loadResources() { - ResourceSet _xblockexpression = null; - { - ResourceSet _get = this.resourceSetProvider.get(); - this.resourceSet = _get; - String _fileEncoding = this.getFileEncoding(); - this.encodingProvider.setDefaultEncoding(_fileEncoding); - Map _loadOptions = this.resourceSet.getLoadOptions(); - String _fileEncoding_1 = this.getFileEncoding(); - _loadOptions.put(XtextResource.OPTION_ENCODING, _fileEncoding_1); - final NameBasedFilter nameBasedFilter = new NameBasedFilter(); - String _primaryFileExtension = this.fileExtensionProvider.getPrimaryFileExtension(); - nameBasedFilter.setExtension(_primaryFileExtension); - final PathTraverser pathTraverser = new PathTraverser(); - List _sourcePathDirectories = this.getSourcePathDirectories(); - final Predicate _function = new Predicate() { - @Override - public boolean apply(final URI input) { - final boolean matches = nameBasedFilter.matches(input); - if (matches) { - JnarioDocCompiler.this.resourceSet.getResource(input, true); - } - return matches; - } - }; - pathTraverser.resolvePathes(_sourcePathDirectories, _function); - final File classDirectory = this.createTempDir("classes"); - this.installJvmTypeProvider(this.resourceSet, classDirectory); - EcoreUtil.resolveAll(this.resourceSet); - _xblockexpression = this.resourceSet; - } - return _xblockexpression; - } - - public void generateDocumentation(final Executable2ResultMapping executable2ResultMapping) { - final JavaIoFileSystemAccess javaIoFileSystemAccess = this.javaIoFileSystemAccessProvider.get(); - javaIoFileSystemAccess.setOutputPath(DocOutputConfigurationProvider.DOC_OUTPUT, this.outputPath); - EList _resources = this.resourceSet.getResources(); - for (final Resource r : _resources) { - URI _uRI = r.getURI(); - String _fileExtension = _uRI.fileExtension(); - boolean _isValid = this.fileExtensionProvider.isValid(_fileExtension); - if (_isValid) { - this.docGenerator.doGenerate(r, javaIoFileSystemAccess, executable2ResultMapping); - } - } - } - - @Pure - public String getResultFolder() { - return this._resultFolder; - } - - public void setResultFolder(final String resultFolder) { - this._resultFolder = resultFolder; - } -} +/** + * Copyright (c) 2012 BMW Car IT and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.jnario.compiler; + +import com.google.common.base.Predicate; +import com.google.inject.Inject; +import java.io.File; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.emf.ecore.util.EcoreUtil; +import org.eclipse.xtend.lib.Property; +import org.eclipse.xtext.generator.JavaIoFileSystemAccess; +import org.eclipse.xtext.mwe.NameBasedFilter; +import org.eclipse.xtext.mwe.PathTraverser; +import org.eclipse.xtext.parser.IEncodingProvider; +import org.eclipse.xtext.resource.XtextResource; +import org.eclipse.xtext.xbase.lib.Pure; +import org.jnario.compiler.AbstractBatchCompiler; +import org.jnario.doc.AbstractDocGenerator; +import org.jnario.doc.DocOutputConfigurationProvider; +import org.jnario.report.Executable2ResultMapping; + +@SuppressWarnings("all") +public class JnarioDocCompiler extends AbstractBatchCompiler { + private Executable2ResultMapping resultMapping; + + @Property + private String _resultFolder; + + @Inject + private AbstractDocGenerator docGenerator; + + @Inject + private IEncodingProvider.Runtime encodingProvider; + + private ResourceSet resourceSet; + + @Override + public boolean compile() { + this.loadResources(); + this.generateDocumentation(this.resultMapping); + return true; + } + + @Inject + public Executable2ResultMapping setExecutable2ResultMapping(final Executable2ResultMapping resultMapping) { + return this.resultMapping = resultMapping; + } + + public ResourceSet loadResources() { + ResourceSet _xblockexpression = null; + { + this.resourceSet = this.resourceSetProvider.get(); + this.encodingProvider.setDefaultEncoding(this.getFileEncoding()); + this.resourceSet.getLoadOptions().put(XtextResource.OPTION_ENCODING, this.getFileEncoding()); + final NameBasedFilter nameBasedFilter = new NameBasedFilter(); + nameBasedFilter.setExtension(this.fileExtensionProvider.getPrimaryFileExtension()); + final PathTraverser pathTraverser = new PathTraverser(); + final Predicate _function = new Predicate() { + @Override + public boolean apply(final URI input) { + final boolean matches = nameBasedFilter.matches(input); + if (matches) { + JnarioDocCompiler.this.resourceSet.getResource(input, true); + } + return matches; + } + }; + pathTraverser.resolvePathes(this.getSourcePathDirectories(), _function); + final File classDirectory = this.createTempDir("classes"); + this.installJvmTypeProvider(this.resourceSet, classDirectory); + EcoreUtil.resolveAll(this.resourceSet); + _xblockexpression = this.resourceSet; + } + return _xblockexpression; + } + + public void generateDocumentation(final Executable2ResultMapping executable2ResultMapping) { + final JavaIoFileSystemAccess javaIoFileSystemAccess = this.javaIoFileSystemAccessProvider.get(); + javaIoFileSystemAccess.setOutputPath(DocOutputConfigurationProvider.DOC_OUTPUT, this.outputPath); + EList _resources = this.resourceSet.getResources(); + for (final Resource r : _resources) { + boolean _isValid = this.fileExtensionProvider.isValid(r.getURI().fileExtension()); + if (_isValid) { + this.docGenerator.doGenerate(r, javaIoFileSystemAccess, executable2ResultMapping); + } + } + } + + @Pure + public String getResultFolder() { + return this._resultFolder; + } + + public void setResultFolder(final String resultFolder) { + this._resultFolder = resultFolder; + } +} diff --git a/plugins/org.jnario/xtend-gen/org/jnario/compiler/ProcessorInstanceForJvmTypeProvider.java b/plugins/org.jnario/xtend-gen/org/jnario/compiler/ProcessorInstanceForJvmTypeProvider.java index fde0e625e..2ee5a1af2 100644 --- a/plugins/org.jnario/xtend-gen/org/jnario/compiler/ProcessorInstanceForJvmTypeProvider.java +++ b/plugins/org.jnario/xtend-gen/org/jnario/compiler/ProcessorInstanceForJvmTypeProvider.java @@ -1,170 +1,163 @@ -package org.jnario.compiler; - -import com.google.common.base.Objects; -import com.google.common.collect.Iterables; -import java.io.Closeable; -import java.io.IOException; -import java.net.URL; -import java.net.URLClassLoader; -import org.apache.log4j.Logger; -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.emf.common.notify.Notifier; -import org.eclipse.emf.common.notify.impl.AdapterImpl; -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.emf.ecore.resource.ResourceSet; -import org.eclipse.xtend.lib.annotations.Accessors; -import org.eclipse.xtend.lib.macro.TransformationContext; -import org.eclipse.xtext.common.types.JvmType; -import org.eclipse.xtext.resource.XtextResourceSet; -import org.eclipse.xtext.xbase.lib.Exceptions; -import org.eclipse.xtext.xbase.lib.IterableExtensions; -import org.eclipse.xtext.xbase.lib.Pure; - -@SuppressWarnings("all") -public class ProcessorInstanceForJvmTypeProvider { - @Accessors - public static class ProcessorClassloaderAdapter extends AdapterImpl { - private ClassLoader classLoader; - - public ProcessorClassloaderAdapter(final ClassLoader classLoader) { - this.classLoader = classLoader; - } - - @Override - public boolean isAdapterForType(final Object type) { - return Objects.equal(type, ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter.class); - } - - @Override - public void unsetTarget(final Notifier oldTarget) { - this.discard(); - } - - @Override - public void setTarget(final Notifier newTarget) { - boolean _equals = Objects.equal(newTarget, null); - if (_equals) { - this.discard(); - } - } - - public ClassLoader discard() { - ClassLoader _xifexpression = null; - if ((this.classLoader instanceof Closeable)) { - ClassLoader _xtrycatchfinallyexpression = null; - try { - ClassLoader _xblockexpression = null; - { - ((Closeable) this.classLoader).close(); - _xblockexpression = this.classLoader = null; - } - _xtrycatchfinallyexpression = _xblockexpression; - } catch (final Throwable _t) { - if (_t instanceof IOException) { - final IOException e = (IOException)_t; - String _message = e.getMessage(); - ProcessorInstanceForJvmTypeProvider.logger.error(_message, e); - } else { - throw Exceptions.sneakyThrow(_t); - } - } - _xifexpression = _xtrycatchfinallyexpression; - } - return _xifexpression; - } - - @Pure - public ClassLoader getClassLoader() { - return this.classLoader; - } - - public void setClassLoader(final ClassLoader classLoader) { - this.classLoader = classLoader; - } - } - - private final static Logger logger = Logger.getLogger(ProcessorInstanceForJvmTypeProvider.class); - - /** - * @return an instance of the given JvmType - */ - public Object getProcessorInstance(final JvmType type) { - try { - ClassLoader _classLoader = this.getClassLoader(type); - Class _loadClass = null; - if (_classLoader!=null) { - String _identifier = type.getIdentifier(); - _loadClass=_classLoader.loadClass(_identifier); - } - final Class loadClass = _loadClass; - Object _newInstance = null; - if (loadClass!=null) { - _newInstance=loadClass.newInstance(); - } - return _newInstance; - } catch (final Throwable _t) { - if (_t instanceof Exception) { - final Exception e = (Exception)_t; - String _identifier_1 = type.getIdentifier(); - String _plus = ("Problem during instantiation of " + _identifier_1); - String _plus_1 = (_plus + " : "); - String _message = e.getMessage(); - String _plus_2 = (_plus_1 + _message); - throw new IllegalStateException(_plus_2, e); - } else { - throw Exceptions.sneakyThrow(_t); - } - } - } - - protected ClassLoader getClassLoader(final EObject ctx) { - Resource _eResource = ctx.eResource(); - final ResourceSet resourceSet = _eResource.getResourceSet(); - EList _eAdapters = resourceSet.eAdapters(); - Iterable _filter = Iterables.filter(_eAdapters, ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter.class); - final ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter adapter = IterableExtensions.head(_filter); - boolean _notEquals = (!Objects.equal(adapter, null)); - if (_notEquals) { - return adapter.getClassLoader(); - } - boolean _matched = false; - if (resourceSet instanceof XtextResourceSet) { - _matched=true; - final Object classLoaderCtx = ((XtextResourceSet)resourceSet).getClasspathURIContext(); - ClassLoader _switchResult_1 = null; - boolean _matched_1 = false; - if (classLoaderCtx instanceof ClassLoader) { - _matched_1=true; - _switchResult_1 = ((ClassLoader)classLoaderCtx); - } - if (!_matched_1) { - if (classLoaderCtx instanceof Class) { - _matched_1=true; - _switchResult_1 = ((Class)classLoaderCtx).getClassLoader(); - } - } - final ClassLoader jvmTypeLoader = _switchResult_1; - ClassLoader _xifexpression = null; - if ((jvmTypeLoader instanceof URLClassLoader)) { - URL[] _uRLs = ((URLClassLoader)jvmTypeLoader).getURLs(); - ClassLoader _classLoader = TransformationContext.class.getClassLoader(); - _xifexpression = new URLClassLoader(_uRLs, _classLoader); - } else { - _xifexpression = jvmTypeLoader; - } - final ClassLoader processorClassLoader = _xifexpression; - boolean _notEquals_1 = (!Objects.equal(processorClassLoader, null)); - if (_notEquals_1) { - EList _eAdapters_1 = ((XtextResourceSet)resourceSet).eAdapters(); - ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter _processorClassloaderAdapter = new ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter(processorClassLoader); - _eAdapters_1.add(_processorClassloaderAdapter); - return processorClassLoader; - } - } - ProcessorInstanceForJvmTypeProvider.logger.info("No class loader configured. Trying with this class classloader."); - Class _class = this.getClass(); - return _class.getClassLoader(); - } -} +package org.jnario.compiler; + +import com.google.common.base.Objects; +import com.google.common.collect.Iterables; +import java.io.Closeable; +import java.io.IOException; +import java.net.URL; +import java.net.URLClassLoader; +import org.apache.log4j.Logger; +import org.eclipse.emf.common.notify.Adapter; +import org.eclipse.emf.common.notify.Notifier; +import org.eclipse.emf.common.notify.impl.AdapterImpl; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.xtend.lib.annotations.Accessors; +import org.eclipse.xtend.lib.macro.TransformationContext; +import org.eclipse.xtext.common.types.JvmType; +import org.eclipse.xtext.resource.XtextResourceSet; +import org.eclipse.xtext.xbase.lib.Exceptions; +import org.eclipse.xtext.xbase.lib.IterableExtensions; +import org.eclipse.xtext.xbase.lib.Pure; + +@SuppressWarnings("all") +public class ProcessorInstanceForJvmTypeProvider { + @Accessors + public static class ProcessorClassloaderAdapter extends AdapterImpl { + private ClassLoader classLoader; + + public ProcessorClassloaderAdapter(final ClassLoader classLoader) { + this.classLoader = classLoader; + } + + @Override + public boolean isAdapterForType(final Object type) { + return Objects.equal(type, ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter.class); + } + + @Override + public void unsetTarget(final Notifier oldTarget) { + this.discard(); + } + + @Override + public void setTarget(final Notifier newTarget) { + boolean _equals = Objects.equal(newTarget, null); + if (_equals) { + this.discard(); + } + } + + public ClassLoader discard() { + ClassLoader _xifexpression = null; + if ((this.classLoader instanceof Closeable)) { + ClassLoader _xtrycatchfinallyexpression = null; + try { + ClassLoader _xblockexpression = null; + { + ((Closeable) this.classLoader).close(); + _xblockexpression = this.classLoader = null; + } + _xtrycatchfinallyexpression = _xblockexpression; + } catch (final Throwable _t) { + if (_t instanceof IOException) { + final IOException e = (IOException)_t; + ProcessorInstanceForJvmTypeProvider.logger.error(e.getMessage(), e); + } else { + throw Exceptions.sneakyThrow(_t); + } + } + _xifexpression = _xtrycatchfinallyexpression; + } + return _xifexpression; + } + + @Pure + public ClassLoader getClassLoader() { + return this.classLoader; + } + + public void setClassLoader(final ClassLoader classLoader) { + this.classLoader = classLoader; + } + } + + private final static Logger logger = Logger.getLogger(ProcessorInstanceForJvmTypeProvider.class); + + /** + * @return an instance of the given JvmType + */ + public Object getProcessorInstance(final JvmType type) { + try { + ClassLoader _classLoader = this.getClassLoader(type); + Class _loadClass = null; + if (_classLoader!=null) { + _loadClass=_classLoader.loadClass(type.getIdentifier()); + } + final Class loadClass = _loadClass; + Object _newInstance = null; + if (loadClass!=null) { + _newInstance=loadClass.newInstance(); + } + return _newInstance; + } catch (final Throwable _t) { + if (_t instanceof Exception) { + final Exception e = (Exception)_t; + String _identifier = type.getIdentifier(); + String _plus = ("Problem during instantiation of " + _identifier); + String _plus_1 = (_plus + " : "); + String _message = e.getMessage(); + String _plus_2 = (_plus_1 + _message); + throw new IllegalStateException(_plus_2, e); + } else { + throw Exceptions.sneakyThrow(_t); + } + } + } + + protected ClassLoader getClassLoader(final EObject ctx) { + final ResourceSet resourceSet = ctx.eResource().getResourceSet(); + final ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter adapter = IterableExtensions.head(Iterables.filter(resourceSet.eAdapters(), ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter.class)); + boolean _notEquals = (!Objects.equal(adapter, null)); + if (_notEquals) { + return adapter.getClassLoader(); + } + boolean _matched = false; + if (resourceSet instanceof XtextResourceSet) { + _matched=true; + final Object classLoaderCtx = ((XtextResourceSet)resourceSet).getClasspathURIContext(); + ClassLoader _switchResult_1 = null; + boolean _matched_1 = false; + if (classLoaderCtx instanceof ClassLoader) { + _matched_1=true; + _switchResult_1 = ((ClassLoader)classLoaderCtx); + } + if (!_matched_1) { + if (classLoaderCtx instanceof Class) { + _matched_1=true; + _switchResult_1 = ((Class)classLoaderCtx).getClassLoader(); + } + } + final ClassLoader jvmTypeLoader = _switchResult_1; + ClassLoader _xifexpression = null; + if ((jvmTypeLoader instanceof URLClassLoader)) { + URL[] _uRLs = ((URLClassLoader)jvmTypeLoader).getURLs(); + ClassLoader _classLoader = TransformationContext.class.getClassLoader(); + _xifexpression = new URLClassLoader(_uRLs, _classLoader); + } else { + _xifexpression = jvmTypeLoader; + } + final ClassLoader processorClassLoader = _xifexpression; + boolean _notEquals_1 = (!Objects.equal(processorClassLoader, null)); + if (_notEquals_1) { + EList _eAdapters = ((XtextResourceSet)resourceSet).eAdapters(); + ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter _processorClassloaderAdapter = new ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter(processorClassLoader); + _eAdapters.add(_processorClassloaderAdapter); + return processorClassLoader; + } + } + ProcessorInstanceForJvmTypeProvider.logger.info("No class loader configured. Trying with this class classloader."); + return this.getClass().getClassLoader(); + } +} diff --git a/plugins/org.jnario/xtend-gen/org/jnario/doc/AbstractDocGenerator.java b/plugins/org.jnario/xtend-gen/org/jnario/doc/AbstractDocGenerator.java index 1ace5ecfe..3df0e8f98 100644 --- a/plugins/org.jnario/xtend-gen/org/jnario/doc/AbstractDocGenerator.java +++ b/plugins/org.jnario/xtend-gen/org/jnario/doc/AbstractDocGenerator.java @@ -1,368 +1,337 @@ -/** - * Copyright (c) 2012 BMW Car IT and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.jnario.doc; - -import com.google.common.base.Objects; -import com.google.common.collect.Iterables; -import com.google.inject.Inject; -import java.util.Arrays; -import java.util.List; -import java.util.function.Consumer; -import org.apache.commons.lang.StringEscapeUtils; -import org.apache.log4j.Logger; -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.common.util.URI; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.xtend2.lib.StringConcatenation; -import org.eclipse.xtext.EcoreUtil2; -import org.eclipse.xtext.generator.IFileSystemAccess; -import org.eclipse.xtext.generator.IGenerator; -import org.eclipse.xtext.nodemodel.ICompositeNode; -import org.eclipse.xtext.nodemodel.util.NodeModelUtils; -import org.eclipse.xtext.util.Strings; -import org.eclipse.xtext.xbase.XBlockExpression; -import org.eclipse.xtext.xbase.XExpression; -import org.eclipse.xtext.xbase.lib.CollectionLiterals; -import org.eclipse.xtext.xbase.lib.Conversions; -import org.eclipse.xtext.xbase.lib.Exceptions; -import org.eclipse.xtext.xbase.lib.Extension; -import org.eclipse.xtext.xbase.lib.Functions.Function1; -import org.eclipse.xtext.xbase.lib.IterableExtensions; -import org.eclipse.xtext.xbase.lib.ListExtensions; -import org.jnario.ExampleCell; -import org.jnario.ExampleColumn; -import org.jnario.ExampleRow; -import org.jnario.ExampleTable; -import org.jnario.Executable; -import org.jnario.JnarioClass; -import org.jnario.JnarioFile; -import org.jnario.JnarioTypeDeclaration; -import org.jnario.doc.CssClassProvider; -import org.jnario.doc.DocumentationProvider; -import org.jnario.doc.ErrorMessageProvider; -import org.jnario.doc.Filter; -import org.jnario.doc.HtmlFile; -import org.jnario.doc.HtmlFileBuilder; -import org.jnario.doc.IconProvider; -import org.jnario.doc.WhiteSpaceNormalizer; -import org.jnario.report.Executable2ResultMapping; -import org.jnario.report.SpecExecution; -import org.pegdown.PegDownProcessor; - -@SuppressWarnings("all") -public abstract class AbstractDocGenerator implements IGenerator { - private final static Logger LOG = Logger.getLogger(AbstractDocGenerator.class); - - private final static String SEP = "_"; - - @Inject - @Extension - private WhiteSpaceNormalizer _whiteSpaceNormalizer; - - @Inject - @Extension - private PegDownProcessor _pegDownProcessor; - - @Inject - @Extension - private HtmlFileBuilder _htmlFileBuilder; - - @Inject - @Extension - private DocumentationProvider documentationProvider; - - @Inject - @Extension - private Executable2ResultMapping spec2ResultMapping; - - @Override - public void doGenerate(final Resource input, final IFileSystemAccess fsa) { - this.doGenerate(input, fsa, this.spec2ResultMapping); - } - - public void doGenerate(final Resource input, final IFileSystemAccess fsa, final Executable2ResultMapping spec2ResultMapping) { - this.initResultMapping(spec2ResultMapping); - EList _contents = input.getContents(); - Iterable _filter = Iterables.filter(_contents, JnarioFile.class); - final Consumer _function = new Consumer() { - @Override - public void accept(final JnarioFile it) { - EList _xtendTypes = it.getXtendTypes(); - Iterable _filter = Iterables.filter(_xtendTypes, JnarioClass.class); - final Consumer _function = new Consumer() { - @Override - public void accept(final JnarioClass it) { - HtmlFile _createHtmlFile = AbstractDocGenerator.this.createHtmlFile(it); - AbstractDocGenerator.this._htmlFileBuilder.generate(it, fsa, _createHtmlFile); - } - }; - _filter.forEach(_function); - } - }; - _filter.forEach(_function); - } - - protected Executable2ResultMapping initResultMapping(final Executable2ResultMapping spec2ResultMapping) { - return this.spec2ResultMapping = spec2ResultMapping; - } - - public HtmlFile createHtmlFile(final JnarioClass jnarioClass) { - return HtmlFile.EMPTY_FILE; - } - - protected String toTitle(final String string) { - String _decode = this.decode(string); - return Strings.toFirstUpper(_decode); - } - - protected String decode(final String string) { - try { - boolean _equals = Objects.equal(string, null); - if (_equals) { - return ""; - } else { - return Strings.convertFromJavaString(string, true); - } - } catch (final Throwable _t) { - if (_t instanceof IllegalArgumentException) { - final IllegalArgumentException e = (IllegalArgumentException)_t; - AbstractDocGenerator.LOG.error("Exception when converting string", e); - return string; - } else { - throw Exceptions.sneakyThrow(_t); - } - } - } - - protected String markdown2Html(final String string) { - String _xblockexpression = null; - { - boolean _equals = Objects.equal(string, null); - if (_equals) { - return ""; - } - String _normalize = this._whiteSpaceNormalizer.normalize(string); - final String normalized = (_normalize + "\n"); - String _markdownToHtml = this._pegDownProcessor.markdownToHtml(normalized); - String _replaceAll = _markdownToHtml.replaceAll("
    ", "
    ");
    -      _xblockexpression = _replaceAll.replaceAll("
    ", "
    "); - } - return _xblockexpression; - } - - protected String _serialize(final XExpression expr, final List filters) { - String _serialize = this.serialize(expr); - String _codeToHtml = this.codeToHtml(_serialize); - return _codeToHtml.trim(); - } - - protected String _serialize(final XBlockExpression expr, final List filters) { - String _serialize = this.serialize(expr); - String code = _serialize.trim(); - String _apply = this.apply(filters, code); - code = _apply; - int _length = code.length(); - boolean _equals = (_length == 0); - if (_equals) { - return ""; - } - int _length_1 = code.length(); - int _minus = (_length_1 - 1); - String _substring = code.substring(1, _minus); - code = _substring; - return this.codeToHtml(code); - } - - protected String codeToHtml(final String code) { - String _normalize = this._whiteSpaceNormalizer.normalize(code); - CharSequence _trimWhitespaceAtEnd = org.jnario.util.Strings.trimWhitespaceAtEnd(_normalize); - String _string = _trimWhitespaceAtEnd.toString(); - String _html = this.toHtml(_string); - return _html.replace("\t", " "); - } - - protected String toHtml(final String input) { - return StringEscapeUtils.escapeHtml(input); - } - - protected String serialize(final EObject obj) { - final ICompositeNode node = NodeModelUtils.getNode(obj); - boolean _equals = Objects.equal(node, null); - if (_equals) { - return ""; - } - return node.getText(); - } - - protected String id(final String id) { - String _replaceAll = null; - if (id!=null) { - _replaceAll=id.replaceAll("\\W+", AbstractDocGenerator.SEP); - } - String _trim = null; - if (_replaceAll!=null) { - char _charAt = AbstractDocGenerator.SEP.charAt(0); - _trim=org.jnario.util.Strings.trim(_replaceAll, _charAt); - } - String _plus = (" id=\"" + _trim); - return (_plus + "\""); - } - - protected String apply(final List filters, final String input) { - String result = input; - for (final Filter filter : filters) { - String _apply = filter.apply(result); - result = _apply; - } - return result; - } - - protected String root(final EObject jnarioClass) { - final JnarioFile specFile = EcoreUtil2.getContainerOfType(jnarioClass, JnarioFile.class); - final String packageName = specFile.getPackage(); - boolean _equals = Objects.equal(packageName, null); - if (_equals) { - return ""; - } - final String[] fragments = packageName.split("\\."); - final Function1 _function = new Function1() { - @Override - public String apply(final String s) { - return "../"; - } - }; - final List path = ListExtensions.map(((List)Conversions.doWrapArray(fragments)), _function); - return IterableExtensions.join(path, ""); - } - - protected CharSequence generate(final ExampleTable table) { - StringConcatenation _builder = new StringConcatenation(); - _builder.append(""); - _builder.newLine(); - _builder.append("\t"); - _builder.append(""); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append(""); - _builder.newLine(); - { - EList _columns = table.getColumns(); - for(final ExampleColumn headingCell : _columns) { - _builder.append("\t\t"); - _builder.append(""); - _builder.newLineIfNotEmpty(); - } - } - _builder.append("\t\t"); - _builder.append(""); - _builder.newLine(); - _builder.append("\t"); - _builder.append(""); - _builder.newLine(); - _builder.append("\t"); - _builder.append(""); - _builder.newLine(); - { - EList _rows = table.getRows(); - for(final ExampleRow row : _rows) { - _builder.append("\t"); - _builder.append(""); - _builder.newLine(); - { - EList _cells = row.getCells(); - for(final ExampleCell cell : _cells) { - _builder.append("\t"); - _builder.append("\t"); - _builder.append(""); - _builder.newLineIfNotEmpty(); - } - } - _builder.append("\t"); - _builder.append(""); - _builder.newLine(); - } - } - _builder.append("\t"); - _builder.append(""); - _builder.newLine(); - _builder.append("
    "); - String _name = headingCell.getName(); - _builder.append(_name, "\t\t"); - _builder.append("
    "); - XExpression _expression = cell.getExpression(); - List _emptyList = CollectionLiterals.emptyList(); - String _serialize = this.serialize(_expression, _emptyList); - _builder.append(_serialize, "\t\t"); - _builder.append("
    "); - _builder.newLine(); - return _builder; - } - - protected String htmlFileName(final String name) { - return this._htmlFileBuilder.toHtmlFileName(name); - } - - protected String documentation(final EObject obj) { - return this.documentationProvider.getDocumentation(obj); - } - - protected String fileName(final EObject eObject) { - Resource _eResource = eObject.eResource(); - URI _uRI = _eResource.getURI(); - return _uRI.lastSegment(); - } - - protected CharSequence pre(final EObject eObject, final String lang) { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("
    ");
    -    _builder.newLineIfNotEmpty();
    -    String _serialize = this.serialize(eObject);
    -    String _codeToHtml = this.codeToHtml(_serialize);
    -    _builder.append(_codeToHtml, "");
    -    _builder.newLineIfNotEmpty();
    -    _builder.append("
    "); - _builder.newLine(); - return _builder; - } - - protected String executionState(final Executable executable) { - String _xblockexpression = null; - { - final SpecExecution result = this.spec2ResultMapping.getResult(executable); - IconProvider _iconProvider = new IconProvider(); - _xblockexpression = _iconProvider.doSwitch(result); - } - return _xblockexpression; - } - - protected String executionStateClass(final Executable executable) { - CssClassProvider _cssClassProvider = new CssClassProvider(); - SpecExecution _result = this.spec2ResultMapping.getResult(executable); - return _cssClassProvider.doSwitch(_result); - } - - protected String errorMessage(final Executable executable) { - ErrorMessageProvider _errorMessageProvider = new ErrorMessageProvider(); - SpecExecution _result = this.spec2ResultMapping.getResult(executable); - return _errorMessageProvider.doSwitch(_result); - } - - protected String serialize(final XExpression expr, final List filters) { - if (expr instanceof XBlockExpression) { - return _serialize((XBlockExpression)expr, filters); - } else if (expr != null) { - return _serialize(expr, filters); - } else { - throw new IllegalArgumentException("Unhandled parameter types: " + - Arrays.asList(expr, filters).toString()); - } - } -} +/** + * Copyright (c) 2012 BMW Car IT and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.jnario.doc; + +import com.google.common.base.Objects; +import com.google.common.collect.Iterables; +import com.google.inject.Inject; +import java.util.Arrays; +import java.util.List; +import java.util.function.Consumer; +import org.apache.commons.lang.StringEscapeUtils; +import org.apache.log4j.Logger; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.xtend2.lib.StringConcatenation; +import org.eclipse.xtext.EcoreUtil2; +import org.eclipse.xtext.generator.IFileSystemAccess; +import org.eclipse.xtext.generator.IGenerator; +import org.eclipse.xtext.nodemodel.ICompositeNode; +import org.eclipse.xtext.nodemodel.util.NodeModelUtils; +import org.eclipse.xtext.util.Strings; +import org.eclipse.xtext.xbase.XBlockExpression; +import org.eclipse.xtext.xbase.XExpression; +import org.eclipse.xtext.xbase.lib.CollectionLiterals; +import org.eclipse.xtext.xbase.lib.Conversions; +import org.eclipse.xtext.xbase.lib.Exceptions; +import org.eclipse.xtext.xbase.lib.Extension; +import org.eclipse.xtext.xbase.lib.Functions.Function1; +import org.eclipse.xtext.xbase.lib.IterableExtensions; +import org.eclipse.xtext.xbase.lib.ListExtensions; +import org.jnario.ExampleCell; +import org.jnario.ExampleColumn; +import org.jnario.ExampleRow; +import org.jnario.ExampleTable; +import org.jnario.Executable; +import org.jnario.JnarioClass; +import org.jnario.JnarioFile; +import org.jnario.doc.CssClassProvider; +import org.jnario.doc.DocumentationProvider; +import org.jnario.doc.ErrorMessageProvider; +import org.jnario.doc.Filter; +import org.jnario.doc.HtmlFile; +import org.jnario.doc.HtmlFileBuilder; +import org.jnario.doc.IconProvider; +import org.jnario.doc.WhiteSpaceNormalizer; +import org.jnario.report.Executable2ResultMapping; +import org.jnario.report.SpecExecution; +import org.pegdown.PegDownProcessor; + +@SuppressWarnings("all") +public abstract class AbstractDocGenerator implements IGenerator { + private final static Logger LOG = Logger.getLogger(AbstractDocGenerator.class); + + private final static String SEP = "_"; + + @Inject + @Extension + private WhiteSpaceNormalizer _whiteSpaceNormalizer; + + @Inject + @Extension + private PegDownProcessor _pegDownProcessor; + + @Inject + @Extension + private HtmlFileBuilder _htmlFileBuilder; + + @Inject + @Extension + private DocumentationProvider documentationProvider; + + @Inject + @Extension + private Executable2ResultMapping spec2ResultMapping; + + @Override + public void doGenerate(final Resource input, final IFileSystemAccess fsa) { + this.doGenerate(input, fsa, this.spec2ResultMapping); + } + + public void doGenerate(final Resource input, final IFileSystemAccess fsa, final Executable2ResultMapping spec2ResultMapping) { + this.initResultMapping(spec2ResultMapping); + final Consumer _function = new Consumer() { + @Override + public void accept(final JnarioFile it) { + final Consumer _function = new Consumer() { + @Override + public void accept(final JnarioClass it) { + AbstractDocGenerator.this._htmlFileBuilder.generate(it, fsa, AbstractDocGenerator.this.createHtmlFile(it)); + } + }; + Iterables.filter(it.getXtendTypes(), JnarioClass.class).forEach(_function); + } + }; + Iterables.filter(input.getContents(), JnarioFile.class).forEach(_function); + } + + protected Executable2ResultMapping initResultMapping(final Executable2ResultMapping spec2ResultMapping) { + return this.spec2ResultMapping = spec2ResultMapping; + } + + public HtmlFile createHtmlFile(final JnarioClass jnarioClass) { + return HtmlFile.EMPTY_FILE; + } + + protected String toTitle(final String string) { + return Strings.toFirstUpper(this.decode(string)); + } + + protected String decode(final String string) { + try { + boolean _equals = Objects.equal(string, null); + if (_equals) { + return ""; + } else { + return Strings.convertFromJavaString(string, true); + } + } catch (final Throwable _t) { + if (_t instanceof IllegalArgumentException) { + final IllegalArgumentException e = (IllegalArgumentException)_t; + AbstractDocGenerator.LOG.error("Exception when converting string", e); + return string; + } else { + throw Exceptions.sneakyThrow(_t); + } + } + } + + protected String markdown2Html(final String string) { + String _xblockexpression = null; + { + boolean _equals = Objects.equal(string, null); + if (_equals) { + return ""; + } + String _normalize = this._whiteSpaceNormalizer.normalize(string); + final String normalized = (_normalize + "\n"); + _xblockexpression = this._pegDownProcessor.markdownToHtml(normalized).replaceAll("
    ", "
    ").replaceAll("
    ", "
    "); + } + return _xblockexpression; + } + + protected String _serialize(final XExpression expr, final List filters) { + return this.codeToHtml(this.serialize(expr)).trim(); + } + + protected String _serialize(final XBlockExpression expr, final List filters) { + String code = this.serialize(expr).trim(); + code = this.apply(filters, code); + int _length = code.length(); + boolean _equals = (_length == 0); + if (_equals) { + return ""; + } + int _length_1 = code.length(); + int _minus = (_length_1 - 1); + code = code.substring(1, _minus); + return this.codeToHtml(code); + } + + protected String codeToHtml(final String code) { + return this.toHtml(org.jnario.util.Strings.trimWhitespaceAtEnd(this._whiteSpaceNormalizer.normalize(code)).toString()).replace("\t", " "); + } + + protected String toHtml(final String input) { + return StringEscapeUtils.escapeHtml(input); + } + + protected String serialize(final EObject obj) { + final ICompositeNode node = NodeModelUtils.getNode(obj); + boolean _equals = Objects.equal(node, null); + if (_equals) { + return ""; + } + return node.getText(); + } + + protected String id(final String id) { + String _replaceAll = null; + if (id!=null) { + _replaceAll=id.replaceAll("\\W+", AbstractDocGenerator.SEP); + } + String _trim = null; + if (_replaceAll!=null) { + _trim=org.jnario.util.Strings.trim(_replaceAll, AbstractDocGenerator.SEP.charAt(0)); + } + String _plus = (" id=\"" + _trim); + return (_plus + "\""); + } + + protected String apply(final List filters, final String input) { + String result = input; + for (final Filter filter : filters) { + result = filter.apply(result); + } + return result; + } + + protected String root(final EObject jnarioClass) { + final JnarioFile specFile = EcoreUtil2.getContainerOfType(jnarioClass, JnarioFile.class); + final String packageName = specFile.getPackage(); + boolean _equals = Objects.equal(packageName, null); + if (_equals) { + return ""; + } + final String[] fragments = packageName.split("\\."); + final Function1 _function = new Function1() { + @Override + public String apply(final String s) { + return "../"; + } + }; + final List path = ListExtensions.map(((List)Conversions.doWrapArray(fragments)), _function); + return IterableExtensions.join(path, ""); + } + + protected CharSequence generate(final ExampleTable table) { + StringConcatenation _builder = new StringConcatenation(); + _builder.append(""); + _builder.newLine(); + _builder.append("\t"); + _builder.append(""); + _builder.newLine(); + _builder.append("\t\t"); + _builder.append(""); + _builder.newLine(); + { + EList _columns = table.getColumns(); + for(final ExampleColumn headingCell : _columns) { + _builder.append("\t\t"); + _builder.append(""); + _builder.newLineIfNotEmpty(); + } + } + _builder.append("\t\t"); + _builder.append(""); + _builder.newLine(); + _builder.append("\t"); + _builder.append(""); + _builder.newLine(); + _builder.append("\t"); + _builder.append(""); + _builder.newLine(); + { + EList _rows = table.getRows(); + for(final ExampleRow row : _rows) { + _builder.append("\t"); + _builder.append(""); + _builder.newLine(); + { + EList _cells = row.getCells(); + for(final ExampleCell cell : _cells) { + _builder.append("\t"); + _builder.append("\t"); + _builder.append(""); + _builder.newLineIfNotEmpty(); + } + } + _builder.append("\t"); + _builder.append(""); + _builder.newLine(); + } + } + _builder.append("\t"); + _builder.append(""); + _builder.newLine(); + _builder.append("
    "); + String _name = headingCell.getName(); + _builder.append(_name, "\t\t"); + _builder.append("
    "); + String _serialize = this.serialize(cell.getExpression(), CollectionLiterals.emptyList()); + _builder.append(_serialize, "\t\t"); + _builder.append("
    "); + _builder.newLine(); + return _builder; + } + + protected String htmlFileName(final String name) { + return this._htmlFileBuilder.toHtmlFileName(name); + } + + protected String documentation(final EObject obj) { + return this.documentationProvider.getDocumentation(obj); + } + + protected String fileName(final EObject eObject) { + return eObject.eResource().getURI().lastSegment(); + } + + protected CharSequence pre(final EObject eObject, final String lang) { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("
    ");
    +    _builder.newLineIfNotEmpty();
    +    String _codeToHtml = this.codeToHtml(this.serialize(eObject));
    +    _builder.append(_codeToHtml);
    +    _builder.newLineIfNotEmpty();
    +    _builder.append("
    "); + _builder.newLine(); + return _builder; + } + + protected String executionState(final Executable executable) { + String _xblockexpression = null; + { + final SpecExecution result = this.spec2ResultMapping.getResult(executable); + _xblockexpression = new IconProvider().doSwitch(result); + } + return _xblockexpression; + } + + protected String executionStateClass(final Executable executable) { + return new CssClassProvider().doSwitch(this.spec2ResultMapping.getResult(executable)); + } + + protected String errorMessage(final Executable executable) { + return new ErrorMessageProvider().doSwitch(this.spec2ResultMapping.getResult(executable)); + } + + protected String serialize(final XExpression expr, final List filters) { + if (expr instanceof XBlockExpression) { + return _serialize((XBlockExpression)expr, filters); + } else if (expr != null) { + return _serialize(expr, filters); + } else { + throw new IllegalArgumentException("Unhandled parameter types: " + + Arrays.asList(expr, filters).toString()); + } + } +} diff --git a/plugins/org.jnario/xtend-gen/org/jnario/doc/CssClassProvider.java b/plugins/org.jnario/xtend-gen/org/jnario/doc/CssClassProvider.java index e84d55c0f..12310c806 100644 --- a/plugins/org.jnario/xtend-gen/org/jnario/doc/CssClassProvider.java +++ b/plugins/org.jnario/xtend-gen/org/jnario/doc/CssClassProvider.java @@ -1,46 +1,46 @@ -/** - * Copyright (c) 2012 BMW Car IT and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.jnario.doc; - -import org.eclipse.xtend2.lib.StringConcatenation; -import org.jnario.report.ExecutableStateSwitch; -import org.jnario.report.Failed; -import org.jnario.report.NotRun; -import org.jnario.report.Passed; -import org.jnario.report.Pending; - -@SuppressWarnings("all") -public class CssClassProvider extends ExecutableStateSwitch { - @Override - protected String handleFailed(final Failed result) { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("failed"); - return _builder.toString(); - } - - @Override - protected String handleNotRun(final NotRun execution) { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("notrun"); - return _builder.toString(); - } - - @Override - protected String handlePassed(final Passed execution) { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("passed"); - return _builder.toString(); - } - - @Override - protected String handlePending(final Pending execution) { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("pending"); - return _builder.toString(); - } -} +/** + * Copyright (c) 2012 BMW Car IT and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.jnario.doc; + +import org.eclipse.xtend2.lib.StringConcatenation; +import org.jnario.report.ExecutableStateSwitch; +import org.jnario.report.Failed; +import org.jnario.report.NotRun; +import org.jnario.report.Passed; +import org.jnario.report.Pending; + +@SuppressWarnings("all") +public class CssClassProvider extends ExecutableStateSwitch { + @Override + protected String handleFailed(final Failed result) { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("failed"); + return _builder.toString(); + } + + @Override + protected String handleNotRun(final NotRun execution) { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("notrun"); + return _builder.toString(); + } + + @Override + protected String handlePassed(final Passed execution) { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("passed"); + return _builder.toString(); + } + + @Override + protected String handlePending(final Pending execution) { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("pending"); + return _builder.toString(); + } +} diff --git a/plugins/org.jnario/xtend-gen/org/jnario/doc/DocumentationProvider.java b/plugins/org.jnario/xtend-gen/org/jnario/doc/DocumentationProvider.java index 135769569..b710aed51 100644 --- a/plugins/org.jnario/xtend-gen/org/jnario/doc/DocumentationProvider.java +++ b/plugins/org.jnario/xtend-gen/org/jnario/doc/DocumentationProvider.java @@ -1,37 +1,36 @@ -/** - * Copyright (c) 2012 BMW Car IT and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.jnario.doc; - -import com.google.common.base.Objects; -import com.google.inject.Inject; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.xtext.documentation.IEObjectDocumentationProvider; - -@SuppressWarnings("all") -public class DocumentationProvider { - private final IEObjectDocumentationProvider delegate; - - @Inject - public DocumentationProvider(final IEObjectDocumentationProvider delegate) { - this.delegate = delegate; - } - - public String getDocumentation(final EObject eObject) { - String _xblockexpression = null; - { - final String doc = this.delegate.getDocumentation(eObject); - boolean _equals = Objects.equal(doc, null); - if (_equals) { - return null; - } - String _replaceAll = doc.replaceAll("\\\\/\\*", "/*"); - _xblockexpression = _replaceAll.replaceAll("\\\\\\*/", "*/"); - } - return _xblockexpression; - } -} +/** + * Copyright (c) 2012 BMW Car IT and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.jnario.doc; + +import com.google.common.base.Objects; +import com.google.inject.Inject; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.xtext.documentation.IEObjectDocumentationProvider; + +@SuppressWarnings("all") +public class DocumentationProvider { + private final IEObjectDocumentationProvider delegate; + + @Inject + public DocumentationProvider(final IEObjectDocumentationProvider delegate) { + this.delegate = delegate; + } + + public String getDocumentation(final EObject eObject) { + String _xblockexpression = null; + { + final String doc = this.delegate.getDocumentation(eObject); + boolean _equals = Objects.equal(doc, null); + if (_equals) { + return null; + } + _xblockexpression = doc.replaceAll("\\\\/\\*", "/*").replaceAll("\\\\\\*/", "*/"); + } + return _xblockexpression; + } +} diff --git a/plugins/org.jnario/xtend-gen/org/jnario/doc/ErrorMessageProvider.java b/plugins/org.jnario/xtend-gen/org/jnario/doc/ErrorMessageProvider.java index d195194e9..b96b64da7 100644 --- a/plugins/org.jnario/xtend-gen/org/jnario/doc/ErrorMessageProvider.java +++ b/plugins/org.jnario/xtend-gen/org/jnario/doc/ErrorMessageProvider.java @@ -1,57 +1,56 @@ -/** - * Copyright (c) 2012 BMW Car IT and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.jnario.doc; - -import java.util.List; -import org.apache.commons.lang.StringEscapeUtils; -import org.eclipse.xtend2.lib.StringConcatenation; -import org.jnario.report.ExecutableStateSwitch; -import org.jnario.report.Failed; -import org.jnario.report.NotRun; -import org.jnario.report.Passed; -import org.jnario.report.Pending; -import org.jnario.report.SpecFailure; - -@SuppressWarnings("all") -public class ErrorMessageProvider extends ExecutableStateSwitch { - @Override - protected String handleFailed(final Failed result) { - StringConcatenation _builder = new StringConcatenation(); - { - List _failures = result.getFailures(); - for(final SpecFailure failure : _failures) { - _builder.append("
    ");
    -        _builder.newLine();
    -        String _message = failure.getMessage();
    -        String _escapeHtml = StringEscapeUtils.escapeHtml(_message);
    -        _builder.append(_escapeHtml, "");
    -        _builder.append("
    "); - _builder.newLineIfNotEmpty(); - } - } - return _builder.toString(); - } - - @Override - protected String handleNotRun(final NotRun execution) { - StringConcatenation _builder = new StringConcatenation(); - return _builder.toString(); - } - - @Override - protected String handlePassed(final Passed execution) { - StringConcatenation _builder = new StringConcatenation(); - return _builder.toString(); - } - - @Override - protected String handlePending(final Pending execution) { - StringConcatenation _builder = new StringConcatenation(); - return _builder.toString(); - } -} +/** + * Copyright (c) 2012 BMW Car IT and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.jnario.doc; + +import java.util.List; +import org.apache.commons.lang.StringEscapeUtils; +import org.eclipse.xtend2.lib.StringConcatenation; +import org.jnario.report.ExecutableStateSwitch; +import org.jnario.report.Failed; +import org.jnario.report.NotRun; +import org.jnario.report.Passed; +import org.jnario.report.Pending; +import org.jnario.report.SpecFailure; + +@SuppressWarnings("all") +public class ErrorMessageProvider extends ExecutableStateSwitch { + @Override + protected String handleFailed(final Failed result) { + StringConcatenation _builder = new StringConcatenation(); + { + List _failures = result.getFailures(); + for(final SpecFailure failure : _failures) { + _builder.append("
    ");
    +        _builder.newLine();
    +        String _escapeHtml = StringEscapeUtils.escapeHtml(failure.getMessage());
    +        _builder.append(_escapeHtml);
    +        _builder.append("
    "); + _builder.newLineIfNotEmpty(); + } + } + return _builder.toString(); + } + + @Override + protected String handleNotRun(final NotRun execution) { + StringConcatenation _builder = new StringConcatenation(); + return _builder.toString(); + } + + @Override + protected String handlePassed(final Passed execution) { + StringConcatenation _builder = new StringConcatenation(); + return _builder.toString(); + } + + @Override + protected String handlePending(final Pending execution) { + StringConcatenation _builder = new StringConcatenation(); + return _builder.toString(); + } +} diff --git a/plugins/org.jnario/xtend-gen/org/jnario/doc/FilterExtractor.java b/plugins/org.jnario/xtend-gen/org/jnario/doc/FilterExtractor.java index 57a5422e4..b9d885c36 100644 --- a/plugins/org.jnario/xtend-gen/org/jnario/doc/FilterExtractor.java +++ b/plugins/org.jnario/xtend-gen/org/jnario/doc/FilterExtractor.java @@ -1,74 +1,70 @@ -/** - * Copyright (c) 2012 BMW Car IT and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.jnario.doc; - -import com.google.common.base.Objects; -import java.util.List; -import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import org.eclipse.xtext.xbase.lib.CollectionLiterals; -import org.eclipse.xtext.xbase.lib.Functions.Function1; -import org.eclipse.xtext.xbase.lib.Pair; -import org.jnario.doc.Filter; -import org.jnario.doc.FilteringResult; -import org.jnario.doc.LangFilter; -import org.jnario.doc.RegexFilter; - -@SuppressWarnings("all") -public class FilterExtractor { - private static String TAG = "(^|\\W)@(\\w+)(\\((.*?)\\))"; - - private static Pattern TAG_PATTERN = Pattern.compile(FilterExtractor.TAG, Pattern.DOTALL); - - private Map> filterRegistry = CollectionLiterals.>newHashMap( - Pair.>of("filter", new Function1() { - @Override - public Filter apply(final String s) { - return RegexFilter.create(s); - } - }), - Pair.>of("lang", new Function1() { - @Override - public Filter apply(final String s) { - return LangFilter.create(s); - } - })); - - public FilteringResult apply(final String input) { - boolean _equals = Objects.equal(input, null); - if (_equals) { - return FilteringResult.EMPTY_RESULT; - } - final StringBuilder resultString = new StringBuilder(); - final List filters = CollectionLiterals.newArrayList(); - final Matcher matcher = FilterExtractor.TAG_PATTERN.matcher(input); - int offset = 0; - while (matcher.find()) { - { - final String key = matcher.group(2); - final Function1 candidate = this.filterRegistry.get(key); - boolean _notEquals = (!Objects.equal(candidate, null)); - if (_notEquals) { - String _group = matcher.group(4); - Filter _apply = candidate.apply(_group); - filters.add(_apply); - } - final int nextOffset = matcher.start(); - String _substring = input.substring(offset, nextOffset); - resultString.append(_substring); - int _end = matcher.end(); - offset = _end; - } - } - String _substring = input.substring(offset); - resultString.append(_substring); - String _string = resultString.toString(); - return new FilteringResult(_string, filters); - } -} +/** + * Copyright (c) 2012 BMW Car IT and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.jnario.doc; + +import com.google.common.base.Objects; +import java.util.List; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import org.eclipse.xtext.xbase.lib.CollectionLiterals; +import org.eclipse.xtext.xbase.lib.Functions.Function1; +import org.eclipse.xtext.xbase.lib.Pair; +import org.jnario.doc.Filter; +import org.jnario.doc.FilteringResult; +import org.jnario.doc.LangFilter; +import org.jnario.doc.RegexFilter; + +@SuppressWarnings("all") +public class FilterExtractor { + private static String TAG = "(^|\\W)@(\\w+)(\\((.*?)\\))"; + + private static Pattern TAG_PATTERN = Pattern.compile(FilterExtractor.TAG, Pattern.DOTALL); + + private Map> filterRegistry = CollectionLiterals.>newHashMap( + Pair.>of("filter", new Function1() { + @Override + public Filter apply(final String s) { + return RegexFilter.create(s); + } + }), + Pair.>of("lang", new Function1() { + @Override + public Filter apply(final String s) { + return LangFilter.create(s); + } + })); + + public FilteringResult apply(final String input) { + boolean _equals = Objects.equal(input, null); + if (_equals) { + return FilteringResult.EMPTY_RESULT; + } + final StringBuilder resultString = new StringBuilder(); + final List filters = CollectionLiterals.newArrayList(); + final Matcher matcher = FilterExtractor.TAG_PATTERN.matcher(input); + int offset = 0; + while (matcher.find()) { + { + final String key = matcher.group(2); + final Function1 candidate = this.filterRegistry.get(key); + boolean _notEquals = (!Objects.equal(candidate, null)); + if (_notEquals) { + Filter _apply = candidate.apply(matcher.group(4)); + filters.add(_apply); + } + final int nextOffset = matcher.start(); + resultString.append(input.substring(offset, nextOffset)); + offset = matcher.end(); + } + } + resultString.append(input.substring(offset)); + String _string = resultString.toString(); + return new FilteringResult(_string, filters); + } +} diff --git a/plugins/org.jnario/xtend-gen/org/jnario/doc/HtmlAssets.java b/plugins/org.jnario/xtend-gen/org/jnario/doc/HtmlAssets.java index b11d875c0..a7bf13fab 100644 --- a/plugins/org.jnario/xtend-gen/org/jnario/doc/HtmlAssets.java +++ b/plugins/org.jnario/xtend-gen/org/jnario/doc/HtmlAssets.java @@ -1,141 +1,135 @@ -/** - * Copyright (c) 2012 BMW Car IT and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.jnario.doc; - -import com.google.inject.Singleton; -import java.io.InputStream; -import java.util.List; -import java.util.Map; -import org.eclipse.emf.common.util.URI; -import org.eclipse.emf.ecore.resource.URIConverter; -import org.eclipse.xtend.lib.Data; -import org.eclipse.xtext.generator.IFileSystemAccess; -import org.eclipse.xtext.generator.IFileSystemAccessExtension2; -import org.eclipse.xtext.xbase.lib.CollectionLiterals; -import org.eclipse.xtext.xbase.lib.Functions.Function1; -import org.eclipse.xtext.xbase.lib.IterableExtensions; -import org.eclipse.xtext.xbase.lib.ListExtensions; -import org.eclipse.xtext.xbase.lib.Pure; -import org.eclipse.xtext.xbase.lib.util.ToStringHelper; -import org.jnario.doc.DocOutputConfigurationProvider; -import org.jnario.util.Strings; - -@Data -@Singleton -@SuppressWarnings("all") -public class HtmlAssets { - private final List _cssFiles = ListExtensions.map(CollectionLiterals.newArrayList( - "bootstrap.min.css", - "bootstrap-responsive.min.css", - "custom.css", - "prettify.css"), new Function1() { - @Override - public String apply(final String it) { - return ("css/" + it); - } - }); - - private final List _jsFiles = ListExtensions.map(CollectionLiterals.newArrayList( - "prettify.js", - "lang-jnario.js", - "jquery.js", - "bootstrap-tab.js"), new Function1() { - @Override - public String apply(final String it) { - return ("js/" + it); - } - }); - - public void generate(final IFileSystemAccess fsa) { - List _cssFiles = this.getCssFiles(); - this.copy(fsa, _cssFiles); - List _jsFiles = this.getJsFiles(); - this.copy(fsa, _jsFiles); - } - - private void copy(final IFileSystemAccess fsa, final Iterable files) { - final Function1 _function = new Function1() { - @Override - public Boolean apply(final String it) { - boolean _exists = HtmlAssets.this.exists(fsa, it); - return Boolean.valueOf((!_exists)); - } - }; - Iterable _filter = IterableExtensions.filter(files, _function); - for (final String file : _filter) { - String _load = this.load(file); - fsa.generateFile(file, DocOutputConfigurationProvider.ASSET_OUTPUT, _load); - } - } - - private boolean exists(final IFileSystemAccess fsa, final String file) { - if ((!(fsa instanceof IFileSystemAccessExtension2))) { - return false; - } - final IFileSystemAccessExtension2 fsa2 = ((IFileSystemAccessExtension2) fsa); - final URI uri = fsa2.getURI(file, DocOutputConfigurationProvider.ASSET_OUTPUT); - Map _emptyMap = CollectionLiterals.emptyMap(); - return URIConverter.INSTANCE.exists(uri, _emptyMap); - } - - private String load(final String file) { - Class _class = this.getClass(); - final InputStream inputStream = _class.getResourceAsStream(file); - return Strings.convertStreamToString(inputStream); - } - - @Override - @Pure - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((this._cssFiles== null) ? 0 : this._cssFiles.hashCode()); - result = prime * result + ((this._jsFiles== null) ? 0 : this._jsFiles.hashCode()); - return result; - } - - @Override - @Pure - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - HtmlAssets other = (HtmlAssets) obj; - if (this._cssFiles == null) { - if (other._cssFiles != null) - return false; - } else if (!this._cssFiles.equals(other._cssFiles)) - return false; - if (this._jsFiles == null) { - if (other._jsFiles != null) - return false; - } else if (!this._jsFiles.equals(other._jsFiles)) - return false; - return true; - } - - @Override - @Pure - public String toString() { - String result = new ToStringHelper().toString(this); - return result; - } - - @Pure - public List getCssFiles() { - return this._cssFiles; - } - - @Pure - public List getJsFiles() { - return this._jsFiles; - } -} +/** + * Copyright (c) 2012 BMW Car IT and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.jnario.doc; + +import com.google.inject.Singleton; +import java.io.InputStream; +import java.util.List; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.resource.URIConverter; +import org.eclipse.xtend.lib.Data; +import org.eclipse.xtext.generator.IFileSystemAccess; +import org.eclipse.xtext.generator.IFileSystemAccessExtension2; +import org.eclipse.xtext.xbase.lib.CollectionLiterals; +import org.eclipse.xtext.xbase.lib.Functions.Function1; +import org.eclipse.xtext.xbase.lib.IterableExtensions; +import org.eclipse.xtext.xbase.lib.ListExtensions; +import org.eclipse.xtext.xbase.lib.Pure; +import org.eclipse.xtext.xbase.lib.util.ToStringHelper; +import org.jnario.doc.DocOutputConfigurationProvider; +import org.jnario.util.Strings; + +@Data +@Singleton +@SuppressWarnings("all") +public class HtmlAssets { + private final List _cssFiles = ListExtensions.map(CollectionLiterals.newArrayList( + "bootstrap.min.css", + "bootstrap-responsive.min.css", + "custom.css", + "prettify.css"), new Function1() { + @Override + public String apply(final String it) { + return ("css/" + it); + } + }); + + private final List _jsFiles = ListExtensions.map(CollectionLiterals.newArrayList( + "prettify.js", + "lang-jnario.js", + "jquery.js", + "bootstrap-tab.js"), new Function1() { + @Override + public String apply(final String it) { + return ("js/" + it); + } + }); + + public void generate(final IFileSystemAccess fsa) { + this.copy(fsa, this.getCssFiles()); + this.copy(fsa, this.getJsFiles()); + } + + private void copy(final IFileSystemAccess fsa, final Iterable files) { + final Function1 _function = new Function1() { + @Override + public Boolean apply(final String it) { + boolean _exists = HtmlAssets.this.exists(fsa, it); + return Boolean.valueOf((!_exists)); + } + }; + Iterable _filter = IterableExtensions.filter(files, _function); + for (final String file : _filter) { + fsa.generateFile(file, DocOutputConfigurationProvider.ASSET_OUTPUT, this.load(file)); + } + } + + private boolean exists(final IFileSystemAccess fsa, final String file) { + if ((!(fsa instanceof IFileSystemAccessExtension2))) { + return false; + } + final IFileSystemAccessExtension2 fsa2 = ((IFileSystemAccessExtension2) fsa); + final URI uri = fsa2.getURI(file, DocOutputConfigurationProvider.ASSET_OUTPUT); + return URIConverter.INSTANCE.exists(uri, CollectionLiterals.emptyMap()); + } + + private String load(final String file) { + final InputStream inputStream = this.getClass().getResourceAsStream(file); + return Strings.convertStreamToString(inputStream); + } + + @Override + @Pure + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((this._cssFiles== null) ? 0 : this._cssFiles.hashCode()); + result = prime * result + ((this._jsFiles== null) ? 0 : this._jsFiles.hashCode()); + return result; + } + + @Override + @Pure + public boolean equals(final Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + HtmlAssets other = (HtmlAssets) obj; + if (this._cssFiles == null) { + if (other._cssFiles != null) + return false; + } else if (!this._cssFiles.equals(other._cssFiles)) + return false; + if (this._jsFiles == null) { + if (other._jsFiles != null) + return false; + } else if (!this._jsFiles.equals(other._jsFiles)) + return false; + return true; + } + + @Override + @Pure + public String toString() { + String result = new ToStringHelper().toString(this); + return result; + } + + @Pure + public List getCssFiles() { + return this._cssFiles; + } + + @Pure + public List getJsFiles() { + return this._jsFiles; + } +} diff --git a/plugins/org.jnario/xtend-gen/org/jnario/doc/HtmlFile.java b/plugins/org.jnario/xtend-gen/org/jnario/doc/HtmlFile.java index 317c4e6d8..ea50287bb 100644 --- a/plugins/org.jnario/xtend-gen/org/jnario/doc/HtmlFile.java +++ b/plugins/org.jnario/xtend-gen/org/jnario/doc/HtmlFile.java @@ -1,287 +1,285 @@ -/** - * Copyright (c) 2012 BMW Car IT and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.jnario.doc; - -import java.util.List; -import org.eclipse.xtend.lib.Property; -import org.eclipse.xtend2.lib.StringConcatenation; -import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; -import org.eclipse.xtext.xbase.lib.Pure; -import org.jnario.doc.HtmlAssets; - -@SuppressWarnings("all") -public class HtmlFile { - public static HtmlFile EMPTY_FILE = new HtmlFile(); - - public static HtmlFile newHtmlFile(final Procedure1 initializer) { - final HtmlFile htmlFile = new HtmlFile(); - initializer.apply(htmlFile); - return htmlFile; - } - - @Property - private HtmlAssets _assets = new HtmlAssets(); - - @Property - private CharSequence _name = ""; - - @Property - private CharSequence _title = ""; - - @Property - private CharSequence _content = ""; - - @Property - private String _rootFolder = ""; - - @Property - private CharSequence _sourceCode = ""; - - @Property - private CharSequence _fileName = ""; - - @Property - private String _executionStatus = ""; - - public CharSequence toText() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append(""); - _builder.newLine(); - _builder.append(""); - _builder.newLine(); - _builder.append(""); - _builder.newLine(); - _builder.append(""); - _builder.newLine(); - _builder.append(""); - CharSequence _title = this.getTitle(); - _builder.append(_title, ""); - _builder.append(""); - _builder.newLineIfNotEmpty(); - _builder.append(""); - _builder.newLine(); - _builder.append(""); - _builder.newLine(); - _builder.newLine(); - _builder.append(""); - _builder.newLine(); - _builder.newLine(); - { - HtmlAssets _assets = this.getAssets(); - List _cssFiles = _assets.getCssFiles(); - for(final String cssFile : _cssFiles) { - _builder.append(""); - _builder.newLineIfNotEmpty(); - } - } - { - HtmlAssets _assets_1 = this.getAssets(); - List _jsFiles = _assets_1.getJsFiles(); - for(final String jsFile : _jsFiles) { - _builder.append(""); - _builder.newLineIfNotEmpty(); - } - } - _builder.append(""); - _builder.newLine(); - _builder.newLine(); - _builder.append(""); - _builder.newLine(); - _builder.append("\t"); - _builder.append("
    "); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("
    "); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("
    "); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("
    "); - _builder.newLineIfNotEmpty(); - _builder.append("\t\t\t\t\t"); - _builder.append("

    "); - CharSequence _title_1 = this.getTitle(); - _builder.append(_title_1, "\t\t\t\t\t"); - _builder.append("

    "); - _builder.newLineIfNotEmpty(); - _builder.append("\t\t\t\t\t "); - _builder.append("
      "); - _builder.newLine(); - _builder.append("\t\t\t\t\t "); - _builder.append("
    • Spec
    • "); - _builder.newLine(); - _builder.append("\t\t\t\t\t\t"); - _builder.append("
    • Source
    • "); - _builder.newLine(); - _builder.append("\t\t\t\t\t "); - _builder.append("
    "); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("
    "); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("
    "); - _builder.newLine(); - _builder.append("\t\t\t\t\t"); - _builder.append("
    "); - _builder.newLine(); - _builder.append("\t\t\t\t\t\t "); - _builder.append("
    "); - _builder.newLine(); - _builder.append("\t\t\t\t\t\t\t \t"); - _builder.append("
    "); - _builder.newLine(); - CharSequence _content = this.getContent(); - _builder.append(_content, ""); - _builder.newLineIfNotEmpty(); - _builder.append("\t\t\t\t\t\t\t"); - _builder.append("
    "); - _builder.newLine(); - _builder.append("\t\t\t\t\t\t "); - _builder.append("
    "); - _builder.newLine(); - _builder.append("\t\t\t\t\t\t \t"); - _builder.append("

    "); - CharSequence _fileName = this.getFileName(); - _builder.append(_fileName, "\t\t\t\t\t\t \t"); - _builder.append("

    "); - _builder.newLineIfNotEmpty(); - _builder.append("\t\t\t\t\t\t \t"); - _builder.append("

    "); - _builder.newLine(); - CharSequence _sourceCode = this.getSourceCode(); - _builder.append(_sourceCode, ""); - _builder.newLineIfNotEmpty(); - _builder.append("\t\t\t\t\t\t "); - _builder.append("

    "); - _builder.newLine(); - _builder.append("\t\t\t\t\t\t "); - _builder.append("
    "); - _builder.newLine(); - _builder.append("\t\t\t\t\t"); - _builder.append("
    "); - _builder.newLine(); - _builder.append("\t\t\t\t"); - _builder.append("
    "); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("
    "); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("
    "); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("
    "); - _builder.newLine(); - _builder.append("\t\t\t"); - _builder.append("

    Generated by Jnario.

    "); - _builder.newLine(); - _builder.append("\t\t"); - _builder.append("
    "); - _builder.newLine(); - _builder.append("\t"); - _builder.append("
    "); - _builder.newLine(); - _builder.newLine(); - _builder.append(""); - _builder.newLine(); - _builder.append(""); - _builder.newLine(); - return _builder; - } - - @Pure - public HtmlAssets getAssets() { - return this._assets; - } - - public void setAssets(final HtmlAssets assets) { - this._assets = assets; - } - - @Pure - public CharSequence getName() { - return this._name; - } - - public void setName(final CharSequence name) { - this._name = name; - } - - @Pure - public CharSequence getTitle() { - return this._title; - } - - public void setTitle(final CharSequence title) { - this._title = title; - } - - @Pure - public CharSequence getContent() { - return this._content; - } - - public void setContent(final CharSequence content) { - this._content = content; - } - - @Pure - public String getRootFolder() { - return this._rootFolder; - } - - public void setRootFolder(final String rootFolder) { - this._rootFolder = rootFolder; - } - - @Pure - public CharSequence getSourceCode() { - return this._sourceCode; - } - - public void setSourceCode(final CharSequence sourceCode) { - this._sourceCode = sourceCode; - } - - @Pure - public CharSequence getFileName() { - return this._fileName; - } - - public void setFileName(final CharSequence fileName) { - this._fileName = fileName; - } - - @Pure - public String getExecutionStatus() { - return this._executionStatus; - } - - public void setExecutionStatus(final String executionStatus) { - this._executionStatus = executionStatus; - } -} +/** + * Copyright (c) 2012 BMW Car IT and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.jnario.doc; + +import java.util.List; +import org.eclipse.xtend.lib.Property; +import org.eclipse.xtend2.lib.StringConcatenation; +import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; +import org.eclipse.xtext.xbase.lib.Pure; +import org.jnario.doc.HtmlAssets; + +@SuppressWarnings("all") +public class HtmlFile { + public static HtmlFile EMPTY_FILE = new HtmlFile(); + + public static HtmlFile newHtmlFile(final Procedure1 initializer) { + final HtmlFile htmlFile = new HtmlFile(); + initializer.apply(htmlFile); + return htmlFile; + } + + @Property + private HtmlAssets _assets = new HtmlAssets(); + + @Property + private CharSequence _name = ""; + + @Property + private CharSequence _title = ""; + + @Property + private CharSequence _content = ""; + + @Property + private String _rootFolder = ""; + + @Property + private CharSequence _sourceCode = ""; + + @Property + private CharSequence _fileName = ""; + + @Property + private String _executionStatus = ""; + + public CharSequence toText() { + StringConcatenation _builder = new StringConcatenation(); + _builder.append(""); + _builder.newLine(); + _builder.append(""); + _builder.newLine(); + _builder.append(""); + _builder.newLine(); + _builder.append(""); + _builder.newLine(); + _builder.append(""); + CharSequence _title = this.getTitle(); + _builder.append(_title); + _builder.append(""); + _builder.newLineIfNotEmpty(); + _builder.append(""); + _builder.newLine(); + _builder.append(""); + _builder.newLine(); + _builder.newLine(); + _builder.append(""); + _builder.newLine(); + _builder.newLine(); + { + List _cssFiles = this.getAssets().getCssFiles(); + for(final String cssFile : _cssFiles) { + _builder.append(""); + _builder.newLineIfNotEmpty(); + } + } + { + List _jsFiles = this.getAssets().getJsFiles(); + for(final String jsFile : _jsFiles) { + _builder.append(""); + _builder.newLineIfNotEmpty(); + } + } + _builder.append(""); + _builder.newLine(); + _builder.newLine(); + _builder.append(""); + _builder.newLine(); + _builder.append("\t"); + _builder.append("
    "); + _builder.newLine(); + _builder.append("\t\t"); + _builder.append("
    "); + _builder.newLine(); + _builder.append("\t\t\t"); + _builder.append("
    "); + _builder.newLine(); + _builder.append("\t\t\t\t"); + _builder.append("
    "); + _builder.newLineIfNotEmpty(); + _builder.append("\t\t\t\t\t"); + _builder.append("

    "); + CharSequence _title_1 = this.getTitle(); + _builder.append(_title_1, "\t\t\t\t\t"); + _builder.append("

    "); + _builder.newLineIfNotEmpty(); + _builder.append("\t\t\t\t\t "); + _builder.append("
      "); + _builder.newLine(); + _builder.append("\t\t\t\t\t "); + _builder.append("
    • Spec
    • "); + _builder.newLine(); + _builder.append("\t\t\t\t\t\t"); + _builder.append("
    • Source
    • "); + _builder.newLine(); + _builder.append("\t\t\t\t\t "); + _builder.append("
    "); + _builder.newLine(); + _builder.append("\t\t\t\t"); + _builder.append("
    "); + _builder.newLine(); + _builder.append("\t\t\t\t"); + _builder.append("
    "); + _builder.newLine(); + _builder.append("\t\t\t\t\t"); + _builder.append("
    "); + _builder.newLine(); + _builder.append("\t\t\t\t\t\t "); + _builder.append("
    "); + _builder.newLine(); + _builder.append("\t\t\t\t\t\t\t \t"); + _builder.append("
    "); + _builder.newLine(); + CharSequence _content = this.getContent(); + _builder.append(_content); + _builder.newLineIfNotEmpty(); + _builder.append("\t\t\t\t\t\t\t"); + _builder.append("
    "); + _builder.newLine(); + _builder.append("\t\t\t\t\t\t "); + _builder.append("
    "); + _builder.newLine(); + _builder.append("\t\t\t\t\t\t \t"); + _builder.append("

    "); + CharSequence _fileName = this.getFileName(); + _builder.append(_fileName, "\t\t\t\t\t\t \t"); + _builder.append("

    "); + _builder.newLineIfNotEmpty(); + _builder.append("\t\t\t\t\t\t \t"); + _builder.append("

    "); + _builder.newLine(); + CharSequence _sourceCode = this.getSourceCode(); + _builder.append(_sourceCode); + _builder.newLineIfNotEmpty(); + _builder.append("\t\t\t\t\t\t "); + _builder.append("

    "); + _builder.newLine(); + _builder.append("\t\t\t\t\t\t "); + _builder.append("
    "); + _builder.newLine(); + _builder.append("\t\t\t\t\t"); + _builder.append("
    "); + _builder.newLine(); + _builder.append("\t\t\t\t"); + _builder.append("
    "); + _builder.newLine(); + _builder.append("\t\t\t"); + _builder.append("
    "); + _builder.newLine(); + _builder.append("\t\t"); + _builder.append("
    "); + _builder.newLine(); + _builder.append("\t\t"); + _builder.append("
    "); + _builder.newLine(); + _builder.append("\t\t\t"); + _builder.append("

    Generated by Jnario.

    "); + _builder.newLine(); + _builder.append("\t\t"); + _builder.append("
    "); + _builder.newLine(); + _builder.append("\t"); + _builder.append("
    "); + _builder.newLine(); + _builder.newLine(); + _builder.append(""); + _builder.newLine(); + _builder.append(""); + _builder.newLine(); + return _builder; + } + + @Pure + public HtmlAssets getAssets() { + return this._assets; + } + + public void setAssets(final HtmlAssets assets) { + this._assets = assets; + } + + @Pure + public CharSequence getName() { + return this._name; + } + + public void setName(final CharSequence name) { + this._name = name; + } + + @Pure + public CharSequence getTitle() { + return this._title; + } + + public void setTitle(final CharSequence title) { + this._title = title; + } + + @Pure + public CharSequence getContent() { + return this._content; + } + + public void setContent(final CharSequence content) { + this._content = content; + } + + @Pure + public String getRootFolder() { + return this._rootFolder; + } + + public void setRootFolder(final String rootFolder) { + this._rootFolder = rootFolder; + } + + @Pure + public CharSequence getSourceCode() { + return this._sourceCode; + } + + public void setSourceCode(final CharSequence sourceCode) { + this._sourceCode = sourceCode; + } + + @Pure + public CharSequence getFileName() { + return this._fileName; + } + + public void setFileName(final CharSequence fileName) { + this._fileName = fileName; + } + + @Pure + public String getExecutionStatus() { + return this._executionStatus; + } + + public void setExecutionStatus(final String executionStatus) { + this._executionStatus = executionStatus; + } +} diff --git a/plugins/org.jnario/xtend-gen/org/jnario/doc/HtmlFileBuilder.java b/plugins/org.jnario/xtend-gen/org/jnario/doc/HtmlFileBuilder.java index 9dff6afaa..a4118d8d4 100644 --- a/plugins/org.jnario/xtend-gen/org/jnario/doc/HtmlFileBuilder.java +++ b/plugins/org.jnario/xtend-gen/org/jnario/doc/HtmlFileBuilder.java @@ -1,58 +1,56 @@ -/** - * Copyright (c) 2012 BMW Car IT and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.jnario.doc; - -import com.google.common.base.Objects; -import org.eclipse.xtext.generator.IFileSystemAccess; -import org.jnario.JnarioTypeDeclaration; -import org.jnario.doc.DocOutputConfigurationProvider; -import org.jnario.doc.HtmlFile; -import org.jnario.util.Strings; -import org.jnario.util.XtendTypes; - -@SuppressWarnings("all") -public class HtmlFileBuilder { - public void generate(final JnarioTypeDeclaration context, final IFileSystemAccess fsa, final HtmlFile htmlFile) { - CharSequence _name = htmlFile.getName(); - boolean _equals = Objects.equal(_name, null); - if (_equals) { - return; - } - final CharSequence content = htmlFile.toText(); - String _filePath = this.filePath(context, htmlFile); - fsa.generateFile(_filePath, DocOutputConfigurationProvider.DOC_OUTPUT, content); - } - - public String toHtmlFileName(final CharSequence nameWithoutExtension) { - String _string = null; - if (nameWithoutExtension!=null) { - _string=nameWithoutExtension.toString(); - } - String result = _string; - String _trim = Strings.trim(result, '_'); - return (_trim + ".html"); - } - - private String filePath(final JnarioTypeDeclaration xtendClass, final HtmlFile htmlFile) { - CharSequence _name = htmlFile.getName(); - String _htmlFileName = null; - if (_name!=null) { - _htmlFileName=this.toHtmlFileName(_name); - } - final String fileName = ("/" + _htmlFileName); - String _packageName = XtendTypes.packageName(xtendClass); - boolean _equals = Objects.equal(_packageName, null); - if (_equals) { - return fileName; - } - String _packageName_1 = XtendTypes.packageName(xtendClass); - String _replaceAll = _packageName_1.replaceAll("\\.", "/"); - String _plus = ("/" + _replaceAll); - return (_plus + fileName); - } -} +/** + * Copyright (c) 2012 BMW Car IT and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.jnario.doc; + +import com.google.common.base.Objects; +import org.eclipse.xtext.generator.IFileSystemAccess; +import org.jnario.JnarioTypeDeclaration; +import org.jnario.doc.DocOutputConfigurationProvider; +import org.jnario.doc.HtmlFile; +import org.jnario.util.Strings; +import org.jnario.util.XtendTypes; + +@SuppressWarnings("all") +public class HtmlFileBuilder { + public void generate(final JnarioTypeDeclaration context, final IFileSystemAccess fsa, final HtmlFile htmlFile) { + CharSequence _name = htmlFile.getName(); + boolean _equals = Objects.equal(_name, null); + if (_equals) { + return; + } + final CharSequence content = htmlFile.toText(); + fsa.generateFile(this.filePath(context, htmlFile), DocOutputConfigurationProvider.DOC_OUTPUT, content); + } + + public String toHtmlFileName(final CharSequence nameWithoutExtension) { + String _string = null; + if (nameWithoutExtension!=null) { + _string=nameWithoutExtension.toString(); + } + String result = _string; + String _trim = Strings.trim(result, '_'); + return (_trim + ".html"); + } + + private String filePath(final JnarioTypeDeclaration xtendClass, final HtmlFile htmlFile) { + CharSequence _name = htmlFile.getName(); + String _htmlFileName = null; + if (_name!=null) { + _htmlFileName=this.toHtmlFileName(_name); + } + final String fileName = ("/" + _htmlFileName); + String _packageName = XtendTypes.packageName(xtendClass); + boolean _equals = Objects.equal(_packageName, null); + if (_equals) { + return fileName; + } + String _replaceAll = XtendTypes.packageName(xtendClass).replaceAll("\\.", "/"); + String _plus = ("/" + _replaceAll); + return (_plus + fileName); + } +} diff --git a/plugins/org.jnario/xtend-gen/org/jnario/doc/IconProvider.java b/plugins/org.jnario/xtend-gen/org/jnario/doc/IconProvider.java index a0d236b95..7a4f4328b 100644 --- a/plugins/org.jnario/xtend-gen/org/jnario/doc/IconProvider.java +++ b/plugins/org.jnario/xtend-gen/org/jnario/doc/IconProvider.java @@ -1,48 +1,48 @@ -/** - * Copyright (c) 2012 BMW Car IT and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.jnario.doc; - -import org.eclipse.xtend2.lib.StringConcatenation; -import org.jnario.report.ExecutableStateSwitch; -import org.jnario.report.Failed; -import org.jnario.report.NotRun; -import org.jnario.report.Passed; -import org.jnario.report.Pending; - -@SuppressWarnings("all") -public class IconProvider extends ExecutableStateSwitch { - @Override - protected String handleFailed(final Failed result) { - StringConcatenation _builder = new StringConcatenation(); - _builder.append(" "); - _builder.append(""); - return _builder.toString(); - } - - @Override - protected String handleNotRun(final NotRun execution) { - StringConcatenation _builder = new StringConcatenation(); - return _builder.toString(); - } - - @Override - protected String handlePassed(final Passed execution) { - StringConcatenation _builder = new StringConcatenation(); - _builder.append(" "); - _builder.append(""); - return _builder.toString(); - } - - @Override - protected String handlePending(final Pending execution) { - StringConcatenation _builder = new StringConcatenation(); - _builder.append(" "); - _builder.append("~"); - return _builder.toString(); - } -} +/** + * Copyright (c) 2012 BMW Car IT and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.jnario.doc; + +import org.eclipse.xtend2.lib.StringConcatenation; +import org.jnario.report.ExecutableStateSwitch; +import org.jnario.report.Failed; +import org.jnario.report.NotRun; +import org.jnario.report.Passed; +import org.jnario.report.Pending; + +@SuppressWarnings("all") +public class IconProvider extends ExecutableStateSwitch { + @Override + protected String handleFailed(final Failed result) { + StringConcatenation _builder = new StringConcatenation(); + _builder.append(" "); + _builder.append(""); + return _builder.toString(); + } + + @Override + protected String handleNotRun(final NotRun execution) { + StringConcatenation _builder = new StringConcatenation(); + return _builder.toString(); + } + + @Override + protected String handlePassed(final Passed execution) { + StringConcatenation _builder = new StringConcatenation(); + _builder.append(" "); + _builder.append(""); + return _builder.toString(); + } + + @Override + protected String handlePending(final Pending execution) { + StringConcatenation _builder = new StringConcatenation(); + _builder.append(" "); + _builder.append("~"); + return _builder.toString(); + } +} diff --git a/plugins/org.jnario/xtend-gen/org/jnario/doc/LangFilter.java b/plugins/org.jnario/xtend-gen/org/jnario/doc/LangFilter.java index ab0e77743..e52c2212f 100644 --- a/plugins/org.jnario/xtend-gen/org/jnario/doc/LangFilter.java +++ b/plugins/org.jnario/xtend-gen/org/jnario/doc/LangFilter.java @@ -1,33 +1,33 @@ -/** - * Copyright (c) 2012 BMW Car IT and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.jnario.doc; - -import org.jnario.doc.Filter; - -@SuppressWarnings("all") -public class LangFilter implements Filter { - public static Filter create(final String regex) { - return new LangFilter(regex); - } - - private String language; - - public LangFilter(final String language) { - this.language = language; - } - - @Override - public String apply(final String input) { - return input.replace("
     lines = Arrays.asList(_split);
    -      boolean _isEmpty = IterableExtensions.isEmpty(lines);
    -      if (_isEmpty) {
    -        return "";
    -      }
    -      String firstLine = IterableExtensions.head(lines);
    -      while ((firstLine.trim().length() == 0)) {
    -        {
    -          Iterable _drop = IterableExtensions.drop(lines, 1);
    -          lines = _drop;
    -          String _head = IterableExtensions.head(lines);
    -          firstLine = _head;
    -          boolean _equals = Objects.equal(firstLine, null);
    -          if (_equals) {
    -            return "";
    -          }
    -        }
    -      }
    -      final String whitespace = this.whitespaceAtBeginning(firstLine);
    -      String ending = "";
    -      boolean _endsWith = Strings.endsWith(input, "\n");
    -      if (_endsWith) {
    -        ending = "\n";
    -      }
    -      final Function1 _function = new Function1() {
    -        @Override
    -        public String apply(final String it) {
    -          return WhiteSpaceNormalizer.this.remove(it, whitespace);
    -        }
    -      };
    -      Iterable _map = IterableExtensions.map(lines, _function);
    -      String _join = IterableExtensions.join(_map, "\n");
    -      String result = (_join + ending);
    -      _xblockexpression = result;
    -    }
    -    return _xblockexpression;
    -  }
    -  
    -  public String whitespaceAtBeginning(final String string) {
    -    final StringBuilder whitespace = new StringBuilder();
    -    char[] _charArray = string.toCharArray();
    -    for (final char c : _charArray) {
    -      boolean _isWhitespace = Character.isWhitespace(c);
    -      if (_isWhitespace) {
    -        whitespace.append(c);
    -      } else {
    -        return whitespace.toString();
    -      }
    -    }
    -    return "";
    -  }
    -  
    -  public String remove(final String input, final String toReplace) {
    -    int _length = input.length();
    -    int _length_1 = toReplace.length();
    -    boolean _lessThan = (_length < _length_1);
    -    if (_lessThan) {
    -      boolean _startsWith = toReplace.startsWith(input);
    -      if (_startsWith) {
    -        return "";
    -      } else {
    -        return input;
    -      }
    -    }
    -    int i = 0;
    -    while ((i < toReplace.length())) {
    -      {
    -        char _charAt = input.charAt(i);
    -        char _charAt_1 = toReplace.charAt(i);
    -        boolean _notEquals = (_charAt != _charAt_1);
    -        if (_notEquals) {
    -          return input;
    -        }
    -        i = (i + 1);
    -      }
    -    }
    -    int _length_2 = toReplace.length();
    -    return input.substring(_length_2);
    -  }
    -}
    +/**
    + * Copyright (c) 2012 BMW Car IT and others.
    + * All rights reserved. This program and the accompanying materials
    + * are made available under the terms of the Eclipse Public License v1.0
    + * which accompanies this distribution, and is available at
    + * http://www.eclipse.org/legal/epl-v10.html
    + */
    +package org.jnario.doc;
    +
    +import com.google.common.base.Objects;
    +import java.util.Arrays;
    +import org.eclipse.xtext.xbase.lib.Functions.Function1;
    +import org.eclipse.xtext.xbase.lib.IterableExtensions;
    +import org.jnario.util.Strings;
    +
    +@SuppressWarnings("all")
    +public class WhiteSpaceNormalizer {
    +  public String normalize(final CharSequence input) {
    +    String _xblockexpression = null;
    +    {
    +      if ((Objects.equal(input, null) || (input.length() == 0))) {
    +        return "";
    +      }
    +      Iterable lines = Arrays.asList(input.toString().split("\r?\n"));
    +      boolean _isEmpty = IterableExtensions.isEmpty(lines);
    +      if (_isEmpty) {
    +        return "";
    +      }
    +      String firstLine = IterableExtensions.head(lines);
    +      while ((firstLine.trim().length() == 0)) {
    +        {
    +          lines = IterableExtensions.drop(lines, 1);
    +          firstLine = IterableExtensions.head(lines);
    +          boolean _equals = Objects.equal(firstLine, null);
    +          if (_equals) {
    +            return "";
    +          }
    +        }
    +      }
    +      final String whitespace = this.whitespaceAtBeginning(firstLine);
    +      String ending = "";
    +      boolean _endsWith = Strings.endsWith(input, "\n");
    +      if (_endsWith) {
    +        ending = "\n";
    +      }
    +      final Function1 _function = new Function1() {
    +        @Override
    +        public String apply(final String it) {
    +          return WhiteSpaceNormalizer.this.remove(it, whitespace);
    +        }
    +      };
    +      String _join = IterableExtensions.join(IterableExtensions.map(lines, _function), "\n");
    +      String result = (_join + ending);
    +      _xblockexpression = result;
    +    }
    +    return _xblockexpression;
    +  }
    +  
    +  public String whitespaceAtBeginning(final String string) {
    +    final StringBuilder whitespace = new StringBuilder();
    +    char[] _charArray = string.toCharArray();
    +    for (final char c : _charArray) {
    +      boolean _isWhitespace = Character.isWhitespace(c);
    +      if (_isWhitespace) {
    +        whitespace.append(c);
    +      } else {
    +        return whitespace.toString();
    +      }
    +    }
    +    return "";
    +  }
    +  
    +  public String remove(final String input, final String toReplace) {
    +    int _length = input.length();
    +    int _length_1 = toReplace.length();
    +    boolean _lessThan = (_length < _length_1);
    +    if (_lessThan) {
    +      boolean _startsWith = toReplace.startsWith(input);
    +      if (_startsWith) {
    +        return "";
    +      } else {
    +        return input;
    +      }
    +    }
    +    int i = 0;
    +    while ((i < toReplace.length())) {
    +      {
    +        char _charAt = input.charAt(i);
    +        char _charAt_1 = toReplace.charAt(i);
    +        boolean _notEquals = (_charAt != _charAt_1);
    +        if (_notEquals) {
    +          return input;
    +        }
    +        i = (i + 1);
    +      }
    +    }
    +    return input.substring(toReplace.length());
    +  }
    +}
    diff --git a/plugins/org.jnario/xtend-gen/org/jnario/documentation/XtendDocumentationProvider.java b/plugins/org.jnario/xtend-gen/org/jnario/documentation/XtendDocumentationProvider.java
    index 61587d80d..fdc9aa77e 100644
    --- a/plugins/org.jnario/xtend-gen/org/jnario/documentation/XtendDocumentationProvider.java
    +++ b/plugins/org.jnario/xtend-gen/org/jnario/documentation/XtendDocumentationProvider.java
    @@ -1,48 +1,48 @@
    -package org.jnario.documentation;
    -
    -import com.google.common.base.Objects;
    -import java.util.List;
    -import org.eclipse.emf.ecore.EObject;
    -import org.eclipse.xtext.documentation.impl.MultiLineCommentDocumentationProvider;
    -import org.eclipse.xtext.nodemodel.INode;
    -import org.eclipse.xtext.xbase.lib.CollectionLiterals;
    -import org.jnario.JnarioAnnotationTarget;
    -import org.jnario.JnarioPackage;
    -
    -@SuppressWarnings("all")
    -public class XtendDocumentationProvider extends MultiLineCommentDocumentationProvider {
    -  @Override
    -  public String getDocumentation(final EObject o) {
    -    String _xblockexpression = null;
    -    {
    -      boolean _shouldBeHandeled = this.shouldBeHandeled(o);
    -      boolean _not = (!_shouldBeHandeled);
    -      if (_not) {
    -        return null;
    -      }
    -      _xblockexpression = super.getDocumentation(o);
    -    }
    -    return _xblockexpression;
    -  }
    -  
    -  @Override
    -  public List getDocumentationNodes(final EObject o) {
    -    List _xblockexpression = null;
    -    {
    -      boolean _shouldBeHandeled = this.shouldBeHandeled(o);
    -      boolean _not = (!_shouldBeHandeled);
    -      if (_not) {
    -        return CollectionLiterals.emptyList();
    -      }
    -      _xblockexpression = super.getDocumentationNodes(o);
    -    }
    -    return _xblockexpression;
    -  }
    -  
    -  /**
    -   * The Xtend parser constructs a synthetic nested AST element to hold annotations which should be ignored as a documentation provider
    -   */
    -  public boolean shouldBeHandeled(final EObject o) {
    -    return (!((o instanceof JnarioAnnotationTarget) && Objects.equal(o.eContainingFeature(), JnarioPackage.Literals.JNARIO_MEMBER__ANNOTATION_INFO)));
    -  }
    -}
    +package org.jnario.documentation;
    +
    +import com.google.common.base.Objects;
    +import java.util.List;
    +import org.eclipse.emf.ecore.EObject;
    +import org.eclipse.xtext.documentation.impl.MultiLineCommentDocumentationProvider;
    +import org.eclipse.xtext.nodemodel.INode;
    +import org.eclipse.xtext.xbase.lib.CollectionLiterals;
    +import org.jnario.JnarioAnnotationTarget;
    +import org.jnario.JnarioPackage;
    +
    +@SuppressWarnings("all")
    +public class XtendDocumentationProvider extends MultiLineCommentDocumentationProvider {
    +  @Override
    +  public String getDocumentation(final EObject o) {
    +    String _xblockexpression = null;
    +    {
    +      boolean _shouldBeHandeled = this.shouldBeHandeled(o);
    +      boolean _not = (!_shouldBeHandeled);
    +      if (_not) {
    +        return null;
    +      }
    +      _xblockexpression = super.getDocumentation(o);
    +    }
    +    return _xblockexpression;
    +  }
    +  
    +  @Override
    +  public List getDocumentationNodes(final EObject o) {
    +    List _xblockexpression = null;
    +    {
    +      boolean _shouldBeHandeled = this.shouldBeHandeled(o);
    +      boolean _not = (!_shouldBeHandeled);
    +      if (_not) {
    +        return CollectionLiterals.emptyList();
    +      }
    +      _xblockexpression = super.getDocumentationNodes(o);
    +    }
    +    return _xblockexpression;
    +  }
    +  
    +  /**
    +   * The Xtend parser constructs a synthetic nested AST element to hold annotations which should be ignored as a documentation provider
    +   */
    +  public boolean shouldBeHandeled(final EObject o) {
    +    return (!((o instanceof JnarioAnnotationTarget) && Objects.equal(o.eContainingFeature(), JnarioPackage.Literals.JNARIO_MEMBER__ANNOTATION_INFO)));
    +  }
    +}
    diff --git a/plugins/org.jnario/xtend-gen/org/jnario/formatter/JnarioFormatter.java b/plugins/org.jnario/xtend-gen/org/jnario/formatter/JnarioFormatter.java
    index 896d31c1c..90b0805bd 100644
    --- a/plugins/org.jnario/xtend-gen/org/jnario/formatter/JnarioFormatter.java
    +++ b/plugins/org.jnario/xtend-gen/org/jnario/formatter/JnarioFormatter.java
    @@ -1,378 +1,350 @@
    -package org.jnario.formatter;
    -
    -import com.google.common.base.Objects;
    -import java.util.Arrays;
    -import java.util.List;
    -import java.util.function.Consumer;
    -import org.eclipse.emf.common.util.EList;
    -import org.eclipse.emf.ecore.EObject;
    -import org.eclipse.xtext.common.types.JvmFormalParameter;
    -import org.eclipse.xtext.common.types.JvmGenericArrayTypeReference;
    -import org.eclipse.xtext.common.types.JvmParameterizedTypeReference;
    -import org.eclipse.xtext.common.types.JvmTypeConstraint;
    -import org.eclipse.xtext.common.types.JvmTypeParameter;
    -import org.eclipse.xtext.common.types.JvmTypeReference;
    -import org.eclipse.xtext.common.types.JvmWildcardTypeReference;
    -import org.eclipse.xtext.formatting2.IFormattableDocument;
    -import org.eclipse.xtext.formatting2.IHiddenRegionFormatter;
    -import org.eclipse.xtext.formatting2.regionaccess.IEObjectRegion;
    -import org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion;
    -import org.eclipse.xtext.formatting2.regionaccess.ISemanticRegionsFinder;
    -import org.eclipse.xtext.formatting2.regionaccess.ITextSegment;
    -import org.eclipse.xtext.nodemodel.ICompositeNode;
    -import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
    -import org.eclipse.xtext.resource.XtextResource;
    -import org.eclipse.xtext.xbase.XAssignment;
    -import org.eclipse.xtext.xbase.XBasicForLoopExpression;
    -import org.eclipse.xtext.xbase.XBinaryOperation;
    -import org.eclipse.xtext.xbase.XBlockExpression;
    -import org.eclipse.xtext.xbase.XCastedExpression;
    -import org.eclipse.xtext.xbase.XClosure;
    -import org.eclipse.xtext.xbase.XCollectionLiteral;
    -import org.eclipse.xtext.xbase.XConstructorCall;
    -import org.eclipse.xtext.xbase.XDoWhileExpression;
    -import org.eclipse.xtext.xbase.XExpression;
    -import org.eclipse.xtext.xbase.XFeatureCall;
    -import org.eclipse.xtext.xbase.XForLoopExpression;
    -import org.eclipse.xtext.xbase.XIfExpression;
    -import org.eclipse.xtext.xbase.XInstanceOfExpression;
    -import org.eclipse.xtext.xbase.XMemberFeatureCall;
    -import org.eclipse.xtext.xbase.XPostfixOperation;
    -import org.eclipse.xtext.xbase.XReturnExpression;
    -import org.eclipse.xtext.xbase.XSwitchExpression;
    -import org.eclipse.xtext.xbase.XSynchronizedExpression;
    -import org.eclipse.xtext.xbase.XThrowExpression;
    -import org.eclipse.xtext.xbase.XTryCatchFinallyExpression;
    -import org.eclipse.xtext.xbase.XTypeLiteral;
    -import org.eclipse.xtext.xbase.XVariableDeclaration;
    -import org.eclipse.xtext.xbase.XWhileExpression;
    -import org.eclipse.xtext.xbase.annotations.formatting2.XbaseWithAnnotationsFormatter;
    -import org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation;
    -import org.eclipse.xtext.xbase.lib.Conversions;
    -import org.eclipse.xtext.xbase.lib.Extension;
    -import org.eclipse.xtext.xbase.lib.Functions.Function1;
    -import org.eclipse.xtext.xbase.lib.Functions.Function2;
    -import org.eclipse.xtext.xbase.lib.IntegerRange;
    -import org.eclipse.xtext.xbase.lib.IterableExtensions;
    -import org.eclipse.xtext.xbase.lib.ListExtensions;
    -import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
    -import org.eclipse.xtext.xtype.XFunctionTypeRef;
    -import org.eclipse.xtext.xtype.XImportDeclaration;
    -import org.eclipse.xtext.xtype.XImportSection;
    -import org.jnario.ExampleCell;
    -import org.jnario.ExampleColumn;
    -import org.jnario.ExampleRow;
    -import org.jnario.JnarioPackage;
    -
    -/**
    - * TODO NO_XTEND - Verify implementation
    - * @author Sebastian Benz - Initial contribution and API
    - */
    -@SuppressWarnings("all")
    -public class JnarioFormatter extends XbaseWithAnnotationsFormatter {
    -  private void formatRows(final EList rows, @Extension final IFormattableDocument format) {
    -    final Consumer _function = new Consumer() {
    -      @Override
    -      public void accept(final ExampleRow it) {
    -        final Procedure1 _function = new Procedure1() {
    -          @Override
    -          public void apply(final IHiddenRegionFormatter it) {
    -            it.newLine();
    -          }
    -        };
    -        format.append(it, _function);
    -      }
    -    };
    -    rows.forEach(_function);
    -  }
    -  
    -  private void formatColumns(final EList columns, @Extension final IFormattableDocument format) {
    -    final Consumer _function = new Consumer() {
    -      @Override
    -      public void accept(final ExampleColumn it) {
    -        ISemanticRegionsFinder _regionFor = JnarioFormatter.this.textRegionExtensions.regionFor(it);
    -        final ISemanticRegion nameNode = _regionFor.feature(JnarioPackage.Literals.EXAMPLE_COLUMN__NAME);
    -        final JvmTypeReference typeNode = it.getType();
    -        int _xifexpression = (int) 0;
    -        boolean _equals = Objects.equal(typeNode, null);
    -        if (_equals) {
    -          _xifexpression = nameNode.getLength();
    -        } else {
    -          int _offset = nameNode.getOffset();
    -          int _length = nameNode.getLength();
    -          int _plus = (_offset + _length);
    -          IEObjectRegion _regionForEObject = JnarioFormatter.this.textRegionExtensions.regionForEObject(typeNode);
    -          int _offset_1 = _regionForEObject.getOffset();
    -          _xifexpression = (_plus - _offset_1);
    -        }
    -        final int headerLength = _xifexpression;
    -        Integer _elvis = null;
    -        EList _cells = it.getCells();
    -        final Function1 _function = new Function1() {
    -          @Override
    -          public Integer apply(final ExampleCell it) {
    -            XExpression _expression = it.getExpression();
    -            IEObjectRegion _regionForEObject = JnarioFormatter.this.textRegionExtensions.regionForEObject(_expression);
    -            return JnarioFormatter.this.getMultilineLength(format, _regionForEObject);
    -          }
    -        };
    -        List _map = ListExtensions.map(_cells, _function);
    -        final Function2 _function_1 = new Function2() {
    -          @Override
    -          public Integer apply(final Integer p1, final Integer p2) {
    -            return Integer.valueOf(Math.max((p1).intValue(), (p2).intValue()));
    -          }
    -        };
    -        Integer _reduce = IterableExtensions.reduce(_map, _function_1);
    -        if (_reduce != null) {
    -          _elvis = _reduce;
    -        } else {
    -          _elvis = Integer.valueOf(0);
    -        }
    -        final Integer maxExprLength = _elvis;
    -        final int maxLength = Math.max(headerLength, (maxExprLength).intValue());
    -        final int columnLength = ((1 + maxLength) - headerLength);
    -        final Procedure1 _function_2 = new Procedure1() {
    -          @Override
    -          public void apply(final IHiddenRegionFormatter it) {
    -            it.oneSpace();
    -          }
    -        };
    -        format.prepend(it, _function_2);
    -        ISemanticRegionsFinder _regionFor_1 = JnarioFormatter.this.textRegionExtensions.regionFor(it);
    -        ISemanticRegion _keyword = _regionFor_1.keyword("|");
    -        final Procedure1 _function_3 = new Procedure1() {
    -          @Override
    -          public void apply(final IHiddenRegionFormatter it) {
    -            JnarioFormatter.this.spaces(it, columnLength);
    -          }
    -        };
    -        format.prepend(_keyword, _function_3);
    -        EList _cells_1 = it.getCells();
    -        final Consumer _function_4 = new Consumer() {
    -          @Override
    -          public void accept(final ExampleCell it) {
    -            XExpression _expression = it.getExpression();
    -            final Procedure1 _function = new Procedure1() {
    -              @Override
    -              public void apply(final IHiddenRegionFormatter it) {
    -                it.oneSpace();
    -              }
    -            };
    -            format.prepend(_expression, _function);
    -            XExpression _expression_1 = it.getExpression();
    -            IEObjectRegion _regionForEObject = JnarioFormatter.this.textRegionExtensions.regionForEObject(_expression_1);
    -            int _multilineLastSegmentLength = JnarioFormatter.this.getMultilineLastSegmentLength(format, _regionForEObject);
    -            final int length = ((1 + maxLength) - _multilineLastSegmentLength);
    -            XExpression _expression_2 = it.getExpression();
    -            final Procedure1 _function_1 = new Procedure1() {
    -              @Override
    -              public void apply(final IHiddenRegionFormatter it) {
    -                JnarioFormatter.this.spaces(it, length);
    -              }
    -            };
    -            format.append(_expression_2, _function_1);
    -          }
    -        };
    -        _cells_1.forEach(_function_4);
    -      }
    -    };
    -    columns.forEach(_function);
    -    ExampleColumn _last = IterableExtensions.last(columns);
    -    final Procedure1 _function_1 = new Procedure1() {
    -      @Override
    -      public void apply(final IHiddenRegionFormatter it) {
    -        it.newLine();
    -      }
    -    };
    -    format.append(_last, _function_1);
    -  }
    -  
    -  public void spaces(final IHiddenRegionFormatter init, final int i) {
    -    IntegerRange _upTo = new IntegerRange(1, i);
    -    final Function2 _function = new Function2() {
    -      @Override
    -      public String apply(final String p1, final Integer p2) {
    -        return (p1 + " ");
    -      }
    -    };
    -    String _fold = IterableExtensions.fold(_upTo, "", _function);
    -    init.setSpace(_fold);
    -  }
    -  
    -  private String[] getSplittedMultilineCell(final IFormattableDocument format, final ITextSegment segment) {
    -    ITextSegment _region = format.getRegion();
    -    String _text = _region.getText();
    -    int _offset = segment.getOffset();
    -    ITextSegment _region_1 = format.getRegion();
    -    int _offset_1 = _region_1.getOffset();
    -    int _minus = (_offset - _offset_1);
    -    int _offset_2 = segment.getOffset();
    -    int _length = segment.getLength();
    -    int _plus = (_offset_2 + _length);
    -    ITextSegment _region_2 = format.getRegion();
    -    int _offset_3 = _region_2.getOffset();
    -    int _minus_1 = (_plus - _offset_3);
    -    String _substring = _text.substring(_minus, _minus_1);
    -    return _substring.split("\r?\n");
    -  }
    -  
    -  private int getMultilineLastSegmentLength(final IFormattableDocument format, final ITextSegment segment) {
    -    String[] _splittedMultilineCell = this.getSplittedMultilineCell(format, segment);
    -    String _last = IterableExtensions.last(((Iterable)Conversions.doWrapArray(_splittedMultilineCell)));
    -    String _trim = _last.trim();
    -    return _trim.length();
    -  }
    -  
    -  private Integer getMultilineLength(final IFormattableDocument format, final ITextSegment segment) {
    -    String[] _splittedMultilineCell = this.getSplittedMultilineCell(format, segment);
    -    final Function1 _function = new Function1() {
    -      @Override
    -      public Integer apply(final String it) {
    -        String _trim = it.trim();
    -        return Integer.valueOf(_trim.length());
    -      }
    -    };
    -    List _map = ListExtensions.map(((List)Conversions.doWrapArray(_splittedMultilineCell)), _function);
    -    final Function2 _function_1 = new Function2() {
    -      @Override
    -      public Integer apply(final Integer p1, final Integer p2) {
    -        return Integer.valueOf(Math.max((p1).intValue(), (p2).intValue()));
    -      }
    -    };
    -    return IterableExtensions.reduce(_map, _function_1);
    -  }
    -  
    -  /**
    -   * Hack: No node for type Void - prevent NullPointerException
    -   */
    -  @Override
    -  public void _format(final JvmParameterizedTypeReference type, final IFormattableDocument format) {
    -    ICompositeNode _findActualNodeFor = NodeModelUtils.findActualNodeFor(type);
    -    boolean _notEquals = (!Objects.equal(_findActualNodeFor, null));
    -    if (_notEquals) {
    -      super._format(type, format);
    -    }
    -  }
    -  
    -  public void format(final Object type, final IFormattableDocument format) {
    -    if (type instanceof JvmTypeParameter) {
    -      _format((JvmTypeParameter)type, format);
    -      return;
    -    } else if (type instanceof JvmFormalParameter) {
    -      _format((JvmFormalParameter)type, format);
    -      return;
    -    } else if (type instanceof XtextResource) {
    -      _format((XtextResource)type, format);
    -      return;
    -    } else if (type instanceof XAssignment) {
    -      _format((XAssignment)type, format);
    -      return;
    -    } else if (type instanceof XBinaryOperation) {
    -      _format((XBinaryOperation)type, format);
    -      return;
    -    } else if (type instanceof XDoWhileExpression) {
    -      _format((XDoWhileExpression)type, format);
    -      return;
    -    } else if (type instanceof XFeatureCall) {
    -      _format((XFeatureCall)type, format);
    -      return;
    -    } else if (type instanceof XMemberFeatureCall) {
    -      _format((XMemberFeatureCall)type, format);
    -      return;
    -    } else if (type instanceof XPostfixOperation) {
    -      _format((XPostfixOperation)type, format);
    -      return;
    -    } else if (type instanceof XWhileExpression) {
    -      _format((XWhileExpression)type, format);
    -      return;
    -    } else if (type instanceof XFunctionTypeRef) {
    -      _format((XFunctionTypeRef)type, format);
    -      return;
    -    } else if (type instanceof JvmGenericArrayTypeReference) {
    -      _format((JvmGenericArrayTypeReference)type, format);
    -      return;
    -    } else if (type instanceof JvmParameterizedTypeReference) {
    -      _format((JvmParameterizedTypeReference)type, format);
    -      return;
    -    } else if (type instanceof JvmWildcardTypeReference) {
    -      _format((JvmWildcardTypeReference)type, format);
    -      return;
    -    } else if (type instanceof XBasicForLoopExpression) {
    -      _format((XBasicForLoopExpression)type, format);
    -      return;
    -    } else if (type instanceof XBlockExpression) {
    -      _format((XBlockExpression)type, format);
    -      return;
    -    } else if (type instanceof XCastedExpression) {
    -      _format((XCastedExpression)type, format);
    -      return;
    -    } else if (type instanceof XClosure) {
    -      _format((XClosure)type, format);
    -      return;
    -    } else if (type instanceof XCollectionLiteral) {
    -      _format((XCollectionLiteral)type, format);
    -      return;
    -    } else if (type instanceof XConstructorCall) {
    -      _format((XConstructorCall)type, format);
    -      return;
    -    } else if (type instanceof XForLoopExpression) {
    -      _format((XForLoopExpression)type, format);
    -      return;
    -    } else if (type instanceof XIfExpression) {
    -      _format((XIfExpression)type, format);
    -      return;
    -    } else if (type instanceof XInstanceOfExpression) {
    -      _format((XInstanceOfExpression)type, format);
    -      return;
    -    } else if (type instanceof XReturnExpression) {
    -      _format((XReturnExpression)type, format);
    -      return;
    -    } else if (type instanceof XSwitchExpression) {
    -      _format((XSwitchExpression)type, format);
    -      return;
    -    } else if (type instanceof XSynchronizedExpression) {
    -      _format((XSynchronizedExpression)type, format);
    -      return;
    -    } else if (type instanceof XThrowExpression) {
    -      _format((XThrowExpression)type, format);
    -      return;
    -    } else if (type instanceof XTryCatchFinallyExpression) {
    -      _format((XTryCatchFinallyExpression)type, format);
    -      return;
    -    } else if (type instanceof XTypeLiteral) {
    -      _format((XTypeLiteral)type, format);
    -      return;
    -    } else if (type instanceof XVariableDeclaration) {
    -      _format((XVariableDeclaration)type, format);
    -      return;
    -    } else if (type instanceof XAnnotation) {
    -      _format((XAnnotation)type, format);
    -      return;
    -    } else if (type instanceof JvmTypeConstraint) {
    -      _format((JvmTypeConstraint)type, format);
    -      return;
    -    } else if (type instanceof XExpression) {
    -      _format((XExpression)type, format);
    -      return;
    -    } else if (type instanceof XImportDeclaration) {
    -      _format((XImportDeclaration)type, format);
    -      return;
    -    } else if (type instanceof XImportSection) {
    -      _format((XImportSection)type, format);
    -      return;
    -    } else if (type instanceof EObject) {
    -      _format((EObject)type, format);
    -      return;
    -    } else if (type == null) {
    -      _format((Void)null, format);
    -      return;
    -    } else if (type != null) {
    -      _format(type, format);
    -      return;
    -    } else {
    -      throw new IllegalArgumentException("Unhandled parameter types: " +
    -        Arrays.asList(type, format).toString());
    -    }
    -  }
    -}
    +package org.jnario.formatter;
    +
    +import com.google.common.base.Objects;
    +import java.util.Arrays;
    +import java.util.List;
    +import java.util.function.Consumer;
    +import org.eclipse.emf.common.util.EList;
    +import org.eclipse.emf.ecore.EObject;
    +import org.eclipse.xtext.common.types.JvmFormalParameter;
    +import org.eclipse.xtext.common.types.JvmGenericArrayTypeReference;
    +import org.eclipse.xtext.common.types.JvmParameterizedTypeReference;
    +import org.eclipse.xtext.common.types.JvmTypeConstraint;
    +import org.eclipse.xtext.common.types.JvmTypeParameter;
    +import org.eclipse.xtext.common.types.JvmTypeReference;
    +import org.eclipse.xtext.common.types.JvmWildcardTypeReference;
    +import org.eclipse.xtext.formatting2.IFormattableDocument;
    +import org.eclipse.xtext.formatting2.IHiddenRegionFormatter;
    +import org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion;
    +import org.eclipse.xtext.formatting2.regionaccess.ITextSegment;
    +import org.eclipse.xtext.nodemodel.ICompositeNode;
    +import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
    +import org.eclipse.xtext.resource.XtextResource;
    +import org.eclipse.xtext.xbase.XAssignment;
    +import org.eclipse.xtext.xbase.XBasicForLoopExpression;
    +import org.eclipse.xtext.xbase.XBinaryOperation;
    +import org.eclipse.xtext.xbase.XBlockExpression;
    +import org.eclipse.xtext.xbase.XCastedExpression;
    +import org.eclipse.xtext.xbase.XClosure;
    +import org.eclipse.xtext.xbase.XCollectionLiteral;
    +import org.eclipse.xtext.xbase.XConstructorCall;
    +import org.eclipse.xtext.xbase.XDoWhileExpression;
    +import org.eclipse.xtext.xbase.XExpression;
    +import org.eclipse.xtext.xbase.XFeatureCall;
    +import org.eclipse.xtext.xbase.XForLoopExpression;
    +import org.eclipse.xtext.xbase.XIfExpression;
    +import org.eclipse.xtext.xbase.XInstanceOfExpression;
    +import org.eclipse.xtext.xbase.XMemberFeatureCall;
    +import org.eclipse.xtext.xbase.XPostfixOperation;
    +import org.eclipse.xtext.xbase.XReturnExpression;
    +import org.eclipse.xtext.xbase.XSwitchExpression;
    +import org.eclipse.xtext.xbase.XSynchronizedExpression;
    +import org.eclipse.xtext.xbase.XThrowExpression;
    +import org.eclipse.xtext.xbase.XTryCatchFinallyExpression;
    +import org.eclipse.xtext.xbase.XTypeLiteral;
    +import org.eclipse.xtext.xbase.XVariableDeclaration;
    +import org.eclipse.xtext.xbase.XWhileExpression;
    +import org.eclipse.xtext.xbase.annotations.formatting2.XbaseWithAnnotationsFormatter;
    +import org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation;
    +import org.eclipse.xtext.xbase.lib.Conversions;
    +import org.eclipse.xtext.xbase.lib.Extension;
    +import org.eclipse.xtext.xbase.lib.Functions.Function1;
    +import org.eclipse.xtext.xbase.lib.Functions.Function2;
    +import org.eclipse.xtext.xbase.lib.IntegerRange;
    +import org.eclipse.xtext.xbase.lib.IterableExtensions;
    +import org.eclipse.xtext.xbase.lib.ListExtensions;
    +import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
    +import org.eclipse.xtext.xtype.XFunctionTypeRef;
    +import org.eclipse.xtext.xtype.XImportDeclaration;
    +import org.eclipse.xtext.xtype.XImportSection;
    +import org.jnario.ExampleCell;
    +import org.jnario.ExampleColumn;
    +import org.jnario.ExampleRow;
    +import org.jnario.JnarioPackage;
    +
    +/**
    + * TODO NO_XTEND - Verify implementation
    + * @author Sebastian Benz - Initial contribution and API
    + */
    +@SuppressWarnings("all")
    +public class JnarioFormatter extends XbaseWithAnnotationsFormatter {
    +  private void formatRows(final EList rows, @Extension final IFormattableDocument format) {
    +    final Consumer _function = new Consumer() {
    +      @Override
    +      public void accept(final ExampleRow it) {
    +        final Procedure1 _function = new Procedure1() {
    +          @Override
    +          public void apply(final IHiddenRegionFormatter it) {
    +            it.newLine();
    +          }
    +        };
    +        format.append(it, _function);
    +      }
    +    };
    +    rows.forEach(_function);
    +  }
    +  
    +  private void formatColumns(final EList columns, @Extension final IFormattableDocument format) {
    +    final Consumer _function = new Consumer() {
    +      @Override
    +      public void accept(final ExampleColumn it) {
    +        final ISemanticRegion nameNode = JnarioFormatter.this.textRegionExtensions.regionFor(it).feature(JnarioPackage.Literals.EXAMPLE_COLUMN__NAME);
    +        final JvmTypeReference typeNode = it.getType();
    +        int _xifexpression = (int) 0;
    +        boolean _equals = Objects.equal(typeNode, null);
    +        if (_equals) {
    +          _xifexpression = nameNode.getLength();
    +        } else {
    +          int _offset = nameNode.getOffset();
    +          int _length = nameNode.getLength();
    +          int _plus = (_offset + _length);
    +          int _offset_1 = JnarioFormatter.this.textRegionExtensions.regionForEObject(typeNode).getOffset();
    +          _xifexpression = (_plus - _offset_1);
    +        }
    +        final int headerLength = _xifexpression;
    +        Integer _elvis = null;
    +        final Function1 _function = new Function1() {
    +          @Override
    +          public Integer apply(final ExampleCell it) {
    +            return JnarioFormatter.this.getMultilineLength(format, JnarioFormatter.this.textRegionExtensions.regionForEObject(it.getExpression()));
    +          }
    +        };
    +        final Function2 _function_1 = new Function2() {
    +          @Override
    +          public Integer apply(final Integer p1, final Integer p2) {
    +            return Integer.valueOf(Math.max((p1).intValue(), (p2).intValue()));
    +          }
    +        };
    +        Integer _reduce = IterableExtensions.reduce(ListExtensions.map(it.getCells(), _function), _function_1);
    +        if (_reduce != null) {
    +          _elvis = _reduce;
    +        } else {
    +          _elvis = Integer.valueOf(0);
    +        }
    +        final Integer maxExprLength = _elvis;
    +        final int maxLength = Math.max(headerLength, (maxExprLength).intValue());
    +        final int columnLength = ((1 + maxLength) - headerLength);
    +        final Procedure1 _function_2 = new Procedure1() {
    +          @Override
    +          public void apply(final IHiddenRegionFormatter it) {
    +            it.oneSpace();
    +          }
    +        };
    +        format.prepend(it, _function_2);
    +        final Procedure1 _function_3 = new Procedure1() {
    +          @Override
    +          public void apply(final IHiddenRegionFormatter it) {
    +            JnarioFormatter.this.spaces(it, columnLength);
    +          }
    +        };
    +        format.prepend(JnarioFormatter.this.textRegionExtensions.regionFor(it).keyword("|"), _function_3);
    +        final Consumer _function_4 = new Consumer() {
    +          @Override
    +          public void accept(final ExampleCell it) {
    +            final Procedure1 _function = new Procedure1() {
    +              @Override
    +              public void apply(final IHiddenRegionFormatter it) {
    +                it.oneSpace();
    +              }
    +            };
    +            format.prepend(it.getExpression(), _function);
    +            int _multilineLastSegmentLength = JnarioFormatter.this.getMultilineLastSegmentLength(format, JnarioFormatter.this.textRegionExtensions.regionForEObject(it.getExpression()));
    +            final int length = ((1 + maxLength) - _multilineLastSegmentLength);
    +            final Procedure1 _function_1 = new Procedure1() {
    +              @Override
    +              public void apply(final IHiddenRegionFormatter it) {
    +                JnarioFormatter.this.spaces(it, length);
    +              }
    +            };
    +            format.append(it.getExpression(), _function_1);
    +          }
    +        };
    +        it.getCells().forEach(_function_4);
    +      }
    +    };
    +    columns.forEach(_function);
    +    final Procedure1 _function_1 = new Procedure1() {
    +      @Override
    +      public void apply(final IHiddenRegionFormatter it) {
    +        it.newLine();
    +      }
    +    };
    +    format.append(IterableExtensions.last(columns), _function_1);
    +  }
    +  
    +  public void spaces(final IHiddenRegionFormatter init, final int i) {
    +    final Function2 _function = new Function2() {
    +      @Override
    +      public String apply(final String p1, final Integer p2) {
    +        return (p1 + " ");
    +      }
    +    };
    +    init.setSpace(IterableExtensions.fold(new IntegerRange(1, i), "", _function));
    +  }
    +  
    +  private String[] getSplittedMultilineCell(final IFormattableDocument format, final ITextSegment segment) {
    +    String _text = format.getRegion().getText();
    +    int _offset = segment.getOffset();
    +    int _offset_1 = format.getRegion().getOffset();
    +    int _minus = (_offset - _offset_1);
    +    int _offset_2 = segment.getOffset();
    +    int _length = segment.getLength();
    +    int _plus = (_offset_2 + _length);
    +    int _offset_3 = format.getRegion().getOffset();
    +    int _minus_1 = (_plus - _offset_3);
    +    return _text.substring(_minus, _minus_1).split("\r?\n");
    +  }
    +  
    +  private int getMultilineLastSegmentLength(final IFormattableDocument format, final ITextSegment segment) {
    +    return IterableExtensions.last(((Iterable)Conversions.doWrapArray(this.getSplittedMultilineCell(format, segment)))).trim().length();
    +  }
    +  
    +  private Integer getMultilineLength(final IFormattableDocument format, final ITextSegment segment) {
    +    final Function1 _function = new Function1() {
    +      @Override
    +      public Integer apply(final String it) {
    +        return Integer.valueOf(it.trim().length());
    +      }
    +    };
    +    final Function2 _function_1 = new Function2() {
    +      @Override
    +      public Integer apply(final Integer p1, final Integer p2) {
    +        return Integer.valueOf(Math.max((p1).intValue(), (p2).intValue()));
    +      }
    +    };
    +    return IterableExtensions.reduce(ListExtensions.map(((List)Conversions.doWrapArray(this.getSplittedMultilineCell(format, segment))), _function), _function_1);
    +  }
    +  
    +  /**
    +   * Hack: No node for type Void - prevent NullPointerException
    +   */
    +  @Override
    +  public void _format(final JvmParameterizedTypeReference type, final IFormattableDocument format) {
    +    ICompositeNode _findActualNodeFor = NodeModelUtils.findActualNodeFor(type);
    +    boolean _notEquals = (!Objects.equal(_findActualNodeFor, null));
    +    if (_notEquals) {
    +      super._format(type, format);
    +    }
    +  }
    +  
    +  public void format(final Object type, final IFormattableDocument format) {
    +    if (type instanceof JvmTypeParameter) {
    +      _format((JvmTypeParameter)type, format);
    +      return;
    +    } else if (type instanceof JvmFormalParameter) {
    +      _format((JvmFormalParameter)type, format);
    +      return;
    +    } else if (type instanceof XtextResource) {
    +      _format((XtextResource)type, format);
    +      return;
    +    } else if (type instanceof XAssignment) {
    +      _format((XAssignment)type, format);
    +      return;
    +    } else if (type instanceof XBinaryOperation) {
    +      _format((XBinaryOperation)type, format);
    +      return;
    +    } else if (type instanceof XDoWhileExpression) {
    +      _format((XDoWhileExpression)type, format);
    +      return;
    +    } else if (type instanceof XFeatureCall) {
    +      _format((XFeatureCall)type, format);
    +      return;
    +    } else if (type instanceof XMemberFeatureCall) {
    +      _format((XMemberFeatureCall)type, format);
    +      return;
    +    } else if (type instanceof XPostfixOperation) {
    +      _format((XPostfixOperation)type, format);
    +      return;
    +    } else if (type instanceof XWhileExpression) {
    +      _format((XWhileExpression)type, format);
    +      return;
    +    } else if (type instanceof XFunctionTypeRef) {
    +      _format((XFunctionTypeRef)type, format);
    +      return;
    +    } else if (type instanceof JvmGenericArrayTypeReference) {
    +      _format((JvmGenericArrayTypeReference)type, format);
    +      return;
    +    } else if (type instanceof JvmParameterizedTypeReference) {
    +      _format((JvmParameterizedTypeReference)type, format);
    +      return;
    +    } else if (type instanceof JvmWildcardTypeReference) {
    +      _format((JvmWildcardTypeReference)type, format);
    +      return;
    +    } else if (type instanceof XBasicForLoopExpression) {
    +      _format((XBasicForLoopExpression)type, format);
    +      return;
    +    } else if (type instanceof XBlockExpression) {
    +      _format((XBlockExpression)type, format);
    +      return;
    +    } else if (type instanceof XCastedExpression) {
    +      _format((XCastedExpression)type, format);
    +      return;
    +    } else if (type instanceof XClosure) {
    +      _format((XClosure)type, format);
    +      return;
    +    } else if (type instanceof XCollectionLiteral) {
    +      _format((XCollectionLiteral)type, format);
    +      return;
    +    } else if (type instanceof XConstructorCall) {
    +      _format((XConstructorCall)type, format);
    +      return;
    +    } else if (type instanceof XForLoopExpression) {
    +      _format((XForLoopExpression)type, format);
    +      return;
    +    } else if (type instanceof XIfExpression) {
    +      _format((XIfExpression)type, format);
    +      return;
    +    } else if (type instanceof XInstanceOfExpression) {
    +      _format((XInstanceOfExpression)type, format);
    +      return;
    +    } else if (type instanceof XReturnExpression) {
    +      _format((XReturnExpression)type, format);
    +      return;
    +    } else if (type instanceof XSwitchExpression) {
    +      _format((XSwitchExpression)type, format);
    +      return;
    +    } else if (type instanceof XSynchronizedExpression) {
    +      _format((XSynchronizedExpression)type, format);
    +      return;
    +    } else if (type instanceof XThrowExpression) {
    +      _format((XThrowExpression)type, format);
    +      return;
    +    } else if (type instanceof XTryCatchFinallyExpression) {
    +      _format((XTryCatchFinallyExpression)type, format);
    +      return;
    +    } else if (type instanceof XTypeLiteral) {
    +      _format((XTypeLiteral)type, format);
    +      return;
    +    } else if (type instanceof XVariableDeclaration) {
    +      _format((XVariableDeclaration)type, format);
    +      return;
    +    } else if (type instanceof XAnnotation) {
    +      _format((XAnnotation)type, format);
    +      return;
    +    } else if (type instanceof JvmTypeConstraint) {
    +      _format((JvmTypeConstraint)type, format);
    +      return;
    +    } else if (type instanceof XExpression) {
    +      _format((XExpression)type, format);
    +      return;
    +    } else if (type instanceof XImportDeclaration) {
    +      _format((XImportDeclaration)type, format);
    +      return;
    +    } else if (type instanceof XImportSection) {
    +      _format((XImportSection)type, format);
    +      return;
    +    } else if (type instanceof EObject) {
    +      _format((EObject)type, format);
    +      return;
    +    } else if (type == null) {
    +      _format((Void)null, format);
    +      return;
    +    } else if (type != null) {
    +      _format(type, format);
    +      return;
    +    } else {
    +      throw new IllegalArgumentException("Unhandled parameter types: " +
    +        Arrays.asList(type, format).toString());
    +    }
    +  }
    +}
    diff --git a/plugins/org.jnario/xtend-gen/org/jnario/formatter/JnarioNodeModelAccess.java b/plugins/org.jnario/xtend-gen/org/jnario/formatter/JnarioNodeModelAccess.java
    index c54e1fecb..db0c53c1e 100644
    --- a/plugins/org.jnario/xtend-gen/org/jnario/formatter/JnarioNodeModelAccess.java
    +++ b/plugins/org.jnario/xtend-gen/org/jnario/formatter/JnarioNodeModelAccess.java
    @@ -1,48 +1,46 @@
    -package org.jnario.formatter;
    -
    -import com.google.common.base.Objects;
    -import java.util.Collections;
    -import java.util.List;
    -import org.eclipse.emf.ecore.EObject;
    -import org.eclipse.xtext.Keyword;
    -import org.eclipse.xtext.nodemodel.BidiTreeIterable;
    -import org.eclipse.xtext.nodemodel.ICompositeNode;
    -import org.eclipse.xtext.nodemodel.ILeafNode;
    -import org.eclipse.xtext.nodemodel.INode;
    -import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
    -import org.eclipse.xtext.xbase.formatting.NodeModelAccess;
    -import org.eclipse.xtext.xbase.lib.CollectionLiterals;
    -import org.eclipse.xtext.xbase.lib.Functions.Function1;
    -import org.eclipse.xtext.xbase.lib.IterableExtensions;
    -
    -@SuppressWarnings("all")
    -public class JnarioNodeModelAccess extends NodeModelAccess {
    -  @Override
    -  public Iterable nodesForKeyword(final EObject obj, final String kw) {
    -    List _xblockexpression = null;
    -    {
    -      final ICompositeNode node = NodeModelUtils.findActualNodeFor(obj);
    -      boolean _equals = Objects.equal(node, null);
    -      if (_equals) {
    -        return Collections.unmodifiableList(CollectionLiterals.newArrayList());
    -      }
    -      BidiTreeIterable _asTreeIterable = node.getAsTreeIterable();
    -      final Function1 _function = new Function1() {
    -        @Override
    -        public Boolean apply(final INode it) {
    -          return Boolean.valueOf(((Objects.equal(it.getSemanticElement(), obj) && (it.getGrammarElement() instanceof Keyword)) && Objects.equal(it.getText(), kw)));
    -        }
    -      };
    -      INode _findFirst = IterableExtensions.findFirst(_asTreeIterable, _function);
    -      final ILeafNode leafNode = ((ILeafNode) _findFirst);
    -      List _xifexpression = null;
    -      if ((leafNode == null)) {
    -        _xifexpression = Collections.unmodifiableList(CollectionLiterals.newArrayList());
    -      } else {
    -        _xifexpression = Collections.unmodifiableList(CollectionLiterals.newArrayList(leafNode));
    -      }
    -      _xblockexpression = _xifexpression;
    -    }
    -    return _xblockexpression;
    -  }
    -}
    +package org.jnario.formatter;
    +
    +import com.google.common.base.Objects;
    +import java.util.Collections;
    +import java.util.List;
    +import org.eclipse.emf.ecore.EObject;
    +import org.eclipse.xtext.Keyword;
    +import org.eclipse.xtext.nodemodel.ICompositeNode;
    +import org.eclipse.xtext.nodemodel.ILeafNode;
    +import org.eclipse.xtext.nodemodel.INode;
    +import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
    +import org.eclipse.xtext.xbase.formatting.NodeModelAccess;
    +import org.eclipse.xtext.xbase.lib.CollectionLiterals;
    +import org.eclipse.xtext.xbase.lib.Functions.Function1;
    +import org.eclipse.xtext.xbase.lib.IterableExtensions;
    +
    +@SuppressWarnings("all")
    +public class JnarioNodeModelAccess extends NodeModelAccess {
    +  @Override
    +  public Iterable nodesForKeyword(final EObject obj, final String kw) {
    +    List _xblockexpression = null;
    +    {
    +      final ICompositeNode node = NodeModelUtils.findActualNodeFor(obj);
    +      boolean _equals = Objects.equal(node, null);
    +      if (_equals) {
    +        return Collections.unmodifiableList(CollectionLiterals.newArrayList());
    +      }
    +      final Function1 _function = new Function1() {
    +        @Override
    +        public Boolean apply(final INode it) {
    +          return Boolean.valueOf(((Objects.equal(it.getSemanticElement(), obj) && (it.getGrammarElement() instanceof Keyword)) && Objects.equal(it.getText(), kw)));
    +        }
    +      };
    +      INode _findFirst = IterableExtensions.findFirst(node.getAsTreeIterable(), _function);
    +      final ILeafNode leafNode = ((ILeafNode) _findFirst);
    +      List _xifexpression = null;
    +      if ((leafNode == null)) {
    +        _xifexpression = Collections.unmodifiableList(CollectionLiterals.newArrayList());
    +      } else {
    +        _xifexpression = Collections.unmodifiableList(CollectionLiterals.newArrayList(leafNode));
    +      }
    +      _xblockexpression = _xifexpression;
    +    }
    +    return _xblockexpression;
    +  }
    +}
    diff --git a/plugins/org.jnario/xtend-gen/org/jnario/jvmmodel/ExtendedJvmModelGenerator.java b/plugins/org.jnario/xtend-gen/org/jnario/jvmmodel/ExtendedJvmModelGenerator.java
    index 7adc42354..140c2cc2c 100644
    --- a/plugins/org.jnario/xtend-gen/org/jnario/jvmmodel/ExtendedJvmModelGenerator.java
    +++ b/plugins/org.jnario/xtend-gen/org/jnario/jvmmodel/ExtendedJvmModelGenerator.java
    @@ -1,14 +1,14 @@
    -/**
    - * Copyright (c) 2012 BMW Car IT and others.
    - * All rights reserved. This program and the accompanying materials
    - * are made available under the terms of the Eclipse Public License v1.0
    - * which accompanies this distribution, and is available at
    - * http://www.eclipse.org/legal/epl-v10.html
    - */
    -package org.jnario.jvmmodel;
    -
    -import org.eclipse.xtext.xbase.compiler.JvmModelGenerator;
    -
    -@SuppressWarnings("all")
    -public class ExtendedJvmModelGenerator extends JvmModelGenerator {
    -}
    +/**
    + * Copyright (c) 2012 BMW Car IT and others.
    + * All rights reserved. This program and the accompanying materials
    + * are made available under the terms of the Eclipse Public License v1.0
    + * which accompanies this distribution, and is available at
    + * http://www.eclipse.org/legal/epl-v10.html
    + */
    +package org.jnario.jvmmodel;
    +
    +import org.eclipse.xtext.xbase.compiler.JvmModelGenerator;
    +
    +@SuppressWarnings("all")
    +public class ExtendedJvmModelGenerator extends JvmModelGenerator {
    +}
    diff --git a/plugins/org.jnario/xtend-gen/org/jnario/jvmmodel/JUnit3RuntimeSupport.java b/plugins/org.jnario/xtend-gen/org/jnario/jvmmodel/JUnit3RuntimeSupport.java
    index 63de66fb1..ddfac7e23 100644
    --- a/plugins/org.jnario/xtend-gen/org/jnario/jvmmodel/JUnit3RuntimeSupport.java
    +++ b/plugins/org.jnario/xtend-gen/org/jnario/jvmmodel/JUnit3RuntimeSupport.java
    @@ -1,502 +1,476 @@
    -package org.jnario.jvmmodel;
    -
    -import com.google.common.base.Objects;
    -import com.google.common.collect.Iterables;
    -import com.google.inject.Inject;
    -import java.util.Collection;
    -import java.util.List;
    -import org.eclipse.emf.common.util.EList;
    -import org.eclipse.emf.ecore.EClass;
    -import org.eclipse.xtend2.lib.StringConcatenation;
    -import org.eclipse.xtext.common.types.JvmConstructor;
    -import org.eclipse.xtext.common.types.JvmField;
    -import org.eclipse.xtext.common.types.JvmFormalParameter;
    -import org.eclipse.xtext.common.types.JvmGenericType;
    -import org.eclipse.xtext.common.types.JvmMember;
    -import org.eclipse.xtext.common.types.JvmOperation;
    -import org.eclipse.xtext.common.types.JvmTypeReference;
    -import org.eclipse.xtext.common.types.JvmVisibility;
    -import org.eclipse.xtext.common.types.util.TypeReferences;
    -import org.eclipse.xtext.xbase.compiler.output.ITreeAppendable;
    -import org.eclipse.xtext.xbase.lib.CollectionLiterals;
    -import org.eclipse.xtext.xbase.lib.Extension;
    -import org.eclipse.xtext.xbase.lib.Functions.Function1;
    -import org.eclipse.xtext.xbase.lib.IterableExtensions;
    -import org.eclipse.xtext.xbase.lib.ListExtensions;
    -import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
    -import org.jnario.Executable;
    -import org.jnario.JnarioClass;
    -import org.jnario.JnarioFunction;
    -import org.jnario.JnarioMember;
    -import org.jnario.Specification;
    -import org.jnario.jvmmodel.ExtendedJvmTypesBuilder;
    -import org.jnario.jvmmodel.JnarioNameProvider;
    -import org.jnario.jvmmodel.TestRuntimeSupport;
    -
    -@SuppressWarnings("all")
    -public class JUnit3RuntimeSupport implements TestRuntimeSupport {
    -  @Inject
    -  @Extension
    -  private TypeReferences _typeReferences;
    -  
    -  @Inject
    -  @Extension
    -  private JnarioNameProvider _jnarioNameProvider;
    -  
    -  @Inject
    -  @Extension
    -  private ExtendedJvmTypesBuilder _extendedJvmTypesBuilder;
    -  
    -  @Override
    -  public void afterAllMethod(final JnarioMember before, final JvmOperation operation) {
    -  }
    -  
    -  @Override
    -  public void afterMethod(final JnarioMember before, final JvmOperation operation) {
    -  }
    -  
    -  @Override
    -  public void beforeAllMethod(final JnarioMember before, final JvmOperation operation) {
    -  }
    -  
    -  @Override
    -  public void beforeMethod(final JnarioMember before, final JvmOperation operation) {
    -  }
    -  
    -  @Override
    -  public void markAsPending(final Executable element, final JvmOperation operation) {
    -  }
    -  
    -  @Override
    -  public void addChildren(final Specification context, final JvmGenericType parent, final Collection children) {
    -    EClass _eClass = context.eClass();
    -    String _name = _eClass.getName();
    -    boolean _equals = Objects.equal(_name, "Suite");
    -    if (_equals) {
    -      final Function1 _function = new Function1() {
    -        @Override
    -        public String apply(final JvmTypeReference it) {
    -          return it.getSimpleName();
    -        }
    -      };
    -      Iterable _map = IterableExtensions.map(children, _function);
    -      List _emptyList = CollectionLiterals.emptyList();
    -      this.addSuite(parent, context, _map, _emptyList);
    -    }
    -  }
    -  
    -  @Override
    -  public void updateExampleGroup(final JnarioClass exampleGroup, final JvmGenericType inferredType) {
    -    this.makeTestCase(exampleGroup, inferredType);
    -    this.addTestCase(inferredType, exampleGroup);
    -    Iterable _children = this.children(exampleGroup);
    -    Iterable _examples = this.examples(exampleGroup);
    -    this.addSuite(inferredType, exampleGroup, _children, _examples);
    -    Iterable _befores = this.befores(exampleGroup);
    -    this.generateSetup("setUp", exampleGroup, inferredType, _befores);
    -    Iterable _afters = this.afters(exampleGroup);
    -    this.generateSetup("tearDown", exampleGroup, inferredType, _afters);
    -  }
    -  
    -  public boolean generateSetup(final String methodName, final JnarioClass exampleGroup, final JvmGenericType type, final Iterable executables) {
    -    boolean _xblockexpression = false;
    -    {
    -      final JvmTypeReference voidType = this._typeReferences.getTypeForName(Void.TYPE, exampleGroup);
    -      EList _members = type.getMembers();
    -      final Procedure1 _function = new Procedure1() {
    -        @Override
    -        public void apply(final JvmOperation it) {
    -          it.setVisibility(JvmVisibility.PUBLIC);
    -          EList _exceptions = it.getExceptions();
    -          JvmTypeReference _typeForName = JUnit3RuntimeSupport.this._typeReferences.getTypeForName(Exception.class, exampleGroup);
    -          JUnit3RuntimeSupport.this._extendedJvmTypesBuilder.operator_add(_exceptions, _typeForName);
    -          final Procedure1 _function = new Procedure1() {
    -            @Override
    -            public void apply(final ITreeAppendable it) {
    -              StringConcatenation _builder = new StringConcatenation();
    -              _builder.append("super.");
    -              _builder.append(methodName, "");
    -              _builder.append("();");
    -              _builder.newLineIfNotEmpty();
    -              {
    -                for(final JnarioFunction executable : executables) {
    -                  String _methodName = JUnit3RuntimeSupport.this._jnarioNameProvider.toMethodName(executable);
    -                  _builder.append(_methodName, "");
    -                  _builder.append("();");
    -                  _builder.newLineIfNotEmpty();
    -                }
    -              }
    -              it.append(_builder);
    -            }
    -          };
    -          JUnit3RuntimeSupport.this._extendedJvmTypesBuilder.setBody(it, _function);
    -        }
    -      };
    -      JvmOperation _method = this._extendedJvmTypesBuilder.toMethod(exampleGroup, methodName, voidType, _function);
    -      _xblockexpression = this._extendedJvmTypesBuilder.operator_add(_members, _method);
    -    }
    -    return _xblockexpression;
    -  }
    -  
    -  private Iterable befores(final JnarioClass exampleGroup) {
    -    EList _members = exampleGroup.getMembers();
    -    Iterable _filter = Iterables.filter(_members, JnarioFunction.class);
    -    final Function1 _function = new Function1() {
    -      @Override
    -      public Boolean apply(final JnarioFunction it) {
    -        EClass _eClass = it.eClass();
    -        String _name = _eClass.getName();
    -        return Boolean.valueOf(Objects.equal(_name, "Before"));
    -      }
    -    };
    -    return IterableExtensions.filter(_filter, _function);
    -  }
    -  
    -  private Iterable afters(final JnarioClass exampleGroup) {
    -    EList _members = exampleGroup.getMembers();
    -    Iterable _filter = Iterables.filter(_members, JnarioFunction.class);
    -    final Function1 _function = new Function1() {
    -      @Override
    -      public Boolean apply(final JnarioFunction it) {
    -        EClass _eClass = it.eClass();
    -        String _name = _eClass.getName();
    -        return Boolean.valueOf(Objects.equal(_name, "After"));
    -      }
    -    };
    -    return IterableExtensions.filter(_filter, _function);
    -  }
    -  
    -  private boolean addSuite(final JvmGenericType it, final JnarioClass context, final Iterable children, final Iterable tests) {
    -    boolean _xblockexpression = false;
    -    {
    -      final JvmTypeReference testType = this._typeReferences.getTypeForName("junit.framework.Test", context);
    -      EList _members = it.getMembers();
    -      final Procedure1 _function = new Procedure1() {
    -        @Override
    -        public void apply(final JvmOperation it) {
    -          it.setStatic(true);
    -          final Procedure1 _function = new Procedure1() {
    -            @Override
    -            public void apply(final ITreeAppendable it) {
    -              StringConcatenation _builder = new StringConcatenation();
    -              _builder.append("org.jnario.junit3.JnarioTestSuite suite = new org.jnario.junit3.JnarioTestSuite(\"");
    -              String _describe = JUnit3RuntimeSupport.this._jnarioNameProvider.describe(context);
    -              _builder.append(_describe, "");
    -              _builder.append("\");");
    -              _builder.newLineIfNotEmpty();
    -              {
    -                for(final Executable test : tests) {
    -                  _builder.append("suite.addTest(new ");
    -                  String _javaClassName = JUnit3RuntimeSupport.this._jnarioNameProvider.toJavaClassName(context);
    -                  _builder.append(_javaClassName, "");
    -                  _builder.append("(\"");
    -                  String _testName = JUnit3RuntimeSupport.this.testName(test);
    -                  _builder.append(_testName, "");
    -                  _builder.append("\"));");
    -                  _builder.newLineIfNotEmpty();
    -                }
    -              }
    -              {
    -                for(final String child : children) {
    -                  _builder.append("suite.addTest(");
    -                  _builder.append(child, "");
    -                  _builder.append(".suite());");
    -                  _builder.newLineIfNotEmpty();
    -                }
    -              }
    -              _builder.append("return suite;");
    -              _builder.newLine();
    -              it.append(_builder);
    -            }
    -          };
    -          JUnit3RuntimeSupport.this._extendedJvmTypesBuilder.setBody(it, _function);
    -        }
    -      };
    -      JvmOperation _method = this._extendedJvmTypesBuilder.toMethod(context, "suite", testType, _function);
    -      _xblockexpression = this._extendedJvmTypesBuilder.operator_add(_members, _method);
    -    }
    -    return _xblockexpression;
    -  }
    -  
    -  private boolean makeTestCase(final JnarioClass exampleGroup, final JvmGenericType inferredType) {
    -    boolean _xblockexpression = false;
    -    {
    -      final JvmTypeReference stringType = this._typeReferences.getTypeForName("java.lang.String", exampleGroup);
    -      EList _members = inferredType.getMembers();
    -      JvmField _field = this._extendedJvmTypesBuilder.toField(exampleGroup, "__name", stringType);
    -      this._extendedJvmTypesBuilder.operator_add(_members, _field);
    -      EList _members_1 = inferredType.getMembers();
    -      final Procedure1 _function = new Procedure1() {
    -        @Override
    -        public void apply(final JvmConstructor it) {
    -          EList _parameters = it.getParameters();
    -          JvmFormalParameter _parameter = JUnit3RuntimeSupport.this._extendedJvmTypesBuilder.toParameter(exampleGroup, "name", stringType);
    -          JUnit3RuntimeSupport.this._extendedJvmTypesBuilder.operator_add(_parameters, _parameter);
    -          final Procedure1 _function = new Procedure1() {
    -            @Override
    -            public void apply(final ITreeAppendable it) {
    -              StringConcatenation _builder = new StringConcatenation();
    -              _builder.append("setName(name);");
    -              _builder.newLine();
    -              _builder.append("this.__name = name;");
    -              it.append(_builder);
    -            }
    -          };
    -          JUnit3RuntimeSupport.this._extendedJvmTypesBuilder.setBody(it, _function);
    -        }
    -      };
    -      JvmConstructor _constructor = this._extendedJvmTypesBuilder.toConstructor(exampleGroup, _function);
    -      this._extendedJvmTypesBuilder.operator_add(_members_1, _constructor);
    -      EList _members_2 = inferredType.getMembers();
    -      final Procedure1 _function_1 = new Procedure1() {
    -        @Override
    -        public void apply(final JvmOperation it) {
    -          final Procedure1 _function = new Procedure1() {
    -            @Override
    -            public void apply(final ITreeAppendable it) {
    -              StringConcatenation _builder = new StringConcatenation();
    -              _builder.append("return org.jnario.runner.NameProvider.create().nameOf(getClass(), __name);");
    -              it.append(_builder);
    -            }
    -          };
    -          JUnit3RuntimeSupport.this._extendedJvmTypesBuilder.setBody(it, _function);
    -        }
    -      };
    -      JvmOperation _method = this._extendedJvmTypesBuilder.toMethod(exampleGroup, "getName", stringType, _function_1);
    -      _xblockexpression = this._extendedJvmTypesBuilder.operator_add(_members_2, _method);
    -    }
    -    return _xblockexpression;
    -  }
    -  
    -  public Object addTestCase(final JvmGenericType inferredType, final JnarioClass context) {
    -    Object _xifexpression = null;
    -    EList _superTypes = inferredType.getSuperTypes();
    -    boolean _isEmpty = _superTypes.isEmpty();
    -    if (_isEmpty) {
    -      EList _superTypes_1 = inferredType.getSuperTypes();
    -      JvmTypeReference _typeForName = this._typeReferences.getTypeForName("junit.framework.TestCase", context);
    -      _xifexpression = Boolean.valueOf(this._extendedJvmTypesBuilder.operator_add(_superTypes_1, _typeForName));
    -    } else {
    -      JvmTypeReference _xifexpression_1 = null;
    -      EList _superTypes_2 = inferredType.getSuperTypes();
    -      JvmTypeReference _get = _superTypes_2.get(0);
    -      String _simpleName = _get.getSimpleName();
    -      boolean _equals = Objects.equal(_simpleName, "Object");
    -      if (_equals) {
    -        EList _superTypes_3 = inferredType.getSuperTypes();
    -        JvmTypeReference _typeForName_1 = this._typeReferences.getTypeForName("junit.framework.TestCase", context);
    -        _xifexpression_1 = _superTypes_3.set(0, _typeForName_1);
    -      }
    -      _xifexpression = _xifexpression_1;
    -    }
    -    return _xifexpression;
    -  }
    -  
    -  private Iterable children(final JnarioClass exampleGroup) {
    -    EList _members = exampleGroup.getMembers();
    -    Iterable _filter = Iterables.filter(_members, Specification.class);
    -    final Function1 _function = new Function1() {
    -      @Override
    -      public String apply(final Specification it) {
    -        return JUnit3RuntimeSupport.this._jnarioNameProvider.toJavaClassName(it);
    -      }
    -    };
    -    return IterableExtensions.map(_filter, _function);
    -  }
    -  
    -  private Iterable examples(final JnarioClass exampleGroup) {
    -    EList _members = exampleGroup.getMembers();
    -    Iterable _filter = Iterables.filter(_members, Executable.class);
    -    final Function1 _function = new Function1() {
    -      @Override
    -      public Boolean apply(final Executable it) {
    -        return Boolean.valueOf((!(it instanceof Specification)));
    -      }
    -    };
    -    return IterableExtensions.filter(_filter, _function);
    -  }
    -  
    -  @Override
    -  public void markAsTestMethod(final Executable element, final JvmOperation operation) {
    -    String _testName = this.testName(element);
    -    operation.setSimpleName(_testName);
    -  }
    -  
    -  private String testName(final Executable e) {
    -    String _methodName = this._jnarioNameProvider.toMethodName(e);
    -    return ("test" + _methodName);
    -  }
    -  
    -  @Override
    -  public void updateFeature(final JnarioClass feature, final JvmGenericType inferredType, final List scenarios) {
    -    this.addTestCase(inferredType, feature);
    -    final Function1 _function = new Function1() {
    -      @Override
    -      public String apply(final JvmTypeReference it) {
    -        return it.getSimpleName();
    -      }
    -    };
    -    List _map = ListExtensions.map(scenarios, _function);
    -    List _emptyList = CollectionLiterals.emptyList();
    -    this.addSuite(inferredType, feature, _map, _emptyList);
    -  }
    -  
    -  @Override
    -  public void updateScenario(final JnarioClass scenario, final JvmGenericType inferredType) {
    -    final JvmTypeReference testType = this._typeReferences.getTypeForName("junit.framework.Test", scenario);
    -    final Iterable tests = this.examples(scenario);
    -    EList _members = inferredType.getMembers();
    -    final Procedure1 _function = new Procedure1() {
    -      @Override
    -      public void apply(final JvmOperation it) {
    -        it.setStatic(true);
    -        final Procedure1 _function = new Procedure1() {
    -          @Override
    -          public void apply(final ITreeAppendable it) {
    -            StringConcatenation _builder = new StringConcatenation();
    -            _builder.append("org.jnario.junit3.JnarioTestSuite suite = new org.jnario.junit3.JnarioTestSuite(\"");
    -            String _describe = JUnit3RuntimeSupport.this._jnarioNameProvider.describe(scenario);
    -            _builder.append(_describe, "");
    -            _builder.append("\");");
    -            _builder.newLineIfNotEmpty();
    -            String _javaClassName = JUnit3RuntimeSupport.this._jnarioNameProvider.toJavaClassName(scenario);
    -            _builder.append(_javaClassName, "");
    -            _builder.append(" scenario = new ");
    -            String _javaClassName_1 = JUnit3RuntimeSupport.this._jnarioNameProvider.toJavaClassName(scenario);
    -            _builder.append(_javaClassName_1, "");
    -            _builder.append("(");
    -            _builder.newLineIfNotEmpty();
    -            _builder.append("new org.jnario.junit3.TestQueue(");
    -            _builder.newLine();
    -            {
    -              boolean _hasElements = false;
    -              for(final Executable test : tests) {
    -                if (!_hasElements) {
    -                  _hasElements = true;
    -                } else {
    -                  _builder.appendImmediate(", ", "");
    -                }
    -                _builder.append("\"");
    -                String _testName = JUnit3RuntimeSupport.this.testName(test);
    -                _builder.append(_testName, "");
    -                _builder.append("\"");
    -              }
    -            }
    -            _builder.append("));");
    -            _builder.newLineIfNotEmpty();
    -            {
    -              for(final Executable test_1 : tests) {
    -                _builder.append("suite.addTest(new org.jnario.junit3.DelegatingTestCase(\"");
    -                String _describe_1 = JUnit3RuntimeSupport.this._jnarioNameProvider.describe(test_1);
    -                _builder.append(_describe_1, "");
    -                _builder.append("\", scenario));");
    -                _builder.newLineIfNotEmpty();
    -              }
    -            }
    -            _builder.append("return suite;");
    -            _builder.newLine();
    -            it.append(_builder);
    -          }
    -        };
    -        JUnit3RuntimeSupport.this._extendedJvmTypesBuilder.setBody(it, _function);
    -      }
    -    };
    -    JvmOperation _method = this._extendedJvmTypesBuilder.toMethod(scenario, "suite", testType, _function);
    -    this._extendedJvmTypesBuilder.operator_add(_members, _method);
    -    final JvmTypeReference queueType = this._typeReferences.getTypeForName("org.jnario.junit3.TestQueue", scenario);
    -    EList _members_1 = inferredType.getMembers();
    -    JvmField _field = this._extendedJvmTypesBuilder.toField(scenario, "testQueue", queueType);
    -    this._extendedJvmTypesBuilder.operator_add(_members_1, _field);
    -    EList _members_2 = inferredType.getMembers();
    -    final Procedure1 _function_1 = new Procedure1() {
    -      @Override
    -      public void apply(final JvmConstructor it) {
    -        EList _parameters = it.getParameters();
    -        JvmFormalParameter _parameter = JUnit3RuntimeSupport.this._extendedJvmTypesBuilder.toParameter(scenario, "testQueue", queueType);
    -        JUnit3RuntimeSupport.this._extendedJvmTypesBuilder.operator_add(_parameters, _parameter);
    -        final Procedure1 _function = new Procedure1() {
    -          @Override
    -          public void apply(final ITreeAppendable it) {
    -            StringConcatenation _builder = new StringConcatenation();
    -            _builder.append("setName(testQueue.next());");
    -            _builder.newLine();
    -            _builder.append("this.testQueue = testQueue;");
    -            it.append(_builder);
    -          }
    -        };
    -        JUnit3RuntimeSupport.this._extendedJvmTypesBuilder.setBody(it, _function);
    -      }
    -    };
    -    JvmConstructor _constructor = this._extendedJvmTypesBuilder.toConstructor(scenario, _function_1);
    -    this._extendedJvmTypesBuilder.operator_add(_members_2, _constructor);
    -    final JvmTypeReference voidType = this._typeReferences.getTypeForName(Void.TYPE, scenario);
    -    EList _members_3 = inferredType.getMembers();
    -    final Procedure1 _function_2 = new Procedure1() {
    -      @Override
    -      public void apply(final JvmOperation it) {
    -        it.setVisibility(JvmVisibility.PUBLIC);
    -        EList _exceptions = it.getExceptions();
    -        JvmTypeReference _typeForName = JUnit3RuntimeSupport.this._typeReferences.getTypeForName(Exception.class, scenario);
    -        JUnit3RuntimeSupport.this._extendedJvmTypesBuilder.operator_add(_exceptions, _typeForName);
    -        final Procedure1 _function = new Procedure1() {
    -          @Override
    -          public void apply(final ITreeAppendable it) {
    -            StringConcatenation _builder = new StringConcatenation();
    -            _builder.append("if(testQueue.isRunning()){");
    -            _builder.newLine();
    -            _builder.append("\t");
    -            _builder.append("return;");
    -            _builder.newLine();
    -            _builder.append("}");
    -            _builder.newLine();
    -            _builder.append("super.");
    -            _builder.append("setUp", "");
    -            _builder.append("();");
    -            it.append(_builder);
    -          }
    -        };
    -        JUnit3RuntimeSupport.this._extendedJvmTypesBuilder.setBody(it, _function);
    -      }
    -    };
    -    JvmOperation _method_1 = this._extendedJvmTypesBuilder.toMethod(scenario, "setUp", voidType, _function_2);
    -    this._extendedJvmTypesBuilder.operator_add(_members_3, _method_1);
    -    EList _members_4 = inferredType.getMembers();
    -    final Procedure1 _function_3 = new Procedure1() {
    -      @Override
    -      public void apply(final JvmOperation it) {
    -        it.setVisibility(JvmVisibility.PUBLIC);
    -        EList _exceptions = it.getExceptions();
    -        JvmTypeReference _typeForName = JUnit3RuntimeSupport.this._typeReferences.getTypeForName(Exception.class, scenario);
    -        JUnit3RuntimeSupport.this._extendedJvmTypesBuilder.operator_add(_exceptions, _typeForName);
    -        final Procedure1 _function = new Procedure1() {
    -          @Override
    -          public void apply(final ITreeAppendable it) {
    -            StringConcatenation _builder = new StringConcatenation();
    -            _builder.append("if(testQueue.isDone()){");
    -            _builder.newLine();
    -            _builder.append("\t");
    -            _builder.append("super.");
    -            _builder.append("tearDown", "\t");
    -            _builder.append("();");
    -            _builder.newLineIfNotEmpty();
    -            _builder.append("}else{");
    -            _builder.newLine();
    -            _builder.append("\t");
    -            _builder.append("setName(testQueue.next());");
    -            _builder.newLine();
    -            _builder.append("}");
    -            _builder.newLine();
    -            it.append(_builder);
    -          }
    -        };
    -        JUnit3RuntimeSupport.this._extendedJvmTypesBuilder.setBody(it, _function);
    -      }
    -    };
    -    JvmOperation _method_2 = this._extendedJvmTypesBuilder.toMethod(scenario, "tearDown", voidType, _function_3);
    -    this._extendedJvmTypesBuilder.operator_add(_members_4, _method_2);
    -  }
    -  
    -  @Override
    -  public void updateSuite(final JnarioClass exampleGroup, final JvmGenericType inferredType) {
    -  }
    -}
    +package org.jnario.jvmmodel;
    +
    +import com.google.common.base.Objects;
    +import com.google.common.collect.Iterables;
    +import com.google.inject.Inject;
    +import java.util.Collection;
    +import java.util.List;
    +import org.eclipse.emf.common.util.EList;
    +import org.eclipse.xtend2.lib.StringConcatenation;
    +import org.eclipse.xtext.common.types.JvmConstructor;
    +import org.eclipse.xtext.common.types.JvmField;
    +import org.eclipse.xtext.common.types.JvmFormalParameter;
    +import org.eclipse.xtext.common.types.JvmGenericType;
    +import org.eclipse.xtext.common.types.JvmMember;
    +import org.eclipse.xtext.common.types.JvmOperation;
    +import org.eclipse.xtext.common.types.JvmTypeReference;
    +import org.eclipse.xtext.common.types.JvmVisibility;
    +import org.eclipse.xtext.common.types.util.TypeReferences;
    +import org.eclipse.xtext.xbase.compiler.output.ITreeAppendable;
    +import org.eclipse.xtext.xbase.lib.CollectionLiterals;
    +import org.eclipse.xtext.xbase.lib.Extension;
    +import org.eclipse.xtext.xbase.lib.Functions.Function1;
    +import org.eclipse.xtext.xbase.lib.IterableExtensions;
    +import org.eclipse.xtext.xbase.lib.ListExtensions;
    +import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
    +import org.jnario.Executable;
    +import org.jnario.JnarioClass;
    +import org.jnario.JnarioFunction;
    +import org.jnario.JnarioMember;
    +import org.jnario.Specification;
    +import org.jnario.jvmmodel.ExtendedJvmTypesBuilder;
    +import org.jnario.jvmmodel.JnarioNameProvider;
    +import org.jnario.jvmmodel.TestRuntimeSupport;
    +
    +@SuppressWarnings("all")
    +public class JUnit3RuntimeSupport implements TestRuntimeSupport {
    +  @Inject
    +  @Extension
    +  private TypeReferences _typeReferences;
    +  
    +  @Inject
    +  @Extension
    +  private JnarioNameProvider _jnarioNameProvider;
    +  
    +  @Inject
    +  @Extension
    +  private ExtendedJvmTypesBuilder _extendedJvmTypesBuilder;
    +  
    +  @Override
    +  public void afterAllMethod(final JnarioMember before, final JvmOperation operation) {
    +  }
    +  
    +  @Override
    +  public void afterMethod(final JnarioMember before, final JvmOperation operation) {
    +  }
    +  
    +  @Override
    +  public void beforeAllMethod(final JnarioMember before, final JvmOperation operation) {
    +  }
    +  
    +  @Override
    +  public void beforeMethod(final JnarioMember before, final JvmOperation operation) {
    +  }
    +  
    +  @Override
    +  public void markAsPending(final Executable element, final JvmOperation operation) {
    +  }
    +  
    +  @Override
    +  public void addChildren(final Specification context, final JvmGenericType parent, final Collection children) {
    +    String _name = context.eClass().getName();
    +    boolean _equals = Objects.equal(_name, "Suite");
    +    if (_equals) {
    +      final Function1 _function = new Function1() {
    +        @Override
    +        public String apply(final JvmTypeReference it) {
    +          return it.getSimpleName();
    +        }
    +      };
    +      this.addSuite(parent, context, IterableExtensions.map(children, _function), CollectionLiterals.emptyList());
    +    }
    +  }
    +  
    +  @Override
    +  public void updateExampleGroup(final JnarioClass exampleGroup, final JvmGenericType inferredType) {
    +    this.makeTestCase(exampleGroup, inferredType);
    +    this.addTestCase(inferredType, exampleGroup);
    +    this.addSuite(inferredType, exampleGroup, this.children(exampleGroup), this.examples(exampleGroup));
    +    this.generateSetup("setUp", exampleGroup, inferredType, this.befores(exampleGroup));
    +    this.generateSetup("tearDown", exampleGroup, inferredType, this.afters(exampleGroup));
    +  }
    +  
    +  public boolean generateSetup(final String methodName, final JnarioClass exampleGroup, final JvmGenericType type, final Iterable executables) {
    +    boolean _xblockexpression = false;
    +    {
    +      final JvmTypeReference voidType = this._typeReferences.getTypeForName(Void.TYPE, exampleGroup);
    +      EList _members = type.getMembers();
    +      final Procedure1 _function = new Procedure1() {
    +        @Override
    +        public void apply(final JvmOperation it) {
    +          it.setVisibility(JvmVisibility.PUBLIC);
    +          EList _exceptions = it.getExceptions();
    +          JvmTypeReference _typeForName = JUnit3RuntimeSupport.this._typeReferences.getTypeForName(Exception.class, exampleGroup);
    +          JUnit3RuntimeSupport.this._extendedJvmTypesBuilder.operator_add(_exceptions, _typeForName);
    +          final Procedure1 _function = new Procedure1() {
    +            @Override
    +            public void apply(final ITreeAppendable it) {
    +              StringConcatenation _builder = new StringConcatenation();
    +              _builder.append("super.");
    +              _builder.append(methodName);
    +              _builder.append("();");
    +              _builder.newLineIfNotEmpty();
    +              {
    +                for(final JnarioFunction executable : executables) {
    +                  String _methodName = JUnit3RuntimeSupport.this._jnarioNameProvider.toMethodName(executable);
    +                  _builder.append(_methodName);
    +                  _builder.append("();");
    +                  _builder.newLineIfNotEmpty();
    +                }
    +              }
    +              it.append(_builder);
    +            }
    +          };
    +          JUnit3RuntimeSupport.this._extendedJvmTypesBuilder.setBody(it, _function);
    +        }
    +      };
    +      JvmOperation _method = this._extendedJvmTypesBuilder.toMethod(exampleGroup, methodName, voidType, _function);
    +      _xblockexpression = this._extendedJvmTypesBuilder.operator_add(_members, _method);
    +    }
    +    return _xblockexpression;
    +  }
    +  
    +  private Iterable befores(final JnarioClass exampleGroup) {
    +    final Function1 _function = new Function1() {
    +      @Override
    +      public Boolean apply(final JnarioFunction it) {
    +        String _name = it.eClass().getName();
    +        return Boolean.valueOf(Objects.equal(_name, "Before"));
    +      }
    +    };
    +    return IterableExtensions.filter(Iterables.filter(exampleGroup.getMembers(), JnarioFunction.class), _function);
    +  }
    +  
    +  private Iterable afters(final JnarioClass exampleGroup) {
    +    final Function1 _function = new Function1() {
    +      @Override
    +      public Boolean apply(final JnarioFunction it) {
    +        String _name = it.eClass().getName();
    +        return Boolean.valueOf(Objects.equal(_name, "After"));
    +      }
    +    };
    +    return IterableExtensions.filter(Iterables.filter(exampleGroup.getMembers(), JnarioFunction.class), _function);
    +  }
    +  
    +  private boolean addSuite(final JvmGenericType it, final JnarioClass context, final Iterable children, final Iterable tests) {
    +    boolean _xblockexpression = false;
    +    {
    +      final JvmTypeReference testType = this._typeReferences.getTypeForName("junit.framework.Test", context);
    +      EList _members = it.getMembers();
    +      final Procedure1 _function = new Procedure1() {
    +        @Override
    +        public void apply(final JvmOperation it) {
    +          it.setStatic(true);
    +          final Procedure1 _function = new Procedure1() {
    +            @Override
    +            public void apply(final ITreeAppendable it) {
    +              StringConcatenation _builder = new StringConcatenation();
    +              _builder.append("org.jnario.junit3.JnarioTestSuite suite = new org.jnario.junit3.JnarioTestSuite(\"");
    +              String _describe = JUnit3RuntimeSupport.this._jnarioNameProvider.describe(context);
    +              _builder.append(_describe);
    +              _builder.append("\");");
    +              _builder.newLineIfNotEmpty();
    +              {
    +                for(final Executable test : tests) {
    +                  _builder.append("suite.addTest(new ");
    +                  String _javaClassName = JUnit3RuntimeSupport.this._jnarioNameProvider.toJavaClassName(context);
    +                  _builder.append(_javaClassName);
    +                  _builder.append("(\"");
    +                  String _testName = JUnit3RuntimeSupport.this.testName(test);
    +                  _builder.append(_testName);
    +                  _builder.append("\"));");
    +                  _builder.newLineIfNotEmpty();
    +                }
    +              }
    +              {
    +                for(final String child : children) {
    +                  _builder.append("suite.addTest(");
    +                  _builder.append(child);
    +                  _builder.append(".suite());");
    +                  _builder.newLineIfNotEmpty();
    +                }
    +              }
    +              _builder.append("return suite;");
    +              _builder.newLine();
    +              it.append(_builder);
    +            }
    +          };
    +          JUnit3RuntimeSupport.this._extendedJvmTypesBuilder.setBody(it, _function);
    +        }
    +      };
    +      JvmOperation _method = this._extendedJvmTypesBuilder.toMethod(context, "suite", testType, _function);
    +      _xblockexpression = this._extendedJvmTypesBuilder.operator_add(_members, _method);
    +    }
    +    return _xblockexpression;
    +  }
    +  
    +  private boolean makeTestCase(final JnarioClass exampleGroup, final JvmGenericType inferredType) {
    +    boolean _xblockexpression = false;
    +    {
    +      final JvmTypeReference stringType = this._typeReferences.getTypeForName("java.lang.String", exampleGroup);
    +      EList _members = inferredType.getMembers();
    +      JvmField _field = this._extendedJvmTypesBuilder.toField(exampleGroup, "__name", stringType);
    +      this._extendedJvmTypesBuilder.operator_add(_members, _field);
    +      EList _members_1 = inferredType.getMembers();
    +      final Procedure1 _function = new Procedure1() {
    +        @Override
    +        public void apply(final JvmConstructor it) {
    +          EList _parameters = it.getParameters();
    +          JvmFormalParameter _parameter = JUnit3RuntimeSupport.this._extendedJvmTypesBuilder.toParameter(exampleGroup, "name", stringType);
    +          JUnit3RuntimeSupport.this._extendedJvmTypesBuilder.operator_add(_parameters, _parameter);
    +          final Procedure1 _function = new Procedure1() {
    +            @Override
    +            public void apply(final ITreeAppendable it) {
    +              StringConcatenation _builder = new StringConcatenation();
    +              _builder.append("setName(name);");
    +              _builder.newLine();
    +              _builder.append("this.__name = name;");
    +              it.append(_builder);
    +            }
    +          };
    +          JUnit3RuntimeSupport.this._extendedJvmTypesBuilder.setBody(it, _function);
    +        }
    +      };
    +      JvmConstructor _constructor = this._extendedJvmTypesBuilder.toConstructor(exampleGroup, _function);
    +      this._extendedJvmTypesBuilder.operator_add(_members_1, _constructor);
    +      EList _members_2 = inferredType.getMembers();
    +      final Procedure1 _function_1 = new Procedure1() {
    +        @Override
    +        public void apply(final JvmOperation it) {
    +          final Procedure1 _function = new Procedure1() {
    +            @Override
    +            public void apply(final ITreeAppendable it) {
    +              StringConcatenation _builder = new StringConcatenation();
    +              _builder.append("return org.jnario.runner.NameProvider.create().nameOf(getClass(), __name);");
    +              it.append(_builder);
    +            }
    +          };
    +          JUnit3RuntimeSupport.this._extendedJvmTypesBuilder.setBody(it, _function);
    +        }
    +      };
    +      JvmOperation _method = this._extendedJvmTypesBuilder.toMethod(exampleGroup, "getName", stringType, _function_1);
    +      _xblockexpression = this._extendedJvmTypesBuilder.operator_add(_members_2, _method);
    +    }
    +    return _xblockexpression;
    +  }
    +  
    +  public Object addTestCase(final JvmGenericType inferredType, final JnarioClass context) {
    +    Object _xifexpression = null;
    +    boolean _isEmpty = inferredType.getSuperTypes().isEmpty();
    +    if (_isEmpty) {
    +      EList _superTypes = inferredType.getSuperTypes();
    +      JvmTypeReference _typeForName = this._typeReferences.getTypeForName("junit.framework.TestCase", context);
    +      _xifexpression = Boolean.valueOf(this._extendedJvmTypesBuilder.operator_add(_superTypes, _typeForName));
    +    } else {
    +      JvmTypeReference _xifexpression_1 = null;
    +      String _simpleName = inferredType.getSuperTypes().get(0).getSimpleName();
    +      boolean _equals = Objects.equal(_simpleName, "Object");
    +      if (_equals) {
    +        _xifexpression_1 = inferredType.getSuperTypes().set(0, this._typeReferences.getTypeForName("junit.framework.TestCase", context));
    +      }
    +      _xifexpression = _xifexpression_1;
    +    }
    +    return _xifexpression;
    +  }
    +  
    +  private Iterable children(final JnarioClass exampleGroup) {
    +    final Function1 _function = new Function1() {
    +      @Override
    +      public String apply(final Specification it) {
    +        return JUnit3RuntimeSupport.this._jnarioNameProvider.toJavaClassName(it);
    +      }
    +    };
    +    return IterableExtensions.map(Iterables.filter(exampleGroup.getMembers(), Specification.class), _function);
    +  }
    +  
    +  private Iterable examples(final JnarioClass exampleGroup) {
    +    final Function1 _function = new Function1() {
    +      @Override
    +      public Boolean apply(final Executable it) {
    +        return Boolean.valueOf((!(it instanceof Specification)));
    +      }
    +    };
    +    return IterableExtensions.filter(Iterables.filter(exampleGroup.getMembers(), Executable.class), _function);
    +  }
    +  
    +  @Override
    +  public void markAsTestMethod(final Executable element, final JvmOperation operation) {
    +    operation.setSimpleName(this.testName(element));
    +  }
    +  
    +  private String testName(final Executable e) {
    +    String _methodName = this._jnarioNameProvider.toMethodName(e);
    +    return ("test" + _methodName);
    +  }
    +  
    +  @Override
    +  public void updateFeature(final JnarioClass feature, final JvmGenericType inferredType, final List scenarios) {
    +    this.addTestCase(inferredType, feature);
    +    final Function1 _function = new Function1() {
    +      @Override
    +      public String apply(final JvmTypeReference it) {
    +        return it.getSimpleName();
    +      }
    +    };
    +    this.addSuite(inferredType, feature, ListExtensions.map(scenarios, _function), CollectionLiterals.emptyList());
    +  }
    +  
    +  @Override
    +  public void updateScenario(final JnarioClass scenario, final JvmGenericType inferredType) {
    +    final JvmTypeReference testType = this._typeReferences.getTypeForName("junit.framework.Test", scenario);
    +    final Iterable tests = this.examples(scenario);
    +    EList _members = inferredType.getMembers();
    +    final Procedure1 _function = new Procedure1() {
    +      @Override
    +      public void apply(final JvmOperation it) {
    +        it.setStatic(true);
    +        final Procedure1 _function = new Procedure1() {
    +          @Override
    +          public void apply(final ITreeAppendable it) {
    +            StringConcatenation _builder = new StringConcatenation();
    +            _builder.append("org.jnario.junit3.JnarioTestSuite suite = new org.jnario.junit3.JnarioTestSuite(\"");
    +            String _describe = JUnit3RuntimeSupport.this._jnarioNameProvider.describe(scenario);
    +            _builder.append(_describe);
    +            _builder.append("\");");
    +            _builder.newLineIfNotEmpty();
    +            String _javaClassName = JUnit3RuntimeSupport.this._jnarioNameProvider.toJavaClassName(scenario);
    +            _builder.append(_javaClassName);
    +            _builder.append(" scenario = new ");
    +            String _javaClassName_1 = JUnit3RuntimeSupport.this._jnarioNameProvider.toJavaClassName(scenario);
    +            _builder.append(_javaClassName_1);
    +            _builder.append("(");
    +            _builder.newLineIfNotEmpty();
    +            _builder.append("new org.jnario.junit3.TestQueue(");
    +            _builder.newLine();
    +            {
    +              boolean _hasElements = false;
    +              for(final Executable test : tests) {
    +                if (!_hasElements) {
    +                  _hasElements = true;
    +                } else {
    +                  _builder.appendImmediate(", ", "");
    +                }
    +                _builder.append("\"");
    +                String _testName = JUnit3RuntimeSupport.this.testName(test);
    +                _builder.append(_testName);
    +                _builder.append("\"");
    +              }
    +            }
    +            _builder.append("));");
    +            _builder.newLineIfNotEmpty();
    +            {
    +              for(final Executable test_1 : tests) {
    +                _builder.append("suite.addTest(new org.jnario.junit3.DelegatingTestCase(\"");
    +                String _describe_1 = JUnit3RuntimeSupport.this._jnarioNameProvider.describe(test_1);
    +                _builder.append(_describe_1);
    +                _builder.append("\", scenario));");
    +                _builder.newLineIfNotEmpty();
    +              }
    +            }
    +            _builder.append("return suite;");
    +            _builder.newLine();
    +            it.append(_builder);
    +          }
    +        };
    +        JUnit3RuntimeSupport.this._extendedJvmTypesBuilder.setBody(it, _function);
    +      }
    +    };
    +    JvmOperation _method = this._extendedJvmTypesBuilder.toMethod(scenario, "suite", testType, _function);
    +    this._extendedJvmTypesBuilder.operator_add(_members, _method);
    +    final JvmTypeReference queueType = this._typeReferences.getTypeForName("org.jnario.junit3.TestQueue", scenario);
    +    EList _members_1 = inferredType.getMembers();
    +    JvmField _field = this._extendedJvmTypesBuilder.toField(scenario, "testQueue", queueType);
    +    this._extendedJvmTypesBuilder.operator_add(_members_1, _field);
    +    EList _members_2 = inferredType.getMembers();
    +    final Procedure1 _function_1 = new Procedure1() {
    +      @Override
    +      public void apply(final JvmConstructor it) {
    +        EList _parameters = it.getParameters();
    +        JvmFormalParameter _parameter = JUnit3RuntimeSupport.this._extendedJvmTypesBuilder.toParameter(scenario, "testQueue", queueType);
    +        JUnit3RuntimeSupport.this._extendedJvmTypesBuilder.operator_add(_parameters, _parameter);
    +        final Procedure1 _function = new Procedure1() {
    +          @Override
    +          public void apply(final ITreeAppendable it) {
    +            StringConcatenation _builder = new StringConcatenation();
    +            _builder.append("setName(testQueue.next());");
    +            _builder.newLine();
    +            _builder.append("this.testQueue = testQueue;");
    +            it.append(_builder);
    +          }
    +        };
    +        JUnit3RuntimeSupport.this._extendedJvmTypesBuilder.setBody(it, _function);
    +      }
    +    };
    +    JvmConstructor _constructor = this._extendedJvmTypesBuilder.toConstructor(scenario, _function_1);
    +    this._extendedJvmTypesBuilder.operator_add(_members_2, _constructor);
    +    final JvmTypeReference voidType = this._typeReferences.getTypeForName(Void.TYPE, scenario);
    +    EList _members_3 = inferredType.getMembers();
    +    final Procedure1 _function_2 = new Procedure1() {
    +      @Override
    +      public void apply(final JvmOperation it) {
    +        it.setVisibility(JvmVisibility.PUBLIC);
    +        EList _exceptions = it.getExceptions();
    +        JvmTypeReference _typeForName = JUnit3RuntimeSupport.this._typeReferences.getTypeForName(Exception.class, scenario);
    +        JUnit3RuntimeSupport.this._extendedJvmTypesBuilder.operator_add(_exceptions, _typeForName);
    +        final Procedure1 _function = new Procedure1() {
    +          @Override
    +          public void apply(final ITreeAppendable it) {
    +            StringConcatenation _builder = new StringConcatenation();
    +            _builder.append("if(testQueue.isRunning()){");
    +            _builder.newLine();
    +            _builder.append("\t");
    +            _builder.append("return;");
    +            _builder.newLine();
    +            _builder.append("}");
    +            _builder.newLine();
    +            _builder.append("super.");
    +            _builder.append("setUp");
    +            _builder.append("();");
    +            it.append(_builder);
    +          }
    +        };
    +        JUnit3RuntimeSupport.this._extendedJvmTypesBuilder.setBody(it, _function);
    +      }
    +    };
    +    JvmOperation _method_1 = this._extendedJvmTypesBuilder.toMethod(scenario, "setUp", voidType, _function_2);
    +    this._extendedJvmTypesBuilder.operator_add(_members_3, _method_1);
    +    EList _members_4 = inferredType.getMembers();
    +    final Procedure1 _function_3 = new Procedure1() {
    +      @Override
    +      public void apply(final JvmOperation it) {
    +        it.setVisibility(JvmVisibility.PUBLIC);
    +        EList _exceptions = it.getExceptions();
    +        JvmTypeReference _typeForName = JUnit3RuntimeSupport.this._typeReferences.getTypeForName(Exception.class, scenario);
    +        JUnit3RuntimeSupport.this._extendedJvmTypesBuilder.operator_add(_exceptions, _typeForName);
    +        final Procedure1 _function = new Procedure1() {
    +          @Override
    +          public void apply(final ITreeAppendable it) {
    +            StringConcatenation _builder = new StringConcatenation();
    +            _builder.append("if(testQueue.isDone()){");
    +            _builder.newLine();
    +            _builder.append("\t");
    +            _builder.append("super.");
    +            _builder.append("tearDown", "\t");
    +            _builder.append("();");
    +            _builder.newLineIfNotEmpty();
    +            _builder.append("}else{");
    +            _builder.newLine();
    +            _builder.append("\t");
    +            _builder.append("setName(testQueue.next());");
    +            _builder.newLine();
    +            _builder.append("}");
    +            _builder.newLine();
    +            it.append(_builder);
    +          }
    +        };
    +        JUnit3RuntimeSupport.this._extendedJvmTypesBuilder.setBody(it, _function);
    +      }
    +    };
    +    JvmOperation _method_2 = this._extendedJvmTypesBuilder.toMethod(scenario, "tearDown", voidType, _function_3);
    +    this._extendedJvmTypesBuilder.operator_add(_members_4, _method_2);
    +  }
    +  
    +  @Override
    +  public void updateSuite(final JnarioClass exampleGroup, final JvmGenericType inferredType) {
    +  }
    +}
    diff --git a/plugins/org.jnario/xtend-gen/org/jnario/jvmmodel/JUnit4RuntimeSupport.java b/plugins/org.jnario/xtend-gen/org/jnario/jvmmodel/JUnit4RuntimeSupport.java
    index 77ab5d98e..1bde75d4a 100644
    --- a/plugins/org.jnario/xtend-gen/org/jnario/jvmmodel/JUnit4RuntimeSupport.java
    +++ b/plugins/org.jnario/xtend-gen/org/jnario/jvmmodel/JUnit4RuntimeSupport.java
    @@ -1,135 +1,131 @@
    -package org.jnario.jvmmodel;
    -
    -import com.google.common.base.Objects;
    -import com.google.inject.Inject;
    -import java.util.Collection;
    -import java.util.List;
    -import org.eclipse.emf.common.notify.Notifier;
    -import org.eclipse.emf.common.util.EList;
    -import org.eclipse.xtext.common.types.JvmAnnotationReference;
    -import org.eclipse.xtext.common.types.JvmGenericType;
    -import org.eclipse.xtext.common.types.JvmOperation;
    -import org.eclipse.xtext.common.types.JvmTypeReference;
    -import org.eclipse.xtext.common.types.util.TypeReferences;
    -import org.eclipse.xtext.xbase.jvmmodel.JvmTypesBuilder;
    -import org.eclipse.xtext.xbase.lib.Extension;
    -import org.jnario.Executable;
    -import org.jnario.JnarioClass;
    -import org.jnario.JnarioMember;
    -import org.jnario.Specification;
    -import org.jnario.jvmmodel.TestRuntimeSupport;
    -import org.jnario.runner.Contains;
    -import org.jnario.runner.ExampleGroupRunner;
    -import org.jnario.runner.FeatureRunner;
    -
    -@SuppressWarnings("all")
    -public class JUnit4RuntimeSupport implements TestRuntimeSupport {
    -  private final static String RUN_WITH = "org.junit.runner.RunWith";
    -  
    -  @Inject
    -  @Extension
    -  private JvmTypesBuilder _jvmTypesBuilder;
    -  
    -  @Inject
    -  private TypeReferences typeReferences;
    -  
    -  @Override
    -  public void addChildren(final Specification context, final JvmGenericType parent, final Collection children) {
    -    boolean _isEmpty = children.isEmpty();
    -    boolean _not = (!_isEmpty);
    -    if (_not) {
    -      EList _annotations = parent.getAnnotations();
    -      JvmAnnotationReference _annotation = this._jvmTypesBuilder.toAnnotation(context, Contains.class, children);
    -      this._jvmTypesBuilder.operator_add(_annotations, _annotation);
    -    }
    -  }
    -  
    -  @Override
    -  public void afterAllMethod(final JnarioMember after, final JvmOperation operation) {
    -    EList _annotations = operation.getAnnotations();
    -    JvmAnnotationReference _annotation = this._jvmTypesBuilder.toAnnotation(after, "org.junit.AfterClass");
    -    this._jvmTypesBuilder.operator_add(_annotations, _annotation);
    -  }
    -  
    -  @Override
    -  public void afterMethod(final JnarioMember after, final JvmOperation operation) {
    -    EList _annotations = operation.getAnnotations();
    -    JvmAnnotationReference _annotation = this._jvmTypesBuilder.toAnnotation(after, "org.junit.After");
    -    this._jvmTypesBuilder.operator_add(_annotations, _annotation);
    -  }
    -  
    -  @Override
    -  public void beforeAllMethod(final JnarioMember before, final JvmOperation operation) {
    -    EList _annotations = operation.getAnnotations();
    -    JvmAnnotationReference _annotation = this._jvmTypesBuilder.toAnnotation(before, "org.junit.BeforeClass");
    -    this._jvmTypesBuilder.operator_add(_annotations, _annotation);
    -  }
    -  
    -  @Override
    -  public void beforeMethod(final JnarioMember before, final JvmOperation operation) {
    -    EList _annotations = operation.getAnnotations();
    -    JvmAnnotationReference _annotation = this._jvmTypesBuilder.toAnnotation(before, "org.junit.Before");
    -    this._jvmTypesBuilder.operator_add(_annotations, _annotation);
    -  }
    -  
    -  @Override
    -  public void markAsPending(final Executable element, final JvmOperation operation) {
    -    EList _annotations = operation.getAnnotations();
    -    JvmAnnotationReference _annotation = this._jvmTypesBuilder.toAnnotation(element, "org.junit.Ignore");
    -    this._jvmTypesBuilder.operator_add(_annotations, _annotation);
    -  }
    -  
    -  @Override
    -  public void updateExampleGroup(final JnarioClass exampleGroup, final JvmGenericType inferredType) {
    -    EList _annotations = inferredType.getAnnotations();
    -    JvmTypeReference _typeForName = this.getTypeForName(ExampleGroupRunner.class, exampleGroup);
    -    JvmAnnotationReference _annotation = this._jvmTypesBuilder.toAnnotation(exampleGroup, JUnit4RuntimeSupport.RUN_WITH, _typeForName);
    -    this._jvmTypesBuilder.operator_add(_annotations, _annotation);
    -  }
    -  
    -  @Override
    -  public void markAsTestMethod(final Executable element, final JvmOperation operation) {
    -    EList _annotations = operation.getAnnotations();
    -    JvmAnnotationReference _annotation = this._jvmTypesBuilder.toAnnotation(element, "org.junit.Test");
    -    this._jvmTypesBuilder.operator_add(_annotations, _annotation);
    -  }
    -  
    -  @Override
    -  public void updateFeature(final JnarioClass feature, final JvmGenericType inferredType, final List scenarios) {
    -    EList _annotations = inferredType.getAnnotations();
    -    JvmTypeReference _typeForName = this.getTypeForName(FeatureRunner.class, feature);
    -    JvmAnnotationReference _annotation = this._jvmTypesBuilder.toAnnotation(feature, JUnit4RuntimeSupport.RUN_WITH, _typeForName);
    -    this._jvmTypesBuilder.operator_add(_annotations, _annotation);
    -  }
    -  
    -  @Override
    -  public void updateScenario(final JnarioClass scenario, final JvmGenericType inferredType) {
    -    EList _annotations = inferredType.getAnnotations();
    -    JvmTypeReference _typeForName = this.getTypeForName(FeatureRunner.class, scenario);
    -    JvmAnnotationReference _annotation = this._jvmTypesBuilder.toAnnotation(scenario, JUnit4RuntimeSupport.RUN_WITH, _typeForName);
    -    this._jvmTypesBuilder.operator_add(_annotations, _annotation);
    -  }
    -  
    -  @Override
    -  public void updateSuite(final JnarioClass exampleGroup, final JvmGenericType inferredType) {
    -    EList _annotations = inferredType.getAnnotations();
    -    JvmTypeReference _typeForName = this.getTypeForName(ExampleGroupRunner.class, exampleGroup);
    -    JvmAnnotationReference _annotation = this._jvmTypesBuilder.toAnnotation(exampleGroup, JUnit4RuntimeSupport.RUN_WITH, _typeForName);
    -    this._jvmTypesBuilder.operator_add(_annotations, _annotation);
    -  }
    -  
    -  public JvmTypeReference getTypeForName(final Class type, final Notifier context) {
    -    JvmTypeReference _xblockexpression = null;
    -    {
    -      final JvmTypeReference result = this.typeReferences.getTypeForName(type, context);
    -      boolean _equals = Objects.equal(result, null);
    -      if (_equals) {
    -        String _name = type.getName();
    -        String _plus = ("Jnario runtime could not be resolved: " + _name);
    -        throw new IllegalStateException(_plus);
    -      }
    -      _xblockexpression = result;
    -    }
    -    return _xblockexpression;
    -  }
    -}
    +package org.jnario.jvmmodel;
    +
    +import com.google.common.base.Objects;
    +import com.google.inject.Inject;
    +import java.util.Collection;
    +import java.util.List;
    +import org.eclipse.emf.common.notify.Notifier;
    +import org.eclipse.emf.common.util.EList;
    +import org.eclipse.xtext.common.types.JvmAnnotationReference;
    +import org.eclipse.xtext.common.types.JvmGenericType;
    +import org.eclipse.xtext.common.types.JvmOperation;
    +import org.eclipse.xtext.common.types.JvmTypeReference;
    +import org.eclipse.xtext.common.types.util.TypeReferences;
    +import org.eclipse.xtext.xbase.jvmmodel.JvmTypesBuilder;
    +import org.eclipse.xtext.xbase.lib.Extension;
    +import org.jnario.Executable;
    +import org.jnario.JnarioClass;
    +import org.jnario.JnarioMember;
    +import org.jnario.Specification;
    +import org.jnario.jvmmodel.TestRuntimeSupport;
    +import org.jnario.runner.Contains;
    +import org.jnario.runner.ExampleGroupRunner;
    +import org.jnario.runner.FeatureRunner;
    +
    +@SuppressWarnings("all")
    +public class JUnit4RuntimeSupport implements TestRuntimeSupport {
    +  private final static String RUN_WITH = "org.junit.runner.RunWith";
    +  
    +  @Inject
    +  @Extension
    +  private JvmTypesBuilder _jvmTypesBuilder;
    +  
    +  @Inject
    +  private TypeReferences typeReferences;
    +  
    +  @Override
    +  public void addChildren(final Specification context, final JvmGenericType parent, final Collection children) {
    +    boolean _isEmpty = children.isEmpty();
    +    boolean _not = (!_isEmpty);
    +    if (_not) {
    +      EList _annotations = parent.getAnnotations();
    +      JvmAnnotationReference _annotation = this._jvmTypesBuilder.toAnnotation(context, Contains.class, children);
    +      this._jvmTypesBuilder.operator_add(_annotations, _annotation);
    +    }
    +  }
    +  
    +  @Override
    +  public void afterAllMethod(final JnarioMember after, final JvmOperation operation) {
    +    EList _annotations = operation.getAnnotations();
    +    JvmAnnotationReference _annotation = this._jvmTypesBuilder.toAnnotation(after, "org.junit.AfterClass");
    +    this._jvmTypesBuilder.operator_add(_annotations, _annotation);
    +  }
    +  
    +  @Override
    +  public void afterMethod(final JnarioMember after, final JvmOperation operation) {
    +    EList _annotations = operation.getAnnotations();
    +    JvmAnnotationReference _annotation = this._jvmTypesBuilder.toAnnotation(after, "org.junit.After");
    +    this._jvmTypesBuilder.operator_add(_annotations, _annotation);
    +  }
    +  
    +  @Override
    +  public void beforeAllMethod(final JnarioMember before, final JvmOperation operation) {
    +    EList _annotations = operation.getAnnotations();
    +    JvmAnnotationReference _annotation = this._jvmTypesBuilder.toAnnotation(before, "org.junit.BeforeClass");
    +    this._jvmTypesBuilder.operator_add(_annotations, _annotation);
    +  }
    +  
    +  @Override
    +  public void beforeMethod(final JnarioMember before, final JvmOperation operation) {
    +    EList _annotations = operation.getAnnotations();
    +    JvmAnnotationReference _annotation = this._jvmTypesBuilder.toAnnotation(before, "org.junit.Before");
    +    this._jvmTypesBuilder.operator_add(_annotations, _annotation);
    +  }
    +  
    +  @Override
    +  public void markAsPending(final Executable element, final JvmOperation operation) {
    +    EList _annotations = operation.getAnnotations();
    +    JvmAnnotationReference _annotation = this._jvmTypesBuilder.toAnnotation(element, "org.junit.Ignore");
    +    this._jvmTypesBuilder.operator_add(_annotations, _annotation);
    +  }
    +  
    +  @Override
    +  public void updateExampleGroup(final JnarioClass exampleGroup, final JvmGenericType inferredType) {
    +    EList _annotations = inferredType.getAnnotations();
    +    JvmAnnotationReference _annotation = this._jvmTypesBuilder.toAnnotation(exampleGroup, JUnit4RuntimeSupport.RUN_WITH, this.getTypeForName(ExampleGroupRunner.class, exampleGroup));
    +    this._jvmTypesBuilder.operator_add(_annotations, _annotation);
    +  }
    +  
    +  @Override
    +  public void markAsTestMethod(final Executable element, final JvmOperation operation) {
    +    EList _annotations = operation.getAnnotations();
    +    JvmAnnotationReference _annotation = this._jvmTypesBuilder.toAnnotation(element, "org.junit.Test");
    +    this._jvmTypesBuilder.operator_add(_annotations, _annotation);
    +  }
    +  
    +  @Override
    +  public void updateFeature(final JnarioClass feature, final JvmGenericType inferredType, final List scenarios) {
    +    EList _annotations = inferredType.getAnnotations();
    +    JvmAnnotationReference _annotation = this._jvmTypesBuilder.toAnnotation(feature, JUnit4RuntimeSupport.RUN_WITH, this.getTypeForName(FeatureRunner.class, feature));
    +    this._jvmTypesBuilder.operator_add(_annotations, _annotation);
    +  }
    +  
    +  @Override
    +  public void updateScenario(final JnarioClass scenario, final JvmGenericType inferredType) {
    +    EList _annotations = inferredType.getAnnotations();
    +    JvmAnnotationReference _annotation = this._jvmTypesBuilder.toAnnotation(scenario, JUnit4RuntimeSupport.RUN_WITH, this.getTypeForName(FeatureRunner.class, scenario));
    +    this._jvmTypesBuilder.operator_add(_annotations, _annotation);
    +  }
    +  
    +  @Override
    +  public void updateSuite(final JnarioClass exampleGroup, final JvmGenericType inferredType) {
    +    EList _annotations = inferredType.getAnnotations();
    +    JvmAnnotationReference _annotation = this._jvmTypesBuilder.toAnnotation(exampleGroup, JUnit4RuntimeSupport.RUN_WITH, this.getTypeForName(ExampleGroupRunner.class, exampleGroup));
    +    this._jvmTypesBuilder.operator_add(_annotations, _annotation);
    +  }
    +  
    +  public JvmTypeReference getTypeForName(final Class type, final Notifier context) {
    +    JvmTypeReference _xblockexpression = null;
    +    {
    +      final JvmTypeReference result = this.typeReferences.getTypeForName(type, context);
    +      boolean _equals = Objects.equal(result, null);
    +      if (_equals) {
    +        String _name = type.getName();
    +        String _plus = ("Jnario runtime could not be resolved: " + _name);
    +        throw new IllegalStateException(_plus);
    +      }
    +      _xblockexpression = result;
    +    }
    +    return _xblockexpression;
    +  }
    +}
    diff --git a/plugins/org.jnario/xtend-gen/org/jnario/jvmmodel/JnarioJvmModelInferrer.java b/plugins/org.jnario/xtend-gen/org/jnario/jvmmodel/JnarioJvmModelInferrer.java
    index c5f0e7062..bf8988a8b 100644
    --- a/plugins/org.jnario/xtend-gen/org/jnario/jvmmodel/JnarioJvmModelInferrer.java
    +++ b/plugins/org.jnario/xtend-gen/org/jnario/jvmmodel/JnarioJvmModelInferrer.java
    @@ -1,581 +1,523 @@
    -/**
    - * Copyright (c) 2012 BMW Car IT and others.
    - * All rights reserved. This program and the accompanying materials
    - * are made available under the terms of the Eclipse Public License v1.0
    - * which accompanies this distribution, and is available at
    - * http://www.eclipse.org/legal/epl-v10.html
    - */
    -package org.jnario.jvmmodel;
    -
    -import com.google.common.base.Objects;
    -import com.google.common.collect.Iterables;
    -import com.google.inject.Inject;
    -import java.lang.annotation.Annotation;
    -import java.util.Arrays;
    -import java.util.List;
    -import java.util.NoSuchElementException;
    -import java.util.Set;
    -import java.util.function.Consumer;
    -import org.eclipse.emf.common.notify.Notifier;
    -import org.eclipse.emf.common.util.EList;
    -import org.eclipse.emf.ecore.EClass;
    -import org.eclipse.emf.ecore.EObject;
    -import org.eclipse.emf.ecore.resource.Resource;
    -import org.eclipse.xtext.EcoreUtil2;
    -import org.eclipse.xtext.common.types.JvmAnnotationReference;
    -import org.eclipse.xtext.common.types.JvmAnnotationTarget;
    -import org.eclipse.xtext.common.types.JvmAnnotationType;
    -import org.eclipse.xtext.common.types.JvmDeclaredType;
    -import org.eclipse.xtext.common.types.JvmExecutable;
    -import org.eclipse.xtext.common.types.JvmField;
    -import org.eclipse.xtext.common.types.JvmFormalParameter;
    -import org.eclipse.xtext.common.types.JvmGenericArrayTypeReference;
    -import org.eclipse.xtext.common.types.JvmGenericType;
    -import org.eclipse.xtext.common.types.JvmMember;
    -import org.eclipse.xtext.common.types.JvmOperation;
    -import org.eclipse.xtext.common.types.JvmParameterizedTypeReference;
    -import org.eclipse.xtext.common.types.JvmType;
    -import org.eclipse.xtext.common.types.JvmTypeConstraint;
    -import org.eclipse.xtext.common.types.JvmTypeParameter;
    -import org.eclipse.xtext.common.types.JvmTypeParameterDeclarator;
    -import org.eclipse.xtext.common.types.JvmTypeReference;
    -import org.eclipse.xtext.common.types.JvmUpperBound;
    -import org.eclipse.xtext.common.types.JvmVisibility;
    -import org.eclipse.xtext.common.types.TypesFactory;
    -import org.eclipse.xtext.common.types.TypesPackage;
    -import org.eclipse.xtext.common.types.util.TypeReferences;
    -import org.eclipse.xtext.documentation.IFileHeaderProvider;
    -import org.eclipse.xtext.nodemodel.ICompositeNode;
    -import org.eclipse.xtext.nodemodel.INode;
    -import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
    -import org.eclipse.xtext.util.Strings;
    -import org.eclipse.xtext.xbase.XExpression;
    -import org.eclipse.xtext.xbase.XTypeLiteral;
    -import org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation;
    -import org.eclipse.xtext.xbase.compiler.XbaseCompiler;
    -import org.eclipse.xtext.xbase.jvmmodel.AbstractModelInferrer;
    -import org.eclipse.xtext.xbase.jvmmodel.IJvmDeclaredTypeAcceptor;
    -import org.eclipse.xtext.xbase.jvmmodel.IJvmModelAssociations;
    -import org.eclipse.xtext.xbase.jvmmodel.IJvmModelAssociator;
    -import org.eclipse.xtext.xbase.jvmmodel.JvmTypesBuilder;
    -import org.eclipse.xtext.xbase.lib.Exceptions;
    -import org.eclipse.xtext.xbase.lib.Extension;
    -import org.eclipse.xtext.xbase.lib.Functions.Function1;
    -import org.eclipse.xtext.xbase.lib.IterableExtensions;
    -import org.eclipse.xtext.xbase.lib.ObjectExtensions;
    -import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
    -import org.jnario.JnarioClass;
    -import org.jnario.JnarioField;
    -import org.jnario.JnarioFile;
    -import org.jnario.JnarioFunction;
    -import org.jnario.JnarioMember;
    -import org.jnario.JnarioParameter;
    -import org.jnario.JnarioTypeDeclaration;
    -import org.jnario.jvmmodel.JnarioNameProvider;
    -import org.jnario.jvmmodel.TestRuntimeProvider;
    -import org.jnario.jvmmodel.TestRuntimeSupport;
    -import org.jnario.runner.Extends;
    -
    -/**
    - * TODO NO_XTEND - verify all methods. Remove unused.
    - * @author Birgit Engelmann
    - * @author Sebastian Benz
    - */
    -@SuppressWarnings("all")
    -public abstract class JnarioJvmModelInferrer extends AbstractModelInferrer {
    -  @Inject
    -  @Extension
    -  private IJvmModelAssociator modelAssociator;
    -  
    -  @Inject
    -  @Extension
    -  private IJvmModelAssociations _iJvmModelAssociations;
    -  
    -  @Inject
    -  @Extension
    -  private IFileHeaderProvider _iFileHeaderProvider;
    -  
    -  @Inject
    -  @Extension
    -  private JvmTypesBuilder _jvmTypesBuilder;
    -  
    -  @Inject
    -  public XbaseCompiler compiler;
    -  
    -  @Inject
    -  @Extension
    -  private TypeReferences _typeReferences;
    -  
    -  @Inject
    -  private TestRuntimeProvider runtime;
    -  
    -  @Inject
    -  @Extension
    -  private JnarioNameProvider _jnarioNameProvider;
    -  
    -  private TestRuntimeSupport testRuntime;
    -  
    -  @Inject
    -  @Extension
    -  private TypesFactory typesFactory;
    -  
    -  @Override
    -  public void infer(final EObject obj, final IJvmDeclaredTypeAcceptor acceptor, final boolean preIndexingPhase) {
    -    try {
    -      TestRuntimeSupport _get = this.runtime.get(obj);
    -      this.testRuntime = _get;
    -    } catch (final Throwable _t) {
    -      if (_t instanceof NoSuchElementException) {
    -        final NoSuchElementException ex = (NoSuchElementException)_t;
    -        return;
    -      } else {
    -        throw Exceptions.sneakyThrow(_t);
    -      }
    -    }
    -    this.doInfer(obj, acceptor, preIndexingPhase);
    -  }
    -  
    -  public void doInfer(final EObject e, final IJvmDeclaredTypeAcceptor acceptor, final boolean preIndexingPhase) {
    -    throw new UnsupportedOperationException();
    -  }
    -  
    -  public String serialize(final EObject obj) {
    -    ICompositeNode _node = NodeModelUtils.getNode(obj);
    -    String _text = null;
    -    if (_node!=null) {
    -      _text=_node.getText();
    -    }
    -    return _text;
    -  }
    -  
    -  public JnarioFile jnarioFile(final EObject obj) {
    -    return EcoreUtil2.getContainerOfType(obj, JnarioFile.class);
    -  }
    -  
    -  public String packageName(final EObject obj) {
    -    JnarioFile _jnarioFile = this.jnarioFile(obj);
    -    String _package = null;
    -    if (_jnarioFile!=null) {
    -      _package=_jnarioFile.getPackage();
    -    }
    -    return _package;
    -  }
    -  
    -  protected TestRuntimeSupport getTestRuntime() {
    -    return this.testRuntime;
    -  }
    -  
    -  protected void addSuperClass(final JnarioClass jnarioClass) {
    -    EObject xtendType = jnarioClass;
    -    while (((!Objects.equal(xtendType, null)) && (xtendType instanceof JnarioClass))) {
    -      {
    -        final JnarioClass current = ((JnarioClass) xtendType);
    -        EList _annotations = current.getAnnotations();
    -        final Function1 _function = new Function1() {
    -          @Override
    -          public Boolean apply(final XAnnotation it) {
    -            return Boolean.valueOf(JnarioJvmModelInferrer.this.hasExtendsAnnotation(it));
    -          }
    -        };
    -        Iterable _filter = IterableExtensions.filter(_annotations, _function);
    -        final Function1 _function_1 = new Function1() {
    -          @Override
    -          public XTypeLiteral apply(final XAnnotation it) {
    -            XExpression _value = it.getValue();
    -            return ((XTypeLiteral) _value);
    -          }
    -        };
    -        Iterable _map = IterableExtensions.map(_filter, _function_1);
    -        for (final XTypeLiteral extendedType : _map) {
    -          JvmType _type = extendedType.getType();
    -          boolean _notEquals = (!Objects.equal(_type, null));
    -          if (_notEquals) {
    -            JvmType _type_1 = extendedType.getType();
    -            JvmParameterizedTypeReference _createTypeRef = this._typeReferences.createTypeRef(_type_1);
    -            jnarioClass.setExtends(_createTypeRef);
    -            return;
    -          }
    -        }
    -        EObject _eContainer = xtendType.eContainer();
    -        xtendType = _eContainer;
    -      }
    -    }
    -  }
    -  
    -  protected boolean hasExtendsAnnotation(final XAnnotation annotation) {
    -    boolean _and = false;
    -    JvmType _annotationType = annotation.getAnnotationType();
    -    String _qualifiedName = null;
    -    if (_annotationType!=null) {
    -      _qualifiedName=_annotationType.getQualifiedName();
    -    }
    -    String _name = Extends.class.getName();
    -    boolean _equals = Objects.equal(_qualifiedName, _name);
    -    if (!_equals) {
    -      _and = false;
    -    } else {
    -      XExpression _value = annotation.getValue();
    -      _and = (_value instanceof XTypeLiteral);
    -    }
    -    return _and;
    -  }
    -  
    -  protected void setNameAndAssociate(final JnarioFile file, final JnarioTypeDeclaration jnarioType, final JvmDeclaredType javaType) {
    -    String _package = file.getPackage();
    -    javaType.setPackageName(_package);
    -    String _javaClassName = this._jnarioNameProvider.toJavaClassName(jnarioType);
    -    javaType.setSimpleName(_javaClassName);
    -    javaType.setVisibility(JvmVisibility.PUBLIC);
    -    this.setFileHeader(file, javaType);
    -    this.modelAssociator.associatePrimary(jnarioType, javaType);
    -  }
    -  
    -  protected void setFileHeader(final JnarioFile jnarioFile, final JvmDeclaredType jvmDeclaredType) {
    -    Resource _eResource = jnarioFile.eResource();
    -    String _fileHeader = this._iFileHeaderProvider.getFileHeader(_eResource);
    -    this._jvmTypesBuilder.setFileHeader(jvmDeclaredType, _fileHeader);
    -  }
    -  
    -  protected void initialize(final JnarioClass source, final JvmGenericType inferredJvmType) {
    -    final Procedure1 _function = new Procedure1() {
    -      @Override
    -      public void apply(final JvmGenericType it) {
    -        it.setVisibility(JvmVisibility.PUBLIC);
    -        boolean _isStatic = source.isStatic();
    -        it.setStatic(_isStatic);
    -      }
    -    };
    -    ObjectExtensions.operator_doubleArrow(inferredJvmType, _function);
    -    EList _annotations = source.getAnnotations();
    -    this.translateAnnotations(inferredJvmType, _annotations);
    -    final JvmTypeReference extendsClause = source.getExtends();
    -    if ((Objects.equal(extendsClause, null) || Objects.equal(extendsClause.getType(), null))) {
    -      EList _superTypes = inferredJvmType.getSuperTypes();
    -      JvmTypeReference _typeForName = this._typeReferences.getTypeForName(Object.class, source);
    -      _superTypes.add(_typeForName);
    -    } else {
    -      EList _superTypes_1 = inferredJvmType.getSuperTypes();
    -      JvmTypeReference _cloneWithProxies = this._jvmTypesBuilder.cloneWithProxies(extendsClause);
    -      _superTypes_1.add(_cloneWithProxies);
    -    }
    -    EList _members = source.getMembers();
    -    for (final JnarioMember member : _members) {
    -      if (((member instanceof JnarioField) || ((member instanceof JnarioFunction) && (!Objects.equal(((JnarioFunction) member).getName(), null))))) {
    -        this.transform(member, inferredJvmType);
    -      }
    -    }
    -    this._jvmTypesBuilder.copyDocumentationTo(source, inferredJvmType);
    -  }
    -  
    -  protected void _transform(final JnarioField source, final JvmGenericType container) {
    -    if (((source.isExtension() && (!Objects.equal(source.getType(), null))) || (!Objects.equal(source.getName(), null)))) {
    -      JvmField _createJvmField = this.typesFactory.createJvmField();
    -      final Procedure1 _function = new Procedure1() {
    -        @Override
    -        public void apply(final JvmField it) {
    -          String _computeFieldName = JnarioJvmModelInferrer.this.computeFieldName(source);
    -          it.setSimpleName(_computeFieldName);
    -          JvmVisibility _visibility = source.getVisibility();
    -          it.setVisibility(_visibility);
    -          boolean _isStatic = source.isStatic();
    -          it.setStatic(_isStatic);
    -          boolean _isTransient = source.isTransient();
    -          it.setTransient(_isTransient);
    -          boolean _isVolatile = source.isVolatile();
    -          it.setVolatile(_isVolatile);
    -          boolean _isFinal = source.isFinal();
    -          it.setFinal(_isFinal);
    -          EList _members = container.getMembers();
    -          JnarioJvmModelInferrer.this._jvmTypesBuilder.operator_add(_members, it);
    -          JvmTypeReference _type = source.getType();
    -          boolean _notEquals = (!Objects.equal(_type, null));
    -          if (_notEquals) {
    -            JvmTypeReference _type_1 = source.getType();
    -            JvmTypeReference _cloneWithProxies = JnarioJvmModelInferrer.this._jvmTypesBuilder.cloneWithProxies(_type_1);
    -            it.setType(_cloneWithProxies);
    -          } else {
    -            XExpression _initialValue = source.getInitialValue();
    -            boolean _notEquals_1 = (!Objects.equal(_initialValue, null));
    -            if (_notEquals_1) {
    -              XExpression _initialValue_1 = source.getInitialValue();
    -              JvmTypeReference _inferredType = JnarioJvmModelInferrer.this._jvmTypesBuilder.inferredType(_initialValue_1);
    -              it.setType(_inferredType);
    -            }
    -          }
    -          JvmVisibility _visibility_1 = it.getVisibility();
    -          boolean _equals = Objects.equal(_visibility_1, JvmVisibility.PRIVATE);
    -          if (_equals) {
    -            it.setVisibility(JvmVisibility.DEFAULT);
    -          }
    -          boolean _isExtension = source.isExtension();
    -          if (_isExtension) {
    -            it.setVisibility(JvmVisibility.PUBLIC);
    -            EList _annotations = it.getAnnotations();
    -            JnarioJvmModelInferrer.this.addAnnotationIfFound(_annotations, Extension.class, source);
    -            EList _annotations_1 = it.getAnnotations();
    -            JnarioJvmModelInferrer.this.addAnnotationIfFound(_annotations_1, org.jnario.runner.Extension.class, source);
    -          }
    -          EList _annotations_2 = source.getAnnotations();
    -          JnarioJvmModelInferrer.this.translateAnnotations(it, _annotations_2);
    -          JnarioJvmModelInferrer.this.modelAssociator.associatePrimary(source, it);
    -          JnarioJvmModelInferrer.this._jvmTypesBuilder.copyDocumentationTo(source, it);
    -          XExpression _initialValue_2 = source.getInitialValue();
    -          JnarioJvmModelInferrer.this._jvmTypesBuilder.setInitializer(it, _initialValue_2);
    -        }
    -      };
    -      ObjectExtensions.operator_doubleArrow(_createJvmField, _function);
    -    }
    -  }
    -  
    -  public boolean addAnnotationIfFound(final List annotations, final Class annotationType, final Notifier context) {
    -    boolean _xblockexpression = false;
    -    {
    -      final JvmType jvmType = this._typeReferences.findDeclaredType(annotationType, context);
    -      boolean _xifexpression = false;
    -      if ((jvmType instanceof JvmAnnotationType)) {
    -        JvmAnnotationReference _annotationRef = this._annotationTypesBuilder.annotationRef(annotationType);
    -        _xifexpression = annotations.add(_annotationRef);
    -      }
    -      _xblockexpression = _xifexpression;
    -    }
    -    return _xblockexpression;
    -  }
    -  
    -  protected void _transform(final JnarioFunction source, final JvmGenericType container) {
    -    final JvmOperation operation = this.typesFactory.createJvmOperation();
    -    operation.setAbstract(false);
    -    operation.setNative(false);
    -    operation.setSynchronized(false);
    -    operation.setStrictFloatingPoint(false);
    -    boolean _isAbstract = operation.isAbstract();
    -    boolean _not = (!_isAbstract);
    -    if (_not) {
    -      boolean _isFinal = source.isFinal();
    -      operation.setFinal(_isFinal);
    -    }
    -    EList _members = container.getMembers();
    -    _members.add(operation);
    -    this.modelAssociator.associatePrimary(source, operation);
    -    final String sourceName = source.getName();
    -    final JvmVisibility visibility = source.getVisibility();
    -    operation.setSimpleName(sourceName);
    -    operation.setVisibility(visibility);
    -    boolean _isStatic = source.isStatic();
    -    operation.setStatic(_isStatic);
    -    if ((((!operation.isAbstract()) && (!operation.isStatic())) && container.isInterface())) {
    -      operation.setDefault(true);
    -    }
    -    EList _parameters = source.getParameters();
    -    for (final JnarioParameter parameter : _parameters) {
    -      this.translateParameter(operation, parameter);
    -    }
    -    final XExpression expression = source.getExpression();
    -    JvmTypeReference returnType = null;
    -    JvmTypeReference _returnType = source.getReturnType();
    -    boolean _notEquals = (!Objects.equal(_returnType, null));
    -    if (_notEquals) {
    -      JvmTypeReference _returnType_1 = source.getReturnType();
    -      JvmTypeReference _cloneWithProxies = this._jvmTypesBuilder.cloneWithProxies(_returnType_1);
    -      returnType = _cloneWithProxies;
    -    } else {
    -      boolean _notEquals_1 = (!Objects.equal(expression, null));
    -      if (_notEquals_1) {
    -        JvmTypeReference _inferredType = this._jvmTypesBuilder.inferredType(expression);
    -        returnType = _inferredType;
    -      } else {
    -        JvmTypeReference _inferredType_1 = this._jvmTypesBuilder.inferredType();
    -        returnType = _inferredType_1;
    -      }
    -    }
    -    operation.setReturnType(returnType);
    -    EList _typeParameters = source.getTypeParameters();
    -    this.copyAndFixTypeParameters(_typeParameters, operation);
    -    EList _exceptions = source.getExceptions();
    -    for (final JvmTypeReference exception : _exceptions) {
    -      EList _exceptions_1 = operation.getExceptions();
    -      JvmTypeReference _cloneWithProxies_1 = this._jvmTypesBuilder.cloneWithProxies(exception);
    -      this._jvmTypesBuilder.operator_add(_exceptions_1, _cloneWithProxies_1);
    -    }
    -    EList _annotations = source.getAnnotations();
    -    this.translateAnnotations(operation, _annotations);
    -    this._jvmTypesBuilder.setBody(operation, expression);
    -    this._jvmTypesBuilder.copyDocumentationTo(source, operation);
    -  }
    -  
    -  protected void translateParameter(final JvmExecutable executable, final JnarioParameter parameter) {
    -    final JvmFormalParameter jvmParam = this.typesFactory.createJvmFormalParameter();
    -    String _name = parameter.getName();
    -    jvmParam.setName(_name);
    -    boolean _isVarArg = parameter.isVarArg();
    -    if (_isVarArg) {
    -      executable.setVarArgs(true);
    -      JvmTypeReference _parameterType = parameter.getParameterType();
    -      JvmTypeReference _cloneWithProxies = this._jvmTypesBuilder.cloneWithProxies(_parameterType);
    -      final JvmGenericArrayTypeReference arrayType = this._typeReferences.createArrayType(_cloneWithProxies);
    -      jvmParam.setParameterType(arrayType);
    -    } else {
    -      JvmTypeReference _parameterType_1 = parameter.getParameterType();
    -      JvmTypeReference _cloneWithProxies_1 = this._jvmTypesBuilder.cloneWithProxies(_parameterType_1);
    -      jvmParam.setParameterType(_cloneWithProxies_1);
    -    }
    -    this.modelAssociator.associate(parameter, jvmParam);
    -    EList _annotations = parameter.getAnnotations();
    -    this.translateAnnotations(jvmParam, _annotations);
    -    EList _annotations_1 = jvmParam.getAnnotations();
    -    this.addAnnotationIfFound(_annotations_1, Extension.class, parameter);
    -    EList _parameters = executable.getParameters();
    -    this._jvmTypesBuilder.operator_add(_parameters, jvmParam);
    -  }
    -  
    -  protected void copyAndFixTypeParameters(final List typeParameters, final JvmTypeParameterDeclarator target) {
    -    this.copyTypeParameters(typeParameters, target);
    -    this.fixTypeParameters(target);
    -  }
    -  
    -  protected void copyTypeParameters(final List typeParameters, final JvmTypeParameterDeclarator target) {
    -    for (final JvmTypeParameter typeParameter : typeParameters) {
    -      {
    -        final JvmTypeParameter clonedTypeParameter = this._jvmTypesBuilder.cloneWithProxies(typeParameter);
    -        boolean _notEquals = (!Objects.equal(clonedTypeParameter, null));
    -        if (_notEquals) {
    -          EList _typeParameters = target.getTypeParameters();
    -          _typeParameters.add(clonedTypeParameter);
    -          this.modelAssociator.associate(typeParameter, clonedTypeParameter);
    -        }
    -      }
    -    }
    -  }
    -  
    -  protected void fixTypeParameters(final JvmTypeParameterDeclarator target) {
    -    EList _typeParameters = target.getTypeParameters();
    -    for (final JvmTypeParameter typeParameter : _typeParameters) {
    -      EList _constraints = typeParameter.getConstraints();
    -      Iterable _filter = Iterables.filter(_constraints, JvmUpperBound.class);
    -      boolean _isEmpty = IterableExtensions.isEmpty(_filter);
    -      if (_isEmpty) {
    -        final JvmUpperBound upperBound = this.typesFactory.createJvmUpperBound();
    -        JvmTypeReference _typeForName = this._typeReferences.getTypeForName(Object.class, target);
    -        upperBound.setTypeReference(_typeForName);
    -        EList _constraints_1 = typeParameter.getConstraints();
    -        this._jvmTypesBuilder.operator_add(_constraints_1, upperBound);
    -      }
    -    }
    -  }
    -  
    -  protected void _transform(final JnarioMember source, final JvmGenericType container) {
    -    EClass _eClass = source.eClass();
    -    String _plus = ("Not implemented for type: " + _eClass);
    -    throw new RuntimeException(_plus);
    -  }
    -  
    -  protected String computeFieldName(final JnarioField field) {
    -    String _xblockexpression = null;
    -    {
    -      String _name = field.getName();
    -      boolean _notEquals = (!Objects.equal(_name, null));
    -      if (_notEquals) {
    -        return field.getName();
    -      }
    -      JvmTypeReference type = field.getType();
    -      String name = null;
    -      boolean _notEquals_1 = (!Objects.equal(type, null));
    -      if (_notEquals_1) {
    -        while ((type instanceof JvmGenericArrayTypeReference)) {
    -          JvmTypeReference _componentType = ((JvmGenericArrayTypeReference)type).getComponentType();
    -          type = _componentType;
    -        }
    -        if ((type instanceof JvmParameterizedTypeReference)) {
    -          final List nodes = NodeModelUtils.findNodesForFeature(type, 
    -            TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE);
    -          boolean _isEmpty = nodes.isEmpty();
    -          boolean _not = (!_isEmpty);
    -          if (_not) {
    -            INode _get = nodes.get(0);
    -            String _text = _get.getText();
    -            String typeName = _text.trim();
    -            final int lastDot = typeName.lastIndexOf(".");
    -            if ((lastDot != (-1))) {
    -              String _substring = typeName.substring((lastDot + 1));
    -              typeName = _substring;
    -            }
    -            String _firstLower = Strings.toFirstLower(typeName);
    -            String _plus = ("_" + _firstLower);
    -            name = _plus;
    -          }
    -        }
    -      }
    -      _xblockexpression = name;
    -    }
    -    return _xblockexpression;
    -  }
    -  
    -  /**
    -   * Prevents error message
    -   * Cannot root object twice: JvmGenericType: org.jnario.jnario.tests.integration.ParsingSpecResultsFromJUnitXMLReportsFeatureMatchingFailedSpecRuns ....
    -   * 
    - *
    - * This solution developed by Lorenzo BettiniFriend and published here - * https://www.eclipse.org/forums/index.php/t/864890/ - *
    - * Thank you very much! - */ - protected void translateAnnotations(final JvmAnnotationTarget target, final List annotations) { - final Function1 _function = new Function1() { - @Override - public Boolean apply(final XAnnotation it) { - JvmType _annotationType = null; - if (it!=null) { - _annotationType=it.getAnnotationType(); - } - return Boolean.valueOf((!Objects.equal(_annotationType, null))); - } - }; - Iterable annotationsToAdd = IterableExtensions.filter(annotations, _function); - for (final XAnnotation a : annotationsToAdd) { - { - final JvmAnnotationReference annotationReference = this._jvmTypesBuilder.getJvmAnnotationReference(a); - boolean _notEquals = (!Objects.equal(annotationReference, null)); - if (_notEquals) { - Set _jvmElements = this._iJvmModelAssociations.getJvmElements(a); - final Function1 _function_1 = new Function1() { - @Override - public Boolean apply(final EObject it) { - return Boolean.valueOf((it != annotationReference)); - } - }; - Iterable _filter = IterableExtensions.filter(_jvmElements, _function_1); - final List associatedElements = IterableExtensions.toList(_filter); - boolean _isEmpty = associatedElements.isEmpty(); - boolean _not = (!_isEmpty); - if (_not) { - final Consumer _function_2 = new Consumer() { - @Override - public void accept(final EObject assoc) { - JnarioJvmModelInferrer.this.modelAssociator.removeAllAssociation(assoc); - } - }; - associatedElements.forEach(_function_2); - } - EList _annotations = target.getAnnotations(); - this._jvmTypesBuilder.operator_add(_annotations, annotationReference); - } - } - } - } - - protected void transform(final JnarioMember source, final JvmGenericType container) { - if (source instanceof JnarioField) { - _transform((JnarioField)source, container); - return; - } else if (source instanceof JnarioFunction) { - _transform((JnarioFunction)source, container); - return; - } else if (source != null) { - _transform(source, container); - return; - } else { - throw new IllegalArgumentException("Unhandled parameter types: " + - Arrays.asList(source, container).toString()); - } - } -} +/** + * Copyright (c) 2012 BMW Car IT and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.jnario.jvmmodel; + +import com.google.common.base.Objects; +import com.google.common.collect.Iterables; +import com.google.inject.Inject; +import java.lang.annotation.Annotation; +import java.util.Arrays; +import java.util.List; +import java.util.NoSuchElementException; +import java.util.function.Consumer; +import org.eclipse.emf.common.notify.Notifier; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.xtext.EcoreUtil2; +import org.eclipse.xtext.common.types.JvmAnnotationReference; +import org.eclipse.xtext.common.types.JvmAnnotationTarget; +import org.eclipse.xtext.common.types.JvmAnnotationType; +import org.eclipse.xtext.common.types.JvmDeclaredType; +import org.eclipse.xtext.common.types.JvmExecutable; +import org.eclipse.xtext.common.types.JvmField; +import org.eclipse.xtext.common.types.JvmFormalParameter; +import org.eclipse.xtext.common.types.JvmGenericArrayTypeReference; +import org.eclipse.xtext.common.types.JvmGenericType; +import org.eclipse.xtext.common.types.JvmMember; +import org.eclipse.xtext.common.types.JvmOperation; +import org.eclipse.xtext.common.types.JvmParameterizedTypeReference; +import org.eclipse.xtext.common.types.JvmType; +import org.eclipse.xtext.common.types.JvmTypeConstraint; +import org.eclipse.xtext.common.types.JvmTypeParameter; +import org.eclipse.xtext.common.types.JvmTypeParameterDeclarator; +import org.eclipse.xtext.common.types.JvmTypeReference; +import org.eclipse.xtext.common.types.JvmUpperBound; +import org.eclipse.xtext.common.types.JvmVisibility; +import org.eclipse.xtext.common.types.TypesFactory; +import org.eclipse.xtext.common.types.TypesPackage; +import org.eclipse.xtext.common.types.util.TypeReferences; +import org.eclipse.xtext.documentation.IFileHeaderProvider; +import org.eclipse.xtext.nodemodel.ICompositeNode; +import org.eclipse.xtext.nodemodel.INode; +import org.eclipse.xtext.nodemodel.util.NodeModelUtils; +import org.eclipse.xtext.util.Strings; +import org.eclipse.xtext.xbase.XExpression; +import org.eclipse.xtext.xbase.XTypeLiteral; +import org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation; +import org.eclipse.xtext.xbase.compiler.XbaseCompiler; +import org.eclipse.xtext.xbase.jvmmodel.AbstractModelInferrer; +import org.eclipse.xtext.xbase.jvmmodel.IJvmDeclaredTypeAcceptor; +import org.eclipse.xtext.xbase.jvmmodel.IJvmModelAssociations; +import org.eclipse.xtext.xbase.jvmmodel.IJvmModelAssociator; +import org.eclipse.xtext.xbase.jvmmodel.JvmTypesBuilder; +import org.eclipse.xtext.xbase.lib.Exceptions; +import org.eclipse.xtext.xbase.lib.Extension; +import org.eclipse.xtext.xbase.lib.Functions.Function1; +import org.eclipse.xtext.xbase.lib.IterableExtensions; +import org.eclipse.xtext.xbase.lib.ObjectExtensions; +import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; +import org.jnario.JnarioClass; +import org.jnario.JnarioField; +import org.jnario.JnarioFile; +import org.jnario.JnarioFunction; +import org.jnario.JnarioMember; +import org.jnario.JnarioParameter; +import org.jnario.JnarioTypeDeclaration; +import org.jnario.jvmmodel.JnarioNameProvider; +import org.jnario.jvmmodel.TestRuntimeProvider; +import org.jnario.jvmmodel.TestRuntimeSupport; +import org.jnario.runner.Extends; + +/** + * TODO NO_XTEND - verify all methods. Remove unused. + * @author Birgit Engelmann + * @author Sebastian Benz + */ +@SuppressWarnings("all") +public abstract class JnarioJvmModelInferrer extends AbstractModelInferrer { + @Inject + @Extension + private IJvmModelAssociator modelAssociator; + + @Inject + @Extension + private IJvmModelAssociations _iJvmModelAssociations; + + @Inject + @Extension + private IFileHeaderProvider _iFileHeaderProvider; + + @Inject + @Extension + private JvmTypesBuilder _jvmTypesBuilder; + + @Inject + public XbaseCompiler compiler; + + @Inject + @Extension + private TypeReferences _typeReferences; + + @Inject + private TestRuntimeProvider runtime; + + @Inject + @Extension + private JnarioNameProvider _jnarioNameProvider; + + private TestRuntimeSupport testRuntime; + + @Inject + @Extension + private TypesFactory typesFactory; + + @Override + public void infer(final EObject obj, final IJvmDeclaredTypeAcceptor acceptor, final boolean preIndexingPhase) { + try { + this.testRuntime = this.runtime.get(obj); + } catch (final Throwable _t) { + if (_t instanceof NoSuchElementException) { + final NoSuchElementException ex = (NoSuchElementException)_t; + return; + } else { + throw Exceptions.sneakyThrow(_t); + } + } + this.doInfer(obj, acceptor, preIndexingPhase); + } + + public void doInfer(final EObject e, final IJvmDeclaredTypeAcceptor acceptor, final boolean preIndexingPhase) { + throw new UnsupportedOperationException(); + } + + public String serialize(final EObject obj) { + ICompositeNode _node = NodeModelUtils.getNode(obj); + String _text = null; + if (_node!=null) { + _text=_node.getText(); + } + return _text; + } + + public JnarioFile jnarioFile(final EObject obj) { + return EcoreUtil2.getContainerOfType(obj, JnarioFile.class); + } + + public String packageName(final EObject obj) { + JnarioFile _jnarioFile = this.jnarioFile(obj); + String _package = null; + if (_jnarioFile!=null) { + _package=_jnarioFile.getPackage(); + } + return _package; + } + + protected TestRuntimeSupport getTestRuntime() { + return this.testRuntime; + } + + protected void addSuperClass(final JnarioClass jnarioClass) { + EObject xtendType = jnarioClass; + while (((!Objects.equal(xtendType, null)) && (xtendType instanceof JnarioClass))) { + { + final JnarioClass current = ((JnarioClass) xtendType); + final Function1 _function = new Function1() { + @Override + public Boolean apply(final XAnnotation it) { + return Boolean.valueOf(JnarioJvmModelInferrer.this.hasExtendsAnnotation(it)); + } + }; + final Function1 _function_1 = new Function1() { + @Override + public XTypeLiteral apply(final XAnnotation it) { + XExpression _value = it.getValue(); + return ((XTypeLiteral) _value); + } + }; + Iterable _map = IterableExtensions.map(IterableExtensions.filter(current.getAnnotations(), _function), _function_1); + for (final XTypeLiteral extendedType : _map) { + JvmType _type = extendedType.getType(); + boolean _notEquals = (!Objects.equal(_type, null)); + if (_notEquals) { + jnarioClass.setExtends(this._typeReferences.createTypeRef(extendedType.getType())); + return; + } + } + xtendType = xtendType.eContainer(); + } + } + } + + protected boolean hasExtendsAnnotation(final XAnnotation annotation) { + boolean _and = false; + JvmType _annotationType = annotation.getAnnotationType(); + String _qualifiedName = null; + if (_annotationType!=null) { + _qualifiedName=_annotationType.getQualifiedName(); + } + String _name = Extends.class.getName(); + boolean _equals = Objects.equal(_qualifiedName, _name); + if (!_equals) { + _and = false; + } else { + XExpression _value = annotation.getValue(); + _and = (_value instanceof XTypeLiteral); + } + return _and; + } + + protected void setNameAndAssociate(final JnarioFile file, final JnarioTypeDeclaration jnarioType, final JvmDeclaredType javaType) { + javaType.setPackageName(file.getPackage()); + javaType.setSimpleName(this._jnarioNameProvider.toJavaClassName(jnarioType)); + javaType.setVisibility(JvmVisibility.PUBLIC); + this.setFileHeader(file, javaType); + this.modelAssociator.associatePrimary(jnarioType, javaType); + } + + protected void setFileHeader(final JnarioFile jnarioFile, final JvmDeclaredType jvmDeclaredType) { + this._jvmTypesBuilder.setFileHeader(jvmDeclaredType, this._iFileHeaderProvider.getFileHeader(jnarioFile.eResource())); + } + + protected void initialize(final JnarioClass source, final JvmGenericType inferredJvmType) { + final Procedure1 _function = new Procedure1() { + @Override + public void apply(final JvmGenericType it) { + it.setVisibility(JvmVisibility.PUBLIC); + it.setStatic(source.isStatic()); + } + }; + ObjectExtensions.operator_doubleArrow(inferredJvmType, _function); + this.translateAnnotations(inferredJvmType, source.getAnnotations()); + final JvmTypeReference extendsClause = source.getExtends(); + if ((Objects.equal(extendsClause, null) || Objects.equal(extendsClause.getType(), null))) { + inferredJvmType.getSuperTypes().add(this._typeReferences.getTypeForName(Object.class, source)); + } else { + inferredJvmType.getSuperTypes().add(this._jvmTypesBuilder.cloneWithProxies(extendsClause)); + } + EList _members = source.getMembers(); + for (final JnarioMember member : _members) { + if (((member instanceof JnarioField) || ((member instanceof JnarioFunction) && (!Objects.equal(((JnarioFunction) member).getName(), null))))) { + this.transform(member, inferredJvmType); + } + } + this._jvmTypesBuilder.copyDocumentationTo(source, inferredJvmType); + } + + protected void _transform(final JnarioField source, final JvmGenericType container) { + if (((source.isExtension() && (!Objects.equal(source.getType(), null))) || (!Objects.equal(source.getName(), null)))) { + JvmField _createJvmField = this.typesFactory.createJvmField(); + final Procedure1 _function = new Procedure1() { + @Override + public void apply(final JvmField it) { + it.setSimpleName(JnarioJvmModelInferrer.this.computeFieldName(source)); + it.setVisibility(source.getVisibility()); + it.setStatic(source.isStatic()); + it.setTransient(source.isTransient()); + it.setVolatile(source.isVolatile()); + it.setFinal(source.isFinal()); + EList _members = container.getMembers(); + JnarioJvmModelInferrer.this._jvmTypesBuilder.operator_add(_members, it); + JvmTypeReference _type = source.getType(); + boolean _notEquals = (!Objects.equal(_type, null)); + if (_notEquals) { + it.setType(JnarioJvmModelInferrer.this._jvmTypesBuilder.cloneWithProxies(source.getType())); + } else { + XExpression _initialValue = source.getInitialValue(); + boolean _notEquals_1 = (!Objects.equal(_initialValue, null)); + if (_notEquals_1) { + it.setType(JnarioJvmModelInferrer.this._jvmTypesBuilder.inferredType(source.getInitialValue())); + } + } + JvmVisibility _visibility = it.getVisibility(); + boolean _equals = Objects.equal(_visibility, JvmVisibility.PRIVATE); + if (_equals) { + it.setVisibility(JvmVisibility.DEFAULT); + } + boolean _isExtension = source.isExtension(); + if (_isExtension) { + it.setVisibility(JvmVisibility.PUBLIC); + JnarioJvmModelInferrer.this.addAnnotationIfFound(it.getAnnotations(), Extension.class, source); + JnarioJvmModelInferrer.this.addAnnotationIfFound(it.getAnnotations(), org.jnario.runner.Extension.class, source); + } + JnarioJvmModelInferrer.this.translateAnnotations(it, source.getAnnotations()); + JnarioJvmModelInferrer.this.modelAssociator.associatePrimary(source, it); + JnarioJvmModelInferrer.this._jvmTypesBuilder.copyDocumentationTo(source, it); + JnarioJvmModelInferrer.this._jvmTypesBuilder.setInitializer(it, source.getInitialValue()); + } + }; + ObjectExtensions.operator_doubleArrow(_createJvmField, _function); + } + } + + public boolean addAnnotationIfFound(final List annotations, final Class annotationType, final Notifier context) { + boolean _xblockexpression = false; + { + final JvmType jvmType = this._typeReferences.findDeclaredType(annotationType, context); + boolean _xifexpression = false; + if ((jvmType instanceof JvmAnnotationType)) { + JvmAnnotationReference _annotationRef = this._annotationTypesBuilder.annotationRef(annotationType); + _xifexpression = annotations.add(_annotationRef); + } + _xblockexpression = _xifexpression; + } + return _xblockexpression; + } + + protected void _transform(final JnarioFunction source, final JvmGenericType container) { + final JvmOperation operation = this.typesFactory.createJvmOperation(); + operation.setAbstract(false); + operation.setNative(false); + operation.setSynchronized(false); + operation.setStrictFloatingPoint(false); + boolean _isAbstract = operation.isAbstract(); + boolean _not = (!_isAbstract); + if (_not) { + operation.setFinal(source.isFinal()); + } + container.getMembers().add(operation); + this.modelAssociator.associatePrimary(source, operation); + final String sourceName = source.getName(); + final JvmVisibility visibility = source.getVisibility(); + operation.setSimpleName(sourceName); + operation.setVisibility(visibility); + operation.setStatic(source.isStatic()); + if ((((!operation.isAbstract()) && (!operation.isStatic())) && container.isInterface())) { + operation.setDefault(true); + } + EList _parameters = source.getParameters(); + for (final JnarioParameter parameter : _parameters) { + this.translateParameter(operation, parameter); + } + final XExpression expression = source.getExpression(); + JvmTypeReference returnType = null; + JvmTypeReference _returnType = source.getReturnType(); + boolean _notEquals = (!Objects.equal(_returnType, null)); + if (_notEquals) { + returnType = this._jvmTypesBuilder.cloneWithProxies(source.getReturnType()); + } else { + boolean _notEquals_1 = (!Objects.equal(expression, null)); + if (_notEquals_1) { + returnType = this._jvmTypesBuilder.inferredType(expression); + } else { + returnType = this._jvmTypesBuilder.inferredType(); + } + } + operation.setReturnType(returnType); + this.copyAndFixTypeParameters(source.getTypeParameters(), operation); + EList _exceptions = source.getExceptions(); + for (final JvmTypeReference exception : _exceptions) { + EList _exceptions_1 = operation.getExceptions(); + JvmTypeReference _cloneWithProxies = this._jvmTypesBuilder.cloneWithProxies(exception); + this._jvmTypesBuilder.operator_add(_exceptions_1, _cloneWithProxies); + } + this.translateAnnotations(operation, source.getAnnotations()); + this._jvmTypesBuilder.setBody(operation, expression); + this._jvmTypesBuilder.copyDocumentationTo(source, operation); + } + + protected void translateParameter(final JvmExecutable executable, final JnarioParameter parameter) { + final JvmFormalParameter jvmParam = this.typesFactory.createJvmFormalParameter(); + jvmParam.setName(parameter.getName()); + boolean _isVarArg = parameter.isVarArg(); + if (_isVarArg) { + executable.setVarArgs(true); + final JvmGenericArrayTypeReference arrayType = this._typeReferences.createArrayType(this._jvmTypesBuilder.cloneWithProxies(parameter.getParameterType())); + jvmParam.setParameterType(arrayType); + } else { + jvmParam.setParameterType(this._jvmTypesBuilder.cloneWithProxies(parameter.getParameterType())); + } + this.modelAssociator.associate(parameter, jvmParam); + this.translateAnnotations(jvmParam, parameter.getAnnotations()); + this.addAnnotationIfFound(jvmParam.getAnnotations(), Extension.class, parameter); + EList _parameters = executable.getParameters(); + this._jvmTypesBuilder.operator_add(_parameters, jvmParam); + } + + protected void copyAndFixTypeParameters(final List typeParameters, final JvmTypeParameterDeclarator target) { + this.copyTypeParameters(typeParameters, target); + this.fixTypeParameters(target); + } + + protected void copyTypeParameters(final List typeParameters, final JvmTypeParameterDeclarator target) { + for (final JvmTypeParameter typeParameter : typeParameters) { + { + final JvmTypeParameter clonedTypeParameter = this._jvmTypesBuilder.cloneWithProxies(typeParameter); + boolean _notEquals = (!Objects.equal(clonedTypeParameter, null)); + if (_notEquals) { + target.getTypeParameters().add(clonedTypeParameter); + this.modelAssociator.associate(typeParameter, clonedTypeParameter); + } + } + } + } + + protected void fixTypeParameters(final JvmTypeParameterDeclarator target) { + EList _typeParameters = target.getTypeParameters(); + for (final JvmTypeParameter typeParameter : _typeParameters) { + boolean _isEmpty = IterableExtensions.isEmpty(Iterables.filter(typeParameter.getConstraints(), JvmUpperBound.class)); + if (_isEmpty) { + final JvmUpperBound upperBound = this.typesFactory.createJvmUpperBound(); + upperBound.setTypeReference(this._typeReferences.getTypeForName(Object.class, target)); + EList _constraints = typeParameter.getConstraints(); + this._jvmTypesBuilder.operator_add(_constraints, upperBound); + } + } + } + + protected void _transform(final JnarioMember source, final JvmGenericType container) { + EClass _eClass = source.eClass(); + String _plus = ("Not implemented for type: " + _eClass); + throw new RuntimeException(_plus); + } + + protected String computeFieldName(final JnarioField field) { + String _xblockexpression = null; + { + String _name = field.getName(); + boolean _notEquals = (!Objects.equal(_name, null)); + if (_notEquals) { + return field.getName(); + } + JvmTypeReference type = field.getType(); + String name = null; + boolean _notEquals_1 = (!Objects.equal(type, null)); + if (_notEquals_1) { + while ((type instanceof JvmGenericArrayTypeReference)) { + type = ((JvmGenericArrayTypeReference)type).getComponentType(); + } + if ((type instanceof JvmParameterizedTypeReference)) { + final List nodes = NodeModelUtils.findNodesForFeature(type, + TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE); + boolean _isEmpty = nodes.isEmpty(); + boolean _not = (!_isEmpty); + if (_not) { + String typeName = nodes.get(0).getText().trim(); + final int lastDot = typeName.lastIndexOf("."); + if ((lastDot != (-1))) { + typeName = typeName.substring((lastDot + 1)); + } + String _firstLower = Strings.toFirstLower(typeName); + String _plus = ("_" + _firstLower); + name = _plus; + } + } + } + _xblockexpression = name; + } + return _xblockexpression; + } + + /** + * Prevents error message + * Cannot root object twice: JvmGenericType: org.jnario.jnario.tests.integration.ParsingSpecResultsFromJUnitXMLReportsFeatureMatchingFailedSpecRuns .... + *
    + *
    + * This solution developed by Lorenzo BettiniFriend and published here + * https://www.eclipse.org/forums/index.php/t/864890/ + *
    + * Thank you very much! + */ + protected void translateAnnotations(final JvmAnnotationTarget target, final List annotations) { + final Function1 _function = new Function1() { + @Override + public Boolean apply(final XAnnotation it) { + JvmType _annotationType = null; + if (it!=null) { + _annotationType=it.getAnnotationType(); + } + return Boolean.valueOf((!Objects.equal(_annotationType, null))); + } + }; + Iterable annotationsToAdd = IterableExtensions.filter(annotations, _function); + for (final XAnnotation a : annotationsToAdd) { + { + final JvmAnnotationReference annotationReference = this._jvmTypesBuilder.getJvmAnnotationReference(a); + boolean _notEquals = (!Objects.equal(annotationReference, null)); + if (_notEquals) { + final Function1 _function_1 = new Function1() { + @Override + public Boolean apply(final EObject it) { + return Boolean.valueOf((it != annotationReference)); + } + }; + final List associatedElements = IterableExtensions.toList(IterableExtensions.filter(this._iJvmModelAssociations.getJvmElements(a), _function_1)); + boolean _isEmpty = associatedElements.isEmpty(); + boolean _not = (!_isEmpty); + if (_not) { + final Consumer _function_2 = new Consumer() { + @Override + public void accept(final EObject assoc) { + JnarioJvmModelInferrer.this.modelAssociator.removeAllAssociation(assoc); + } + }; + associatedElements.forEach(_function_2); + } + EList _annotations = target.getAnnotations(); + this._jvmTypesBuilder.operator_add(_annotations, annotationReference); + } + } + } + } + + protected void transform(final JnarioMember source, final JvmGenericType container) { + if (source instanceof JnarioField) { + _transform((JnarioField)source, container); + return; + } else if (source instanceof JnarioFunction) { + _transform((JnarioFunction)source, container); + return; + } else if (source != null) { + _transform(source, container); + return; + } else { + throw new IllegalArgumentException("Unhandled parameter types: " + + Arrays.asList(source, container).toString()); + } + } +} diff --git a/plugins/org.jnario/xtend-gen/org/jnario/jvmmodel/TestRuntimeProvider.java b/plugins/org.jnario/xtend-gen/org/jnario/jvmmodel/TestRuntimeProvider.java index bc1e57afd..2c3b327cd 100644 --- a/plugins/org.jnario/xtend-gen/org/jnario/jvmmodel/TestRuntimeProvider.java +++ b/plugins/org.jnario/xtend-gen/org/jnario/jvmmodel/TestRuntimeProvider.java @@ -1,48 +1,48 @@ -package org.jnario.jvmmodel; - -import com.google.common.base.Objects; -import com.google.inject.Inject; -import com.google.inject.Provider; -import java.util.NoSuchElementException; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.xtext.common.types.JvmType; -import org.eclipse.xtext.common.types.util.TypeReferences; -import org.eclipse.xtext.xbase.lib.Extension; -import org.jnario.jvmmodel.JUnit3RuntimeSupport; -import org.jnario.jvmmodel.JUnit4RuntimeSupport; -import org.jnario.jvmmodel.TestRuntimeSupport; - -@SuppressWarnings("all") -public class TestRuntimeProvider { - private Provider junit4Support; - - private Provider junit3Support; - - private final static String JUNIT3_CLASS = "junit.framework.TestCase"; - - private final static String JUNIT4_CLASS = "org.junit.rules.TestRule"; - - @Extension - private TypeReferences typeReferences; - - @Inject - public TestRuntimeProvider(final TypeReferences typeReferences, final Provider junit3Support, final Provider junit4Support) { - this.typeReferences = typeReferences; - this.junit3Support = junit3Support; - this.junit4Support = junit4Support; - } - - public TestRuntimeSupport get(final EObject context) { - JvmType _findDeclaredType = this.typeReferences.findDeclaredType(TestRuntimeProvider.JUNIT4_CLASS, context); - boolean _notEquals = (!Objects.equal(_findDeclaredType, null)); - if (_notEquals) { - return this.junit4Support.get(); - } - JvmType _findDeclaredType_1 = this.typeReferences.findDeclaredType(TestRuntimeProvider.JUNIT3_CLASS, context); - boolean _notEquals_1 = (!Objects.equal(_findDeclaredType_1, null)); - if (_notEquals_1) { - return this.junit3Support.get(); - } - throw new NoSuchElementException("Mandatory test library bundle \'org.junit\' 3.8.x or 4.8.x not found on the classpath."); - } -} +package org.jnario.jvmmodel; + +import com.google.common.base.Objects; +import com.google.inject.Inject; +import com.google.inject.Provider; +import java.util.NoSuchElementException; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.xtext.common.types.JvmType; +import org.eclipse.xtext.common.types.util.TypeReferences; +import org.eclipse.xtext.xbase.lib.Extension; +import org.jnario.jvmmodel.JUnit3RuntimeSupport; +import org.jnario.jvmmodel.JUnit4RuntimeSupport; +import org.jnario.jvmmodel.TestRuntimeSupport; + +@SuppressWarnings("all") +public class TestRuntimeProvider { + private Provider junit4Support; + + private Provider junit3Support; + + private final static String JUNIT3_CLASS = "junit.framework.TestCase"; + + private final static String JUNIT4_CLASS = "org.junit.rules.TestRule"; + + @Extension + private TypeReferences typeReferences; + + @Inject + public TestRuntimeProvider(final TypeReferences typeReferences, final Provider junit3Support, final Provider junit4Support) { + this.typeReferences = typeReferences; + this.junit3Support = junit3Support; + this.junit4Support = junit4Support; + } + + public TestRuntimeSupport get(final EObject context) { + JvmType _findDeclaredType = this.typeReferences.findDeclaredType(TestRuntimeProvider.JUNIT4_CLASS, context); + boolean _notEquals = (!Objects.equal(_findDeclaredType, null)); + if (_notEquals) { + return this.junit4Support.get(); + } + JvmType _findDeclaredType_1 = this.typeReferences.findDeclaredType(TestRuntimeProvider.JUNIT3_CLASS, context); + boolean _notEquals_1 = (!Objects.equal(_findDeclaredType_1, null)); + if (_notEquals_1) { + return this.junit3Support.get(); + } + throw new NoSuchElementException("Mandatory test library bundle \'org.junit\' 3.8.x or 4.8.x not found on the classpath."); + } +} diff --git a/plugins/org.jnario/xtend-gen/org/jnario/report/HashBasedSpec2ResultMapping.java b/plugins/org.jnario/xtend-gen/org/jnario/report/HashBasedSpec2ResultMapping.java index 37aa6ad09..a927bb1a2 100644 --- a/plugins/org.jnario/xtend-gen/org/jnario/report/HashBasedSpec2ResultMapping.java +++ b/plugins/org.jnario/xtend-gen/org/jnario/report/HashBasedSpec2ResultMapping.java @@ -1,202 +1,197 @@ -package org.jnario.report; - -import com.google.common.base.Objects; -import com.google.common.collect.Iterables; -import com.google.inject.Inject; -import java.util.HashMap; -import java.util.List; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.xtext.resource.IResourceServiceProvider; -import org.eclipse.xtext.resource.XtextResource; -import org.eclipse.xtext.util.Strings; -import org.eclipse.xtext.xbase.lib.CollectionLiterals; -import org.eclipse.xtext.xbase.lib.Extension; -import org.eclipse.xtext.xbase.lib.Functions.Function1; -import org.eclipse.xtext.xbase.lib.Functions.Function2; -import org.eclipse.xtext.xbase.lib.IterableExtensions; -import org.eclipse.xtext.xbase.lib.ListExtensions; -import org.eclipse.xtext.xbase.lib.Pair; -import org.jnario.Executable; -import org.jnario.jvmmodel.ExecutableProvider; -import org.jnario.jvmmodel.JnarioNameProvider; -import org.jnario.report.Executable2ResultMapping; -import org.jnario.report.Failed; -import org.jnario.report.NotRun; -import org.jnario.report.Passed; -import org.jnario.report.Pending; -import org.jnario.report.SpecExecution; -import org.jnario.report.SpecExecutionAcceptor; -import org.jnario.report.SpecFailure; - -@SuppressWarnings("all") -public class HashBasedSpec2ResultMapping implements SpecExecutionAcceptor, Executable2ResultMapping { - private final HashMap, SpecExecution> results = CollectionLiterals., SpecExecution>newHashMap(); - - @Extension - private JnarioNameProvider nameProvider; - - @Inject - public HashBasedSpec2ResultMapping(final JnarioNameProvider nameProvider) { - this.nameProvider = nameProvider; - } - - @Override - public SpecExecution getResult(final Executable executable) { - SpecExecution _xblockexpression = null; - { - boolean _equals = Objects.equal(executable, null); - if (_equals) { - return new NotRun("", ""); - } - Pair _asKey = this.asKey(executable); - SpecExecution result = this.results.get(_asKey); - boolean _notEquals = (!Objects.equal(result, null)); - if (_notEquals) { - return result; - } - SpecExecution _calculateResult = this.calculateResult(executable); - result = _calculateResult; - this.accept(result); - _xblockexpression = result; - } - return _xblockexpression; - } - - private SpecExecution calculateResult(final Executable specification) { - SpecExecution _xblockexpression = null; - { - final List children = this.executables(specification); - final Function1 _function = new Function1() { - @Override - public SpecExecution apply(final Executable it) { - return HashBasedSpec2ResultMapping.this.getResult(it); - } - }; - List _map = ListExtensions.map(children, _function); - final List results = IterableExtensions.toList(_map); - _xblockexpression = this.createResult(specification, results); - } - return _xblockexpression; - } - - private SpecExecution createResult(final Executable specification, final Iterable children) { - SpecExecution _xblockexpression = null; - { - final Pair specId = this.asKey(specification); - boolean _areNotExecuted = this.areNotExecuted(children); - if (_areNotExecuted) { - return this.notRunOrPending(specification, specId); - } - final Double executionTime = this.executionTime(children); - final Function1> _function = new Function1>() { - @Override - public List apply(final SpecExecution it) { - return it.getFailures(); - } - }; - Iterable> _map = IterableExtensions.>map(children, _function); - final Iterable failures = Iterables.concat(_map); - SpecExecution _xifexpression = null; - boolean _isEmpty = IterableExtensions.isEmpty(failures); - if (_isEmpty) { - _xifexpression = this.passedOrPending(specification, specId, (executionTime).doubleValue()); - } else { - String _key = specId.getKey(); - String _value = specId.getValue(); - _xifexpression = new Failed(_key, _value, (executionTime).doubleValue(), failures); - } - _xblockexpression = _xifexpression; - } - return _xblockexpression; - } - - private SpecExecution notRunOrPending(final Executable executable, final Pair specId) { - SpecExecution _xifexpression = null; - boolean _isPending = executable.isPending(); - if (_isPending) { - String _key = specId.getKey(); - String _value = specId.getValue(); - _xifexpression = new Pending(_key, _value, 0.0); - } else { - String _key_1 = specId.getKey(); - String _value_1 = specId.getValue(); - _xifexpression = new NotRun(_key_1, _value_1); - } - return _xifexpression; - } - - private SpecExecution passedOrPending(final Executable executable, final Pair specId, final double executionTime) { - SpecExecution _xifexpression = null; - boolean _isPending = executable.isPending(); - if (_isPending) { - String _key = specId.getKey(); - String _value = specId.getValue(); - _xifexpression = new Pending(_key, _value, executionTime); - } else { - String _key_1 = specId.getKey(); - String _value_1 = specId.getValue(); - _xifexpression = new Passed(_key_1, _value_1, executionTime); - } - return _xifexpression; - } - - private Double executionTime(final Iterable results) { - final Function2 _function = new Function2() { - @Override - public Double apply(final Double sum, final SpecExecution result) { - double _executionTimeInSeconds = result.getExecutionTimeInSeconds(); - return Double.valueOf(((sum).doubleValue() + _executionTimeInSeconds)); - } - }; - return IterableExtensions.fold(results, Double.valueOf(0.0), _function); - } - - private boolean areNotExecuted(final Iterable executions) { - return (IterableExtensions.isEmpty(executions) || (!IterableExtensions.isEmpty(Iterables.filter(executions, NotRun.class)))); - } - - private Pair asKey(final Executable executable) { - Pair _xblockexpression = null; - { - String _qualifiedJavaClassName = this.nameProvider.toQualifiedJavaClassName(executable); - String _convertFromJavaString = null; - if (_qualifiedJavaClassName!=null) { - _convertFromJavaString=Strings.convertFromJavaString(_qualifiedJavaClassName, true); - } - final String expectedClassName = _convertFromJavaString; - String _describe = this.nameProvider.describe(executable); - String _convertFromJavaString_1 = null; - if (_describe!=null) { - _convertFromJavaString_1=Strings.convertFromJavaString(_describe, true); - } - final String expectedName = _convertFromJavaString_1; - final Pair key = Pair.of(expectedClassName, expectedName); - _xblockexpression = key; - } - return _xblockexpression; - } - - private List executables(final Executable element) { - List _xblockexpression = null; - { - Resource _eResource = element.eResource(); - final XtextResource resource = ((XtextResource) _eResource); - boolean _equals = Objects.equal(resource, null); - if (_equals) { - return CollectionLiterals.emptyList(); - } - final IResourceServiceProvider resourceServiceProvider = resource.getResourceServiceProvider(); - ExecutableProvider _get = resourceServiceProvider.get(ExecutableProvider.class); - _xblockexpression = _get.getExecutables(element); - } - return _xblockexpression; - } - - @Override - public void accept(final SpecExecution result) { - String _className = result.getClassName(); - String _name = result.getName(); - final Pair key = Pair.of(_className, _name); - this.results.put(key, result); - } -} +package org.jnario.report; + +import com.google.common.base.Objects; +import com.google.common.collect.Iterables; +import com.google.inject.Inject; +import java.util.HashMap; +import java.util.List; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.xtext.resource.IResourceServiceProvider; +import org.eclipse.xtext.resource.XtextResource; +import org.eclipse.xtext.util.Strings; +import org.eclipse.xtext.xbase.lib.CollectionLiterals; +import org.eclipse.xtext.xbase.lib.Extension; +import org.eclipse.xtext.xbase.lib.Functions.Function1; +import org.eclipse.xtext.xbase.lib.Functions.Function2; +import org.eclipse.xtext.xbase.lib.IterableExtensions; +import org.eclipse.xtext.xbase.lib.ListExtensions; +import org.eclipse.xtext.xbase.lib.Pair; +import org.jnario.Executable; +import org.jnario.jvmmodel.ExecutableProvider; +import org.jnario.jvmmodel.JnarioNameProvider; +import org.jnario.report.Executable2ResultMapping; +import org.jnario.report.Failed; +import org.jnario.report.NotRun; +import org.jnario.report.Passed; +import org.jnario.report.Pending; +import org.jnario.report.SpecExecution; +import org.jnario.report.SpecExecutionAcceptor; +import org.jnario.report.SpecFailure; + +@SuppressWarnings("all") +public class HashBasedSpec2ResultMapping implements SpecExecutionAcceptor, Executable2ResultMapping { + private final HashMap, SpecExecution> results = CollectionLiterals., SpecExecution>newHashMap(); + + @Extension + private JnarioNameProvider nameProvider; + + @Inject + public HashBasedSpec2ResultMapping(final JnarioNameProvider nameProvider) { + this.nameProvider = nameProvider; + } + + @Override + public SpecExecution getResult(final Executable executable) { + SpecExecution _xblockexpression = null; + { + boolean _equals = Objects.equal(executable, null); + if (_equals) { + return new NotRun("", ""); + } + SpecExecution result = this.results.get(this.asKey(executable)); + boolean _notEquals = (!Objects.equal(result, null)); + if (_notEquals) { + return result; + } + result = this.calculateResult(executable); + this.accept(result); + _xblockexpression = result; + } + return _xblockexpression; + } + + private SpecExecution calculateResult(final Executable specification) { + SpecExecution _xblockexpression = null; + { + final List children = this.executables(specification); + final Function1 _function = new Function1() { + @Override + public SpecExecution apply(final Executable it) { + return HashBasedSpec2ResultMapping.this.getResult(it); + } + }; + final List results = IterableExtensions.toList(ListExtensions.map(children, _function)); + _xblockexpression = this.createResult(specification, results); + } + return _xblockexpression; + } + + private SpecExecution createResult(final Executable specification, final Iterable children) { + SpecExecution _xblockexpression = null; + { + final Pair specId = this.asKey(specification); + boolean _areNotExecuted = this.areNotExecuted(children); + if (_areNotExecuted) { + return this.notRunOrPending(specification, specId); + } + final Double executionTime = this.executionTime(children); + final Function1> _function = new Function1>() { + @Override + public List apply(final SpecExecution it) { + return it.getFailures(); + } + }; + final Iterable failures = Iterables.concat(IterableExtensions.>map(children, _function)); + SpecExecution _xifexpression = null; + boolean _isEmpty = IterableExtensions.isEmpty(failures); + if (_isEmpty) { + _xifexpression = this.passedOrPending(specification, specId, (executionTime).doubleValue()); + } else { + String _key = specId.getKey(); + String _value = specId.getValue(); + _xifexpression = new Failed(_key, _value, (executionTime).doubleValue(), failures); + } + _xblockexpression = _xifexpression; + } + return _xblockexpression; + } + + private SpecExecution notRunOrPending(final Executable executable, final Pair specId) { + SpecExecution _xifexpression = null; + boolean _isPending = executable.isPending(); + if (_isPending) { + String _key = specId.getKey(); + String _value = specId.getValue(); + _xifexpression = new Pending(_key, _value, 0.0); + } else { + String _key_1 = specId.getKey(); + String _value_1 = specId.getValue(); + _xifexpression = new NotRun(_key_1, _value_1); + } + return _xifexpression; + } + + private SpecExecution passedOrPending(final Executable executable, final Pair specId, final double executionTime) { + SpecExecution _xifexpression = null; + boolean _isPending = executable.isPending(); + if (_isPending) { + String _key = specId.getKey(); + String _value = specId.getValue(); + _xifexpression = new Pending(_key, _value, executionTime); + } else { + String _key_1 = specId.getKey(); + String _value_1 = specId.getValue(); + _xifexpression = new Passed(_key_1, _value_1, executionTime); + } + return _xifexpression; + } + + private Double executionTime(final Iterable results) { + final Function2 _function = new Function2() { + @Override + public Double apply(final Double sum, final SpecExecution result) { + double _executionTimeInSeconds = result.getExecutionTimeInSeconds(); + return Double.valueOf(((sum).doubleValue() + _executionTimeInSeconds)); + } + }; + return IterableExtensions.fold(results, Double.valueOf(0.0), _function); + } + + private boolean areNotExecuted(final Iterable executions) { + return (IterableExtensions.isEmpty(executions) || (!IterableExtensions.isEmpty(Iterables.filter(executions, NotRun.class)))); + } + + private Pair asKey(final Executable executable) { + Pair _xblockexpression = null; + { + String _qualifiedJavaClassName = this.nameProvider.toQualifiedJavaClassName(executable); + String _convertFromJavaString = null; + if (_qualifiedJavaClassName!=null) { + _convertFromJavaString=Strings.convertFromJavaString(_qualifiedJavaClassName, true); + } + final String expectedClassName = _convertFromJavaString; + String _describe = this.nameProvider.describe(executable); + String _convertFromJavaString_1 = null; + if (_describe!=null) { + _convertFromJavaString_1=Strings.convertFromJavaString(_describe, true); + } + final String expectedName = _convertFromJavaString_1; + final Pair key = Pair.of(expectedClassName, expectedName); + _xblockexpression = key; + } + return _xblockexpression; + } + + private List executables(final Executable element) { + List _xblockexpression = null; + { + Resource _eResource = element.eResource(); + final XtextResource resource = ((XtextResource) _eResource); + boolean _equals = Objects.equal(resource, null); + if (_equals) { + return CollectionLiterals.emptyList(); + } + final IResourceServiceProvider resourceServiceProvider = resource.getResourceServiceProvider(); + _xblockexpression = resourceServiceProvider.get(ExecutableProvider.class).getExecutables(element); + } + return _xblockexpression; + } + + @Override + public void accept(final SpecExecution result) { + String _className = result.getClassName(); + String _name = result.getName(); + final Pair key = Pair.of(_className, _name); + this.results.put(key, result); + } +} diff --git a/plugins/org.jnario/xtend-gen/org/jnario/report/NotRun.java b/plugins/org.jnario/xtend-gen/org/jnario/report/NotRun.java index ac82a35ea..abd9e54fb 100644 --- a/plugins/org.jnario/xtend-gen/org/jnario/report/NotRun.java +++ b/plugins/org.jnario/xtend-gen/org/jnario/report/NotRun.java @@ -1,12 +1,12 @@ -package org.jnario.report; - -import org.eclipse.xtext.xbase.lib.CollectionLiterals; -import org.jnario.report.SpecExecution; -import org.jnario.report.SpecFailure; - -@SuppressWarnings("all") -public class NotRun extends SpecExecution { - public NotRun(final String className, final String name) { - super(className, name, 0.0, CollectionLiterals.emptyList()); - } -} +package org.jnario.report; + +import org.eclipse.xtext.xbase.lib.CollectionLiterals; +import org.jnario.report.SpecExecution; +import org.jnario.report.SpecFailure; + +@SuppressWarnings("all") +public class NotRun extends SpecExecution { + public NotRun(final String className, final String name) { + super(className, name, 0.0, CollectionLiterals.emptyList()); + } +} diff --git a/plugins/org.jnario/xtend-gen/org/jnario/report/Passed.java b/plugins/org.jnario/xtend-gen/org/jnario/report/Passed.java index b5b1640c4..2215c6620 100644 --- a/plugins/org.jnario/xtend-gen/org/jnario/report/Passed.java +++ b/plugins/org.jnario/xtend-gen/org/jnario/report/Passed.java @@ -1,16 +1,16 @@ -package org.jnario.report; - -import org.eclipse.xtext.xbase.lib.CollectionLiterals; -import org.jnario.report.SpecExecution; -import org.jnario.report.SpecFailure; - -@SuppressWarnings("all") -public class Passed extends SpecExecution { - public static Passed passingSpec(final String className, final String name, final double executionTimeInSeconds) { - return new Passed(className, name, executionTimeInSeconds); - } - - public Passed(final String className, final String name, final double executionTimeInSeconds) { - super(className, name, executionTimeInSeconds, CollectionLiterals.emptyList()); - } -} +package org.jnario.report; + +import org.eclipse.xtext.xbase.lib.CollectionLiterals; +import org.jnario.report.SpecExecution; +import org.jnario.report.SpecFailure; + +@SuppressWarnings("all") +public class Passed extends SpecExecution { + public static Passed passingSpec(final String className, final String name, final double executionTimeInSeconds) { + return new Passed(className, name, executionTimeInSeconds); + } + + public Passed(final String className, final String name, final double executionTimeInSeconds) { + super(className, name, executionTimeInSeconds, CollectionLiterals.emptyList()); + } +} diff --git a/plugins/org.jnario/xtend-gen/org/jnario/report/Pending.java b/plugins/org.jnario/xtend-gen/org/jnario/report/Pending.java index a1a220552..162d94b34 100644 --- a/plugins/org.jnario/xtend-gen/org/jnario/report/Pending.java +++ b/plugins/org.jnario/xtend-gen/org/jnario/report/Pending.java @@ -1,17 +1,17 @@ -package org.jnario.report; - -import org.eclipse.xtext.xbase.lib.CollectionLiterals; -import org.jnario.report.Passed; -import org.jnario.report.SpecExecution; -import org.jnario.report.SpecFailure; - -@SuppressWarnings("all") -public class Pending extends SpecExecution { - public static Passed pendingSpec(final String className, final String name, final double executionTimeInSeconds) { - return new Passed(className, name, executionTimeInSeconds); - } - - public Pending(final String className, final String name, final double executionTimeInSeconds) { - super(className, name, executionTimeInSeconds, CollectionLiterals.emptyList()); - } -} +package org.jnario.report; + +import org.eclipse.xtext.xbase.lib.CollectionLiterals; +import org.jnario.report.Passed; +import org.jnario.report.SpecExecution; +import org.jnario.report.SpecFailure; + +@SuppressWarnings("all") +public class Pending extends SpecExecution { + public static Passed pendingSpec(final String className, final String name, final double executionTimeInSeconds) { + return new Passed(className, name, executionTimeInSeconds); + } + + public Pending(final String className, final String name, final double executionTimeInSeconds) { + super(className, name, executionTimeInSeconds, CollectionLiterals.emptyList()); + } +} diff --git a/plugins/org.jnario/xtend-gen/org/jnario/report/SpecResultParser.java b/plugins/org.jnario/xtend-gen/org/jnario/report/SpecResultParser.java index 8840a10dc..ad8118484 100644 --- a/plugins/org.jnario/xtend-gen/org/jnario/report/SpecResultParser.java +++ b/plugins/org.jnario/xtend-gen/org/jnario/report/SpecResultParser.java @@ -1,211 +1,197 @@ -package org.jnario.report; - -import com.google.common.base.Objects; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.List; -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; -import org.eclipse.xtext.xbase.lib.CollectionLiterals; -import org.eclipse.xtext.xbase.lib.Exceptions; -import org.eclipse.xtext.xbase.lib.Pair; -import org.jnario.report.Failed; -import org.jnario.report.Passed; -import org.jnario.report.Pending; -import org.jnario.report.SpecExecution; -import org.jnario.report.SpecExecutionAcceptor; -import org.jnario.report.SpecFailure; -import org.jnario.report.SpecResultTags; -import org.jnario.util.Strings; -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; -import org.xml.sax.helpers.DefaultHandler; - -@SuppressWarnings("all") -public class SpecResultParser extends DefaultHandler { - private double currentExecutionTime; - - private String currentClassName; - - private String currentName; - - private SpecExecutionAcceptor acceptor; - - private String currentFailureType; - - private StringBuilder currentFailureStacktrace = new StringBuilder(); - - private boolean isPending = false; - - private List failures; - - public void parse(final InputStream stream, final SpecExecutionAcceptor acceptor) { - try { - this.acceptor = acceptor; - final SAXParserFactory factory = SAXParserFactory.newInstance(); - final SAXParser saxParser = factory.newSAXParser(); - saxParser.parse(stream, this); - } catch (Throwable _e) { - throw Exceptions.sneakyThrow(_e); - } - } - - @Override - public void startElement(final String uri, final String localName, final String qName, final Attributes attributes) throws SAXException { - boolean _matched = false; - if (Objects.equal(qName, SpecResultTags.NODE_TESTCASE)) { - _matched=true; - String _convertValue = this.convertValue(attributes, SpecResultTags.ATTR_CLASSNAME); - this.currentClassName = _convertValue; - String _convertValue_1 = this.convertValue(attributes, SpecResultTags.ATTR_NAME); - this.currentName = _convertValue_1; - double _readTime = this.readTime(attributes); - this.currentExecutionTime = _readTime; - ArrayList _newArrayList = CollectionLiterals.newArrayList(); - this.failures = _newArrayList; - } - if (!_matched) { - if (Objects.equal(qName, SpecResultTags.NODE_ERROR)) { - _matched=true; - this.saveFailureAttributes(attributes); - } - } - if (!_matched) { - if (Objects.equal(qName, SpecResultTags.NODE_FAILURE)) { - _matched=true; - this.saveFailureAttributes(attributes); - StringBuilder _stringBuilder = new StringBuilder(); - this.currentFailureStacktrace = _stringBuilder; - } - } - if (!_matched) { - if (Objects.equal(qName, SpecResultTags.NODE_SKIPPED)) { - _matched=true; - this.isPending = true; - } - } - } - - public String saveFailureAttributes(final Attributes attributes) { - String _convertValue = this.convertValue(attributes, SpecResultTags.ATTR_TYPE); - return this.currentFailureType = _convertValue; - } - - @Override - public void endElement(final String uri, final String localName, final String qName) throws SAXException { - boolean _matched = false; - if (Objects.equal(qName, SpecResultTags.NODE_TESTCASE)) { - _matched=true; - SpecExecution _newSpecExecution = this.newSpecExecution(); - this.acceptor.accept(_newSpecExecution); - this.currentClassName = null; - this.currentName = null; - this.currentExecutionTime = 0.0; - } - if (!_matched) { - if (Objects.equal(qName, SpecResultTags.NODE_ERROR)) { - _matched=true; - this.addFailure(); - } - } - if (!_matched) { - if (Objects.equal(qName, SpecResultTags.NODE_FAILURE)) { - _matched=true; - this.addFailure(); - } - } - } - - public StringBuilder addFailure() { - StringBuilder _xblockexpression = null; - { - final String stacktrace = this.currentFailureStacktrace.toString(); - final Pair errorMessage = this.extractMessage(stacktrace); - String _key = errorMessage.getKey(); - String _value = errorMessage.getValue(); - SpecFailure _specFailure = new SpecFailure(_key, - this.currentFailureType, _value); - this.failures.add(_specFailure); - this.currentFailureType = null; - StringBuilder _stringBuilder = new StringBuilder(); - _xblockexpression = this.currentFailureStacktrace = _stringBuilder; - } - return _xblockexpression; - } - - private Pair extractMessage(final String messageAndStacktrace) { - Pair _xblockexpression = null; - { - final int end = messageAndStacktrace.indexOf("\tat "); - String message = ""; - String stacktrace = ""; - if ((end > (-1))) { - String _substring = messageAndStacktrace.substring(0, (end - 1)); - message = _substring; - int _length = messageAndStacktrace.length(); - String _substring_1 = messageAndStacktrace.substring(end, _length); - stacktrace = _substring_1; - } - String _trim = message.trim(); - String _cleanUp = this.cleanUp(_trim); - message = _cleanUp; - String _cleanUp_1 = this.cleanUp(stacktrace); - _xblockexpression = Pair.of(message, _cleanUp_1); - } - return _xblockexpression; - } - - private String cleanUp(final String s) { - return s.replaceAll("\n\t", "\n"); - } - - @Override - public void characters(final char[] ch, final int start, final int length) throws SAXException { - String _valueOf = String.valueOf(ch, start, length); - this.currentFailureStacktrace.append(_valueOf); - } - - public SpecExecution newSpecExecution() { - SpecExecution _xifexpression = null; - if (this.isPending) { - _xifexpression = new Pending(this.currentClassName, this.currentName, this.currentExecutionTime); - } else { - SpecExecution _xifexpression_1 = null; - boolean _isEmpty = this.failures.isEmpty(); - if (_isEmpty) { - _xifexpression_1 = new Passed(this.currentClassName, this.currentName, this.currentExecutionTime); - } else { - _xifexpression_1 = new Failed(this.currentClassName, this.currentName, this.currentExecutionTime, this.failures); - } - _xifexpression = _xifexpression_1; - } - return _xifexpression; - } - - private double readTime(final Attributes attributes) { - final String timeString = this.convertValue(attributes, SpecResultTags.ATTR_TIME); - boolean _notEquals = (!Objects.equal(timeString, null)); - if (_notEquals) { - try { - return Double.parseDouble(timeString); - } catch (final Throwable _t) { - if (_t instanceof NumberFormatException) { - final NumberFormatException e = (NumberFormatException)_t; - } else { - throw Exceptions.sneakyThrow(_t); - } - } - } - return 0.0; - } - - public String convertValue(final Attributes attributes, final String key) { - String _xblockexpression = null; - { - String _value = attributes.getValue(key); - final String value = _value.replace("\\/", "/"); - _xblockexpression = Strings.convertFromJavaString(value, true); - } - return _xblockexpression; - } -} +package org.jnario.report; + +import com.google.common.base.Objects; +import java.io.InputStream; +import java.util.List; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; +import org.eclipse.xtext.xbase.lib.CollectionLiterals; +import org.eclipse.xtext.xbase.lib.Exceptions; +import org.eclipse.xtext.xbase.lib.Pair; +import org.jnario.report.Failed; +import org.jnario.report.Passed; +import org.jnario.report.Pending; +import org.jnario.report.SpecExecution; +import org.jnario.report.SpecExecutionAcceptor; +import org.jnario.report.SpecFailure; +import org.jnario.report.SpecResultTags; +import org.jnario.util.Strings; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.DefaultHandler; + +@SuppressWarnings("all") +public class SpecResultParser extends DefaultHandler { + private double currentExecutionTime; + + private String currentClassName; + + private String currentName; + + private SpecExecutionAcceptor acceptor; + + private String currentFailureType; + + private StringBuilder currentFailureStacktrace = new StringBuilder(); + + private boolean isPending = false; + + private List failures; + + public void parse(final InputStream stream, final SpecExecutionAcceptor acceptor) { + try { + this.acceptor = acceptor; + final SAXParserFactory factory = SAXParserFactory.newInstance(); + final SAXParser saxParser = factory.newSAXParser(); + saxParser.parse(stream, this); + } catch (Throwable _e) { + throw Exceptions.sneakyThrow(_e); + } + } + + @Override + public void startElement(final String uri, final String localName, final String qName, final Attributes attributes) throws SAXException { + boolean _matched = false; + if (Objects.equal(qName, SpecResultTags.NODE_TESTCASE)) { + _matched=true; + this.currentClassName = this.convertValue(attributes, SpecResultTags.ATTR_CLASSNAME); + this.currentName = this.convertValue(attributes, SpecResultTags.ATTR_NAME); + this.currentExecutionTime = this.readTime(attributes); + this.failures = CollectionLiterals.newArrayList(); + } + if (!_matched) { + if (Objects.equal(qName, SpecResultTags.NODE_ERROR)) { + _matched=true; + this.saveFailureAttributes(attributes); + } + } + if (!_matched) { + if (Objects.equal(qName, SpecResultTags.NODE_FAILURE)) { + _matched=true; + this.saveFailureAttributes(attributes); + StringBuilder _stringBuilder = new StringBuilder(); + this.currentFailureStacktrace = _stringBuilder; + } + } + if (!_matched) { + if (Objects.equal(qName, SpecResultTags.NODE_SKIPPED)) { + _matched=true; + this.isPending = true; + } + } + } + + public String saveFailureAttributes(final Attributes attributes) { + return this.currentFailureType = this.convertValue(attributes, SpecResultTags.ATTR_TYPE); + } + + @Override + public void endElement(final String uri, final String localName, final String qName) throws SAXException { + boolean _matched = false; + if (Objects.equal(qName, SpecResultTags.NODE_TESTCASE)) { + _matched=true; + this.acceptor.accept(this.newSpecExecution()); + this.currentClassName = null; + this.currentName = null; + this.currentExecutionTime = 0.0; + } + if (!_matched) { + if (Objects.equal(qName, SpecResultTags.NODE_ERROR)) { + _matched=true; + this.addFailure(); + } + } + if (!_matched) { + if (Objects.equal(qName, SpecResultTags.NODE_FAILURE)) { + _matched=true; + this.addFailure(); + } + } + } + + public StringBuilder addFailure() { + StringBuilder _xblockexpression = null; + { + final String stacktrace = this.currentFailureStacktrace.toString(); + final Pair errorMessage = this.extractMessage(stacktrace); + String _key = errorMessage.getKey(); + String _value = errorMessage.getValue(); + SpecFailure _specFailure = new SpecFailure(_key, + this.currentFailureType, _value); + this.failures.add(_specFailure); + this.currentFailureType = null; + StringBuilder _stringBuilder = new StringBuilder(); + _xblockexpression = this.currentFailureStacktrace = _stringBuilder; + } + return _xblockexpression; + } + + private Pair extractMessage(final String messageAndStacktrace) { + Pair _xblockexpression = null; + { + final int end = messageAndStacktrace.indexOf("\tat "); + String message = ""; + String stacktrace = ""; + if ((end > (-1))) { + message = messageAndStacktrace.substring(0, (end - 1)); + stacktrace = messageAndStacktrace.substring(end, messageAndStacktrace.length()); + } + message = this.cleanUp(message.trim()); + String _cleanUp = this.cleanUp(stacktrace); + _xblockexpression = Pair.of(message, _cleanUp); + } + return _xblockexpression; + } + + private String cleanUp(final String s) { + return s.replaceAll("\n\t", "\n"); + } + + @Override + public void characters(final char[] ch, final int start, final int length) throws SAXException { + this.currentFailureStacktrace.append(String.valueOf(ch, start, length)); + } + + public SpecExecution newSpecExecution() { + SpecExecution _xifexpression = null; + if (this.isPending) { + _xifexpression = new Pending(this.currentClassName, this.currentName, this.currentExecutionTime); + } else { + SpecExecution _xifexpression_1 = null; + boolean _isEmpty = this.failures.isEmpty(); + if (_isEmpty) { + _xifexpression_1 = new Passed(this.currentClassName, this.currentName, this.currentExecutionTime); + } else { + _xifexpression_1 = new Failed(this.currentClassName, this.currentName, this.currentExecutionTime, this.failures); + } + _xifexpression = _xifexpression_1; + } + return _xifexpression; + } + + private double readTime(final Attributes attributes) { + final String timeString = this.convertValue(attributes, SpecResultTags.ATTR_TIME); + boolean _notEquals = (!Objects.equal(timeString, null)); + if (_notEquals) { + try { + return Double.parseDouble(timeString); + } catch (final Throwable _t) { + if (_t instanceof NumberFormatException) { + final NumberFormatException e = (NumberFormatException)_t; + } else { + throw Exceptions.sneakyThrow(_t); + } + } + } + return 0.0; + } + + public String convertValue(final Attributes attributes, final String key) { + String _xblockexpression = null; + { + final String value = attributes.getValue(key).replace("\\/", "/"); + _xblockexpression = Strings.convertFromJavaString(value, true); + } + return _xblockexpression; + } +} diff --git a/plugins/org.jnario/xtend-gen/org/jnario/typing/JnarioTypeResolver.java b/plugins/org.jnario/xtend-gen/org/jnario/typing/JnarioTypeResolver.java index bf7f0b53f..6d037a37e 100644 --- a/plugins/org.jnario/xtend-gen/org/jnario/typing/JnarioTypeResolver.java +++ b/plugins/org.jnario/xtend-gen/org/jnario/typing/JnarioTypeResolver.java @@ -1,151 +1,124 @@ -package org.jnario.typing; - -import com.google.inject.Inject; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.function.Consumer; -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.xtext.common.types.JvmConstructor; -import org.eclipse.xtext.common.types.JvmField; -import org.eclipse.xtext.common.types.JvmFormalParameter; -import org.eclipse.xtext.common.types.JvmIdentifiableElement; -import org.eclipse.xtext.common.types.JvmMember; -import org.eclipse.xtext.common.types.JvmOperation; -import org.eclipse.xtext.common.types.JvmType; -import org.eclipse.xtext.common.types.JvmTypeReference; -import org.eclipse.xtext.common.types.util.TypeReferences; -import org.eclipse.xtext.xbase.XExpression; -import org.eclipse.xtext.xbase.XNullLiteral; -import org.eclipse.xtext.xbase.jvmmodel.IJvmModelAssociations; -import org.eclipse.xtext.xbase.lib.Extension; -import org.eclipse.xtext.xbase.lib.Functions.Function1; -import org.eclipse.xtext.xbase.lib.IterableExtensions; -import org.eclipse.xtext.xbase.scoping.batch.IFeatureScopeSession; -import org.eclipse.xtext.xbase.typesystem.InferredTypeIndicator; -import org.eclipse.xtext.xbase.typesystem.conformance.TypeConformanceComputer; -import org.eclipse.xtext.xbase.typesystem.internal.LogicalContainerAwareReentrantTypeResolver; -import org.eclipse.xtext.xbase.typesystem.internal.ResolvedTypes; -import org.eclipse.xtext.xbase.typesystem.references.ITypeReferenceOwner; -import org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference; -import org.eclipse.xtext.xbase.typesystem.util.CommonTypeComputationServices; -import org.eclipse.xtext.xtype.XComputedTypeReference; -import org.eclipse.xtext.xtype.XtypeFactory; -import org.jnario.ExampleCell; -import org.jnario.ExampleColumn; -import org.jnario.ExampleTable; -import org.jnario.typing.ColumnTypeProvider; - -@SuppressWarnings("all") -public class JnarioTypeResolver extends LogicalContainerAwareReentrantTypeResolver { - @Inject - @Extension - private IJvmModelAssociations _iJvmModelAssociations; - - @Override - protected void _doPrepare(final ResolvedTypes resolvedTypes, final IFeatureScopeSession session, final JvmConstructor constructor, final Map resolvedTypesByContext) { - super._doPrepare(resolvedTypes, session, constructor, resolvedTypesByContext); - final EObject source = this._iJvmModelAssociations.getPrimarySourceElement(constructor); - if ((source instanceof ExampleTable)) { - EList _parameters = constructor.getParameters(); - final Consumer _function = new Consumer() { - @Override - public void accept(final JvmFormalParameter param) { - EObject _primarySourceElement = JnarioTypeResolver.this._iJvmModelAssociations.getPrimarySourceElement(param); - final ExampleColumn column = ((ExampleColumn) _primarySourceElement); - JvmTypeReference _parameterType = param.getParameterType(); - JnarioTypeResolver.this.setColumnTypeProvider(_parameterType, constructor, resolvedTypes, session, column, resolvedTypesByContext); - } - }; - _parameters.forEach(_function); - } - } - - @Override - protected void _doPrepare(final ResolvedTypes resolvedTypes, final IFeatureScopeSession session, final JvmField field, final Map resolvedTypesByContext) { - super._doPrepare(resolvedTypes, session, field, resolvedTypesByContext); - final EObject source = this._iJvmModelAssociations.getPrimarySourceElement(field); - if ((source instanceof ExampleColumn)) { - JvmTypeReference _type = field.getType(); - this.setColumnTypeProvider(_type, field, resolvedTypes, session, ((ExampleColumn) source), resolvedTypesByContext); - } - } - - @Override - protected void _doPrepare(final ResolvedTypes resolvedTypes, final IFeatureScopeSession session, final JvmOperation operation, final Map resolvedTypesByContext) { - super._doPrepare(resolvedTypes, session, operation, resolvedTypesByContext); - final EObject source = this._iJvmModelAssociations.getPrimarySourceElement(operation); - if ((source instanceof ExampleColumn)) { - JvmTypeReference _returnType = operation.getReturnType(); - this.setColumnTypeProvider(_returnType, operation, resolvedTypes, session, ((ExampleColumn) source), resolvedTypesByContext); - } - } - - public void setColumnTypeProvider(final JvmTypeReference typeRef, final JvmMember member, final ResolvedTypes resolvedTypes, final IFeatureScopeSession session, final ExampleColumn column, final Map resolvedTypesByContext) { - boolean _isInferred = InferredTypeIndicator.isInferred(typeRef); - boolean _not = (!_isInferred); - if (_not) { - return; - } - final XComputedTypeReference casted = ((XComputedTypeReference) typeRef); - CommonTypeComputationServices _services = this.getServices(); - XtypeFactory _xtypeFactory = _services.getXtypeFactory(); - final XComputedTypeReference resultRef = _xtypeFactory.createXComputedTypeReference(); - final Function1 _function = new Function1() { - @Override - public JvmTypeReference apply(final XComputedTypeReference it) { - EList _cells = column.getCells(); - final Function1 _function = new Function1() { - @Override - public Boolean apply(final ExampleCell it) { - XExpression _expression = it.getExpression(); - return Boolean.valueOf((!(_expression instanceof XNullLiteral))); - } - }; - Iterable _filter = IterableExtensions.filter(_cells, _function); - final Function1 _function_1 = new Function1() { - @Override - public LightweightTypeReference apply(final ExampleCell it) { - LightweightTypeReference _xblockexpression = null; - { - Set _jvmElements = JnarioTypeResolver.this._iJvmModelAssociations.getJvmElements(it); - EObject _head = IterableExtensions.head(_jvmElements); - final JvmIdentifiableElement operation = ((JvmIdentifiableElement) _head); - final LightweightTypeReference type = resolvedTypes.getActualType(operation); - _xblockexpression = type; - } - return _xblockexpression; - } - }; - final Iterable types = IterableExtensions.map(_filter, _function_1); - final ITypeReferenceOwner owner = resolvedTypes.getReferenceOwner(); - boolean _isEmpty = IterableExtensions.isEmpty(types); - if (_isEmpty) { - CommonTypeComputationServices _services = JnarioTypeResolver.this.getServices(); - TypeReferences _typeReferences = _services.getTypeReferences(); - CommonTypeComputationServices _services_1 = JnarioTypeResolver.this.getServices(); - TypeReferences _typeReferences_1 = _services_1.getTypeReferences(); - JvmType _findDeclaredType = _typeReferences_1.findDeclaredType(Object.class, member); - return _typeReferences.createTypeRef(_findDeclaredType); - } - CommonTypeComputationServices _services_2 = JnarioTypeResolver.this.getServices(); - TypeConformanceComputer _typeConformanceComputer = _services_2.getTypeConformanceComputer(); - List _list = IterableExtensions.toList(types); - LightweightTypeReference result = _typeConformanceComputer.getCommonSuperType(_list, owner); - EList _cells_1 = column.getCells(); - int _size = _cells_1.size(); - int _size_1 = IterableExtensions.size(types); - boolean _notEquals = (_size != _size_1); - if (_notEquals) { - LightweightTypeReference _wrapperTypeIfPrimitive = result.getWrapperTypeIfPrimitive(); - result = _wrapperTypeIfPrimitive; - } - return result.toJavaCompliantTypeReference(); - } - }; - ColumnTypeProvider _columnTypeProvider = new ColumnTypeProvider(_function); - resultRef.setTypeProvider(_columnTypeProvider); - casted.setEquivalent(resultRef); - } -} +package org.jnario.typing; + +import com.google.inject.Inject; +import java.util.Map; +import java.util.function.Consumer; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.xtext.common.types.JvmConstructor; +import org.eclipse.xtext.common.types.JvmField; +import org.eclipse.xtext.common.types.JvmFormalParameter; +import org.eclipse.xtext.common.types.JvmIdentifiableElement; +import org.eclipse.xtext.common.types.JvmMember; +import org.eclipse.xtext.common.types.JvmOperation; +import org.eclipse.xtext.common.types.JvmTypeReference; +import org.eclipse.xtext.xbase.XExpression; +import org.eclipse.xtext.xbase.XNullLiteral; +import org.eclipse.xtext.xbase.jvmmodel.IJvmModelAssociations; +import org.eclipse.xtext.xbase.lib.Extension; +import org.eclipse.xtext.xbase.lib.Functions.Function1; +import org.eclipse.xtext.xbase.lib.IterableExtensions; +import org.eclipse.xtext.xbase.scoping.batch.IFeatureScopeSession; +import org.eclipse.xtext.xbase.typesystem.InferredTypeIndicator; +import org.eclipse.xtext.xbase.typesystem.internal.LogicalContainerAwareReentrantTypeResolver; +import org.eclipse.xtext.xbase.typesystem.internal.ResolvedTypes; +import org.eclipse.xtext.xbase.typesystem.references.ITypeReferenceOwner; +import org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference; +import org.eclipse.xtext.xtype.XComputedTypeReference; +import org.jnario.ExampleCell; +import org.jnario.ExampleColumn; +import org.jnario.ExampleTable; +import org.jnario.typing.ColumnTypeProvider; + +@SuppressWarnings("all") +public class JnarioTypeResolver extends LogicalContainerAwareReentrantTypeResolver { + @Inject + @Extension + private IJvmModelAssociations _iJvmModelAssociations; + + @Override + protected void _doPrepare(final ResolvedTypes resolvedTypes, final IFeatureScopeSession session, final JvmConstructor constructor, final Map resolvedTypesByContext) { + super._doPrepare(resolvedTypes, session, constructor, resolvedTypesByContext); + final EObject source = this._iJvmModelAssociations.getPrimarySourceElement(constructor); + if ((source instanceof ExampleTable)) { + final Consumer _function = new Consumer() { + @Override + public void accept(final JvmFormalParameter param) { + EObject _primarySourceElement = JnarioTypeResolver.this._iJvmModelAssociations.getPrimarySourceElement(param); + final ExampleColumn column = ((ExampleColumn) _primarySourceElement); + JnarioTypeResolver.this.setColumnTypeProvider(param.getParameterType(), constructor, resolvedTypes, session, column, resolvedTypesByContext); + } + }; + constructor.getParameters().forEach(_function); + } + } + + @Override + protected void _doPrepare(final ResolvedTypes resolvedTypes, final IFeatureScopeSession session, final JvmField field, final Map resolvedTypesByContext) { + super._doPrepare(resolvedTypes, session, field, resolvedTypesByContext); + final EObject source = this._iJvmModelAssociations.getPrimarySourceElement(field); + if ((source instanceof ExampleColumn)) { + this.setColumnTypeProvider(field.getType(), field, resolvedTypes, session, ((ExampleColumn) source), resolvedTypesByContext); + } + } + + @Override + protected void _doPrepare(final ResolvedTypes resolvedTypes, final IFeatureScopeSession session, final JvmOperation operation, final Map resolvedTypesByContext) { + super._doPrepare(resolvedTypes, session, operation, resolvedTypesByContext); + final EObject source = this._iJvmModelAssociations.getPrimarySourceElement(operation); + if ((source instanceof ExampleColumn)) { + this.setColumnTypeProvider(operation.getReturnType(), operation, resolvedTypes, session, ((ExampleColumn) source), resolvedTypesByContext); + } + } + + public void setColumnTypeProvider(final JvmTypeReference typeRef, final JvmMember member, final ResolvedTypes resolvedTypes, final IFeatureScopeSession session, final ExampleColumn column, final Map resolvedTypesByContext) { + boolean _isInferred = InferredTypeIndicator.isInferred(typeRef); + boolean _not = (!_isInferred); + if (_not) { + return; + } + final XComputedTypeReference casted = ((XComputedTypeReference) typeRef); + final XComputedTypeReference resultRef = this.getServices().getXtypeFactory().createXComputedTypeReference(); + final Function1 _function = new Function1() { + @Override + public JvmTypeReference apply(final XComputedTypeReference it) { + final Function1 _function = new Function1() { + @Override + public Boolean apply(final ExampleCell it) { + XExpression _expression = it.getExpression(); + return Boolean.valueOf((!(_expression instanceof XNullLiteral))); + } + }; + final Function1 _function_1 = new Function1() { + @Override + public LightweightTypeReference apply(final ExampleCell it) { + LightweightTypeReference _xblockexpression = null; + { + EObject _head = IterableExtensions.head(JnarioTypeResolver.this._iJvmModelAssociations.getJvmElements(it)); + final JvmIdentifiableElement operation = ((JvmIdentifiableElement) _head); + final LightweightTypeReference type = resolvedTypes.getActualType(operation); + _xblockexpression = type; + } + return _xblockexpression; + } + }; + final Iterable types = IterableExtensions.map(IterableExtensions.filter(column.getCells(), _function), _function_1); + final ITypeReferenceOwner owner = resolvedTypes.getReferenceOwner(); + boolean _isEmpty = IterableExtensions.isEmpty(types); + if (_isEmpty) { + return JnarioTypeResolver.this.getServices().getTypeReferences().createTypeRef(JnarioTypeResolver.this.getServices().getTypeReferences().findDeclaredType(Object.class, member)); + } + LightweightTypeReference result = JnarioTypeResolver.this.getServices().getTypeConformanceComputer().getCommonSuperType(IterableExtensions.toList(types), owner); + int _size = column.getCells().size(); + int _size_1 = IterableExtensions.size(types); + boolean _notEquals = (_size != _size_1); + if (_notEquals) { + result = result.getWrapperTypeIfPrimitive(); + } + return result.toJavaCompliantTypeReference(); + } + }; + ColumnTypeProvider _columnTypeProvider = new ColumnTypeProvider(_function); + resultRef.setTypeProvider(_columnTypeProvider); + casted.setEquivalent(resultRef); + } +} diff --git a/plugins/org.jnario/xtend-gen/org/jnario/util/IEObjectDescriptionFilter.java b/plugins/org.jnario/xtend-gen/org/jnario/util/IEObjectDescriptionFilter.java index a4271d000..e054d9276 100644 --- a/plugins/org.jnario/xtend-gen/org/jnario/util/IEObjectDescriptionFilter.java +++ b/plugins/org.jnario/xtend-gen/org/jnario/util/IEObjectDescriptionFilter.java @@ -1,65 +1,63 @@ -package org.jnario.util; - -import com.google.common.base.Predicate; -import org.eclipse.emf.ecore.EClass; -import org.eclipse.xtend.lib.Data; -import org.eclipse.xtext.resource.IEObjectDescription; -import org.eclipse.xtext.xbase.lib.Pure; -import org.eclipse.xtext.xbase.lib.util.ToStringHelper; - -@Data -@SuppressWarnings("all") -public class IEObjectDescriptionFilter implements Predicate { - private final EClass _type; - - @Override - public boolean apply(final IEObjectDescription input) { - EClass _type = this.getType(); - EClass _eClass = input.getEClass(); - return _type.isSuperTypeOf(_eClass); - } - - public IEObjectDescriptionFilter(final EClass type) { - super(); - this._type = type; - } - - @Override - @Pure - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((this._type== null) ? 0 : this._type.hashCode()); - return result; - } - - @Override - @Pure - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - IEObjectDescriptionFilter other = (IEObjectDescriptionFilter) obj; - if (this._type == null) { - if (other._type != null) - return false; - } else if (!this._type.equals(other._type)) - return false; - return true; - } - - @Override - @Pure - public String toString() { - String result = new ToStringHelper().toString(this); - return result; - } - - @Pure - public EClass getType() { - return this._type; - } -} +package org.jnario.util; + +import com.google.common.base.Predicate; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.xtend.lib.Data; +import org.eclipse.xtext.resource.IEObjectDescription; +import org.eclipse.xtext.xbase.lib.Pure; +import org.eclipse.xtext.xbase.lib.util.ToStringHelper; + +@Data +@SuppressWarnings("all") +public class IEObjectDescriptionFilter implements Predicate { + private final EClass _type; + + @Override + public boolean apply(final IEObjectDescription input) { + return this.getType().isSuperTypeOf(input.getEClass()); + } + + public IEObjectDescriptionFilter(final EClass type) { + super(); + this._type = type; + } + + @Override + @Pure + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((this._type== null) ? 0 : this._type.hashCode()); + return result; + } + + @Override + @Pure + public boolean equals(final Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + IEObjectDescriptionFilter other = (IEObjectDescriptionFilter) obj; + if (this._type == null) { + if (other._type != null) + return false; + } else if (!this._type.equals(other._type)) + return false; + return true; + } + + @Override + @Pure + public String toString() { + String result = new ToStringHelper().toString(this); + return result; + } + + @Pure + public EClass getType() { + return this._type; + } +} diff --git a/tests/org.jnario.standalone.tests/xtend-gen/org/jnario/standalone/tests/FeatureBatchCompilerTest.java b/tests/org.jnario.standalone.tests/xtend-gen/org/jnario/standalone/tests/FeatureBatchCompilerTest.java index 6b380e33e..3d30e1eac 100644 --- a/tests/org.jnario.standalone.tests/xtend-gen/org/jnario/standalone/tests/FeatureBatchCompilerTest.java +++ b/tests/org.jnario.standalone.tests/xtend-gen/org/jnario/standalone/tests/FeatureBatchCompilerTest.java @@ -1,87 +1,87 @@ -/** - * Copyright (c) 2012 BMW Car IT and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.jnario.standalone.tests; - -import com.google.inject.Inject; -import java.io.File; -import java.io.FilenameFilter; -import java.util.List; -import org.eclipse.xtext.junit4.InjectWith; -import org.eclipse.xtext.junit4.XtextRunner; -import org.eclipse.xtext.util.Files; -import org.eclipse.xtext.xbase.lib.Conversions; -import org.eclipse.xtext.xbase.lib.Exceptions; -import org.jnario.feature.compiler.FeatureBatchCompiler; -import org.jnario.jnario.test.util.ExtendedFeatureInjectorProvider; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; - -@RunWith(XtextRunner.class) -@InjectWith(ExtendedFeatureInjectorProvider.class) -@SuppressWarnings("all") -public class FeatureBatchCompilerTest { - @Inject - private FeatureBatchCompiler batchCompiler; - - private static String OUTPUT_DIRECTORY_WITH_SPACES = "./test result"; - - private static String OUTPUT_DIRECTORY = "./test-result"; - - private static String XTEND_SRC_DIRECTORY = "./testdata"; - - private static String TEMP_DIRECTORY = "./test-temp-dir"; - - @Before - public void onSetup() { - try { - this.batchCompiler.setSourcePath(FeatureBatchCompilerTest.XTEND_SRC_DIRECTORY); - this.batchCompiler.setOutputPath(FeatureBatchCompilerTest.OUTPUT_DIRECTORY); - this.batchCompiler.setDeleteTempDirectory(true); - this.batchCompiler.setUseCurrentClassLoaderAsParent(true); - this.batchCompiler.setCurrentClassLoader(this.getClass().getClassLoader()); - new File(FeatureBatchCompilerTest.OUTPUT_DIRECTORY).mkdir(); - File _file = new File(FeatureBatchCompilerTest.OUTPUT_DIRECTORY); - Files.cleanFolder(_file, null, true, false); - new File(FeatureBatchCompilerTest.OUTPUT_DIRECTORY_WITH_SPACES).mkdir(); - } catch (Throwable _e) { - throw Exceptions.sneakyThrow(_e); - } - } - - @After - public void onTearDown() { - try { - File _file = new File(FeatureBatchCompilerTest.OUTPUT_DIRECTORY); - Files.cleanFolder(_file, null, true, true); - File _file_1 = new File(FeatureBatchCompilerTest.OUTPUT_DIRECTORY_WITH_SPACES); - Files.cleanFolder(_file_1, null, true, true); - boolean _exists = new File(FeatureBatchCompilerTest.TEMP_DIRECTORY).exists(); - if (_exists) { - File _file_2 = new File(FeatureBatchCompilerTest.TEMP_DIRECTORY); - Files.cleanFolder(_file_2, null, true, true); - } - } catch (Throwable _e) { - throw Exceptions.sneakyThrow(_e); - } - } - - @Test - public void testCompileTestData() { - this.batchCompiler.compile(); - final FilenameFilter _function = new FilenameFilter() { - @Override - public boolean accept(final File dir, final String name) { - return name.endsWith(".java"); - } - }; - Assert.assertEquals(3, ((List)Conversions.doWrapArray(new File((FeatureBatchCompilerTest.OUTPUT_DIRECTORY + "/test")).list(_function))).size()); - } -} +/** + * Copyright (c) 2012 BMW Car IT and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.jnario.standalone.tests; + +import com.google.inject.Inject; +import java.io.File; +import java.io.FilenameFilter; +import java.util.List; +import org.eclipse.xtext.junit4.InjectWith; +import org.eclipse.xtext.junit4.XtextRunner; +import org.eclipse.xtext.util.Files; +import org.eclipse.xtext.xbase.lib.Conversions; +import org.eclipse.xtext.xbase.lib.Exceptions; +import org.jnario.feature.compiler.FeatureBatchCompiler; +import org.jnario.jnario.test.util.ExtendedFeatureInjectorProvider; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(XtextRunner.class) +@InjectWith(ExtendedFeatureInjectorProvider.class) +@SuppressWarnings("all") +public class FeatureBatchCompilerTest { + @Inject + private FeatureBatchCompiler batchCompiler; + + private static String OUTPUT_DIRECTORY_WITH_SPACES = "./test result"; + + private static String OUTPUT_DIRECTORY = "./test-result"; + + private static String XTEND_SRC_DIRECTORY = "./testdata"; + + private static String TEMP_DIRECTORY = "./test-temp-dir"; + + @Before + public void onSetup() { + try { + this.batchCompiler.setSourcePath(FeatureBatchCompilerTest.XTEND_SRC_DIRECTORY); + this.batchCompiler.setOutputPath(FeatureBatchCompilerTest.OUTPUT_DIRECTORY); + this.batchCompiler.setDeleteTempDirectory(true); + this.batchCompiler.setUseCurrentClassLoaderAsParent(true); + this.batchCompiler.setCurrentClassLoader(this.getClass().getClassLoader()); + new File(FeatureBatchCompilerTest.OUTPUT_DIRECTORY).mkdir(); + File _file = new File(FeatureBatchCompilerTest.OUTPUT_DIRECTORY); + Files.cleanFolder(_file, null, true, false); + new File(FeatureBatchCompilerTest.OUTPUT_DIRECTORY_WITH_SPACES).mkdir(); + } catch (Throwable _e) { + throw Exceptions.sneakyThrow(_e); + } + } + + @After + public void onTearDown() { + try { + File _file = new File(FeatureBatchCompilerTest.OUTPUT_DIRECTORY); + Files.cleanFolder(_file, null, true, true); + File _file_1 = new File(FeatureBatchCompilerTest.OUTPUT_DIRECTORY_WITH_SPACES); + Files.cleanFolder(_file_1, null, true, true); + boolean _exists = new File(FeatureBatchCompilerTest.TEMP_DIRECTORY).exists(); + if (_exists) { + File _file_2 = new File(FeatureBatchCompilerTest.TEMP_DIRECTORY); + Files.cleanFolder(_file_2, null, true, true); + } + } catch (Throwable _e) { + throw Exceptions.sneakyThrow(_e); + } + } + + @Test + public void testCompileTestData() { + this.batchCompiler.compile(); + final FilenameFilter _function = new FilenameFilter() { + @Override + public boolean accept(final File dir, final String name) { + return name.endsWith(".java"); + } + }; + Assert.assertEquals(3, ((List)Conversions.doWrapArray(new File((FeatureBatchCompilerTest.OUTPUT_DIRECTORY + "/test")).list(_function))).size()); + } +} diff --git a/tests/org.jnario.standalone.tests/xtend-gen/org/jnario/standalone/tests/JnarioStandaloneCompilerTest.java b/tests/org.jnario.standalone.tests/xtend-gen/org/jnario/standalone/tests/JnarioStandaloneCompilerTest.java index 2182e0777..653a56709 100644 --- a/tests/org.jnario.standalone.tests/xtend-gen/org/jnario/standalone/tests/JnarioStandaloneCompilerTest.java +++ b/tests/org.jnario.standalone.tests/xtend-gen/org/jnario/standalone/tests/JnarioStandaloneCompilerTest.java @@ -1,107 +1,107 @@ -/** - * Copyright (c) 2012 BMW Car IT and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.jnario.standalone.tests; - -import com.google.common.base.Charsets; -import com.google.inject.Inject; -import com.google.inject.Provider; -import java.io.File; -import java.io.FilenameFilter; -import java.util.List; -import org.eclipse.emf.ecore.resource.ResourceSet; -import org.eclipse.xtext.junit4.InjectWith; -import org.eclipse.xtext.junit4.XtextRunner; -import org.eclipse.xtext.resource.XtextResourceSet; -import org.eclipse.xtext.util.Files; -import org.eclipse.xtext.xbase.lib.Conversions; -import org.eclipse.xtext.xbase.lib.Exceptions; -import org.eclipse.xtext.xbase.lib.Extension; -import org.jnario.compiler.AbstractBatchCompiler; -import org.jnario.compiler.JnarioStandaloneCompiler; -import org.jnario.jnario.test.util.ExtendedSuiteInjectorProvider; -import org.jnario.jnario.test.util.ModelStore; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; - -@RunWith(XtextRunner.class) -@InjectWith(ExtendedSuiteInjectorProvider.class) -@SuppressWarnings("all") -public class JnarioStandaloneCompilerTest { - @Inject - @Extension - private ModelStore modelStore; - - private static String OUTPUT_DIRECTORY = "test-result"; - - private static String XTEND_SRC_DIRECTORY = "testdata2"; - - @Before - public void onSetup() { - try { - final File dir = new File(JnarioStandaloneCompilerTest.OUTPUT_DIRECTORY); - boolean _exists = dir.exists(); - if (_exists) { - Files.cleanFolder(dir, null, true, false); - } - new File(JnarioStandaloneCompilerTest.OUTPUT_DIRECTORY).mkdir(); - } catch (Throwable _e) { - throw Exceptions.sneakyThrow(_e); - } - } - - public void compile(final AbstractBatchCompiler batchCompiler) { - batchCompiler.setSourcePath(JnarioStandaloneCompilerTest.XTEND_SRC_DIRECTORY); - batchCompiler.setOutputPath(JnarioStandaloneCompilerTest.OUTPUT_DIRECTORY); - batchCompiler.setDeleteTempDirectory(true); - batchCompiler.setUseCurrentClassLoaderAsParent(true); - batchCompiler.setCurrentClassLoader(this.getClass().getClassLoader()); - final Provider _function = new Provider() { - @Override - public ResourceSet get() { - XtextResourceSet _resourceSet = JnarioStandaloneCompilerTest.this.modelStore.getResourceSet(); - return ((ResourceSet) _resourceSet); - } - }; - batchCompiler.setResourceSetProvider(_function); - batchCompiler.compile(); - } - - @After - public void onTearDown() { - try { - File _file = new File(JnarioStandaloneCompilerTest.OUTPUT_DIRECTORY); - Files.cleanFolder(_file, null, true, true); - } catch (Throwable _e) { - throw Exceptions.sneakyThrow(_e); - } - } - - @Test - public void testCompileTestData() { - try { - final JnarioStandaloneCompiler compiler = JnarioStandaloneCompiler.create(); - this.compile(compiler); - final File outputDir = new File((JnarioStandaloneCompilerTest.OUTPUT_DIRECTORY + "/linking")); - final FilenameFilter _function = new FilenameFilter() { - @Override - public boolean accept(final File dir, final String name) { - return name.endsWith(".java"); - } - }; - Assert.assertEquals(7, ((List)Conversions.doWrapArray(outputDir.list(_function))).size()); - File _file = new File(outputDir, "ExampleSuiteSuite.java"); - final String fileContent = com.google.common.io.Files.toString(_file, Charsets.UTF_8); - Assert.assertTrue(("Expected to be to contain others specs, but was: \n\n" + fileContent), fileContent.contains("@Contains(")); - } catch (Throwable _e) { - throw Exceptions.sneakyThrow(_e); - } - } -} +/** + * Copyright (c) 2012 BMW Car IT and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.jnario.standalone.tests; + +import com.google.common.base.Charsets; +import com.google.inject.Inject; +import com.google.inject.Provider; +import java.io.File; +import java.io.FilenameFilter; +import java.util.List; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.xtext.junit4.InjectWith; +import org.eclipse.xtext.junit4.XtextRunner; +import org.eclipse.xtext.resource.XtextResourceSet; +import org.eclipse.xtext.util.Files; +import org.eclipse.xtext.xbase.lib.Conversions; +import org.eclipse.xtext.xbase.lib.Exceptions; +import org.eclipse.xtext.xbase.lib.Extension; +import org.jnario.compiler.AbstractBatchCompiler; +import org.jnario.compiler.JnarioStandaloneCompiler; +import org.jnario.jnario.test.util.ExtendedSuiteInjectorProvider; +import org.jnario.jnario.test.util.ModelStore; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(XtextRunner.class) +@InjectWith(ExtendedSuiteInjectorProvider.class) +@SuppressWarnings("all") +public class JnarioStandaloneCompilerTest { + @Inject + @Extension + private ModelStore modelStore; + + private static String OUTPUT_DIRECTORY = "test-result"; + + private static String XTEND_SRC_DIRECTORY = "testdata2"; + + @Before + public void onSetup() { + try { + final File dir = new File(JnarioStandaloneCompilerTest.OUTPUT_DIRECTORY); + boolean _exists = dir.exists(); + if (_exists) { + Files.cleanFolder(dir, null, true, false); + } + new File(JnarioStandaloneCompilerTest.OUTPUT_DIRECTORY).mkdir(); + } catch (Throwable _e) { + throw Exceptions.sneakyThrow(_e); + } + } + + public void compile(final AbstractBatchCompiler batchCompiler) { + batchCompiler.setSourcePath(JnarioStandaloneCompilerTest.XTEND_SRC_DIRECTORY); + batchCompiler.setOutputPath(JnarioStandaloneCompilerTest.OUTPUT_DIRECTORY); + batchCompiler.setDeleteTempDirectory(true); + batchCompiler.setUseCurrentClassLoaderAsParent(true); + batchCompiler.setCurrentClassLoader(this.getClass().getClassLoader()); + final Provider _function = new Provider() { + @Override + public ResourceSet get() { + XtextResourceSet _resourceSet = JnarioStandaloneCompilerTest.this.modelStore.getResourceSet(); + return ((ResourceSet) _resourceSet); + } + }; + batchCompiler.setResourceSetProvider(_function); + batchCompiler.compile(); + } + + @After + public void onTearDown() { + try { + File _file = new File(JnarioStandaloneCompilerTest.OUTPUT_DIRECTORY); + Files.cleanFolder(_file, null, true, true); + } catch (Throwable _e) { + throw Exceptions.sneakyThrow(_e); + } + } + + @Test + public void testCompileTestData() { + try { + final JnarioStandaloneCompiler compiler = JnarioStandaloneCompiler.create(); + this.compile(compiler); + final File outputDir = new File((JnarioStandaloneCompilerTest.OUTPUT_DIRECTORY + "/linking")); + final FilenameFilter _function = new FilenameFilter() { + @Override + public boolean accept(final File dir, final String name) { + return name.endsWith(".java"); + } + }; + Assert.assertEquals(7, ((List)Conversions.doWrapArray(outputDir.list(_function))).size()); + File _file = new File(outputDir, "ExampleSuiteSuite.java"); + final String fileContent = com.google.common.io.Files.toString(_file, Charsets.UTF_8); + Assert.assertTrue(("Expected to be to contain others specs, but was: \n\n" + fileContent), fileContent.contains("@Contains(")); + } catch (Throwable _e) { + throw Exceptions.sneakyThrow(_e); + } + } +} diff --git a/tests/org.jnario.standalone.tests/xtend-gen/org/jnario/standalone/tests/SpecBatchCompilerTest.java b/tests/org.jnario.standalone.tests/xtend-gen/org/jnario/standalone/tests/SpecBatchCompilerTest.java index 76826ee96..6a380d554 100644 --- a/tests/org.jnario.standalone.tests/xtend-gen/org/jnario/standalone/tests/SpecBatchCompilerTest.java +++ b/tests/org.jnario.standalone.tests/xtend-gen/org/jnario/standalone/tests/SpecBatchCompilerTest.java @@ -1,82 +1,82 @@ -/** - * Copyright (c) 2012 BMW Car IT and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.jnario.standalone.tests; - -import com.google.inject.Inject; -import java.io.File; -import java.io.FilenameFilter; -import java.util.List; -import org.eclipse.xtext.junit4.InjectWith; -import org.eclipse.xtext.junit4.XtextRunner; -import org.eclipse.xtext.util.Files; -import org.eclipse.xtext.xbase.lib.Conversions; -import org.eclipse.xtext.xbase.lib.Exceptions; -import org.jnario.jnario.test.util.ExtendedSpecInjectorProvider; -import org.jnario.spec.compiler.SpecBatchCompiler; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; - -@RunWith(XtextRunner.class) -@InjectWith(ExtendedSpecInjectorProvider.class) -@SuppressWarnings("all") -public class SpecBatchCompilerTest { - @Inject - private SpecBatchCompiler batchCompiler; - - private static String OUTPUT_DIRECTORY = "./test-result"; - - private static String XTEND_SRC_DIRECTORY = "./testdata"; - - private static String TEMP_DIRECTORY = "./test-temp-dir"; - - @Before - public void onSetup() { - try { - this.batchCompiler.setSourcePath(SpecBatchCompilerTest.XTEND_SRC_DIRECTORY); - this.batchCompiler.setOutputPath(SpecBatchCompilerTest.OUTPUT_DIRECTORY); - this.batchCompiler.setDeleteTempDirectory(true); - this.batchCompiler.setUseCurrentClassLoaderAsParent(true); - this.batchCompiler.setCurrentClassLoader(this.getClass().getClassLoader()); - new File(SpecBatchCompilerTest.OUTPUT_DIRECTORY).mkdir(); - File _file = new File(SpecBatchCompilerTest.OUTPUT_DIRECTORY); - Files.cleanFolder(_file, null, true, false); - } catch (Throwable _e) { - throw Exceptions.sneakyThrow(_e); - } - } - - @After - public void onTearDown() { - try { - File _file = new File(SpecBatchCompilerTest.OUTPUT_DIRECTORY); - Files.cleanFolder(_file, null, true, true); - boolean _exists = new File(SpecBatchCompilerTest.TEMP_DIRECTORY).exists(); - if (_exists) { - File _file_1 = new File(SpecBatchCompilerTest.TEMP_DIRECTORY); - Files.cleanFolder(_file_1, null, true, true); - } - } catch (Throwable _e) { - throw Exceptions.sneakyThrow(_e); - } - } - - @Test - public void testCompileTestData() { - this.batchCompiler.compile(); - final FilenameFilter _function = new FilenameFilter() { - @Override - public boolean accept(final File dir, final String name) { - return name.endsWith(".java"); - } - }; - Assert.assertEquals(3, ((List)Conversions.doWrapArray(new File((SpecBatchCompilerTest.OUTPUT_DIRECTORY + "/test")).list(_function))).size()); - } -} +/** + * Copyright (c) 2012 BMW Car IT and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.jnario.standalone.tests; + +import com.google.inject.Inject; +import java.io.File; +import java.io.FilenameFilter; +import java.util.List; +import org.eclipse.xtext.junit4.InjectWith; +import org.eclipse.xtext.junit4.XtextRunner; +import org.eclipse.xtext.util.Files; +import org.eclipse.xtext.xbase.lib.Conversions; +import org.eclipse.xtext.xbase.lib.Exceptions; +import org.jnario.jnario.test.util.ExtendedSpecInjectorProvider; +import org.jnario.spec.compiler.SpecBatchCompiler; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(XtextRunner.class) +@InjectWith(ExtendedSpecInjectorProvider.class) +@SuppressWarnings("all") +public class SpecBatchCompilerTest { + @Inject + private SpecBatchCompiler batchCompiler; + + private static String OUTPUT_DIRECTORY = "./test-result"; + + private static String XTEND_SRC_DIRECTORY = "./testdata"; + + private static String TEMP_DIRECTORY = "./test-temp-dir"; + + @Before + public void onSetup() { + try { + this.batchCompiler.setSourcePath(SpecBatchCompilerTest.XTEND_SRC_DIRECTORY); + this.batchCompiler.setOutputPath(SpecBatchCompilerTest.OUTPUT_DIRECTORY); + this.batchCompiler.setDeleteTempDirectory(true); + this.batchCompiler.setUseCurrentClassLoaderAsParent(true); + this.batchCompiler.setCurrentClassLoader(this.getClass().getClassLoader()); + new File(SpecBatchCompilerTest.OUTPUT_DIRECTORY).mkdir(); + File _file = new File(SpecBatchCompilerTest.OUTPUT_DIRECTORY); + Files.cleanFolder(_file, null, true, false); + } catch (Throwable _e) { + throw Exceptions.sneakyThrow(_e); + } + } + + @After + public void onTearDown() { + try { + File _file = new File(SpecBatchCompilerTest.OUTPUT_DIRECTORY); + Files.cleanFolder(_file, null, true, true); + boolean _exists = new File(SpecBatchCompilerTest.TEMP_DIRECTORY).exists(); + if (_exists) { + File _file_1 = new File(SpecBatchCompilerTest.TEMP_DIRECTORY); + Files.cleanFolder(_file_1, null, true, true); + } + } catch (Throwable _e) { + throw Exceptions.sneakyThrow(_e); + } + } + + @Test + public void testCompileTestData() { + this.batchCompiler.compile(); + final FilenameFilter _function = new FilenameFilter() { + @Override + public boolean accept(final File dir, final String name) { + return name.endsWith(".java"); + } + }; + Assert.assertEquals(3, ((List)Conversions.doWrapArray(new File((SpecBatchCompilerTest.OUTPUT_DIRECTORY + "/test")).list(_function))).size()); + } +} diff --git a/tests/org.jnario.standalone.tests/xtend-gen/org/jnario/standalone/tests/SuiteBatchCompilerTest.java b/tests/org.jnario.standalone.tests/xtend-gen/org/jnario/standalone/tests/SuiteBatchCompilerTest.java index 0dac199df..035b72e93 100644 --- a/tests/org.jnario.standalone.tests/xtend-gen/org/jnario/standalone/tests/SuiteBatchCompilerTest.java +++ b/tests/org.jnario.standalone.tests/xtend-gen/org/jnario/standalone/tests/SuiteBatchCompilerTest.java @@ -1,102 +1,102 @@ -/** - * Copyright (c) 2012 BMW Car IT and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.jnario.standalone.tests; - -import com.google.common.base.Charsets; -import com.google.inject.Inject; -import com.google.inject.Provider; -import java.io.File; -import java.io.FilenameFilter; -import java.util.List; -import org.eclipse.emf.ecore.resource.ResourceSet; -import org.eclipse.xtext.junit4.InjectWith; -import org.eclipse.xtext.junit4.XtextRunner; -import org.eclipse.xtext.util.Files; -import org.eclipse.xtext.xbase.lib.Conversions; -import org.eclipse.xtext.xbase.lib.Exceptions; -import org.jnario.compiler.AbstractBatchCompiler; -import org.jnario.compiler.JnarioStandaloneCompiler; -import org.jnario.jnario.test.util.ExtendedSuiteInjectorProvider; -import org.jnario.jnario.test.util.ModelStore; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; - -@RunWith(XtextRunner.class) -@InjectWith(ExtendedSuiteInjectorProvider.class) -@SuppressWarnings("all") -public class SuiteBatchCompilerTest { - @Inject - private Provider modelStoreProvider; - - private static String OUTPUT_DIRECTORY = "test-result"; - - private static String XTEND_SRC_DIRECTORY = "testdata"; - - @Before - public void onSetup() { - try { - final File dir = new File(SuiteBatchCompilerTest.OUTPUT_DIRECTORY); - boolean _exists = dir.exists(); - if (_exists) { - Files.cleanFolder(dir, null, true, false); - } - new File(SuiteBatchCompilerTest.OUTPUT_DIRECTORY).mkdir(); - } catch (Throwable _e) { - throw Exceptions.sneakyThrow(_e); - } - } - - public void compile(final AbstractBatchCompiler batchCompiler) { - batchCompiler.setSourcePath(SuiteBatchCompilerTest.XTEND_SRC_DIRECTORY); - batchCompiler.setOutputPath(SuiteBatchCompilerTest.OUTPUT_DIRECTORY); - batchCompiler.setDeleteTempDirectory(true); - batchCompiler.setUseCurrentClassLoaderAsParent(true); - batchCompiler.setCurrentClassLoader(this.getClass().getClassLoader()); - final Provider _function = new Provider() { - @Override - public ResourceSet get() { - return SuiteBatchCompilerTest.this.modelStoreProvider.get().getResourceSet(); - } - }; - batchCompiler.setResourceSetProvider(_function); - batchCompiler.compile(); - } - - @After - public void onTearDown() { - try { - File _file = new File(SuiteBatchCompilerTest.OUTPUT_DIRECTORY); - Files.cleanFolder(_file, null, true, true); - } catch (Throwable _e) { - throw Exceptions.sneakyThrow(_e); - } - } - - @Test - public void testCompileTestData() { - try { - this.compile(JnarioStandaloneCompiler.create()); - final File outputDir = new File((SuiteBatchCompilerTest.OUTPUT_DIRECTORY + "/test")); - final FilenameFilter _function = new FilenameFilter() { - @Override - public boolean accept(final File dir, final String name) { - return name.endsWith(".java"); - } - }; - Assert.assertEquals(7, ((List)Conversions.doWrapArray(outputDir.list(_function))).size()); - File _file = new File(outputDir, "ExampleSuite.java"); - final String fileContent = com.google.common.io.Files.toString(_file, Charsets.UTF_8); - Assert.assertTrue(("Expected to be to contain others specs, but was: \n\n" + fileContent), fileContent.contains("@Contains")); - } catch (Throwable _e) { - throw Exceptions.sneakyThrow(_e); - } - } -} +/** + * Copyright (c) 2012 BMW Car IT and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.jnario.standalone.tests; + +import com.google.common.base.Charsets; +import com.google.inject.Inject; +import com.google.inject.Provider; +import java.io.File; +import java.io.FilenameFilter; +import java.util.List; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.xtext.junit4.InjectWith; +import org.eclipse.xtext.junit4.XtextRunner; +import org.eclipse.xtext.util.Files; +import org.eclipse.xtext.xbase.lib.Conversions; +import org.eclipse.xtext.xbase.lib.Exceptions; +import org.jnario.compiler.AbstractBatchCompiler; +import org.jnario.compiler.JnarioStandaloneCompiler; +import org.jnario.jnario.test.util.ExtendedSuiteInjectorProvider; +import org.jnario.jnario.test.util.ModelStore; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(XtextRunner.class) +@InjectWith(ExtendedSuiteInjectorProvider.class) +@SuppressWarnings("all") +public class SuiteBatchCompilerTest { + @Inject + private Provider modelStoreProvider; + + private static String OUTPUT_DIRECTORY = "test-result"; + + private static String XTEND_SRC_DIRECTORY = "testdata"; + + @Before + public void onSetup() { + try { + final File dir = new File(SuiteBatchCompilerTest.OUTPUT_DIRECTORY); + boolean _exists = dir.exists(); + if (_exists) { + Files.cleanFolder(dir, null, true, false); + } + new File(SuiteBatchCompilerTest.OUTPUT_DIRECTORY).mkdir(); + } catch (Throwable _e) { + throw Exceptions.sneakyThrow(_e); + } + } + + public void compile(final AbstractBatchCompiler batchCompiler) { + batchCompiler.setSourcePath(SuiteBatchCompilerTest.XTEND_SRC_DIRECTORY); + batchCompiler.setOutputPath(SuiteBatchCompilerTest.OUTPUT_DIRECTORY); + batchCompiler.setDeleteTempDirectory(true); + batchCompiler.setUseCurrentClassLoaderAsParent(true); + batchCompiler.setCurrentClassLoader(this.getClass().getClassLoader()); + final Provider _function = new Provider() { + @Override + public ResourceSet get() { + return SuiteBatchCompilerTest.this.modelStoreProvider.get().getResourceSet(); + } + }; + batchCompiler.setResourceSetProvider(_function); + batchCompiler.compile(); + } + + @After + public void onTearDown() { + try { + File _file = new File(SuiteBatchCompilerTest.OUTPUT_DIRECTORY); + Files.cleanFolder(_file, null, true, true); + } catch (Throwable _e) { + throw Exceptions.sneakyThrow(_e); + } + } + + @Test + public void testCompileTestData() { + try { + this.compile(JnarioStandaloneCompiler.create()); + final File outputDir = new File((SuiteBatchCompilerTest.OUTPUT_DIRECTORY + "/test")); + final FilenameFilter _function = new FilenameFilter() { + @Override + public boolean accept(final File dir, final String name) { + return name.endsWith(".java"); + } + }; + Assert.assertEquals(7, ((List)Conversions.doWrapArray(outputDir.list(_function))).size()); + File _file = new File(outputDir, "ExampleSuite.java"); + final String fileContent = com.google.common.io.Files.toString(_file, Charsets.UTF_8); + Assert.assertTrue(("Expected to be to contain others specs, but was: \n\n" + fileContent), fileContent.contains("@Contains")); + } catch (Throwable _e) { + throw Exceptions.sneakyThrow(_e); + } + } +} diff --git a/tests/org.jnario.tests/doc-gen/org/jnario/jnario/tests/unit/jnario/RichStringsSpec.html b/tests/org.jnario.tests/doc-gen/org/jnario/jnario/tests/unit/jnario/RichStringsSpec.html new file mode 100644 index 000000000..053cfa183 --- /dev/null +++ b/tests/org.jnario.tests/doc-gen/org/jnario/jnario/tests/unit/jnario/RichStringsSpec.html @@ -0,0 +1,304 @@ + + + + +RichStrings + + + + + + + + + + + + + + + + +
    +
    +
    + +
    +
    +
    +
    +

    As expression

    +
    • richstring should be

      +
      +//dont assign to variable, use directly
      +'''abc''' should be "abc"
      +
    • richstring with if

      +
      +'''a «IF true»b«ENDIF»''' should be "a b"
      +
    +

    Tab, newline, etc.

    +
    • tabs

      +
      +//Table does not format correctly yet
      +'''  leading Tab''' should be "\tleading Tab"
      +'''trailing Tab  ''' should be "trailing Tab\t"
      +'''inner  tab''' should be "inner\ttab"
      +
    • spaces

      +
      +//Table does not format correctly yet
      +''' leading ws''' should be " leading ws"
      +'''trailing ws ''' should be "trailing ws "
      +'''inner ws''' should be "inner ws"
      +
    • newlines

      +
      +'''
      +  line1
      +  line2''' should be "line1"+System.lineSeparator()+"line2"
      +
    • empty newlines

      +
      +'''
      +  line1
      +  
      +  line2''' should be "line1"+System.lineSeparator()+System.lineSeparator()+"line2"
      +
    +

    Expressions in richstrings

    +
    • a variable

      +
      +val x = "value"
      +'''pre «x» post''' should be "pre value post"
      +
    • multiple variables

      +
      +val x = "value"
      +val y = "value2"
      +'''pre «x» «y» post''' should be "pre value value2 post"
      +
    • multiple variables in new lines

      +
      +val x = "value"
      +val y = "value2"
      +'''
      +  pre
      +  «x»
      +  «y»
      +  post''' should be "pre"+System.lineSeparator()+"value"+System.lineSeparator()+"value2"+System.lineSeparator()+"post"
      +
    • expression

      +
      +'''1 + 2 = «1+2»''' should be "1 + 2 = 3"
      +
    • expression with variables

      +
      +val a = 1
      +val b = 2
      +'''«a» + «b» = «a + b»''' should be "1 + 2 = 3"
      +
    +

    Indentation

    +
    • no indentation

      +
      +'''
      +a
      +b''' should be "a"+System.lineSeparator()+"b"
      +
    • with indentation

      +
      +'''
      +a
      +  b''' should be "a"+System.lineSeparator()+"\tb"
      +  
      +'''
      +  a
      +b''' should be "\ta"+System.lineSeparator()+"b"
      +
    +

    If condition

    +
    • if false

      +
      +val stringWithIf = '''pre«IF false» x «ENDIF»post'''
      +org.junit.Assert.assertEquals("prepost", stringWithIf)
      +
    • if true

      +
      +val stringWithIf = '''pre«IF true» x «ENDIF»post'''
      +org.junit.Assert.assertEquals("pre x post", stringWithIf)
      +
    • if expression

      +
      +var stringWithIf = '''pre«IF 3 > 2» x «ENDIF»post'''
      +org.junit.Assert.assertEquals("pre x post", stringWithIf) 
      +
      +stringWithIf = '''pre«IF 3 < 2» x «ENDIF»post'''
      +org.junit.Assert.assertEquals("prepost", stringWithIf)
      +
    +

    Loop

    +
    • for 1..3

      +
      +val x = ''' 
      +  «FOR x : (1..3)»
      +  line «x»
      +  «ENDFOR»
      +  '''  
      +
      +org.junit.Assert.assertEquals("line 1"+System.lineSeparator()+"line 2"+System.lineSeparator()+"line 3"+System.lineSeparator(), x)
      +
    • for before after

      +
      +val text = ''' 
      +  «FOR x : (1..3) BEFORE 'pre ' SEPARATOR ',' AFTER ' post'»«x»«ENDFOR»'''  
      + 
      +org.junit.Assert.assertEquals("pre 1,2,3 post", text)
      +
    +
    +
    +

    RichStrings.spec

    +

    +

    +package org.jnario.jnario.tests.unit.jnario
    +
    +describe "RichStrings"{
    +  context "as expression"{
    +
    +    fact "richstring should be"{
    +      //dont assign to variable, use directly
    +      '''abc''' should be "abc"
    +    } 
    +        
    +    fact "richstring with if"{
    +      '''a «IF true»b«ENDIF»''' should be "a b"
    +    }
    +  } 
    +  
    +  context "tab, newline, etc."{
    +
    +    fact "tabs"{
    +      //Table does not format correctly yet
    +      '''  leading Tab''' should be "\tleading Tab"
    +      '''trailing Tab  ''' should be "trailing Tab\t"
    +      '''inner  tab''' should be "inner\ttab"
    +    }
    +    
    +    fact "spaces"{
    +      //Table does not format correctly yet
    +      ''' leading ws''' should be " leading ws"
    +      '''trailing ws ''' should be "trailing ws "
    +      '''inner ws''' should be "inner ws"
    +    }
    +     
    +    fact "newlines"{
    +      '''
    +        line1
    +        line2''' should be "line1"+System.lineSeparator()+"line2"
    +    }
    +    
    +    fact "empty newlines"{
    +      '''
    +        line1
    +        
    +        line2''' should be "line1"+System.lineSeparator()+System.lineSeparator()+"line2"
    +    }
    +  }
    +  
    +  context "expressions in richstrings"{
    +    fact "a variable"{
    +      val x = "value"
    +      '''pre «x» post''' should be "pre value post"
    +    }
    +    
    +    fact "multiple variables"{
    +      val x = "value"
    +      val y = "value2"
    +      '''pre «x» «y» post''' should be "pre value value2 post"
    +    }
    +    
    +    fact "multiple variables in new lines"{
    +      val x = "value"
    +      val y = "value2"
    +      '''
    +        pre
    +        «x»
    +        «y»
    +        post''' should be "pre"+System.lineSeparator()+"value"+System.lineSeparator()+"value2"+System.lineSeparator()+"post"
    +    }
    +    
    +    fact "expression"{
    +      '''1 + 2 = «1+2»''' should be "1 + 2 = 3"
    +    }
    +    
    +    fact "expression with variables"{
    +      val a = 1
    +      val b = 2
    +      '''«a» + «b» = «a + b»''' should be "1 + 2 = 3"
    +    }
    +  }
    +  
    +  context "indentation"{
    +    
    +    fact "no indentation"{
    +      '''
    +      a
    +      b''' should be "a"+System.lineSeparator()+"b"
    +    }
    +    
    +    fact "with indentation"{
    +      '''
    +      a
    +        b''' should be "a"+System.lineSeparator()+"\tb"
    +        
    +      '''
    +        a
    +      b''' should be "\ta"+System.lineSeparator()+"b"
    +    }
    +  }
    +      
    +  context "if condition"{    
    +    fact "if false"{ 
    +      val stringWithIf = '''pre«IF false» x «ENDIF»post'''
    +      org.junit.Assert.assertEquals("prepost", stringWithIf) 
    +    }
    +    
    +    fact "if true"{ 
    +      val stringWithIf = '''pre«IF true» x «ENDIF»post'''
    +      org.junit.Assert.assertEquals("pre x post", stringWithIf) 
    +    }  
    +    
    +    fact "if expression"{
    +      var stringWithIf = '''pre«IF 3 > 2» x «ENDIF»post'''
    +      org.junit.Assert.assertEquals("pre x post", stringWithIf) 
    +      
    +      stringWithIf = '''pre«IF 3 < 2» x «ENDIF»post'''
    +      org.junit.Assert.assertEquals("prepost", stringWithIf) 
    +    }
    +  }
    +  
    +  context "loop" {
    +    fact "for 1..3"{
    +      val x = ''' 
    +        «FOR x : (1..3)»
    +        line «x»
    +        «ENDFOR»
    +        '''  
    +      
    +      org.junit.Assert.assertEquals("line 1"+System.lineSeparator()+"line 2"+System.lineSeparator()+"line 3"+System.lineSeparator(), x)
    +    }
    +    
    +    fact "for before after"{
    +      val text = ''' 
    +        «FOR x : (1..3) BEFORE 'pre ' SEPARATOR ',' AFTER ' post'»«x»«ENDFOR»'''  
    +       
    +      org.junit.Assert.assertEquals("pre 1,2,3 post", text)
    +    }
    +  }
    +}
    +
    +

    +
    +
    +
    +
    +
    + +
    + + + diff --git a/tests/org.jnario.tests/doc-gen/org/jnario/spec/tests/unit/doc/SpecDocGeneratorSpec.html b/tests/org.jnario.tests/doc-gen/org/jnario/spec/tests/unit/doc/SpecDocGeneratorSpec.html new file mode 100644 index 000000000..1056b2711 --- /dev/null +++ b/tests/org.jnario.tests/doc-gen/org/jnario/spec/tests/unit/doc/SpecDocGeneratorSpec.html @@ -0,0 +1,350 @@ + + + + +SpecDocGenerator + + + + + + + + + + + + + + + + +
    +
    +
    + +
    +
    +
    +
    +
    • generates scenario title and heading

      +
      +generateEmptyExampleDoc()
      +
      +val scenarioDoc = generatedFile("ExampleSpec.html")
      +assert scenarioDoc != null && 
      +    scenarioDoc.contains("<title>Example</title>")
      +    scenarioDoc.contains("<h1>Example</h1>")
      +
    • generates scenario documentation

      +
      +generateDoc('''
      +  /*
      +   * Irrelevant documentation.
      +   */
      +   
      +  /*
      +   * This is an example.
      +   */
      +  describe 'Example'{
      +    
      +  } 
      +''')
      +
      +val scenarioDoc = generatedFile("ExampleSpec.html")
      +assert scenarioDoc.contains("<p>This is an example.</p>")
      +assert !scenarioDoc.contains("<p>Irrelevant documentation.</p>")
      +
    • generates example documentation

      +
      +generateDoc('''
      +  describe 'Example'{
      +    /*
      +     * Example documentation
      +     */
      +    fact "should do stuff"{
      +      var x = 0
      +      x = x + 1
      +    }
      +  }''')
      +val scenarioDoc = generatedFile("ExampleSpec.html")
      +assert scenarioDoc.convertNL.contains('''
      +<p id="should_do_stuff" class="example notrun"><strong>should do stuff</strong></p>
      +<p>Example documentation</p>
      +<pre class="prettyprint lang-spec linenums">
      +var x = 0
      +x = x + 1</pre>'''.convertNL)
      +
    • supports markdown for documentation

      +
      +generateDoc('''
      +  /*
      +   * #Example Heading
      +   */
      +  describe 'Example'{
      +    
      +  } 
      +''')
      +val scenarioDoc = generatedFile("ExampleSpec.html")
      +assert scenarioDoc.contains("<h1>Example Heading</h1>")
      +
    • generates table for example tables

      +
      +generateDoc('''
      +  describe 'Example'{
      +    def myExample{
      +      | a | b |
      +      | 1 | 2 |
      +    }
      +  } 
      +''')
      +val scenarioDoc = generatedFile("ExampleSpec.html")
      +assert scenarioDoc.contains('<p id="myExample"><strong>MyExample</strong></p>')
      +assert scenarioDoc.contains("<th>a</th>")
      +assert scenarioDoc.contains("<th>b</th>")
      +assert scenarioDoc.contains("<td>1</td>")
      +assert scenarioDoc.contains("<td>2</td>")
      +
    • No code block for examples without description

      +
      +generateDoc('''
      +  describe 'Example'{
      +    fact 1 + 1 => 2
      +  } 
      +''')
      +val scenarioDoc = generatedFile("ExampleSpec.html")
      +scenarioDoc.convertNL should not contain '''<pre class="prettyprint lang-spec linenums">
      +1 + 1 =&gt; 2</pre>'''.convertNL
      +
    • filters code based on regex in filter annotation

      +
      +generateDoc('''
      +  describe 'Example'{
      +    /*
      +     * @filter(bbb)
      +     */
      +    fact "should do stuff"{
      +      "aaabbbaaa"
      +    }
      +  } 
      +''')
      +val scenarioDoc = generatedFile("ExampleSpec.html")
      +assert scenarioDoc.contains('aaaaaa')
      +
    • includes failing state for examples

      +
      +generateDoc('''
      +  describe 'Example'{
      +    fact "should do stuff"{
      +      "aaabbbaaa"
      +    }
      +  } 
      +''')
      +
    • supports @lang annotation

      +
      +generateDoc('''
      +  describe 'Example'{
      +    /*
      +     * @lang(ruby)
      +     */
      +    fact "test" {
      +      1 + 1 => 2
      +    }
      +  } 
      +''')
      +val scenarioDoc = generatedFile("ExampleSpec.html")
      +scenarioDoc.convertNL should contain '''<pre class="prettyprint lang-ruby linenums">
      +1 + 1 =&gt; 2</pre>'''.convertNL
      +
    +
    +
    +

    SpecDocGenerator.spec

    +

    +

    +/*******************************************************************************
    + * Copyright (c) 2012 BMW Car IT and others.
    + * All rights reserved. This program and the accompanying materials
    + * are made available under the terms of the Eclipse Public License v1.0
    + * which accompanies this distribution, and is available at
    + * http://www.eclipse.org/legal/epl-v10.html
    + *******************************************************************************/
    +package org.jnario.spec.tests.unit.doc
    +
    +import com.google.inject.Inject
    +import org.jnario.jnario.test.util.ModelStore
    +import org.eclipse.xtext.generator.InMemoryFileSystemAccess
    +import org.jnario.spec.doc.SpecDocGenerator
    +import org.jnario.runner.CreateWith
    +import org.jnario.jnario.test.util.SpecTestCreator
    +
    +@CreateWith(typeof(SpecTestCreator))
    +describe SpecDocGenerator {
    +
    +  @Inject extension ModelStore 
    +  @Inject InMemoryFileSystemAccess fsa
    +  
    +  fact "generates scenario title and heading"{
    +    generateEmptyExampleDoc()
    +    
    +    val scenarioDoc = generatedFile("ExampleSpec.html")
    +    assert scenarioDoc != null && 
    +        scenarioDoc.contains("<title>Example</title>")
    +        scenarioDoc.contains("<h1>Example</h1>")
    +  }
    +  
    +  fact "generates scenario documentation"{
    +    generateDoc('''
    +      /*
    +       * Irrelevant documentation.
    +       */
    +       
    +      /*
    +       * This is an example.
    +       */
    +      describe 'Example'{
    +        
    +      } 
    +    ''')
    +    
    +    val scenarioDoc = generatedFile("ExampleSpec.html")
    +    assert scenarioDoc.contains("<p>This is an example.</p>")
    +    assert !scenarioDoc.contains("<p>Irrelevant documentation.</p>")
    +  }
    +  
    +  fact "generates example documentation"{
    +    generateDoc('''
    +      describe 'Example'{
    +        /*
    +         * Example documentation
    +         */
    +        fact "should do stuff"{
    +          var x = 0
    +          x = x + 1
    +        }
    +      }''')
    +    val scenarioDoc = generatedFile("ExampleSpec.html")
    +    assert scenarioDoc.convertNL.contains('''
    +    <p id="should_do_stuff" class="example notrun"><strong>should do stuff</strong></p>
    +    <p>Example documentation</p>
    +    <pre class="prettyprint lang-spec linenums">
    +    var x = 0
    +    x = x + 1</pre>'''.convertNL)
    +  }
    +  fact "supports markdown for documentation"{
    +    generateDoc('''
    +      /*
    +       * #Example Heading
    +       */
    +      describe 'Example'{
    +        
    +      } 
    +    ''')
    +    val scenarioDoc = generatedFile("ExampleSpec.html")
    +    assert scenarioDoc.contains("<h1>Example Heading</h1>")
    +  }
    +  
    +  
    +  fact "generates table for example tables"{
    +    generateDoc('''
    +      describe 'Example'{
    +        def myExample{
    +          | a | b |
    +          | 1 | 2 |
    +        }
    +      } 
    +    ''')
    +    val scenarioDoc = generatedFile("ExampleSpec.html")
    +    assert scenarioDoc.contains('<p id="myExample"><strong>MyExample</strong></p>')
    +    assert scenarioDoc.contains("<th>a</th>")
    +    assert scenarioDoc.contains("<th>b</th>")
    +    assert scenarioDoc.contains("<td>1</td>")
    +    assert scenarioDoc.contains("<td>2</td>")
    +  }
    +  
    +  fact "No code block for examples without description"{
    +    generateDoc('''
    +      describe 'Example'{
    +        fact 1 + 1 => 2
    +      } 
    +    ''')
    +    val scenarioDoc = generatedFile("ExampleSpec.html")
    +    scenarioDoc.convertNL should not contain '''<pre class="prettyprint lang-spec linenums">
    +1 + 1 =&gt; 2</pre>'''.convertNL
    +  }
    +  
    +  fact "filters code based on regex in filter annotation"{
    +    generateDoc('''
    +      describe 'Example'{
    +        /*
    +         * @filter(bbb)
    +         */
    +        fact "should do stuff"{
    +          "aaabbbaaa"
    +        }
    +      } 
    +    ''')
    +    val scenarioDoc = generatedFile("ExampleSpec.html")
    +    assert scenarioDoc.contains('aaaaaa')
    +  }
    +  
    +  fact "includes failing state for examples"{
    +    generateDoc('''
    +      describe 'Example'{
    +        fact "should do stuff"{
    +          "aaabbbaaa"
    +        }
    +      } 
    +    ''')
    +  }
    +  
    +  fact "supports @lang annotation"{
    +    generateDoc('''
    +      describe 'Example'{
    +        /*
    +         * @lang(ruby)
    +         */
    +        fact "test" {
    +          1 + 1 => 2
    +        }
    +      } 
    +    ''')
    +    val scenarioDoc = generatedFile("ExampleSpec.html")
    +    scenarioDoc.convertNL should contain '''<pre class="prettyprint lang-ruby linenums">
    +1 + 1 =&gt; 2</pre>'''.convertNL
    +  }
    +  
    +  def generateEmptyExampleDoc(){
    +    generateDoc('''
    +      describe 'Example'{
    +        
    +      } 
    +    ''')
    +  }
    +  
    +  def generateDoc(CharSequence input){
    +    val resource = parseSpec(input)
    +    subject.doGenerate(resource, fsa)
    +  }
    +
    +  def generatedFile(String name){
    +    return fsa.textFiles.get("DOC_OUTPUT/" + name)?.toString
    +  }
    +  def convertNL(CharSequence s) {
    +    s.toString.replace("\r", "")
    +  }
    +}
    +
    +

    +
    +
    +
    +
    +
    + +
    + + + diff --git a/tests/org.jnario.tests/src/org/jnario/jnario/tests/unit/jnario/RichStrings.spec b/tests/org.jnario.tests/src/org/jnario/jnario/tests/unit/jnario/RichStrings.spec index 06d16af8c..c998323c9 100644 --- a/tests/org.jnario.tests/src/org/jnario/jnario/tests/unit/jnario/RichStrings.spec +++ b/tests/org.jnario.tests/src/org/jnario/jnario/tests/unit/jnario/RichStrings.spec @@ -1,136 +1,136 @@ -package org.jnario.jnario.tests.unit.jnario - -describe "RichStrings"{ - context "as expression"{ - - fact "richstring should be"{ - //dont assign to variable, use directly - '''abc''' should be "abc" - } - - fact "richstring with if"{ - '''a «IF true»b«ENDIF»''' should be "a b" - } - } - - context "tab, newline, etc."{ - - fact "tabs"{ - //Table does not format correctly yet - ''' leading Tab''' should be "\tleading Tab" - '''trailing Tab ''' should be "trailing Tab\t" - '''inner tab''' should be "inner\ttab" - } - - fact "spaces"{ - //Table does not format correctly yet - ''' leading ws''' should be " leading ws" - '''trailing ws ''' should be "trailing ws " - '''inner ws''' should be "inner ws" - } - - fact "newlines"{ - ''' - line1 - line2''' should be "line1\nline2" - } - - fact "empty newlines"{ - ''' - line1 - - line2''' should be "line1\n\nline2" - } - } - - context "expressions in richstrings"{ - fact "a variable"{ - val x = "value" - '''pre «x» post''' should be "pre value post" - } - - fact "multiple variables"{ - val x = "value" - val y = "value2" - '''pre «x» «y» post''' should be "pre value value2 post" - } - - fact "multiple variables in new lines"{ - val x = "value" - val y = "value2" - ''' - pre - «x» - «y» - post''' should be "pre\nvalue\nvalue2\npost" - } - - fact "expression"{ - '''1 + 2 = «1+2»''' should be "1 + 2 = 3" - } - - fact "expression with variables"{ - val a = 1 - val b = 2 - '''«a» + «b» = «a + b»''' should be "1 + 2 = 3" - } - } - - context "indentation"{ - - fact "no indentation"{ - ''' - a - b''' should be "a\nb" - } - - fact "with indentation"{ - ''' - a - b''' should be "a\n\tb" - - ''' - a - b''' should be "\ta\nb" - } - } - - context "if condition"{ - fact "if false"{ - val stringWithIf = '''pre«IF false» x «ENDIF»post''' - org.junit.Assert.assertEquals("prepost", stringWithIf) - } - - fact "if true"{ - val stringWithIf = '''pre«IF true» x «ENDIF»post''' - org.junit.Assert.assertEquals("pre x post", stringWithIf) - } - - fact "if expression"{ - var stringWithIf = '''pre«IF 3 > 2» x «ENDIF»post''' - org.junit.Assert.assertEquals("pre x post", stringWithIf) - - stringWithIf = '''pre«IF 3 < 2» x «ENDIF»post''' - org.junit.Assert.assertEquals("prepost", stringWithIf) - } - } - - context "loop" { - fact "for 1..3"{ - val x = ''' - «FOR x : (1..3)» - line «x» - «ENDFOR» - ''' - - org.junit.Assert.assertEquals("line 1\nline 2\nline 3\n", x) - } - - fact "for before after"{ - val text = ''' - «FOR x : (1..3) BEFORE 'pre ' SEPARATOR ',' AFTER ' post'»«x»«ENDFOR»''' - - org.junit.Assert.assertEquals("pre 1,2,3 post", text) - } - } +package org.jnario.jnario.tests.unit.jnario + +describe "RichStrings"{ + context "as expression"{ + + fact "richstring should be"{ + //dont assign to variable, use directly + '''abc''' should be "abc" + } + + fact "richstring with if"{ + '''a «IF true»b«ENDIF»''' should be "a b" + } + } + + context "tab, newline, etc."{ + + fact "tabs"{ + //Table does not format correctly yet + ''' leading Tab''' should be "\tleading Tab" + '''trailing Tab ''' should be "trailing Tab\t" + '''inner tab''' should be "inner\ttab" + } + + fact "spaces"{ + //Table does not format correctly yet + ''' leading ws''' should be " leading ws" + '''trailing ws ''' should be "trailing ws " + '''inner ws''' should be "inner ws" + } + + fact "newlines"{ + ''' + line1 + line2''' should be "line1"+System.lineSeparator()+"line2" + } + + fact "empty newlines"{ + ''' + line1 + + line2''' should be "line1"+System.lineSeparator()+System.lineSeparator()+"line2" + } + } + + context "expressions in richstrings"{ + fact "a variable"{ + val x = "value" + '''pre «x» post''' should be "pre value post" + } + + fact "multiple variables"{ + val x = "value" + val y = "value2" + '''pre «x» «y» post''' should be "pre value value2 post" + } + + fact "multiple variables in new lines"{ + val x = "value" + val y = "value2" + ''' + pre + «x» + «y» + post''' should be "pre"+System.lineSeparator()+"value"+System.lineSeparator()+"value2"+System.lineSeparator()+"post" + } + + fact "expression"{ + '''1 + 2 = «1+2»''' should be "1 + 2 = 3" + } + + fact "expression with variables"{ + val a = 1 + val b = 2 + '''«a» + «b» = «a + b»''' should be "1 + 2 = 3" + } + } + + context "indentation"{ + + fact "no indentation"{ + ''' + a + b''' should be "a"+System.lineSeparator()+"b" + } + + fact "with indentation"{ + ''' + a + b''' should be "a"+System.lineSeparator()+"\tb" + + ''' + a + b''' should be "\ta"+System.lineSeparator()+"b" + } + } + + context "if condition"{ + fact "if false"{ + val stringWithIf = '''pre«IF false» x «ENDIF»post''' + org.junit.Assert.assertEquals("prepost", stringWithIf) + } + + fact "if true"{ + val stringWithIf = '''pre«IF true» x «ENDIF»post''' + org.junit.Assert.assertEquals("pre x post", stringWithIf) + } + + fact "if expression"{ + var stringWithIf = '''pre«IF 3 > 2» x «ENDIF»post''' + org.junit.Assert.assertEquals("pre x post", stringWithIf) + + stringWithIf = '''pre«IF 3 < 2» x «ENDIF»post''' + org.junit.Assert.assertEquals("prepost", stringWithIf) + } + } + + context "loop" { + fact "for 1..3"{ + val x = ''' + «FOR x : (1..3)» + line «x» + «ENDFOR» + ''' + + org.junit.Assert.assertEquals("line 1"+System.lineSeparator()+"line 2"+System.lineSeparator()+"line 3"+System.lineSeparator(), x) + } + + fact "for before after"{ + val text = ''' + «FOR x : (1..3) BEFORE 'pre ' SEPARATOR ',' AFTER ' post'»«x»«ENDFOR»''' + + org.junit.Assert.assertEquals("pre 1,2,3 post", text) + } + } } \ No newline at end of file diff --git a/tests/org.jnario.tests/xtend-gen/org/jnario/feature/tests/unit/doc/FeatureDocGeneratorSpec.java b/tests/org.jnario.tests/xtend-gen/org/jnario/feature/tests/unit/doc/FeatureDocGeneratorSpec.java index a0a40c090..c113e83c4 100644 --- a/tests/org.jnario.tests/xtend-gen/org/jnario/feature/tests/unit/doc/FeatureDocGeneratorSpec.java +++ b/tests/org.jnario.tests/xtend-gen/org/jnario/feature/tests/unit/doc/FeatureDocGeneratorSpec.java @@ -1,234 +1,234 @@ -/** - * Copyright (c) 2012 BMW Car IT and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.jnario.feature.tests.unit.doc; - -import com.google.inject.Inject; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.xtend2.lib.StringConcatenation; -import org.eclipse.xtext.generator.InMemoryFileSystemAccess; -import org.eclipse.xtext.xbase.lib.Extension; -import org.eclipse.xtext.xbase.lib.Functions.Function0; -import org.eclipse.xtext.xbase.lib.IterableExtensions; -import org.jnario.Executable; -import org.jnario.JnarioTypeDeclaration; -import org.jnario.feature.doc.FeatureDocGenerator; -import org.jnario.feature.feature.Feature; -import org.jnario.feature.feature.FeatureFile; -import org.jnario.jnario.test.util.FeatureTestCreator; -import org.jnario.jnario.test.util.ModelStore; -import org.jnario.lib.JnarioIterableExtensions; -import org.jnario.lib.Should; -import org.jnario.report.Executable2ResultMapping; -import org.jnario.report.Failed; -import org.jnario.report.SpecExecution; -import org.jnario.report.SpecFailure; -import org.jnario.runner.CreateWith; -import org.jnario.runner.ExampleGroupRunner; -import org.jnario.runner.Named; -import org.jnario.runner.Order; -import org.jnario.runner.Subject; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; - -@CreateWith(FeatureTestCreator.class) -@Named("FeatureDocGenerator") -@RunWith(ExampleGroupRunner.class) -@SuppressWarnings("all") -public class FeatureDocGeneratorSpec { - @Subject - public FeatureDocGenerator subject; - - @Extension - @org.jnario.runner.Extension - @Inject - public ModelStore _modelStore; - - @Inject - InMemoryFileSystemAccess fsa; - - @Inject - Executable2ResultMapping mapping; - - @Test - @Named("generates scenario documentation") - @Order(1) - public void _generatesScenarioDocumentation() throws Exception { - final String actual = this.generateDoc("\n\t\t\tpackage test\n\n\t\t\tFeature: Example Feature\n\t\t\t\t\n\t\t\t\tThis is a description.\n\t\t\t\t\n\t\t\t\tScenario: Example Scenario\n\t\t\t\t\n\t\t\t\t\tString input\n\t\t\t\t\n\t\t\t\t\tGiven a step with an argument \"something\", another \"argument\" and a multiline string:\n\t\t\t\t\t\'\'\'\n\t\t\t\t\t\timport java.util.Collections.*;\n\t\t\t\t\t\t\n\t\t\t\t\t\tpublic class Greeter{\n\t\t\t\t\t\t\tpublic static void main(String args[]){\n\t\t\t\t\t\t\t\tList list = new ArrayList(); // should escape angle brackets\n\t\t\t\t\t\t\t\tSysten.out.println(\'Hello World\');\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\'\'\' \n\t\t\t\t\t\tinput = args.first\n\t\t\t\t\t\tprintln(args.last)\n\t\t\t\t\tWhen I do something that is pending.\n\t\t\t\t\t\tAnd something else that is pending\n\t\t\t\t\t\tBut this is implemented\n\t\t\t\t\t\t\t1 + 1 => 2\n\t\t\t\t\tThen it results in \"something else\"\n\t\t\t\t\t\tinput + \' else\' => args.first \n\t\t"); - StringConcatenation _builder = new StringConcatenation(); - _builder.append("

    This is a description.

    "); - _builder.newLine(); - _builder.append("

    Scenario: Example Scenario"); - _builder.newLine(); - _builder.append("

    "); - _builder.newLine(); - _builder.append("
      "); - _builder.newLine(); - _builder.append("
    • Given a step with an argument \"something\", another \"argument\" and a multiline string:

      import java.util.Collections.*;");
      -    _builder.newLine();
      -    _builder.newLine();
      -    _builder.append("public class Greeter{");
      -    _builder.newLine();
      -    _builder.append("  ");
      -    _builder.append("public static void main(String args[]){");
      -    _builder.newLine();
      -    _builder.append("    ");
      -    _builder.append("List<String> list = new ArrayList<String>(); // should escape angle brackets");
      -    _builder.newLine();
      -    _builder.append("    ");
      -    _builder.append("Systen.out.println(\'Hello World\');");
      -    _builder.newLine();
      -    _builder.append("  ");
      -    _builder.append("}");
      -    _builder.newLine();
      -    _builder.append("}
      "); - _builder.newLine(); - _builder.append("
    • "); - _builder.newLine(); - _builder.append("
    • When I do something that is pending. [PENDING]

      "); - _builder.newLine(); - _builder.append("
    • "); - _builder.newLine(); - _builder.append("
    • And something else that is pending [PENDING]

      "); - _builder.newLine(); - _builder.append("
    • "); - _builder.newLine(); - _builder.append("
    • But this is implemented

      "); - _builder.newLine(); - _builder.append("
    • "); - _builder.newLine(); - _builder.append("
    • Then it results in \"something else\"

      "); - _builder.newLine(); - _builder.append("
    • "); - _builder.newLine(); - _builder.append("
    "); - _builder.newLine(); - _builder.append("
    "); - _builder.newLine(); - final String expected = _builder.toString(); - Assert.assertEquals(this.convertNL(expected), this.convertNL(actual)); - } - - @Test - @Named("Includes failure state in Feature") - @Order(2) - public void _includesFailureStateInFeature() throws Exception { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("Feature: Example"); - _builder.newLine(); - _builder.newLine(); - _builder.append("Scenario: A failing Scenario"); - _builder.newLine(); - _builder.newLine(); - _builder.append("Given something"); - _builder.newLine(); - _builder.append("When something happens "); - _builder.newLine(); - _builder.append("Then there is an error"); - _builder.newLine(); - _builder.newLine(); - _builder.append("Scenario: Another scnario"); - _builder.newLine(); - _builder.append("Given something"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("1 + 1 => 2"); - _builder.newLine(); - _builder.append("Then something else"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("\"\" "); - _builder.newLine(); - CharSequence _generateDocWithErrors = this.generateDocWithErrors(_builder); - org.jnario.lib.Assert.assertTrue("\nExpected \'\'\'\n\t\t\tFeature: Example\n\t\t\t\n\t\t\tScenario: A failing Scenario\n\t\t\t\n\t\t\tGiven something\n\t\t\tWhen something happens \n\t\t\tThen there is an error\n\t\t\t\n\t\t\tScenario: Another scnario\n\t\t\tGiven something\n\t\t\t\t1 + 1 => 2\n\t\t\tThen something else\n\t\t\t\t\"\" \n\t\t\'\'\'.generateDocWithErrors should contain \"failed\" but" - + "\n \'\'\'\n\t\t\tFeature: Example\n\t\t\t\n\t\t\tScenario: A failing Scenario\n\t\t\t\n\t\t\tGiven something\n\t\t\tWhen something happens \n\t\t\tThen there is an error\n\t\t\t\n\t\t\tScenario: Another scnario\n\t\t\tGiven something\n\t\t\t\t1 + 1 => 2\n\t\t\tThen something else\n\t\t\t\t\"\" \n\t\t\'\'\'.generateDocWithErrors is " + new org.hamcrest.StringDescription().appendValue(_generateDocWithErrors).toString() - + "\n \'\'\'\n\t\t\tFeature: Example\n\t\t\t\n\t\t\tScenario: A failing Scenario\n\t\t\t\n\t\t\tGiven something\n\t\t\tWhen something happens \n\t\t\tThen there is an error\n\t\t\t\n\t\t\tScenario: Another scnario\n\t\t\tGiven something\n\t\t\t\t1 + 1 => 2\n\t\t\tThen something else\n\t\t\t\t\"\" \n\t\t\'\'\' is " + new org.hamcrest.StringDescription().appendValue(_builder).toString() + "\n", Should.should_contain(_generateDocWithErrors, "failed")); - - } - - final String message = new Function0() { - public String apply() { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("Expected result => args.first.toInt but "); - _builder.newLine(); - _builder.append(" \t\t"); - _builder.append("result is <122> "); - _builder.newLine(); - _builder.append(" \t\t"); - _builder.append("args.first.toInt is <120> "); - _builder.newLine(); - _builder.append(" \t\t"); - _builder.append("args.first is \"120\" "); - _builder.newLine(); - _builder.append(" \t\t"); - _builder.append("args is <[120]>"); - _builder.newLine(); - return _builder.toString(); - } - }.apply(); - - public Executable2ResultMapping mappingWithFailures() { - final Executable2ResultMapping _function = new Executable2ResultMapping() { - @Override - public SpecExecution getResult(final Executable it) { - String _string = FeatureDocGeneratorSpec.this.message.toString(); - StringConcatenation _builder = new StringConcatenation(); - _builder.append("java.lang.StringIndexOutOfBoundsException: String index out of range: -1"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("at java.lang.String.substring(String.java:1937)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("at java.lang.String.substring(String.java:1904)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("at org.jnario.feature.doc.FeatureDocGenerator$1.apply(FeatureDocGenerator.java:44)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("at org.jnario.feature.doc.FeatureDocGenerator$1.apply(FeatureDocGenerator.java:1)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("at org.jnario.doc.HtmlFile.newHtmlFile(HtmlFile.java:21)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("at org.jnario.feature.doc.FeatureDocGenerator.createHtmlFile(FeatureDocGenerator.java:57)"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("at org.jnario.doc.AbstractDocGenerator$2$1.apply(AbstractDocGenerator.java:88)"); - _builder.newLine(); - String _string_1 = _builder.toString(); - SpecFailure _specFailure = new SpecFailure(_string, "Exception", _string_1); - return Failed.failingSpec("org.jnario.Class", "This Feature", 0.3, _specFailure); - } - }; - return this.mapping = _function; - } - - public CharSequence generateDocWithErrors(@Extension final CharSequence input) { - CharSequence _xblockexpression = null; - { - final Resource resource = this._modelStore.parseScenario(input); - this.subject.doGenerate(resource, this.fsa, this.mappingWithFailures()); - _xblockexpression = JnarioIterableExtensions.first(this.fsa.getTextFiles().values()); - } - return _xblockexpression; - } - - public String generateDoc(@Extension final CharSequence input) { - final Resource resource = this._modelStore.parseScenario(input); - EObject _head = IterableExtensions.head(resource.getContents()); - final FeatureFile featureFile = ((FeatureFile) _head); - JnarioTypeDeclaration _head_1 = IterableExtensions.head(featureFile.getXtendTypes()); - return this.subject.generateContent(((Feature) _head_1)).toString(); - } - - public String convertNL(@Extension final String s) { - return s.replace("\r", ""); - } -} +/** + * Copyright (c) 2012 BMW Car IT and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.jnario.feature.tests.unit.doc; + +import com.google.inject.Inject; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.xtend2.lib.StringConcatenation; +import org.eclipse.xtext.generator.InMemoryFileSystemAccess; +import org.eclipse.xtext.xbase.lib.Extension; +import org.eclipse.xtext.xbase.lib.Functions.Function0; +import org.eclipse.xtext.xbase.lib.IterableExtensions; +import org.jnario.Executable; +import org.jnario.JnarioTypeDeclaration; +import org.jnario.feature.doc.FeatureDocGenerator; +import org.jnario.feature.feature.Feature; +import org.jnario.feature.feature.FeatureFile; +import org.jnario.jnario.test.util.FeatureTestCreator; +import org.jnario.jnario.test.util.ModelStore; +import org.jnario.lib.JnarioIterableExtensions; +import org.jnario.lib.Should; +import org.jnario.report.Executable2ResultMapping; +import org.jnario.report.Failed; +import org.jnario.report.SpecExecution; +import org.jnario.report.SpecFailure; +import org.jnario.runner.CreateWith; +import org.jnario.runner.ExampleGroupRunner; +import org.jnario.runner.Named; +import org.jnario.runner.Order; +import org.jnario.runner.Subject; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; + +@CreateWith(FeatureTestCreator.class) +@Named("FeatureDocGenerator") +@RunWith(ExampleGroupRunner.class) +@SuppressWarnings("all") +public class FeatureDocGeneratorSpec { + @Subject + public FeatureDocGenerator subject; + + @Extension + @org.jnario.runner.Extension + @Inject + public ModelStore _modelStore; + + @Inject + InMemoryFileSystemAccess fsa; + + @Inject + Executable2ResultMapping mapping; + + @Test + @Named("generates scenario documentation") + @Order(1) + public void _generatesScenarioDocumentation() throws Exception { + final String actual = this.generateDoc("\r\n\t\t\tpackage test\r\n\r\n\t\t\tFeature: Example Feature\r\n\t\t\t\t\r\n\t\t\t\tThis is a description.\r\n\t\t\t\t\r\n\t\t\t\tScenario: Example Scenario\r\n\t\t\t\t\r\n\t\t\t\t\tString input\r\n\t\t\t\t\r\n\t\t\t\t\tGiven a step with an argument \"something\", another \"argument\" and a multiline string:\r\n\t\t\t\t\t\'\'\'\r\n\t\t\t\t\t\timport java.util.Collections.*;\r\n\t\t\t\t\t\t\r\n\t\t\t\t\t\tpublic class Greeter{\r\n\t\t\t\t\t\t\tpublic static void main(String args[]){\r\n\t\t\t\t\t\t\t\tList list = new ArrayList(); // should escape angle brackets\r\n\t\t\t\t\t\t\t\tSysten.out.println(\'Hello World\');\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\'\'\' \r\n\t\t\t\t\t\tinput = args.first\r\n\t\t\t\t\t\tprintln(args.last)\r\n\t\t\t\t\tWhen I do something that is pending.\r\n\t\t\t\t\t\tAnd something else that is pending\r\n\t\t\t\t\t\tBut this is implemented\r\n\t\t\t\t\t\t\t1 + 1 => 2\r\n\t\t\t\t\tThen it results in \"something else\"\r\n\t\t\t\t\t\tinput + \' else\' => args.first \r\n\t\t"); + StringConcatenation _builder = new StringConcatenation(); + _builder.append("

    This is a description.

    "); + _builder.newLine(); + _builder.append("

    Scenario: Example Scenario"); + _builder.newLine(); + _builder.append("

    "); + _builder.newLine(); + _builder.append("
      "); + _builder.newLine(); + _builder.append("
    • Given a step with an argument \"something\", another \"argument\" and a multiline string:

      import java.util.Collections.*;");
      +    _builder.newLine();
      +    _builder.newLine();
      +    _builder.append("public class Greeter{");
      +    _builder.newLine();
      +    _builder.append("  ");
      +    _builder.append("public static void main(String args[]){");
      +    _builder.newLine();
      +    _builder.append("    ");
      +    _builder.append("List<String> list = new ArrayList<String>(); // should escape angle brackets");
      +    _builder.newLine();
      +    _builder.append("    ");
      +    _builder.append("Systen.out.println(\'Hello World\');");
      +    _builder.newLine();
      +    _builder.append("  ");
      +    _builder.append("}");
      +    _builder.newLine();
      +    _builder.append("}
      "); + _builder.newLine(); + _builder.append("
    • "); + _builder.newLine(); + _builder.append("
    • When I do something that is pending. [PENDING]

      "); + _builder.newLine(); + _builder.append("
    • "); + _builder.newLine(); + _builder.append("
    • And something else that is pending [PENDING]

      "); + _builder.newLine(); + _builder.append("
    • "); + _builder.newLine(); + _builder.append("
    • But this is implemented

      "); + _builder.newLine(); + _builder.append("
    • "); + _builder.newLine(); + _builder.append("
    • Then it results in \"something else\"

      "); + _builder.newLine(); + _builder.append("
    • "); + _builder.newLine(); + _builder.append("
    "); + _builder.newLine(); + _builder.append("
    "); + _builder.newLine(); + final String expected = _builder.toString(); + Assert.assertEquals(this.convertNL(expected), this.convertNL(actual)); + } + + @Test + @Named("Includes failure state in Feature") + @Order(2) + public void _includesFailureStateInFeature() throws Exception { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("Feature: Example"); + _builder.newLine(); + _builder.newLine(); + _builder.append("Scenario: A failing Scenario"); + _builder.newLine(); + _builder.newLine(); + _builder.append("Given something"); + _builder.newLine(); + _builder.append("When something happens "); + _builder.newLine(); + _builder.append("Then there is an error"); + _builder.newLine(); + _builder.newLine(); + _builder.append("Scenario: Another scnario"); + _builder.newLine(); + _builder.append("Given something"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("1 + 1 => 2"); + _builder.newLine(); + _builder.append("Then something else"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("\"\" "); + _builder.newLine(); + CharSequence _generateDocWithErrors = this.generateDocWithErrors(_builder); + org.jnario.lib.Assert.assertTrue("\nExpected \'\'\'\r\n\t\t\tFeature: Example\r\n\t\t\t\r\n\t\t\tScenario: A failing Scenario\r\n\t\t\t\r\n\t\t\tGiven something\r\n\t\t\tWhen something happens \r\n\t\t\tThen there is an error\r\n\t\t\t\r\n\t\t\tScenario: Another scnario\r\n\t\t\tGiven something\r\n\t\t\t\t1 + 1 => 2\r\n\t\t\tThen something else\r\n\t\t\t\t\"\" \r\n\t\t\'\'\'.generateDocWithErrors should contain \"failed\" but" + + "\n \'\'\'\r\n\t\t\tFeature: Example\r\n\t\t\t\r\n\t\t\tScenario: A failing Scenario\r\n\t\t\t\r\n\t\t\tGiven something\r\n\t\t\tWhen something happens \r\n\t\t\tThen there is an error\r\n\t\t\t\r\n\t\t\tScenario: Another scnario\r\n\t\t\tGiven something\r\n\t\t\t\t1 + 1 => 2\r\n\t\t\tThen something else\r\n\t\t\t\t\"\" \r\n\t\t\'\'\'.generateDocWithErrors is " + new org.hamcrest.StringDescription().appendValue(_generateDocWithErrors).toString() + + "\n \'\'\'\r\n\t\t\tFeature: Example\r\n\t\t\t\r\n\t\t\tScenario: A failing Scenario\r\n\t\t\t\r\n\t\t\tGiven something\r\n\t\t\tWhen something happens \r\n\t\t\tThen there is an error\r\n\t\t\t\r\n\t\t\tScenario: Another scnario\r\n\t\t\tGiven something\r\n\t\t\t\t1 + 1 => 2\r\n\t\t\tThen something else\r\n\t\t\t\t\"\" \r\n\t\t\'\'\' is " + new org.hamcrest.StringDescription().appendValue(_builder).toString() + "\n", Should.should_contain(_generateDocWithErrors, "failed")); + + } + + final String message = new Function0() { + public String apply() { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("Expected result => args.first.toInt but "); + _builder.newLine(); + _builder.append(" \t\t"); + _builder.append("result is <122> "); + _builder.newLine(); + _builder.append(" \t\t"); + _builder.append("args.first.toInt is <120> "); + _builder.newLine(); + _builder.append(" \t\t"); + _builder.append("args.first is \"120\" "); + _builder.newLine(); + _builder.append(" \t\t"); + _builder.append("args is <[120]>"); + _builder.newLine(); + return _builder.toString(); + } + }.apply(); + + public Executable2ResultMapping mappingWithFailures() { + final Executable2ResultMapping _function = new Executable2ResultMapping() { + @Override + public SpecExecution getResult(final Executable it) { + String _string = FeatureDocGeneratorSpec.this.message.toString(); + StringConcatenation _builder = new StringConcatenation(); + _builder.append("java.lang.StringIndexOutOfBoundsException: String index out of range: -1"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("at java.lang.String.substring(String.java:1937)"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("at java.lang.String.substring(String.java:1904)"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("at org.jnario.feature.doc.FeatureDocGenerator$1.apply(FeatureDocGenerator.java:44)"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("at org.jnario.feature.doc.FeatureDocGenerator$1.apply(FeatureDocGenerator.java:1)"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("at org.jnario.doc.HtmlFile.newHtmlFile(HtmlFile.java:21)"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("at org.jnario.feature.doc.FeatureDocGenerator.createHtmlFile(FeatureDocGenerator.java:57)"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("at org.jnario.doc.AbstractDocGenerator$2$1.apply(AbstractDocGenerator.java:88)"); + _builder.newLine(); + String _string_1 = _builder.toString(); + SpecFailure _specFailure = new SpecFailure(_string, "Exception", _string_1); + return Failed.failingSpec("org.jnario.Class", "This Feature", 0.3, _specFailure); + } + }; + return this.mapping = _function; + } + + public CharSequence generateDocWithErrors(@Extension final CharSequence input) { + CharSequence _xblockexpression = null; + { + final Resource resource = this._modelStore.parseScenario(input); + this.subject.doGenerate(resource, this.fsa, this.mappingWithFailures()); + _xblockexpression = JnarioIterableExtensions.first(this.fsa.getTextFiles().values()); + } + return _xblockexpression; + } + + public String generateDoc(@Extension final CharSequence input) { + final Resource resource = this._modelStore.parseScenario(input); + EObject _head = IterableExtensions.head(resource.getContents()); + final FeatureFile featureFile = ((FeatureFile) _head); + JnarioTypeDeclaration _head_1 = IterableExtensions.head(featureFile.getXtendTypes()); + return this.subject.generateContent(((Feature) _head_1)).toString(); + } + + public String convertNL(@Extension final String s) { + return s.replace("\r", ""); + } +} diff --git a/tests/org.jnario.tests/xtend-gen/org/jnario/feature/tests/unit/naming/.gitignore b/tests/org.jnario.tests/xtend-gen/org/jnario/feature/tests/unit/naming/.gitignore deleted file mode 100644 index 71ae75ac8..000000000 --- a/tests/org.jnario.tests/xtend-gen/org/jnario/feature/tests/unit/naming/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/FeatureClassNameProviderGetClassNameBackgroundSpecExamples.java diff --git a/tests/org.jnario.tests/xtend-gen/org/jnario/jnario/tests/unit/jnario/RichStringsAsExpressionSpec.java b/tests/org.jnario.tests/xtend-gen/org/jnario/jnario/tests/unit/jnario/RichStringsAsExpressionSpec.java index f4314bb9e..9d9bb6937 100644 --- a/tests/org.jnario.tests/xtend-gen/org/jnario/jnario/tests/unit/jnario/RichStringsAsExpressionSpec.java +++ b/tests/org.jnario.tests/xtend-gen/org/jnario/jnario/tests/unit/jnario/RichStringsAsExpressionSpec.java @@ -1,43 +1,43 @@ -package org.jnario.jnario.tests.unit.jnario; - -import org.eclipse.xtend2.lib.StringConcatenation; -import org.jnario.jnario.tests.unit.jnario.RichStringsSpec; -import org.jnario.lib.Assert; -import org.jnario.lib.Should; -import org.jnario.runner.ExampleGroupRunner; -import org.jnario.runner.Named; -import org.jnario.runner.Order; -import org.junit.Test; -import org.junit.runner.RunWith; - -@Named("as expression") -@RunWith(ExampleGroupRunner.class) -@SuppressWarnings("all") -public class RichStringsAsExpressionSpec extends RichStringsSpec { - @Test - @Named("richstring should be") - @Order(1) - public void _richstringShouldBe() throws Exception { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("abc"); - Assert.assertTrue("\nExpected //dont assign to variable, use directly\n\t\t\t\'\'\'abc\'\'\' should be \"abc\" but" - + "\n //dont assign to variable, use directly\n\t\t\t\'\'\'abc\'\'\' is " + new org.hamcrest.StringDescription().appendValue(_builder.toString()).toString() + "\n", Should.should_be(_builder.toString(), "abc")); - - } - - @Test - @Named("richstring with if") - @Order(2) - public void _richstringWithIf() throws Exception { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("a "); - { - if (true) { - _builder.append("b"); - } - } - Assert.assertTrue("\nExpected \'\'\'a \u00ABIF true\u00BBb\u00ABENDIF\u00BB\'\'\' should be \"a b\" but" - + "\n \'\'\'a \u00ABIF true\u00BBb\u00ABENDIF\u00BB\'\'\' is " + new org.hamcrest.StringDescription().appendValue(_builder.toString()).toString() + "\n", Should.should_be(_builder.toString(), "a b")); - - } -} +package org.jnario.jnario.tests.unit.jnario; + +import org.eclipse.xtend2.lib.StringConcatenation; +import org.jnario.jnario.tests.unit.jnario.RichStringsSpec; +import org.jnario.lib.Assert; +import org.jnario.lib.Should; +import org.jnario.runner.ExampleGroupRunner; +import org.jnario.runner.Named; +import org.jnario.runner.Order; +import org.junit.Test; +import org.junit.runner.RunWith; + +@Named("as expression") +@RunWith(ExampleGroupRunner.class) +@SuppressWarnings("all") +public class RichStringsAsExpressionSpec extends RichStringsSpec { + @Test + @Named("richstring should be") + @Order(1) + public void _richstringShouldBe() throws Exception { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("abc"); + Assert.assertTrue("\nExpected //dont assign to variable, use directly\r\n\t\t\t\'\'\'abc\'\'\' should be \"abc\" but" + + "\n //dont assign to variable, use directly\r\n\t\t\t\'\'\'abc\'\'\' is " + new org.hamcrest.StringDescription().appendValue(_builder.toString()).toString() + "\n", Should.should_be(_builder.toString(), "abc")); + + } + + @Test + @Named("richstring with if") + @Order(2) + public void _richstringWithIf() throws Exception { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("a "); + { + if (true) { + _builder.append("b"); + } + } + Assert.assertTrue("\nExpected \'\'\'a \u00ABIF true\u00BBb\u00ABENDIF\u00BB\'\'\' should be \"a b\" but" + + "\n \'\'\'a \u00ABIF true\u00BBb\u00ABENDIF\u00BB\'\'\' is " + new org.hamcrest.StringDescription().appendValue(_builder.toString()).toString() + "\n", Should.should_be(_builder.toString(), "a b")); + + } +} diff --git a/tests/org.jnario.tests/xtend-gen/org/jnario/jnario/tests/unit/jnario/RichStringsExpressionsInRichstringsSpec.java b/tests/org.jnario.tests/xtend-gen/org/jnario/jnario/tests/unit/jnario/RichStringsExpressionsInRichstringsSpec.java index ec97c95a7..4e283ce70 100644 --- a/tests/org.jnario.tests/xtend-gen/org/jnario/jnario/tests/unit/jnario/RichStringsExpressionsInRichstringsSpec.java +++ b/tests/org.jnario.tests/xtend-gen/org/jnario/jnario/tests/unit/jnario/RichStringsExpressionsInRichstringsSpec.java @@ -1,104 +1,121 @@ -package org.jnario.jnario.tests.unit.jnario; - -import org.eclipse.xtend2.lib.StringConcatenation; -import org.jnario.jnario.tests.unit.jnario.RichStringsSpec; -import org.jnario.lib.Assert; -import org.jnario.lib.Should; -import org.jnario.runner.ExampleGroupRunner; -import org.jnario.runner.Named; -import org.jnario.runner.Order; -import org.junit.Test; -import org.junit.runner.RunWith; - -@Named("expressions in richstrings") -@RunWith(ExampleGroupRunner.class) -@SuppressWarnings("all") -public class RichStringsExpressionsInRichstringsSpec extends RichStringsSpec { - @Test - @Named("a variable") - @Order(1) - public void _aVariable() throws Exception { - final String x = "value"; - StringConcatenation _builder = new StringConcatenation(); - _builder.append("pre "); - _builder.append(x, ""); - _builder.append(" post"); - Assert.assertTrue("\nExpected \'\'\'pre \u00ABx\u00BB post\'\'\' should be \"pre value post\" but" - + "\n \'\'\'pre \u00ABx\u00BB post\'\'\' is " + new org.hamcrest.StringDescription().appendValue(_builder.toString()).toString() - + "\n x is " + new org.hamcrest.StringDescription().appendValue(x).toString() + "\n", Should.should_be(_builder.toString(), "pre value post")); - - } - - @Test - @Named("multiple variables") - @Order(2) - public void _multipleVariables() throws Exception { - final String x = "value"; - final String y = "value2"; - StringConcatenation _builder = new StringConcatenation(); - _builder.append("pre "); - _builder.append(x, ""); - _builder.append(" "); - _builder.append(y, ""); - _builder.append(" post"); - Assert.assertTrue("\nExpected \'\'\'pre \u00ABx\u00BB \u00ABy\u00BB post\'\'\' should be \"pre value value2 post\" but" - + "\n \'\'\'pre \u00ABx\u00BB \u00ABy\u00BB post\'\'\' is " + new org.hamcrest.StringDescription().appendValue(_builder.toString()).toString() - + "\n x is " + new org.hamcrest.StringDescription().appendValue(x).toString() - + "\n y is " + new org.hamcrest.StringDescription().appendValue(y).toString() + "\n", Should.should_be(_builder.toString(), "pre value value2 post")); - - } - - @Test - @Named("multiple variables in new lines") - @Order(3) - public void _multipleVariablesInNewLines() throws Exception { - final String x = "value"; - final String y = "value2"; - StringConcatenation _builder = new StringConcatenation(); - _builder.append("pre"); - _builder.newLine(); - _builder.append(x, ""); - _builder.newLineIfNotEmpty(); - _builder.append(y, ""); - _builder.newLineIfNotEmpty(); - _builder.append("post"); - Assert.assertTrue("\nExpected \'\'\'\n\t\t\t\tpre\n\t\t\t\t\u00ABx\u00BB\n\t\t\t\t\u00ABy\u00BB\n\t\t\t\tpost\'\'\' should be \"pre\\nvalue\\nvalue2\\npost\" but" - + "\n \'\'\'\n\t\t\t\tpre\n\t\t\t\t\u00ABx\u00BB\n\t\t\t\t\u00ABy\u00BB\n\t\t\t\tpost\'\'\' is " + new org.hamcrest.StringDescription().appendValue(_builder.toString()).toString() - + "\n x is " + new org.hamcrest.StringDescription().appendValue(x).toString() - + "\n y is " + new org.hamcrest.StringDescription().appendValue(y).toString() + "\n", Should.should_be(_builder.toString(), "pre\nvalue\nvalue2\npost")); - - } - - @Test - @Named("expression") - @Order(4) - public void _expression() throws Exception { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("1 + 2 = "); - _builder.append((1 + 2), ""); - Assert.assertTrue("\nExpected \'\'\'1 + 2 = \u00AB1+2\u00BB\'\'\' should be \"1 + 2 = 3\" but" - + "\n \'\'\'1 + 2 = \u00AB1+2\u00BB\'\'\' is " + new org.hamcrest.StringDescription().appendValue(_builder.toString()).toString() - + "\n 1+2 is " + new org.hamcrest.StringDescription().appendValue((1 + 2)).toString() + "\n", Should.should_be(_builder.toString(), "1 + 2 = 3")); - - } - - @Test - @Named("expression with variables") - @Order(5) - public void _expressionWithVariables() throws Exception { - final int a = 1; - final int b = 2; - StringConcatenation _builder = new StringConcatenation(); - _builder.append(a, ""); - _builder.append(" + "); - _builder.append(b, ""); - _builder.append(" = "); - _builder.append((a + b), ""); - Assert.assertTrue("\nExpected \'\'\'\u00ABa\u00BB + \u00ABb\u00BB = \u00ABa + b\u00BB\'\'\' should be \"1 + 2 = 3\" but" - + "\n \'\'\'\u00ABa\u00BB + \u00ABb\u00BB = \u00ABa + b\u00BB\'\'\' is " + new org.hamcrest.StringDescription().appendValue(_builder.toString()).toString() - + "\n a is " + new org.hamcrest.StringDescription().appendValue(a).toString() - + "\n b is " + new org.hamcrest.StringDescription().appendValue(b).toString() - + "\n a + b is " + new org.hamcrest.StringDescription().appendValue((a + b)).toString() + "\n", Should.should_be(_builder.toString(), "1 + 2 = 3")); - - } -} +package org.jnario.jnario.tests.unit.jnario; + +import org.eclipse.xtend2.lib.StringConcatenation; +import org.jnario.jnario.tests.unit.jnario.RichStringsSpec; +import org.jnario.lib.Assert; +import org.jnario.lib.Should; +import org.jnario.runner.ExampleGroupRunner; +import org.jnario.runner.Named; +import org.jnario.runner.Order; +import org.junit.Test; +import org.junit.runner.RunWith; + +@Named("expressions in richstrings") +@RunWith(ExampleGroupRunner.class) +@SuppressWarnings("all") +public class RichStringsExpressionsInRichstringsSpec extends RichStringsSpec { + @Test + @Named("a variable") + @Order(1) + public void _aVariable() throws Exception { + final String x = "value"; + StringConcatenation _builder = new StringConcatenation(); + _builder.append("pre "); + _builder.append(x, ""); + _builder.append(" post"); + Assert.assertTrue("\nExpected \'\'\'pre \u00ABx\u00BB post\'\'\' should be \"pre value post\" but" + + "\n \'\'\'pre \u00ABx\u00BB post\'\'\' is " + new org.hamcrest.StringDescription().appendValue(_builder.toString()).toString() + + "\n x is " + new org.hamcrest.StringDescription().appendValue(x).toString() + "\n", Should.should_be(_builder.toString(), "pre value post")); + + } + + @Test + @Named("multiple variables") + @Order(2) + public void _multipleVariables() throws Exception { + final String x = "value"; + final String y = "value2"; + StringConcatenation _builder = new StringConcatenation(); + _builder.append("pre "); + _builder.append(x, ""); + _builder.append(" "); + _builder.append(y, ""); + _builder.append(" post"); + Assert.assertTrue("\nExpected \'\'\'pre \u00ABx\u00BB \u00ABy\u00BB post\'\'\' should be \"pre value value2 post\" but" + + "\n \'\'\'pre \u00ABx\u00BB \u00ABy\u00BB post\'\'\' is " + new org.hamcrest.StringDescription().appendValue(_builder.toString()).toString() + + "\n x is " + new org.hamcrest.StringDescription().appendValue(x).toString() + + "\n y is " + new org.hamcrest.StringDescription().appendValue(y).toString() + "\n", Should.should_be(_builder.toString(), "pre value value2 post")); + + } + + @Test + @Named("multiple variables in new lines") + @Order(3) + public void _multipleVariablesInNewLines() throws Exception { + final String x = "value"; + final String y = "value2"; + StringConcatenation _builder = new StringConcatenation(); + _builder.append("pre"); + _builder.newLine(); + _builder.append(x, ""); + _builder.newLineIfNotEmpty(); + _builder.append(y, ""); + _builder.newLineIfNotEmpty(); + _builder.append("post"); + String _lineSeparator = System.lineSeparator(); + String _plus = ("pre" + _lineSeparator); + String _plus_1 = (_plus + "value"); + String _lineSeparator_1 = System.lineSeparator(); + String _plus_2 = (_plus_1 + _lineSeparator_1); + String _plus_3 = (_plus_2 + "value2"); + String _lineSeparator_2 = System.lineSeparator(); + String _plus_4 = (_plus_3 + _lineSeparator_2); + String _plus_5 = (_plus_4 + "post"); + Assert.assertTrue("\nExpected \'\'\'\r\n\t\t\t\tpre\r\n\t\t\t\t\u00ABx\u00BB\r\n\t\t\t\t\u00ABy\u00BB\r\n\t\t\t\tpost\'\'\' should be \"pre\"+System.lineSeparator()+\"value\"+System.lineSeparator()+\"value2\"+System.lineSeparator()+\"post\" but" + + "\n \'\'\'\r\n\t\t\t\tpre\r\n\t\t\t\t\u00ABx\u00BB\r\n\t\t\t\t\u00ABy\u00BB\r\n\t\t\t\tpost\'\'\' is " + new org.hamcrest.StringDescription().appendValue(_builder.toString()).toString() + + "\n x is " + new org.hamcrest.StringDescription().appendValue(x).toString() + + "\n y is " + new org.hamcrest.StringDescription().appendValue(y).toString() + + "\n \"pre\"+System.lineSeparator()+\"value\"+System.lineSeparator()+\"value2\"+System.lineSeparator()+\"post\" is " + new org.hamcrest.StringDescription().appendValue(_plus_5).toString() + + "\n \"pre\"+System.lineSeparator()+\"value\"+System.lineSeparator()+\"value2\"+System.lineSeparator() is " + new org.hamcrest.StringDescription().appendValue(_plus_4).toString() + + "\n \"pre\"+System.lineSeparator()+\"value\"+System.lineSeparator()+\"value2\" is " + new org.hamcrest.StringDescription().appendValue(_plus_3).toString() + + "\n \"pre\"+System.lineSeparator()+\"value\"+System.lineSeparator() is " + new org.hamcrest.StringDescription().appendValue(_plus_2).toString() + + "\n \"pre\"+System.lineSeparator()+\"value\" is " + new org.hamcrest.StringDescription().appendValue(_plus_1).toString() + + "\n \"pre\"+System.lineSeparator() is " + new org.hamcrest.StringDescription().appendValue(_plus).toString() + + "\n System.lineSeparator() is " + new org.hamcrest.StringDescription().appendValue(_lineSeparator).toString() + + "\n System is " + new org.hamcrest.StringDescription().appendValue(System.class).toString() + "\n", Should.should_be(_builder.toString(), _plus_5)); + + } + + @Test + @Named("expression") + @Order(4) + public void _expression() throws Exception { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("1 + 2 = "); + _builder.append((1 + 2), ""); + Assert.assertTrue("\nExpected \'\'\'1 + 2 = \u00AB1+2\u00BB\'\'\' should be \"1 + 2 = 3\" but" + + "\n \'\'\'1 + 2 = \u00AB1+2\u00BB\'\'\' is " + new org.hamcrest.StringDescription().appendValue(_builder.toString()).toString() + + "\n 1+2 is " + new org.hamcrest.StringDescription().appendValue((1 + 2)).toString() + "\n", Should.should_be(_builder.toString(), "1 + 2 = 3")); + + } + + @Test + @Named("expression with variables") + @Order(5) + public void _expressionWithVariables() throws Exception { + final int a = 1; + final int b = 2; + StringConcatenation _builder = new StringConcatenation(); + _builder.append(a, ""); + _builder.append(" + "); + _builder.append(b, ""); + _builder.append(" = "); + _builder.append((a + b), ""); + Assert.assertTrue("\nExpected \'\'\'\u00ABa\u00BB + \u00ABb\u00BB = \u00ABa + b\u00BB\'\'\' should be \"1 + 2 = 3\" but" + + "\n \'\'\'\u00ABa\u00BB + \u00ABb\u00BB = \u00ABa + b\u00BB\'\'\' is " + new org.hamcrest.StringDescription().appendValue(_builder.toString()).toString() + + "\n a is " + new org.hamcrest.StringDescription().appendValue(a).toString() + + "\n b is " + new org.hamcrest.StringDescription().appendValue(b).toString() + + "\n a + b is " + new org.hamcrest.StringDescription().appendValue((a + b)).toString() + "\n", Should.should_be(_builder.toString(), "1 + 2 = 3")); + + } +} diff --git a/tests/org.jnario.tests/xtend-gen/org/jnario/jnario/tests/unit/jnario/RichStringsIndentationSpec.java b/tests/org.jnario.tests/xtend-gen/org/jnario/jnario/tests/unit/jnario/RichStringsIndentationSpec.java index e5a7d9c6f..325b28f17 100644 --- a/tests/org.jnario.tests/xtend-gen/org/jnario/jnario/tests/unit/jnario/RichStringsIndentationSpec.java +++ b/tests/org.jnario.tests/xtend-gen/org/jnario/jnario/tests/unit/jnario/RichStringsIndentationSpec.java @@ -1,52 +1,73 @@ -package org.jnario.jnario.tests.unit.jnario; - -import org.eclipse.xtend2.lib.StringConcatenation; -import org.jnario.jnario.tests.unit.jnario.RichStringsSpec; -import org.jnario.lib.Assert; -import org.jnario.lib.Should; -import org.jnario.runner.ExampleGroupRunner; -import org.jnario.runner.Named; -import org.jnario.runner.Order; -import org.junit.Test; -import org.junit.runner.RunWith; - -@Named("indentation") -@RunWith(ExampleGroupRunner.class) -@SuppressWarnings("all") -public class RichStringsIndentationSpec extends RichStringsSpec { - @Test - @Named("no indentation") - @Order(1) - public void _noIndentation() throws Exception { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("a"); - _builder.newLine(); - _builder.append("b"); - Assert.assertTrue("\nExpected \'\'\'\n\t\t\ta\n\t\t\tb\'\'\' should be \"a\\nb\" but" - + "\n \'\'\'\n\t\t\ta\n\t\t\tb\'\'\' is " + new org.hamcrest.StringDescription().appendValue(_builder.toString()).toString() + "\n", Should.should_be(_builder.toString(), "a\nb")); - - } - - @Test - @Named("with indentation") - @Order(2) - public void _withIndentation() throws Exception { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("a"); - _builder.newLine(); - _builder.append("\t"); - _builder.append("b"); - boolean _should_be = Should.should_be(_builder.toString(), "a\n\tb"); - Assert.assertTrue("\nExpected \'\'\'\n\t\t\ta\n\t\t\t\tb\'\'\' should be \"a\\n\\tb\" but" - + "\n \'\'\'\n\t\t\ta\n\t\t\t\tb\'\'\' is " + new org.hamcrest.StringDescription().appendValue(_builder.toString()).toString() + "\n", _should_be); - - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("\t"); - _builder_1.append("a"); - _builder_1.newLine(); - _builder_1.append("b"); - Assert.assertTrue("\nExpected \'\'\'\n\t\t\t\ta\n\t\t\tb\'\'\' should be \"\\ta\\nb\" but" - + "\n \'\'\'\n\t\t\t\ta\n\t\t\tb\'\'\' is " + new org.hamcrest.StringDescription().appendValue(_builder_1.toString()).toString() + "\n", Should.should_be(_builder_1.toString(), "\ta\nb")); - - } -} +package org.jnario.jnario.tests.unit.jnario; + +import org.eclipse.xtend2.lib.StringConcatenation; +import org.jnario.jnario.tests.unit.jnario.RichStringsSpec; +import org.jnario.lib.Assert; +import org.jnario.lib.Should; +import org.jnario.runner.ExampleGroupRunner; +import org.jnario.runner.Named; +import org.jnario.runner.Order; +import org.junit.Test; +import org.junit.runner.RunWith; + +@Named("indentation") +@RunWith(ExampleGroupRunner.class) +@SuppressWarnings("all") +public class RichStringsIndentationSpec extends RichStringsSpec { + @Test + @Named("no indentation") + @Order(1) + public void _noIndentation() throws Exception { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("a"); + _builder.newLine(); + _builder.append("b"); + String _lineSeparator = System.lineSeparator(); + String _plus = ("a" + _lineSeparator); + String _plus_1 = (_plus + "b"); + Assert.assertTrue("\nExpected \'\'\'\r\n\t\t\ta\r\n\t\t\tb\'\'\' should be \"a\"+System.lineSeparator()+\"b\" but" + + "\n \'\'\'\r\n\t\t\ta\r\n\t\t\tb\'\'\' is " + new org.hamcrest.StringDescription().appendValue(_builder.toString()).toString() + + "\n \"a\"+System.lineSeparator()+\"b\" is " + new org.hamcrest.StringDescription().appendValue(_plus_1).toString() + + "\n \"a\"+System.lineSeparator() is " + new org.hamcrest.StringDescription().appendValue(_plus).toString() + + "\n System.lineSeparator() is " + new org.hamcrest.StringDescription().appendValue(_lineSeparator).toString() + + "\n System is " + new org.hamcrest.StringDescription().appendValue(System.class).toString() + "\n", Should.should_be(_builder.toString(), _plus_1)); + + } + + @Test + @Named("with indentation") + @Order(2) + public void _withIndentation() throws Exception { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("a"); + _builder.newLine(); + _builder.append("\t"); + _builder.append("b"); + String _lineSeparator = System.lineSeparator(); + String _plus = ("a" + _lineSeparator); + String _plus_1 = (_plus + "\tb"); + boolean _should_be = Should.should_be(_builder.toString(), _plus_1); + Assert.assertTrue("\nExpected \'\'\'\r\n\t\t\ta\r\n\t\t\t\tb\'\'\' should be \"a\"+System.lineSeparator()+\"\\tb\" but" + + "\n \'\'\'\r\n\t\t\ta\r\n\t\t\t\tb\'\'\' is " + new org.hamcrest.StringDescription().appendValue(_builder.toString()).toString() + + "\n \"a\"+System.lineSeparator()+\"\\tb\" is " + new org.hamcrest.StringDescription().appendValue(_plus_1).toString() + + "\n \"a\"+System.lineSeparator() is " + new org.hamcrest.StringDescription().appendValue(_plus).toString() + + "\n System.lineSeparator() is " + new org.hamcrest.StringDescription().appendValue(_lineSeparator).toString() + + "\n System is " + new org.hamcrest.StringDescription().appendValue(System.class).toString() + "\n", _should_be); + + StringConcatenation _builder_1 = new StringConcatenation(); + _builder_1.append("\t"); + _builder_1.append("a"); + _builder_1.newLine(); + _builder_1.append("b"); + String _lineSeparator_1 = System.lineSeparator(); + String _plus_2 = ("\ta" + _lineSeparator_1); + String _plus_3 = (_plus_2 + "b"); + Assert.assertTrue("\nExpected \'\'\'\r\n\t\t\t\ta\r\n\t\t\tb\'\'\' should be \"\\ta\"+System.lineSeparator()+\"b\" but" + + "\n \'\'\'\r\n\t\t\t\ta\r\n\t\t\tb\'\'\' is " + new org.hamcrest.StringDescription().appendValue(_builder_1.toString()).toString() + + "\n \"\\ta\"+System.lineSeparator()+\"b\" is " + new org.hamcrest.StringDescription().appendValue(_plus_3).toString() + + "\n \"\\ta\"+System.lineSeparator() is " + new org.hamcrest.StringDescription().appendValue(_plus_2).toString() + + "\n System.lineSeparator() is " + new org.hamcrest.StringDescription().appendValue(_lineSeparator_1).toString() + + "\n System is " + new org.hamcrest.StringDescription().appendValue(System.class).toString() + "\n", Should.should_be(_builder_1.toString(), _plus_3)); + + } +} diff --git a/tests/org.jnario.tests/xtend-gen/org/jnario/jnario/tests/unit/jnario/RichStringsLoopSpec.java b/tests/org.jnario.tests/xtend-gen/org/jnario/jnario/tests/unit/jnario/RichStringsLoopSpec.java index fd3dc6fc5..fa24bd0cf 100644 --- a/tests/org.jnario.tests/xtend-gen/org/jnario/jnario/tests/unit/jnario/RichStringsLoopSpec.java +++ b/tests/org.jnario.tests/xtend-gen/org/jnario/jnario/tests/unit/jnario/RichStringsLoopSpec.java @@ -1,58 +1,66 @@ -package org.jnario.jnario.tests.unit.jnario; - -import org.eclipse.xtend2.lib.StringConcatenation; -import org.eclipse.xtext.xbase.lib.IntegerRange; -import org.jnario.jnario.tests.unit.jnario.RichStringsSpec; -import org.jnario.runner.ExampleGroupRunner; -import org.jnario.runner.Named; -import org.jnario.runner.Order; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; - -@Named("loop") -@RunWith(ExampleGroupRunner.class) -@SuppressWarnings("all") -public class RichStringsLoopSpec extends RichStringsSpec { - @Test - @Named("for 1..3") - @Order(1) - public void _for13() throws Exception { - StringConcatenation _builder = new StringConcatenation(); - { - IntegerRange _upTo = new IntegerRange(1, 3); - for(final Integer x : _upTo) { - _builder.append("line "); - _builder.append(x, ""); - _builder.newLineIfNotEmpty(); - } - } - final String x_1 = _builder.toString(); - Assert.assertEquals("line 1\nline 2\nline 3\n", x_1); - } - - @Test - @Named("for before after") - @Order(2) - public void _forBeforeAfter() throws Exception { - StringConcatenation _builder = new StringConcatenation(); - { - IntegerRange _upTo = new IntegerRange(1, 3); - boolean _hasElements = false; - for(final Integer x : _upTo) { - if (!_hasElements) { - _hasElements = true; - _builder.append("pre ", ""); - } else { - _builder.appendImmediate(",", ""); - } - _builder.append(x, ""); - } - if (_hasElements) { - _builder.append(" post", ""); - } - } - final String text = _builder.toString(); - Assert.assertEquals("pre 1,2,3 post", text); - } -} +package org.jnario.jnario.tests.unit.jnario; + +import org.eclipse.xtend2.lib.StringConcatenation; +import org.eclipse.xtext.xbase.lib.IntegerRange; +import org.jnario.jnario.tests.unit.jnario.RichStringsSpec; +import org.jnario.runner.ExampleGroupRunner; +import org.jnario.runner.Named; +import org.jnario.runner.Order; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; + +@Named("loop") +@RunWith(ExampleGroupRunner.class) +@SuppressWarnings("all") +public class RichStringsLoopSpec extends RichStringsSpec { + @Test + @Named("for 1..3") + @Order(1) + public void _for13() throws Exception { + StringConcatenation _builder = new StringConcatenation(); + { + IntegerRange _upTo = new IntegerRange(1, 3); + for(final Integer x : _upTo) { + _builder.append("line "); + _builder.append(x, ""); + _builder.newLineIfNotEmpty(); + } + } + final String x_1 = _builder.toString(); + String _lineSeparator = System.lineSeparator(); + String _plus = ("line 1" + _lineSeparator); + String _plus_1 = (_plus + "line 2"); + String _lineSeparator_1 = System.lineSeparator(); + String _plus_2 = (_plus_1 + _lineSeparator_1); + String _plus_3 = (_plus_2 + "line 3"); + String _lineSeparator_2 = System.lineSeparator(); + String _plus_4 = (_plus_3 + _lineSeparator_2); + Assert.assertEquals(_plus_4, x_1); + } + + @Test + @Named("for before after") + @Order(2) + public void _forBeforeAfter() throws Exception { + StringConcatenation _builder = new StringConcatenation(); + { + IntegerRange _upTo = new IntegerRange(1, 3); + boolean _hasElements = false; + for(final Integer x : _upTo) { + if (!_hasElements) { + _hasElements = true; + _builder.append("pre ", ""); + } else { + _builder.appendImmediate(",", ""); + } + _builder.append(x, ""); + } + if (_hasElements) { + _builder.append(" post", ""); + } + } + final String text = _builder.toString(); + Assert.assertEquals("pre 1,2,3 post", text); + } +} diff --git a/tests/org.jnario.tests/xtend-gen/org/jnario/jnario/tests/unit/jnario/RichStringsTabNewlineEtcSpec.java b/tests/org.jnario.tests/xtend-gen/org/jnario/jnario/tests/unit/jnario/RichStringsTabNewlineEtcSpec.java index bc5ce2ba8..f6c658691 100644 --- a/tests/org.jnario.tests/xtend-gen/org/jnario/jnario/tests/unit/jnario/RichStringsTabNewlineEtcSpec.java +++ b/tests/org.jnario.tests/xtend-gen/org/jnario/jnario/tests/unit/jnario/RichStringsTabNewlineEtcSpec.java @@ -1,91 +1,108 @@ -package org.jnario.jnario.tests.unit.jnario; - -import org.eclipse.xtend2.lib.StringConcatenation; -import org.jnario.jnario.tests.unit.jnario.RichStringsSpec; -import org.jnario.lib.Assert; -import org.jnario.lib.Should; -import org.jnario.runner.ExampleGroupRunner; -import org.jnario.runner.Named; -import org.jnario.runner.Order; -import org.junit.Test; -import org.junit.runner.RunWith; - -@Named("tab, newline, etc.") -@RunWith(ExampleGroupRunner.class) -@SuppressWarnings("all") -public class RichStringsTabNewlineEtcSpec extends RichStringsSpec { - @Test - @Named("tabs") - @Order(1) - public void _tabs() throws Exception { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("\t"); - _builder.append("leading Tab"); - boolean _should_be = Should.should_be(_builder.toString(), "\tleading Tab"); - Assert.assertTrue("\nExpected //Table does not format correctly yet\n\t\t\t\'\'\'\tleading Tab\'\'\' should be \"\\tleading Tab\" but" - + "\n //Table does not format correctly yet\n\t\t\t\'\'\'\tleading Tab\'\'\' is " + new org.hamcrest.StringDescription().appendValue(_builder.toString()).toString() + "\n", _should_be); - - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("trailing Tab\t"); - boolean _should_be_1 = Should.should_be(_builder_1.toString(), "trailing Tab\t"); - Assert.assertTrue("\nExpected \'\'\'trailing Tab\t\'\'\' should be \"trailing Tab\\t\" but" - + "\n \'\'\'trailing Tab\t\'\'\' is " + new org.hamcrest.StringDescription().appendValue(_builder_1.toString()).toString() + "\n", _should_be_1); - - StringConcatenation _builder_2 = new StringConcatenation(); - _builder_2.append("inner\ttab"); - Assert.assertTrue("\nExpected \'\'\'inner\ttab\'\'\' should be \"inner\\ttab\" but" - + "\n \'\'\'inner\ttab\'\'\' is " + new org.hamcrest.StringDescription().appendValue(_builder_2.toString()).toString() + "\n", Should.should_be(_builder_2.toString(), "inner\ttab")); - - } - - @Test - @Named("spaces") - @Order(2) - public void _spaces() throws Exception { - StringConcatenation _builder = new StringConcatenation(); - _builder.append(" "); - _builder.append("leading ws"); - boolean _should_be = Should.should_be(_builder.toString(), " leading ws"); - Assert.assertTrue("\nExpected //Table does not format correctly yet\n\t\t\t\'\'\' leading ws\'\'\' should be \" leading ws\" but" - + "\n //Table does not format correctly yet\n\t\t\t\'\'\' leading ws\'\'\' is " + new org.hamcrest.StringDescription().appendValue(_builder.toString()).toString() + "\n", _should_be); - - StringConcatenation _builder_1 = new StringConcatenation(); - _builder_1.append("trailing ws "); - boolean _should_be_1 = Should.should_be(_builder_1.toString(), "trailing ws "); - Assert.assertTrue("\nExpected \'\'\'trailing ws \'\'\' should be \"trailing ws \" but" - + "\n \'\'\'trailing ws \'\'\' is " + new org.hamcrest.StringDescription().appendValue(_builder_1.toString()).toString() + "\n", _should_be_1); - - StringConcatenation _builder_2 = new StringConcatenation(); - _builder_2.append("inner ws"); - Assert.assertTrue("\nExpected \'\'\'inner ws\'\'\' should be \"inner ws\" but" - + "\n \'\'\'inner ws\'\'\' is " + new org.hamcrest.StringDescription().appendValue(_builder_2.toString()).toString() + "\n", Should.should_be(_builder_2.toString(), "inner ws")); - - } - - @Test - @Named("newlines") - @Order(3) - public void _newlines() throws Exception { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("line1"); - _builder.newLine(); - _builder.append("line2"); - Assert.assertTrue("\nExpected \'\'\'\n\t\t\t\tline1\n\t\t\t\tline2\'\'\' should be \"line1\\nline2\" but" - + "\n \'\'\'\n\t\t\t\tline1\n\t\t\t\tline2\'\'\' is " + new org.hamcrest.StringDescription().appendValue(_builder.toString()).toString() + "\n", Should.should_be(_builder.toString(), "line1\nline2")); - - } - - @Test - @Named("empty newlines") - @Order(4) - public void _emptyNewlines() throws Exception { - StringConcatenation _builder = new StringConcatenation(); - _builder.append("line1"); - _builder.newLine(); - _builder.newLine(); - _builder.append("line2"); - Assert.assertTrue("\nExpected \'\'\'\n\t\t\t\tline1\n\t\t\t\t\n\t\t\t\tline2\'\'\' should be \"line1\\n\\nline2\" but" - + "\n \'\'\'\n\t\t\t\tline1\n\t\t\t\t\n\t\t\t\tline2\'\'\' is " + new org.hamcrest.StringDescription().appendValue(_builder.toString()).toString() + "\n", Should.should_be(_builder.toString(), "line1\n\nline2")); - - } -} +package org.jnario.jnario.tests.unit.jnario; + +import org.eclipse.xtend2.lib.StringConcatenation; +import org.jnario.jnario.tests.unit.jnario.RichStringsSpec; +import org.jnario.lib.Assert; +import org.jnario.lib.Should; +import org.jnario.runner.ExampleGroupRunner; +import org.jnario.runner.Named; +import org.jnario.runner.Order; +import org.junit.Test; +import org.junit.runner.RunWith; + +@Named("tab, newline, etc.") +@RunWith(ExampleGroupRunner.class) +@SuppressWarnings("all") +public class RichStringsTabNewlineEtcSpec extends RichStringsSpec { + @Test + @Named("tabs") + @Order(1) + public void _tabs() throws Exception { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("\t"); + _builder.append("leading Tab"); + boolean _should_be = Should.should_be(_builder.toString(), "\tleading Tab"); + Assert.assertTrue("\nExpected //Table does not format correctly yet\r\n\t\t\t\'\'\'\tleading Tab\'\'\' should be \"\\tleading Tab\" but" + + "\n //Table does not format correctly yet\r\n\t\t\t\'\'\'\tleading Tab\'\'\' is " + new org.hamcrest.StringDescription().appendValue(_builder.toString()).toString() + "\n", _should_be); + + StringConcatenation _builder_1 = new StringConcatenation(); + _builder_1.append("trailing Tab\t"); + boolean _should_be_1 = Should.should_be(_builder_1.toString(), "trailing Tab\t"); + Assert.assertTrue("\nExpected \'\'\'trailing Tab\t\'\'\' should be \"trailing Tab\\t\" but" + + "\n \'\'\'trailing Tab\t\'\'\' is " + new org.hamcrest.StringDescription().appendValue(_builder_1.toString()).toString() + "\n", _should_be_1); + + StringConcatenation _builder_2 = new StringConcatenation(); + _builder_2.append("inner\ttab"); + Assert.assertTrue("\nExpected \'\'\'inner\ttab\'\'\' should be \"inner\\ttab\" but" + + "\n \'\'\'inner\ttab\'\'\' is " + new org.hamcrest.StringDescription().appendValue(_builder_2.toString()).toString() + "\n", Should.should_be(_builder_2.toString(), "inner\ttab")); + + } + + @Test + @Named("spaces") + @Order(2) + public void _spaces() throws Exception { + StringConcatenation _builder = new StringConcatenation(); + _builder.append(" "); + _builder.append("leading ws"); + boolean _should_be = Should.should_be(_builder.toString(), " leading ws"); + Assert.assertTrue("\nExpected //Table does not format correctly yet\r\n\t\t\t\'\'\' leading ws\'\'\' should be \" leading ws\" but" + + "\n //Table does not format correctly yet\r\n\t\t\t\'\'\' leading ws\'\'\' is " + new org.hamcrest.StringDescription().appendValue(_builder.toString()).toString() + "\n", _should_be); + + StringConcatenation _builder_1 = new StringConcatenation(); + _builder_1.append("trailing ws "); + boolean _should_be_1 = Should.should_be(_builder_1.toString(), "trailing ws "); + Assert.assertTrue("\nExpected \'\'\'trailing ws \'\'\' should be \"trailing ws \" but" + + "\n \'\'\'trailing ws \'\'\' is " + new org.hamcrest.StringDescription().appendValue(_builder_1.toString()).toString() + "\n", _should_be_1); + + StringConcatenation _builder_2 = new StringConcatenation(); + _builder_2.append("inner ws"); + Assert.assertTrue("\nExpected \'\'\'inner ws\'\'\' should be \"inner ws\" but" + + "\n \'\'\'inner ws\'\'\' is " + new org.hamcrest.StringDescription().appendValue(_builder_2.toString()).toString() + "\n", Should.should_be(_builder_2.toString(), "inner ws")); + + } + + @Test + @Named("newlines") + @Order(3) + public void _newlines() throws Exception { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("line1"); + _builder.newLine(); + _builder.append("line2"); + String _lineSeparator = System.lineSeparator(); + String _plus = ("line1" + _lineSeparator); + String _plus_1 = (_plus + "line2"); + Assert.assertTrue("\nExpected \'\'\'\r\n\t\t\t\tline1\r\n\t\t\t\tline2\'\'\' should be \"line1\"+System.lineSeparator()+\"line2\" but" + + "\n \'\'\'\r\n\t\t\t\tline1\r\n\t\t\t\tline2\'\'\' is " + new org.hamcrest.StringDescription().appendValue(_builder.toString()).toString() + + "\n \"line1\"+System.lineSeparator()+\"line2\" is " + new org.hamcrest.StringDescription().appendValue(_plus_1).toString() + + "\n \"line1\"+System.lineSeparator() is " + new org.hamcrest.StringDescription().appendValue(_plus).toString() + + "\n System.lineSeparator() is " + new org.hamcrest.StringDescription().appendValue(_lineSeparator).toString() + + "\n System is " + new org.hamcrest.StringDescription().appendValue(System.class).toString() + "\n", Should.should_be(_builder.toString(), _plus_1)); + + } + + @Test + @Named("empty newlines") + @Order(4) + public void _emptyNewlines() throws Exception { + StringConcatenation _builder = new StringConcatenation(); + _builder.append("line1"); + _builder.newLine(); + _builder.newLine(); + _builder.append("line2"); + String _lineSeparator = System.lineSeparator(); + String _plus = ("line1" + _lineSeparator); + String _lineSeparator_1 = System.lineSeparator(); + String _plus_1 = (_plus + _lineSeparator_1); + String _plus_2 = (_plus_1 + "line2"); + Assert.assertTrue("\nExpected \'\'\'\r\n\t\t\t\tline1\r\n\t\t\t\t\r\n\t\t\t\tline2\'\'\' should be \"line1\"+System.lineSeparator()+System.lineSeparator()+\"line2\" but" + + "\n \'\'\'\r\n\t\t\t\tline1\r\n\t\t\t\t\r\n\t\t\t\tline2\'\'\' is " + new org.hamcrest.StringDescription().appendValue(_builder.toString()).toString() + + "\n \"line1\"+System.lineSeparator()+System.lineSeparator()+\"line2\" is " + new org.hamcrest.StringDescription().appendValue(_plus_2).toString() + + "\n \"line1\"+System.lineSeparator()+System.lineSeparator() is " + new org.hamcrest.StringDescription().appendValue(_plus_1).toString() + + "\n \"line1\"+System.lineSeparator() is " + new org.hamcrest.StringDescription().appendValue(_plus).toString() + + "\n System.lineSeparator() is " + new org.hamcrest.StringDescription().appendValue(_lineSeparator).toString() + + "\n System is " + new org.hamcrest.StringDescription().appendValue(System.class).toString() + "\n", Should.should_be(_builder.toString(), _plus_2)); + + } +}