use of org.eclipse.jdt.core.dom.NumberLiteral in project che by eclipse.
the class ConvertForLoopOperation method getIndexBindingFromFragment.
/*
* Must be one of:
* <ul>
* <li>[result]= 0</li>
* </ul>
*/
private IVariableBinding getIndexBindingFromFragment(VariableDeclarationFragment fragment) {
Expression initializer = fragment.getInitializer();
if (!(initializer instanceof NumberLiteral))
return null;
NumberLiteral number = (NumberLiteral) initializer;
if (!LITERAL_0.equals(number.getToken()))
return null;
return (IVariableBinding) fragment.getName().resolveBinding();
}
use of org.eclipse.jdt.core.dom.NumberLiteral in project AutoRefactor by JnRouvignac.
the class BigDecimalRefactoring method visit.
@Override
public boolean visit(MethodInvocation node) {
if (node.getExpression() == null) {
return VISIT_SUBTREE;
}
if (getJavaMinorVersion() >= 5 && (isMethod(node, "java.math.BigDecimal", "valueOf", "long") || isMethod(node, "java.math.BigDecimal", "valueOf", "double"))) {
final ITypeBinding typeBinding = node.getExpression().resolveTypeBinding();
final Expression arg0 = arg0(node);
if (arg0 instanceof NumberLiteral) {
final NumberLiteral nb = (NumberLiteral) arg0;
if (nb.getToken().contains(".")) {
this.ctx.getRefactorings().replace(node, getClassInstanceCreatorNode((Name) node.getExpression(), nb.getToken()));
} else if (ZERO_LONG_LITERAL_RE.matcher(nb.getToken()).matches()) {
replaceWithQualifiedName(node, typeBinding, "ZERO");
} else if (ONE_LONG_LITERAL_RE.matcher(nb.getToken()).matches()) {
replaceWithQualifiedName(node, typeBinding, "ONE");
} else if (TEN_LONG_LITERAL_RE.matcher(nb.getToken()).matches()) {
replaceWithQualifiedName(node, typeBinding, "TEN");
} else {
return VISIT_SUBTREE;
}
return DO_NOT_VISIT_SUBTREE;
}
} else if (!(node.getParent() instanceof PrefixExpression) || !hasOperator((PrefixExpression) node.getParent(), NOT)) {
return maybeReplaceEquals(true, node, node);
}
return VISIT_SUBTREE;
}
use of org.eclipse.jdt.core.dom.NumberLiteral in project processing by processing.
the class SourceUtils method preprocessAST.
public static List<Edit> preprocessAST(CompilationUnit cu) {
final List<Edit> edits = new ArrayList<>();
// Walk the tree
cu.accept(new ASTVisitor() {
@Override
public boolean visit(SimpleType node) {
// replace "color" with "int"
if ("color".equals(node.getName().toString())) {
edits.add(Edit.replace(node.getStartPosition(), node.getLength(), "int"));
}
return super.visit(node);
}
@Override
public boolean visit(NumberLiteral node) {
// add 'f' to floats
String s = node.getToken().toLowerCase();
if (FLOATING_POINT_LITERAL_VERIFIER.matcher(s).matches() && !s.endsWith("f") && !s.endsWith("d")) {
edits.add(Edit.insert(node.getStartPosition() + node.getLength(), "f"));
}
return super.visit(node);
}
@Override
public boolean visit(MethodDeclaration node) {
// add 'public' to methods with default visibility
int accessModifiers = node.getModifiers() & ACCESS_MODIFIERS_MASK;
if (accessModifiers == 0) {
edits.add(Edit.insert(node.getStartPosition(), "public "));
}
return super.visit(node);
}
});
return edits;
}
use of org.eclipse.jdt.core.dom.NumberLiteral in project AutoRefactor by JnRouvignac.
the class RemoveUnnecessaryCastRefactoring method visit.
@Override
public boolean visit(CastExpression node) {
final NumberLiteral literal = as(node.getExpression(), NumberLiteral.class);
if (literal != null && (literal.getToken().matches(".*[^lLdDfF]") || literal.getToken().matches("0x.*[^lL]"))) {
if (hasType(node.getType().resolveBinding(), "long")) {
createPrimitive(node, literal, 'L');
return DO_NOT_VISIT_SUBTREE;
}
if (hasType(node.getType().resolveBinding(), "float")) {
createPrimitive(node, literal, 'f');
return DO_NOT_VISIT_SUBTREE;
}
if (hasType(node.getType().resolveBinding(), "double")) {
createPrimitive(node, literal, 'd');
return DO_NOT_VISIT_SUBTREE;
}
}
if (canRemoveCast(node)) {
final ASTBuilder b = ctx.getASTBuilder();
ctx.getRefactorings().replace(node, b.move(node.getExpression()));
return DO_NOT_VISIT_SUBTREE;
}
return VISIT_SUBTREE;
}
use of org.eclipse.jdt.core.dom.NumberLiteral in project AutoRefactor by JnRouvignac.
the class RemoveUnnecessaryCastRefactoring method createPrimitive.
private void createPrimitive(final CastExpression node, final NumberLiteral literal, final char postfix) {
final ASTBuilder b = this.ctx.getASTBuilder();
final NumberLiteral numberLiteral = b.numberLiteral();
numberLiteral.setToken(literal.getToken() + postfix);
ctx.getRefactorings().replace(node, numberLiteral);
}
Aggregations