Bug 21145 - $NON-NLS-<n> Syntax Peculiarities [refactoring]
Summary: $NON-NLS-<n> Syntax Peculiarities [refactoring]
Status: RESOLVED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 2.0   Edit
Hardware: PC All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Adam Kiezun CLA
QA Contact:
URL:
Whiteboard:
Keywords: investigate
Depends on:
Blocks:
 
Reported: 2002-06-28 16:59 EDT by Simon Archer CLA
Modified: 2008-01-21 12:12 EST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Simon Archer CLA 2002-06-28 16:59:49 EDT
The syntax for tagging non-externalized string literals is peculiar:

Firstly, make "Non-externalized string" a warning or error:
1. Window > Preferences.
2. Turn to Java\Compiler preference page.
3. Set "Non-externalized string" to either "Warning" or "Error".
4. Click OK to close the Preferences.

Now create a class as follows:
    public class NlsTest {
        public static void main(String[] args) {
            String platform = "Eclipse " + "2.0"; //$NON-NLS-1$ //$NON-NLS-2$
            System.out.println(platform);
        }
    }

- This class has TWO non-externalized string literals.
- The format used above seems to be the only valid format.
- The following DO NOT seem to be accepted, and perhaps should be:

  1. Removal of // before second $NON-NLS-<n> entry:
     String platform = "Eclipse " + "2.0"; //$NON-NLS-1$ $NON-NLS-2$
            
  2. Insertion of whitespace between // and first $
     String platform = "Eclipse " + "2.0"; // $NON-NLS-1$ //$NON-NLS-2$

  3. Usage of block-comments rather than line comments:
     String platform = "Eclipse " + "2.0"; /* $NON-NLS-1$ $NON-NLS-2$ */

  4. Insertion of a line break between $NON-NLS-<n> entries:
     String platform = "Eclipse " + "2.0"; // $NON-NLS-1$
                                           // $NON-NLS-2$
Comment 1 Philipe Mulet CLA 2002-07-01 06:03:27 EDT
Indeed, we probably should be more resilient, and not consider the prefix '// ' 
from the recognized tag.
Comment 2 Olivier Thomann CLA 2002-07-03 09:10:44 EDT
I agree that we could accept the first three cases, but not the fourth. This tag
is used to determine which strings are externalized on the same line. This is
important in case of multiple line with strings on each line.
Comment 3 Simon Archer CLA 2002-07-08 13:50:57 EDT
Yes, I agree with what you say about the 4th example.  I included the 4th 
example simply as food-for-thought - typically the formatting of code has no 
bearing on its behavior.
Comment 4 Olivier Thomann CLA 2002-07-24 12:05:17 EDT
This syntax cannot be accepted:
/* $NON-NLS-1$ */ // $NON-NLS-2$
but I can now accept:
//$NON-NLS-1$ $NON-NLS-2$
/*$NON-NLS-1$ $NON-NLS-2$ */
// $NON-NLS-1$ //$NON-NLS-2$
Is this good for you?
This change won't be enough. The tools which is checking for non externalized
strings will have to be updated as well.
Comment 5 Simon Archer CLA 2002-07-24 12:49:44 EDT
That sounds great.  How about these variations, where the $NON-NLS piece is 
always on the correct line, but with more complex comments surrounding:

/*$NON-NLS-1$ $NON-NLS-2$
 */

/*
 *$NON-NLS-1$ $NON-NLS-2$
 */

/*Comments before
 *$NON-NLS-1$ $NON-NLS-2$
 *Comments after
 */
Comment 6 Olivier Thomann CLA 2002-07-24 12:57:20 EDT
The last two suggestions are not anymore on the correct line :-). The first one 
is already handled properly. This change will handle only the reporting of non-
externalized strings at the compilation level, but won't change the tool that 
is checking for non-externalized strings. This tool will have to be updated in 
the same way.
Comment 7 Simon Archer CLA 2002-07-24 13:08:23 EDT
Of course, my mistake.  Thanks :-)
Comment 8 Olivier Thomann CLA 2002-07-24 13:46:33 EDT
Ok, I summarize what we would like to be valid syntax:
//$NON-NLS-1$ $NON-NLS-2$
// $NON-NLS-1$ //$NON-NLS-2$
/* $NON-NLS-1$ $NON-NLS-2$ */
/*$NON-NLS-1$ $NON-NLS-2$
 */

The code is ready on my side, but I need to move this PR to JDT/UI to get an 
update the the tool. We cannot release only part of the code.
Please move it back to JDT/Core when you are ready and we will synch the 
release of the code for the same build.
Comment 9 Dirk Baeumer CLA 2002-07-29 13:14:14 EDT
Good improvements. Adam please improve our code as well. The open question that 
remains is which one we insert in the future when we externalize the string the 
first time or when we mark the string as not to be externalized. Any 
suggestions on this front.
Comment 10 Knut Radloff CLA 2002-07-29 14:05:49 EDT
I think //$NON-NLS-1$ $NON-NLS-2$ or // $NON-NLS-1$ $NON-NLS-2$ would make most 
sense. Whether or not to use the leading whitespace is a matter of personal 
preference.
BTW: I didn't realize this earlier but is the fixed code still sensitive to 
random whitespace between the // comment and the $NON-NLS?
I think it should just strip out any whitespace so that
// $NON-NLS-1$ $NON-NLS-2$ or even 
//$NON-NLS-1$ //    $NON-NLS-2$ is valid.

The relevant information is the $NON-NLS-n$ strings and everything else would 
ideally be ignored.

Comment 11 Olivier Thomann CLA 2002-07-29 14:10:48 EDT
The fixed code is looking only for $NON-NLS-?. The // is not considered. This 
is not released for now. I won't release it as long as the tool, which is used 
to check non-externalized strings, is not fixed as well.
If I release the change on the compiler side, you won't get an error or a 
warning, but the tool will still find non-externalized strings.
Comment 12 Dirk Baeumer CLA 2002-07-30 04:48:07 EDT
Adam, when you are done please forward to Martin that he can consider quick fix.
Comment 13 Adam Kiezun CLA 2003-02-21 05:22:08 EST
no action for 2.1
Comment 14 Dirk Baeumer CLA 2003-04-25 04:39:43 EDT
We shopuld make sime progress here for 3.0.
Comment 15 Adam Kiezun CLA 2003-04-25 13:10:19 EDT
reopen for consideration but only a P3
Comment 16 Adam Kiezun CLA 2003-07-08 09:56:30 EDT
for now, no plans to improve the current state
Comment 17 Simon Archer CLA 2008-01-21 12:12:18 EST
Is there any chance that this bug could be reopened and considered for Eclipse 3.4 or Eclipse 4.0?