/** * Hacky fix for poor javac 6 literal parsing. javac 6 doesn't set the AST node start position * correctly when a numeric literal is preceded by -. So we scan the source backwards starting at * the provided start position, looking for whitespace, until we find the true start position. * javac 7 gets this right. * * @return The actual start position of the literal. May be the same as the start position given * by the tree node itself. */ public static int getActualStartPosition(JCLiteral tree, CharSequence source) { // This only applies to negative numeric literals. Object value = tree.getValue(); if ((value instanceof Number) && (((Number) value).doubleValue() < 0)) { int start = tree.getStartPosition() - 1; while (WHITESPACE_CHARS.matches(source.charAt(start))) { start--; } if (source.charAt(start) == '-') { return start; } } return tree.getStartPosition(); }