-
Bug
-
Resolution: Won't Fix
-
P4
-
None
-
6
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 ] ###@###.###
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 ] ###@###.###