@Test public void testStrings() { assertEquals("foo", LiteralSupport.getLiteralValue("'foo'")); assertEquals("foo", LiteralSupport.getLiteralValue("\"foo\"")); }
static Object getLiteralValue(String literal) { if (literal == null || literal.isEmpty()) { return Result.NOT_FOUND; } Object value = Result.NOT_FOUND; if (isStringLiteralSeparator(literal.charAt(0))) { value = literal.substring(1, literal.length() - 1); } else if (literal.equals("true")) { value = Boolean.TRUE; } else if (literal.equals("false")) { value = Boolean.FALSE; } else if (literal.equals("null")) { value = null; } else { char firstChar = literal.charAt(0); if (Character.isDigit(firstChar) || firstChar == '-' || firstChar == '+') { if (INTEGER_LITERAL_PATTERN.matcher(literal).matches()) { try { value = Integer.parseInt(literal); } catch (NumberFormatException e) { LOGGER.warn("Unable to parse integer literal: " + literal, e); } } else if (LONG_LITERAL_PATTERN.matcher(literal).matches()) { try { value = Long .parseLong(literal.substring(0, literal.length() - 1)); } catch (NumberFormatException e) { LOGGER.warn("Unable to parse long literal: " + literal, e); } } else if (DOUBLE_LITERAL_PATTERN.matcher(literal).matches()) { try { value = Double .parseDouble(literal.substring(0, literal.length() - 1)); } catch (NumberFormatException e) { LOGGER.warn("Unable to parse double literal: " + literal, e); } } else if (FLOAT_LITERAL_PATTERN.matcher(literal).matches()) { try { value = Float .parseFloat(literal.substring(0, literal.length() - 1)); } catch (NumberFormatException e) { LOGGER.warn("Unable to parse float literal: " + literal, e); } } } } return value; }
LiteralSupport { static Object getLiteralValue(String literal) { if (literal == null || literal.isEmpty()) { return Result.NOT_FOUND; } Object value = Result.NOT_FOUND; if (isStringLiteralSeparator(literal.charAt(0))) { value = literal.substring(1, literal.length() - 1); } else if (literal.equals("true")) { value = Boolean.TRUE; } else if (literal.equals("false")) { value = Boolean.FALSE; } else if (literal.equals("null")) { value = null; } else { char firstChar = literal.charAt(0); if (Character.isDigit(firstChar) || firstChar == '-' || firstChar == '+') { if (INTEGER_LITERAL_PATTERN.matcher(literal).matches()) { try { value = Integer.parseInt(literal); } catch (NumberFormatException e) { LOGGER.warn("Unable to parse integer literal: " + literal, e); } } else if (LONG_LITERAL_PATTERN.matcher(literal).matches()) { try { value = Long .parseLong(literal.substring(0, literal.length() - 1)); } catch (NumberFormatException e) { LOGGER.warn("Unable to parse long literal: " + literal, e); } } else if (DOUBLE_LITERAL_PATTERN.matcher(literal).matches()) { try { value = Double .parseDouble(literal.substring(0, literal.length() - 1)); } catch (NumberFormatException e) { LOGGER.warn("Unable to parse double literal: " + literal, e); } } else if (FLOAT_LITERAL_PATTERN.matcher(literal).matches()) { try { value = Float .parseFloat(literal.substring(0, literal.length() - 1)); } catch (NumberFormatException e) { LOGGER.warn("Unable to parse float literal: " + literal, e); } } } } return value; } }
LiteralSupport { static Object getLiteralValue(String literal) { if (literal == null || literal.isEmpty()) { return Result.NOT_FOUND; } Object value = Result.NOT_FOUND; if (isStringLiteralSeparator(literal.charAt(0))) { value = literal.substring(1, literal.length() - 1); } else if (literal.equals("true")) { value = Boolean.TRUE; } else if (literal.equals("false")) { value = Boolean.FALSE; } else if (literal.equals("null")) { value = null; } else { char firstChar = literal.charAt(0); if (Character.isDigit(firstChar) || firstChar == '-' || firstChar == '+') { if (INTEGER_LITERAL_PATTERN.matcher(literal).matches()) { try { value = Integer.parseInt(literal); } catch (NumberFormatException e) { LOGGER.warn("Unable to parse integer literal: " + literal, e); } } else if (LONG_LITERAL_PATTERN.matcher(literal).matches()) { try { value = Long .parseLong(literal.substring(0, literal.length() - 1)); } catch (NumberFormatException e) { LOGGER.warn("Unable to parse long literal: " + literal, e); } } else if (DOUBLE_LITERAL_PATTERN.matcher(literal).matches()) { try { value = Double .parseDouble(literal.substring(0, literal.length() - 1)); } catch (NumberFormatException e) { LOGGER.warn("Unable to parse double literal: " + literal, e); } } else if (FLOAT_LITERAL_PATTERN.matcher(literal).matches()) { try { value = Float .parseFloat(literal.substring(0, literal.length() - 1)); } catch (NumberFormatException e) { LOGGER.warn("Unable to parse float literal: " + literal, e); } } } } return value; }  }
LiteralSupport { static Object getLiteralValue(String literal) { if (literal == null || literal.isEmpty()) { return Result.NOT_FOUND; } Object value = Result.NOT_FOUND; if (isStringLiteralSeparator(literal.charAt(0))) { value = literal.substring(1, literal.length() - 1); } else if (literal.equals("true")) { value = Boolean.TRUE; } else if (literal.equals("false")) { value = Boolean.FALSE; } else if (literal.equals("null")) { value = null; } else { char firstChar = literal.charAt(0); if (Character.isDigit(firstChar) || firstChar == '-' || firstChar == '+') { if (INTEGER_LITERAL_PATTERN.matcher(literal).matches()) { try { value = Integer.parseInt(literal); } catch (NumberFormatException e) { LOGGER.warn("Unable to parse integer literal: " + literal, e); } } else if (LONG_LITERAL_PATTERN.matcher(literal).matches()) { try { value = Long .parseLong(literal.substring(0, literal.length() - 1)); } catch (NumberFormatException e) { LOGGER.warn("Unable to parse long literal: " + literal, e); } } else if (DOUBLE_LITERAL_PATTERN.matcher(literal).matches()) { try { value = Double .parseDouble(literal.substring(0, literal.length() - 1)); } catch (NumberFormatException e) { LOGGER.warn("Unable to parse double literal: " + literal, e); } } else if (FLOAT_LITERAL_PATTERN.matcher(literal).matches()) { try { value = Float .parseFloat(literal.substring(0, literal.length() - 1)); } catch (NumberFormatException e) { LOGGER.warn("Unable to parse float literal: " + literal, e); } } } } return value; }   }
LiteralSupport { static Object getLiteralValue(String literal) { if (literal == null || literal.isEmpty()) { return Result.NOT_FOUND; } Object value = Result.NOT_FOUND; if (isStringLiteralSeparator(literal.charAt(0))) { value = literal.substring(1, literal.length() - 1); } else if (literal.equals("true")) { value = Boolean.TRUE; } else if (literal.equals("false")) { value = Boolean.FALSE; } else if (literal.equals("null")) { value = null; } else { char firstChar = literal.charAt(0); if (Character.isDigit(firstChar) || firstChar == '-' || firstChar == '+') { if (INTEGER_LITERAL_PATTERN.matcher(literal).matches()) { try { value = Integer.parseInt(literal); } catch (NumberFormatException e) { LOGGER.warn("Unable to parse integer literal: " + literal, e); } } else if (LONG_LITERAL_PATTERN.matcher(literal).matches()) { try { value = Long .parseLong(literal.substring(0, literal.length() - 1)); } catch (NumberFormatException e) { LOGGER.warn("Unable to parse long literal: " + literal, e); } } else if (DOUBLE_LITERAL_PATTERN.matcher(literal).matches()) { try { value = Double .parseDouble(literal.substring(0, literal.length() - 1)); } catch (NumberFormatException e) { LOGGER.warn("Unable to parse double literal: " + literal, e); } } else if (FLOAT_LITERAL_PATTERN.matcher(literal).matches()) { try { value = Float .parseFloat(literal.substring(0, literal.length() - 1)); } catch (NumberFormatException e) { LOGGER.warn("Unable to parse float literal: " + literal, e); } } } } return value; }    }