use of org.eclipse.jdt.core.dom.InfixExpression in project che by eclipse.
the class AssociativeInfixExpressionFragment method createCopyTarget.
public Expression createCopyTarget(ASTRewrite rewrite, boolean removeSurroundingParenthesis) throws JavaModelException {
List<Expression> allOperands = findGroupMembersInOrderFor(fGroupRoot);
if (allOperands.size() == fOperands.size()) {
return (Expression) rewrite.createCopyTarget(fGroupRoot);
}
CompilationUnit root = (CompilationUnit) fGroupRoot.getRoot();
ICompilationUnit cu = (ICompilationUnit) root.getJavaElement();
String source = cu.getBuffer().getText(getStartPosition(), getLength());
return (Expression) rewrite.createStringPlaceholder(source, ASTNode.INFIX_EXPRESSION);
// //Todo: see whether we could copy bigger chunks of the original selection
// // (probably only possible from extendedOperands list or from nested InfixExpressions)
// InfixExpression result= rewrite.getAST().newInfixExpression();
// result.setOperator(getOperator());
// Expression first= (Expression) fOperands.get(0);
// Expression second= (Expression) fOperands.get(1);
// result.setLeftOperand((Expression) rewrite.createCopyTarget(first));
// result.setRightOperand((Expression) rewrite.createCopyTarget(second));
// for (int i= 2; i < fOperands.size(); i++) {
// Expression next= (Expression) fOperands.get(i);
// result.extendedOperands().add(rewrite.createCopyTarget(next));
// }
// return result;
}
use of org.eclipse.jdt.core.dom.InfixExpression in project che by eclipse.
the class AssociativeInfixExpressionFragment method createFragmentForFullSubtree.
public static IExpressionFragment createFragmentForFullSubtree(InfixExpression node) {
Assert.isNotNull(node);
if (!isAssociativeInfix(node))
return null;
InfixExpression groupRoot = findGroupRoot(node);
Assert.isTrue(isAGroupRoot(groupRoot));
List<Expression> groupMembers = AssociativeInfixExpressionFragment.findGroupMembersInOrderFor(node);
return new AssociativeInfixExpressionFragment(groupRoot, groupMembers);
}
use of org.eclipse.jdt.core.dom.InfixExpression in project Main by SpartanRefactoring.
the class MultiplicationToCast method replacement.
@Override
public ASTNode replacement(final InfixExpression x) {
if (x.getOperator() != Operator.TIMES)
return null;
int i = 0;
boolean found = false;
final CastExpression $ = x.getAST().newCastExpression();
for (final Expression e : extract.allOperands(x)) {
if (iz.hexaDecimal(e))
continue;
if (iz.literal(e, 1.)) {
$.setType(x.getAST().newPrimitiveType(PrimitiveType.DOUBLE));
found = true;
}
if (iz.literal(e, 1L)) {
$.setType(x.getAST().newPrimitiveType(PrimitiveType.LONG));
found = true;
}
if (found) {
if (x.hasExtendedOperands()) {
final List<Expression> xs = extract.allOperands(x);
xs.remove(i);
$.setExpression(subject.operands(xs).to(x.getOperator()));
} else {
if (i == 0) {
$.setExpression(copy.of(x.getRightOperand()));
return $;
}
$.setExpression(copy.of(x.getLeftOperand()));
}
return $;
}
++i;
}
return null;
}
use of org.eclipse.jdt.core.dom.InfixExpression in project Main by SpartanRefactoring.
the class $EvaluateInfixExpression method replacement.
@Override
public final ASTNode replacement(final InfixExpression x) {
try {
if (iz.validForEvaluation(x)) {
final String $ = opportunisticReplacement(x);
if ($ != null && $.length() < (x + "").length())
return x.getAST().newNumberLiteral($);
}
if (indexForLeftEvaluation(x) > 1) {
final int index = indexForLeftEvaluation(x);
final InfixExpression cuttedExpression = subject.operands(extract.allOperands(x).subList(0, index)).to(operator());
final List<Expression> afterExpressionOperands = extract.allOperands(x).subList(index, extract.allOperands(x).size());
if (iz.validForEvaluation(cuttedExpression)) {
final String str = opportunisticReplacement(cuttedExpression);
if (str != null)
return subject.pair(az.expression(x.getAST().newNumberLiteral(str)), afterExpressionOperands.size() == 1 ? the.firstOf(afterExpressionOperands) : subject.operands(afterExpressionOperands).to(operator())).to(operator());
}
}
if (indexForRightEvaluation(x) > 1 && operator() != DIVIDE && operator() != REMAINDER) {
final int index = indexForRightEvaluation(x);
final InfixExpression cuttedExpression = subject.operands(extract.allOperands(x).subList(extract.allOperands(x).size() - index, extract.allOperands(x).size())).to(operator());
final List<Expression> beforeExpressionOperands = extract.allOperands(x).subList(0, extract.allOperands(x).size() - index);
if (iz.validForEvaluation(cuttedExpression)) {
final String s = opportunisticReplacement(cuttedExpression);
if (s != null)
return subject.pair(beforeExpressionOperands.size() == 1 ? the.firstOf(beforeExpressionOperands) : subject.operands(beforeExpressionOperands).to(operator()), az.expression(x.getAST().newNumberLiteral(s))).to(operator());
}
}
} catch (@SuppressWarnings("unused") final IllegalArgumentException __) {
// /* Logging Java code */ monitor.logEvaluationError(this,e);
return null;
}
return null;
}
use of org.eclipse.jdt.core.dom.InfixExpression in project Main by SpartanRefactoring.
the class InfixComparisonSizeToZero method replacement.
@Override
public ASTNode replacement(final InfixExpression x) {
final Operator $ = x.getOperator();
if (!iz.comparison($))
return null;
final Expression right = right(x), left = left(x);
return !validTypes(right, left) ? null : iz.methodInvocation(left) ? replacement($, az.methodInvocation(left), right) : replacement(op.conjugate($), az.methodInvocation(right), left);
}
Aggregations