-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
OpenOffice Refactor subtasks #15380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OpenOffice Refactor subtasks #15380
Changes from 50 commits
7cdc3af
48f8eb4
5870f9d
de7dd85
33689a4
f518aac
e5e218a
3e5877c
ca13ca0
93a78a6
1ab2595
16ba9e8
13c7f4d
618a6b4
f6b3709
d1cffb6
b857f68
7b4ec49
2e9cd37
7f807e2
6b2de1f
d08ed3d
734bf9d
0751f17
c552f58
2d0e663
ff016c5
13f49ab
59bc3ec
ed2a2a2
6a4e06e
272b074
eb13470
69c9671
dbdd05d
d3914c1
0b66b9f
cbb41e0
b260df5
562cb7d
83a2429
16b2939
bb13c26
85d38c7
57db384
e479a65
17366a2
66768cf
16ac73b
7e8f94d
ce2289a
7cb6768
24b00f4
7d527d6
0c834b4
c637726
588b4c6
b8c44c3
0aa82de
793d4dd
3671985
8bcab01
8d965bb
4d74798
f046095
f4c73d5
9c871e0
23b43b0
0d28a32
3c7015b
84fe9ad
0179d92
d363569
72aa46d
c87eee4
dfb0bac
27b9b6d
62a666c
329c93f
8ad1e37
1484221
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -218,19 +218,10 @@ public boolean isDocumentConnectionMissing() { | |
| return false; | ||
| } | ||
|
|
||
| /// Either return a valid XTextDocument or throw NoDocumentException. | ||
| public XTextDocument getXTextDocumentOrThrow() | ||
| throws | ||
| NoDocumentException { | ||
| if (isDocumentConnectionMissing()) { | ||
| throw new NoDocumentException("Not connected to document"); | ||
| } | ||
| return this.xTextDocument; | ||
| } | ||
|
|
||
| /// Returns either a valid XTextDocument in OOResult or a NoDocumentException error | ||
| public OOResult<XTextDocument, OOError> getXTextDocument() { | ||
| if (isDocumentConnectionMissing()) { | ||
| return OOResult.error(OOError.from(new NoDocumentException())); | ||
| return OOResult.error(OOError.from(new NoDocumentException("Not connected to document"))); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to add error message. |
||
| } | ||
| return OOResult.ok(this.xTextDocument); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -141,6 +141,9 @@ private static boolean checkAddToGroup(ScanState state, CitationGroup group, XTe | |
| return false; | ||
| } | ||
|
|
||
| final String exceptionTitle = "MergeCitationGroups failed"; | ||
| final String loggerMessage = "MergeCitationGroups: cursorBetween.end != currentGroupCursor.end"; | ||
|
|
||
| Objects.requireNonNull(state.currentGroupCursor); | ||
| Objects.requireNonNull(state.cursorBetween); | ||
| Objects.requireNonNull(state.prev); | ||
|
|
@@ -187,14 +190,21 @@ private static boolean checkAddToGroup(ScanState state, CitationGroup group, XTe | |
|
|
||
| // assume: currentGroupCursor.getEnd() == cursorBetween.getEnd() | ||
| if (UnoTextRange.compareEnds(state.cursorBetween, state.currentGroupCursor) != 0) { | ||
| LOGGER.warn("MergeCitationGroups: cursorBetween.end != currentGroupCursor.end"); | ||
| throw new IllegalStateException("MergeCitationGroups failed"); | ||
| LOGGER.warn(loggerMessage); | ||
| throw new IllegalStateException(exceptionTitle); | ||
|
qodo-free-for-open-source-projects[bot] marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| /* | ||
| * Try to expand state.currentGroupCursor and state.cursorBetween by going right to reach | ||
| * rangeStart. | ||
| */ | ||
|
Comment on lines
-194
to
-197
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment should not be lost |
||
| return checkCouldExpand(state, currentRange, loggerMessage, exceptionTitle); | ||
| } | ||
|
|
||
| /// Helper method for checkAddToGroup. Tries to expand state.currentGroupCursor and state.cursorBetween by going right to reach rangeStart. | ||
| /// | ||
| /// @param state The CitationGroup to test. | ||
| /// @param currentRange The XTextRange corresponding to group. | ||
| /// @param loggerMessage The failure message for the LOGGER. | ||
| /// @param exceptionTitle The custom exception message. | ||
| /// @return false if cannot expand, true if can. | ||
| private static boolean checkCouldExpand(ScanState state, XTextRange currentRange, String loggerMessage, String exceptionTitle) { | ||
| XTextRange rangeStart = currentRange.getStart(); | ||
| boolean couldExpand = true; | ||
| XTextCursor thisCharCursor = | ||
|
|
@@ -219,11 +229,10 @@ private static boolean checkAddToGroup(ScanState state, CitationGroup group, XTe | |
|
|
||
| // These two should move in sync: | ||
| if (UnoTextRange.compareEnds(state.cursorBetween, state.currentGroupCursor) != 0) { | ||
| LOGGER.warn("MergeCitationGroups: cursorBetween.end != currentGroupCursor.end (during expand)"); | ||
| throw new IllegalStateException("MergeCitationGroups failed"); | ||
| LOGGER.warn(loggerMessage + " (during expand)"); | ||
| throw new IllegalStateException(exceptionTitle); | ||
| } | ||
| } | ||
|
|
||
| return couldExpand; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -247,6 +247,13 @@ public XTextCursor getFillCursor(XTextDocument doc) | |
| if (fullText.length() < 2) { | ||
| throw new IllegalStateException("getFillCursor: fullText.length() < 2 (after loop)'%n"); | ||
| } | ||
|
|
||
| // NamedRangeReferenceMark.checkFillCursor(beta); | ||
| return getStringForFillCursor(full, fullText, debugThisFun); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the point of this comment?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it looks like its a statement that i happened to miss when extracting
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we really need this refactoring? Reasons:
This feels like a refactoring for the sake of refactoring.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fair enough. i am really bad at naming methods honestly. ill work on reverting this change |
||
| } | ||
|
|
||
| /// Helper method for getFillCursor | ||
| public XTextCursor getStringForFillCursor(XTextCursor full, String fullText, boolean debugThisFun) { | ||
| XTextCursor beta = full.getText().createTextCursorByRange(full); | ||
| beta.collapseToStart(); | ||
| beta.goRight((short) 1, false); | ||
|
|
@@ -311,8 +318,6 @@ public XTextCursor getFillCursor(XTextDocument doc) | |
| LOGGER.debug("getFillCursor: omega(8) covers '{}', should be '{}'", omega.getString(), right); | ||
| } | ||
| } | ||
|
|
||
| // NamedRangeReferenceMark.checkFillCursor(beta); | ||
| return beta; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -320,34 +320,7 @@ private void updateAllCitationsWithNewStyle(CitationStyle style, CSLCitationType | |
| StringBuilder finalText = new StringBuilder(); | ||
| Iterator<BibEntry> iterator = entries.iterator(); | ||
|
|
||
| while (iterator.hasNext()) { | ||
| BibEntry currentEntry = iterator.next(); | ||
|
|
||
| // We re-generate the citation in the new style and update it in the document | ||
| String newCitation; | ||
|
|
||
| if (isAlphaNumericStyle) { | ||
| newCitation = CSLFormatUtils.generateAlphanumericInTextCitation(currentEntry, unifiedBibDatabaseContext); | ||
| } else { | ||
| newCitation = CitationStyleGenerator.generateCitation(List.of(currentEntry), style.getSource(), HTML_OUTPUT_FORMAT, unifiedBibDatabaseContext, bibEntryTypesManager); | ||
| } | ||
|
|
||
| String formattedCitation = CSLFormatUtils.transformHTML(newCitation); | ||
|
|
||
| if (isNumericStyle) { | ||
| formattedCitation = updateSingleOrMultipleCitationNumbers(formattedCitation, List.of(currentEntry)); | ||
| String prefix = CSLFormatUtils.generateAuthorPrefix(currentEntry, unifiedBibDatabaseContext); | ||
| formattedCitation = prefix + formattedCitation; | ||
| } else if (!isAlphaNumericStyle) { | ||
| formattedCitation = CSLFormatUtils.changeToInText(formattedCitation); | ||
| } | ||
|
|
||
| finalText.append(formattedCitation); | ||
|
|
||
| if (iterator.hasNext()) { | ||
| finalText.append(","); | ||
| } | ||
| } | ||
| updateCitations(style, iterator, unifiedBibDatabaseContext, finalText); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure about this,
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hello, thank you for the suggestion. I have reverted the initial refactoring and extracted duplicate logic from those three methods in 'CSLCitationOOAdapter'. |
||
|
|
||
| markManager.updateMarkAndTextWithNewStyle(mark, finalText.toString(), CSLCitationType.IN_TEXT); | ||
| } | ||
|
|
@@ -377,6 +350,46 @@ private void updateAllCitationsWithNewStyle(CitationStyle style, CSLCitationType | |
| } | ||
| } | ||
|
|
||
| /// Helper method for updateAllCitationsWithNewStyle. | ||
| /// | ||
| /// @param style The current style we are using. | ||
| /// @param iterator Used to iterate through entries. | ||
| /// @param unifiedBibDatabaseContext Used to generate citations. | ||
| /// @param finalText Resulting text for updated citations. | ||
| private void updateCitations(CitationStyle style, Iterator<BibEntry> iterator, BibDatabaseContext unifiedBibDatabaseContext, StringBuilder finalText) { | ||
| boolean isAlphaNumericStyle = style.isAlphanumericStyle(); | ||
| boolean isNumericStyle = style.isNumericStyle(); | ||
|
|
||
| while (iterator.hasNext()) { | ||
| BibEntry currentEntry = iterator.next(); | ||
|
|
||
| // We re-generate the citation in the new style and update it in the document | ||
| String newCitation; | ||
|
|
||
| if (isAlphaNumericStyle) { | ||
| newCitation = CSLFormatUtils.generateAlphanumericInTextCitation(currentEntry, unifiedBibDatabaseContext); | ||
| } else { | ||
| newCitation = CitationStyleGenerator.generateCitation(List.of(currentEntry), style.getSource(), HTML_OUTPUT_FORMAT, unifiedBibDatabaseContext, bibEntryTypesManager); | ||
| } | ||
|
|
||
| String formattedCitation = CSLFormatUtils.transformHTML(newCitation); | ||
|
|
||
| if (isNumericStyle) { | ||
| formattedCitation = updateSingleOrMultipleCitationNumbers(formattedCitation, List.of(currentEntry)); | ||
| String prefix = CSLFormatUtils.generateAuthorPrefix(currentEntry, unifiedBibDatabaseContext); | ||
| formattedCitation = prefix + formattedCitation; | ||
| } else if (!isAlphaNumericStyle) { | ||
| formattedCitation = CSLFormatUtils.changeToInText(formattedCitation); | ||
| } | ||
|
|
||
| finalText.append(formattedCitation); | ||
|
|
||
| if (iterator.hasNext()) { | ||
| finalText.append(","); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Checks if an entry has already been cited before in the document. | ||
| /// Required for consistent numbering of numeric citations - if present, the number is to be reused, else a new number is to be assigned. | ||
| public boolean isCitedEntry(BibEntry entry) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.