Bug 513502 - When pasting into a string literal with escaping, Unicode escape syntax should be used for non-ASCII characters
Summary: When pasting into a string literal with escaping, Unicode escape syntax shoul...
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.7   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 4.8 M3   Edit
Assignee: Till Brychcy CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-03-10 17:51 EST by Till Brychcy CLA
Modified: 2018-01-23 05:25 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 Till Brychcy CLA 2017-03-10 17:51:17 EST
To avoid encoding problems, we prefer to keep our source code in ASCII.
Especially when creating tests, it is often necessary non-ascii content in Strings.
Manually encoding this using \uXXXX is very cumbersome.

To make things easier, I propose adding an option that lets the "Escape text when pasting into a string literal"-Feature use Unicode escape syntax for all characters <32 or >127
Comment 1 Eclipse Genie CLA 2017-03-10 17:53:34 EST
New Gerrit change created: https://git.eclipse.org/r/92825
Comment 2 Till Brychcy CLA 2017-09-30 16:42:43 EDT
@Noopur, @Dani, is it OK if I add this feature?
Comment 3 Noopur Gupta CLA 2017-10-01 04:04:42 EDT
(In reply to Till Brychcy from comment #2)
> @Noopur, @Dani, is it OK if I add this feature?

It will be OK for me to add this feature though I am not sure if it should be enabled by default.

I quickly had a look at the Gerrit and noticed the following:
- the Javadoc of the new constant EDITOR_ESCAPE_STRINGS_NON_ASCII should be fixed.
- the new option should have a mnemonic.

Please make sure to add a N&N entry for any relevant fix/feature that you add.
Comment 5 Till Brychcy CLA 2017-10-10 01:33:30 EDT
(In reply to Noopur Gupta from comment #3)
> (In reply to Till Brychcy from comment #2)
> > @Noopur, @Dani, is it OK if I add this feature?
> 
> It will be OK for me to add this feature though I am not sure if it should
> be enabled by default.
Done: Disabled by default

> 
> I quickly had a look at the Gerrit and noticed the following:
> - the Javadoc of the new constant EDITOR_ESCAPE_STRINGS_NON_ASCII should be
> fixed.
Done

> - the new option should have a mnemonic.
Done.

> 
> Please make sure to add a N&N entry for any relevant fix/feature that you
> add.
Sure, will do that.

(In reply to Eclipse Genie from comment #4)
> Gerrit change https://git.eclipse.org/r/92825 was merged to [master].
> Commit:
> http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/
> ?id=80371eef36debbd7dcb3ee20d5518acd4ea5e10d

Released for 4.8M3
Comment 6 Noopur Gupta CLA 2017-10-18 02:16:09 EDT
(In reply to Till Brychcy from comment #5)
> > Please make sure to add a N&N entry for any relevant fix/feature that you
> > add.
> Sure, will do that.

The N&N doc for M3 is available for additions. Closing the bug as the patch has been released.
Comment 7 Eclipse Genie CLA 2017-10-18 13:58:45 EDT
New Gerrit change created: https://git.eclipse.org/r/110338
Comment 9 Sebastian Ratz CLA 2018-01-22 11:38:31 EST
Great feature, very useful!

However, I noticed a small problem:

The substitution is only performed if you paste more than one character -- a single pasted unicode character does not undergo the substitution due to the following length>1 check:

https://git.eclipse.org/r/plugins/gitiles/jdt/eclipse.jdt.ui/+/refs/changes/25/92825/2/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/JavaStringAutoIndentStrategy.java#199

Is this the intended behavior?
Comment 10 Till Brychcy CLA 2018-01-22 13:05:56 EST
(In reply to Sebastian Ratz from comment #9)
> Great feature, very useful!
> 
> However, I noticed a small problem:
> 
> The substitution is only performed if you paste more than one character -- a
> single pasted unicode character does not undergo the substitution due to the
> following length>1 check:
> 
> https://git.eclipse.org/r/plugins/gitiles/jdt/eclipse.jdt.ui/+/refs/changes/
> 25/92825/2/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/
> JavaStringAutoIndentStrategy.java#199

Hmm I haven't touched that line, it is from Bug 395257.

> 
> Is this the intended behavior?

Not really, maybe this is was just an optimization. But this needs a bit of examination.

As this bug is already resolved, can you please make a new one?
Comment 11 Sebastian Ratz CLA 2018-01-23 05:15:14 EST
There is already bug 209976 which is essentially the same. The the non-ASCII escaping feature makes it more prominent.

Should I create a new bug specific to non-ASCII escaping?
Comment 12 Till Brychcy CLA 2018-01-23 05:25:53 EST
(In reply to Sebastian Ratz from comment #11)
> There is already bug 209976 which is essentially the same. The the non-ASCII
> escaping feature makes it more prominent.
> 
> Should I create a new bug specific to non-ASCII escaping?

No, thanks for finding this.