Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix verifier error when there is no main reactor #1916

Merged
merged 1 commit into from
Jul 25, 2023
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
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