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
|
@anuv-bit @amanda-d-e can you tick "Allow maintainers to edit this pull request" on the right hand side? |
subhramit
left a comment
There was a problem hiding this comment.
Some refactoring has changed semantics - need to double check
| /* | ||
| * Try to expand state.currentGroupCursor and state.cursorBetween by going right to reach | ||
| * rangeStart. | ||
| */ |
There was a problem hiding this comment.
This comment should not be lost
| 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)) { |
There was a problem hiding this comment.
This changes semantics (the order of returning if checks at a particular stage fail)
| 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)) { |
| // Release controller lock | ||
| doc.unlockControllers(); | ||
| } | ||
| insertCSLCitation(entries, doc, citationType, citationStyle, bibDatabaseContext, bibEntryTypesManager, cursor, syncOptions); |
There was a problem hiding this comment.
For >=4 arguments, each should go into a new line for readability
| 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 { |
| 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) |
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. |
Hey @subhramit, I clicked it. |
jablib/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLCitationOOAdapter.java
Show resolved
Hide resolved
subhramit
left a comment
There was a problem hiding this comment.
One more iteration of comments. Thanks for keeping patience and following up so far.
jablib/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLCitationOOAdapter.java
Outdated
Show resolved
Hide resolved
jablib/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLCitationOOAdapter.java
Outdated
Show resolved
Hide resolved
jablib/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLCitationOOAdapter.java
Outdated
Show resolved
Hide resolved
jablib/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLCitationOOAdapter.java
Outdated
Show resolved
Hide resolved
jablib/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLCitationOOAdapter.java
Outdated
Show resolved
Hide resolved
jablib/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLCitationOOAdapter.java
Outdated
Show resolved
Hide resolved
jablib/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLCitationOOAdapter.java
Outdated
Show resolved
Hide resolved
jablib/src/main/java/org/jabref/logic/openoffice/frontend/OOFrontend.java
Show resolved
Hide resolved
| List<String> unresolvedKeys; | ||
| try { | ||
| UnoUndo.enterUndoContext(doc, "Refresh bibliography"); | ||
| if (!performPreUpdateChecks(errorTitle, odoc, style, getFrontend(doc), fcursor, doc)) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
…CitationOOAdapter.java Co-authored-by: Subhramit Basu <subhramit.bb@live.in>
Co-authored-by: Subhramit Basu <subhramit.bb@live.in>
f675f0c to
d363569
Compare
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
CHANGELOG.mdin a way that can be understood by the average user (if change is visible to the user)