Search in sources :

Example 11 with NumberLiteral

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;
}
Also used : NumberLiteral(org.eclipse.jdt.core.dom.NumberLiteral)

Example 12 with NumberLiteral

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;
}
Also used : InstanceofExpression(org.eclipse.jdt.core.dom.InstanceofExpression) ThisExpression(org.eclipse.jdt.core.dom.ThisExpression) Expression(org.eclipse.jdt.core.dom.Expression) CastExpression(org.eclipse.jdt.core.dom.CastExpression) VariableDeclarationExpression(org.eclipse.jdt.core.dom.VariableDeclarationExpression) PostfixExpression(org.eclipse.jdt.core.dom.PostfixExpression) PrefixExpression(org.eclipse.jdt.core.dom.PrefixExpression) ConditionalExpression(org.eclipse.jdt.core.dom.ConditionalExpression) InfixExpression(org.eclipse.jdt.core.dom.InfixExpression) ParenthesizedExpression(org.eclipse.jdt.core.dom.ParenthesizedExpression) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) NumberLiteral(org.eclipse.jdt.core.dom.NumberLiteral)

Example 13 with NumberLiteral

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;
}
Also used : Expression(org.eclipse.jdt.core.dom.Expression) ParenthesizedExpression(org.eclipse.jdt.core.dom.ParenthesizedExpression) InfixExpression(org.eclipse.jdt.core.dom.InfixExpression) PrefixExpression(org.eclipse.jdt.core.dom.PrefixExpression) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) PrefixExpression(org.eclipse.jdt.core.dom.PrefixExpression) NumberLiteral(org.eclipse.jdt.core.dom.NumberLiteral) Name(org.eclipse.jdt.core.dom.Name)

Aggregations

NumberLiteral (org.eclipse.jdt.core.dom.NumberLiteral)13 InfixExpression (org.eclipse.jdt.core.dom.InfixExpression)5 Expression (org.eclipse.jdt.core.dom.Expression)4 Name (org.eclipse.jdt.core.dom.Name)4 PrefixExpression (org.eclipse.jdt.core.dom.PrefixExpression)4 ASTBuilder (org.autorefactor.refactoring.ASTBuilder)3 CastExpression (org.eclipse.jdt.core.dom.CastExpression)3 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)3 IVariableBinding (org.eclipse.jdt.core.dom.IVariableBinding)3 ParenthesizedExpression (org.eclipse.jdt.core.dom.ParenthesizedExpression)3 VariableDeclarationExpression (org.eclipse.jdt.core.dom.VariableDeclarationExpression)3 FieldAccess (org.eclipse.jdt.core.dom.FieldAccess)2 IBinding (org.eclipse.jdt.core.dom.IBinding)2 MethodInvocation (org.eclipse.jdt.core.dom.MethodInvocation)2 PostfixExpression (org.eclipse.jdt.core.dom.PostfixExpression)2 StringLiteral (org.eclipse.jdt.core.dom.StringLiteral)2 SuperMethodInvocation (org.eclipse.jdt.core.dom.SuperMethodInvocation)2 ThisExpression (org.eclipse.jdt.core.dom.ThisExpression)2 ArrayList (java.util.ArrayList)1 ASTVisitor (org.eclipse.jdt.core.dom.ASTVisitor)1