diff --git a/redwood-tooling-schema/src/main/kotlin/app/cash/redwood/tooling/schema/schemaParser.kt b/redwood-tooling-schema/src/main/kotlin/app/cash/redwood/tooling/schema/schemaParser.kt index e5dd84b050..d11f4ca761 100644 --- a/redwood-tooling-schema/src/main/kotlin/app/cash/redwood/tooling/schema/schemaParser.kt +++ b/redwood-tooling-schema/src/main/kotlin/app/cash/redwood/tooling/schema/schemaParser.kt @@ -53,13 +53,19 @@ internal fun loadProtocolSchemaSet( classLoader: ClassLoader, ): ProtocolSchemaSet { val schema = loadProtocolSchema(type, classLoader) - val dependencies = schema.taggedDependencies.map { (tag, dependency) -> - loadProtocolSchema(dependency, classLoader, tag) - } - return ParsedProtocolSchemaSet( - schema = schema, - dependencies = dependencies.associateBy { it.type }, - ) + return loadProtocolSchemaDependencies(schema, classLoader) +} + +internal fun loadProtocolSchemaDependencies( + schema: ProtocolSchema, + classLoader: ClassLoader, +): ParsedProtocolSchemaSet { + val dependencies = schema.taggedDependencies.entries + .associate { (tag, type) -> + require(tag != 0) { "Dependency $type tag must be non-zero" } + type to loadProtocolSchema(type, classLoader, tag) + } + return ParsedProtocolSchemaSet(schema, dependencies) } internal fun loadProtocolSchema( @@ -228,33 +234,14 @@ internal fun parseProtocolSchemaSet(schemaType: KClass<*>): ProtocolSchemaSet { ) } - val dependencies = schemaAnnotation.dependencies - .associate { - val dependencyTag = it.tag - val dependencyType = it.schema.toFqType() - require(dependencyTag != 0) { - "Dependency $dependencyType tag must not be non-zero" - } - - val schema = loadProtocolSchema( - type = dependencyType, - classLoader = schemaType.java.classLoader, - tag = dependencyTag, - ) - dependencyTag to schema - } - val schema = ParsedProtocolSchema( type = schemaType.toFqType(), scopes = scopes.toList(), widgets = widgets, modifiers = modifiers, - taggedDependencies = dependencies.mapValues { (_, schema) -> schema.type }, - ) - val schemaSet = ParsedProtocolSchemaSet( - schema, - dependencies.values.associateBy { it.type }, + taggedDependencies = schemaAnnotation.dependencies.associate { it.tag to it.schema.toFqType() }, ) + val schemaSet = loadProtocolSchemaDependencies(schema, schemaType.java.classLoader) val duplicatedWidgets = schemaSet.all .flatMap { it.widgets.map { widget -> widget to it } } diff --git a/redwood-tooling-schema/src/main/kotlin/app/cash/redwood/tooling/schema/schemaParserFir.kt b/redwood-tooling-schema/src/main/kotlin/app/cash/redwood/tooling/schema/schemaParserFir.kt index fba3e5ecd1..b90c3d2d3a 100644 --- a/redwood-tooling-schema/src/main/kotlin/app/cash/redwood/tooling/schema/schemaParserFir.kt +++ b/redwood-tooling-schema/src/main/kotlin/app/cash/redwood/tooling/schema/schemaParserFir.kt @@ -202,24 +202,7 @@ public fun parseProtocolSchema( disposable.dispose() val dependencyClassLoader = URLClassLoader(dependencies.map { it.toURI().toURL() }.toTypedArray()) - val dependencySchemas = schema.taggedDependencies.entries - .associate { (dependencyTag, dependencyType) -> - require(dependencyTag != 0) { - "Dependency $dependencyType tag must not be non-zero" - } - - val dependency = loadProtocolSchema( - type = dependencyType, - classLoader = dependencyClassLoader, - tag = dependencyTag, - ) - dependencyTag to dependency - } - - val schemaSet = ParsedProtocolSchemaSet( - schema, - dependencySchemas.values.associateBy { it.type }, - ) + val schemaSet = loadProtocolSchemaDependencies(schema, dependencyClassLoader) val duplicatedWidgets = schemaSet.all .flatMap { it.widgets.map { widget -> widget to it } } diff --git a/redwood-tooling-schema/src/test/kotlin/app/cash/redwood/tooling/schema/SchemaParserTest.kt b/redwood-tooling-schema/src/test/kotlin/app/cash/redwood/tooling/schema/SchemaParserTest.kt index a4344a0f93..738b349fd8 100644 --- a/redwood-tooling-schema/src/test/kotlin/app/cash/redwood/tooling/schema/SchemaParserTest.kt +++ b/redwood-tooling-schema/src/test/kotlin/app/cash/redwood/tooling/schema/SchemaParserTest.kt @@ -1090,7 +1090,7 @@ class SchemaParserTest( assertFailure { parser.parse(SchemaDependencyTagZero::class) } .isInstanceOf() .hasMessage( - "Dependency app.cash.redwood.layout.RedwoodLayout tag must not be non-zero", + "Dependency app.cash.redwood.layout.RedwoodLayout tag must be non-zero", ) }