Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 413942

Summary: [1.8][dom ast] Bad source ranges for non-marker annotations with nontrivial arguments
Product: [Eclipse Project] JDT Reporter: Markus Keller <markus.kell.r>
Component: CoreAssignee: Manoj N Palat <manoj.palat>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: daniel_megert, jarthana, manoj.palat, srikanth_sankaran
Version: 4.3   
Target Milestone: BETA J8   
Hardware: All   
OS: All   
Whiteboard:

Description Markus Keller CLA 2013-07-29 14:41:35 EDT
The ASTParser has various problems where it generates wrong source ranges with nontrivial annotations. While investigating these problems I found the problem with the wrong nesting of ArrayType nodes (bug 413569).

The problem is that various ASTConverter#retrieve*(..) methods make wrong assumptions about the possible form of annotations. E.g. retrieveExtraDimension(..) and retrieveEndOfElementTypeNamePosition(..) assume they can just skip "@AnnotationName", but that strategy fails as soon as the annotation has arguments. retrieveProperRightBracketPosition(..) and its callers also use a similarly doomed strategy in trying to find the brackets of an array type starting from the beginning of the array type.

The loops in the retrieve*(..) methods should only skip over TokenNameCOMMENT_* tokens, and otherwise give up when they encounter an unknown token id.

The strategy should not be to scan over annotations, but to use the annotation nodes' source ranges to update the start position and then only scan for the brackets after the annotation node.


Test case with all kinds of problems (but syntactically correct):

public class ArrayTypeAnnotations extends @NonNull(int[].class) Object {
    Object field = new ArrayList< @NonEmpty(Bla) int @NonNull(Bla) [] @NonEmpty(Blu) [ ]>() ;
    
    int[][] xxx;
    ArrayList<int[]> [][] yyy; // source ranges already broken in AST.JLS4
    ArrayList<int[][]> [][][][] zzz;
    ArrayList<Float> [][][] zzz2;
    Object a = new ArrayList< @TakeType(int[].class) int @TakeType(float.class) [] @TakeType(double.class) []>() ;
    Object b = new @NonNull(Math.PI) ArrayList< >() ;
    Object c = new ArrayList<@NonNull(Math.PI) Object[]>() ;

    void foo(int i) {
        for (String tab@TakeType(int[].class) [] = null;; ++i) { break; }
        for (@Deprecated String tab@TakeType(int[].class) [][]  = null;; ++i) {}
    }
}
Comment 1 Srikanth Sankaran CLA 2013-08-26 01:44:21 EDT
Manoj, please work on this in tandem with bug 413569
Comment 2 Manoj N Palat CLA 2013-09-25 05:24:24 EDT
Issues in the listed testcases taken care in bug 413569 and released as mentioned in bug 413569 comment 21