use of com.github.javaparser.ast.CompilationUnit in project javaparser by javaparser.
the class ParsingSteps method thenConstructorInClassDeclarationShortFormAsAStringIs.
@Then("constructor $constructorPosition in class $classPosition declaration short form as a String is \"$expectedString\"")
public void thenConstructorInClassDeclarationShortFormAsAStringIs(int constructorPosition, int classPosition, String expectedString) {
CompilationUnit compilationUnit = (CompilationUnit) state.get("cu1");
ClassOrInterfaceDeclaration clazz = (ClassOrInterfaceDeclaration) compilationUnit.getType(classPosition - 1);
ConstructorDeclaration constructor = (ConstructorDeclaration) clazz.getMember(constructorPosition - 1);
assertThat(constructor.getDeclarationAsString(false, false), is(expectedString));
}
use of com.github.javaparser.ast.CompilationUnit in project javaparser by javaparser.
the class ParsingSteps method assertAllNodesOfTheCompilationUnitHaveTheirParentSet.
private void assertAllNodesOfTheCompilationUnitHaveTheirParentSet(String stateKey) {
CompilationUnit compilationUnit = (CompilationUnit) state.get(stateKey);
ExistenceOfParentNodeVerifier parentVerifier = new ExistenceOfParentNodeVerifier();
parentVerifier.verify(compilationUnit);
}
use of com.github.javaparser.ast.CompilationUnit in project javaparser by javaparser.
the class ParsingSteps method thenTheAssignExprProducedDoesntHaveANullTarget.
@Then("the assignExpr produced doesn't have a null target")
public void thenTheAssignExprProducedDoesntHaveANullTarget() {
CompilationUnit compilationUnit = (CompilationUnit) state.get("cu1");
ClassOrInterfaceDeclaration classDeclaration = compilationUnit.getType(0).asClassOrInterfaceDeclaration();
ConstructorDeclaration ctor = classDeclaration.getMember(1).asConstructorDeclaration();
ExpressionStmt assignStmt = ctor.getBody().getStatement(0).asExpressionStmt();
AssignExpr assignExpr = assignStmt.getExpression().asAssignExpr();
assertNotNull(assignExpr.getTarget());
assertEquals(NameExpr.class, assignExpr.getTarget().getClass());
assertEquals(assignExpr.getTarget().asNameExpr().getNameAsString(), "mString");
}
use of com.github.javaparser.ast.CompilationUnit in project javaparser by javaparser.
the class SharedSteps method thenTheCompilationUnitHasADifferentHashcodeToTheSecondCompilationUnit.
@Then("the CompilationUnit has a different hashcode to the second CompilationUnit")
public void thenTheCompilationUnitHasADifferentHashcodeToTheSecondCompilationUnit() {
CompilationUnit compilationUnit = (CompilationUnit) state.get("cu1");
CompilationUnit compilationUnit2 = (CompilationUnit) state.get("cu2");
assertThat(compilationUnit.hashCode(), not(equalTo(compilationUnit2.hashCode())));
}
use of com.github.javaparser.ast.CompilationUnit in project javaparser by javaparser.
the class SharedSteps method thenTheCompilationUnitHasTheSameHashcodeToTheSecondCompilationUnit.
@Then("the CompilationUnit has the same hashcode to the second CompilationUnit")
public void thenTheCompilationUnitHasTheSameHashcodeToTheSecondCompilationUnit() {
CompilationUnit compilationUnit = (CompilationUnit) state.get("cu1");
CompilationUnit compilationUnit2 = (CompilationUnit) state.get("cu2");
assertThat(compilationUnit.hashCode(), is(equalTo(compilationUnit2.hashCode())));
}
Aggregations