diff --git a/jabgui/src/main/java/org/jabref/gui/consistency/ConsistencyCheckAction.java b/jabgui/src/main/java/org/jabref/gui/consistency/ConsistencyCheckAction.java index 3cb1d9adaab..f2d34b1b155 100644 --- a/jabgui/src/main/java/org/jabref/gui/consistency/ConsistencyCheckAction.java +++ b/jabgui/src/main/java/org/jabref/gui/consistency/ConsistencyCheckAction.java @@ -44,7 +44,6 @@ public ConsistencyCheckAction(Supplier tabSupplier, this.preferences = preferences; this.entryTypesManager = entryTypesManager; this.taskExecutor = taskExecutor; - this.executable.bind(needsDatabase(stateManager)); } @@ -63,7 +62,7 @@ public BibliographyConsistencyCheck.Result call() { BibDatabaseContext bibContext = databaseContext.get(); BibliographyConsistencyCheck consistencyCheck = new BibliographyConsistencyCheck(); - return consistencyCheck.check(bibContext, (count, total) -> + return consistencyCheck.check(bibContext, entryTypesManager, (count, total) -> UiTaskExecutor.runInJavaFXThread(() -> { updateProgress(count, total); updateMessage(Localization.lang("%0/%1 entry types", count + 1, total)); diff --git a/jabkit/src/main/java/org/jabref/toolkit/commands/CheckConsistency.java b/jabkit/src/main/java/org/jabref/toolkit/commands/CheckConsistency.java index 1791d626a24..8f2097d3e6c 100644 --- a/jabkit/src/main/java/org/jabref/toolkit/commands/CheckConsistency.java +++ b/jabkit/src/main/java/org/jabref/toolkit/commands/CheckConsistency.java @@ -14,6 +14,7 @@ import org.jabref.logic.quality.consistency.BibliographyConsistencyCheckResultTxtWriter; import org.jabref.logic.quality.consistency.BibliographyConsistencyCheckResultWriter; import org.jabref.model.database.BibDatabaseContext; +import org.jabref.model.entry.BibEntryTypesManager; import org.jabref.toolkit.converter.CygWinPathConverter; import org.slf4j.Logger; @@ -65,7 +66,8 @@ public Integer call() { BibDatabaseContext databaseContext = parserResult.get().getDatabaseContext(); BibliographyConsistencyCheck consistencyCheck = new BibliographyConsistencyCheck(); - BibliographyConsistencyCheck.Result result = consistencyCheck.check(databaseContext, (count, total) -> { + BibEntryTypesManager bibEntryTypesManager = new BibEntryTypesManager(); + BibliographyConsistencyCheck.Result result = consistencyCheck.check(databaseContext, bibEntryTypesManager, (count, total) -> { if (!sharedOptions.porcelain) { System.out.println(Localization.lang("Checking consistency for entry type %0 of %1", count + 1, total)); } diff --git a/jablib/src/main/java/org/jabref/logic/quality/consistency/BibliographyConsistencyCheck.java b/jablib/src/main/java/org/jabref/logic/quality/consistency/BibliographyConsistencyCheck.java index 64915003c35..c1f17954a31 100644 --- a/jablib/src/main/java/org/jabref/logic/quality/consistency/BibliographyConsistencyCheck.java +++ b/jablib/src/main/java/org/jabref/logic/quality/consistency/BibliographyConsistencyCheck.java @@ -20,13 +20,12 @@ import org.jabref.model.database.BibDatabaseMode; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.BibEntryType; +import org.jabref.model.entry.BibEntryTypesManager; import org.jabref.model.entry.field.Field; import org.jabref.model.entry.field.InternalField; import org.jabref.model.entry.field.SpecialField; import org.jabref.model.entry.field.StandardField; import org.jabref.model.entry.field.UserSpecificCommentField; -import org.jabref.model.entry.types.BiblatexEntryTypeDefinitions; -import org.jabref.model.entry.types.BibtexEntryTypeDefinitions; import org.jabref.model.entry.types.EntryType; import com.google.common.annotations.VisibleForTesting; @@ -102,7 +101,7 @@ public record EntryTypeResult(Collection fields, SequencedCollection entriesGroupingProgress) { + public Result check(BibDatabaseContext bibContext, BibEntryTypesManager bibEntryTypesManager, BiConsumer entriesGroupingProgress) { // collects fields existing in any entry, scoped by entry type Map> entryTypeToFieldsInAnyEntryMap = new HashMap<>(); // collects fields existing in all entries, scoped by entry type @@ -112,12 +111,7 @@ public Result check(BibDatabaseContext bibContext, BiConsumer collectEntriesIntoMaps(bibContext, entryTypeToFieldsInAnyEntryMap, entryTypeToFieldsInAllEntriesMap, entryTypeToEntriesMap); - List entryTypeDefinitions; - if (bibContext.getMode() == BibDatabaseMode.BIBLATEX) { - entryTypeDefinitions = BiblatexEntryTypeDefinitions.ALL; - } else { - entryTypeDefinitions = BibtexEntryTypeDefinitions.ALL; - } + List entryTypeDefinitions = bibEntryTypesManager.getAllTypes(bibContext.getMode()).stream().toList(); // Use LinkedHashMap to preserve the order of Bib(tex|latex)EntryTypeDefinitions.ALL Map resultMap = new LinkedHashMap<>(); diff --git a/jablib/src/test/java/org/jabref/logic/quality/consistency/BibliographyConsistencyCheckResultCsvWriterTest.java b/jablib/src/test/java/org/jabref/logic/quality/consistency/BibliographyConsistencyCheckResultCsvWriterTest.java index 6bcb7ba90a6..0bb03627eee 100644 --- a/jablib/src/test/java/org/jabref/logic/quality/consistency/BibliographyConsistencyCheckResultCsvWriterTest.java +++ b/jablib/src/test/java/org/jabref/logic/quality/consistency/BibliographyConsistencyCheckResultCsvWriterTest.java @@ -5,6 +5,8 @@ import java.io.Writer; import java.nio.file.Files; import java.nio.file.Path; +import java.util.List; +import java.util.Set; import org.jabref.logic.importer.ImportFormatPreferences; import org.jabref.logic.importer.fileformat.BibtexImporter; @@ -12,11 +14,18 @@ import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.database.BibDatabaseMode; import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.BibEntryType; +import org.jabref.model.entry.BibEntryTypesManager; +import org.jabref.model.entry.field.BibField; +import org.jabref.model.entry.field.FieldPriority; import org.jabref.model.entry.field.StandardField; import org.jabref.model.entry.field.UnknownField; +import org.jabref.model.entry.types.EntryType; import org.jabref.model.entry.types.StandardEntryType; +import org.jabref.model.entry.types.UnknownEntryType; import org.jabref.model.util.DummyFileUpdateMonitor; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; @@ -27,8 +36,30 @@ class BibliographyConsistencyCheckResultCsvWriterTest { + private static final EntryType UNKNOWN_TYPE = new UnknownEntryType("unknownType"); + private static final EntryType CUSTOM_TYPE = new UnknownEntryType("customType"); + private final BibtexImporter importer = new BibtexImporter(mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS), new DummyFileUpdateMonitor()); + private BibEntryType newCustomType; + private BibEntryType overwrittenStandardType; + private BibEntryTypesManager entryTypesManager; + + @BeforeEach + void setUp() { + newCustomType = new BibEntryType( + CUSTOM_TYPE, + List.of(new BibField(StandardField.AUTHOR, FieldPriority.IMPORTANT)), + Set.of()); + + overwrittenStandardType = new BibEntryType( + StandardEntryType.Article, + List.of(new BibField(StandardField.TITLE, FieldPriority.IMPORTANT)), + Set.of()); + + entryTypesManager = new BibEntryTypesManager(); + } + @Test void checkSimpleLibrary(@TempDir Path tempDir) throws IOException { BibEntry first = new BibEntry(StandardEntryType.Article, "first") @@ -42,7 +73,7 @@ void checkSimpleLibrary(@TempDir Path tempDir) throws IOException { database.insertEntry(second); BibDatabaseContext bibContext = new BibDatabaseContext(database); - BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, (count, total) -> { + BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, entryTypesManager, (count, total) -> { }); Path csvFile = tempDir.resolve("checkSimpleLibrary-result.csv"); @@ -73,7 +104,7 @@ void checkDifferentOutputSymbols(@TempDir Path tempDir) throws IOException { BibDatabaseContext bibContext = new BibDatabaseContext(database); bibContext.setMode(BibDatabaseMode.BIBTEX); - BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, (count, total) -> { + BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, entryTypesManager, (count, total) -> { }); Path csvFile = tempDir.resolve("checkDifferentOutputSymbols-result.csv"); @@ -119,7 +150,7 @@ void checkComplexLibrary(@TempDir Path tempDir) throws IOException { database.insertEntry(fifth); BibDatabaseContext bibContext = new BibDatabaseContext(database); - BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, (count, total) -> { + BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, entryTypesManager, (count, total) -> { }); Path csvFile = tempDir.resolve("checkSimpleLibrary-result.csv"); @@ -151,7 +182,7 @@ void checkLibraryWithoutIssues(@TempDir Path tempDir) throws IOException { BibDatabaseContext bibContext = new BibDatabaseContext(database); bibContext.setMode(BibDatabaseMode.BIBTEX); - BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, (count, total) -> { + BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, entryTypesManager, (count, total) -> { }); Path csvFile = tempDir.resolve("checkLibraryWithoutIssues-result.csv"); @@ -170,7 +201,7 @@ void checkManualInput() throws IOException { Path file = Path.of("C:\\TEMP\\JabRef\\biblio-anon.bib"); Path csvFile = file.resolveSibling("biblio-cited.csv"); BibDatabaseContext databaseContext = importer.importDatabase(file).getDatabaseContext(); - BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(databaseContext, (_, _) -> { + BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(databaseContext, entryTypesManager, (_, _) -> { }); try (Writer writer = new OutputStreamWriter(Files.newOutputStream(csvFile)); BibliographyConsistencyCheckResultCsvWriter paperConsistencyCheckResultCsvWriter = new BibliographyConsistencyCheckResultCsvWriter(result, writer, true)) { diff --git a/jablib/src/test/java/org/jabref/logic/quality/consistency/BibliographyConsistencyCheckResultTxtWriterTest.java b/jablib/src/test/java/org/jabref/logic/quality/consistency/BibliographyConsistencyCheckResultTxtWriterTest.java index 176ee0fc7c3..7c0e03786dd 100644 --- a/jablib/src/test/java/org/jabref/logic/quality/consistency/BibliographyConsistencyCheckResultTxtWriterTest.java +++ b/jablib/src/test/java/org/jabref/logic/quality/consistency/BibliographyConsistencyCheckResultTxtWriterTest.java @@ -44,7 +44,7 @@ void checkSimpleLibrary(@TempDir Path tempDir) throws IOException { BibDatabaseContext bibContext = new BibDatabaseContext(database); bibContext.setMode(BibDatabaseMode.BIBTEX); - BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, (count, total) -> { + BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, new BibEntryTypesManager(), (count, total) -> { }); Path txtFile = tempDir.resolve("checkSimpleLibrary-result.txt"); @@ -89,7 +89,7 @@ void entriesMissingRequiredFieldsAreReported(@TempDir Path tempDir) throws Excep bibContext.setMode(BibDatabaseMode.BIBLATEX); BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck() - .check(bibContext, (_, _) -> { + .check(bibContext, new BibEntryTypesManager(), (_, _) -> { }); Path txtFile = tempDir.resolve("checkSimpleLibrary-result.txt"); @@ -131,7 +131,7 @@ void checkDifferentOutputSymbols(@TempDir Path tempDir) throws IOException { BibDatabaseContext bibContext = new BibDatabaseContext(bibDatabase); bibContext.setMode(BibDatabaseMode.BIBTEX); - BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, (_, _) -> { + BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, new BibEntryTypesManager(), (_, _) -> { }); Path txtFile = tempDir.resolve("checkDifferentOutputSymbols-result.txt"); @@ -171,7 +171,7 @@ void checkVeryLongCitationKey(@TempDir Path tempDir) throws IOException { bibDatabase.insertEntries(bibEntriesList); BibDatabaseContext bibContext = new BibDatabaseContext(bibDatabase); bibContext.setMode(BibDatabaseMode.BIBTEX); - BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, (_, _) -> { + BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, new BibEntryTypesManager(), (_, _) -> { }); Path txtFile = tempDir.resolve("checkDifferentOutputSymbols-result.txt"); @@ -228,7 +228,7 @@ void checkComplexLibrary(@TempDir Path tempDir) throws IOException { bibDatabase.insertEntries(bibEntriesList); BibDatabaseContext bibContext = new BibDatabaseContext(bibDatabase); - BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, (_, _) -> { + BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, new BibEntryTypesManager(), (_, _) -> { }); Path txtFile = tempDir.resolve("checkSimpleLibrary-result.txt"); @@ -270,7 +270,7 @@ void checkLibraryWithoutIssuesWithOutPorcelain(@TempDir Path tempDir) throws IOE bibDatabase.insertEntries(bibEntriesList); BibDatabaseContext bibContext = new BibDatabaseContext(bibDatabase); - BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, (_, _) -> { + BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, new BibEntryTypesManager(), (_, _) -> { }); Path txtFile = tempDir.resolve("checkLibraryWithoutIssues-result.txt"); @@ -298,7 +298,7 @@ void checkLibraryWithoutIssuesWithPorcelain(@TempDir Path tempDir) throws IOExce bibDatabase.insertEntries(bibEntriesList); BibDatabaseContext bibContext = new BibDatabaseContext(bibDatabase); - BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, (_, _) -> { + BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, new BibEntryTypesManager(), (_, _) -> { }); Path txtFile = tempDir.resolve("checkLibraryWithoutIssues-result.txt"); @@ -315,7 +315,7 @@ void checkManualInput() throws IOException { Path file = Path.of("C:\\TEMP\\JabRef\\biblio-anon.bib"); Path txtFile = file.resolveSibling("biblio-cited.txt"); BibDatabaseContext databaseContext = importer.importDatabase(file).getDatabaseContext(); - BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(databaseContext, (_, _) -> { + BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(databaseContext, new BibEntryTypesManager(), (_, _) -> { }); try (Writer writer = new OutputStreamWriter(Files.newOutputStream(txtFile)); BibliographyConsistencyCheckResultTxtWriter txtWriter = new BibliographyConsistencyCheckResultTxtWriter(result, writer, true)) { diff --git a/jablib/src/test/java/org/jabref/logic/quality/consistency/BibliographyConsistencyCheckTest.java b/jablib/src/test/java/org/jabref/logic/quality/consistency/BibliographyConsistencyCheckTest.java index 12987b2cf40..ecb8f043e96 100644 --- a/jablib/src/test/java/org/jabref/logic/quality/consistency/BibliographyConsistencyCheckTest.java +++ b/jablib/src/test/java/org/jabref/logic/quality/consistency/BibliographyConsistencyCheckTest.java @@ -9,13 +9,20 @@ import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.database.BibDatabaseMode; import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.BibEntryType; +import org.jabref.model.entry.BibEntryTypesManager; +import org.jabref.model.entry.field.BibField; import org.jabref.model.entry.field.Field; +import org.jabref.model.entry.field.FieldPriority; import org.jabref.model.entry.field.SpecialField; import org.jabref.model.entry.field.StandardField; import org.jabref.model.entry.field.UnknownField; import org.jabref.model.entry.field.UserSpecificCommentField; +import org.jabref.model.entry.types.EntryType; import org.jabref.model.entry.types.StandardEntryType; +import org.jabref.model.entry.types.UnknownEntryType; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; @@ -23,6 +30,109 @@ class BibliographyConsistencyCheckTest { + private static final EntryType UNKNOWN_TYPE = new UnknownEntryType("unknownType"); + private static final EntryType CUSTOM_TYPE = new UnknownEntryType("customType"); + + private BibEntryType newCustomType; + private BibEntryType overwrittenStandardType; + private BibEntryTypesManager entryTypesManager; + + @BeforeEach + void setUp() { + newCustomType = new BibEntryType( + CUSTOM_TYPE, + List.of(new BibField(StandardField.AUTHOR, FieldPriority.IMPORTANT)), + Set.of()); + + overwrittenStandardType = new BibEntryType( + StandardEntryType.Article, + List.of(new BibField(StandardField.TITLE, FieldPriority.IMPORTANT)), + Set.of()); + + entryTypesManager = new BibEntryTypesManager(); + } + + @Test + void checkComplexLibraryWithCustomEntryTypes(@TempDir Path tempDir) { + BibEntry first = new BibEntry(StandardEntryType.Article, "first") + .withField(StandardField.AUTHOR, "Author One") + .withField(StandardField.PAGES, "some pages"); + BibEntry second = new BibEntry(StandardEntryType.Article, "second") + .withField(StandardField.AUTHOR, "Author One") + .withField(StandardField.PUBLISHER, "publisher"); + BibEntry third = new BibEntry(StandardEntryType.InProceedings, "third") + .withField(StandardField.AUTHOR, "Author One") + .withField(StandardField.LOCATION, "location") + .withField(StandardField.YEAR, "2024") + .withField(StandardField.PAGES, "some pages"); + BibEntry fourth = new BibEntry(StandardEntryType.InProceedings, "fourth") + .withField(StandardField.AUTHOR, "Author One") + .withField(StandardField.YEAR, "2024") + .withField(StandardField.PUBLISHER, "publisher"); + BibEntry fifth = new BibEntry(StandardEntryType.InProceedings, "fifth") + .withField(StandardField.AUTHOR, "Author One") + .withField(StandardField.YEAR, "2024"); + BibEntry sixth = new BibEntry(newCustomType.getType(), "sixth") + .withField(StandardField.AUTHOR, "Author One") + .withField(StandardField.PAGES, "some pages") + .withField(StandardField.ABSTRACT, "some abstract"); + BibEntry seventh = new BibEntry(newCustomType.getType(), "seventh") + .withField(StandardField.AUTHOR, "Author One") + .withField(StandardField.PAGES, "some pages"); + BibEntry eighth = new BibEntry(newCustomType.getType(), "eighth") + .withField(StandardField.AUTHOR, "Author One") + .withField(StandardField.PAGES, "some pages") + .withField(StandardField.ABSTRACT, "some abstract") + .withField(StandardField.YEAR, "2025"); + BibEntry ninth = new BibEntry(newCustomType.getType(), "ninth") + .withField(StandardField.AUTHOR, "Author One") + .withField(StandardField.PAGES, "some pages") + .withField(StandardField.YEAR, "2025"); + + BibDatabase bibDatabase = new BibDatabase(List.of(first, second, third, fourth, fifth, sixth, seventh, eighth, ninth)); + BibDatabaseContext bibContext = new BibDatabaseContext(bibDatabase); + + BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, entryTypesManager, (_, _) -> { + }); + + BibliographyConsistencyCheck.EntryTypeResult articleResult = new BibliographyConsistencyCheck.EntryTypeResult(Set.of(StandardField.PAGES, StandardField.PUBLISHER), List.of(first, second)); + BibliographyConsistencyCheck.EntryTypeResult inProceedingsResult = new BibliographyConsistencyCheck.EntryTypeResult(Set.of(StandardField.PAGES, StandardField.PUBLISHER, StandardField.LOCATION), List.of(fifth, fourth, third)); + BibliographyConsistencyCheck.EntryTypeResult customResult = new BibliographyConsistencyCheck.EntryTypeResult(Set.of(StandardField.ABSTRACT, StandardField.YEAR), List.of(eighth, ninth, sixth)); + BibliographyConsistencyCheck.Result expected = new BibliographyConsistencyCheck.Result(Map.of( + StandardEntryType.Article, articleResult, + StandardEntryType.InProceedings, inProceedingsResult, + CUSTOM_TYPE, customResult + )); + assertEquals(expected, result); + } + + @Test + void checkSimpleLibraryWithCustomTypes() { + BibEntry first = new BibEntry(newCustomType.getType(), "first") + .withField(StandardField.AUTHOR, "Author One") + .withField(StandardField.PAGES, "some pages"); + BibEntry second = new BibEntry(newCustomType.getType(), "second") + .withField(StandardField.AUTHOR, "Author Two") + .withField(StandardField.PAGES, "some pages"); + BibEntry third = new BibEntry(newCustomType.getType(), "third") + .withField(StandardField.AUTHOR, "Author Three") + .withField(StandardField.PAGES, "some pages") + .withField(StandardField.ABSTRACT, "some abstract"); + + BibDatabase database = new BibDatabase(List.of(first, second, third)); + BibDatabaseContext bibContext = new BibDatabaseContext(database); + bibContext.setMode(BibDatabaseMode.BIBTEX); + + entryTypesManager.addCustomOrModifiedType(newCustomType, bibContext.getMode()); + + BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, entryTypesManager, (count, total) -> { + }); + + BibliographyConsistencyCheck.EntryTypeResult entryTypeResult = new BibliographyConsistencyCheck.EntryTypeResult(Set.of(StandardField.ABSTRACT), List.of(third)); + BibliographyConsistencyCheck.Result expected = new BibliographyConsistencyCheck.Result(Map.of(CUSTOM_TYPE, entryTypeResult)); + assertEquals(expected, result); + } + @Test void checkSimpleLibrary(@TempDir Path tempDir) { BibEntry first = new BibEntry(StandardEntryType.Article, "first") @@ -34,7 +144,7 @@ void checkSimpleLibrary(@TempDir Path tempDir) { BibDatabase database = new BibDatabase(List.of(first, second)); BibDatabaseContext bibContext = new BibDatabaseContext(database); bibContext.setMode(BibDatabaseMode.BIBTEX); - BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, (count, total) -> { + BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, entryTypesManager, (count, total) -> { }); BibliographyConsistencyCheck.EntryTypeResult entryTypeResult = new BibliographyConsistencyCheck.EntryTypeResult(Set.of(StandardField.PAGES, StandardField.PUBLISHER), List.of(first, second)); @@ -55,7 +165,7 @@ void checkDifferentOutputSymbols(@TempDir Path tempDir) { BibDatabase bibDatabase = new BibDatabase(List.of(first, second)); BibDatabaseContext bibContext = new BibDatabaseContext(bibDatabase); bibContext.setMode(BibDatabaseMode.BIBTEX); - BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, (_, _) -> { + BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, entryTypesManager, (_, _) -> { }); BibliographyConsistencyCheck.EntryTypeResult entryTypeResult = new BibliographyConsistencyCheck.EntryTypeResult(Set.of(StandardField.PAGES, StandardField.TITLE, customField), List.of(first, second)); @@ -88,7 +198,7 @@ void checkComplexLibrary(@TempDir Path tempDir) { BibDatabase bibDatabase = new BibDatabase(List.of(first, second, third, fourth, fifth)); BibDatabaseContext bibContext = new BibDatabaseContext(bibDatabase); - BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, (_, _) -> { + BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, entryTypesManager, (_, _) -> { }); BibliographyConsistencyCheck.EntryTypeResult articleResult = new BibliographyConsistencyCheck.EntryTypeResult(Set.of(StandardField.PAGES, StandardField.PUBLISHER), List.of(first, second)); @@ -111,7 +221,7 @@ void checkLibraryWithoutIssues(@TempDir Path tempDir) { BibDatabase bibDatabase = new BibDatabase(List.of(first, second)); BibDatabaseContext bibContext = new BibDatabaseContext(bibDatabase); - BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, (_, _) -> { + BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, entryTypesManager, (_, _) -> { }); BibliographyConsistencyCheck.Result expected = new BibliographyConsistencyCheck.Result(Map.of()); @@ -133,7 +243,7 @@ void filteredFieldsAreIgnored() { BibDatabaseContext bibContext = new BibDatabaseContext(bibDatabase); BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck() - .check(bibContext, (_, _) -> { + .check(bibContext, entryTypesManager, (_, _) -> { }); assertEquals(Map.of(), result.entryTypeToResultMap(), @@ -150,7 +260,7 @@ void nonFilteredFieldDifferenceIsReported() { BibDatabaseContext bibContext = new BibDatabaseContext(bibDatabase); BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck() - .check(bibContext, (_, _) -> { + .check(bibContext, entryTypesManager, (_, _) -> { }); BibliographyConsistencyCheck.EntryTypeResult typeResult = @@ -174,7 +284,7 @@ void unsetRequriedFieldsReported() { bibContext.setMode(BibDatabaseMode.BIBLATEX); BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck() - .check(bibContext, (_, _) -> { + .check(bibContext, entryTypesManager, (_, _) -> { }); BibliographyConsistencyCheck.EntryTypeResult typeResult = @@ -198,7 +308,7 @@ void unsetFieldsReportedInBibtexMode() { BibDatabaseContext bibContext = new BibDatabaseContext(bibDatabase); bibContext.setMode(BibDatabaseMode.BIBTEX); BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck() - .check(bibContext, (_, _) -> { + .check(bibContext, entryTypesManager, (_, _) -> { }); BibliographyConsistencyCheck.EntryTypeResult typeResult = result.entryTypeToResultMap().get(StandardEntryType.Online); @@ -268,7 +378,7 @@ void checkComplexLibraryWithAdditionalEntry(@TempDir Path tempDir) { BibDatabase bibDatabase = new BibDatabase(List.of(first, second, third, fourth, fifth, sixth)); BibDatabaseContext bibContext = new BibDatabaseContext(bibDatabase); - BibliographyConsistencyCheck.Result actualResult = new BibliographyConsistencyCheck().check(bibContext, (_, _) -> { + BibliographyConsistencyCheck.Result actualResult = new BibliographyConsistencyCheck().check(bibContext, entryTypesManager, (_, _) -> { }); BibliographyConsistencyCheck.EntryTypeResult articleResult = new BibliographyConsistencyCheck.EntryTypeResult(Set.of(StandardField.PAGES, StandardField.PUBLISHER), List.of(first, second)); diff --git a/jabls/src/main/java/org/jabref/languageserver/util/LspConsistencyCheck.java b/jabls/src/main/java/org/jabref/languageserver/util/LspConsistencyCheck.java index 0e4635e70ff..1bdbed27e25 100644 --- a/jabls/src/main/java/org/jabref/languageserver/util/LspConsistencyCheck.java +++ b/jabls/src/main/java/org/jabref/languageserver/util/LspConsistencyCheck.java @@ -28,10 +28,10 @@ public LspConsistencyCheck(ExtensionSettings settings) { this.settings = settings; } - public List check(ParserResult parserResult) { + public List check(ParserResult parserResult, BibEntryTypesManager bibEntryTypesManager) { List diagnostics = new ArrayList<>(); BibliographyConsistencyCheck consistencyCheck = new BibliographyConsistencyCheck(); - BibliographyConsistencyCheck.Result result = consistencyCheck.check(parserResult.getDatabaseContext(), (_, _) -> { + BibliographyConsistencyCheck.Result result = consistencyCheck.check(parserResult.getDatabaseContext(), bibEntryTypesManager, (_, _) -> { }); Set allReportedFields = result.entryTypeToResultMap().values().stream().flatMap(entryTypeResult -> entryTypeResult.fields().stream()).collect(Collectors.toUnmodifiableSet()); diff --git a/jabls/src/main/java/org/jabref/languageserver/util/LspDiagnosticHandler.java b/jabls/src/main/java/org/jabref/languageserver/util/LspDiagnosticHandler.java index fe08f777144..e2e5a8ba47c 100644 --- a/jabls/src/main/java/org/jabref/languageserver/util/LspDiagnosticHandler.java +++ b/jabls/src/main/java/org/jabref/languageserver/util/LspDiagnosticHandler.java @@ -16,6 +16,7 @@ import org.jabref.logic.journals.JournalAbbreviationRepository; import org.jabref.logic.l10n.Localization; import org.jabref.logic.preferences.CliPreferences; +import org.jabref.model.entry.BibEntryTypesManager; import org.eclipse.lsp4j.Diagnostic; import org.eclipse.lsp4j.DiagnosticSeverity; @@ -88,7 +89,8 @@ private List computeDiagnostics(String content, String uri) { } if (clientHandler.getSettings().isConsistencyCheck()) { - consistencyDiagnosticsCache.put(uri, lspConsistencyCheck.check(parserResult)); + BibEntryTypesManager bibEntryTypesManager = new BibEntryTypesManager(); + consistencyDiagnosticsCache.put(uri, lspConsistencyCheck.check(parserResult, bibEntryTypesManager)); LOGGER.debug("Cached consistency diagnostics for {}", uri); }