Esempio n. 1
0
 private static void addSuppressWarningsAll(
     JCModifiers mods, JavacNode node, int pos, JCTree source) {
   TreeMaker maker = node.getTreeMaker();
   JCExpression suppressWarningsType = chainDots(node, "java", "lang", "SuppressWarnings");
   JCLiteral allLiteral = maker.Literal("all");
   suppressWarningsType.pos = pos;
   allLiteral.pos = pos;
   JCAnnotation annotation =
       recursiveSetGeneratedBy(
           maker.Annotation(suppressWarningsType, List.<JCExpression>of(allLiteral)), source);
   annotation.pos = pos;
   mods.annotations = mods.annotations.append(annotation);
 }
Esempio n. 2
0
 /**
  * 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();
 }