List of usage examples for org.eclipse.jdt.core.dom NumberLiteral getParent
public final ASTNode getParent()
null if this is the root node. From source file:org.ebayopensource.dsf.javatojs.translate.LiteralTranslator.java
License:Open Source License
SimpleLiteral toJstLiteral(final NumberLiteral astExpr, final BaseJstNode jstNode) { // TODO/*from ww w . ja 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.ebayopensource.dsf.javatojs.translate.LiteralTranslator.java
License:Open Source License
private String getTypeName(NumberLiteral astExpr) { ASTNode parent = astExpr.getParent(); if (parent instanceof MethodInvocation && "equals".equals(((MethodInvocation) parent).getName().toString())) { Expression expr = ((MethodInvocation) parent).getExpression(); if (expr instanceof ClassInstanceCreation) { Object type = ((ClassInstanceCreation) expr).getType(); if (type != null) { if ("Double".equals(type.toString())) { return "double"; } else if ("Float".equals(type.toString())) { return "float"; } else if ("Long".equals(type.toString())) { return "long"; }/*from ww w.j a va2 s . c o m*/ } } } return null; }
From source file:org.eclipselabs.javainterpreter.ExpressionVisitor.java
License:Open Source License
@Override public boolean visit(NumberLiteral node) { String token = node.getToken(); ASTNode parent = node.getParent(); if (node.getParent() instanceof PrefixExpression) { PrefixExpression exp = (PrefixExpression) node.getParent(); if (exp.getOperator() == PrefixExpression.Operator.MINUS) { token = "-" + token; parent = exp.getParent();//from w ww.ja v a2 s. com } } Number number = null; if (token.indexOf('.') == -1) number = new Integer(token); else number = new Double(token); if (argsTable.containsKey(parent)) argsTable.get(parent).add(number); return true; }