Example usage for org.eclipse.jdt.core.dom Assignment getRightHandSide

List of usage examples for org.eclipse.jdt.core.dom Assignment getRightHandSide

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom Assignment getRightHandSide.

Prototype

public Expression getRightHandSide() 

Source Link

Document

Returns the right hand side of this assignment expression.

Usage

From source file:at.bestsolution.fxide.jdt.corext.dom.ASTFlattener.java

License:Open Source License

@Override
public boolean visit(Assignment node) {
    node.getLeftHandSide().accept(this);
    this.fBuffer.append(node.getOperator().toString());
    node.getRightHandSide().accept(this);
    return false;
}

From source file:boa.datagen.util.Java7Visitor.java

License:Apache License

@Override
public boolean visit(Assignment node) {
    boa.types.Ast.Expression.Builder b = boa.types.Ast.Expression.newBuilder();
    //      b.setPosition(pos.build());
    node.getLeftHandSide().accept(this);
    b.addExpressions(expressions.pop());
    node.getRightHandSide().accept(this);
    b.addExpressions(expressions.pop());
    if (node.getOperator() == Assignment.Operator.ASSIGN)
        b.setKind(boa.types.Ast.Expression.ExpressionKind.ASSIGN);
    else if (node.getOperator() == Assignment.Operator.BIT_AND_ASSIGN)
        b.setKind(boa.types.Ast.Expression.ExpressionKind.ASSIGN_BITAND);
    else if (node.getOperator() == Assignment.Operator.BIT_OR_ASSIGN)
        b.setKind(boa.types.Ast.Expression.ExpressionKind.ASSIGN_BITOR);
    else if (node.getOperator() == Assignment.Operator.BIT_XOR_ASSIGN)
        b.setKind(boa.types.Ast.Expression.ExpressionKind.ASSIGN_BITXOR);
    else if (node.getOperator() == Assignment.Operator.DIVIDE_ASSIGN)
        b.setKind(boa.types.Ast.Expression.ExpressionKind.ASSIGN_DIV);
    else if (node.getOperator() == Assignment.Operator.LEFT_SHIFT_ASSIGN)
        b.setKind(boa.types.Ast.Expression.ExpressionKind.ASSIGN_LSHIFT);
    else if (node.getOperator() == Assignment.Operator.MINUS_ASSIGN)
        b.setKind(boa.types.Ast.Expression.ExpressionKind.ASSIGN_SUB);
    else if (node.getOperator() == Assignment.Operator.PLUS_ASSIGN)
        b.setKind(boa.types.Ast.Expression.ExpressionKind.ASSIGN_ADD);
    else if (node.getOperator() == Assignment.Operator.REMAINDER_ASSIGN)
        b.setKind(boa.types.Ast.Expression.ExpressionKind.ASSIGN_MOD);
    else if (node.getOperator() == Assignment.Operator.RIGHT_SHIFT_SIGNED_ASSIGN)
        b.setKind(boa.types.Ast.Expression.ExpressionKind.ASSIGN_RSHIFT);
    else if (node.getOperator() == Assignment.Operator.RIGHT_SHIFT_UNSIGNED_ASSIGN)
        b.setKind(boa.types.Ast.Expression.ExpressionKind.ASSIGN_UNSIGNEDRSHIFT);
    else if (node.getOperator() == Assignment.Operator.TIMES_ASSIGN)
        b.setKind(boa.types.Ast.Expression.ExpressionKind.ASSIGN_MULT);
    expressions.push(b.build());/* ww w. j  a v a 2  s . c  o m*/
    return false;
}

From source file:ca.mcgill.cs.swevo.ppa.inference.AssignInferenceStrategy.java

License:Open Source License

private boolean isRightSafe(ASTNode node) {
    boolean rightSafe = true;
    Assignment assign = (Assignment) node;
    Expression right = assign.getRightHandSide();
    if (indexer.isIndexable(right)) {
        rightSafe = indexer.isSafe(right);
    }/*w w w .  j a v  a 2  s  .  com*/
    return rightSafe;
}

From source file:ca.mcgill.cs.swevo.ppa.inference.AssignInferenceStrategy.java

License:Open Source License

public void inferTypes(ASTNode node) {
    Assignment assign = (Assignment) node;
    Expression left = assign.getLeftHandSide();
    Expression right = assign.getRightHandSide();
    ITypeBinding leftBinding = PPABindingsUtil.getTypeBinding(left);
    ITypeBinding rightBinding = PPABindingsUtil.getTypeBinding(right);

    boolean isLeftSafe = isLeftSafe(node);
    boolean isRightSafe = isRightSafe(node);
    int leftValue = PPABindingsUtil.getSafetyValue(leftBinding);
    int rightValue = PPABindingsUtil.getSafetyValue(rightBinding);

    if ((isLeftSafe && isRightSafe) || (leftValue == rightValue)) {
        return;// ww  w  .j  av a2 s.co m
    } else if (!isRightSafe && leftValue > rightValue) {
        TypeFact tFact = new TypeFact(indexer.getMainIndex(right), rightBinding, TypeFact.UNKNOWN, leftBinding,
                TypeFact.SUBTYPE, TypeFact.ASSIGN_STRATEGY);
        ppaEngine.reportTypeFact(tFact);
    } else if (!isLeftSafe && rightValue > leftValue) {
        TypeFact tFact = new TypeFact(indexer.getMainIndex(left), leftBinding, TypeFact.UNKNOWN, rightBinding,
                TypeFact.SUPERTYPE, TypeFact.ASSIGN_STRATEGY);
        ppaEngine.reportTypeFact(tFact);
    }
}

From source file:ca.mcgill.cs.swevo.ppa.inference.AssignInferenceStrategy.java

License:Open Source License

public boolean isSafe(ASTNode node) {
    Assignment assign = (Assignment) node;
    boolean leftSafe = true;
    boolean rightSafe = true;

    Expression left = assign.getLeftHandSide();
    Expression right = assign.getRightHandSide();

    leftSafe = indexer.isSafe(left);/* w w w.ja  v a2 s .  co m*/

    rightSafe = indexer.isSafe(right);

    return leftSafe && rightSafe;
}

From source file:ca.mcgill.cs.swevo.ppa.inference.AssignInferenceStrategy.java

License:Open Source License

public List<PPAIndex> getSecondaryIndexes(ASTNode node) {
    Assignment assign = (Assignment) node;
    List<PPAIndex> indexes = new ArrayList<PPAIndex>();

    Expression left = assign.getLeftHandSide();
    Expression right = assign.getRightHandSide();

    if (indexer.isIndexable(left)) {
        PPAIndex tempIndex = indexer.getMainIndex(left);
        indexes.add(tempIndex);//w w w .  j  a  v a 2s  .  c  o m
    }

    if (indexer.isIndexable(right)) {
        PPAIndex tempIndex = indexer.getMainIndex(right);
        indexes.add(tempIndex);
    }

    return indexes;
}

From source file:ch.acanda.eclipse.pmd.java.resolution.design.SingularFieldQuickFix.java

License:Open Source License

/**
 * Replaces the assignment with a variable declaration. If the assignment is the only one in the block for this
 * variable, the final modifier is added to the declaration.
 *//*from  w  ww  .j av  a2s.  c  o  m*/
@SuppressWarnings("unchecked")
private void replaceAssignment(final VariableDeclarationFragment node, final Assignment assignment,
        final boolean finalDeclaration) {
    final FieldDeclaration fieldDeclaration = (FieldDeclaration) node.getParent();
    final VariableDeclarationStatement declaration = (VariableDeclarationStatement) node.getAST()
            .createInstance(VariableDeclarationStatement.class);
    declaration.setType(ASTUtil.copy(fieldDeclaration.getType()));
    final VariableDeclarationFragment fragment = (VariableDeclarationFragment) node.getAST()
            .createInstance(VariableDeclarationFragment.class);
    fragment.setName(ASTUtil.copy(node.getName()));
    fragment.setInitializer(ASTUtil.copy(assignment.getRightHandSide()));
    declaration.fragments().add(fragment);
    if (finalDeclaration) {
        final Modifier modifier = (Modifier) node.getAST().createInstance(Modifier.class);
        modifier.setKeyword(ModifierKeyword.FINAL_KEYWORD);
        declaration.modifiers().add(modifier);
    }
    ASTUtil.replace(assignment.getParent(), declaration);
}

From source file:coloredide.utils.CopiedNaiveASTFlattener.java

License:Open Source License

public boolean visit(Assignment node) {
    node.getLeftHandSide().accept(this);
    this.buffer.append(node.getOperator().toString());
    node.getRightHandSide().accept(this);
    return false;
}

From source file:com.bsiag.eclipse.jdt.java.formatter.linewrap.WrapPreparator.java

License:Open Source License

@Override
public boolean visit(Assignment node) {
    this.wrapIndexes.add(this.tm.firstIndexIn(node.getRightHandSide(), -1));

    int operatorIndex = this.tm.firstIndexBefore(node.getRightHandSide(), -1);
    while (this.tm.get(operatorIndex).isComment())
        operatorIndex--;//from  w w w  . ja va2 s .  com
    assert node.getOperator().toString().equals(this.tm.toString(operatorIndex));

    this.wrapParentIndex = operatorIndex;
    this.wrapGroupEnd = this.tm.lastIndexIn(node.getRightHandSide(), -1);
    handleWrap(this.options.alignment_for_assignment);
    return true;
}

From source file:com.bsiag.eclipse.jdt.java.formatter.SpacePreparator.java

License:Open Source License

@Override
public boolean visit(Assignment node) {
    handleOperator(node.getOperator().toString(), node.getRightHandSide(),
            this.options.insert_space_before_assignment_operator,
            this.options.insert_space_after_assignment_operator);
    return true;//  w  w w. ja  v a2s  . c  o  m
}