/** @deprecated using deprecated code */ public void testPostfixExpression() throws Exception { IPackageFragment pack1 = this.sourceFolder.createPackageFragment("test1", false, null); StringBuffer buf = new StringBuffer(); buf.append(" function foo() {\n"); buf.append(" i= x--;\n"); buf.append(" }\n"); IJavaScriptUnit cu = pack1.createCompilationUnit("E.js", buf.toString(), false, null); JavaScriptUnit astRoot = createAST(cu); ASTRewrite rewrite = ASTRewrite.create(astRoot.getAST()); AST ast = astRoot.getAST(); assertTrue("Parse errors", (astRoot.getFlags() & ASTNode.MALFORMED) == 0); // TypeDeclaration type= findTypeDeclaration(astRoot, "E"); FunctionDeclaration methodDecl = findMethodDeclaration(astRoot, "foo"); Block block = methodDecl.getBody(); List statements = block.statements(); assertTrue("Number of statements not 1", statements.size() == 1); { // modify operand and operation ExpressionStatement stmt = (ExpressionStatement) statements.get(0); Assignment assignment = (Assignment) stmt.getExpression(); PostfixExpression postExpression = (PostfixExpression) assignment.getRightHandSide(); NumberLiteral newOperation = ast.newNumberLiteral("10"); rewrite.replace(postExpression.getOperand(), newOperation, null); rewrite.set( postExpression, PostfixExpression.OPERATOR_PROPERTY, PostfixExpression.Operator.INCREMENT, null); } String preview = evaluateRewrite(cu, rewrite); buf = new StringBuffer(); buf.append(" function foo() {\n"); buf.append(" i= 10++;\n"); buf.append(" }\n"); assertEqualString(preview, buf.toString()); }
/* * @see ASTVisitor#visit(PostfixExpression) */ public boolean visit(PostfixExpression node) { node.getOperand().accept(this); this.fBuffer.append(node.getOperator().toString()); return false; }