Bug 155550 - [1.5][compiler] parser problem with annotations and array initializers
Summary: [1.5][compiler] parser problem with annotations and array initializers
Status: RESOLVED WORKSFORME
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.3 RC4   Edit
Assignee: David Audel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-08-29 10:38 EDT by Brian Vosburgh CLA
Modified: 2007-06-19 09:55 EDT (History)
0 users

See Also:


Attachments
JUnit Plug-in Test to re-create problem (10.04 KB, text/plain)
2006-08-29 21:16 EDT, Brian Vosburgh CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Brian Vosburgh CLA 2006-08-29 10:38:43 EDT
The following code is mis-parsed:

    @Foo({"bar", "baz"})
    private String name;

while the following, functionally equivalent, code is parsed correctly:

    @Foo(value={"bar", "baz"})
    private String name;

In the former case, the parser ignores the annotation and generates an empty Initializer block in the parent TypeDeclaration's bodyDeclarations.

In the latter case, the parser correctly generates a NormalAnnotation and places it in the following FieldDeclaration's modifiers.

The former should be parsed as a SingleMemberAnnotation in the FieldDeclaration's modifiers.
Comment 1 Olivier Thomann CLA 2006-08-29 10:43:22 EDT
Could you please let me know if you are in a code snippet page (scrapbook page) or inside a normal compilation unit?
Comment 2 Brian Vosburgh CLA 2006-08-29 10:50:02 EDT
(In reply to comment #1)
> Could you please let me know if you are in a code snippet page (scrapbook page)
> or inside a normal compilation unit?
> 

normal compilation unit
Comment 3 Olivier Thomann CLA 2006-08-29 13:14:25 EDT
I could not reproduce with HEAD contents.
What is your build id + compiler settings ?
Comment 4 Olivier Thomann CLA 2006-08-29 13:45:41 EDT
Could not reproduce with 3.2.1 maintenance build.
Could you please tell me what you have installed over 3.2 and WTP?
Thanks.
Comment 5 Brian Vosburgh CLA 2006-08-29 15:18:02 EDT
(In reply to comment #4)
> Could you please tell me what you have installed over 3.2 and WTP?

The HEAD of the org.eclipse.dali.* and org.eclipse.jst.jpa.* packages.
Comment 6 Olivier Thomann CLA 2006-08-29 15:22:55 EDT
And what do you do to get the error?
Comment 7 Brian Vosburgh CLA 2006-08-29 21:16:30 EDT
Created attachment 49025 [details]
JUnit Plug-in Test to re-create problem

This JUnit test case class has two tests:
    test1 uses the annotation "@Foo(value={1, 2})" and passes
    test2 uses the annotation "@Foo({1, 2})" and fails
Comment 8 Olivier Thomann CLA 2006-08-30 10:40:51 EDT
In the source that you use for the test case, you missed a semi-colon after the package name.
You have:
package test

public class TestClass {

    @Foo({1, 2})
    private int id;

    public int getId() {
        return this.id;
    }

    public void setId(int id) {
        this.id = id;
    }

}

In this case the error recovery cannot retrieve the annotation. If the source doesn't contain any error, it works fine.

David, do you believe this is doable? If not, simply close as INVALID.
Comment 9 Brian Vosburgh CLA 2006-08-30 10:55:56 EDT
Ahhh, right you are. I have over 100 other tests that manipulate various types of annotations in that same spot; but only this one has caused problems. I guess the parser recovers in the other cases. I added the semicolon and things work fine. Sorry about the hassle.
Comment 10 Olivier Thomann CLA 2006-08-30 11:49:21 EDT
No problem.
Comment 11 David Audel CLA 2007-06-19 09:55:01 EDT
I cannot reproduce the bug using 3.3RC4.
This bug has been fixed in a previous build.
I close this bug as WORKSFORME.