Skip to content

Commit

Permalink
Clean up Main
Browse files Browse the repository at this point in the history
  • Loading branch information
Baltoli committed Oct 24, 2023
1 parent 17fb4e5 commit ebc5455
Showing 1 changed file with 9 additions and 19 deletions.
28 changes: 9 additions & 19 deletions kernel/src/main/java/org/kframework/main/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@
import java.util.ServiceLoader;
import java.util.concurrent.ExecutionException;

public class Main {
public record Main(
Provider<KExceptionManager> kem,
Provider<FrontEnd> frontEnd,
@Named("requestScope") SimpleScope requestScope
) {

/**
* @param args
Expand Down Expand Up @@ -91,19 +95,8 @@ public static void nailMain(NGContext context) {
invalidJarArguments();
}

private final Provider<KExceptionManager> kem;
private final Provider<FrontEnd> frontEnd;
private final SimpleScope requestScope;

@Inject
public Main(
Provider<KExceptionManager> kem,
Provider<FrontEnd> frontEnd,
@Named("requestScope") SimpleScope requestScope) {
this.kem = kem;
this.frontEnd = frontEnd;
this.requestScope = requestScope;
}
public Main {}

public SimpleScope getRequestScope() {
return requestScope;
Expand All @@ -123,14 +116,12 @@ public int runApplication() {
KExceptionManager kem = this.kem.get();
kem.installForUncaughtExceptions();
try {
int retval = frontEnd.get().main();
return retval;
return frontEnd.get().main();
} catch (ProvisionException e) {
for (Message m : e.getErrorMessages()) {
if (!(m.getCause() instanceof KEMException)) {
if (!(m.getCause() instanceof KEMException ex)) {
throw e;
} else {
KEMException ex = (KEMException) m.getCause();
kem.registerThrown(ex);
}
}
Expand Down Expand Up @@ -208,8 +199,7 @@ public static Injector getInjector(String tool) {
//boot error, we should have printed it already
Main.exit(1);
}
Injector injector = Guice.createInjector(modules);
return injector;
return Guice.createInjector(modules);
}

private static void invalidJarArguments() {
Expand Down

0 comments on commit ebc5455

Please sign in to comment.