Search in sources :

Example 21 with CompilationUnit

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));
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) Then(org.jbehave.core.annotations.Then)

Example 22 with CompilationUnit

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);
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit)

Example 23 with 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");
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) ExpressionStmt(com.github.javaparser.ast.stmt.ExpressionStmt) Then(org.jbehave.core.annotations.Then)

Example 24 with CompilationUnit

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())));
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) Then(org.jbehave.core.annotations.Then)

Example 25 with CompilationUnit

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())));
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) Then(org.jbehave.core.annotations.Then)

Aggregations

CompilationUnit (com.github.javaparser.ast.CompilationUnit)489 Test (org.junit.Test)304 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)160 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)140 ReflectionTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver)128 AbstractResolutionTest (com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest)101 MethodCallExpr (com.github.javaparser.ast.expr.MethodCallExpr)70 ResolvedType (com.github.javaparser.resolution.types.ResolvedType)66 Context (com.github.javaparser.symbolsolver.core.resolution.Context)62 TypeSolver (com.github.javaparser.symbolsolver.model.resolution.TypeSolver)55 CompilationUnitContext (com.github.javaparser.symbolsolver.javaparsermodel.contexts.CompilationUnitContext)51 JavaParserFacade (com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade)45 File (java.io.File)39 Expression (com.github.javaparser.ast.expr.Expression)38 ClassOrInterfaceDeclarationContext (com.github.javaparser.symbolsolver.javaparsermodel.contexts.ClassOrInterfaceDeclarationContext)38 MethodUsage (com.github.javaparser.resolution.MethodUsage)34 MemoryTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.MemoryTypeSolver)33 AbstractTest (com.github.javaparser.symbolsolver.AbstractTest)29 CombinedTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver)29 ArrayList (java.util.ArrayList)29