Skip to content

Commit

Permalink
Do not abort on empty tag collections (#4241)
Browse files Browse the repository at this point in the history
  • Loading branch information
MisterErwin committed Oct 14, 2024
1 parent abc11f9 commit e22ba98
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -99,13 +98,14 @@ protected Stream<ASTTargetElement> findTagTargets(@Nonnull ISymbol symbol) {
Iterator<ASTTargetElement> iterator = new ProgressiveIterator<ASTTargetElement, ASTTagUnit>
(backingTagUnits.get().iterator()) {
@Override
Collection<? extends ASTTargetElement> doWork(ASTTagUnit tagUnit) {
@Nonnull
protected Collection<? extends ASTTargetElement> 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();
}
Expand Down Expand Up @@ -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();
}
}

/**
Expand All @@ -247,9 +253,9 @@ void tryToAdvance() {
* @return the values to be added to a buffer
*/
@Nonnull
abstract Collection<? extends A> doWork(B next);
protected abstract Collection<? extends A> doWork(B next);

abstract void cleanup();
protected abstract void cleanup();
}

protected static class TagFQNMapping {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* (c) https://github.com/MontiCore/monticore */

tags Empty {
// no tags, empty
}

0 comments on commit e22ba98

Please sign in to comment.