Skip to content

Conversation

@mbien
Copy link
Member

@mbien mbien commented Oct 20, 2025

Switched to non-deprecated editor utilities API.

PR is split into commits which usually handle a method pair.

note to first commit:

LineDocumentUtils unfortunately broke symmetry in getLine[Start/End]:

  • getLineStart didn't declare BadLocationException to be thrown and did not have any range checks
  • getRowStart declared BadLocationException but called getLineStart which can't throw the Exception

to resolve this I had to add getLine[Start/End]Offset and deprecate getLine[Start/End]:

  • getLine[Start/End]Offset checks the range and declares BadLocationException, just like the getLineEnd sibling did.
  • this makes the API symmetrical and allows the try-catch blocks (which had to be already implemented) to function

its ugly but this was the best option I came up with.

@mbien mbien added this to the NB29 milestone Oct 20, 2025
@mbien mbien added Code cleanup ci:all-tests [ci] enable all tests labels Oct 20, 2025
@mbien mbien force-pushed the editor-utilities-deprecation-fixes branch from c872fe9 to fc386c5 Compare November 18, 2025 02:14
@mbien mbien marked this pull request as ready for review November 18, 2025 02:31
Comment on lines 71 to 92
/**
* Get start offset of a (newline character separated) line.
* @param doc non-null document to operate on
* @param offset position in document where to start searching
* @return offset of character right above newline prior the given offset or zero.
* @throws javax.swing.text.BadLocationException If offset is out of bounds
*/
public static int getLineStart2(@NonNull LineDocument doc, int offset) throws BadLocationException {
checkOffsetValid(doc, offset);
return doc.getParagraphElement(offset).getStartOffset();
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new method. the old is now deprecated

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's ugly. Surely we can get a slightly better name here? Maybe getLineStartOffset / getLineEndOffset or findLineStart / findLineEnd, or even lineStart / lineEnd? Be good to document the line end method while you're at it. Change should probably go in apichanges.xml.

@ebarboni should consider changes required to get this module in Javadoc too?

Copy link
Member Author

@mbien mbien Dec 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was actually about to rename it, but this got delayed since I noticed while rebasing that the file history tab sorts git commits by AuthorDate not CommitDate, which confused me since I thought i merged into the wrong direction. Something we probably should fix. (git log --pretty=fuller shows both dates)

i like lineStart / lineEnd will update it soon

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on second thought: getLineStartOffset is probably better since it doesn't break the get* naming pattern + the methods return getStartOffset() of javax.​swing.​text.​Element

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's ugly. Surely we can get a slightly better name here? Maybe getLineStartOffset / getLineEndOffset or findLineStart / findLineEnd, or even lineStart / lineEnd? Be good to document the line end method while you're at it. Change should probably go in apichanges.xml.

@ebarboni should consider changes required to get this module in Javadoc too?

Maybe looks like there is around 20 modules not in apidoc that hava apichanges.xml. Will try to list them. No findings on bz of api/spi move or so but AFAIK editor.document is not in apidoc since the begining.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mbien added 3 commits December 2, 2025 19:34
…Offset

avoid using deprecated NB API to reduce warning noise

adds getLine[Start/End]Offset and deprecates getLine[Start/End]

 - getLineStart didn't declare BadLocationException to be thrown
   and did not make any range checks
 - getRowStart declared BadLocationException but called getLineStart
   which can't throw the Exception
 - getLineStartOffset checks the range and declares
   BadLocationException just like the getLineEndOffset sibling.
 - this makes the API symmetrical and allows the catch blocks (which
   had to be already implemented) to function
@mbien mbien force-pushed the editor-utilities-deprecation-fixes branch 2 times, most recently from 210afcf to b4204ec Compare December 2, 2025 18:58
@mbien
Copy link
Member Author

mbien commented Dec 2, 2025

duplicated code strikes again

@mbien mbien force-pushed the editor-utilities-deprecation-fixes branch from b4204ec to 034d38d Compare December 2, 2025 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:all-tests [ci] enable all tests Code cleanup

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants