Intrepid/Prometeu/Studio/pipeline/pr-master Build started...
JaCoCo Coverage #### Project Overview
No changes detected, that affect the code coverage.
* Line Coverage: 62.10% (17811/28682)
* Branch Coverage: 52.81% (6878/13025)
* Lines of Code: 28682
* Cyclomatic Complexity: 11494
#### Quality Gates Summary
Output truncated.
Test / Build skipped: 15, passed: 653
Intrepid/Prometeu/Studio/pipeline/head This commit looks good
Add a test-only synth FrontendProvider that traverses compile() to verified bytecode without PBS. Expose register/unregister on the static registry and lock the obligation in specs 23 and 22. Housekeep DSC-0063 with LSN-0065.
88 lines
3.1 KiB
Java
88 lines
3.1 KiB
Java
package p.studio.compiler;
|
|
|
|
import p.studio.compiler.models.FrontendSpec;
|
|
import p.studio.compiler.services.FrontendPhaseService;
|
|
import p.studio.compiler.services.FrontendProvider;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Optional;
|
|
|
|
public class FrontendRegistryService {
|
|
private static final Map<String, FrontendProvider> FRONTEND_PROVIDERS = new HashMap<>();
|
|
|
|
static {
|
|
bootstrapDefaults();
|
|
}
|
|
|
|
public static void bootstrapDefaults() {
|
|
registerIfAbsent(new PBSFrontendProvider());
|
|
}
|
|
|
|
public static FrontendSpec getDefaultFrontendSpec() {
|
|
return getDefaultProvider().specification();
|
|
}
|
|
|
|
public static FrontendProvider getDefaultProvider() {
|
|
return require(PBSDefinitions.PBS.getLanguageId());
|
|
}
|
|
|
|
public static Optional<FrontendSpec> getFrontendSpec(final String languageId) {
|
|
return getProvider(languageId).map(FrontendProvider::specification);
|
|
}
|
|
|
|
public static Optional<FrontendPhaseService> getFrontendPhaseService(final String languageId) {
|
|
return getProvider(languageId).map(FrontendProvider::compiler);
|
|
}
|
|
|
|
public static Optional<FrontendProvider> getProvider(final String languageId) {
|
|
return Optional.ofNullable(FRONTEND_PROVIDERS.get(languageId));
|
|
}
|
|
|
|
public static FrontendProvider require(final String languageId) {
|
|
final var provider = FRONTEND_PROVIDERS.get(languageId);
|
|
if (provider == null) {
|
|
throw new IllegalArgumentException("Unknown frontend languageId: " + languageId);
|
|
}
|
|
|
|
return provider;
|
|
}
|
|
|
|
public static List<FrontendSpec> listFrontendSpecs() {
|
|
return FRONTEND_PROVIDERS.values().stream()
|
|
.map(FrontendProvider::specification)
|
|
.sorted((left, right) -> left.getLanguageId().compareToIgnoreCase(right.getLanguageId()))
|
|
.toList();
|
|
}
|
|
|
|
public static List<FrontendProvider> listProviders() {
|
|
return FRONTEND_PROVIDERS.values().stream()
|
|
.sorted((left, right) -> left.specification().getLanguageId().compareToIgnoreCase(right.specification().getLanguageId()))
|
|
.toList();
|
|
}
|
|
|
|
public static void register(final FrontendProvider provider) {
|
|
final var languageId = provider.specification().getLanguageId();
|
|
if (FRONTEND_PROVIDERS.containsKey(languageId)) {
|
|
throw new IllegalArgumentException("Duplicate frontend languageId: " + languageId);
|
|
}
|
|
|
|
FRONTEND_PROVIDERS.put(languageId, provider);
|
|
}
|
|
|
|
public static void unregister(final String languageId) {
|
|
if (languageId == null || languageId.isBlank()) {
|
|
return;
|
|
}
|
|
if (PBSDefinitions.PBS.getLanguageId().equals(languageId)) {
|
|
throw new IllegalArgumentException("Cannot unregister the default PBS frontend: " + languageId);
|
|
}
|
|
FRONTEND_PROVIDERS.remove(languageId);
|
|
}
|
|
|
|
private static void registerIfAbsent(final FrontendProvider provider) {
|
|
FRONTEND_PROVIDERS.putIfAbsent(provider.specification().getLanguageId(), provider);
|
|
}
|
|
}
|