Bug 102132 - [nls tooling] Externalize Strings Wizard should not touch annotation arguments
Summary: [nls tooling] Externalize Strings Wizard should not touch annotation arguments
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal with 1 vote (vote)
Target Milestone: 3.4 M6   Edit
Assignee: Markus Keller CLA
QA Contact:
URL:
Whiteboard:
Keywords: contributed
: 132308 144596 159469 169713 (view as bug list)
Depends on:
Blocks: 227482
  Show dependency tree
 
Reported: 2005-06-29 06:25 EDT by Markus Keller CLA
Modified: 2008-04-18 09:14 EDT (History)
7 users (show)

See Also:


Attachments
basic patch (5.26 KB, patch)
2007-11-21 17:51 EST, Benjamin Muskalla CLA
no flags Details | Diff
updated patch (5.18 KB, patch)
2007-12-05 19:04 EST, Benjamin Muskalla CLA
markus.kell.r: review-
Details | Diff
updated patch (6.11 KB, patch)
2008-02-04 07:15 EST, Benjamin Muskalla CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Keller CLA 2005-06-29 06:25:26 EDT
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;
	}
}
Comment 1 Nick Crossley CLA 2005-09-26 18:10:26 EDT
See also bug 110613 - Externalize Strings Wizards should not touch literals in 
annotation declarations, either.
Comment 2 Dani Megert CLA 2006-03-21 05:37:39 EST
*** Bug 132308 has been marked as a duplicate of this bug. ***
Comment 3 Dani Megert CLA 2006-05-31 03:55:34 EDT
*** Bug 144596 has been marked as a duplicate of this bug. ***
Comment 4 Markus Keller CLA 2006-10-02 13:58:20 EDT
*** Bug 159469 has been marked as a duplicate of this bug. ***
Comment 5 Benno Baumgartner CLA 2007-01-09 07:11:02 EST
*** Bug 169713 has been marked as a duplicate of this bug. ***
Comment 6 Simon Archer CLA 2007-05-05 15:51:28 EDT
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.
Comment 7 Dani Megert CLA 2007-05-07 03:00:24 EDT
Sorry no time for this but if a good patch is provided we will look at it.
Comment 8 Benjamin Muskalla CLA 2007-11-21 17:51:28 EST
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?
Comment 9 Dani Megert CLA 2007-11-23 08:38:15 EST
c) it is.
Comment 10 Benjamin Muskalla CLA 2007-12-05 19:04:57 EST
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 11 Markus Keller CLA 2007-12-06 04:43:23 EST
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();
}
Comment 12 Benjamin Muskalla CLA 2008-02-04 07:15:30 EST
Created attachment 88756 [details]
updated patch

Here is an updated version of the patch to ignore strings in annotations
Comment 13 Dani Megert CLA 2008-02-04 07:18:44 EST
To be looked at during M6.
Comment 14 Markus Keller CLA 2008-03-18 17:15:55 EDT
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";
        }
    }
}
Comment 15 Dani Megert CLA 2008-03-25 12:27:33 EDT
Verified in I20080325-0100.