Community
Participate
Working Groups
I20050627-1435 Externalize Strings Wizard should not touch strings that are annotation arguments. In the example below, the string "unused" cannot be externalized and should not appear in the table at all. See also JDT/Core bug 102130 (don't warn about non-externalized string in annotation). public class Klass { void use() { @SuppressWarnings("unused") String s; } }
See also bug 110613 - Externalize Strings Wizards should not touch literals in annotation declarations, either.
*** Bug 132308 has been marked as a duplicate of this bug. ***
*** Bug 144596 has been marked as a duplicate of this bug. ***
*** Bug 159469 has been marked as a duplicate of this bug. ***
*** Bug 169713 has been marked as a duplicate of this bug. ***
I fear that it is getting too late for this 3.1 bug to be resolved in time for 3.3, but it would be nice. This bug is getting close to its second birthday, so I'm surprised that it has not yet been addressed.
Sorry no time for this but if a good patch is provided we will look at it.
Created attachment 83486 [details] basic patch Dani, here is a little patch which tries to solve the issue. In the first throw i totally forgot that annotations can be spanned across several lines which makes the whole thing a little bit difficult (see test16). It looks like you try to avoid any AST operations in the nls stuff so i didn't start hacking on that. What I need to know is: a) ignore these cases / matching too much strings b) use AST magic to see if we are in an annotation c) go the road down and try to detect annotation start/end based on the token approach. Any suggestions?
c) it is.
Created attachment 84580 [details] updated patch Dani, here is an updated patch. It looks so simple that I'm really nervous if this is the right way ;) Do you know any other cases where this approach will fail?
Comment on attachment 84580 [details] updated patch (In reply to comment #10) I guess it really is simple, but not that simple ;-). The updated patch fails with nested annotations and with parenthesized expressions as arguments. You need to count the nesting level of parentheses inside annotations. Test cases: @Annotation(a= @Nested("Hello"), b= "World") @Annotation2(a= (1 + 2) * 3, b= "xx") public class Annot { } @interface Annotation { Nested a(); String b(); } @interface Annotation2 { int a(); String b(); } @interface Nested { String value(); }
Created attachment 88756 [details] updated patch Here is an updated version of the patch to ignore strings in annotations
To be looked at during M6.
Released an improved version of the last patch to HEAD. Added support and tests for @interface and default values, e.g.: @interface Annotation3 { String a= "translate me"; } @interface Annotation { Nested a(); String c() default true ? "x" : "y"; } class C { void m() { switch (12) { default: String s= "x"; } } }
Verified in I20080325-0100.