Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Reformat code

  • Loading branch information...
commit 11d3ab848ad0562852e3efa9a4324f90db53e034 1 parent 99d3de9
@aslakhellesoy aslakhellesoy authored
View
571 java/src/main/java/gherkin/parser/FilterListener.java
@@ -5,95 +5,90 @@
import java.util.*;
public class FilterListener implements Listener {
-
- private final List filters;
- private final Listener listener;
- private List<Sexp> metaBuffer = new ArrayList<Sexp>();
- private List<Sexp> featureBuffer = new ArrayList<Sexp>();
- private List<Sexp> scenarioBuffer = new ArrayList<Sexp>();
- private List<Sexp> examplesBuffer = new ArrayList<Sexp>();
- private List<Sexp> examplesRowsBuffer = new ArrayList<Sexp>();
-
- private List<String> featureTags = new ArrayList<String>();
- private List<String> scenarioTags = new ArrayList<String>();
- private List<String> exampleTags = new ArrayList<String>();
-
- private boolean featureOk = false;
- private TableState tableState = TableState.STEP;
- private boolean scenarioOk = false;
- private boolean examplesOk = false;
- private IFilterMethod filterMethod;
-
- @SuppressWarnings("unchecked")
- public FilterListener(Listener listener, List filters) {
- this.listener = listener;
- this.filters = filters;
- detectFilters(filters);
- }
-
- public void tag(String name, int line) throws Exception {
- if (hasNoFilters()){
- listener.tag(name, line);
- }
- else{
- metaBuffer.add(new Sexp(Sexp.Events.TAG, name, line));
- }
- replayBuffersIfAllOk();
- }
-
- public void comment(String content, int line) throws Exception {
- if (hasNoFilters()){
- listener.comment(content, line);
- }
- else{
- metaBuffer.add(new Sexp(Sexp.Events.COMMENT, content, line));
- }
- replayBuffersIfAllOk();
- }
-
- public void feature(String keyword, String name, int line) throws Exception {
- if (hasNoFilters()){
- listener.feature(keyword, name, line);
- }
- else{
- Sexp sexp = new Sexp(Sexp.Events.FEATURE, keyword, name, line);
- featureBuffer = metaBuffer;
- featureBuffer.add(sexp);
- featureTags = extractTags();
- metaBuffer = new ArrayList<Sexp>();
- if (filterMatch(sexp)){
- featureOk = true;
- }
- }
- replayBuffersIfAllOk();
- }
-
- public void background(String keyword, String name, int line)
- throws Exception {
- if (hasNoFilters()){
- listener.background(keyword, name, line);
- }
- else{
- Sexp sexp = new Sexp(Sexp.Events.BACKGROUND, keyword, name, line);
- featureBuffer.addAll(metaBuffer);
- featureBuffer.add(sexp);
- metaBuffer = new ArrayList<Sexp>();
- tableState = TableState.BACKGROUND;
- if (filterMatch(sexp)){
- featureOk = true;
- }
- }
- replayBuffersIfAllOk();
- }
-
- public void scenario(String keyword, String name, int line)
- throws Exception {
- if (hasNoFilters()){
- listener.scenario(keyword, name, line);
- }
- else{
- Sexp sexp = new Sexp(Sexp.Events.SCENARIO, keyword, name, line);
- replayExamplesRowsBuffer();
+
+ private final List filters;
+ private final Listener listener;
+ private List<Sexp> metaBuffer = new ArrayList<Sexp>();
+ private List<Sexp> featureBuffer = new ArrayList<Sexp>();
+ private List<Sexp> scenarioBuffer = new ArrayList<Sexp>();
+ private List<Sexp> examplesBuffer = new ArrayList<Sexp>();
+ private List<Sexp> examplesRowsBuffer = new ArrayList<Sexp>();
+
+ private List<String> featureTags = new ArrayList<String>();
+ private List<String> scenarioTags = new ArrayList<String>();
+ private List<String> exampleTags = new ArrayList<String>();
+
+ private boolean featureOk = false;
+ private TableState tableState = TableState.STEP;
+ private boolean scenarioOk = false;
+ private boolean examplesOk = false;
+ private IFilterMethod filterMethod;
+
+ @SuppressWarnings("unchecked")
+ public FilterListener(Listener listener, List filters) {
+ this.listener = listener;
+ this.filters = filters;
+ detectFilters(filters);
+ }
+
+ public void tag(String name, int line) throws Exception {
+ if (hasNoFilters()) {
+ listener.tag(name, line);
+ } else {
+ metaBuffer.add(new Sexp(Sexp.Events.TAG, name, line));
+ }
+ replayBuffersIfAllOk();
+ }
+
+ public void comment(String content, int line) throws Exception {
+ if (hasNoFilters()) {
+ listener.comment(content, line);
+ } else {
+ metaBuffer.add(new Sexp(Sexp.Events.COMMENT, content, line));
+ }
+ replayBuffersIfAllOk();
+ }
+
+ public void feature(String keyword, String name, int line) throws Exception {
+ if (hasNoFilters()) {
+ listener.feature(keyword, name, line);
+ } else {
+ Sexp sexp = new Sexp(Sexp.Events.FEATURE, keyword, name, line);
+ featureBuffer = metaBuffer;
+ featureBuffer.add(sexp);
+ featureTags = extractTags();
+ metaBuffer = new ArrayList<Sexp>();
+ if (filterMatch(sexp)) {
+ featureOk = true;
+ }
+ }
+ replayBuffersIfAllOk();
+ }
+
+ public void background(String keyword, String name, int line)
+ throws Exception {
+ if (hasNoFilters()) {
+ listener.background(keyword, name, line);
+ } else {
+ Sexp sexp = new Sexp(Sexp.Events.BACKGROUND, keyword, name, line);
+ featureBuffer.addAll(metaBuffer);
+ featureBuffer.add(sexp);
+ metaBuffer = new ArrayList<Sexp>();
+ tableState = TableState.BACKGROUND;
+ if (filterMatch(sexp)) {
+ featureOk = true;
+ }
+ }
+ replayBuffersIfAllOk();
+ }
+
+ public void scenario(String keyword, String name, int line)
+ throws Exception {
+ if (hasNoFilters()) {
+ listener.scenario(keyword, name, line);
+ } else {
+ Sexp sexp = new Sexp(Sexp.Events.SCENARIO, keyword, name, line);
+ replayExamplesRowsBuffer();
scenarioBuffer = metaBuffer;
scenarioBuffer.add(sexp);
scenarioTags = extractTags();
@@ -102,217 +97,207 @@ public void scenario(String keyword, String name, int line)
scenarioOk = filterMatch(scenarioBuffer) || tagMatch();
examplesOk = false;
tableState = TableState.STEP;
- }
- replayBuffersIfAllOk();
- }
-
- public void scenario_outline(String keyword, String name, int line)
- throws Exception {
- if (hasNoFilters()){
- listener.scenario_outline(keyword, name, line);
- }
- else{
- Sexp sexp = new Sexp(Sexp.Events.SCENARIO_OUTLINE, keyword, name, line);
- replayExamplesRowsBuffer();
- scenarioBuffer = metaBuffer;
- scenarioBuffer.add(sexp);
- scenarioTags = extractTags();
- exampleTags = new ArrayList<String>();
- metaBuffer = new ArrayList<Sexp>();
- scenarioOk = filterMatch(scenarioBuffer);
- examplesOk = false;
- tableState = TableState.STEP;
- }
- replayBuffersIfAllOk();
- }
-
- public void examples(String keyword, String name, int line)
- throws Exception {
- if (hasNoFilters()){
- listener.examples(keyword, name, line);
- }
- else{
- Sexp sexp = new Sexp(Sexp.Events.EXAMPLES, keyword, name, line);
- replayExamplesRowsBuffer();
- examplesBuffer = metaBuffer;
- examplesBuffer.add(sexp);
- exampleTags = extractTags();
- metaBuffer = new ArrayList<Sexp>();
- examplesRowsBuffer = new ArrayList<Sexp>();
- examplesOk = filterMatch(examplesBuffer) || tagMatch();
- tableState = TableState.EXAMPLES;
- }
- replayBuffersIfAllOk();
- }
-
- public void step(String keyword, String name, int line) throws Exception {
- if (hasNoFilters()){
- listener.step(keyword, name, line);
- }
- else{
- Sexp sexp = new Sexp(Sexp.Events.STEP, keyword, name, line);
- if (tableState.equals(TableState.BACKGROUND)){
- featureBuffer.addAll(metaBuffer);
- featureBuffer.add(sexp);
- metaBuffer = new ArrayList<Sexp>();
- if (filterMatch(sexp)){
- featureOk = true;
- }
- }
- else{
- scenarioBuffer.add(sexp);
- scenarioOk |= filterMatch(scenarioBuffer);
- tableState = TableState.STEP;
- }
- }
- replayBuffersIfAllOk();
- }
-
- public void row(List<String> row, int line) throws Exception {
- if (hasNoFilters()){
- listener.row(row, line);
- }
- else{
- Sexp sexp = new Sexp(Sexp.Events.ROW, row, line);
- if (tableState.equals(TableState.EXAMPLES)){
- if (!headerRowAllreadyBuffered()){
- examplesBuffer.add(sexp);
- if (filterMatch(examplesBuffer)){
- examplesOk = true;
- }
- }
- else{
- if (scenarioOk || examplesOk || featureOk || filterMatch(sexp)){
- examplesRowsBuffer.add(sexp);
- }
- }
- }
- else if (tableState.equals(TableState.STEP)){
- scenarioBuffer.add(sexp);
- scenarioOk |= filterMatch(scenarioBuffer);
- }
- else if (tableState.equals(TableState.BACKGROUND)){
- featureBuffer.addAll(metaBuffer);
- featureBuffer.add(sexp);
- metaBuffer = new ArrayList<Sexp>();
- }
- else{
- throw new RuntimeException("Bad table_state:" + tableState);
- }
- }
- replayBuffersIfAllOk();
- }
-
- public void py_string(String string, int line) throws Exception {
- if (hasNoFilters()){
- listener.py_string(string, line);
- }
- else{
- scenarioBuffer.add(new Sexp(Sexp.Events.PY_STRING, string, line));
- scenarioOk |= filterMatch(scenarioBuffer);
- }
- replayBuffersIfAllOk();
- }
-
- public void eof() throws Exception {
- replayExamplesRowsBuffer();
- listener.eof();
- }
-
- public void syntax_error(String state, String event,
- List<String> legalEvents, int line) throws Exception {
- }
-
- private void detectFilters(List filters) {
- if (hasNoFilters()){
- return;
- }
- checkIfMoreThanOneFilterType(filters);
- this.filterMethod = new FilterMethodFactory().getFilterMethod(filters.get(0).getClass());
- this.filterMethod.setFilters(filters);
- }
-
- private void checkIfMoreThanOneFilterType(List filters) {
- Set<Class> filterTypes = new HashSet<Class>();
- for (Object object : filters) {
- filterTypes.add(object.getClass());
- }
- if (filterTypes.size() > 1){
- throw new RuntimeException("Bad Filter: " + filterTypes);
- }
- }
-
- private boolean hasNoFilters() {
- return filters.size() == 0;
- }
-
- private boolean headerRowAllreadyBuffered() {
+ }
+ replayBuffersIfAllOk();
+ }
+
+ public void scenario_outline(String keyword, String name, int line)
+ throws Exception {
+ if (hasNoFilters()) {
+ listener.scenario_outline(keyword, name, line);
+ } else {
+ Sexp sexp = new Sexp(Sexp.Events.SCENARIO_OUTLINE, keyword, name, line);
+ replayExamplesRowsBuffer();
+ scenarioBuffer = metaBuffer;
+ scenarioBuffer.add(sexp);
+ scenarioTags = extractTags();
+ exampleTags = new ArrayList<String>();
+ metaBuffer = new ArrayList<Sexp>();
+ scenarioOk = filterMatch(scenarioBuffer);
+ examplesOk = false;
+ tableState = TableState.STEP;
+ }
+ replayBuffersIfAllOk();
+ }
+
+ public void examples(String keyword, String name, int line)
+ throws Exception {
+ if (hasNoFilters()) {
+ listener.examples(keyword, name, line);
+ } else {
+ Sexp sexp = new Sexp(Sexp.Events.EXAMPLES, keyword, name, line);
+ replayExamplesRowsBuffer();
+ examplesBuffer = metaBuffer;
+ examplesBuffer.add(sexp);
+ exampleTags = extractTags();
+ metaBuffer = new ArrayList<Sexp>();
+ examplesRowsBuffer = new ArrayList<Sexp>();
+ examplesOk = filterMatch(examplesBuffer) || tagMatch();
+ tableState = TableState.EXAMPLES;
+ }
+ replayBuffersIfAllOk();
+ }
+
+ public void step(String keyword, String name, int line) throws Exception {
+ if (hasNoFilters()) {
+ listener.step(keyword, name, line);
+ } else {
+ Sexp sexp = new Sexp(Sexp.Events.STEP, keyword, name, line);
+ if (tableState.equals(TableState.BACKGROUND)) {
+ featureBuffer.addAll(metaBuffer);
+ featureBuffer.add(sexp);
+ metaBuffer = new ArrayList<Sexp>();
+ if (filterMatch(sexp)) {
+ featureOk = true;
+ }
+ } else {
+ scenarioBuffer.add(sexp);
+ scenarioOk |= filterMatch(scenarioBuffer);
+ tableState = TableState.STEP;
+ }
+ }
+ replayBuffersIfAllOk();
+ }
+
+ public void row(List<String> row, int line) throws Exception {
+ if (hasNoFilters()) {
+ listener.row(row, line);
+ } else {
+ Sexp sexp = new Sexp(Sexp.Events.ROW, row, line);
+ if (tableState.equals(TableState.EXAMPLES)) {
+ if (!headerRowAllreadyBuffered()) {
+ examplesBuffer.add(sexp);
+ if (filterMatch(examplesBuffer)) {
+ examplesOk = true;
+ }
+ } else {
+ if (scenarioOk || examplesOk || featureOk || filterMatch(sexp)) {
+ examplesRowsBuffer.add(sexp);
+ }
+ }
+ } else if (tableState.equals(TableState.STEP)) {
+ scenarioBuffer.add(sexp);
+ scenarioOk |= filterMatch(scenarioBuffer);
+ } else if (tableState.equals(TableState.BACKGROUND)) {
+ featureBuffer.addAll(metaBuffer);
+ featureBuffer.add(sexp);
+ metaBuffer = new ArrayList<Sexp>();
+ } else {
+ throw new RuntimeException("Bad table_state:" + tableState);
+ }
+ }
+ replayBuffersIfAllOk();
+ }
+
+ public void py_string(String string, int line) throws Exception {
+ if (hasNoFilters()) {
+ listener.py_string(string, line);
+ } else {
+ scenarioBuffer.add(new Sexp(Sexp.Events.PY_STRING, string, line));
+ scenarioOk |= filterMatch(scenarioBuffer);
+ }
+ replayBuffersIfAllOk();
+ }
+
+ public void eof() throws Exception {
+ replayExamplesRowsBuffer();
+ listener.eof();
+ }
+
+ public void syntax_error(String state, String event,
+ List<String> legalEvents, int line) throws Exception {
+ }
+
+ private void detectFilters(List filters) {
+ if (hasNoFilters()) {
+ return;
+ }
+ checkIfMoreThanOneFilterType(filters);
+ this.filterMethod = new FilterMethodFactory().getFilterMethod(filters.get(0).getClass());
+ this.filterMethod.setFilters(filters);
+ }
+
+ private void checkIfMoreThanOneFilterType(List filters) {
+ Set<Class> filterTypes = new HashSet<Class>();
+ for (Object object : filters) {
+ filterTypes.add(object.getClass());
+ }
+ if (filterTypes.size() > 1) {
+ throw new RuntimeException("Bad Filter: " + filterTypes);
+ }
+ }
+
+ private boolean hasNoFilters() {
+ return filters.size() == 0;
+ }
+
+ private boolean headerRowAllreadyBuffered() {
return !examplesBuffer.isEmpty() && examplesBuffer.get(examplesBuffer.size() - 1).getEvent() == Sexp.Events.ROW;
}
- private boolean filterMatch(Sexp sexp) {
- return filterMatch(Arrays.asList(sexp));
- }
+ private boolean filterMatch(Sexp sexp) {
+ return filterMatch(Arrays.asList(sexp));
+ }
- private boolean filterMatch(List<Sexp> buffer) {
- for (Sexp sexp : buffer) {
- if (filterMethod.filter(sexp)){
- return true;
- }
- }
- return false;
- }
+ private boolean filterMatch(List<Sexp> buffer) {
+ for (Sexp sexp : buffer) {
+ if (filterMethod.filter(sexp)) {
+ return true;
+ }
+ }
+ return false;
+ }
- private boolean tagMatch() {
+ private boolean tagMatch() {
return filterMethod.getClass() == TagFilterMethod.class && filterMethod.filterTags(currentTags());
}
- private void replayBuffers() throws Exception {
- List<Sexp> allItems = new ArrayList<Sexp>();
- allItems.addAll(featureBuffer);
- allItems.addAll(scenarioBuffer);
- for (Sexp item : allItems) {
- item.replay(listener);
- }
- featureBuffer.clear();
- scenarioBuffer.clear();
- }
-
- private List<String> extractTags() {
- List<String> retVal = new ArrayList<String>();
- for (Sexp sexp : metaBuffer) {
- if (sexp.getEvent() == Sexp.Events.TAG){
- retVal.add(sexp.getName());
- }
- }
- return retVal;
- }
-
- private void replayExamplesRowsBuffer() throws Exception {
- if (!examplesRowsBuffer.isEmpty()){
- replayBuffers();
- List<Sexp> exampleItems = new ArrayList<Sexp>();
- exampleItems.addAll(examplesBuffer);
- exampleItems.addAll(examplesRowsBuffer);
- for (Sexp sexp : exampleItems) {
- sexp.replay(listener);
- }
- examplesRowsBuffer.clear();
- }
- }
-
- private void replayBuffersIfAllOk() throws Exception {
- if (scenarioOk || examplesOk || featureOk){
- replayBuffers();
- }
- }
-
- private List<String> currentTags() {
- List<String> retVal = new ArrayList<String>();
- retVal.addAll(featureTags);
- retVal.addAll(scenarioTags);
- retVal.addAll(exampleTags);
- return retVal;
- }
+ private void replayBuffers() throws Exception {
+ List<Sexp> allItems = new ArrayList<Sexp>();
+ allItems.addAll(featureBuffer);
+ allItems.addAll(scenarioBuffer);
+ for (Sexp item : allItems) {
+ item.replay(listener);
+ }
+ featureBuffer.clear();
+ scenarioBuffer.clear();
+ }
+
+ private List<String> extractTags() {
+ List<String> retVal = new ArrayList<String>();
+ for (Sexp sexp : metaBuffer) {
+ if (sexp.getEvent() == Sexp.Events.TAG) {
+ retVal.add(sexp.getName());
+ }
+ }
+ return retVal;
+ }
+
+ private void replayExamplesRowsBuffer() throws Exception {
+ if (!examplesRowsBuffer.isEmpty()) {
+ replayBuffers();
+ List<Sexp> exampleItems = new ArrayList<Sexp>();
+ exampleItems.addAll(examplesBuffer);
+ exampleItems.addAll(examplesRowsBuffer);
+ for (Sexp sexp : exampleItems) {
+ sexp.replay(listener);
+ }
+ examplesRowsBuffer.clear();
+ }
+ }
+
+ private void replayBuffersIfAllOk() throws Exception {
+ if (scenarioOk || examplesOk || featureOk) {
+ replayBuffers();
+ }
+ }
+
+ private List<String> currentTags() {
+ List<String> retVal = new ArrayList<String>();
+ retVal.addAll(featureTags);
+ retVal.addAll(scenarioTags);
+ retVal.addAll(exampleTags);
+ return retVal;
+ }
}
View
25 java/src/main/java/gherkin/parser/FilterMethodFactory.java
@@ -4,19 +4,16 @@
public class FilterMethodFactory {
- public IFilterMethod getFilterMethod(Class<?> typeOfFilter) {
- if (String.class.isAssignableFrom(typeOfFilter)){
- return new TagFilterMethod();
- }
- else if (Number.class.isAssignableFrom(typeOfFilter)){
- return new LineFilterMethod();
- }
- else if (Pattern.class.isAssignableFrom(typeOfFilter)){
- return new NameFilterMethod();
- }
- else{
- throw new RuntimeException("Could not create filter method for unknown filter of type: " + typeOfFilter);
- }
- }
+ public IFilterMethod getFilterMethod(Class<?> typeOfFilter) {
+ if (String.class.isAssignableFrom(typeOfFilter)) {
+ return new TagFilterMethod();
+ } else if (Number.class.isAssignableFrom(typeOfFilter)) {
+ return new LineFilterMethod();
+ } else if (Pattern.class.isAssignableFrom(typeOfFilter)) {
+ return new NameFilterMethod();
+ } else {
+ throw new RuntimeException("Could not create filter method for unknown filter of type: " + typeOfFilter);
+ }
+ }
}
View
8 java/src/main/java/gherkin/parser/IFilterMethod.java
@@ -4,8 +4,10 @@
public interface IFilterMethod {
- void setFilters(List filters);
- boolean filterTags(List currentTags);
- boolean filter(Sexp sexp);
+ void setFilters(List filters);
+
+ boolean filterTags(List currentTags);
+
+ boolean filter(Sexp sexp);
}
View
30 java/src/main/java/gherkin/parser/LineFilterMethod.java
@@ -4,24 +4,24 @@
public class LineFilterMethod implements IFilterMethod {
- private List<Number> filters;
+ private List<Number> filters;
- public boolean filterTags(List currentTags) {
- return false;
- }
+ public boolean filterTags(List currentTags) {
+ return false;
+ }
@SuppressWarnings("unchecked")
- public void setFilters(List filters) {
- this.filters = (List<Number>)filters;
- }
+ public void setFilters(List filters) {
+ this.filters = (List<Number>) filters;
+ }
- public boolean filter(Sexp sexp) {
- for (Number filterItem : filters) {
- if (filterItem.toString().equals(sexp.getLine().toString())){
- return true;
- }
- }
- return false;
- }
+ public boolean filter(Sexp sexp) {
+ for (Number filterItem : filters) {
+ if (filterItem.toString().equals(sexp.getLine().toString())) {
+ return true;
+ }
+ }
+ return false;
+ }
}
View
28 java/src/main/java/gherkin/parser/NameFilterMethod.java
@@ -5,24 +5,24 @@
public class NameFilterMethod implements IFilterMethod {
- private List<Pattern> filters;
+ private List<Pattern> filters;
- public boolean filterTags(List currentTags) {
- return false;
- }
+ public boolean filterTags(List currentTags) {
+ return false;
+ }
- @SuppressWarnings("unchecked")
- public void setFilters(List filters) {
- this.filters = filters;
- }
+ @SuppressWarnings("unchecked")
+ public void setFilters(List filters) {
+ this.filters = filters;
+ }
- public boolean filter(Sexp sexp) {
- for (Pattern filter : filters) {
- if(sexp.matches(filter)) {
+ public boolean filter(Sexp sexp) {
+ for (Pattern filter : filters) {
+ if (sexp.matches(filter)) {
return true;
}
- }
- return false;
- }
+ }
+ return false;
+ }
}
View
116 java/src/main/java/gherkin/parser/Sexp.java
@@ -6,30 +6,30 @@
import java.util.regex.Pattern;
public class Sexp {
- enum Events{
- ROW, TAG, COMMENT,
- FEATURE, BACKGROUND, SCENARIO,
- SCENARIO_OUTLINE, EXAMPLES, STEP,
- PY_STRING
- }
+ enum Events {
+ ROW, TAG, COMMENT,
+ FEATURE, BACKGROUND, SCENARIO,
+ SCENARIO_OUTLINE, EXAMPLES, STEP,
+ PY_STRING
+ }
- private final Events event;
+ private final Events event;
private final String keyword;
private final String name;
private final List<String> row;
private final int line;
- public Sexp(Events event, String name, int line) {
+ public Sexp(Events event, String name, int line) {
this(event, null, name, line);
- }
+ }
- public Sexp(Events event, String keyword, String name, int line) {
+ public Sexp(Events event, String keyword, String name, int line) {
this(event, keyword, name, null, line);
- }
+ }
- public Sexp(Events event, List<String> row, int line) {
- this(event, null, null, row, line);
- }
+ public Sexp(Events event, List<String> row, int line) {
+ this(event, null, null, row, line);
+ }
private Sexp(Events event, String keyword, String name, List<String> row, int line) {
this.event = event;
@@ -39,49 +39,49 @@ private Sexp(Events event, String keyword, String name, List<String> row, int li
this.line = line;
}
- public Events getEvent() {
- return this.event;
- }
+ public Events getEvent() {
+ return this.event;
+ }
- public void replay(Listener listener) throws Exception {
- switch (this.event) {
- case ROW:
- listener.row(row, line);
- break;
- case TAG:
- listener.tag(name, line);
- break;
- case COMMENT:
- listener.comment(name, line);
- break;
- case FEATURE:
- listener.feature(keyword, name, line);
- break;
- case BACKGROUND:
- listener.background(keyword, name, line);
- break;
- case SCENARIO:
- listener.scenario(keyword, name, line);
- break;
- case SCENARIO_OUTLINE:
- listener.scenario_outline(keyword, name, line);
- break;
- case EXAMPLES:
- listener.examples(keyword, name, line);
- break;
- case STEP:
- listener.step(keyword, name, line);
- break;
- case PY_STRING:
- listener.py_string(name, line);
- break;
- default:
- throw new RuntimeException("Bad event");
- }
- }
+ public void replay(Listener listener) throws Exception {
+ switch (this.event) {
+ case ROW:
+ listener.row(row, line);
+ break;
+ case TAG:
+ listener.tag(name, line);
+ break;
+ case COMMENT:
+ listener.comment(name, line);
+ break;
+ case FEATURE:
+ listener.feature(keyword, name, line);
+ break;
+ case BACKGROUND:
+ listener.background(keyword, name, line);
+ break;
+ case SCENARIO:
+ listener.scenario(keyword, name, line);
+ break;
+ case SCENARIO_OUTLINE:
+ listener.scenario_outline(keyword, name, line);
+ break;
+ case EXAMPLES:
+ listener.examples(keyword, name, line);
+ break;
+ case STEP:
+ listener.step(keyword, name, line);
+ break;
+ case PY_STRING:
+ listener.py_string(name, line);
+ break;
+ default:
+ throw new RuntimeException("Bad event");
+ }
+ }
public boolean matches(Pattern filter) {
- switch(event) {
+ switch (event) {
case FEATURE:
case SCENARIO:
case SCENARIO_OUTLINE:
@@ -95,8 +95,8 @@ public boolean matches(Pattern filter) {
public String getName() {
return name;
}
-
- public Integer getLine() {
- return line;
- }
+
+ public Integer getLine() {
+ return line;
+ }
}
View
2  java/src/main/java/gherkin/parser/TableState.java
@@ -1,5 +1,5 @@
package gherkin.parser;
public enum TableState {
- BACKGROUND, STEP, EXAMPLES
+ BACKGROUND, STEP, EXAMPLES
}
View
20 java/src/main/java/gherkin/parser/TagExpression.java
@@ -6,11 +6,11 @@
import java.util.Map;
public class TagExpression {
- private final Map<String, Integer> limits = new HashMap<String,Integer>();
+ private final Map<String, Integer> limits = new HashMap<String, Integer>();
private And and = new And();
public TagExpression(List<String> tagExpressions) {
- for(String tagExpression: tagExpressions) {
+ for (String tagExpression : tagExpressions) {
add(tagExpression.split("\\s*,\\s*"));
}
}
@@ -19,19 +19,19 @@ public boolean eval(List<String> tags) {
return and.isEmpty() || and.eval(tags);
}
- public Map<String,Integer> limits() {
+ public Map<String, Integer> limits() {
return limits;
}
private void add(String[] tags) {
Or or = new Or();
- for(String tag : tags) {
+ for (String tag : tags) {
tag = tag.trim();
- if(tag.startsWith("~")) {
+ if (tag.startsWith("~")) {
or.add(new Not(new Var(tag.substring(1))));
} else {
String[] tagAndLimit = tag.split(":");
- if(tagAndLimit.length == 2) {
+ if (tagAndLimit.length == 2) {
tag = tagAndLimit[0];
int limit = Integer.parseInt(tagAndLimit[1]);
limits.put(tag, limit);
@@ -67,7 +67,7 @@ public void add(Expression expression) {
public boolean eval(List<String> tags) {
boolean result = true;
- for(Expression expression: expressions) {
+ for (Expression expression : expressions) {
result = result && expression.eval(tags);
}
return result;
@@ -87,7 +87,7 @@ public void add(Expression expression) {
public boolean eval(List<String> tags) {
boolean result = false;
- for(Expression expression : expressions) {
+ for (Expression expression : expressions) {
result = result || expression.eval(tags);
}
return result;
@@ -102,8 +102,8 @@ public Var(String tagName) {
}
public boolean eval(List<String> tags) {
- for(String tag: tags) {
- if(tagName.equals(tag)) {
+ for (String tag : tags) {
+ if (tagName.equals(tag)) {
return true;
}
}
View
24 java/src/main/java/gherkin/parser/TagFilterMethod.java
@@ -4,20 +4,20 @@
public class TagFilterMethod implements IFilterMethod {
- private TagExpression tagExpression;
+ private TagExpression tagExpression;
- @SuppressWarnings("unchecked")
- public boolean filterTags(List currentTags) {
- return tagExpression.eval(currentTags);
- }
+ @SuppressWarnings("unchecked")
+ public boolean filterTags(List currentTags) {
+ return tagExpression.eval(currentTags);
+ }
- @SuppressWarnings("unchecked")
- public void setFilters(List filters) {
- this.tagExpression = new TagExpression(filters);
- }
+ @SuppressWarnings("unchecked")
+ public void setFilters(List filters) {
+ this.tagExpression = new TagExpression(filters);
+ }
- public boolean filter(Sexp sexp) {
- return false;
- }
+ public boolean filter(Sexp sexp) {
+ return false;
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.