Bug 245348

Summary: [DOM] Annotations are recognized by ASTParser even in COMPILER_SOURCE is set < 1.5
Product: [Eclipse Project] JDT Reporter: Robert Walter <rwalter>
Component: CoreAssignee: Olivier Thomann <Olivier_Thomann>
Status: VERIFIED FIXED QA Contact:
Severity: minor    
Priority: P3 CC: jerome_lanneluc, Olivier_Thomann
Version: 3.3.2   
Target Milestone: 3.5 M2   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Demo Project to illustrate problem
none
Proposed fix + regression tests none

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