@@ -32,18 +32,21 @@ public final class StaticModuleScope implements ProcessingPass.Metadata {
3232 private final TypeScopeReference associatedType ;
3333 private final List <StaticImportExportScope > imports ;
3434 private final List <StaticImportExportScope > exports ;
35+ private final Map <String , AtomType > typesDefinedHere ;
3536 private final Map <TypeScopeReference , Map <String , TypeRepresentation >> methods ;
3637
3738 private StaticModuleScope (
3839 QualifiedName moduleName ,
3940 TypeScopeReference associatedType ,
4041 List <StaticImportExportScope > imports ,
4142 List <StaticImportExportScope > exports ,
43+ Map <String , AtomType > typesDefinedHere ,
4244 Map <TypeScopeReference , Map <String , TypeRepresentation >> methods ) {
4345 this .moduleName = moduleName ;
4446 this .associatedType = associatedType ;
4547 this .imports = imports ;
4648 this .exports = exports ;
49+ this .typesDefinedHere = typesDefinedHere ;
4750 this .methods = methods ;
4851 }
4952
@@ -52,6 +55,7 @@ static final class Builder {
5255 private final TypeScopeReference associatedType ;
5356 private final List <StaticImportExportScope > imports = new ArrayList <>();
5457 private final List <StaticImportExportScope > exports = new ArrayList <>();
58+ private final Map <String , AtomType > typesDefinedHere = new HashMap <>();
5559 private final Map <TypeScopeReference , Map <String , TypeRepresentation >> methods =
5660 new HashMap <>();
5761
@@ -76,6 +80,7 @@ public StaticModuleScope build() {
7680 associatedType ,
7781 Collections .unmodifiableList (imports ),
7882 Collections .unmodifiableList (exports ),
83+ Collections .unmodifiableMap (typesDefinedHere ),
7984 Collections .unmodifiableMap (methods ));
8085 }
8186
@@ -87,6 +92,14 @@ public TypeScopeReference getAssociatedType() {
8792 return associatedType ;
8893 }
8994
95+ void registerType (AtomType type ) {
96+ checkSealed ();
97+ var previous = typesDefinedHere .putIfAbsent (type .getName (), type );
98+ if (previous != null ) {
99+ throw new IllegalStateException ("Type already defined: " + type .getName ());
100+ }
101+ }
102+
90103 void registerMethod (TypeScopeReference parentType , String name , TypeRepresentation type ) {
91104 checkSealed ();
92105 var typeMethods = methods .computeIfAbsent (parentType , k -> new HashMap <>());
0 commit comments