-
Notifications
You must be signed in to change notification settings - Fork 869
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enforcing a space in one-line comment breaks //$NON-NLS-x$ notation #221
Comments
By way of background, the Eclipse Compiler for Java (ecj) can be configured to warn about non-externalized strings for internationalization. The warnings can be suppressed by annotating strings with comments like An alternative approach to #222 would be to special case
However there's one additional difference in that the |
The line wrapping is actually a complicated issue to handle in google-java-format. The Eclipse formatter is actually doing this properly. It's been a while this I reported this issue without answers, so I went ahead and implemented the only way I could think of:
This works like a charm but this is quite a big change, so I did not make a PR for it. I think @briandealwis or my initial solution is a fine, simple solution which covers the non-wrapping cases. |
I understand that reformatting e.g. I'm not sure I understand the line wrapping issue, though: google-java-format doesn't currently reflow long string literals, or move line comments off very long lines. e.g. this is not currently wrapped: class T {
private String s =
"long looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong string"; // $NON-NLS-1$
} Do you have an example of a |
We'll see it where the string is an argument followed by another argument. The following snippet
is line wrapped to
The Eclipse formatter will move the |
Thanks, is it an option to write that code like this instead? } catch (CoreException ex) {
logger.log(
Level.WARNING,
"Unable to obtain jst.web facet version from selected project", //$NON-NLS-1$
ex);
} |
Sorry, I should have said that: it would be extraordinarily helpful for the formatter to do it automatically, but manually moving tags is perfectly acceptable. |
Thanks for clarifying. I agree it would be nice if the formatter could do that automatically, but I'd prefer to avoid adding a lot of logic to the formatter to handle this specific case. It sounds like not adding the space to |
Yup, that would be great. Eclipse can be configured to flag strings missing a |
Unfortunately this fix is insufficient. Consider the following sample class: public class ExampleClass {
public Object resolveClasspathContainer() {
System.out.printf(
"This is an expression %s\n", //$NON-NLS-1$
"value"); //$NON-NLS-2$
System.out.println("statement"); //$NON-NLS-3$
Job resolveJob = new Job("Resolving libraries for " + webFacetVersion) { //$NON-NLS-4$
@Override
protected IStatus run(IProgressMonitor monitor) {}
};
return null;
}
} The formatting of @@ -3,8 +3,8 @@
System.out.printf(
"This is an expression %s\n", //$NON-NLS-1$
"value"); //$NON-NLS-2$
- System.out.println("statement"); //$NON-NLS-3$
- Job resolveJob = new Job("Resolving libraries for " + webFacetVersion) { //$NON-NLS-4$
+ System.out.println("statement"); // $NON-NLS-3$
+ Job resolveJob = new Job("Resolving libraries for " + webFacetVersion) { // $NON-NLS-4$
@Override
protected IStatus run(IProgressMonitor monitor) {}
}; |
I am a bit puzzled by your example because the number in the non-nls comment should correspond to the literal's number on the line. If you copy this code in Eclipse you will get warnings for invalid non-nls comments. |
Sorry I should have made that clear: the numbers are purely for referencing purposes. |
Hi,
Since version 1.4 a new rule formats "//comment" into "// comment". Unfortunately Eclipse uses "//$NON-NLS-x$" comments to avoid internationalization warnings. If you add the space it does not work anymore. We have these all over the place in our codebase which prevents us of using versions of google-java-format later than 1.3.
Would it be possible to handle this case? (maybe a solution is to check if the first character is alpha-numeric)
Alternatively would there be a workaround for us with a setting.
Thanks!
The text was updated successfully, but these errors were encountered: