Bug 251224 - [misc] Allow custom token for WhitespaceRule
Summary: [misc] Allow custom token for WhitespaceRule
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 3.4   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 3.5 M3   Edit
Assignee: Dani Megert CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-10-17 09:41 EDT by Anton Leherbauer CLA
Modified: 2008-10-20 10:32 EDT (History)
0 users

See Also:


Attachments
New constructor (2.66 KB, patch)
2008-10-17 09:45 EDT, Anton Leherbauer CLA
daniel_megert: iplog+
Details | Diff
Patch against JDT (891 bytes, patch)
2008-10-20 07:58 EDT, Anton Leherbauer CLA
no flags Details | Diff
Patch against JavaCodeScanner only (891 bytes, patch)
2008-10-20 08:26 EDT, Anton Leherbauer CLA
daniel_megert: iplog+
Details | Diff
Patch against JavaDocScanner only (869 bytes, patch)
2008-10-20 09:23 EDT, Anton Leherbauer CLA
daniel_megert: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Anton Leherbauer CLA 2008-10-17 09:41:18 EDT
The token returned by WhitespaceRule should be customizable.

The background is that this can help reduce the amount of style ranges created by the DefaultDamagerRepairer. Subsequent equal style ranges are merged while scanning the text. This is hindered by the whitespace token which does not contain a text attribute and the default text attribute of the DefaultDamagerRepairer in general does not match the text attribute of the default return token of the scanner. 
The result is that much more style ranges are created than necessary.
E.g. in the case of the Java editor, for StyledText.java currently 86620 style ranges are created, but only 57752 when exploiting this little optimization.
Comment 1 Anton Leherbauer CLA 2008-10-17 09:45:59 EDT
Created attachment 115391 [details]
New constructor

This adds a new constructor to WhitespaceRule taking the custom token.
Comment 2 Dani Megert CLA 2008-10-20 06:46:00 EDT
>The result is that much more style ranges are created than necessary.
>E.g. in the case of the Java editor, for StyledText.java currently 86620 style
>ranges are created, but only 57752 when exploiting this little optimization.
Anton, could you also add this to the patch (including for Properties file editor)?
Comment 3 Anton Leherbauer CLA 2008-10-20 07:58:42 EDT
Created attachment 115548 [details]
Patch against JDT

This patch enables the optimization for the Java editor.

The Properties file editor is different in that it does not define an "Other" highlighting category. So I don't see an easy way to improve things there.
Comment 4 Anton Leherbauer CLA 2008-10-20 08:26:22 EDT
Created attachment 115552 [details]
Patch against JavaCodeScanner only

I forgot to change the JavaDocScanner also.

The number of style ranges are (with default highlighting preferences):
- 75477 ranges before applying the patch
- 12893 after applying the patch

These are the numbers for plain syntax highlighting. Of course, semantic highlighting increases this number later on.
Comment 5 Dani Megert CLA 2008-10-20 09:02:12 EDT
Wow, you're fast: I was just about to ask for the Javadoc scanner ;-) However, the new patch seems to be a copy of the first one.

I've committed the first and second patch with some small changes:
- the field needs to be protected because the class can be subclassed by clients
- improved Javadoc for evaluate(...)
- added the following copyright entry:
Anton Leherbauer (Wind River Systems) - [misc] Allow custom token for WhitespaceRule - https://bugs.eclipse.org/bugs/show_bug.cgi?id=251224

Thanks for your help!
Comment 6 Anton Leherbauer CLA 2008-10-20 09:12:46 EDT
(In reply to comment #5)
> Wow, you're fast: I was just about to ask for the Javadoc scanner ;-) However,
> the new patch seems to be a copy of the first one.

Maybe I was too fast ;-)
Thanks!
Comment 7 Anton Leherbauer CLA 2008-10-20 09:23:42 EDT
Created attachment 115556 [details]
Patch against  JavaDocScanner only

Second try.
Comment 8 Dani Megert CLA 2008-10-20 09:45:12 EDT
Committed the latest patch to HEAD.
Available in builds > N20081019-2000.