Search in sources :

Example 16 with CompilationUnit

use of com.github.javaparser.ast.CompilationUnit in project javaparser by javaparser.

the class ManipulationSteps method thenMethodInClassHasTheName.

@Then("method $methodPosition in class $classPosition has the name \"$expectedName\"")
public void thenMethodInClassHasTheName(int methodPosition, int classPosition, String expectedName) {
    CompilationUnit compilationUnit = (CompilationUnit) state.get("cu1");
    MethodDeclaration method = getMethodByPositionAndClassPosition(compilationUnit, methodPosition, classPosition);
    assertThat(method.getNameAsString(), is(expectedName));
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) Then(org.jbehave.core.annotations.Then)

Example 17 with CompilationUnit

use of com.github.javaparser.ast.CompilationUnit in project javaparser by javaparser.

the class ManipulationSteps method whenMethodInClassHasItsNameConvertedToUppercase.

@When("method $methodPosition in class $classPosition has it's name converted to uppercase")
public void whenMethodInClassHasItsNameConvertedToUppercase(int methodPosition, int classPosition) {
    CompilationUnit compilationUnit = (CompilationUnit) state.get("cu1");
    MethodDeclaration method = getMethodByPositionAndClassPosition(compilationUnit, methodPosition, classPosition);
    method.setName(method.getNameAsString().toUpperCase());
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) When(org.jbehave.core.annotations.When)

Example 18 with CompilationUnit

use of com.github.javaparser.ast.CompilationUnit in project javaparser by javaparser.

the class ManipulationSteps method thenIsNotEqualToNull.

@Then("is not equal to null")
public void thenIsNotEqualToNull() {
    CompilationUnit compilationUnit = (CompilationUnit) state.get("cu1");
    assertNotEquals(compilationUnit, null);
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) Then(org.jbehave.core.annotations.Then)

Example 19 with CompilationUnit

use of com.github.javaparser.ast.CompilationUnit in project javaparser by javaparser.

the class ParsingSteps method thenMethodClassIsNotADefaultMethod.

@Then("method $methodPosition class $classPosition is not a default method")
public void thenMethodClassIsNotADefaultMethod(int methodPosition, int classPosition) {
    CompilationUnit compilationUnit = (CompilationUnit) state.get("cu1");
    MethodDeclaration methodUnderTest = getMethodByPositionAndClassPosition(compilationUnit, methodPosition, classPosition);
    assertThat(methodUnderTest.isDefault(), is(false));
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) Then(org.jbehave.core.annotations.Then)

Example 20 with CompilationUnit

use of com.github.javaparser.ast.CompilationUnit in project javaparser by javaparser.

the class ParsingSteps method getStatementInMethodInClass.

private Statement getStatementInMethodInClass(int statementPosition, int methodPosition, int classPosition) {
    CompilationUnit compilationUnit = (CompilationUnit) state.get("cu1");
    MethodDeclaration method = getMethodByPositionAndClassPosition(compilationUnit, methodPosition, classPosition);
    return method.getBody().get().getStatement(statementPosition - 1);
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit)

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