Package org.eclipse.jdt.core.dom

Examples of org.eclipse.jdt.core.dom.Assignment


     *
     * @param expr
     * @param name
     */
    public void addAssignToName(Expression expr, String name) {
        Assignment asgn = m_ast.newAssignment();
        asgn.setLeftHandSide(m_ast.newSimpleName(name));
        asgn.setRightHandSide(expr);
        m_block.statements().add(m_ast.newExpressionStatement(asgn));
    }
View Full Code Here


     *
     * @param vname
     * @param fname
     */
    public void addAssignVariableToField(String vname, String fname) {
        Assignment asgn = m_ast.newAssignment();
        if (fname.equals(vname)) {
            FieldAccess access = m_ast.newFieldAccess();
            access.setExpression(m_ast.newThisExpression());
            access.setName(m_ast.newSimpleName(fname));
            asgn.setLeftHandSide(access);
        } else {
            asgn.setLeftHandSide(m_ast.newSimpleName(fname));
        }
        asgn.setRightHandSide(m_ast.newSimpleName(vname));
        m_block.statements().add(m_ast.newExpressionStatement(asgn));
    }
View Full Code Here

      return null;
  }

  private boolean isLoad(Expression node) {
    if(node.getParent() instanceof Assignment) {
      Assignment parent = (Assignment) node.getParent();
      if(parent.getLeftHandSide() != node)
        return true;
      // node is on the left
      // it's still a load if this is += or something like that.
      return Assignment.Operator.ASSIGN.equals(parent.getOperator()) == false;
    }
    else if((node.getParent() instanceof VariableDeclaration) &&
        (((VariableDeclaration) node.getParent()).getName() == node))
      // node is the name of a declaration --> not a load but a store
      return false;
View Full Code Here

  @Test
  public void testFieldWrite() throws Exception {
    CompilationUnit cu = EclipseTACSimpleTestDriver.parseCode("FieldWrite", FIELD_WRITE);
    MethodDeclaration m = EclipseTACSimpleTestDriver.getFirstMethod(cu);
    EclipseTAC tac = new EclipseTAC(m.resolveBinding());
    Assignment write = (Assignment) EclipseTACSimpleTestDriver.getLastStatementReturn(m).getExpression();
    TACInstruction instr = tac.instruction(write);
    Assert.assertTrue(instr != null);
    Assert.assertTrue(instr instanceof StoreFieldInstruction);
   
    StoreFieldInstruction store = (StoreFieldInstruction) instr;
    Assert.assertTrue(store.getDestinationObject() instanceof ThisVariable);
    Assert.assertTrue(store.getDestinationObject().isUnqualifiedThis());
    Assert.assertEquals(
        tac.sourceVariable(((SingleVariableDeclaration) m.parameters().get(0)).resolveBinding()),
        store.getSourceOperand());
    Assert.assertEquals("f", store.getFieldName());
   
    Assert.assertEquals(tac.variable(write.getRightHandSide()), store.getSourceOperand());
   
    // Make sure there's no FieldLoad generated for the assigned-to field
    Assert.assertNull(tac.instruction(write.getLeftHandSide()));
  }
View Full Code Here

   
    List<Variable> args = call.getArgOperands();
    EclipseTACSimpleTestDriver.assertOperands(inv.arguments(), args, tac);
    Assert.assertEquals(1, args.size());
   
    Assignment write = (Assignment) inv.arguments().get(0);
    instr = tac.instruction(write);
    Assert.assertTrue(instr != null);
    Assert.assertTrue(instr instanceof StoreFieldInstruction);
    StoreFieldInstruction store = (StoreFieldInstruction) instr;
   
    Assert.assertTrue(store.getDestinationObject() instanceof ThisVariable);
    Assert.assertEquals("o", store.getFieldName());
    Assert.assertEquals(tac.variable(write.getRightHandSide()), store.getSourceOperand());
    Assert.assertEquals(tac.variable(write), store.getSourceOperand());
    Assert.assertEquals(args.get(0), store.getSourceOperand());
   
    // Make sure there's no FieldLoad generated for the assigned-to field
    Assert.assertNull(tac.instruction(write.getLeftHandSide()));
  }
View Full Code Here

  @Test
  public void testArrayWrite() throws Exception {
    CompilationUnit cu = EclipseTACSimpleTestDriver.parseCode("ArrayWrite", ARRAY_WRITE);
    MethodDeclaration m = EclipseTACSimpleTestDriver.getFirstMethod(cu);
    EclipseTAC tac = new EclipseTAC(m.resolveBinding());
    Assignment write = (Assignment) ((ExpressionStatement) EclipseTACSimpleTestDriver.getLastStatement(m)).getExpression();
    TACInstruction instr = tac.instruction(write);
    Assert.assertTrue(instr != null);
    Assert.assertTrue(instr instanceof StoreArrayInstruction);
    StoreArrayInstruction store = (StoreArrayInstruction) instr;

    EclipseTACSimpleTestDriver.assertMethodParameter(store.getDestinationArray(), m, 0, tac);
    EclipseTACSimpleTestDriver.assertMethodParameter(store.getArrayIndex(), m, 1, tac);   
   
    Assert.assertEquals(tac.variable(write.getRightHandSide()), store.getSourceOperand());
    EclipseTACSimpleTestDriver.assertMethodParameter(store.getSourceOperand(), m, 2, tac);   
   
    // Make sure there's no ArrayLoad generated for the assigned-to array
    Assert.assertNull("Load generated for array assignment", tac.instruction(write.getLeftHandSide()));
  }
View Full Code Here

   
    List<Variable> args = call.getArgOperands();
    EclipseTACSimpleTestDriver.assertOperands(inv.arguments(), args, tac);
    Assert.assertEquals(1, args.size());
   
    Assignment write = (Assignment) inv.arguments().get(0);
    instr = tac.instruction(write);
    Assert.assertTrue(instr != null);
    Assert.assertTrue(instr instanceof StoreArrayInstruction);
    StoreArrayInstruction store = (StoreArrayInstruction) instr;

    Assert.assertEquals(tac.variable(write.getRightHandSide()), store.getSourceOperand());
    Assert.assertEquals(tac.variable(write), store.getSourceOperand());
    Assert.assertEquals(args.get(0), store.getSourceOperand());
   
    // Make sure there's no ArrayLoad generated for the assigned-to array
    Assert.assertNull("Load generated for array assignment", tac.instruction(write.getLeftHandSide()));
  }
View Full Code Here

    Assert.assertTrue(instr instanceof LoadLiteralInstruction);
   
    LoadLiteralInstruction load = (LoadLiteralInstruction) instr;
    Assert.assertEquals(load.getTarget(), store.getSourceOperand());
   
    Assignment write = (Assignment) ((ExpressionStatement) EclipseTACSimpleTestDriver.getLastStatement(c)).getExpression();
    TACInstruction again = tac.instruction(write);
    Assert.assertNotNull(again);
    Assert.assertTrue(again instanceof StoreFieldInstruction);
    Assert.assertFalse(store.equals(again));
  }
View Full Code Here

        ifStatement.setThenStatement(thenBranch);
        block.statements().add(ifStatement);

        // Finally, assign the new value to the field.
        Assignment assignment = ast.newAssignment();
        assignment
                .setLeftHandSide((Expression) ASTNode.copySubtree(ast, field));
        assignment.setRightHandSide(ast.newSimpleName("newValue"));
        assignment.setOperator(Assignment.Operator.ASSIGN);

        // Set the checkpoint object of the new value, if necessary.
        Class c;

        try {
            c = fieldType.toClass(state.getClassLoader());
        } catch (ClassNotFoundException e) {
            throw new ASTClassNotFoundException(fieldType.getName());
        }

        if (hasMethod(c, _getSetCheckpointMethodName(false),
                new Class[] { Checkpoint.class })
                || state.getCrossAnalyzedTypes().contains(c.getName())) {
            block.statements().add(_createSetCheckpointInvocation(ast));
        } else {
            addToLists(_fixSetCheckpoint, c.getName(), block);
        }

        // Return the result of the assignment.
        if (special && _assignOperators.containsKey(fieldType.getName())) {
            String[] operators = _assignOperators.get(fieldType.getName());

            SwitchStatement switchStatement = ast.newSwitchStatement();
            switchStatement.setExpression(ast.newSimpleName("operator"));

            boolean isPostfix = true;

            for (int i = 0; i < operators.length; i++) {
                String operator = operators[i];

                SwitchCase switchCase = ast.newSwitchCase();
                switchCase.setExpression(ast.newNumberLiteral(Integer
                        .toString(i)));
                switchStatement.statements().add(switchCase);

                ReturnStatement returnStatement = ast.newReturnStatement();

                if (operator.equals("=")) {
                    Assignment newAssignment = (Assignment) ASTNode
                            .copySubtree(ast, assignment);
                    returnStatement.setExpression(newAssignment);
                } else if (operator.equals("++") || operator.equals("--")) {
                    Expression expression;

                    if (isPostfix) {
                        PostfixExpression postfix = ast.newPostfixExpression();
                        postfix.setOperand((Expression) ASTNode.copySubtree(
                                ast, assignment.getLeftHandSide()));
                        postfix.setOperator(PostfixExpression.Operator
                                .toOperator(operator));
                        expression = postfix;

                        // Produce prefix operators next time.
                        if (operator.equals("--")) {
                            isPostfix = false;
                        }
                    } else {
                        PrefixExpression prefix = ast.newPrefixExpression();
                        prefix.setOperand((Expression) ASTNode.copySubtree(ast,
                                assignment.getLeftHandSide()));
                        prefix.setOperator(PrefixExpression.Operator
                                .toOperator(operator));
                        expression = prefix;
                    }

                    returnStatement.setExpression(expression);
                } else {
                    Assignment newAssignment = (Assignment) ASTNode
                            .copySubtree(ast, assignment);
                    newAssignment.setOperator(Assignment.Operator
                            .toOperator(operator));
                    returnStatement.setExpression(newAssignment);
                }

                switchStatement.statements().add(returnStatement);
View Full Code Here

                        castExpression.setType(createType(ast, typeName));
                        castExpression.setExpression(restoreMethodCall);
                        rightHandSide = castExpression;
                    }

                    Assignment assignment = ast.newAssignment();
                    assignment.setLeftHandSide(ast.newSimpleName(fieldName));
                    assignment.setRightHandSide(rightHandSide);
                    body.statements().add(
                            ast.newExpressionStatement(assignment));
                }
            }

            // Add a call to the restore method in the superclass, if necessary.
            SuperMethodInvocation superRestore = ast.newSuperMethodInvocation();
            superRestore.setName(ast
                    .newSimpleName(_getRestoreMethodName(false)));
            superRestore.arguments().add(ast.newSimpleName("timestamp"));
            superRestore.arguments().add(ast.newSimpleName("trim"));

            Statement superRestoreStatement = ast
                    .newExpressionStatement(superRestore);

            if ((parent != null)
                    && (state.getCrossAnalyzedTypes()
                            .contains(parent.getName()) || hasMethod(parent,
                            methodName,
                            new Class[] { int.class, boolean.class }))) {
                body.statements().add(superRestoreStatement);
            } else {
                // Restore the previous checkpoint, if necessary.
                IfStatement restoreCheckpoint = ast.newIfStatement();

                InfixExpression timestampTester = ast.newInfixExpression();
                timestampTester.setLeftOperand(ast.newSimpleName("timestamp"));
                timestampTester
                        .setOperator(InfixExpression.Operator.LESS_EQUALS);

                MethodInvocation topTimestamp = ast.newMethodInvocation();
                topTimestamp.setExpression(ast
                        .newSimpleName(CHECKPOINT_RECORD_NAME));
                topTimestamp.setName(ast.newSimpleName("getTopTimestamp"));
                timestampTester.setRightOperand(topTimestamp);
                restoreCheckpoint.setExpression(timestampTester);

                Block restoreBlock = ast.newBlock();
                restoreCheckpoint.setThenStatement(restoreBlock);

                // Assign the old checkpoint.
                Assignment assignCheckpoint = ast.newAssignment();
                assignCheckpoint.setLeftHandSide(ast
                        .newSimpleName(CHECKPOINT_NAME));

                MethodInvocation restoreCheckpointInvocation = ast
                        .newMethodInvocation();
                restoreCheckpointInvocation.setExpression(ast
                        .newSimpleName(CHECKPOINT_RECORD_NAME));
                restoreCheckpointInvocation.setName(ast
                        .newSimpleName("restore"));
                restoreCheckpointInvocation.arguments().add(
                        ast.newSimpleName(CHECKPOINT_NAME));
                restoreCheckpointInvocation.arguments().add(
                        _createRollbackableObject(ast, isAnonymous));
                restoreCheckpointInvocation.arguments().add(
                        ast.newSimpleName("timestamp"));
                restoreCheckpointInvocation.arguments().add(
                        ast.newSimpleName("trim"));
                assignCheckpoint.setRightHandSide(restoreCheckpointInvocation);
                restoreBlock.statements().add(
                        ast.newExpressionStatement(assignCheckpoint));

                // Pop the old states.
                MethodInvocation popStates = ast.newMethodInvocation();
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.core.dom.Assignment

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.