Skip to content

Commit

Permalink
Merge pull request #1916 from lf-lang/verifier-opt-fix
Browse files Browse the repository at this point in the history
Fix verifier error when there is no main reactor
  • Loading branch information
lhstrh authored Jul 25, 2023
2 parents 9776309 + 794dba0 commit 0864dd0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 3 additions & 3 deletions core/src/main/java/org/lflang/ast/ASTUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.Predicate;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -154,14 +155,13 @@ public static List<Reactor> getAllReactors(Resource resource) {
* @param resource the resource to extract reactors from
* @return An iterable over all reactors found in the resource
*/
public static Reactor getMainReactor(Resource resource) {
public static Optional<Reactor> getMainReactor(Resource resource) {
return StreamSupport.stream(
IteratorExtensions.toIterable(resource.getAllContents()).spliterator(), false)
.filter(Reactor.class::isInstance)
.map(Reactor.class::cast)
.filter(it -> it.isMain())
.findFirst()
.get();
.findFirst();
}

/**
Expand Down
5 changes: 4 additions & 1 deletion core/src/main/java/org/lflang/generator/LFGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.xtext.generator.AbstractGenerator;
Expand Down Expand Up @@ -158,7 +159,9 @@ protected void cleanIfNeeded(LFGeneratorContext context) {
* connections, etc.).
*/
private void runVerifierIfPropertiesDetected(Resource resource, LFGeneratorContext lfContext) {
Reactor main = ASTUtils.getMainReactor(resource);
Optional<Reactor> mainOpt = ASTUtils.getMainReactor(resource);
if (mainOpt.isEmpty()) return;
Reactor main = mainOpt.get();
final MessageReporter messageReporter = lfContext.getErrorReporter();
List<Attribute> properties =
AttributeUtils.getAttributes(main).stream()
Expand Down

0 comments on commit 0864dd0

Please sign in to comment.