use of org.eclipse.jdt.core.dom.NumberLiteral in project AutoRefactor by JnRouvignac.
the class CapitalizeLongLiteralRefactoring method visit.
@Override
public boolean visit(NumberLiteral node) {
String token = node.getToken();
if (token.endsWith("l")) {
NumberLiteral replacement = ctx.getAST().newNumberLiteral();
String newToken = token.substring(0, token.length() - 1) + "L";
replacement.setToken(newToken);
ctx.getRefactorings().replace(node, replacement);
return DO_NOT_VISIT_SUBTREE;
}
return VISIT_SUBTREE;
}
use of org.eclipse.jdt.core.dom.NumberLiteral in project xtext-xtend by eclipse.
the class JavaASTFlattener method visit.
@Override
public boolean visit(final ArrayAccess node) {
Expression _index = node.getIndex();
if ((_index instanceof NumberLiteral)) {
node.getArray().accept(this);
this.appendToBuffer(".get(");
node.getIndex().accept(this);
this.appendToBuffer(")");
} else {
final String arrayname = this.computeArrayName(node);
StringConcatenation _builder = new StringConcatenation();
_builder.append("{val _rdIndx_");
_builder.append(arrayname);
_builder.append("=");
this.appendToBuffer(_builder.toString());
node.getIndex().accept(this);
this.appendSpaceToBuffer();
node.getArray().accept(this);
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append(".get(_rdIndx_");
_builder_1.append(arrayname);
_builder_1.append(")}");
this.appendToBuffer(_builder_1.toString());
}
return false;
}
use of org.eclipse.jdt.core.dom.NumberLiteral in project AutoRefactor by JnRouvignac.
the class BigNumberRefactoring method visit.
@Override
public boolean visit(MethodInvocation node) {
if (node.getExpression() == null) {
return VISIT_SUBTREE;
}
if (getJavaMinorVersion() >= 5 && (isMethod(node, "java.math.BigInteger", "valueOf", "long") || 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 String token = ((NumberLiteral) arg0).getToken().replaceFirst("[lLfFdD]$", "");
if (token.contains(".") && hasType(typeBinding, "java.math.BigDecimal")) {
this.ctx.getRefactorings().replace(node, getClassInstanceCreatorNode((Name) node.getExpression(), token));
} else if (ZERO_LONG_LITERAL_RE.matcher(token).matches()) {
replaceWithQualifiedName(node, typeBinding, "ZERO");
} else if (ONE_LONG_LITERAL_RE.matcher(token).matches()) {
replaceWithQualifiedName(node, typeBinding, "ONE");
} else if (TEN_LONG_LITERAL_RE.matcher(token).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;
}
Aggregations