Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 334635 - [typing] Correct indentation is incorrect when annotation parameters are on a separate line
Summary: [typing] Correct indentation is incorrect when annotation parameters are on a...
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 3.7   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: 3.7 M6   Edit
Assignee: Rajesh CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-01-18 08:32 EST by Didier Loiseau CLA
Modified: 2011-02-14 12:18 EST (History)
2 users (show)

See Also:
deepakazad: review-
deepakazad: review-
deepakazad: review+


Attachments
Patch with test. (4.74 KB, patch)
2011-02-10 04:27 EST, Rajesh CLA
no flags Details | Diff
Patch with test. (5.01 KB, patch)
2011-02-11 07:36 EST, Rajesh CLA
no flags Details | Diff
Patch with test. (5.23 KB, patch)
2011-02-14 09:24 EST, Rajesh CLA
deepakazad: iplog+
deepakazad: review+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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.