OpenOffice refactoring- subtask: Break down large methods like guiActionInsertEntry()#15380
OpenOffice refactoring- subtask: Break down large methods like guiActionInsertEntry()#15380anuv-bit wants to merge 30 commits intoJabRef:mainfrom
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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"); |
There was a problem hiding this comment.
Please revert these renamings - since they are function-local, they needn't be more specific
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
These are more like class names - please use names denoting actions for methods
| LOGGER.error("Could not insert entry", e); | ||
| OOError.fromMisc(e).setTitle(errorTitle).showErrorDialog(dialogService); | ||
| throw new RuntimeException(e); |
There was a problem hiding this comment.
Shouldn't this still use OOError.fromMisc?
There was a problem hiding this comment.
Honestly no clue when or why that happened. Might have been a IDE suggestion change in another area that affected this. I can assure you it was not intentional.
|
Could you please also extract methods for JStyle and CSL in |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…ame methods for clarity
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Thank you for the guidance @pluto-han. I extracted a 'performPreUpdateChecks()' method similar to the 'performPreInsertionChecks()' method extracted from |
Thank you for helping in reviews @pluto-han! |
For me, I would prefer include try-catch as well for more readability, but I am not maintainer cannot simply decide it. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| } | ||
|
|
||
| syncOptions.map(e -> e.setAlwaysAddCitedOnPages(openOfficePreferences.getAlwaysAddCitedOnPages())); | ||
| syncOptions.ifPresent(e -> e.setAlwaysAddCitedOnPages(openOfficePreferences.getAlwaysAddCitedOnPages())); |
There was a problem hiding this comment.
Since syncOptions has already been checked in if, you can move syncOptions.ifPresent(e -> e.setAlwaysAddCitedOnPages(openOfficePreferences.getAlwaysAddCitedOnPages())); into if block
| List<BibEntry> citedEntries = databases.stream() | ||
| .flatMap(database -> database.getEntries().stream()) | ||
| .filter(cslCitationOOAdapter::isCitedEntry) | ||
| .toList(); |
There was a problem hiding this comment.
This makes citedEntries an immutable list. Modifying (e.g. CSLCitationOOAdapter#L206: entries.sort()) the list throws an exception.
| // Found one, no need to look further for now | ||
|
|
||
| boolean emptyKeys = entries.stream() |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
✅ All tests passed ✅🏷️ Commit: ed2a2a2 Learn more about TestLens at testlens.app. |
Related issues and pull requests
Closes #11829
PR Description
This PR focuses on the subtasks, such as breaking down the large methods guiActionInsertEntry() and guiActionUpdateDocument() in OOBibBase.java. It also focuses on the use of more constants instead of magic strings. Also addresses the subtask of using modern Java features(streams and Optional chaining). Next steps would be making sure changes line up with the guidelines.
Checklist
CHANGELOG.mdin a way that can be understood by the average user (if change is visible to the user)