Skip to content

OpenOffice Refactor subtasks#15380

Open
anuv-bit wants to merge 79 commits intoJabRef:mainfrom
anuv-bit:fixes-for-issue-11829
Open

OpenOffice Refactor subtasks#15380
anuv-bit wants to merge 79 commits intoJabRef:mainfrom
anuv-bit:fixes-for-issue-11829

Conversation

@anuv-bit
Copy link
Copy Markdown

@anuv-bit anuv-bit commented Mar 20, 2026

Related issues and pull requests

Closes #11829

PR Description

This PR focuses on several subtasks, such as:

Break down large methods like guiActionInsertEntry() - the refactoring technique ‘extract method’ was used on long methods or repeated blocks of code in ‘OOBibBase’, ‘EditMerge’, ‘OOFrontend’, and ‘CSLCitationOOAdapter’ in order to increase readability and modifiability.

Using more constants instead of magic strings - this task focused on replacing repeated magic strings with named constants across OOBibBase.java, OpenOfficePanel.java, and EditMerge.java to improve readability and reduce duplicated elements.

Using modern Java features(streams and Optional chaining) - this task focused on replacing for loops with stream pipelines using flatMap(), filter(), and anyMatch(). Additionally, getBaseList() was refactored to use streams while preserving mutability.

Unification of error handling methods - Instead of throwing runtime exceptions, we standardized the use of logging combined with OOError dialogs, minimizing the use of throwing exceptions without being caught by some other area of code.

Additionally, this PR includes some minor refactorings such as removing unused parameters and duplicate methods.

Checklist

  • I own the copyright of the code submitted and I license it under the MIT license
  • I manually tested my changes in running JabRef (always required)
  • [/] I added JUnit tests for changes (if applicable)
  • [/] I added screenshots in the PR description (if change is visible to the user)
  • [/] I added a screenshot in the PR description showing a library with a single entry with me as author and as title the issue number
  • [/] I described the change in CHANGELOG.md in a way that can be understood by the average user (if change is visible to the user)
  • [/] I checked the user documentation for up to dateness and submitted a pull request to our user documentation repository

@anuv-bit anuv-bit changed the title Fix-for-issue #11829- subtask: Break down large methods like guiActionInsertEntry() OpenOffice refactoring- subtask: Break down large methods like guiActionInsertEntry() Mar 20, 2026
@github-actions github-actions bot added status: changes-required Pull requests that are not yet complete status: no-bot-comments and removed status: changes-required Pull requests that are not yet complete labels Mar 20, 2026
@testlens-app

This comment has been minimized.

@testlens-app

This comment has been minimized.

@testlens-app

This comment has been minimized.

@testlens-app

This comment has been minimized.

@testlens-app

This comment has been minimized.

@testlens-app

This comment has been minimized.

@testlens-app

This comment has been minimized.

@testlens-app

This comment has been minimized.


public void guiActionSelectDocument(boolean autoSelectForSingle) throws WrappedTargetException, NoSuchElementException {
final String errorTitle = Localization.lang("Problem connecting");
final String connectionError = Localization.lang("Problem connecting");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please revert these renamings - since they are function-local, they needn't be more specific

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Understood, I reverted them. Are there more magic strings that you would like replaced with constants (that I have not already replaced)? My understanding was that not every single string needed to be replaced with a constant, especially in cases where the string is unique and is only used once.

Thank you!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These above were not magic strings. They were already constants.
Yes, ideally we extract constants for strings used more than once.
But there is one other case - when the string reduces readability of the code, or is long.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thank you for the confirmation! To clarify: I was referring to changes made in a previous commit in which I did replace magic strings with constants, not this commit which was just renaming the existing constants.

/// @param citationType Indicates whether it is an in-text citation, a citation in parenthesis or an invisible citation.
/// @param citationStyle Indicates style, name and path of citation
/// @param syncOptions Indicates whether in-text citations should be refreshed in the document. Optional.empty() indicates no refresh. Otherwise, provides options for refreshing the reference list.
public void guiActionCSLCitationHandler(List<BibEntry> entries, XTextDocument doc, CitationType citationType, CitationStyle citationStyle,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These are more like class names - please use names denoting actions for methods

@subhramit
Copy link
Copy Markdown
Member

@anuv-bit @amanda-d-e can you tick "Allow maintainers to edit this pull request" on the right hand side?
We wish to finish the remaining changes and get this in.

Copy link
Copy Markdown
Member

@subhramit subhramit left a comment

Choose a reason for hiding this comment

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

Some refactoring has changed semantics - need to double check

Comment on lines -194 to -197
/*
* Try to expand state.currentGroupCursor and state.cursorBetween by going right to reach
* rangeStart.
*/
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This comment should not be lost

Comment on lines +649 to +674
if (testDialog(errorTitle,
odoc.asVoidResult(),
styleIsRequired(jStyle),
databaseIsRequired(databases, OOError::noDataBaseIsOpen))) {
return;
}

XTextDocument doc = odoc.get();

OOResult<FunctionalTextViewCursor, OOError> fcursor = getFunctionalTextViewCursor(doc, errorTitle);

if (testDialog(errorTitle,
fcursor.asVoidResult(),
checkStylesExistInTheDocument(jStyle, doc),
checkIfOpenOfficeIsRecordingChanges(doc))) {
if (!performPreMergeSeparateChecks(databases, errorTitle, odoc, jStyle, fcursor, doc)) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This changes semantics (the order of returning if checks at a particular stage fail)

Comment on lines +703 to +720
if (testDialog(errorTitle,
odoc.asVoidResult(),
styleIsRequired(jStyle),
databaseIsRequired(databases, OOError::noDataBaseIsOpen))) {
return;
}

XTextDocument doc = odoc.get();

OOResult<FunctionalTextViewCursor, OOError> fcursor = getFunctionalTextViewCursor(doc, errorTitle);

if (testDialog(errorTitle,
fcursor.asVoidResult(),
checkStylesExistInTheDocument(jStyle, doc),
checkIfOpenOfficeIsRecordingChanges(doc))) {
if (!performPreMergeSeparateChecks(databases, errorTitle, odoc, jStyle, fcursor, doc)) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same here

@github-actions github-actions bot added status: changes-required Pull requests that are not yet complete and removed status: no-bot-comments labels Apr 4, 2026
Copy link
Copy Markdown
Member

@subhramit subhramit left a comment

Choose a reason for hiding this comment

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

Other cosmetic comments

// Release controller lock
doc.unlockControllers();
}
insertCSLCitation(entries, doc, citationType, citationStyle, bibDatabaseContext, bibEntryTypesManager, cursor, syncOptions);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For >=4 arguments, each should go into a new line for readability

Comment on lines +606 to +608
public void insertCSLCitation(List<BibEntry> entries, XTextDocument doc, CitationType citationType, CitationStyle citationStyle,
BibDatabaseContext bibDatabaseContext, BibEntryTypesManager bibEntryTypesManager, OOResult<XTextCursor, OOError> cursor,
Optional<Update.SyncOptions> syncOptions) throws CreationException, com.sun.star.uno.Exception {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Each parameter in new line

Comment on lines +645 to +647
public void insertJStyleCitation(List<BibEntry> entries, XTextDocument doc, CitationType citationType, JStyle jStyle, OOResult<OOFrontend, OOError> frontend,
OOResult<XTextCursor, OOError> cursor, BibDatabaseContext bibDatabaseContext, Optional<Update.SyncOptions> syncOptions,
String pageInfo, OOResult<FunctionalTextViewCursor, OOError> fcursor)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same as above

@amanda-d-e
Copy link
Copy Markdown

@anuv-bit @amanda-d-e can you tick "Allow maintainers to edit this pull request" on the right hand side? We wish to finish the remaining changes and get this in.

Hello @subhramit, I think that @anuv-bit has to allow maintainers to edit the pull request since she is the one who made it, so I will try to get in contact with her as soon as possible. Apologies for the inconvenience, and thank you for all of the feedback and guidance.

@anuv-bit
Copy link
Copy Markdown
Author

anuv-bit commented Apr 4, 2026

@anuv-bit @amanda-d-e can you tick "Allow maintainers to edit this pull request" on the right hand side? We wish to finish the remaining changes and get this in.

Hey @subhramit, I clicked it.

@github-actions github-actions bot added status: no-bot-comments and removed status: changes-required Pull requests that are not yet complete labels Apr 8, 2026
Copy link
Copy Markdown
Member

@subhramit subhramit left a comment

Choose a reason for hiding this comment

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

One more iteration of comments. Thanks for keeping patience and following up so far.

List<String> unresolvedKeys;
try {
UnoUndo.enterUndoContext(doc, "Refresh bibliography");
if (!performPreUpdateChecks(errorTitle, odoc, style, getFrontend(doc), fcursor, doc)) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As mentioned in an earlier comment, this changes semantics - for example, fcursor was earlier being fetched only if doc, odoc passed the earlier checks, etc.

Please revert.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hello @subhramit, I have reverted the extracted method. I think that should be the last of the requested fixes, but please let me know if we are missing anything or if you would like anything else changed.

Thank you for your guidance. This has been a very valuable learning experience for my group and I, and we appreciate the opportunity to work on this issue.

@github-actions github-actions bot added status: changes-required Pull requests that are not yet complete and removed status: no-bot-comments labels Apr 8, 2026
anuv-bit and others added 2 commits April 8, 2026 11:52
@github-actions github-actions bot added status: no-bot-comments and removed status: changes-required Pull requests that are not yet complete labels Apr 8, 2026
@anuv-bit anuv-bit force-pushed the fixes-for-issue-11829 branch 2 times, most recently from f675f0c to d363569 Compare April 9, 2026 04:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Project: Refactor and unify JabRef OO components

5 participants