Example usage for org.eclipse.jdt.core.dom NumberLiteral toString

List of usage examples for org.eclipse.jdt.core.dom NumberLiteral toString

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom NumberLiteral toString.

Prototype

@Override
public final String toString() 

Source Link

Document

Returns a string representation of this node suitable for debugging purposes only.

Usage

From source file:org.ebayopensource.dsf.javatojs.translate.LiteralTranslator.java

License:Open Source License

SimpleLiteral toJstLiteral(final NumberLiteral astExpr, final BaseJstNode jstNode) {

    // TODO/* w  ww.  j a  va2 s .  c o  m*/
    String literal = astExpr.toString();
    String typeName = "";
    if ((literal.endsWith("f") || literal.endsWith("F"))
            && (!literal.startsWith("0x") && !literal.startsWith("0X"))) {
        typeName = "float";
    } else if ((literal.endsWith("d") || literal.endsWith("D"))
            && (!literal.startsWith("0x") && !literal.startsWith("0X"))) {
        typeName = "double";
    } else if (literal.endsWith("l") || literal.endsWith("L")) {
        typeName = "long";
    } else if (literal.contains(".")) {
        String actType = getTypeName((NumberLiteral) astExpr);
        if (actType != null) {
            typeName = actType;
        } else {
            typeName = "float";
        }
    } else {

        //         IJstType type = null;
        //         if(jstNode instanceof JstProperty){
        //            type = ((JstProperty)jstNode).getType();
        //         }
        //         
        //         if(type!=null && type.getName().contains(Integer.class.getSimpleName())){
        //            typeName= "Integer";
        //         }else{
        typeName = "int";
        //         }

    }
    ASTNode ast = astExpr.getParent();
    VarTable varTable = null;

    if (ast instanceof VariableDeclarationFragment) {
        VariableDeclarationFragment o = (VariableDeclarationFragment) ast;
        SimpleName n = o.getName();
        if (jstNode instanceof JstType) {
            JstType jstType = (JstType) jstNode;
            varTable = jstType.getVarTable();
        }
        if (jstNode instanceof JstBlock) {
            JstBlock jstBlock = (JstBlock) jstNode;
            varTable = jstBlock.getVarTable();
        }

        String name = getNameTranslator().processVarName(n, jstNode);
        if (varTable != null) {
            IJstType type = varTable.getVarType(name);
            //typeName = type.getSimpleName();

            //See bug #4728 vjo.test.junit.defects.tc6.ClassB
            if (!type.getSimpleName().equals("Object"))
                typeName = type.getSimpleName();
        }
    }

    if (typeName.equals("int")) {
        return SimpleLiteral.getIntegerLiteral(literal);
    }

    if (typeName.equals("Integer")) {
        return SimpleLiteral.getIntegerLiteral(literal);
    }

    if (typeName.equals("Long") || typeName.equals("long")) {
        return SimpleLiteral.getLongLiteral(literal);
    }

    if (typeName.equals("short") || typeName.equals("Short")) {
        return SimpleLiteral.getShortLiteral(literal);
    }
    if (typeName.equals("byte") || typeName.equals("Byte")) {
        return SimpleLiteral.getByteLiteral(literal);
    }
    if (typeName.equals("float") || typeName.equals("Float")) {
        return SimpleLiteral.getFloatLiteral(literal);
    }
    return SimpleLiteral.getDoubleLiteral(literal);
}

From source file:org.jboss.windup.decorator.java.JavaASTAnnotationVisitor.java

License:Open Source License

protected String extract(NumberLiteral value) {
    return value.toString();
}