Skip to content
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

Parser no longer warns about empty BibTeX keys #2699

Merged
merged 3 commits into from
Apr 1, 2017
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,6 @@ private void parseAndAddEntry(String type) {
boolean duplicateKey = database.insertEntry(entry);
if (duplicateKey) {
parserResult.addDuplicateKey(entry.getCiteKey());
} else if (!entry.getCiteKeyOptional().isPresent() || entry.getCiteKeyOptional().get().isEmpty()) {
parserResult.addWarning(Localization.lang("Empty BibTeX key") + ": " + entry.getAuthorTitleYear(40)
+ " (" + Localization.lang("Grouping may not work for this entry.") + ")");
}
} catch (IOException ex) {
LOGGER.debug("Could not parse entry", ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,21 @@
/**
* Currently only checks the key if there is an author, year, and title present.
*/
public class BibtexkeyChecker implements Checker {
public class BibtexKeyChecker implements Checker {

@Override
public List<IntegrityMessage> check(BibEntry entry) {
Optional<String> valuekey = entry.getCiteKeyOptional();
Optional<String> valueauthor = entry.getField(FieldName.AUTHOR);
Optional<String> valuetitle = entry.getField(FieldName.TITLE);
Optional<String> valueyear = entry.getField(FieldName.YEAR);
String authortitleyear = entry.getAuthorTitleYear(100);

if (!valueauthor.isPresent() || !valuetitle.isPresent() || !valueyear.isPresent()) {
Optional<String> author = entry.getField(FieldName.AUTHOR);
Optional<String> title = entry.getField(FieldName.TITLE);
Optional<String> year = entry.getField(FieldName.YEAR);
if (!author.isPresent() || !title.isPresent() || !year.isPresent()) {
return Collections.emptyList();
}

if (StringUtil.isBlank(valuekey)) {
if (StringUtil.isBlank(entry.getCiteKeyOptional())) {
String authorTitleYear = entry.getAuthorTitleYear(100);
return Collections.singletonList(new IntegrityMessage(
Localization.lang("empty BibTeX key") + ": " + authortitleyear, entry, BibEntry.KEY_FIELD));
Localization.lang("empty BibTeX key") + ": " + authorTitleYear, entry, BibEntry.KEY_FIELD));
}

return Collections.emptyList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private List<IntegrityMessage> checkBibtexEntry(BibEntry entry) {
result.addAll(new JournalInAbbreviationListChecker(FieldName.JOURNALTITLE, journalAbbreviationRepository).check(entry));
}

result.addAll(new BibtexkeyChecker().check(entry));
result.addAll(new BibtexKeyChecker().check(entry));
result.addAll(new TypeChecker().check(entry));
result.addAll(new BibStringChecker().check(entry));
result.addAll(new HTMLCharacterChecker().check(entry));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -648,12 +648,12 @@ public void parseRecognizesDuplicateBibtexKeys() throws IOException {
}

@Test
public void parseWarnsAboutEntryWithoutBibtexKey() throws IOException {
public void parseNotWarnsAboutEntryWithoutBibtexKey() throws IOException {

ParserResult result = parser
.parse(new StringReader("@article{,author={Ed von Test}}"));

assertTrue(result.hasWarnings());
assertFalse(result.hasWarnings());

Collection<BibEntry> c = result.getDatabase().getEntries();

Expand Down