switch (literal.getKind()) { case DOUBLE_LITERAL: double doubleValue = ((Double) literalValue).doubleValue();
/** * Turns an expression into a guessed intended literal. Only works for * literals, as you can imagine. * * Will for example turn a TrueLiteral into 'Boolean.valueOf(true)'. */ public static Object calculateGuess(JCExpression expr) { if (expr instanceof JCLiteral) { JCLiteral lit = (JCLiteral) expr; if (lit.getKind() == com.sun.source.tree.Tree.Kind.BOOLEAN_LITERAL) { return ((Number) lit.value).intValue() == 0 ? false : true; } return lit.value; } if (expr instanceof JCIdent || expr instanceof JCFieldAccess) { String x = expr.toString(); if (x.endsWith(".class")) return new ClassLiteral(x.substring(0, x.length() - 6)); int idx = x.lastIndexOf('.'); if (idx > -1) x = x.substring(idx + 1); return new FieldSelect(x); } return null; }
switch (literal.getKind()) { case DOUBLE_LITERAL: double doubleValue = ((Double) literalValue).doubleValue();
boolean negative = false; Expression literal = null; switch (node.getKind()) { case INT_LITERAL: int intValue = ((Number)val).intValue();
boolean negative = false; Expression literal = null; switch (node.getKind()) { case INT_LITERAL: int intValue = ((Number)val).intValue();
boolean negative = false; Expression literal = null; switch (node.getKind()) { case INT_LITERAL: int intValue = ((Number)val).intValue();
private static void analyzeLiteral( SourceContext context, JCTree.JCLiteral literal, int preferredPos, int endPos) { Source src = context.source; Tree.Kind kind = literal.getKind(); Object value = literal.getValue(); Range range = Range.create(src, preferredPos, endPos); Variable variable = new Variable(kind.toString(), preferredPos, range); if (nonNull(value)) { variable.fqcn = value.getClass().getCanonicalName(); variable.argumentIndex = context.argumentIndex; context.setArgumentFQCN(variable.fqcn); } else { variable.fqcn = "<null>"; variable.argumentIndex = context.argumentIndex; context.setArgumentFQCN(variable.fqcn); } src.getCurrentScope() .ifPresent( scope -> { scope.addVariable(variable); addSymbolIndex(src, scope, variable); }); }