Bug 245348 - [DOM] Annotations are recognized by ASTParser even in COMPILER_SOURCE is set < 1.5
Summary: [DOM] Annotations are recognized by ASTParser even in COMPILER_SOURCE is set ...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3.2   Edit
Hardware: PC Windows XP
: P3 minor (vote)
Target Milestone: 3.5 M2   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-08-27 03:54 EDT by Robert Walter CLA
Modified: 2008-09-16 07:58 EDT (History)
2 users (show)

See Also:


Attachments
Demo Project to illustrate problem (6.27 KB, application/zip)
2008-08-27 03:55 EDT, Robert Walter CLA
no flags Details
Proposed fix + regression tests (5.41 KB, patch)
2008-08-27 12:12 EDT, Olivier Thomann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Robert Walter CLA 2008-08-27 03:54:35 EDT
Hi,

when using ASTParser class of "org.eclipse.jdt.core_3.3.1.v_780_R33x.jar" to create an AST of a java source file using the default options (COMPILER_SOURCE = "1.3"), an AnnotationTypeDeclaration is recognized and can be visited using an ASTVisitor extension. I think that should not be possible since AnnotationTypeDeclarations are new to "1.5". An EnumDeclaration which is also new to "1.5" in comparasion does not get recognized (keyword enum gets scanned as identifer in internal Scanner class).

I attached a small demo project that shows the described effects.

Greetings
Robert
Comment 1 Robert Walter CLA 2008-08-27 03:55:58 EDT
Created attachment 111043 [details]
Demo Project to illustrate problem
Comment 2 Jerome Lanneluc CLA 2008-08-27 07:47:55 EDT
Indeed, we should return an empty CompilationUnit (since the source contains syntax errors) with getProblems() that would return the syntax errors.
Comment 3 Olivier Thomann CLA 2008-08-27 11:54:36 EDT
Note that we still return the syntax error in the compilation unit's problems.
Comment 4 Olivier Thomann CLA 2008-08-27 12:08:16 EDT
In case the scanner source is < 1.5, we should not convert annotation declarations.
Comment 5 Olivier Thomann CLA 2008-08-27 12:12:24 EDT
Created attachment 111087 [details]
Proposed fix + regression tests
Comment 6 Olivier Thomann CLA 2008-08-27 12:13:52 EDT
Released for 3.5M2.
Regression tests added in org.eclipse.jdt.core.tests.dom.ASTConverterTestAST3_2#test0695
org.eclipse.jdt.core.tests.dom.ASTConverterTestAST3_2#test0696
Comment 7 Jerome Lanneluc CLA 2008-09-15 11:26:45 EDT
Verified for 3.5M2 using I20080914-2000