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

Bug 334635

Summary: [typing] Correct indentation is incorrect when annotation parameters are on a separate line
Product: [Eclipse Project] JDT Reporter: Didier Loiseau <didierloiseau+eclipse>
Component: TextAssignee: Rajesh <rthakkar>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: daniel_megert, deepakazad
Version: 3.7Flags: deepakazad: review-
deepakazad: review-
deepakazad: review+
Target Milestone: 3.7 M6   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Attachments:
Description Flags
Patch with test.
none
Patch with test.
none
Patch with test. deepakazad: iplog+, deepakazad: review+

Description Didier Loiseau CLA 2011-01-18 08:32:49 EST
Build Identifier: 20100617-1415

When an annotation parameter is on a separate line than the annotation itself, and the closing parenthesis is on the same line as the parameter, the next line is indented at the same level as the parameter, which is incorrect.

This issue is similar to Bug 237081

Reproducible: Always

Steps to Reproduce:
1. Copy the code below in a new java editor
2. Select all, and ctrl+I (Correct Indentation)
3. The class declaration is indented at the same level as the value parameter.
This is the same when the next line is also an annotation, or with array annotations (like when using @javax.persistence.NamedQueries). However this does not occur when "value=" is omitted (but it is not always possible) or when the annotation's closing parenthesis is on a separate line.

@MyAnnotation(
	value="hello")
public class ArrayAnnotationBug {

}

@interface MyAnnotation {
	String value();
}
Comment 1 Dani Megert CLA 2011-01-21 04:24:38 EST
Rajesh, please check if this is still the case with your recent patches.
Comment 2 Rajesh CLA 2011-01-23 23:52:34 EST
(In reply to comment #1)
> Rajesh, please check if this is still the case with your recent patches.

Yes, this is still an issue even with latest patch and needs to be addressed separately.
Comment 3 Rajesh CLA 2011-02-10 04:27:52 EST
Created attachment 188661 [details]
Patch with test.
Comment 4 Dani Megert CLA 2011-02-10 04:34:23 EST
Deepak, please do the first review.
Comment 5 Deepak Azad CLA 2011-02-11 03:45:46 EST
- Patch does not work if fully qualified name of the annotation is used (see JavaIndenter.looksLikeAnonymousTypeDecl() on how to handle fully qualified names)

-------------------------------------------------------------------
package org.eclipse.annotation;
public @interface MyAnnotation {
	String value();
}

package org.eclipse.test;
@org.eclipse.annotation.MyAnnotation( 
		value="hello")
public class ArrayAnnotationBug {

}

------------------------------------------------------------------

- Rename looksLikeAnnotationDecl to looksLikeAnnotation. "@interface MyAnnotation {...}"  is the annotation declaration.
- Add "(i.e. an annotation name (potentially qualified) and an at-sign)" to the javadoc of looksLikeAnnotation.
Comment 6 Rajesh CLA 2011-02-11 07:36:47 EST
Created attachment 188768 [details]
Patch with test.

Now handles qualified name.
Comment 7 Deepak Azad CLA 2011-02-11 07:59:28 EST
The fix is good, but..

(In reply to comment #6)
> Now handles qualified name.
Please add a test for this.
Comment 8 Rajesh CLA 2011-02-14 09:24:36 EST
Created attachment 188903 [details]
Patch with test.
Comment 9 Deepak Azad CLA 2011-02-14 12:18:29 EST
Committed to HEAD.

Rajesh, thanks for the patch.