Bug 130778

Summary: Invalid annotation elements cause no annotation to be in the AST
Product: [Eclipse Project] JDT Reporter: Karen Butzke <karenfbutzke>
Component: CoreAssignee: David Audel <david_audel>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P2 CC: jerome_lanneluc, paul.fullbright
Version: 3.1.1   
Target Milestone: 3.4 M5   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Bug Depends on:    
Bug Blocks: 130790, 130794    
Attachments:
Description Flags
falings tests for invalid annotation syntax
none
Proposed fix none

Description Karen Butzke CLA 2006-03-07 14:16:34 EST
Annotations with invalid syntax on the annotation elements are not found in the AST.

In this first example the call to 
TypeDeclaration.modifiers() returns a List containing the 
SingleMemberAnnotation.

  MyAnnotation(name)
  class Foo {}


In this example, TypeDeclaration.modifiers() returns an empty list and I 
am not able to see that there is an annotation on the class.

  MyAnnotation(name=)
  class Foo {}
Comment 1 Karen Butzke CLA 2006-03-07 14:38:51 EST
Created attachment 35852 [details]
falings tests for invalid annotation syntax

This attachment contains one JUnit test class with 1 passing test and 2 failing tests. The failing tests start with classes containing the following source code and then try to get the Annotation from the TypeDeclaration.

Source code contains @MyAnnotation(name=)
Source code contains @MyAnnotation(name="foo" , )

More explanation is given in the test class.
Comment 2 Philipe Mulet CLA 2006-03-07 15:27:12 EST
Broken annotations are known to cause grief to the syntax recovery currently.
Comment 3 David Audel CLA 2008-01-25 06:52:43 EST
Created attachment 87852 [details]
Proposed fix

With this fix annotation name and all correct member value pairs are recovered. This behavior is similar to method declaration recovery (method name and all correct parameters are recovered).

With the following test case
  MyAnnotation(name=)
  class Foo {}
the recovered ast will be
  MyAnnotation
  class Foo {}

With the following test case
  MyAnnotation(name1="a", name2=)
  class Foo {}
the recovered ast will be
  MyAnnotation(name1="a")
  class Foo {}


This fix also add modifiers recovery.
Comment 4 David Audel CLA 2008-01-25 07:00:08 EST
Released for 3.4M5.

Tests added
  AnnotationDietRecoveryTest#test0013()->test0035()
  StatementRecoveryTest_1_5#test003()->test0007()
  ASTConverterBugsTestJLS3#testBug130778a()->testBug130778x()
Comment 5 Frederic Fusier CLA 2008-02-04 12:49:09 EST
Verified for 3.4M5 using build I20080204-0010.