fix: tolerate an unresolvable grammar in export model generation#1459
Draft
joaodinissf wants to merge 2 commits into
Draft
fix: tolerate an unresolvable grammar in export model generation#1459joaodinissf wants to merge 2 commits into
joaodinissf wants to merge 2 commits into
Conversation
…neratorX ExportGeneratorX.getPrefix derives the target package from raw URI segment arithmetic and misbehaves on every short URI shape: 1 segment (e.g. ParseHelper's __synthetic0.export) crashes with IndexOutOfBoundsException (subList(-1, 0)); 2 segments emit the literal segment "resource"; project-root URIs emit the raw project name (uncompilable generated code when the project is not named like a Java package); source-folder-root URIs emit an empty package, producing leading-dot qualified names. Keep the derivation for URIs with five or more segments byte for byte (segments between position 3 and the file) and make every shorter shape fall back to the project name when it already is a valid Java package name (SourceVersion.isName) or "generated" otherwise. No existing test ever failed on this: the builder participant catches the exception per resource and logs it (the long-standing "Error during compilation of '....export'" noise in master test runs), and export tests never assert generated output. ExportGeneratorXTest pins the full shape table with synthetic resource URIs. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018ANGM7L3BaEGfGUmPVKRt4
The sibling-grammar lookup in ExportGeneratorX.getGrammar demand-loads <name>.xtext next to the export model; for models with no such sibling (every test .export file, models built via ParseHelper) the load throws and the builder participant logs "Error during compilation" and silently aborts generation for the file — dozens of ERROR entries in every full test run, and the generator's main path never executes over the test fixtures. Make grammar resolution defensive: guard a missing resource or resource set, reject unresolved targetGrammar proxies, and catch the demand-load failure, returning null. Downstream, GeneratorUtil.allInstantiatedTypes treats a null grammar as "no parser-instantiated subtypes" (covering typeMap and canContain), and the remaining generator call sites already tolerate a null grammar (grammar?.name in ExportedNamesProviderGenerator; an explicit null check in ResourceDescriptionManagerGenerator). Export model generation now degrades gracefully instead of aborting. Phase 0 of dsldevkit#1458.
432b02f to
733e78c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #1281.
Summary
ExportGeneratorX.getGrammardemand-loads the sibling<name>.xtextnext to an export model (resourceSet.getResource(..., true)). For any model without such a sibling — every test.exportfile, models built via ParseHelper — the load throws, so the Xtext builder participant logsError during compilation of '<file>'with a full stack trace and silently aborts generation for that file. Every full test run carries dozens of these ERROR entries, and the generator's main path never actually executes over the test fixtures.This makes grammar resolution defensive: guard a missing resource/resource set, reject unresolved
targetGrammarproxies, catch the demand-load failure — return null. Downstream,GeneratorUtil.allInstantiatedTypestreats a null grammar as "no parser-instantiated subtypes" (one guard covering bothtypeMapandcanContain— exercising generation past the resolver for the first time exposed this second latent NPE), and the remaining call sites already tolerate a null grammar (grammar?.name ?: …inExportedNamesProviderGenerator; explicit null check inResourceDescriptionManagerGenerator). Export model generation now degrades gracefully (direct type mappings, no subtype expansion) instead of aborting.Phase 0 of #1458 (role-aware package identity): resolution failure must select the fallback, never fail generation.
Verification
testGetGrammarReturnsNullWithoutResolvableGrammarcovers the resolver matrix: detached model, resource without resource set, missing sibling grammar, unresolvedtargetGrammarproxy.mvn -T 3C clean verify pmd:check checkstyle:check spotbugs:check→ BUILD SUCCESS;Error during compilationentries for export fixtures gone from the AllTests log (baseline: ~25 per run).🤖 Generated with Claude Code