mbien commented on code in PR #8011:
URL: https://github.com/apache/netbeans/pull/8011#discussion_r1870353730
##########
ide/csl.api/src/org/netbeans/modules/csl/editor/semantic/GsfSemanticLayer.java:
##########
@@ -233,101 +187,61 @@ public int getShiftedPos(int pos) {
* of ranges (e.g. for every highlight in the whole document) whereas
asking for the
* current positions is typically only done for the highlights visible on
the screen.
*/
- private class Edit {
- public Edit(int offset, int len, boolean insert) {
- this.offset = offset;
- this.len = len;
- this.insert = insert;
- }
-
- int offset;
- int len;
- boolean insert; // true: insert, false: delete
- }
+ private record Edit(int offset, int len, boolean insert) {}
/**
* An implementation of a HighlightsSequence which can show OffsetRange
* sections and keep them up to date during edits.
*
* @author Tor Norbye
*/
- private static final class GsfHighlightSequence implements
HighlightsSequence {
- private Iterator<SequenceElement> iterator;
+ private final class GsfHighlightSequence implements HighlightsSequence {
+ private final Iterator<SequenceElement> iterator;
private SequenceElement element;
- private final GsfSemanticLayer layer;
- private final int endOffset;
- private SequenceElement nextElement;
- private int nextElementStartOffset = Integer.MAX_VALUE;
- GsfHighlightSequence(GsfSemanticLayer layer, Document doc,
- int startOffset, int endOffset,
- SortedSet<SequenceElement> colorings) {
- this.layer = layer;
- this.endOffset = endOffset;
-
- SequenceElement.ComparisonItem fromInclusive = new
SequenceElement.ComparisonItem(startOffset);
- SortedSet<SequenceElement> subMap =
colorings.tailSet(fromInclusive);
- iterator = subMap.iterator();
- }
-
- private SequenceElement fetchElementFromIterator(boolean
updateNextElementStartOffset) {
- int seStartOffset;
- SequenceElement se;
- if (iterator != null && iterator.hasNext()) {
- se = iterator.next();
- seStartOffset = se.range.getStart();
- if (LOG.isLoggable(Level.FINE)) {
- LOG.log(Level.FINE, "Fetched highlight <{0},{1}>\n", //
NOI18N
- new Object[]{seStartOffset, se.range.getEnd()});
- }
- if (seStartOffset >= endOffset) {
- se = null;
- seStartOffset = Integer.MAX_VALUE;
- iterator = null;
- }
- } else {
- se = null;
- seStartOffset = Integer.MAX_VALUE;
- iterator = null;
- }
- if (updateNextElementStartOffset) {
- nextElementStartOffset = seStartOffset;
- }
- return se;
+ GsfHighlightSequence(Iterator<SequenceElement> it) {
+ iterator = it;
}
@Override
public boolean moveNext() {
- if (nextElement != null) {
- element = nextElement;
- nextElement = fetchElementFromIterator(true);
- } else {
- if ((element = fetchElementFromIterator(false)) != null) {
- nextElement = fetchElementFromIterator(true);
- }
- }
- return (element != null);
+ element = iterator.hasNext() ? iterator.next() : null;
+ return element != null;
}
@Override
public int getStartOffset() {
- return (element != null)
- ? layer.getShiftedPos(element.range.getStart())
- : Integer.MAX_VALUE;
+ return getShiftedPos(element.range().getStart());
}
@Override
public int getEndOffset() {
- return (element != null)
- ? Math.min(layer.getShiftedPos(element.range.getEnd()),
nextElementStartOffset)
- : Integer.MAX_VALUE;
+ return getShiftedPos(element.range().getEnd());
}
Review Comment:
your choice. Commit messages is all what is left in the repo history once
merged. If they describe what they do -> all good. But if you want to split
this into two PRs -> also good of course.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists