1919
2020import app .packed .application .ApplicationMirror ;
2121import app .packed .extension .Extension ;
22+ import app .packed .namespace .NamespaceMirror ;
2223import app .packed .namespace .OverviewHandle ;
2324import app .packed .namespace .OverviewMirror ;
2425import app .packed .operation .OperationMirror ;
2526import internal .app .packed .application .ApplicationSetup ;
27+ import internal .app .packed .namespace .NamespaceSetup ;
2628import internal .app .packed .extension .ExtensionClassModel ;
2729import internal .app .packed .invoke .ConstructorSupport ;
2830import internal .app .packed .invoke .ConstructorSupport .OverviewMirrorFactory ;
3335 */
3436public abstract sealed class PackedOverviewHandle <E extends Extension <E >> implements OverviewHandle <E > {
3537
38+ /** Cache OverviewMirror constructor factories. */
39+ private static final ClassValue <OverviewMirrorFactory > CONSTRUCTORS = new ClassValue <>() {
40+
41+ @ SuppressWarnings ("unchecked" )
42+ @ Override
43+ protected OverviewMirrorFactory computeValue (Class <?> type ) {
44+ return ConstructorSupport .findOverviewMirrorConstructor ((Class <? extends OverviewMirror <?>>) type );
45+ }
46+ };
47+
3648 /** Extract the extension type variable from OverviewMirror. */
3749 private static final ClassValue <Class <? extends Extension <?>>> EXTENSION_TYPES = new ClassValue <>() {
3850
@@ -44,15 +56,11 @@ protected Class<? extends Extension<?>> computeValue(Class<?> type) {
4456 }
4557 };
4658
47- /** Cache OverviewMirror constructor factories. */
48- private static final ClassValue <OverviewMirrorFactory > CONSTRUCTORS = new ClassValue <>() {
4959
50- @ SuppressWarnings ("unchecked" )
51- @ Override
52- protected OverviewMirrorFactory computeValue (Class <?> type ) {
53- return ConstructorSupport .findOverviewMirrorConstructor ((Class <? extends OverviewMirror <?>>) type );
54- }
55- };
60+ @ Override
61+ public final <T extends OperationMirror > OperationMirror .OfStream <T > operations (Class <T > operationType ) {
62+ return (OperationMirror .OfStream <T >) operations ().ofType (operationType );
63+ }
5664
5765 @ SuppressWarnings ("unchecked" )
5866 public static <O extends OverviewMirror <?>> O ofApplication (ApplicationSetup application , Class <O > type ) {
@@ -66,6 +74,43 @@ public static <O extends OverviewMirror<?>> O ofApplication(ApplicationSetup app
6674 return (O ) factory .create (handle );
6775 }
6876
77+ /**
78+ * @param <O>
79+ * @param application
80+ * @param extensionType
81+ * @param type
82+ * @return
83+ */
84+ @ SuppressWarnings ("unchecked" )
85+ public static <O extends OverviewMirror <?>> O ofExtension (ApplicationSetup application , Class <? extends Extension <?>> extensionType , Class <O > type ) {
86+ requireNonNull (extensionType , "extensionType is null" );
87+ requireNonNull (type , "type is null" );
88+
89+ Class <? extends Extension <?>> mirrorExtensionType = EXTENSION_TYPES .get (type );
90+ if (extensionType != mirrorExtensionType ) {
91+ throw new IllegalArgumentException (
92+ "extensionType " + extensionType + " does not match the extension type of " + type + " which is " + mirrorExtensionType );
93+ }
94+
95+ OverviewMirrorFactory factory = CONSTRUCTORS .get (type );
96+
97+ PackedExtensionOverviewHandle <?> handle = new PackedExtensionOverviewHandle <>(application .mirror (), extensionType );
98+
99+ return (O ) factory .create (handle );
100+ }
101+
102+ @ SuppressWarnings ("unchecked" )
103+ public static <O extends OverviewMirror <?>> O ofNamespace (NamespaceSetup namespace , Class <O > type ) {
104+ requireNonNull (type , "type is null" );
105+
106+ Class <? extends Extension <?>> extensionType = EXTENSION_TYPES .get (type );
107+ OverviewMirrorFactory factory = CONSTRUCTORS .get (type );
108+
109+ PackedNamespaceOverviewHandle <?> handle = new PackedNamespaceOverviewHandle <>(namespace .mirror (), extensionType );
110+
111+ return (O ) factory .create (handle );
112+ }
113+
69114 public static final class PackedApplicationOverviewHandle <E extends Extension <E >> extends PackedOverviewHandle <E > {
70115
71116 private final ApplicationMirror applicationMirror ;
@@ -82,9 +127,39 @@ public OperationMirror.OfStream<OperationMirror> operations() {
82127 return applicationMirror .operations ().filter (op -> op .installedByExtension () == extensionType );
83128 }
84129
130+ }
131+
132+ public static final class PackedExtensionOverviewHandle <E extends Extension <E >> extends PackedOverviewHandle <E > {
133+
134+ private final ApplicationMirror applicationMirror ;
135+
136+ private final Class <? extends Extension <?>> extensionType ;
137+
138+ public PackedExtensionOverviewHandle (ApplicationMirror applicationMirror , Class <? extends Extension <?>> extensionType ) {
139+ this .applicationMirror = requireNonNull (applicationMirror );
140+ this .extensionType = requireNonNull (extensionType );
141+ }
142+
143+ @ Override
144+ public OperationMirror .OfStream <OperationMirror > operations () {
145+ return applicationMirror .allOperations ().filter (op -> op .bean ().owner ().isExtension (extensionType ));
146+ }
147+ }
148+
149+ public static final class PackedNamespaceOverviewHandle <E extends Extension <E >> extends PackedOverviewHandle <E > {
150+
151+ private final NamespaceMirror namespaceMirror ;
152+
153+ private final Class <? extends Extension <?>> extensionType ;
154+
155+ public PackedNamespaceOverviewHandle (NamespaceMirror namespaceMirror , Class <? extends Extension <?>> extensionType ) {
156+ this .namespaceMirror = requireNonNull (namespaceMirror );
157+ this .extensionType = requireNonNull (extensionType );
158+ }
159+
85160 @ Override
86- public < T extends OperationMirror > OperationMirror .OfStream <T > operations (Class < T > operationType ) {
87- return ( OperationMirror . OfStream < T >) operations ().ofType ( operationType );
161+ public OperationMirror .OfStream <OperationMirror > operations () {
162+ return namespaceMirror . operations ().filter ( op -> op . installedByExtension () == extensionType );
88163 }
89164 }
90165}
0 commit comments