@@ -119,16 +119,37 @@ def shortest_name(dotted_path):
119119 if len (parts ) == 1 :
120120 return parts [0 ].lstrip ("+" )
121121
122+ if "@" in dotted_path :
123+ return dotted_path
124+
122125 parts_to_keep = []
123126 for part in parts [:- 1 ]:
124- if part .startswith ("+" ) or part . startswith ( "@" ) :
125- parts_to_keep .append (part .lstrip ("+@ " ))
127+ if part .startswith ("+" ):
128+ parts_to_keep .append (part .lstrip ("+" ))
126129 elif len (parts_to_keep ) > 0 :
127130 parts_to_keep = []
128- parts_to_keep .append (parts [- 1 ].lstrip ("+@ " ))
131+ parts_to_keep .append (parts [- 1 ].lstrip ("+" ))
129132 return "." .join (parts_to_keep )
130133
131134
135+ def classfolder_class_name (dotted_path ):
136+ # Returns a @ClassFolder classname if applicable, otherwise the dotted_path is returned
137+ #
138+ if "@" not in dotted_path :
139+ return dotted_path
140+
141+ parts = dotted_path .split ("." )
142+ if len (parts ) == 1 :
143+ return dotted_path
144+
145+ stripped_parts = [part .lstrip ("@" ) for part in parts ]
146+
147+ if stripped_parts [- 1 ] == stripped_parts [- 2 ]:
148+ return "." .join (parts [0 :- 2 ] + [stripped_parts [- 1 ]])
149+ else :
150+ return dotted_path
151+
152+
132153def recursive_find_all (obj ):
133154 # Recursively finds all entities in all "modules" aka directories.
134155 for _ , o in obj .entities :
@@ -204,6 +225,43 @@ def analyze(app):
204225 populate_entities_table (root )
205226 entities_table ["." ] = root
206227
228+ # Transform Class Folders classes from
229+ #
230+ # @ClassFolder (Module)
231+ # ClassFolder (Class)
232+ # method1 (Function)
233+ # method2 (Function)
234+ #
235+ # To
236+ #
237+ # ClassFolder (Class) with the method1 and method2 add to the ClassFolder Class.
238+ class_folder_modules = {
239+ k : v for k , v in entities_table .items () if "@" in k and isinstance (v , MatModule )
240+ }
241+ # For each Class Folder module
242+ for cf_name , cf_entity in class_folder_modules .items ():
243+ # Find the class entity class.
244+ class_entities = [e for e in cf_entity .entities if isinstance (e [1 ], MatClass )]
245+ func_entities = [e for e in cf_entity .entities if isinstance (e [1 ], MatFunction )]
246+ assert len (class_entities ) == 1
247+ cls = class_entities [0 ][1 ]
248+
249+ # Add functions to class
250+ for func_name , func in func_entities :
251+ func .__class__ = MatMethod
252+ func .cls = cls
253+ # TODO: Find the method attributes defined in classfolder class defintion.
254+ func .attrs = {}
255+ cls .methods [func .name ] = func
256+
257+ # Transform @ClassFolder names. Specifically
258+ class_folder_names = {}
259+ for name , entity in entities_table .items ():
260+ alt_name = classfolder_class_name (name )
261+ if name != alt_name :
262+ class_folder_names [alt_name ] = entity
263+ entities_table .update (class_folder_names )
264+
207265 # Find alternative names to entities
208266 # target.+package.+sub.Class -> package.sub.Class
209267 # folder.subfolder.Class -> Class
0 commit comments