Persist citation nature in the CSL reference mark#15437
Conversation
Review Summary by QodoPersist citation type in CSL reference marks using enum
WalkthroughsDescription• Replace boolean inText variable with CSLCitationType enum • Embed citation type (NORMAL/IN_TEXT/EMPTY) into CSL reference marks • Update reference mark format to persist citation nature across document operations • Refactor citation type tracking throughout adapter and manager classes Diagramflowchart LR
A["Boolean inText"] -->|Replace with| B["CSLCitationType Enum"]
B -->|NORMAL| C["Reference Mark Format"]
B -->|IN_TEXT| C
B -->|EMPTY| C
C -->|Embedded in| D["Citation Persistence"]
File Changes1. jablib/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLCitationType.java
|
Code Review by Qodo
1.
|
| CSLReferenceMark mark = new CSLReferenceMark(named, referenceMark); | ||
| marksByName.put(name, mark); | ||
| marksInOrder.add(mark); | ||
| isInTextCite = isInTextCite || referenceMark.isInText(); | ||
| citationType = referenceMark.getCitationType(); | ||
|
|
There was a problem hiding this comment.
3. Citation type derived from last 🐞 Bug ✓ Correctness
CSLReferenceMarkManager.readAndUpdateExistingMarks overwrites the manager-wide citationType for each mark and ends up returning the last mark’s type. If a document contains mixed/legacy marks, CSLCitationOOAdapter can skip required global updates or apply the wrong global conversion, leaving mixed citation types in the document.
Agent Prompt
### Issue description
`readAndUpdateExistingMarks` sets `citationType` to the last mark’s type, which can be wrong when marks differ (common for legacy docs or corrupted state) and causes the adapter’s global-update decision to be incorrect.
### Issue Context
The adapter relies on a document-wide citation type to decide whether it must rewrite all existing citations before inserting a new one.
### Fix Focus Areas
- jablib/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLReferenceMarkManager.java[129-163]
- jablib/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLCitationOOAdapter.java[57-71]
- jablib/src/main/java/org/jabref/logic/openoffice/oocsltext/CSLCitationOOAdapter.java[80-100]
### Suggested fix
Compute document citationType by aggregating across all marks (e.g., if any EMPTY -> EMPTY, else if any IN_TEXT -> IN_TEXT, else NORMAL), and optionally log a warning if multiple types are found. Ensure the adapter refreshes its `citationType` from the manager after `readAndUpdateExistingMarks()` in workflows that depend on the current document state.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
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.
| } | ||
| if (referenceMarkName.endsWith(ReferenceMark.EMPTY_MARKER)) { |
There was a problem hiding this comment.
Forgot else? Or chosen deliberately?
There was a problem hiding this comment.
If chosen deliberately, please make a comment
There was a problem hiding this comment.
It should be else if. But maybe we can use a switch like the comment above?
There was a problem hiding this comment.
It should be
else if. But maybe we can use a switch like the comment above?
I think we can keep if, as switch cannot be followed by boolean expression.
There was a problem hiding this comment.
I think we can keep if, as switch cannot be followed by boolean expression.
You "can" switch over referenceMarkName.substring(lastIndexOf(" ") +1) but that will be much less readable. If else is fine here.
There was a problem hiding this comment.
I made some small refactors to updateMarkAndTextWithNewStyle, is it better?
This comment has been minimized.
This comment has been minimized.
calixtus
left a comment
There was a problem hiding this comment.
Did not expect to have that huge impacht in simplification with the enum, but it turned out great. Thanks so far. Just one comment on a switch
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| updatedName = updatedName.substring(0, updatedName.length() - ReferenceMark.IN_TEXT_MARKER.length() - 1); | ||
| } else if (updatedName.endsWith(ReferenceMark.EMPTY_MARKER)) { | ||
| updatedName = updatedName.substring(0, updatedName.length() - ReferenceMark.EMPTY_MARKER.length() - 1); | ||
| } else { |
There was a problem hiding this comment.
Lets use an else if instead of else here, just in case it is run on existing documents without the NORMAL marker
There was a problem hiding this comment.
Lets use an else if instead of else here, just in case it is run on existing documents without the
NORMALmarker
updated
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
|
||
| ### Changed | ||
|
|
||
| - We changed CSL reference format by adding citation type at the end, and used enum to replace boolean variables in the method signature. [#15370](https://github.com/JabRef/jabref/issues/15370) [#15434](https://github.com/JabRef/jabref/issues/15434) |
There was a problem hiding this comment.
Changelog is for the end users, so please not any technical details
There was a problem hiding this comment.
Removed technical details. Thank you for the note.
✅ All tests passed ✅🏷️ Commit: d06f6e9 Learn more about TestLens at testlens.app. |
|
Overall good, just questions:
|
Old citations work well with this PR. They are converted when inserting in-text or empty citations. |
No, backwards parsing compatibility is discussed in this comment
Yes, I requested this in the "remove and update" logic here.
Good point, currently there will be compatibility as the extension would produce the same backward-compatible format, but now we can introduce more JStyle-like granularity such that IN_TEXT etc is also embedded by it and then captured by JabRef. |
|
Thanks for the update! |
* Persist in-text/empty nature in the CSL reference mark * Backward compatibility with legacy citations * Remove superfluous comments * Add comments in `getUpdatedReferenceMarkNameWithNewNumbers` * Extract citation style and citation type into one method * Reformat code * Update CHANGELOG.md * Transform if-else to switch * Refactor updateMarkAndTextWithNewStyle * use else-if for backward compatibility * update CHANGELOG.md --------- Co-authored-by: Carl Christian Snethlage <50491877+calixtus@users.noreply.github.com>
Related issues and pull requests
Closes #15434
PR Description
This PR embeded citation nature into reference marks, and use enum to replace boolean variables.
Steps to test
Checklist
CHANGELOG.mdin a way that can be understood by the average user (if change is visible to the user)