Skip to content

Feature/issue 9 cross file extension - #13

Merged
haumacher merged 28 commits into
mainfrom
feature/issue-9-cross-file-extension
Mar 25, 2026
Merged

haumacher merged 28 commits into
mainfrom
feature/issue-9-cross-file-extension

Conversation

@haumacher

Copy link
Copy Markdown
Member

Fixes #9

haumacher and others added 28 commits March 25, 2026 09:01
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…mports)

- Replace ConcurrentHashMap/Supplier with HashMap/Factory for GWT compat
- Add instanceof-based visitor dispatch for extension types
- Specify import path resolution and transitive import support
- Document AST changes and bootstrapping impact
- OpenWorld implies NoBinary + NoXml
- Expand test plan with edge cases
- Add registration class naming convention

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
XML uses string-based type names like JSON, so there are no
type-ID conflict issues. Only binary serialization is excluded.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Simplifies implementation by avoiding the NoInterfaces code path
for OpenWorld protocols.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The generator doesn't know the target platform, so ServiceLoader
logic belongs in the runtime library with graceful fallback for
GWT/JS environments.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
12 tasks covering: runtime API, AST changes, parser, import resolution,
OpenWorld validation, code generation (registry, visitor, registration
classes), NameTable cross-package lookup, Maven plugin, and tests.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add `repeated string imports` to DefinitionFile in proto.proto to
support cross-file proto references. Also fix proto.proto/Java sync
by moving the shared `index` field from Constant up to Part (where it
already lived in the previously committed Java) and regenerate all AST
classes. All 67 generator tests pass.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add IMPORT token and import parsing rule to the JavaCC grammar so that
proto files can declare zero or more `import "path/to/file.proto";`
statements after the package declaration and before option statements.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
When resolving a QName like 'test.openworld.base.SSEEvent', the lookup
now tries progressively longer package prefixes as fallback, enabling
cross-file type references.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Track loaded files by canonical path to prevent duplicate loads and circular imports
- Resolve import statements by searching relative to source file then configured include paths (-I flag)
- Imported files participate in name resolution and specialization building but do not produce generated output
- OpenWorld option implies NoBinary and is incompatible with NoInterfaces
- Skip TypeIdSynthesizer for OpenWorld files

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add OpenWorld-specific code generation to MessageGenerator:
- Registry (Map + register method) on abstract root types
- Registry lookup in default case of polymorphic JSON reader
- TypeRegistryLoader.ensureLoaded() call before deserialization switch
- visitDefault() method on Visitor interface for unknown subtypes
- Extension Visitor interface on cross-file extension types
- instanceof-based visit dispatch for cross-file extensions

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
When an extension .proto file defines types that extend an abstract type
from an imported OpenWorld protocol, the generator now produces a
registration class (e.g., Ext1Types) that implements TypeRegistration
and registers each concrete extension type with the root OpenWorld type's
factory registry.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Fix cross-file extension type extends clause using wrong package casing
(camelCase was applied to all QName parts). Use resolved Definition for
fully-qualified type references. Propagate NoBinary from OpenWorld base
to extension files. Generate kind() returning null for cross-file
extension types not in the base TypeKind enum. Make PROPERTIES and
TRANSIENT_PROPERTIES protected in OpenWorld hierarchies for cross-package
access.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Generate Java code from test proto files (base/SSEEvent, ext1/GraphPatchEvent,
ext2/AnalyticsPatchEvent) and add TestOpenWorld with 6 test cases covering:
- Base type JSON round-trip
- Extension type registration and deserialization
- Multiple extension types
- Visitor dispatch to visitDefault for unknown extensions
- Extended visitor with instanceof-based routing
- Unknown type graceful handling (returns null)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The extends clause fix now uses resolved Definition objects, producing
fully-qualified type names in extends clauses. This is a cosmetic change
with no behavioral impact.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Instead of calling ensureLoaded() on every readXxx() invocation,
trigger it once via a static initializer block in the abstract
Impl class. This runs exactly once at class-loading time.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Generator writes ServiceLoader descriptor to a separate resource
  output directory specified via -resources CLI arg
- Maven plugin passes resourceOutputDir to generator
- TypeRegistryLoader.ensureLoaded() moved to static initializer in
  Impl class (runs once at class-loading, not per deserialization)
- Test uses auto-loading via ServiceLoader instead of explicit init()

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
target/classes is the compiled output, not a source directory.
Generated service descriptors must go through the normal Maven
resource processing.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There is no reliable Maven variable for the resource source directory.
Users must configure resourceOutputDir explicitly when using OpenWorld.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Better to have a visible default that might need adjusting than
to silently skip service descriptor generation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
When generating code for an OpenWorld protocol, the Visitor interface,
type dispatch switch, and TypeKind enum now only include specializations
from the same proto file. Cross-file extensions are handled at runtime
via the dynamic registry.

The filtering is implemented in AbstractMessageGenerator so that all
plugins (including XmlStreamingPlugin) benefit automatically.

Also:
- Move TypeRegistryLoader.ensureLoaded() to static initializer in Impl
- Generate META-INF/services descriptor via -resources CLI arg
- Add resourceOutputDir to Maven plugin
- TestParser sets include paths and resource dir for OpenWorld protos
- Test uses ServiceLoader auto-discovery instead of explicit init()

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Proto files packaged as resources in dependency JARs can now be
imported without having the source files on disk. The generator
tries file system resolution first, then falls back to classpath.

Generator changes:
- New setImportClassLoader() API for classpath-based resolution
- New -cp CLI argument for standalone usage
- resolveImports() tries file system first, then classpath
- Extracted loadPlugins() as public method

Maven plugin changes:
- Uses Generator API directly instead of main() CLI
- Automatically builds URLClassLoader from compile classpath
- requiresDependencyResolution = COMPILE on @mojo

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Imports are resolved from dependency JARs automatically in Maven.
For CLI usage, the -cp argument specifies JARs to search.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@haumacher
haumacher merged commit 69d520e into main Mar 25, 2026
@haumacher
haumacher deleted the feature/issue-9-cross-file-extension branch March 25, 2026 08:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support cross-file protocol extension (extends across .proto files)

1 participant