use of org.eclipse.jdt.core.dom.Assignment in project xtext-xtend by eclipse.
the class JavaASTFlattener method visit.
@Override
public boolean visit(final PrefixExpression node) {
final Expression operand = node.getOperand();
PrefixExpression.Operator _operator = node.getOperator();
boolean _matched = false;
if (Objects.equal(_operator, PrefixExpression.Operator.DECREMENT)) {
_matched = true;
}
if (!_matched) {
if (Objects.equal(_operator, PrefixExpression.Operator.INCREMENT)) {
_matched = true;
}
}
if (_matched) {
if ((operand instanceof ArrayAccess)) {
final String arrayName = this.computeArrayName(((ArrayAccess) operand));
StringConcatenation _builder = new StringConcatenation();
_builder.append("_tPreInx_");
_builder.append(arrayName);
final String idxName = _builder.toString();
String op = "-";
PrefixExpression.Operator _operator_1 = node.getOperator();
boolean _equals = Objects.equal(_operator_1, PrefixExpression.Operator.INCREMENT);
if (_equals) {
op = "+";
}
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("{val ");
_builder_1.append(idxName);
_builder_1.append("=");
this.appendToBuffer(_builder_1.toString());
((ArrayAccess) operand).getIndex().accept(this);
StringConcatenation _builder_2 = new StringConcatenation();
_builder_2.append(" ");
_builder_2.append("val ");
_builder_2.append(idxName, " ");
_builder_2.append("_res=");
_builder_2.append(arrayName, " ");
_builder_2.append(".get(");
_builder_2.append(idxName, " ");
_builder_2.append(")");
_builder_2.append(op, " ");
_builder_2.append("1");
this.appendToBuffer(_builder_2.toString());
StringConcatenation _builder_3 = new StringConcatenation();
_builder_3.append(" ");
_builder_3.append(arrayName, " ");
_builder_3.append(".set(");
_builder_3.append(idxName, " ");
_builder_3.append(", ");
_builder_3.append(idxName, " ");
_builder_3.append("_res) ");
_builder_3.append(idxName, " ");
_builder_3.append("_res}");
this.appendToBuffer(_builder_3.toString());
return false;
} else {
final AST dummyAST = AST.newAST(node.getAST().apiLevel());
final Assignment assigment = dummyAST.newAssignment();
final InfixExpression infixOp = dummyAST.newInfixExpression();
ASTNode _copySubtree = ASTNode.copySubtree(dummyAST, operand);
infixOp.setLeftOperand(((Expression) _copySubtree));
PrefixExpression.Operator _operator_2 = node.getOperator();
boolean _equals_1 = Objects.equal(_operator_2, PrefixExpression.Operator.DECREMENT);
if (_equals_1) {
infixOp.setOperator(InfixExpression.Operator.MINUS);
} else {
infixOp.setOperator(InfixExpression.Operator.PLUS);
}
infixOp.setRightOperand(dummyAST.newNumberLiteral("1"));
ASTNode _copySubtree_1 = ASTNode.copySubtree(dummyAST, operand);
final Expression leftSide = ((Expression) _copySubtree_1);
assigment.setLeftHandSide(leftSide);
assigment.setRightHandSide(infixOp);
this.appendToBuffer("{");
Type type = null;
if ((operand instanceof SimpleName)) {
type = this._aSTFlattenerUtils.findDeclaredType(((SimpleName) operand));
}
this.handleAssignment(assigment, leftSide, type);
this.appendToBuffer("}");
return false;
}
}
if (!_matched) {
if (Objects.equal(_operator, PrefixExpression.Operator.COMPLEMENT)) {
_matched = true;
node.getOperand().accept(this);
this.appendToBuffer(".bitwiseNot");
}
}
if (!_matched) {
{
this.appendToBuffer(node.getOperator().toString());
node.getOperand().accept(this);
}
}
return false;
}
use of org.eclipse.jdt.core.dom.Assignment in project AutoRefactor by JnRouvignac.
the class HotSpotIntrinsicedAPIsRefactoring method visit.
@Override
public boolean visit(ForStatement node) {
final SystemArrayCopyParams params = new SystemArrayCopyParams();
collectUniqueIndex(node, params);
final IVariableBinding incrementedIdx = getUniqueIncrementedVariable(node);
final List<Statement> stmts = asList(node.getBody());
if (equalNotNull(params.indexVarBinding, incrementedIdx) && stmts.size() == 1) {
collectLength(node.getExpression(), incrementedIdx, params);
final Assignment as = asExpression(stmts.get(0), Assignment.class);
if (hasOperator(as, ASSIGN)) {
final Expression lhs = as.getLeftHandSide();
final Expression rhs = as.getRightHandSide();
if (lhs instanceof ArrayAccess && rhs instanceof ArrayAccess) {
final ArrayAccess aaLHS = (ArrayAccess) lhs;
final ArrayAccess aaRHS = (ArrayAccess) rhs;
params.destArrayExpr = aaLHS.getArray();
params.srcArrayExpr = aaRHS.getArray();
if (haveSameType(params.srcArrayExpr, params.destArrayExpr)) {
params.destPos = calcIndex(aaLHS.getIndex(), params);
params.srcPos = calcIndex(aaRHS.getIndex(), params);
return replaceWithSystemArrayCopyCloneAll(node, params);
}
}
}
}
return VISIT_SUBTREE;
}
use of org.eclipse.jdt.core.dom.Assignment in project AutoRefactor by JnRouvignac.
the class ReduceVariableScopeRefactoring method copy.
private Block copy(Statement stmtToCopy, Name varName) {
if (stmtToCopy != null && !(stmtToCopy instanceof Block)) {
final Block b = this.ctx.getAST().newBlock();
final Assignment a = asExpression(stmtToCopy, Assignment.class);
if (a != null) {
final VariableDeclarationFragment vdf = getVariableDeclarationFragment(a, varName);
statements(b).add(this.ctx.getAST().newVariableDeclarationStatement(vdf));
} else {
throw new NotImplementedException(stmtToCopy);
}
return b;
}
// We should never come here if we had a Block statement, see the replace() method
throw new NotImplementedException(stmtToCopy);
}
use of org.eclipse.jdt.core.dom.Assignment in project AutoRefactor by JnRouvignac.
the class BooleanRefactoring method noThenReturnStmt.
private boolean noThenReturnStmt(final IfStatement node) {
final Assignment thenA = asExpression(node.getThenStatement(), Assignment.class);
if (hasOperator(thenA, ASSIGN) && asList(node.getElseStatement()).isEmpty() && (thenA.getLeftHandSide() instanceof Name || thenA.getLeftHandSide() instanceof FieldAccess)) {
final Statement previousSibling = getPreviousSibling(node);
if (previousSibling instanceof VariableDeclarationStatement) {
final VariableDeclarationStatement vds = (VariableDeclarationStatement) previousSibling;
VariableDeclarationFragment vdf = getVariableDeclarationFragment(vds, thenA.getLeftHandSide());
if (vdf != null) {
final VariableDefinitionsUsesVisitor variableUseVisitor = new VariableDefinitionsUsesVisitor(vdf.resolveBinding(), node.getExpression()).find();
if (variableUseVisitor.getUses().isEmpty()) {
final ITypeBinding typeBinding = vds.getType().resolveBinding();
return maybeReplace(node, thenA, typeBinding, vdf.getInitializer());
}
}
} else if (previousSibling instanceof ExpressionStatement) {
final Assignment elseA = asExpression(previousSibling, Assignment.class);
if (hasOperator(elseA, ASSIGN) && isSameVariable(thenA.getLeftHandSide(), elseA.getLeftHandSide())) {
final ITypeBinding typeBinding = elseA.resolveTypeBinding();
return maybeReplace(node, thenA, typeBinding, elseA.getRightHandSide());
}
}
}
return VISIT_SUBTREE;
}
use of org.eclipse.jdt.core.dom.Assignment in project AutoRefactor by JnRouvignac.
the class ForLoopHelper method decomposeInitializer.
/**
* Decomposes an initializer into a {@link Pair} with the name of the initialized variable
* and the initializing expression.
*
* @param init
* the initializer to decompose
* @return a {@link Pair} with the name of the initialized variable and the initializing
* expression, or {@code null} if the initializer could not be decomposed
*/
public static Pair<Name, Expression> decomposeInitializer(Expression init) {
if (init instanceof VariableDeclarationExpression) {
final VariableDeclarationExpression vde = (VariableDeclarationExpression) init;
final List<VariableDeclarationFragment> fragments = fragments(vde);
if (fragments.size() == 1) {
final VariableDeclarationFragment fragment = fragments.get(0);
return Pair.of((Name) fragment.getName(), fragment.getInitializer());
}
} else if (init instanceof Assignment) {
final Assignment as = (Assignment) init;
if (hasOperator(as, ASSIGN) && as.getLeftHandSide() instanceof Name) {
return Pair.of((Name) as.getLeftHandSide(), as.getRightHandSide());
}
}
return Pair.empty();
}
Aggregations