Skip to content

Commit

Permalink
moving steps from SharedSteps to ParsingSteps
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomassetti committed Aug 24, 2015
1 parent 3b9e681 commit 3c678ae
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 35 deletions.
Expand Up @@ -21,19 +21,23 @@

package com.github.javaparser.bdd.steps;

import com.github.javaparser.ASTHelper;
import com.github.javaparser.ast.*;
import com.github.javaparser.ast.body.*;
import com.github.javaparser.ast.expr.*;
import com.github.javaparser.ast.stmt.*;
import org.jbehave.core.annotations.Then;
import org.jbehave.core.annotations.When;

import java.util.List;
import java.util.Map;

import static com.github.javaparser.bdd.steps.SharedSteps.getMemberByTypeAndPosition;
import static com.github.javaparser.bdd.steps.SharedSteps.getMethodByPositionAndClassPosition;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNull.notNullValue;
import static org.hamcrest.core.IsNull.nullValue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;

public class ParsingSteps {
Expand Down Expand Up @@ -218,4 +222,37 @@ public void thenLambdaInConditionalExpressionInMethodInClassIsParentOfContainedP
assertThat(conditionalExpr.getElseExpr().getClass().getName(), is(LambdaExpr.class.getName()));
}

@Then("the begin line is $line")
public void thenTheBeginLineIs(int line) {
Node node = (Node) state.get("selectedNode");
assertEquals(line, node.getBeginLine());
}

@Then("the begin column is $column")
public void thenTheBeginColumnIs(int column) {
Node node = (Node) state.get("selectedNode");
assertEquals(column, node.getBeginColumn());
}

@Then("the end line is $line")
public void thenTheEndLineIs(int line) {
Node node = (Node) state.get("selectedNode");
assertEquals(line, node.getEndLine());
}

@Then("the end column is $column")
public void thenTheEndColumnIs(int column) {
Node node = (Node) state.get("selectedNode");
assertEquals(column, node.getEndColumn());
}

@When("I take the ArrayCreationExpr")
public void iTakeTheArrayCreationExpr() {
CompilationUnit compilationUnit = (CompilationUnit) state.get("cu1");
List<ArrayCreationExpr> arrayCreationExprs = ASTHelper.getNodesByType(compilationUnit, ArrayCreationExpr.class);
if (arrayCreationExprs.size() != 1) {
throw new RuntimeException("Exactly one ArrayCreationExpr expected");
}
state.put("selectedNode", arrayCreationExprs.get(0));
}
}
Expand Up @@ -79,7 +79,6 @@ public void whenTheFollowingSourceIsParsedTrimmingSpace(String classSrc) throws
state.put("cu1", JavaParser.parse(new ByteArrayInputStream(classSrc.trim().getBytes())));
}


@When("the following sources is parsed by the second CompilationUnit:$classSrc")
public void whenTheFollowingSourcesIsParsedBytTheSecondCompilationUnit(String classSrc) throws ParseException {
state.put("cu2", JavaParser.parse(new ByteArrayInputStream(classSrc.getBytes())));
Expand Down Expand Up @@ -130,40 +129,6 @@ public void thenTheExpectedSourcesShouldBe(String classSrc) {
assertThat(compilationUnit.toString(), CoreMatchers.is(equalToIgnoringWhiteSpace(classSrc)));
}

@Then("the begin line is $line")
public void thenTheBeginLineIs(int line) {
Node node = (Node) state.get("selectedNode");
assertEquals(line, node.getBeginLine());
}

@Then("the begin column is $line")
public void thenTheBeginColumnIs(int column) {
Node node = (Node) state.get("selectedNode");
assertEquals(column, node.getBeginColumn());
}

@Then("the end line is $line")
public void thenTheEndLineIs(int line) {
Node node = (Node) state.get("selectedNode");
assertEquals(line, node.getEndLine());
}

@Then("the end column is $line")
public void thenTheEndColumnIs(int column) {
Node node = (Node) state.get("selectedNode");
assertEquals(column, node.getEndColumn());
}

@When("I take the ArrayCreationExpr")
public void iTakeTheArrayCreationExpr() {
CompilationUnit compilationUnit = (CompilationUnit) state.get("cu1");
List<ArrayCreationExpr> arrayCreationExprs = ASTHelper.getNodesByType(compilationUnit, ArrayCreationExpr.class);
if (arrayCreationExprs.size() != 1) {
throw new RuntimeException("Exactly one ArrayCreationExpr expected");
}
state.put("selectedNode", arrayCreationExprs.get(0));
}

public static BodyDeclaration getMemberByTypeAndPosition(TypeDeclaration typeDeclaration, int position,
Class<? extends BodyDeclaration> typeClass){
int typeCount = 0;
Expand Down

0 comments on commit 3c678ae

Please sign in to comment.