/* (omit javadoc for this method) * Method declared on ASTNode. */ ASTNode clone0(AST target) { InfixExpression result = new InfixExpression(target); result.setSourceRange(this.getStartPosition(), this.getLength()); result.setOperator(getOperator()); result.setLeftOperand((Expression) getLeftOperand().clone(target)); result.setRightOperand((Expression) getRightOperand().clone(target)); if (this.extendedOperands != null) { // be careful not to trigger lazy creation of list result.extendedOperands().addAll(ASTNode.copySubtrees(target, this.extendedOperands())); } return result; }
/** @deprecated using deprecated code */ public void testConditionalExpression() throws Exception { IPackageFragment pack1 = this.sourceFolder.createPackageFragment("test1", false, null); StringBuffer buf = new StringBuffer(); buf.append(" function foo() {\n"); buf.append(" i= (k == 0) ? 1 : 2;\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); { // change compare expression, then expression & else expression ExpressionStatement stmt = (ExpressionStatement) statements.get(0); Assignment assignment = (Assignment) stmt.getExpression(); ConditionalExpression condExpression = (ConditionalExpression) assignment.getRightHandSide(); BooleanLiteral literal = ast.newBooleanLiteral(true); rewrite.replace(condExpression.getExpression(), literal, null); SimpleName newThenExpre = ast.newSimpleName("x"); rewrite.replace(condExpression.getThenExpression(), newThenExpre, null); InfixExpression infixExpression = ast.newInfixExpression(); infixExpression.setLeftOperand(ast.newNumberLiteral("1")); infixExpression.setRightOperand(ast.newNumberLiteral("2")); infixExpression.setOperator(InfixExpression.Operator.PLUS); rewrite.replace(condExpression.getElseExpression(), infixExpression, null); } String preview = evaluateRewrite(cu, rewrite); buf = new StringBuffer(); buf.append(" function foo() {\n"); buf.append(" i= true ? x : 1 + 2;\n"); buf.append(" }\n"); assertEqualString(preview, buf.toString()); }
/* (omit javadoc for this method) * Method declared on ASTNode. */ final ASTNode internalGetSetChildProperty( ChildPropertyDescriptor property, boolean get, ASTNode child) { if (property == LEFT_OPERAND_PROPERTY) { if (get) { return getLeftOperand(); } else { setLeftOperand((Expression) child); return null; } } if (property == RIGHT_OPERAND_PROPERTY) { if (get) { return getRightOperand(); } else { setRightOperand((Expression) child); return null; } } // allow default implementation to flag the error return super.internalGetSetChildProperty(property, get, child); }