Skip to content

refactor org.jabref.gui.journals.UndoableAbbreviator#abbreviate #12101

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

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions src/main/java/org/jabref/gui/journals/UndoableAbbreviator.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,32 +38,32 @@ public boolean abbreviate(BibDatabase database, BibEntry entry, Field fieldName,
return false;
}

String text = entry.getField(fieldName).get();
String origText = text;
if (database != null) {
text = database.resolveForStrings(text);
}

if (!journalAbbreviationRepository.isKnownName(text)) {
return false; // Unknown, cannot abbreviate anything.
String originalName = getOriginalName(entry, fieldName, database);
if (!journalAbbreviationRepository.isKnownName(originalName)) {
return false;
}

Abbreviation abbreviation = journalAbbreviationRepository.get(text).get();
String newText = getAbbreviatedName(abbreviation);

if (newText.equals(origText)) {
String abbreviatedName = getAbbreviatedName(journalAbbreviationRepository.get(originalName).get());
if (abbreviatedName.equals(originalName)) {
return false;
}

// Store full name into fjournal but only if it exists
Copy link
Member

Choose a reason for hiding this comment

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

Do not remove comments adding value

updateFields(entry, fieldName, originalName, abbreviatedName, compoundEdit);
return true;
}

private String getOriginalName(BibEntry entry, Field fieldName, BibDatabase database) {
String name = entry.getField(fieldName).get();
return (database != null) ? database.resolveForStrings(name) : name;
}

private void updateFields(BibEntry entry, Field fieldName, String originalName, String newName, CompoundEdit compoundEdit) {
if (useFJournalField && (StandardField.JOURNAL == fieldName || StandardField.JOURNALTITLE == fieldName)) {
entry.setField(AMSField.FJOURNAL, abbreviation.getName());
ce.addEdit(new UndoableFieldChange(entry, AMSField.FJOURNAL, null, abbreviation.getName()));
entry.setField(AMSField.FJOURNAL, journalAbbreviationRepository.get(originalName).get().getName());
compoundEdit.addEdit(new UndoableFieldChange(entry, AMSField.FJOURNAL, null, journalAbbreviationRepository.get(originalName).get().getName()));
}

entry.setField(fieldName, newText);
ce.addEdit(new UndoableFieldChange(entry, fieldName, origText, newText));
return true;
entry.setField(fieldName, newName);
compoundEdit.addEdit(new UndoableFieldChange(entry, fieldName, originalName, newName));
}

private String getAbbreviatedName(Abbreviation text) {
Expand Down