2828unimplemented (t:: Type , x:: Symbol ) =
2929 error (" AbstractFBCModels interface method $x is not implemented for type $t " )
3030
31+
3132"""
3233$(TYPEDSIGNATURES)
3334
3435Provide a `methodswith`-style listing of accessors that the model implementors
3536may implement.
36-
37- For typesystem reasons, the list **will not contain** methods for
38- [`load`](@ref) and [`filename_extensions`](@ref) that dispatch on type objects.
39- You should implement these as well.
40-
41- See also [`required_accessors`](@ref) for the minimal list that must be implemented.
4237"""
4338function accessors ()
4439 ms = Method[]
@@ -48,9 +43,29 @@ function accessors()
4843 methodswith (AbstractFBCModels. AbstractFBCModel, f, ms)
4944 end
5045 end
46+
47+ append! (ms, _type_accessors ())
48+ return ms
49+ end
50+
51+ function _type_accessors ()
52+ # special case: some "accessors" take the Type argument instead of actual instance
53+ ms = Method[]
54+ for f in (AbstractFBCModels. load, AbstractFBCModels. filename_extensions)
55+ for m in methods (f)
56+ m. sig isa UnionAll || continue
57+ # Deep magic: basically this matches on `f(::Type{A},...) where A<:AbstractFBCModel`
58+ type_param = Base. unwrap_unionall (m. sig). parameters[2 ]. parameters[1 ]. ub
59+ if type_param == AbstractFBCModels. AbstractFBCModel
60+ push! (ms, m)
61+ end
62+ end
63+ end
64+
5165 return ms
5266end
5367
68+
5469"""
5570$(TYPEDSIGNATURES)
5671
@@ -70,6 +85,7 @@ function required_accessors()
7085 for f in REQUIRED_ACCESSORS
7186 methodswith (AbstractFBCModels. AbstractFBCModel, f, ms)
7287 end
88+ append! (ms, _type_accessors ())
7389 return ms
7490end
7591
0 commit comments