This kind of node is used to convert an expression (Expression) into a statement (Statement) by wrapping it.
Expression
Statement
ExpressionStatement: StatementExpression ;
5455565758596061626364
} public void andAssignTo(FieldInfo fieldInfo) { Assignment assignment = ast.newAssignment(); ExpressionStatement statement = ast.newExpressionStatement(assignment); block.statements().add(statement); MethodInvocation invocation = getterInfo.toMethodInvocation(ast, name); assignment.setRightHandSide(invocation); assignment.setOperator(Operator.ASSIGN);
70717273747576777879
md.setBody(block); MethodInvocation mi = ast.newMethodInvocation(); mi.setName(ast.newSimpleName("x")); ExpressionStatement e = ast.newExpressionStatement(mi); block.statements().add(e); System.out.println(cu); }
103104105106107108109110111
IMethodBinding definition = BindingUtils.findMethodDefininition(invocation.resolveMethodBinding(), null); assertEquals("sharpen.ui.tests.BindingTestCaseSubject.Foo.bar", BindingUtils.qualifiedName(definition)); } private MethodInvocation getFirstMethodInvocation(MethodDeclaration method) { ExpressionStatement stmt = (ExpressionStatement) method.getBody().statements().get(0); MethodInvocation invocation = (MethodInvocation) stmt.getExpression(); return invocation; }
280281282283284285286287288289290
.setOperator(org.eclipse.jdt.core.dom.Assignment.Operator.ASSIGN); assignment.setLeftHandSide(fieldAccess); assignment.setRightHandSide(parameter); // Expression ExpressionStatement expressionStatement = ast .newExpressionStatement(assignment); block.statements().add(expressionStatement); }
100101102103104105106107
String mockMethodInvocationCode = getNewMethodName() + "(" + getNewMethodParameters() + ");"; fooParser.setSource(mockMethodInvocationCode.toCharArray()); fooParser.setResolveBindings(true); ASTNode parsedAstNode = fooParser.createAST(null); Block codeBlock = (Block) parsedAstNode; ExpressionStatement methodInvocationExpressionStatement = (ExpressionStatement) codeBlock.statements().get(0); return methodInvocationExpressionStatement.getExpression(); }