Search in sources :

Example 16 with Statement

use of com.github.javaparser.ast.stmt.Statement in project javaparser by javaparser.

the class SourceFileInfoExtractor method solve.

private void solve(Node node) {
    if (node instanceof ClassOrInterfaceDeclaration) {
        solveTypeDecl((ClassOrInterfaceDeclaration) node);
    } else if (node instanceof Expression) {
        if ((requireParentNode(node) instanceof ImportDeclaration) || (requireParentNode(node) instanceof Expression) || (requireParentNode(node) instanceof MethodDeclaration) || (requireParentNode(node) instanceof PackageDeclaration)) {
        // skip
        } else if ((requireParentNode(node) instanceof Statement) || (requireParentNode(node) instanceof VariableDeclarator)) {
            try {
                ResolvedType ref = JavaParserFacade.get(typeSolver).getType(node);
                out.println("  Line " + node.getRange().get().begin.line + ") " + node + " ==> " + ref.describe());
                ok++;
            } catch (UnsupportedOperationException upe) {
                unsupported++;
                err.println(upe.getMessage());
                throw upe;
            } catch (RuntimeException re) {
                ko++;
                err.println(re.getMessage());
                throw re;
            }
        }
    }
}
Also used : ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) Expression(com.github.javaparser.ast.expr.Expression) ResolvedMethodDeclaration(com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) Statement(com.github.javaparser.ast.stmt.Statement) ImportDeclaration(com.github.javaparser.ast.ImportDeclaration) PackageDeclaration(com.github.javaparser.ast.PackageDeclaration) ResolvedType(com.github.javaparser.resolution.types.ResolvedType) VariableDeclarator(com.github.javaparser.ast.body.VariableDeclarator)

Example 17 with Statement

use of com.github.javaparser.ast.stmt.Statement in project javaparser by javaparser.

the class ManipulationSteps method thenTheBlockStmtContentIs.

@Then("Statement $position in BlockStmt toString is \"$expectedContent\"")
public void thenTheBlockStmtContentIs(int position, String expectedContent) {
    Statement statementUnderTest = blockStmt.getStatement(position - 1);
    assertThat(statementUnderTest.toString(), is(expectedContent));
}
Also used : Statement(com.github.javaparser.ast.stmt.Statement) Then(org.jbehave.core.annotations.Then)

Example 18 with Statement

use of com.github.javaparser.ast.stmt.Statement in project javaparser by javaparser.

the class ParsingSteps method thenLambdaInStatementInMethodInClassIsParentOfContainedBody.

@Then("lambda in statement $statementPosition in method $methodPosition in class $classPosition is parent of contained body")
public void thenLambdaInStatementInMethodInClassIsParentOfContainedBody(int statementPosition, int methodPosition, int classPosition) {
    LambdaExpr lambdaExpr = getLambdaExprInStatementInMethodInClass(statementPosition, methodPosition, classPosition);
    Statement body = lambdaExpr.getBody();
    assertThat(body.getParentNode().get(), is(lambdaExpr));
}
Also used : Statement(com.github.javaparser.ast.stmt.Statement) Then(org.jbehave.core.annotations.Then)

Example 19 with Statement

use of com.github.javaparser.ast.stmt.Statement in project javaparser by javaparser.

the class ParsingSteps method thenLambdaInClassIsCalled.

@Then("lambda in statement $statementPosition in method $methodPosition in class $classPosition is called $expectedName")
public void thenLambdaInClassIsCalled(int statementPosition, int methodPosition, int classPosition, String expectedName) {
    Statement statement = getStatementInMethodInClass(statementPosition, methodPosition, classPosition);
    VariableDeclarationExpr expression = (VariableDeclarationExpr) ((ExpressionStmt) statement).getExpression();
    VariableDeclarator variableDeclarator = expression.getVariable(0);
    assertThat(variableDeclarator.getNameAsString(), is(expectedName));
}
Also used : Statement(com.github.javaparser.ast.stmt.Statement) Then(org.jbehave.core.annotations.Then)

Example 20 with Statement

use of com.github.javaparser.ast.stmt.Statement in project javaparser by javaparser.

the class ParsingSteps method thenMethodReferenceInStatementInMethodInClassIdentifierIsCompareByAge.

@Then("method reference in statement $statementPosition in method $methodPosition in class $classPosition identifier is $expectedName")
public void thenMethodReferenceInStatementInMethodInClassIdentifierIsCompareByAge(int statementPosition, int methodPosition, int classPosition, String expectedName) {
    Statement statementUnderTest = getStatementInMethodInClass(statementPosition, methodPosition, classPosition);
    assertEquals(1, statementUnderTest.findAll(MethodReferenceExpr.class).size());
    MethodReferenceExpr methodReferenceUnderTest = statementUnderTest.findFirst(MethodReferenceExpr.class).get();
    assertThat(methodReferenceUnderTest.getIdentifier(), is(expectedName));
}
Also used : Statement(com.github.javaparser.ast.stmt.Statement) Then(org.jbehave.core.annotations.Then)

Aggregations

Statement (com.github.javaparser.ast.stmt.Statement)23 Test (org.junit.Test)7 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)6 ExpressionStmt (com.github.javaparser.ast.stmt.ExpressionStmt)6 Then (org.jbehave.core.annotations.Then)5 Expression (com.github.javaparser.ast.expr.Expression)4 BlockStmt (com.github.javaparser.ast.stmt.BlockStmt)3 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)2 Parameter (com.github.javaparser.ast.body.Parameter)2 ResolvedType (com.github.javaparser.resolution.types.ResolvedType)2 ASTParser (com.github.javaparser.ASTParser)1 CompilationUnit (com.github.javaparser.ast.CompilationUnit)1 ImportDeclaration (com.github.javaparser.ast.ImportDeclaration)1 PackageDeclaration (com.github.javaparser.ast.PackageDeclaration)1 TypeParameter (com.github.javaparser.ast.TypeParameter)1 MultiTypeParameter (com.github.javaparser.ast.body.MultiTypeParameter)1 VariableDeclarator (com.github.javaparser.ast.body.VariableDeclarator)1 LambdaExpr (com.github.javaparser.ast.expr.LambdaExpr)1 SwitchEntryStmt (com.github.javaparser.ast.stmt.SwitchEntryStmt)1 SwitchStmt (com.github.javaparser.ast.stmt.SwitchStmt)1