Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6665294

javac-api: toString() for simple annotations/inner classes contains extra characters

XMLWordPrintable

      javac-api: When toString() is called for a ClassTree which corresponds to inner class, it prints extra "class {" instead of just "{", see example below. This probably should not compile at all.
      Parent trees toString works correctly. Also @Override annotations contain extra "()" characters which
      are missing from the source. Both of these leads to the problem, when tree.toString() contains
      some extra characters when compared to the source file, which probably should not happen.
      A test is attached, it also demonstrates that SourcePositions::getEndPosition() doesn't work correctly
      in many cases (it is often EQUAL to getStartPosition()), which is probably duplicate of 6599152.

      example:

       new TreeScanner<Void, Void>()
              {
      @Override
           public Void visitClass(ClassTree class_item, Void arg1)
           {
            System.out.print(" class "+ class_item.getSimpleName()+ " starts at
                            " +sourcePositions.getStartPosition(compilation_tree, class_item));
            System.out.println(" ends at "+sourcePositions.getEndPosition(compilation_tree, class_item));
                      if(class_item.getSimpleName().length()==0)
                          System.out.println(" class dump:"+ class_item.toString());
                      return super.visitClass(class_item, arg1);
           }
          }.scan(compilation_tree, null);

      outputs (when ran againts itself):
      class {
          @Override()
          public Void visitClass(ClassTree class_item, Void arg1) {
              System.out.print(" class " + class_item.getSimpleName() + " starts at " + sourcePositions.getStartPosition(compilation_tree, class_item));
              System.out.println(" ends at " + sourcePositions.getEndPosition(compilation_tree, class_item));
              if (class_item.getSimpleName().length() == 0) System.out.println(" class dump:" + class_item.toString());
              return super.visitClass(class_item, arg1);
          }
      }

      *** (#1 of 1): [ UNSAVED ] ###@###.###

            jjg Jonathan Gibbons
            nzinovie Nikita Zinoviev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: