diff --git a/monticore-grammar/src/main/java/de/monticore/tagging/SimpleSymbolTagger.java b/monticore-grammar/src/main/java/de/monticore/tagging/SimpleSymbolTagger.java index 1511ee30d4..882375134d 100644 --- a/monticore-grammar/src/main/java/de/monticore/tagging/SimpleSymbolTagger.java +++ b/monticore-grammar/src/main/java/de/monticore/tagging/SimpleSymbolTagger.java @@ -1,7 +1,6 @@ /* (c) https://github.com/MontiCore/monticore */ package de.monticore.tagging; -import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; @@ -99,13 +98,14 @@ protected Stream findTagTargets(@Nonnull ISymbol symbol) { Iterator iterator = new ProgressiveIterator (backingTagUnits.get().iterator()) { @Override - Collection doWork(ASTTagUnit tagUnit) { + @Nonnull + protected Collection doWork(ASTTagUnit tagUnit) { // Add the matching ASTTargetElement from #findTagTargetsOfTagUnit to the buffer return findTagTargetsOfTagUnit(tagUnit, fqn); } @Override - void cleanup() { + protected void cleanup() { // cleanup (remove unloaded TagUnits) tagUnitMapping.cleanUp(); } @@ -237,7 +237,13 @@ void tryToAdvance() { return; } // Actually do the tagging related logic - targetElementBuffer.addAll(this.doWork(backing.next())); + while (backing.hasNext() && targetElementBuffer.isEmpty()) { + // Repeat the work until the buffer is no longer empty (or the backing iterator consumed) + targetElementBuffer.addAll(this.doWork(backing.next())); + } + if (!backing.hasNext()) { + this.cleanup(); + } } /** @@ -247,9 +253,9 @@ void tryToAdvance() { * @return the values to be added to a buffer */ @Nonnull - abstract Collection doWork(B next); + protected abstract Collection doWork(B next); - abstract void cleanup(); + protected abstract void cleanup(); } protected static class TagFQNMapping { diff --git a/monticore-test/01.experiments/tagging/src/test/java/TagTest.java b/monticore-test/01.experiments/tagging/src/test/java/TagTest.java index 0eb71f524e..ad397d42fd 100644 --- a/monticore-test/01.experiments/tagging/src/test/java/TagTest.java +++ b/monticore-test/01.experiments/tagging/src/test/java/TagTest.java @@ -41,9 +41,12 @@ public static void init() throws Exception { Log.enableFailQuick(false); // Load all relevant models - Optional opt = TagRepository.loadTagModel(new File("src/test/resources/models/Simple.tags")); - if (opt.isEmpty()) - Assert.fail("Failed to load Simple.tags"); + var emptyTagsOpt1 = TagRepository.loadTagModel(new File("src/test/resources/models/Empty.tags")); + Assert.assertTrue("Failed to load Empty.tags", emptyTagsOpt1.isPresent()); + var opt = TagRepository.loadTagModel(new File("src/test/resources/models/Simple.tags")); + Assert.assertTrue("Failed to load Simple.tags", opt.isPresent()); + var emptyTagsOpt2 = TagRepository.loadTagModel(new File("src/test/resources/models/Empty.tags")); + Assert.assertTrue("Failed to load Empty.tags", emptyTagsOpt2.isPresent()); tagger = new SimpleSymbolTagger(TagRepository::getLoadedTagUnits); diff --git a/monticore-test/01.experiments/tagging/src/test/resources/models/Empty.tags b/monticore-test/01.experiments/tagging/src/test/resources/models/Empty.tags new file mode 100644 index 0000000000..7748f6b231 --- /dev/null +++ b/monticore-test/01.experiments/tagging/src/test/resources/models/Empty.tags @@ -0,0 +1,5 @@ +/* (c) https://github.com/MontiCore/monticore */ + +tags Empty { + // no tags, empty +} \ No newline at end of file